author | Tom Henderson <tomh@tomh.org> |
Fri, 20 Aug 2010 12:17:19 -0700 | |
changeset 6589 | 9c325569fb01 |
parent 6543 | c4a419fce478 |
permissions | -rw-r--r-- |
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") |
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
47 |
wifiMac.SetType ("ns3::AdhocWifiMac", "Ssid", ns3.SsidValue(ssid)) |
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
48 |
|
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
49 |
internet = ns3.InternetStackHelper() |
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
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
|
55 |
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
|
56 |
|
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
57 |
ipv4Addresses = ns3.Ipv4AddressHelper() |
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
58 |
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
|
59 |
|
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
60 |
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
|
61 |
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
|
62 |
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
|
63 |
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
|
64 |
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
|
65 |
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
|
66 |
|
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
67 |
addresses = [] |
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
68 |
nodes = [] |
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
69 |
|
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
70 |
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
|
71 |
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
|
72 |
else: |
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
73 |
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
|
74 |
|
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
75 |
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
|
76 |
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
|
77 |
|
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
78 |
node = ns3.Node() |
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
79 |
nodes.append(node) |
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
80 |
|
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
81 |
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
|
82 |
|
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
83 |
mobility = ns3.ConstantPositionMobilityModel() |
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
84 |
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
|
85 |
node.AggregateObject(mobility) |
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
86 |
|
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
87 |
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
|
88 |
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
|
89 |
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
|
90 |
|
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
91 |
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
|
92 |
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
|
93 |
#print i, destaddr |
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
94 |
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
|
95 |
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
|
96 |
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
|
97 |
|
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
98 |
#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
|
99 |
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
|
100 |
#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
|
101 |
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
|
102 |
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
|
103 |
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
|
104 |
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
|
105 |
|
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
106 |
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
|
107 |
ns3.Simulator.Run() |
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
108 |
|
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
109 |
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
|
110 |
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
|
111 |
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
|
112 |
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
|
113 |
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
|
114 |
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
|
115 |
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
|
116 |
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
|
117 |
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
|
118 |
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
|
119 |
|
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
120 |
if 0: |
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
121 |
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
|
122 |
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
|
123 |
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
|
124 |
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
|
125 |
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
|
126 |
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
|
127 |
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
|
128 |
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
|
129 |
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
|
130 |
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
|
131 |
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
|
132 |
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
|
133 |
|
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
134 |
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
|
135 |
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
|
136 |
#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
|
137 |
# 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
|
138 |
|
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
139 |
monitor.CheckForLostPackets() |
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
140 |
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
|
141 |
|
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
142 |
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
|
143 |
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
|
144 |
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
|
145 |
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
|
146 |
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
|
147 |
(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
|
148 |
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
|
149 |
else: |
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
150 |
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
|
151 |
|
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 |
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
|
154 |
import pylab |
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
155 |
delays = [] |
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
156 |
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
|
157 |
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
|
158 |
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
|
159 |
continue |
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
160 |
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
|
161 |
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
|
162 |
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
|
163 |
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
|
164 |
pylab.show() |
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
165 |
|
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
166 |
return 0 |
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
167 |
|
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 |
if __name__ == '__main__': |
d6bbde9c6712
Add an example with Wifi, OLSR, and Flow Monitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
170 |
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
|
171 |