Add a wifi-adhoc/olsr scenario as basis for the flow monitor demonstration
authorGustavo J. A. M. Carneiro <gjc@inescporto.pt>
Tue Apr 28 18:59:13 2009 +0100 (9 months ago)
changeset 3927dce929afa491
parent 3926 c791fdb74629
child 3928 fedfd2d1c9d0
Add a wifi-adhoc/olsr scenario as basis for the flow monitor demonstration
examples/flowmon.py
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/examples/flowmon.py	Tue Apr 28 18:59:13 2009 +0100
     1.3 @@ -0,0 +1,86 @@
     1.4 +# -*-  Mode: Python; -*-
     1.5 +#  Copyright (c) 2009 INESC Porto
     1.6 +# 
     1.7 +#  This program is free software; you can redistribute it and/or modify
     1.8 +#  it under the terms of the GNU General Public License version 2 as
     1.9 +#  published by the Free Software Foundation;
    1.10 +# 
    1.11 +#  This program is distributed in the hope that it will be useful,
    1.12 +#  but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.13 +#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.14 +#  GNU General Public License for more details.
    1.15 +# 
    1.16 +#  You should have received a copy of the GNU General Public License
    1.17 +#  along with this program; if not, write to the Free Software
    1.18 +#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.19 +# 
    1.20 +#  Authors: Gustavo Carneiro <gjc@inescporto.pt>
    1.21 +
    1.22 +import sys
    1.23 +import ns3
    1.24 +import visualizer
    1.25 +
    1.26 +DISTANCE = 150 # (m)
    1.27 +NUM_NODES_SIDE = 3
    1.28 +
    1.29 +def main(argv):
    1.30 +
    1.31 +    ns3.RandomVariable.UseGlobalSeed(1, 1, 2, 3, 5, 8)
    1.32 +
    1.33 +    #ns3.Config.SetDefault("ns3::Ipv4L3Protocol::CalcChecksum", ns3.BooleanValue(True))
    1.34 +
    1.35 +    channel = ns3.WifiChannel()
    1.36 +    channel.SetPropagationDelayModel(ns3.ConstantSpeedPropagationDelayModel())
    1.37 +    log = ns3.LogDistancePropagationLossModel()
    1.38 +    log.SetReferenceModel(ns3.FriisPropagationLossModel())
    1.39 +    channel.SetPropagationLossModel(log)
    1.40 +
    1.41 +    wifi = ns3.WifiHelper()
    1.42 +    wifi.SetMac("ns3::AdhocWifiMac")
    1.43 +    wifi.SetPhy("ns3::WifiPhy");
    1.44 +    wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
    1.45 +
    1.46 +    internet = ns3.InternetStackHelper()
    1.47 +    ipv4Addresses = ns3.Ipv4AddressHelper()
    1.48 +    ipv4Addresses.SetBase(ns3.Ipv4Address("10.0.0.0"), ns3.Ipv4Mask("255.255.255.255"))
    1.49 +    
    1.50 +    olsrHelper = ns3.OlsrHelper()
    1.51 +
    1.52 +    port = 9   # Discard port(RFC 863)
    1.53 +    onOffHelper = ns3.OnOffHelper("ns3::UdpSocketFactory",
    1.54 +                                  ns3.Address(ns3.InetSocketAddress(ns3.Ipv4Address("10.0.0.1"), port)))
    1.55 +    onOffHelper.SetAttribute("OnTime", ns3.RandomVariableValue(ns3.ConstantVariable(1)))
    1.56 +    onOffHelper.SetAttribute("OffTime", ns3.RandomVariableValue(ns3.ConstantVariable(0)))
    1.57 +
    1.58 +
    1.59 +    for xi in range(NUM_NODES_SIDE):
    1.60 +        for yi in range(NUM_NODES_SIDE):
    1.61 +
    1.62 +            node = ns3.Node()
    1.63 +            internet.Install(ns3.NodeContainer(node))
    1.64 +
    1.65 +            mobility = ns3.StaticMobilityModel()
    1.66 +            mobility.SetPosition(ns3.Vector(xi*DISTANCE, yi*DISTANCE, 0))
    1.67 +            node.AggregateObject(mobility)
    1.68 +            
    1.69 +            devices = wifi.Install(ns3.NodeContainer(node), channel)
    1.70 +            ipv4Addresses.Assign(devices)
    1.71 +            
    1.72 +            olsrHelper.Install(ns3.NodeContainer(node))
    1.73 +
    1.74 +            if xi > 0 or yi > 0:
    1.75 +                app = onOffHelper.Install(ns3.NodeContainer(node))
    1.76 +                app.Start(ns3.Seconds(ns3.UniformVariable(20, 30).GetValue()))
    1.77 +            
    1.78 +    internet.EnablePcapAll("wifi-olsr")
    1.79 +
    1.80 +    ns3.Simulator.Stop(ns3.Seconds(44.0))
    1.81 +    visualizer.start()
    1.82 +    #ns3.Simulator.Run()
    1.83 +
    1.84 +    return 0
    1.85 +
    1.86 +
    1.87 +if __name__ == '__main__':
    1.88 +    sys.exit(main(sys.argv))
    1.89 +