A Discrete-Event Network Simulator
API
wimax-multicast.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007,2008, 2009 INRIA, UDcast
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
18  * <amine.ismail@udcast.com>
19  */
20 
21 // Default network topology includes:
22 // - A base station (BS)
23 // - Some number of SSs specified by the variable nbSS (defaults to 10)
24 // - A multicast router (ASNGW)
25 // - A multicast streamer
26 
27 // Two Lans are setup: The first one between the multicast streamer and the
28 // ASNGW, the second one between the ASNGW (router) and the base station
29 
30 // +-----+ +-----+ +-----+ +-----+ +-----+
31 // | SS0 | | SS1 | | SS2 | | SS3 | | SS4 |
32 // +-----+ +-----+ +-----+ +-----+ +-----+
33 // 10.1.0.1 10.1.0.2 10.1.0.3 10.1.0.4 10.1.0.5
34 // -------- -------- ------- ------- --------
35 // ((*)) ((*)) ((*)) ((*)) ((*))
36 //
37 // LAN2 (11.1.1.0)
38 // ===============
39 // 10.1.0.11 | |
40 // +------------+ ASNGW multicast Streamer
41 // ((*))==|Base Station| | (12.1.1.0) |
42 // +------------+ ==================
43 // LAN1
44 //
45 // ((*)) ((*)) ((*)) ((*)) ((*))
46 // ------- -------- -------- ------- --------
47 // 10.1.0.6 10.1.0.7 10.1.0.8 10.1.0.9 10.1.0.10
48 // +-----+ +-----+ +-----+ +-----+ +-----+
49 // | SS5 | | SS6 | | SS7 | | SS8 | | SS9 |
50 // +-----+ +-----+ +-----+ +-----+ +-----+
51 
52 #include "ns3/applications-module.h"
53 #include "ns3/config-store-module.h"
54 #include "ns3/core-module.h"
55 #include "ns3/csma-module.h"
56 #include "ns3/global-route-manager.h"
57 #include "ns3/internet-module.h"
58 #include "ns3/mobility-module.h"
59 #include "ns3/network-module.h"
60 #include "ns3/vector.h"
61 #include "ns3/wimax-module.h"
62 
63 #include <iostream>
64 #include <vector>
65 
66 using namespace ns3;
67 
68 NS_LOG_COMPONENT_DEFINE("WimaxMulticastSimulation");
69 
70 int
71 main(int argc, char* argv[])
72 {
73  bool verbose = false;
74 
75  NodeContainer ssNodes;
76  std::vector<Ptr<SubscriberStationNetDevice>> ss;
77  NetDeviceContainer ssDevs;
78  Ipv4InterfaceContainer SSinterfaces;
79 
80  NodeContainer bsNodes;
82  NetDeviceContainer bsDevs;
83  NetDeviceContainer bsDevsOne;
84  Ipv4InterfaceContainer BSinterfaces;
85 
86  UdpTraceClientHelper udpClient;
88 
90  NodeContainer Streamer_Node;
91  NodeContainer ASNGW_Node;
92 
94  std::vector<Ptr<RandomWaypointMobilityModel>> SSPosition;
95  std::vector<Ptr<RandomRectanglePositionAllocator>> SSPosAllocator;
96 
97  // default values
98  int nbSS = 10;
99  int duration = 7;
100  int schedType = 0;
102 
103  CommandLine cmd(__FILE__);
104  cmd.AddValue("nbSS", "number of subscriber station to create", nbSS);
105  cmd.AddValue("scheduler", "type of scheduler to use with the netdevices", schedType);
106  cmd.AddValue("duration", "duration of the simulation in seconds", duration);
107  cmd.AddValue("verbose", "turn on all WimaxNetDevice log components", verbose);
108  cmd.Parse(argc, argv);
109 
110  LogComponentEnable("UdpTraceClient", LOG_LEVEL_INFO);
111  LogComponentEnable("UdpServer", LOG_LEVEL_INFO);
112 
113  switch (schedType)
114  {
115  case 0:
116  scheduler = WimaxHelper::SCHED_TYPE_SIMPLE;
117  break;
118  case 1:
119  scheduler = WimaxHelper::SCHED_TYPE_MBQOS;
120  break;
121  case 2:
122  scheduler = WimaxHelper::SCHED_TYPE_RTPS;
123  break;
124  default:
125  scheduler = WimaxHelper::SCHED_TYPE_SIMPLE;
126  }
127 
128  ss.resize(nbSS);
129  SSPosition.resize(nbSS);
130  SSPosAllocator.resize(nbSS);
131 
132  ssNodes.Create(nbSS);
133  bsNodes.Create(1);
134 
135  Streamer_Node.Create(1);
136  ASNGW_Node.Create(1);
137 
138  WimaxHelper wimax;
139 
140  channel = CreateObject<SimpleOfdmWimaxChannel>();
142  ssDevs = wimax.Install(ssNodes,
145  channel,
146  scheduler);
147  Ptr<WimaxNetDevice> dev = wimax.Install(bsNodes.Get(0),
150  channel,
151  scheduler);
152 
153  BSPosition = CreateObject<ConstantPositionMobilityModel>();
154 
155  BSPosition->SetPosition(Vector(1000, 0, 0));
156  bsNodes.Get(0)->AggregateObject(BSPosition);
157  bsDevs.Add(dev);
158  if (verbose)
159  {
160  WimaxHelper::EnableLogComponents(); // Turn on all wimax logging
161  }
162 
163  for (int i = 0; i < nbSS; i++)
164  {
165  SSPosition[i] = CreateObject<RandomWaypointMobilityModel>();
166  SSPosAllocator[i] = CreateObject<RandomRectanglePositionAllocator>();
167  Ptr<UniformRandomVariable> xVar = CreateObject<UniformRandomVariable>();
168  xVar->SetAttribute("Min", DoubleValue((i / 40.0) * 2000));
169  xVar->SetAttribute("Max", DoubleValue((i / 40.0 + 1) * 2000));
170  SSPosAllocator[i]->SetX(xVar);
171  Ptr<UniformRandomVariable> yVar = CreateObject<UniformRandomVariable>();
172  yVar->SetAttribute("Min", DoubleValue((i / 40.0) * 2000));
173  yVar->SetAttribute("Max", DoubleValue((i / 40.0 + 1) * 2000));
174  SSPosAllocator[i]->SetY(yVar);
175  SSPosition[i]->SetAttribute("PositionAllocator", PointerValue(SSPosAllocator[i]));
176  SSPosition[i]->SetAttribute("Speed",
177  StringValue("ns3::UniformRandomVariable[Min=10.3|Max=40.7]"));
178  SSPosition[i]->SetAttribute("Pause",
179  StringValue("ns3::ConstantRandomVariable[Constant=0.01]"));
180 
181  ss[i] = ssDevs.Get(i)->GetObject<SubscriberStationNetDevice>();
183  ssNodes.Get(i)->AggregateObject(SSPosition[i]);
184  }
185 
186  bs = bsDevs.Get(0)->GetObject<BaseStationNetDevice>();
187 
188  CsmaHelper csmaASN_BS;
189  CsmaHelper csmaStreamer_ASN;
190 
191  // First LAN BS and ASN
192  NodeContainer LAN_ASN_BS;
193 
194  LAN_ASN_BS.Add(bsNodes.Get(0));
195 
196  LAN_ASN_BS.Add(ASNGW_Node.Get(0));
197 
198  csmaASN_BS.SetChannelAttribute("DataRate", DataRateValue(DataRate(10000000)));
199  csmaASN_BS.SetChannelAttribute("Delay", TimeValue(MilliSeconds(2)));
200  csmaASN_BS.SetDeviceAttribute("Mtu", UintegerValue(1500));
201  NetDeviceContainer LAN_ASN_BS_Devs = csmaASN_BS.Install(LAN_ASN_BS);
202 
203  NetDeviceContainer BS_CSMADevs;
204 
205  BS_CSMADevs.Add(LAN_ASN_BS_Devs.Get(0));
206 
207  NetDeviceContainer ASN_Devs1;
208  ASN_Devs1.Add(LAN_ASN_BS_Devs.Get(1));
209 
210  // Second LAN ASN-GW and Streamer
211 
212  NodeContainer LAN_ASN_STREAMER;
213  LAN_ASN_STREAMER.Add(ASNGW_Node.Get(0));
214  LAN_ASN_STREAMER.Add(Streamer_Node.Get(0));
215 
216  csmaStreamer_ASN.SetChannelAttribute("DataRate", DataRateValue(DataRate(10000000)));
217  csmaStreamer_ASN.SetChannelAttribute("Delay", TimeValue(MilliSeconds(2)));
218  csmaStreamer_ASN.SetDeviceAttribute("Mtu", UintegerValue(1500));
219 
220  NetDeviceContainer LAN_ASN_STREAMER_Devs = csmaStreamer_ASN.Install(LAN_ASN_STREAMER);
221 
222  NetDeviceContainer STREAMER_Devs;
223  NetDeviceContainer ASN_Devs2;
224  ASN_Devs2.Add(LAN_ASN_STREAMER_Devs.Get(0));
225  STREAMER_Devs.Add(LAN_ASN_STREAMER_Devs.Get(1));
226 
229  mobility.Install(bsNodes);
230  stack.Install(bsNodes);
231  mobility.Install(ssNodes);
232  stack.Install(ssNodes);
233  stack.Install(Streamer_Node);
234  stack.Install(ASNGW_Node);
235 
237 
238  address.SetBase("10.1.0.0", "255.255.255.0");
239  bsDevsOne.Add(bs);
240  BSinterfaces = address.Assign(bsDevsOne);
241  SSinterfaces = address.Assign(ssDevs);
242 
243  address.SetBase("11.1.1.0", "255.255.255.0");
244  Ipv4InterfaceContainer BSCSMAInterfaces = address.Assign(BS_CSMADevs);
245  Ipv4InterfaceContainer ASNCSMAInterfaces1 = address.Assign(ASN_Devs1);
246 
247  address.SetBase("12.1.1.0", "255.255.255.0");
248  Ipv4InterfaceContainer ASNCSMAInterfaces2 = address.Assign(ASN_Devs2);
249  Ipv4InterfaceContainer StreamerCSMAInterfaces = address.Assign(STREAMER_Devs);
250 
251  Ipv4Address multicastSource("12.1.1.2");
252  Ipv4Address multicastGroup("224.30.10.81");
253 
254  Ipv4StaticRoutingHelper multicast;
255  // 1) Configure a (static) multicast route on ASNGW (multicastRouter)
256  Ptr<Node> multicastRouter = ASNGW_Node.Get(0); // The node in question
257  Ptr<NetDevice> inputIf = ASN_Devs2.Get(0); // The input NetDevice
258 
259  multicast.AddMulticastRoute(multicastRouter,
260  multicastSource,
261  multicastGroup,
262  inputIf,
263  ASN_Devs1);
264 
265  // 2) Set up a default multicast route on the sender n0
266  Ptr<Node> sender = Streamer_Node.Get(0);
267  Ptr<NetDevice> senderIf = STREAMER_Devs.Get(0);
268  multicast.SetDefaultMulticastRoute(sender, senderIf);
269 
270  // 1) Configure a (static) multicast route on ASNGW (multicastRouter)
271  multicastRouter = bsNodes.Get(0); // The node in question
272  inputIf = BS_CSMADevs.Get(0); // The input NetDevice
273 
274  multicast.AddMulticastRoute(multicastRouter,
275  multicastSource,
276  multicastGroup,
277  inputIf,
278  bsDevsOne);
279 
280  uint16_t multicast_port = 100;
281 
282  UdpServerHelper udpServerHelper = UdpServerHelper(multicast_port);
284  serverApps = udpServerHelper.Install(ssNodes);
285  serverApps.Start(Seconds(6));
286  serverApps.Stop(Seconds(duration));
287 
288  udpClient = UdpTraceClientHelper(multicastGroup, multicast_port, "");
289 
290  clientApps = udpClient.Install(Streamer_Node.Get(0));
291  clientApps.Start(Seconds(6));
292  clientApps.Stop(Seconds(duration));
293 
294  IpcsClassifierRecord MulticastClassifier(Ipv4Address("0.0.0.0"),
295  Ipv4Mask("0.0.0.0"),
296  multicastGroup,
297  Ipv4Mask("255.255.255.255"),
298  0,
299  65000,
300  multicast_port,
301  multicast_port,
302  17,
303  1);
304 
305  ServiceFlow MulticastServiceFlow = wimax.CreateServiceFlow(ServiceFlow::SF_DIRECTION_DOWN,
307  MulticastClassifier);
308 
309  bs->GetServiceFlowManager()->AddMulticastServiceFlow(MulticastServiceFlow,
311 
312  Simulator::Stop(Seconds(duration + 0.1));
313  NS_LOG_INFO("Starting simulation.....");
314  Simulator::Run();
315 
316  for (int i = 0; i < nbSS; i++)
317  {
318  ss[i] = nullptr;
319  SSPosition[i] = nullptr;
320  SSPosAllocator[i] = nullptr;
321  }
322 
323  bs = nullptr;
324 
326  NS_LOG_INFO("Done.");
327 
328  return 0;
329 }
holds a vector of ns3::Application pointers.
BaseStation NetDevice.
Definition: bs-net-device.h:54
Parse command-line arguments.
Definition: command-line.h:232
build a set of CsmaNetDevice objects
Definition: csma-helper.h:48
void SetDeviceAttribute(std::string n1, const AttributeValue &v1)
Definition: csma-helper.cc:50
void SetChannelAttribute(std::string n1, const AttributeValue &v1)
Definition: csma-helper.cc:56
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::CsmaChannel with the attributes configured by CsmaHelper::SetChannelAttri...
Definition: csma-helper.cc:226
AttributeValue implementation for DataRate.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
aggregate IP/TCP/UDP functionality to existing Nodes.
IpcsClassifierRecord class.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:43
holds a vector of std::pair of Ptr<Ipv4> and interface index.
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:258
Helper class that adds ns3::Ipv4StaticRouting objects.
void AddMulticastRoute(Ptr< Node > n, Ipv4Address source, Ipv4Address group, Ptr< NetDevice > input, NetDeviceContainer output)
Add a multicast route to a node and net device using explicit Ptr<Node> and Ptr<NetDevice>
void SetDefaultMulticastRoute(Ptr< Node > n, Ptr< NetDevice > nd)
Add a default route to the static routing protocol to forward packets out a particular interface.
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void Add(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this container.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:200
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:259
Hold objects of type Ptr<T>.
Definition: pointer.h:37
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
This class implements service flows as described by the IEEE-802.16 standard.
Definition: service-flow.h:43
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:140
static void Run()
Run the simulation.
Definition: simulator.cc:176
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:184
Hold variables of type string.
Definition: string.h:56
SubscriberStationNetDevice subclass of WimaxNetDevice.
Definition: ss-net-device.h:50
void SetModulationType(WimaxPhy::ModulationType modulationType)
Set the most efficient modulation and coding scheme (MCS) supported by the device.
AttributeValue implementation for Time.
Definition: nstime.h:1423
Create a server application which waits for input UDP packets and uses the information carried into t...
ApplicationContainer Install(NodeContainer c)
Create one UDP server application on each of the Nodes in the NodeContainer.
Create UdpTraceClient application which sends UDP packets based on a trace file of an MPEG4 stream.
ApplicationContainer Install(NodeContainer c)
Hold an unsigned integer type.
Definition: uinteger.h:45
helps to manage and create WimaxNetDevice objects
Definition: wimax-helper.h:59
SchedulerType
Scheduler Type Different implementations of uplink/downlink scheduler.
Definition: wimax-helper.h:86
@ SCHED_TYPE_RTPS
A simple scheduler - rtPS based scheduler.
Definition: wimax-helper.h:88
@ SCHED_TYPE_MBQOS
An migration-based uplink scheduler.
Definition: wimax-helper.h:89
@ SCHED_TYPE_SIMPLE
A simple priority-based FCFS scheduler.
Definition: wimax-helper.h:87
@ DEVICE_TYPE_SUBSCRIBER_STATION
Subscriber station(SS) device.
Definition: wimax-helper.h:67
@ DEVICE_TYPE_BASE_STATION
Base station(BS) device.
Definition: wimax-helper.h:68
NetDeviceContainer Install(NodeContainer c, NetDeviceType type, PhyType phyType, SchedulerType schedulerType)
static void EnableLogComponents()
Helper to enable all WimaxNetDevice log components with one statement.
ServiceFlow CreateServiceFlow(ServiceFlow::Direction direction, ServiceFlow::SchedulingType schedulinType, IpcsClassifierRecord classifier)
Creates a transport service flow.
@ MODULATION_TYPE_QPSK_12
Definition: wimax-phy.h:56
@ MODULATION_TYPE_QAM16_12
Definition: wimax-phy.h:58
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Definition: data-rate.h:328
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1348
address
Definition: first.py:40
serverApps
Definition: first.py:48
clientApps
Definition: first.py:58
stack
Definition: first.py:37
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:305
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition: log.h:107
cmd
Definition: second.py:33
channel
Definition: third.py:81
mobility
Definition: third.py:96
bool verbose