src/contrib/flow-monitor/examples/wifi-olsr-flowmon.py
author Dean Armstrong <deanarm@gmail.com>
Thu, 02 Dec 2010 07:51:34 +0000
changeset 6673 ec22aa763e2d
parent 6631 2fd8e12e635d
permissions -rw-r--r--
Bug 978: Consolidate Wi-Fi MAC high functionality This change reorganises the Wi-Fi MAC high classes in attempt to reduce duplication of functionality that is required for more than one of the MAC high models. A new class called RegularWifiMac has been created. This derives from the abstract WifiMac, and is parent of AdhocWifiMac, StaWifiMac, ApWifiMac, and MeshWifiInterfaceMac. The QoS and non-QoS class variants are no longer, with a RegularWifiMac attribute "QosSupported" allowing selection between these two modes of operation. QosWifiMacHelper and NqosWifiMacHelper continue to work as previously. Updates to some regression traces are necessary because the reorganisation has led to random number streams being initialised in slightly different orders and thus over-the-air timing changing.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5223
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     1
# -*-  Mode: Python; -*-
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     2
#  Copyright (c) 2009 INESC Porto
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     3
# 
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     4
#  This program is free software; you can redistribute it and/or modify
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     5
#  it under the terms of the GNU General Public License version 2 as
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     6
#  published by the Free Software Foundation;
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     7
# 
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     8
#  This program is distributed in the hope that it will be useful,
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     9
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    10
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    11
#  GNU General Public License for more details.
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    12
# 
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    13
#  You should have received a copy of the GNU General Public License
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    14
#  along with this program; if not, write to the Free Software
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    15
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    16
# 
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    17
#  Authors: Gustavo Carneiro <gjc@inescporto.pt>
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    18
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    19
import sys
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    20
import ns3
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    21
6543
c4a419fce478 Bring nodes close together, due to changes in ns-3.9 that bring reduced wifi range
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5369
diff changeset
    22
DISTANCE = 100 # (m)
5223
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    23
NUM_NODES_SIDE = 3
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    24
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    25
def main(argv):
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    26
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    27
    cmd = ns3.CommandLine()
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    28
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    29
    cmd.NumNodesSide = None
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    30
    cmd.AddValue("NumNodesSide", "Grid side number of nodes (total number of nodes will be this number squared)")
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    31
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    32
    cmd.Results = None
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    33
    cmd.AddValue("Results", "Write XML results to file")
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    34
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    35
    cmd.Plot = None
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    36
    cmd.AddValue("Plot", "Plot the results using the matplotlib python module")
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    37
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    38
    cmd.Parse(argv)
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    39
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    40
    wifi = ns3.WifiHelper.Default()
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    41
    wifiMac = ns3.NqosWifiMacHelper.Default()
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    42
    wifiPhy = ns3.YansWifiPhyHelper.Default()
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    43
    wifiChannel = ns3.YansWifiChannelHelper.Default()
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    44
    wifiPhy.SetChannel(wifiChannel.Create())
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    45
    ssid = ns3.Ssid("wifi-default")
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    46
    wifi.SetRemoteStationManager("ns3::ArfWifiManager")
6673
ec22aa763e2d Bug 978: Consolidate Wi-Fi MAC high functionality
Dean Armstrong <deanarm@gmail.com>
parents: 6631
diff changeset
    47
    wifiMac.SetType ("ns3::AdhocWifiMac",
ec22aa763e2d Bug 978: Consolidate Wi-Fi MAC high functionality
Dean Armstrong <deanarm@gmail.com>
parents: 6631
diff changeset
    48
                     "Ssid", ns3.SsidValue(ssid))
5223
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    49
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    50
    internet = ns3.InternetStackHelper()
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    51
    list_routing = ns3.Ipv4ListRoutingHelper()
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    52
    olsr_routing = ns3.OlsrHelper()
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    53
    static_routing = ns3.Ipv4StaticRoutingHelper()
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    54
    list_routing.Add(static_routing, 0)
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    55
    list_routing.Add(olsr_routing, 100)
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    56
    internet.SetRoutingHelper(list_routing)
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    57
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    58
    ipv4Addresses = ns3.Ipv4AddressHelper()
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    59
    ipv4Addresses.SetBase(ns3.Ipv4Address("10.0.0.0"), ns3.Ipv4Mask("255.255.255.0"))
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    60
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    61
    port = 9   # Discard port(RFC 863)
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    62
    onOffHelper = ns3.OnOffHelper("ns3::UdpSocketFactory",
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    63
                                  ns3.Address(ns3.InetSocketAddress(ns3.Ipv4Address("10.0.0.1"), port)))
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    64
    onOffHelper.SetAttribute("DataRate", ns3.DataRateValue(ns3.DataRate("100kbps")))
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    65
    onOffHelper.SetAttribute("OnTime", ns3.RandomVariableValue(ns3.ConstantVariable(1)))
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    66
    onOffHelper.SetAttribute("OffTime", ns3.RandomVariableValue(ns3.ConstantVariable(0)))
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    67
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    68
    addresses = []
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    69
    nodes = []
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    70
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    71
    if cmd.NumNodesSide is None:
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    72
        num_nodes_side = NUM_NODES_SIDE
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    73
    else:
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    74
        num_nodes_side = int(cmd.NumNodesSide)
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    75
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    76
    for xi in range(num_nodes_side):
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    77
        for yi in range(num_nodes_side):
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    78
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    79
            node = ns3.Node()
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    80
            nodes.append(node)
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    81
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    82
            internet.Install(ns3.NodeContainer(node))
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    83
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    84
            mobility = ns3.ConstantPositionMobilityModel()
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    85
            mobility.SetPosition(ns3.Vector(xi*DISTANCE, yi*DISTANCE, 0))
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    86
            node.AggregateObject(mobility)
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    87
            
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    88
            devices = wifi.Install(wifiPhy, wifiMac, node)
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    89
            ipv4_interfaces = ipv4Addresses.Assign(devices)
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    90
            addresses.append(ipv4_interfaces.GetAddress(0))
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    91
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    92
    for i, node in enumerate(nodes):
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    93
        destaddr = addresses[(len(addresses) - 1 - i) % len(addresses)]
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    94
        #print i, destaddr
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    95
        onOffHelper.SetAttribute("Remote", ns3.AddressValue(ns3.InetSocketAddress(destaddr, port)))
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    96
        app = onOffHelper.Install(ns3.NodeContainer(node))
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    97
        app.Start(ns3.Seconds(ns3.UniformVariable(20, 30).GetValue()))
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    98
            
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    99
    #internet.EnablePcapAll("wifi-olsr")
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   100
    flowmon_helper = ns3.FlowMonitorHelper()
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   101
    #flowmon_helper.SetMonitorAttribute("StartTime", ns3.TimeValue(ns3.Seconds(31)))
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   102
    monitor = flowmon_helper.InstallAll()
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   103
    monitor.SetAttribute("DelayBinWidth", ns3.DoubleValue(0.001))
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   104
    monitor.SetAttribute("JitterBinWidth", ns3.DoubleValue(0.001))
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   105
    monitor.SetAttribute("PacketSizeBinWidth", ns3.DoubleValue(20))
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   106
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   107
    ns3.Simulator.Stop(ns3.Seconds(44.0))
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   108
    ns3.Simulator.Run()
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   109
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   110
    def print_stats(os, st):
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   111
        print >> os, "  Tx Bytes: ", st.txBytes
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   112
        print >> os, "  Rx Bytes: ", st.rxBytes
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   113
        print >> os, "  Tx Packets: ", st.txPackets
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   114
        print >> os, "  Rx Packets: ", st.rxPackets
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   115
        print >> os, "  Lost Packets: ", st.lostPackets
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   116
        if st.rxPackets > 0:
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   117
            print >> os, "  Mean{Delay}: ", (st.delaySum.GetSeconds() / st.rxPackets)
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   118
	    print >> os, "  Mean{Jitter}: ", (st.jitterSum.GetSeconds() / (st.rxPackets-1))
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   119
            print >> os, "  Mean{Hop Count}: ", float(st.timesForwarded) / st.rxPackets + 1
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   120
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   121
        if 0:
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   122
            print >> os, "Delay Histogram"
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   123
            for i in range(st.delayHistogram.GetNBins () ):
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   124
              print >> os, " ",i,"(", st.delayHistogram.GetBinStart (i), "-", \
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   125
                  st.delayHistogram.GetBinEnd (i), "): ", st.delayHistogram.GetBinCount (i)
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   126
            print >> os, "Jitter Histogram"
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   127
            for i in range(st.jitterHistogram.GetNBins () ):
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   128
              print >> os, " ",i,"(", st.jitterHistogram.GetBinStart (i), "-", \
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   129
                  st.jitterHistogram.GetBinEnd (i), "): ", st.jitterHistogram.GetBinCount (i)
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   130
            print >> os, "PacketSize Histogram"
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   131
            for i in range(st.packetSizeHistogram.GetNBins () ):
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   132
              print >> os, " ",i,"(", st.packetSizeHistogram.GetBinStart (i), "-", \
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   133
                  st.packetSizeHistogram.GetBinEnd (i), "): ", st.packetSizeHistogram.GetBinCount (i)
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   134
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   135
        for reason, drops in enumerate(st.packetsDropped):
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   136
            print "  Packets dropped by reason %i: %i" % (reason, drops)
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   137
        #for reason, drops in enumerate(st.bytesDropped):
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   138
        #    print "Bytes dropped by reason %i: %i" % (reason, drops)
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   139
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   140
    monitor.CheckForLostPackets()
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   141
    classifier = flowmon_helper.GetClassifier()
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   142
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   143
    if cmd.Results is None:
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   144
        for flow_id, flow_stats in monitor.GetFlowStats():
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   145
            t = classifier.FindFlow(flow_id)
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   146
            proto = {6: 'TCP', 17: 'UDP'} [t.protocol]
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   147
            print "FlowID: %i (%s %s/%s --> %s/%i)" % \
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   148
                (flow_id, proto, t.sourceAddress, t.sourcePort, t.destinationAddress, t.destinationPort)
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   149
            print_stats(sys.stdout, flow_stats)
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   150
    else:
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   151
        print monitor.SerializeToXmlFile(cmd.Results, True, True)
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   152
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   153
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   154
    if cmd.Plot is not None:
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   155
        import pylab
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   156
        delays = []
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   157
        for flow_id, flow_stats in monitor.GetFlowStats():
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   158
            tupl = classifier.FindFlow(flow_id)
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   159
            if tupl.protocol == 17 and tupl.sourcePort == 698:
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   160
                continue
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   161
            delays.append(flow_stats.delaySum.GetSeconds() / flow_stats.rxPackets)
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   162
        pylab.hist(delays, 20)
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   163
        pylab.xlabel("Delay (s)")
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   164
        pylab.ylabel("Number of Flows")
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   165
        pylab.show()
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   166
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   167
    return 0
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   168
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   169
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   170
if __name__ == '__main__':
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   171
    sys.exit(main(sys.argv))
d6bbde9c6712 Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   172