makeUdpPlots.py 4.99 KB
Newer Older
1 2
#
# Copyright (c) 2006 University of Utah and the Flux Group.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
22 23
#

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
import sys
import re

# Read stats from the log output by UdpClient.
inFile = open(sys.argv[1], 'r')

bandwidthFile = "AvailBandwidth.log"
throughputFile = "Throughput.log"
avgThroughputFile = "AvgThroughput.log"
lossFile = "Loss.log"
minDelayFile = "MinDelay.log"
maxDelayFile = "MaxDelay.log"
sendDeviationFile = "SendDeviation.log"
queueDelayFile = "QueueDelay.log"
messageFile = "Messages.log"

# And print out the bandwidth, packet loss, minimum delay and
# queue size into seperate files, so that they can be plotted
# with GnuPlot.
outFileBandwidth = open(bandwidthFile, 'w')
outFileThroughput = open(throughputFile, 'w')
outFileAvgThroughput = open(avgThroughputFile, 'w')
outFileLoss = open(lossFile, 'w')
outFileMinD = open(minDelayFile, 'w')
outFileMaxD = open(maxDelayFile, 'w')
outFileSendDeviation = open(sendDeviationFile, 'w')
outFileQueueD = open(queueDelayFile, 'w')
outFileMessages = open(messageFile, 'w')

regExp = re.compile('^\w*?\s*?\d*?\.\d*?:\s(\w*?):(\w*?)\=(\d*)\,(\w*?)\=([\d\.]*)')

availBandwidth = 0
bandWidthBps = 0
throughputBps = 0

# Array indices, 0 - throughput, 1 - loss, 2 - minimum delay, 3 - queue size
# 4 - deviation in send times, 5 - actual queuing delay per packet
# 6 - average throughput
initTimeArray = [0,0,0,0,0,0,0]
timeDiffArray = [0,0,0,0,0,0,0]
initFlagsArray = [0,0,0,0,0,0,0]

for line in inFile:
	match = regExp.match(line)

	if match:
		if match.group(1) == 'TPUT':
			if initFlagsArray[0] == 0:
				initTimeArray[0] = int(match.group(3))
				timeDiffArray[0] = 0
				initFlagsArray[0] = 1
			else:
				timeDiffArray[0] = int(match.group(3)) - initTimeArray[0]

			if match.group(4) == 'AUTHORITATIVE':
				availBandwidth = float(match.group(5))
			elif match.group(4) == 'TENTATIVE':
				if float(match.group(5)) > availBandwidth:
					availBandwidth = float(match.group(5))

			bandWidthBps = 1024*availBandwidth / ( 8 )
			throughputBps = 1024* ( float(match.group(5) ) ) / ( 8 )
			
			outFileBandwidth.write(str(timeDiffArray[0]) + "  " + str(bandWidthBps) + "\n" )
			outFileThroughput.write(str(timeDiffArray[0]) + "  " + str(throughputBps) + "\n" )

		elif match.group(1) == 'LOSS':
			if initFlagsArray[1] == 0:
				initTimeArray[1] = int(match.group(3))
				timeDiffArray[1] = 0
				initFlagsArray[1] = 1
			else:
				timeDiffArray[1] = int(match.group(3)) - initTimeArray[1]

			outFileLoss.write(str(timeDiffArray[1]) + "  " + match.group(5) + "\n" )

		elif match.group(1) == 'MIND':
			if initFlagsArray[2] == 0:
				initTimeArray[2] = int(match.group(3))
				timeDiffArray[2] = 0
				initFlagsArray[2] = 1
			else:
				timeDiffArray[2] = int(match.group(3)) - initTimeArray[2]

			outFileMinD.write(str(timeDiffArray[2]) + "  " + match.group(5) + "\n" )

		elif match.group(1) == 'MAXD':
			if initFlagsArray[3] == 0:
				initTimeArray[3] = int(match.group(3))
				timeDiffArray[3] = 0
				initFlagsArray[3] = 1
			else:
				timeDiffArray[3] = int(match.group(3)) - initTimeArray[3]

			outFileMaxD.write(str(timeDiffArray[3]) + "  " + match.group(5) + "\n" )
		elif match.group(1) == 'SendDeviation':
			if initFlagsArray[4] == 0:
				initTimeArray[4] = int(match.group(3))
				timeDiffArray[4] = 0
				initFlagsArray[4] = 1
			else:
				timeDiffArray[4] = int(match.group(3)) - initTimeArray[4]

			outFileSendDeviation.write(str(timeDiffArray[4]) + "  " + match.group(5) + "\n" )
		elif match.group(1) == 'ACTUAL_MAXD':
			if initFlagsArray[5] == 0:
				initTimeArray[5] = int(match.group(3))
				timeDiffArray[5] = 0
				initFlagsArray[5] = 1
			else:
				timeDiffArray[5] = int(match.group(3)) - initTimeArray[5]

			outFileQueueD.write(str(timeDiffArray[5]) + "  " + match.group(5) + "\n" )
		elif match.group(1) == 'AVGTPUT':
			if initFlagsArray[6] == 0:
				initTimeArray[6] = int(match.group(3))
				timeDiffArray[6] = 0
				initFlagsArray[6] = 1
			else:
				timeDiffArray[6] = int(match.group(3)) - initTimeArray[6]

			if match.group(4) == 'AUTHORITATIVE':
				availBandwidth = float(match.group(5))
			elif match.group(4) == 'TENTATIVE':
				if float(match.group(5)) > availBandwidth:
					availBandwidth = float(match.group(5))

			bandWidthBps = 1024*availBandwidth / ( 8 )
			
			outFileAvgThroughput.write(str(timeDiffArray[6]) + "  " + str(bandWidthBps) + "\n" )

	else:
		outFileMessages.write(line)