#!/bin/bash
#
-# Copyright: George Milescu 2010 - george.milescu@gmail.com
+# 2010, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro
#
-# Bash script used to parse the log file generated by a tribler client and to generate a data file
+# Bash script used to parse the log file generated by a next-share client
#
# Script arguments:
# * a folder where the log and data files are stored
# * the name of a log file in that folder
-
+#
+# Sample run:
+# ./parse_nextshare.sh ../../../Results/samples/ p2p-next-01-101.log
if [ ! $# -eq 2 ]; then
echo "usage: $0 log-folder log-file"
LOG_FOLDER=$1
LOG_FILE=$2
DATA_FILE=$LOG_FOLDER/${LOG_FILE}.data
+PEER_UPLOAD_DOWNLOAD_FILE=$LOG_FOLDER/${LOG_FILE}.updown
# Check if the log folder exists
if [ ! -d $LOG_FOLDER ]; then
echo "time percent upspeed dlspeed" > $DATA_FILE
# Clean and parse the log file
-cat $LOG_FOLDER/$LOG_FILE | grep "DLSTATUS\|SLEEP" | grep -v "HASHCHECKING" | tr '\t' ' ' | tr -s ' ' | sed -e s/"%"/""/g -e s/"KB\/s"/""/g >> $DATA_FILE.tmp
-
-# Current relative time is=0 (we are at the beginning of the test)
-rel_time=0
-
-# Read all log lines and process the information for the plotting component
-while read FILE_NAME STATUS PERCENT UNKNOWN UP UP_SPEED DOWN DOWN_SPEED; do
- if [ " $FILE_NAME" = " SLEEP" ]; then
- rel_time=$(($rel_time + $STATUS))
- else
- echo "$rel_time $PERCENT $UP_SPEED $DOWN_SPEED" >>$DATA_FILE
- rel_time=$(($rel_time + 1))
- fi
-done <$DATA_FILE.tmp
-
-rm -f $DATA_FILE.tmp
+grep '^peers\|SLEEP' $LOG_FOLDER/$LOG_FILE | awk -F '[ ]+' '
+BEGIN {
+ rel_time = 0;
+}
+
+{
+ if ($1 == "SLEEP")
+ rel_time = rel_time + $2;
+ else {
+ percent = $6 + 0;
+ upspeed = $8 + 0;
+ dlspeed = $10 + 0;
+
+ printf "%d %.2f %.2f %.2f\n", rel_time, percent, upspeed, dlspeed;
+ rel_time++;
+ }
+}' >> $DATA_FILE
+
+# convert host_id and veid to veth IP address in 10.0.0.0/8 network
+host_veid_to_eth_ip()
+{
+ host_id=$1
+ veid=$2
+ ip_part1=$(($veid / 100))
+ ip_part2=$(($veid % 100))
+ id=$(echo "$host_id" | awk '{printf "%d", $1;}')
+ echo "10.$ip_part1.$id.$ip_part2"
+}
+
+# convert p2p-next-${host_id}-${veid} hostname to veth IP address
+hostname_to_ip()
+{
+ hostname=$1
+
+ veid=${hostname##*-}
+tmp=${hostname%-*}
+ host_id=${tmp##*-}
+
+ host_veid_to_eth_ip $host_id $veid
+}
+
+local_ip=$(hostname_to_ip ${LOG_FILE/%.log/})
+
+# Parse the peer log file; output peer download and upload files
+
+grep '^--Peers' $LOG_FOLDER/$LOG_FILE | awk -v ip=${local_ip} -F '[],() []+' '
+{
+ printf "[%s %s %s]", $2, $3, $4;
+ i = 6;
+ for (i = 6; i < NF; i += 6) {
+ j = i+2;
+ k = i+4;
+ down_speed = $j + 0;
+ up_speed = $k + 0;
+ split($i, ip_port, ":");
+ printf " (%s, %s, %s, %s)", ip, ip_port[1], down_speed, up_speed;
+ }
+ printf "\n";
+}' > $PEER_UPLOAD_DOWNLOAD_FILE
+
exit 0