Enable the flow monitor on all nodes.
authorGustavo J. A. M. Carneiro <gjc@inescporto.pt>
Wed Apr 29 15:27:15 2009 +0100 (9 months ago)
changeset 393475ef91d7fc6f
parent 3933 b4f9526aa79d
child 3935 005a03574784
Enable the flow monitor on all nodes.
examples/flowmon.py
     1.1 --- a/examples/flowmon.py	Wed Apr 29 15:26:51 2009 +0100
     1.2 +++ b/examples/flowmon.py	Wed Apr 29 15:27:15 2009 +0100
     1.3 @@ -74,16 +74,33 @@
     1.4  
     1.5      for i, node in enumerate(nodes):
     1.6          destaddr = addresses[(len(addresses) - 1 - i) % len(addresses)]
     1.7 -        print i, destaddr
     1.8 +        #print i, destaddr
     1.9          onOffHelper.SetAttribute("Remote", ns3.AddressValue(ns3.InetSocketAddress(destaddr, port)))
    1.10          app = onOffHelper.Install(ns3.NodeContainer(node))
    1.11          app.Start(ns3.Seconds(ns3.UniformVariable(20, 30).GetValue()))
    1.12              
    1.13      #internet.EnablePcapAll("wifi-olsr")
    1.14 +    flowmon_helper = ns3.FlowMonitorHelper()
    1.15 +    monitor = flowmon_helper.InstallAll()
    1.16  
    1.17      ns3.Simulator.Stop(ns3.Seconds(44.0))
    1.18 -    visualizer.start()
    1.19 -    #ns3.Simulator.Run()
    1.20 +    #visualizer.start()
    1.21 +    ns3.Simulator.Run()
    1.22 +
    1.23 +    def print_stats(os, st):
    1.24 +        print >> os, "  Tx Bytes: ", st.txBytes
    1.25 +        print >> os, "  Rx Bytes: ", st.rxBytes
    1.26 +        print >> os, "  Tx Packets: ", st.txPackets
    1.27 +        print >> os, "  Rx Packets: ", st.rxPackets
    1.28 +        print >> os, "  Lost Packets: ", st.lostPackets
    1.29 +        if st.rxPackets > 0:
    1.30 +            print >> os, "  Mean(Delay): ", (st.delaySum.GetSeconds() / st.rxPackets)
    1.31 +            print >> os, "  Mean(Hop Count): ", float(st.timesForwarded) / st.rxPackets + 1
    1.32 +
    1.33 +    monitor.CheckForLostPackets()
    1.34 +    for flow_id, flow_stats in monitor.GetFlowStats():
    1.35 +        print "FlowID: ", flow_id
    1.36 +        print_stats(sys.stdout, flow_stats)        
    1.37  
    1.38      return 0
    1.39