--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/flowmon-plot.py Tue May 19 18:01:40 2009 +0100
@@ -0,0 +1,58 @@
+import sys
+import pylab
+try:
+ from xml.etree import cElementTree as ElementTree
+except ImportError:
+ from xml.etree import ElementTree
+
+def parse_time(s):
+ assert s.endswidth('ns')
+ return ns3.Nano
+
+def main():
+ et = ElementTree.parse(sys.argv[1])
+ bitrates = []
+ losses = []
+ delays = []
+ for flow in et.findall("FlowStats/Flow"):
+ # filter out OLSR
+ for five_tuple in et.findall("Ipv4FlowClassifier/Flow"):
+ if five_tuple.get('flowId') == flow.get('flowId'):
+ break
+ if five_tuple.get("destinationPort") == '698':
+ continue
+
+ losses.append(int(flow.get('lostPackets')))
+
+ rxPackets = int(flow.get('rxPackets'))
+ if rxPackets == 0:
+ bitrates.append(0)
+ else:
+ t0 = long(flow.get('timeFirstRxPacket')[:-2])
+ t1 = long(flow.get('timeLastRxPacket')[:-2])
+ duration = (t1 - t0)*1e-9 # duration in seconds
+ bitrates.append(8*long(flow.get('rxBytes')) / duration * 1e-3)
+
+ delays.append((float(flow.get('delaySum')[:-2])*1e-9) / rxPackets)
+
+ pylab.subplot(311)
+ pylab.hist(bitrates, bins=40)
+ pylab.xlabel("Flow bitrate (bit/s)")
+ pylab.ylabel("Number of flows")
+
+ pylab.subplot(312)
+ pylab.hist(losses, bins=40)
+ pylab.xlabel("Number of lost packets")
+ pylab.ylabel("Number of flows")
+
+ pylab.subplot(313)
+ pylab.hist(delays, bins=10)
+ pylab.xlabel("Delay (s)")
+ pylab.ylabel("Number of flows")
+
+ pylab.subplots_adjust(hspace=0.4)
+ pylab.savefig("results.pdf")
+ #pylab.show()
+
+if __name__ == '__main__':
+ main()