A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
mesh.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008,2009 IITP RAS
4  *
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
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Kirill Andreev <andreev@iitp.ru>
19  *
20  *
21  * By default this script creates m_xSize * m_ySize square grid topology with
22  * IEEE802.11s stack installed at each node with peering management
23  * and HWMP protocol.
24  * The side of the square cell is defined by m_step parameter.
25  * When topology is created, UDP ping is installed to opposite corners
26  * by diagonals. packet size of the UDP ping and interval between two
27  * successive packets is configurable.
28  *
29  * m_xSize * step
30  * |<--------->|
31  * step
32  * |<--->|
33  * * --- * --- * <---Ping sink _
34  * | \ | / | ^
35  * | \ | / | |
36  * * --- * --- * m_ySize * step |
37  * | / | \ | |
38  * | / | \ | |
39  * * --- * --- * _
40  * ^ Ping source
41  *
42  * See also MeshTest::Configure to read more about configurable
43  * parameters.
44  */
45 
46 
47 #include "ns3/core-module.h"
48 #include "ns3/internet-module.h"
49 #include "ns3/network-module.h"
50 #include "ns3/applications-module.h"
51 #include "ns3/wifi-module.h"
52 #include "ns3/mesh-module.h"
53 #include "ns3/mobility-module.h"
54 #include "ns3/mesh-helper.h"
55 
56 #include <iostream>
57 #include <sstream>
58 #include <fstream>
59 
60 using namespace ns3;
61 
62 NS_LOG_COMPONENT_DEFINE ("TestMeshScript");
63 class MeshTest
64 {
65 public:
67  MeshTest ();
69  void Configure (int argc, char ** argv);
71  int Run ();
72 private:
73  int m_xSize;
74  int m_ySize;
75  double m_step;
76  double m_randomStart;
77  double m_totalTime;
79  uint16_t m_packetSize;
80  uint32_t m_nIfaces;
81  bool m_chan;
82  bool m_pcap;
83  std::string m_stack;
84  std::string m_root;
89  //Addresses of interfaces:
91  // MeshHelper. Report is not static methods
93 private:
95  void CreateNodes ();
97  void InstallInternetStack ();
99  void InstallApplication ();
101  void Report ();
102 };
104  m_xSize (3),
105  m_ySize (3),
106  m_step (100.0),
107  m_randomStart (0.1),
108  m_totalTime (100.0),
109  m_packetInterval (0.1),
110  m_packetSize (1024),
111  m_nIfaces (1),
112  m_chan (true),
113  m_pcap (false),
114  m_stack ("ns3::Dot11sStack"),
115  m_root ("ff:ff:ff:ff:ff:ff")
116 {
117 }
118 void
119 MeshTest::Configure (int argc, char *argv[])
120 {
121  CommandLine cmd;
122  cmd.AddValue ("x-size", "Number of nodes in a row grid. [6]", m_xSize);
123  cmd.AddValue ("y-size", "Number of rows in a grid. [6]", m_ySize);
124  cmd.AddValue ("step", "Size of edge in our grid, meters. [100 m]", m_step);
125  /*
126  * As soon as starting node means that it sends a beacon,
127  * simultaneous start is not good.
128  */
129  cmd.AddValue ("start", "Maximum random start delay, seconds. [0.1 s]", m_randomStart);
130  cmd.AddValue ("time", "Simulation time, seconds [100 s]", m_totalTime);
131  cmd.AddValue ("packet-interval", "Interval between packets in UDP ping, seconds [0.001 s]", m_packetInterval);
132  cmd.AddValue ("packet-size", "Size of packets in UDP ping", m_packetSize);
133  cmd.AddValue ("interfaces", "Number of radio interfaces used by each mesh point. [1]", m_nIfaces);
134  cmd.AddValue ("channels", "Use different frequency channels for different interfaces. [0]", m_chan);
135  cmd.AddValue ("pcap", "Enable PCAP traces on interfaces. [0]", m_pcap);
136  cmd.AddValue ("stack", "Type of protocol stack. ns3::Dot11sStack by default", m_stack);
137  cmd.AddValue ("root", "Mac address of root mesh point in HWMP", m_root);
138 
139  cmd.Parse (argc, argv);
140  NS_LOG_DEBUG ("Grid:" << m_xSize << "*" << m_ySize);
141  NS_LOG_DEBUG ("Simulation time: " << m_totalTime << " s");
142 }
143 void
145 {
146  /*
147  * Create m_ySize*m_xSize stations to form a grid topology
148  */
150  // Configure YansWifiChannel
151  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
152  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
153  wifiPhy.SetChannel (wifiChannel.Create ());
154  /*
155  * Create mesh helper and set stack installer to it
156  * Stack installer creates all needed protocols and install them to
157  * mesh point device
158  */
159  mesh = MeshHelper::Default ();
160  if (!Mac48Address (m_root.c_str ()).IsBroadcast ())
161  {
163  }
164  else
165  {
166  //If root is not set, we do not use "Root" attribute, because it
167  //is specified only for 11s
169  }
170  if (m_chan)
171  {
172  mesh.SetSpreadInterfaceChannels (MeshHelper::SPREAD_CHANNELS);
173  }
174  else
175  {
176  mesh.SetSpreadInterfaceChannels (MeshHelper::ZERO_CHANNEL);
177  }
178  mesh.SetMacType ("RandomStart", TimeValue (Seconds (m_randomStart)));
179  // Set number of interfaces - default is single-interface mesh point
181  // Install protocols and return container if MeshPointDevices
182  meshDevices = mesh.Install (wifiPhy, nodes);
183  // Setup mobility - static grid topology
184  MobilityHelper mobility;
185  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
186  "MinX", DoubleValue (0.0),
187  "MinY", DoubleValue (0.0),
188  "DeltaX", DoubleValue (m_step),
189  "DeltaY", DoubleValue (m_step),
190  "GridWidth", UintegerValue (m_xSize),
191  "LayoutType", StringValue ("RowFirst"));
192  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
193  mobility.Install (nodes);
194  if (m_pcap)
195  wifiPhy.EnablePcapAll (std::string ("mp-"));
196 }
197 void
199 {
200  InternetStackHelper internetStack;
201  internetStack.Install (nodes);
203  address.SetBase ("10.1.1.0", "255.255.255.0");
204  interfaces = address.Assign (meshDevices);
205 }
206 void
208 {
210  ApplicationContainer serverApps = echoServer.Install (nodes.Get (0));
211  serverApps.Start (Seconds (0.0));
212  serverApps.Stop (Seconds (m_totalTime));
214  echoClient.SetAttribute ("MaxPackets", UintegerValue ((uint32_t)(m_totalTime*(1/m_packetInterval))));
215  echoClient.SetAttribute ("Interval", TimeValue (Seconds (m_packetInterval)));
216  echoClient.SetAttribute ("PacketSize", UintegerValue (m_packetSize));
218  clientApps.Start (Seconds (0.0));
219  clientApps.Stop (Seconds (m_totalTime));
220 }
221 int
223 {
224  CreateNodes ();
227  Simulator::Schedule (Seconds (m_totalTime), &MeshTest::Report, this);
228  Simulator::Stop (Seconds (m_totalTime));
229  Simulator::Run ();
230  Simulator::Destroy ();
231  return 0;
232 }
233 void
235 {
236  unsigned n (0);
237  for (NetDeviceContainer::Iterator i = meshDevices.Begin (); i != meshDevices.End (); ++i, ++n)
238  {
239  std::ostringstream os;
240  os << "mp-report-" << n << ".xml";
241  std::cerr << "Printing mesh point device #" << n << " diagnostics to " << os.str () << "\n";
242  std::ofstream of;
243  of.open (os.str ().c_str ());
244  if (!of.is_open ())
245  {
246  std::cerr << "Error: Can't open file " << os.str () << "\n";
247  return;
248  }
249  mesh.Report (*i, of);
250  of.close ();
251  }
252 }
253 int
254 main (int argc, char *argv[])
255 {
256  MeshTest t;
257  t.Configure (argc, argv);
258  return t.Run ();
259 }
holds a vector of ns3::Application pointers.
double m_totalTime
Definition: mesh.cc:77
Iterator Begin(void) const
Get an iterator which refers to the first NetDevice in the container.
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
holds a vector of std::pair of Ptr and interface index.
Ptr< YansWifiChannel > Create(void) const
hold variables of type string
Definition: string.h:19
Make it easy to create and manage PHY objects for the yans model.
std::string m_stack
Definition: mesh.cc:83
tuple echoServer
Definition: first.py:42
Create an application which sends a UDP packet and waits for an echo of this packet.
aggregate IP/TCP/UDP functionality to existing Nodes.
int main(int argc, char *argv[])
Definition: mesh.cc:254
void Report(const ns3::Ptr< ns3::NetDevice > &, std::ostream &)
Print statistics.
Definition: mesh-helper.cc:192
void SetNumberOfInterfaces(uint32_t nInterfaces)
Set a number of interfaces in a mesh network.
Definition: mesh-helper.cc:74
tuple clientApps
Definition: first.py:53
ApplicationContainer Install(Ptr< Node > node) const
Create a UdpEchoServerApplication on the specified Node.
void SetChannel(Ptr< YansWifiChannel > channel)
Create a server application which waits for input UDP packets and sends them back to the original sen...
NetDeviceContainer meshDevices
List of all mesh point devices.
Definition: mesh.cc:88
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
int Run()
Run test.
Definition: mesh.cc:222
void EnablePcapAll(std::string prefix, bool promiscuous=false)
Enable pcap output on each device (which is of the appropriate type) in the set of all nodes created ...
hold objects of type ns3::Time
Definition: nstime.h:961
Hold an unsigned integer type.
Definition: uinteger.h:46
holds a vector of ns3::NetDevice pointers
MeshTest()
Init test.
Definition: mesh.cc:103
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Parse command-line arguments.
Definition: command-line.h:152
void SetMacType(std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Definition: mesh-helper.cc:123
int m_ySize
Definition: mesh.cc:74
Definition: mesh.cc:63
tuple echoClient
Definition: first.py:48
tuple serverApps
Definition: first.py:44
bool m_chan
Definition: mesh.cc:81
void InstallApplication()
Install applications.
Definition: mesh.cc:207
keep track of a set of node pointers.
uint16_t m_packetSize
Definition: mesh.cc:79
void SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
void CreateNodes()
Create nodes and setup their mobility.
Definition: mesh.cc:144
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
an EUI-48 address
Definition: mac48-address.h:41
manage and create wifi channel objects for the yans model.
void SetSpreadInterfaceChannels(ChannelPolicy)
set the channel policy
Definition: mesh-helper.cc:41
void SetStackInstaller(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Definition: mesh-helper.cc:46
Helper class used to assign positions and mobility models to nodes.
Ipv4InterfaceContainer interfaces
Definition: mesh.cc:90
void Configure(int argc, char **argv)
Configure test from command line arguments.
Definition: mesh.cc:119
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
double m_step
Definition: mesh.cc:75
int m_xSize
Definition: mesh.cc:73
uint32_t m_nIfaces
Definition: mesh.cc:80
NetDeviceContainer Install(const WifiPhyHelper &phyHelper, NodeContainer c) const
Install 802.11s mesh device & protocols on given node list.
Definition: mesh-helper.cc:79
hold objects of type ns3::Mac48Address
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Definition: command-line.h:408
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
std::vector< Ptr< NetDevice > >::const_iterator Iterator
#define NS_LOG_DEBUG(msg)
Definition: log.h:289
MeshHelper mesh
Definition: mesh.cc:92
void Parse(int argc, char *argv[])
Parse the program arguments.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
bool m_pcap
Definition: mesh.cc:82
Helper to create IEEE 802.11s mesh networks.
Definition: mesh-helper.h:38
tuple address
Definition: first.py:37
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
Iterator End(void) const
Get an iterator which indicates past-the-last NetDevice in the container.
NodeContainer nodes
List of network nodes.
Definition: mesh.cc:86
Hold a floating point type.
Definition: double.h:41
std::string m_stack
void InstallInternetStack()
Install internet m_stack on nodes.
Definition: mesh.cc:198
double m_randomStart
Definition: mesh.cc:76
void Report()
Print mesh devices diagnostics.
Definition: mesh.cc:234
double m_packetInterval
Definition: mesh.cc:78
std::string m_root
Definition: mesh.cc:84
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const