LEFT | RIGHT |
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2008,2009 IITP RAS | 3 * Copyright (c) 2008,2009 IITP RAS |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 #include "ns3/core-module.h" | 22 #include "ns3/core-module.h" |
23 #include "ns3/simulator-module.h" | 23 #include "ns3/simulator-module.h" |
24 #include "ns3/node-module.h" | 24 #include "ns3/node-module.h" |
25 #include "ns3/helper-module.h" | 25 #include "ns3/helper-module.h" |
26 #include "ns3/global-routing-module.h" | 26 #include "ns3/global-routing-module.h" |
27 #include "ns3/wifi-module.h" | 27 #include "ns3/wifi-module.h" |
28 #include "ns3/mesh-module.h" | 28 #include "ns3/mesh-module.h" |
29 #include "ns3/mobility-module.h" | 29 #include "ns3/mobility-module.h" |
30 #include "ns3/mesh-helper.h" | 30 #include "ns3/mesh-helper.h" |
31 #include "ns3/mesh-interface-helper.h" | |
32 | 31 |
33 #include <iostream> | 32 #include <iostream> |
34 #include <sstream> | 33 #include <sstream> |
35 #include <fstream> | 34 #include <fstream> |
36 | 35 |
37 using namespace ns3; | 36 using namespace ns3; |
38 | 37 |
39 NS_LOG_COMPONENT_DEFINE ("TestMeshScript"); | 38 NS_LOG_COMPONENT_DEFINE ("TestMeshScript"); |
40 class MeshTest | 39 class MeshTest |
41 { | 40 { |
42 public: | 41 public: |
43 /// Init test | 42 /// Init test |
44 MeshTest (); | 43 MeshTest (); |
45 /// Configure test from command line arguments | 44 /// Configure test from command line arguments |
46 void Configure (int argc, char ** argv); | 45 void Configure (int argc, char ** argv); |
47 /// Run test | 46 /// Run test |
48 int Run (); | 47 int Run (); |
49 private: | 48 private: |
50 int xSize; | 49 int m_xSize; |
51 int ySize; | 50 int m_ySize; |
52 double step; | 51 double m_step; |
53 double randomStart; | 52 double m_randomStart; |
54 double totalTime; | 53 double m_totalTime; |
55 double packetInterval; | 54 double m_packetInterval; |
56 uint16_t packetSize; | 55 uint16_t m_packetSize; |
57 uint32_t nIfaces; | 56 uint32_t m_nIfaces; |
58 bool chan; | 57 bool m_chan; |
59 bool pcap; | 58 bool m_pcap; |
60 uint64_t seed; | 59 std::string m_stack; |
61 std::string stack; | 60 std::string m_root; |
62 /// List of network nodes | 61 /// List of network nodes |
63 NodeContainer nodes; | 62 NodeContainer nodes; |
64 /// List of all mesh point devices | 63 /// List of all mesh point devices |
65 NetDeviceContainer meshDevices; | 64 NetDeviceContainer meshDevices; |
66 //Addresses of interfaces: | 65 //Addresses of interfaces: |
67 Ipv4InterfaceContainer interfaces; | 66 Ipv4InterfaceContainer interfaces; |
68 // MeshHelper. Report is not static methods | 67 // MeshHelper. Report is not static methods |
69 MeshHelper mesh; | 68 MeshHelper mesh; |
70 private: | 69 private: |
71 /// Create nodes and setup their mobility | 70 /// Create nodes and setup their mobility |
72 void CreateNodes (); | 71 void CreateNodes (); |
73 /// Install internet stack on nodes | 72 /// Install internet m_stack on nodes |
74 void InstallInternetStack (); | 73 void InstallInternetStack (); |
75 /// Install applications | 74 /// Install applications |
76 void InstallApplication (); | 75 void InstallApplication (); |
77 /// Print mesh devices diagnostics | 76 /// Print mesh devices diagnostics |
78 void Report ();·· | 77 void Report ();·· |
79 }; | 78 }; |
80 MeshTest::MeshTest () : | 79 MeshTest::MeshTest () : |
81 xSize (3), | 80 m_xSize (3), |
82 ySize (3), | 81 m_ySize (3), |
83 step (100.0), | 82 m_step (100.0), |
84 randomStart (0.1), | 83 m_randomStart (0.1), |
85 totalTime (100.0), | 84 m_totalTime (100.0), |
86 packetInterval (0.1), | 85 m_packetInterval (0.1), |
87 packetSize (1024), | 86 m_packetSize (1024), |
88 nIfaces (1), | 87 m_nIfaces (1), |
89 chan (true), | 88 m_chan (true), |
90 pcap (false), | 89 m_pcap (false), |
91 seed (1), | 90 m_stack ("ns3::Dot11sStack"), |
92 stack ("ns3::Dot11sStack") | 91 m_root ("ff:ff:ff:ff:ff:ff") |
93 { | 92 { |
94 } | 93 } |
95 void | 94 void |
96 MeshTest::Configure (int argc, char *argv[]) | 95 MeshTest::Configure (int argc, char *argv[]) |
97 { | 96 { |
98 CommandLine cmd; | 97 CommandLine cmd; |
99 cmd.AddValue ("x-size", "Number of nodes in a row grid. [6]", xSize); | 98 cmd.AddValue ("x-size", "Number of nodes in a row grid. [6]", m_xSize); |
100 cmd.AddValue ("y-size", "Number of rows in a grid. [6]", ySize); | 99 cmd.AddValue ("y-size", "Number of rows in a grid. [6]", m_ySize); |
101 cmd.AddValue ("step", "Size of edge in our grid, meters. [100 m]", step); | 100 cmd.AddValue ("m_step", "Size of edge in our grid, meters. [100 m]", m_step)
; |
102 cmd.AddValue ("start", "Maximum random start delay, seconds. [0.1 s]", random
Start); | 101 cmd.AddValue ("start", "Maximum random start delay, seconds. [0.1 s]", m_rand
omStart); |
103 cmd.AddValue ("time", "Simulation time, seconds [100 s]", totalTime); | 102 cmd.AddValue ("time", "Simulation time, seconds [100 s]", m_totalTime); |
104 cmd.AddValue ("packet-interval", "Interval between packets, seconds [0.001 s]
", packetInterval); | 103 cmd.AddValue ("packet-interval", "Interval between packets, seconds [0.001 s]
", m_packetInterval); |
105 cmd.AddValue ("packet-size", "Size of packets", packetSize); | 104 cmd.AddValue ("packet-size", "Size of packets", m_packetSize); |
106 cmd.AddValue ("interfaces", "Number of radio interfaces used by each mesh poin
t. [1]", nIfaces); | 105 cmd.AddValue ("interfaces", "Number of radio interfaces used by each mesh poin
t. [1]", m_nIfaces); |
107 cmd.AddValue ("channels", "Use different frequency channels for different in
terfaces. [0]", chan); | 106 cmd.AddValue ("m_channels", "Use different frequency m_channels for differen
t interfaces. [0]", m_chan); |
108 cmd.AddValue ("pcap", "Enable PCAP traces on interfaces. [0]", pcap); | 107 cmd.AddValue ("m_pcap", "Enable PCAP traces on interfaces. [0]", m_pcap); |
109 cmd.AddValue ("seed", "Seed value", seed); | 108 cmd.AddValue ("m_stack", "Type of protocol m_stack. ns3::Dot11sStack by defau
lt", m_stack); |
110 cmd.AddValue ("stack", "Type of protocol stack. ns3::Dot11sStack by default",
stack); | 109 cmd.AddValue ("m_root", "Mac address of m_root mesh point", m_root); |
111 ·· | 110 ·· |
112 cmd.Parse (argc, argv); | 111 cmd.Parse (argc, argv); |
113 NS_LOG_DEBUG ("Grid:" << xSize << "*" << ySize); | 112 NS_LOG_DEBUG ("Grid:" << m_xSize << "*" << m_ySize); |
114 NS_LOG_DEBUG ("Simulation time: " << totalTime << " s"); | 113 NS_LOG_DEBUG ("Simulation time: " << m_totalTime << " s"); |
115 SeedManager::SetSeed(seed); | |
116 } | 114 } |
117 void | 115 void |
118 MeshTest::CreateNodes () | 116 MeshTest::CreateNodes () |
119 {· | 117 {· |
120 nodes.Create (ySize*xSize); | 118 nodes.Create (m_ySize*m_xSize); |
121 // Setting channel | 119 // Setting m_channel |
122 YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); | 120 YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); |
123 YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); | 121 YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); |
124 wifiPhy.SetChannel (wifiChannel.Create ()); | 122 wifiPhy.SetChannel (wifiChannel.Create ()); |
| 123 mesh = MeshHelper::Default (); |
125 // Install mesh point devices & protocols | 124 // Install mesh point devices & protocols |
126 mesh.SetStackInstaller (stack); | 125 mesh.SetStackInstaller (m_stack, "Root", Mac48AddressValue (Mac48Address (m_ro
ot.c_str ()))); |
127 mesh.SetSpreadInterfaceChannels (chan); | 126 if (m_chan) |
128 MeshInterfaceHelper interface = MeshInterfaceHelper::Default (); | 127 { |
129 interface.SetType ("RandomStart", TimeValue (Seconds(randomStart))); | 128 mesh.SetSpreadInterfaceChannels (MeshHelper::SPREAD_CHANNELS); |
130 | 129 } |
131 meshDevices = mesh.Install (wifiPhy, interface, nodes, nIfaces); | 130 else |
| 131 { |
| 132 mesh.SetSpreadInterfaceChannels (MeshHelper::ZERO_CHANNEL); |
| 133 } |
| 134 //MeshInterfaceHelper interface = MeshInterfaceHelper::Default (); |
| 135 mesh.SetMacType ("RandomStart", TimeValue (Seconds(m_randomStart))); |
| 136 mesh.SetNumberOfInterfaces (m_nIfaces); |
| 137 meshDevices = mesh.Install (wifiPhy, nodes); |
132 // Setup mobility | 138 // Setup mobility |
133 MobilityHelper mobility; | 139 MobilityHelper mobility; |
134 mobility.SetPositionAllocator ("ns3::GridPositionAllocator", | 140 mobility.SetPositionAllocator ("ns3::GridPositionAllocator", |
135 "MinX", DoubleValue (0.0), | 141 "MinX", DoubleValue (0.0), |
136 "MinY", DoubleValue (0.0), | 142 "MinY", DoubleValue (0.0), |
137 "DeltaX", DoubleValue (step), | 143 "DeltaX", DoubleValue (m_step), |
138 "DeltaY", DoubleValue (step), | 144 "DeltaY", DoubleValue (m_step), |
139 "GridWidth", UintegerValue (xSize), | 145 "GridWidth", UintegerValue (m_xSize), |
140 "LayoutType", StringValue ("RowFirst")); | 146 "LayoutType", StringValue ("RowFirst")); |
141 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); | 147 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); |
142 mobility.Install (nodes); | 148 mobility.Install (nodes); |
143 if (pcap) | 149 if (m_pcap) |
144 wifiPhy.EnablePcapAll (std::string ("mp-")); | 150 wifiPhy.EnablePcapAll (std::string ("mp-")); |
145 } | 151 } |
146 void | 152 void |
147 MeshTest::InstallInternetStack () | 153 MeshTest::InstallInternetStack () |
148 { | 154 { |
149 InternetStackHelper stack; | 155 InternetStackHelper m_stack; |
150 stack.Install (nodes); | 156 m_stack.Install (nodes); |
151 Ipv4AddressHelper address; | 157 Ipv4AddressHelper address; |
152 address.SetBase ("10.1.1.0", "255.255.255.0"); | 158 address.SetBase ("10.1.1.0", "255.255.255.0"); |
153 interfaces = address.Assign (meshDevices); | 159 interfaces = address.Assign (meshDevices); |
154 } | 160 } |
155 void | 161 void |
156 MeshTest::InstallApplication () | 162 MeshTest::InstallApplication () |
157 { | 163 { |
158 UdpEchoServerHelper echoServer (9); | 164 UdpEchoServerHelper echoServer (9); |
159 ApplicationContainer serverApps = echoServer.Install (nodes.Get (0)); | 165 ApplicationContainer serverApps = echoServer.Install (nodes.Get (0)); |
160 serverApps.Start (Seconds (0.0)); | 166 serverApps.Start (Seconds (0.0)); |
161 serverApps.Stop (Seconds (totalTime)); | 167 serverApps.Stop (Seconds (m_totalTime)); |
162 UdpEchoClientHelper echoClient (interfaces.GetAddress (0), 9); | 168 UdpEchoClientHelper echoClient (interfaces.GetAddress (0), 9); |
163 echoClient.SetAttribute ("MaxPackets", UintegerValue ((uint32_t)(totalTime*(1/
packetInterval)))); | 169 echoClient.SetAttribute ("MaxPackets", UintegerValue ((uint32_t)(m_totalTime*(
1/m_packetInterval)))); |
164 echoClient.SetAttribute ("Interval", TimeValue (Seconds (packetInterval))); | 170 echoClient.SetAttribute ("Interval", TimeValue (Seconds (m_packetInterval))); |
165 echoClient.SetAttribute ("PacketSize", UintegerValue (packetSize)); | 171 echoClient.SetAttribute ("PacketSize", UintegerValue (m_packetSize)); |
166 ApplicationContainer clientApps = echoClient.Install (nodes.Get (xSize*ySize-1
)); | 172 ApplicationContainer clientApps = echoClient.Install (nodes.Get (m_xSize*m_ySi
ze-1)); |
167 clientApps.Start (Seconds (0.0)); | 173 clientApps.Start (Seconds (0.0)); |
168 clientApps.Stop (Seconds (totalTime)); | 174 clientApps.Stop (Seconds (m_totalTime)); |
169 } | 175 } |
170 int | 176 int |
171 MeshTest::Run () | 177 MeshTest::Run () |
172 { | 178 { |
173 CreateNodes (); | 179 CreateNodes (); |
174 InstallInternetStack (); | 180 InstallInternetStack (); |
175 InstallApplication (); | 181 InstallApplication (); |
176 Simulator::Schedule (Seconds(totalTime), & MeshTest::Report, this); | 182 Simulator::Schedule (Seconds(m_totalTime), & MeshTest::Report, this); |
177 Simulator::Stop (Seconds (totalTime)); | 183 Simulator::Stop (Seconds (m_totalTime)); |
178 Simulator::Run (); | 184 Simulator::Run (); |
179 Simulator::Destroy (); | 185 Simulator::Destroy (); |
180 return 0; | 186 return 0; |
181 } | 187 } |
182 void | 188 void |
183 MeshTest::Report () | 189 MeshTest::Report () |
184 { | 190 { |
185 NS_LOG_UNCOND("Report is here:"); | |
186 unsigned n (0); | 191 unsigned n (0); |
187 for (NetDeviceContainer::Iterator i = meshDevices.Begin (); i != meshDevices.E
nd (); ++i, ++n) | 192 for (NetDeviceContainer::Iterator i = meshDevices.Begin (); i != meshDevices.E
nd (); ++i, ++n) |
188 { | 193 { |
189 std::ostringstream os; | 194 std::ostringstream os; |
190 os << "mp-report-" << n << ".xml"; | 195 os << "mp-report-" << n << ".xml"; |
191 std::cerr << "Printing mesh point device #" << n << " diagnostics to " << os
.str () << "\n"; | 196 std::cerr << "Printing mesh point device #" << n << " diagnostics to " << os
.str () << "\n"; |
192 std::ofstream of; | 197 std::ofstream of; |
193 of.open (os.str().c_str()); | 198 of.open (os.str().c_str()); |
194 if (! of.is_open ()) | 199 if (! of.is_open ()) |
195 { | 200 { |
196 std::cerr << "Error: Can't open file " << os.str() << "\n"; | 201 std::cerr << "Error: Can't open file " << os.str() << "\n"; |
197 return; | 202 return; |
198 } | 203 } |
199 mesh.Report (*i, of); | 204 mesh.Report (*i, of); |
200 of.close (); | 205 of.close (); |
201 } | 206 } |
202 } | 207 } |
203 int | 208 int |
204 main (int argc, char *argv[]) | 209 main (int argc, char *argv[]) |
205 { | 210 { |
206 MeshTest t;· | 211 MeshTest t;· |
207 t.Configure (argc, argv); | 212 t.Configure (argc, argv); |
208 return t.Run(); | 213 return t.Run(); |
209 } | 214 } |
LEFT | RIGHT |