A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
;
78
double
m_packetInterval
;
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
;
86
NodeContainer
nodes
;
88
NetDeviceContainer
meshDevices
;
89
//Addresses of interfaces:
90
Ipv4InterfaceContainer
interfaces
;
91
// MeshHelper. Report is not static methods
92
MeshHelper
mesh
;
93
private
:
95
void
CreateNodes ();
97
void
InstallInternetStack ();
99
void
InstallApplication ();
101
void
Report ();
102
};
103
MeshTest::MeshTest
() :
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
144
MeshTest::CreateNodes
()
145
{
146
/*
147
* Create m_ySize*m_xSize stations to form a grid topology
148
*/
149
nodes
.
Create
(
m_ySize
*
m_xSize
);
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
{
162
mesh
.
SetStackInstaller
(
m_stack
,
"Root"
,
Mac48AddressValue
(
Mac48Address
(
m_root
.c_str ())));
163
}
164
else
165
{
166
//If root is not set, we do not use "Root" attribute, because it
167
//is specified only for 11s
168
mesh
.
SetStackInstaller
(
m_stack
);
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
180
mesh
.
SetNumberOfInterfaces
(
m_nIfaces
);
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
198
MeshTest::InstallInternetStack
()
199
{
200
InternetStackHelper
internetStack;
201
internetStack.
Install
(
nodes
);
202
Ipv4AddressHelper
address;
203
address.
SetBase
(
"10.1.1.0"
,
"255.255.255.0"
);
204
interfaces
= address.
Assign
(
meshDevices
);
205
}
206
void
207
MeshTest::InstallApplication
()
208
{
209
UdpEchoServerHelper
echoServer (9);
210
ApplicationContainer
serverApps = echoServer.
Install
(
nodes
.
Get
(0));
211
serverApps.
Start
(
Seconds
(0.0));
212
serverApps.
Stop
(
Seconds
(
m_totalTime
));
213
UdpEchoClientHelper
echoClient (
interfaces
.
GetAddress
(0), 9);
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
));
217
ApplicationContainer
clientApps = echoClient.Install (
nodes
.
Get
(
m_xSize
*
m_ySize
-1));
218
clientApps.
Start
(
Seconds
(0.0));
219
clientApps.
Stop
(
Seconds
(
m_totalTime
));
220
}
221
int
222
MeshTest::Run
()
223
{
224
CreateNodes
();
225
InstallInternetStack
();
226
InstallApplication
();
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
234
MeshTest::Report
()
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
}
src
mesh
examples
mesh.cc
Generated on Fri Dec 21 2012 19:00:41 for ns-3 by
1.8.1.2