# configuration file
#
# Sample run:
-# ./rgen ../test-campaign.cfg ../test-scenario-pre-post-nop-ul.cfg > out.R
+# ./rgen performance-experiments-3.01.cfg > out.R
#
-if test $# -ne 2; then
- echo "Usage: $0 campaign-config-file scenario-config-file" 1>&2
+if test $# -ne 1; then
+ echo "Usage: $0 scenario-config-file" 1>&2
exit 1
fi
-campaign_file=$1
-scenario_file=$2
+scenario_file=$1
-campaign_name=${campaign_file/%.cfg}
-scenario_name=${scenario_file/%.cfg}
+scenario_name=$(basename ${scenario_file} .cfg)
+
+declare num_seeders
+declare num_leechers
+declare description
+declare dl_max_limit
+declare ul_max_limit
+
+# parse comment zone in scenario file (description, leechers, seeders etc.)
+parse_comment()
+{
+ num_leechers=$(grep "^[ \t]*#[ \t]*Number of leechers:" ${scenario_file} | awk -F ":" '{print $2;}')
+ num_seeders=$(grep "^[ \t]*#[ \t]*Number of seeders:" ${scenario_file} | awk -F ":" '{print $2;}')
+ dl_max_limit=$(grep "^[ \t]*#[ \t]*Maximum download:" ${scenario_file} | awk -F ":" '{print $2;}')
+ dl_max_upload=$(grep "^[ \t]*#[ \t]*Maximum upload:" ${scenario_file} | awk -F ":" '{print $2;}')
+ description=$(grep "^[ \t]*#[ \t]*Description:" ${scenario_file} | awk -F ":" '{print $2;}')
+}
+
+# test client description for "leecher" string
+test_is_leecher()
+{
+ client_type=$1
+
+ grep "leecher" <<<"${client_type}" &> /dev/null
+}
+
+parse_comment
cat <<END
# Read transmitted command line arguments
index=1
while read server port user remote_path remote_if dl_bw dl_burst ul_bw ul_burst pre_run_script post_run_script client_type torrent_file periods; do
+ new_port=${port%22}
+ if test -z "${new_port}"; then
+ base_log_name=${server%%.*}
+ else
+ base_log_name=${server%%.*}-${new_port}
+ fi
+ if test_is_leecher ${client_type}; then
+ base_client_name="leecher"
+ else
+ base_client_name="seeder"
+ fi
cat <<END
-peer${index}=read.table(paste(target_folder, "${server}.log.data", sep="/"), header=T, sep=" ")
+${base_client_name}${index}=read.table(paste(target_folder, "${base_log_name}.log.data", sep="/"), header=T, sep=" ")
END
((index++))
-done < <(grep -v '^#' ${scenario_file})
+done < <(grep -v '^#\|^[ \t]*$' ${scenario_file})
cat <<END
index=1
while read server port user remote_path remote_if dl_bw dl_burst ul_bw ul_burst pre_run_script post_run_script client_type torrent_file periods; do
+ if ! test_is_leecher ${client_type}; then
+ ((index++))
+ continue
+ fi
cat <<END
-peer${index}\$dlspeed <- peer${index}\$dlspeed*8/1000
+leecher${index}\$dlspeed <- leecher${index}\$dlspeed*8/1000
END
((index++))
-done < <(grep -v '^#' ${scenario_file})
+done < <(grep -v '^#\|^[ \t]*$' ${scenario_file})
cat <<END
index=1
while read server port user remote_path remote_if dl_bw dl_burst ul_bw ul_burst pre_run_script post_run_script client_type torrent_file periods; do
+ if ! test_is_leecher ${client_type}; then
+ ((index++))
+ continue
+ fi
cat <<END
-geom_point(aes(x=peer${index}\$percent, y=peer${index}\$dlspeed, label="Peer ${index}"), size=1) +
+geom_point(aes(x=leecher${index}\$percent, y=leecher${index}\$dlspeed, label="Leecher ${index}"), size=1) +
END
((index++))
-done < <(grep -v '^#' ${scenario_file})
+done < <(grep -v '^#\|^[ \t]*$' ${scenario_file})
cat <<END
theme_bw() +
scale_x_continuous("Percent", limits=c(0, 100), breaks=seq(0, 100, 10)) +
-scale_y_continuous("Download speed (Mbit/s)", limits=c(0, 8), breaks=seq(0, 8, 0.5)) +
+scale_y_continuous("Download speed (Mbit/s)", limits=c(0, ${dl_max_limit}), breaks=seq(0, ${dl_max_limit}, 0.5)) +
coord_cartesian() +
scale_colour_manual("Legend") +
-opts(title=paste(campaign_name, "${campaign_name}: a test swarm (TODO Seeders, TODO Leechers), TODO description", sep="\n"))
+opts(title=paste(campaign_name, "${scenario_name}: a test swarm (${num_seeders} Seeders, ${num_leechers} Leechers), ${description}", sep="\n"))
# plot data as an eps file
-postscript(paste(target_folder, "${scenario_name}.eps", sep="/"))
+postscript(paste(target_folder, "${scenario_name}-dlspeed-percent.eps", sep="/"))
print(p)
dev.off()
# plot data as an png file
-png(paste(target_folder, "${scenario_name}.png", sep="/"), width = 1280, height = 800)
+png(paste(target_folder, "${scenario_name}-dlspeed-percent.png", sep="/"), width = 1280, height = 800)
print(p)
dev.off()
index=1
while read server port user remote_path remote_if dl_bw dl_burst ul_bw ul_burst pre_run_script post_run_script client_type torrent_file periods; do
+ if ! test_is_leecher ${client_type}; then
+ ((index++))
+ continue
+ fi
cat <<END
-geom_point(aes(x=peer${index}\$percent, y=peer${index}\$dlspeed, label="Peer ${index}"), size=1) +
+geom_point(aes(x=leecher${index}\$percent, y=leecher${index}\$dlspeed, label="Leecher ${index}"), size=1) +
END
((index++))
-done < <(grep -v '^#' ${scenario_file})
+done < <(grep -v '^#\|^[ \t]*$' ${scenario_file})
cat <<END
theme_bw() +
scale_x_continuous("Time(s)") +
-scale_y_continuous("Download speed (Mbit/s)", limits=c(0, 8), breaks=seq(0, 8, 0.5)) +
+scale_y_continuous("Download speed (Mbit/s)", limits=c(0, ${dl_max_limit}), breaks=seq(0, ${dl_max_limit}, 0.5)) +
coord_cartesian() +
scale_colour_manual("Legend") +
-opts(title=paste(campaign_name, "${campaign_name}: a test swarm (TODO Seeders, TODO Leechers), TODO description)", sep="\n"))
+opts(title=paste(campaign_name, "${scenario_name}: a test swarm (${num_seeders} Seeders, ${num_leechers} Leechers), ${description}", sep="\n"))
# plot data as an eps file
-postscript(paste(target_folder, "${scenario_name}.eps", sep="/"))
+postscript(paste(target_folder, "${scenario_name}-dlspeed-time.eps", sep="/"))
print(p)
dev.off()
# plot data as an png file
-png(paste(target_folder, "${scenario_name}.png", sep="/"), width = 1280, height = 800)
+png(paste(target_folder, "${scenario_name}-dlspeed-time.png", sep="/"), width = 1280, height = 800)
print(p)
dev.off()
END