Add script to plot flowmon example results
authorGustavo J. A. M. Carneiro <gjc@inescporto.pt>
Tue May 19 18:01:40 2009 +0100 (8 months ago)
changeset 39854d15f24f643f
parent 3984 3bf1e5377c98
child 3986 cf958e02874c
Add script to plot flowmon example results
examples/flowmon-plot.py
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/examples/flowmon-plot.py	Tue May 19 18:01:40 2009 +0100
     1.3 @@ -0,0 +1,58 @@
     1.4 +import sys
     1.5 +import pylab
     1.6 +try:    
     1.7 +    from xml.etree import cElementTree as ElementTree
     1.8 +except ImportError:
     1.9 +    from xml.etree import ElementTree
    1.10 +
    1.11 +def parse_time(s):
    1.12 +    assert s.endswidth('ns')
    1.13 +    return ns3.Nano
    1.14 +
    1.15 +def main():
    1.16 +    et = ElementTree.parse(sys.argv[1])
    1.17 +    bitrates = []
    1.18 +    losses = []
    1.19 +    delays = []
    1.20 +    for flow in et.findall("FlowStats/Flow"):
    1.21 +        # filter out OLSR
    1.22 +        for five_tuple in et.findall("Ipv4FlowClassifier/Flow"):
    1.23 +            if five_tuple.get('flowId') == flow.get('flowId'):
    1.24 +                break
    1.25 +        if five_tuple.get("destinationPort") == '698':
    1.26 +            continue
    1.27 +
    1.28 +        losses.append(int(flow.get('lostPackets')))
    1.29 +
    1.30 +        rxPackets = int(flow.get('rxPackets'))
    1.31 +        if rxPackets == 0:
    1.32 +            bitrates.append(0)
    1.33 +        else:
    1.34 +            t0 = long(flow.get('timeFirstRxPacket')[:-2])
    1.35 +            t1 = long(flow.get('timeLastRxPacket')[:-2])
    1.36 +            duration = (t1 - t0)*1e-9 # duration in seconds
    1.37 +            bitrates.append(8*long(flow.get('rxBytes')) / duration * 1e-3)
    1.38 +
    1.39 +            delays.append((float(flow.get('delaySum')[:-2])*1e-9) / rxPackets)
    1.40 +
    1.41 +    pylab.subplot(311)
    1.42 +    pylab.hist(bitrates, bins=40)
    1.43 +    pylab.xlabel("Flow bitrate (bit/s)")
    1.44 +    pylab.ylabel("Number of flows")
    1.45 +
    1.46 +    pylab.subplot(312)
    1.47 +    pylab.hist(losses, bins=40)
    1.48 +    pylab.xlabel("Number of lost packets")
    1.49 +    pylab.ylabel("Number of flows")
    1.50 +
    1.51 +    pylab.subplot(313)
    1.52 +    pylab.hist(delays, bins=10)
    1.53 +    pylab.xlabel("Delay (s)")
    1.54 +    pylab.ylabel("Number of flows")
    1.55 +
    1.56 +    pylab.subplots_adjust(hspace=0.4)
    1.57 +    pylab.savefig("results.pdf")
    1.58 +    #pylab.show()
    1.59 +    
    1.60 +if __name__ == '__main__':
    1.61 +    main()