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