ControlScripts/clients/hrk: add parsing support for peer-connections upload/download...
authorRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Fri, 13 Aug 2010 15:30:31 +0000 (18:30 +0300)
committerRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Fri, 13 Aug 2010 15:30:31 +0000 (18:30 +0300)
ControlScripts/clients/hrk/parse_hrk.sh

index bb30d00..e8a27e8 100755 (executable)
@@ -16,6 +16,8 @@ fi
 LOG_FOLDER=$1
 LOG_FILE=$2
 DATA_FILE=$LOG_FOLDER/${LOG_FILE}.data
+PEER_DOWNLOAD_FILE=$LOG_FOLDER/${LOG_FILE}.down
+PEER_UPLOAD_FILE=$LOG_FOLDER/${LOG_FILE}.up
 
 # Check if the log folder exists
 if [ ! -d $LOG_FOLDER ]; then
@@ -48,7 +50,7 @@ BEGIN {
        if ($1 == "SLEEP")
                rel_time = rel_time + $2;
        else {
-               lspeed = $6 + 0;
+               dlspeed = $6 + 0;
                upspeed = $8 + 0;
                download = $10 + 0;
                size = $14 + 0;
@@ -59,4 +61,57 @@ BEGIN        {
        }
 }' >> $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\|SLEEP' $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;
+               speed = $j + 0;
+               split($i, ip_port, ":");
+               printf " (%s, %s, %s)", ip, ip_port[1], speed;
+       }
+       printf "\n";
+}' > $PEER_DOWNLOAD_FILE
+
+grep '^--Peers\|SLEEP' $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+4;
+               speed = $j + 0;
+               split($i, ip_port, ":");
+               printf " (%s, %s, %s)", ip, ip_port[1], speed;
+       }
+       printf "\n";
+}' > $PEER_UPLOAD_FILE
+
 exit 0