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/core-module.h"
54 #include "ns3/csma-module.h"
55 #include "ns3/global-route-manager.h"
56 #include "ns3/internet-module.h"
57 #include "ns3/mobility-module.h"
58 #include "ns3/network-module.h"
59 #include "ns3/vector.h"
60 #include "ns3/wimax-module.h"
61 
62 #include <iostream>
63 #include <vector>
64 
65 using namespace ns3;
66 
67 NS_LOG_COMPONENT_DEFINE("WimaxMulticastSimulation");
68 
69 int
70 main(int argc, char* argv[])
71 {
72  bool verbose = false;
73 
74  NodeContainer ssNodes;
75  std::vector<Ptr<SubscriberStationNetDevice>> ss;
76  NetDeviceContainer ssDevs;
77  Ipv4InterfaceContainer SSinterfaces;
78 
79  NodeContainer bsNodes;
81  NetDeviceContainer bsDevs;
82  NetDeviceContainer bsDevsOne;
83  Ipv4InterfaceContainer BSinterfaces;
84 
85  UdpTraceClientHelper udpClient;
87 
89  NodeContainer Streamer_Node;
90  NodeContainer ASNGW_Node;
91 
93  std::vector<Ptr<RandomWaypointMobilityModel>> SSPosition;
94  std::vector<Ptr<RandomRectanglePositionAllocator>> SSPosAllocator;
95 
96  // default values
97  int nbSS = 10;
98  int duration = 7;
99  int schedType = 0;
101 
102  CommandLine cmd(__FILE__);
103  cmd.AddValue("nbSS", "number of subscriber station to create", nbSS);
104  cmd.AddValue("scheduler", "type of scheduler to use with the netdevices", schedType);
105  cmd.AddValue("duration", "duration of the simulation in seconds", duration);
106  cmd.AddValue("verbose", "turn on all WimaxNetDevice log components", verbose);
107  cmd.Parse(argc, argv);
108 
109  LogComponentEnable("UdpTraceClient", LOG_LEVEL_INFO);
110  LogComponentEnable("UdpServer", LOG_LEVEL_INFO);
111 
112  switch (schedType)
113  {
114  case 0:
115  scheduler = WimaxHelper::SCHED_TYPE_SIMPLE;
116  break;
117  case 1:
118  scheduler = WimaxHelper::SCHED_TYPE_MBQOS;
119  break;
120  case 2:
121  scheduler = WimaxHelper::SCHED_TYPE_RTPS;
122  break;
123  default:
124  scheduler = WimaxHelper::SCHED_TYPE_SIMPLE;
125  }
126 
127  ss.resize(nbSS);
128  SSPosition.resize(nbSS);
129  SSPosAllocator.resize(nbSS);
130 
131  ssNodes.Create(nbSS);
132  bsNodes.Create(1);
133 
134  Streamer_Node.Create(1);
135  ASNGW_Node.Create(1);
136 
137  WimaxHelper wimax;
138 
139  channel = CreateObject<SimpleOfdmWimaxChannel>();
141  ssDevs = wimax.Install(ssNodes,
144  channel,
145  scheduler);
146  Ptr<WimaxNetDevice> dev = wimax.Install(bsNodes.Get(0),
149  channel,
150  scheduler);
151 
152  BSPosition = CreateObject<ConstantPositionMobilityModel>();
153 
154  BSPosition->SetPosition(Vector(1000, 0, 0));
155  bsNodes.Get(0)->AggregateObject(BSPosition);
156  bsDevs.Add(dev);
157  if (verbose)
158  {
159  WimaxHelper::EnableLogComponents(); // Turn on all wimax logging
160  }
161 
162  for (int i = 0; i < nbSS; i++)
163  {
164  SSPosition[i] = CreateObject<RandomWaypointMobilityModel>();
165  SSPosAllocator[i] = CreateObject<RandomRectanglePositionAllocator>();
166  Ptr<UniformRandomVariable> xVar = CreateObject<UniformRandomVariable>();
167  xVar->SetAttribute("Min", DoubleValue((i / 40.0) * 2000));
168  xVar->SetAttribute("Max", DoubleValue((i / 40.0 + 1) * 2000));
169  SSPosAllocator[i]->SetX(xVar);
170  Ptr<UniformRandomVariable> yVar = CreateObject<UniformRandomVariable>();
171  yVar->SetAttribute("Min", DoubleValue((i / 40.0) * 2000));
172  yVar->SetAttribute("Max", DoubleValue((i / 40.0 + 1) * 2000));
173  SSPosAllocator[i]->SetY(yVar);
174  SSPosition[i]->SetAttribute("PositionAllocator", PointerValue(SSPosAllocator[i]));
175  SSPosition[i]->SetAttribute("Speed",
176  StringValue("ns3::UniformRandomVariable[Min=10.3|Max=40.7]"));
177  SSPosition[i]->SetAttribute("Pause",
178  StringValue("ns3::ConstantRandomVariable[Constant=0.01]"));
179 
180  ss[i] = ssDevs.Get(i)->GetObject<SubscriberStationNetDevice>();
182  ssNodes.Get(i)->AggregateObject(SSPosition[i]);
183  }
184 
185  bs = bsDevs.Get(0)->GetObject<BaseStationNetDevice>();
186 
187  CsmaHelper csmaASN_BS;
188  CsmaHelper csmaStreamer_ASN;
189 
190  // First LAN BS and ASN
191  NodeContainer LAN_ASN_BS;
192 
193  LAN_ASN_BS.Add(bsNodes.Get(0));
194 
195  LAN_ASN_BS.Add(ASNGW_Node.Get(0));
196 
197  csmaASN_BS.SetChannelAttribute("DataRate", DataRateValue(DataRate(10000000)));
198  csmaASN_BS.SetChannelAttribute("Delay", TimeValue(MilliSeconds(2)));
199  csmaASN_BS.SetDeviceAttribute("Mtu", UintegerValue(1500));
200  NetDeviceContainer LAN_ASN_BS_Devs = csmaASN_BS.Install(LAN_ASN_BS);
201 
202  NetDeviceContainer BS_CSMADevs;
203 
204  BS_CSMADevs.Add(LAN_ASN_BS_Devs.Get(0));
205 
206  NetDeviceContainer ASN_Devs1;
207  ASN_Devs1.Add(LAN_ASN_BS_Devs.Get(1));
208 
209  // Second LAN ASN-GW and Streamer
210 
211  NodeContainer LAN_ASN_STREAMER;
212  LAN_ASN_STREAMER.Add(ASNGW_Node.Get(0));
213  LAN_ASN_STREAMER.Add(Streamer_Node.Get(0));
214 
215  csmaStreamer_ASN.SetChannelAttribute("DataRate", DataRateValue(DataRate(10000000)));
216  csmaStreamer_ASN.SetChannelAttribute("Delay", TimeValue(MilliSeconds(2)));
217  csmaStreamer_ASN.SetDeviceAttribute("Mtu", UintegerValue(1500));
218 
219  NetDeviceContainer LAN_ASN_STREAMER_Devs = csmaStreamer_ASN.Install(LAN_ASN_STREAMER);
220 
221  NetDeviceContainer STREAMER_Devs;
222  NetDeviceContainer ASN_Devs2;
223  ASN_Devs2.Add(LAN_ASN_STREAMER_Devs.Get(0));
224  STREAMER_Devs.Add(LAN_ASN_STREAMER_Devs.Get(1));
225 
228  mobility.Install(bsNodes);
229  stack.Install(bsNodes);
230  mobility.Install(ssNodes);
231  stack.Install(ssNodes);
232  stack.Install(Streamer_Node);
233  stack.Install(ASNGW_Node);
234 
236 
237  address.SetBase("10.1.0.0", "255.255.255.0");
238  bsDevsOne.Add(bs);
239  BSinterfaces = address.Assign(bsDevsOne);
240  SSinterfaces = address.Assign(ssDevs);
241 
242  address.SetBase("11.1.1.0", "255.255.255.0");
243  Ipv4InterfaceContainer BSCSMAInterfaces = address.Assign(BS_CSMADevs);
244  Ipv4InterfaceContainer ASNCSMAInterfaces1 = address.Assign(ASN_Devs1);
245 
246  address.SetBase("12.1.1.0", "255.255.255.0");
247  Ipv4InterfaceContainer ASNCSMAInterfaces2 = address.Assign(ASN_Devs2);
248  Ipv4InterfaceContainer StreamerCSMAInterfaces = address.Assign(STREAMER_Devs);
249 
250  Ipv4Address multicastSource("12.1.1.2");
251  Ipv4Address multicastGroup("224.30.10.81");
252 
253  Ipv4StaticRoutingHelper multicast;
254  // 1) Configure a (static) multicast route on ASNGW (multicastRouter)
255  Ptr<Node> multicastRouter = ASNGW_Node.Get(0); // The node in question
256  Ptr<NetDevice> inputIf = ASN_Devs2.Get(0); // The input NetDevice
257 
258  multicast.AddMulticastRoute(multicastRouter,
259  multicastSource,
260  multicastGroup,
261  inputIf,
262  ASN_Devs1);
263 
264  // 2) Set up a default multicast route on the sender n0
265  Ptr<Node> sender = Streamer_Node.Get(0);
266  Ptr<NetDevice> senderIf = STREAMER_Devs.Get(0);
267  multicast.SetDefaultMulticastRoute(sender, senderIf);
268 
269  // 1) Configure a (static) multicast route on ASNGW (multicastRouter)
270  multicastRouter = bsNodes.Get(0); // The node in question
271  inputIf = BS_CSMADevs.Get(0); // The input NetDevice
272 
273  multicast.AddMulticastRoute(multicastRouter,
274  multicastSource,
275  multicastGroup,
276  inputIf,
277  bsDevsOne);
278 
279  uint16_t multicast_port = 100;
280 
281  UdpServerHelper udpServerHelper = UdpServerHelper(multicast_port);
283  serverApps = udpServerHelper.Install(ssNodes);
284  serverApps.Start(Seconds(6));
285  serverApps.Stop(Seconds(duration));
286 
287  udpClient = UdpTraceClientHelper(multicastGroup, multicast_port, "");
288 
289  clientApps = udpClient.Install(Streamer_Node.Get(0));
290  clientApps.Start(Seconds(6));
291  clientApps.Stop(Seconds(duration));
292 
293  IpcsClassifierRecord MulticastClassifier(Ipv4Address("0.0.0.0"),
294  Ipv4Mask("0.0.0.0"),
295  multicastGroup,
296  Ipv4Mask("255.255.255.255"),
297  0,
298  65000,
299  multicast_port,
300  multicast_port,
301  17,
302  1);
303 
304  ServiceFlow MulticastServiceFlow = wimax.CreateServiceFlow(ServiceFlow::SF_DIRECTION_DOWN,
306  MulticastClassifier);
307 
308  bs->GetServiceFlowManager()->AddMulticastServiceFlow(MulticastServiceFlow,
310 
311  Simulator::Stop(Seconds(duration + 0.1));
312  NS_LOG_INFO("Starting simulation.....");
313  Simulator::Run();
314 
315  for (int i = 0; i < nbSS; i++)
316  {
317  ss[i] = nullptr;
318  SSPosition[i] = nullptr;
319  SSPosAllocator[i] = nullptr;
320  }
321 
322  bs = nullptr;
323 
325  NS_LOG_INFO("Done.");
326 
327  return 0;
328 }
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
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:42
holds a vector of std::pair of Ptr<Ipv4> and interface index.
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:257
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:204
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:77
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:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:186
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.
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:327
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
address
Definition: first.py:47
serverApps
Definition: first.py:54
clientApps
Definition: first.py:64
stack
Definition: first.py:44
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:302
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition: log.h:104
cmd
Definition: second.py:40
channel
Definition: third.py:88
mobility
Definition: third.py:105
bool verbose