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/internet-module.h"
63 #include "ns3/vector.h"
64 
65 using namespace ns3;
66 
67 NS_LOG_COMPONENT_DEFINE ("WimaxMulticastSimulation");
68 
69 #define MAXSS 1000
70 #define MAXDIST 10 // km
71 
72 int main (int argc, char *argv[])
73 {
74  bool verbose = false;
75 
76  NodeContainer ssNodes;
78  NetDeviceContainer ssDevs;
79  Ipv4InterfaceContainer SSinterfaces;
80 
81  NodeContainer bsNodes;
83  NetDeviceContainer bsDevs, bsDevsOne;
84  Ipv4InterfaceContainer BSinterfaces;
85 
86  UdpServerHelper udpServer[MAXSS];
88  UdpTraceClientHelper udpClient;
90 
92  NodeContainer Streamer_Node;
93  NodeContainer ASNGW_Node;
94 
98 
99  // default values
100  int nbSS = 10, duration = 7, schedType = 0;
102 
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  ssNodes.Create (nbSS);
129  bsNodes.Create (1);
130 
131  Streamer_Node.Create (1);
132  ASNGW_Node.Create (1);
133 
134  WimaxHelper wimax;
135 
136  channel = CreateObject<SimpleOfdmWimaxChannel> ();
138  ssDevs = wimax.Install (ssNodes,
141  channel,
142  scheduler);
143  Ptr<WimaxNetDevice> dev = wimax.Install (bsNodes.Get (0),
146  channel,
147  scheduler);
148 
149  BSPosition = CreateObject<ConstantPositionMobilityModel> ();
150 
151  BSPosition->SetPosition (Vector (1000, 0, 0));
152  bsNodes.Get (0)->AggregateObject (BSPosition);
153  bsDevs.Add (dev);
154  if (verbose)
155  {
156  wimax.EnableLogComponents (); // Turn on all wimax logging
157  }
158 
159  for (int i = 0; i < nbSS; i++)
160  {
161  SSPosition[i] = CreateObject<RandomWaypointMobilityModel> ();
162  SSPosAllocator[i] = CreateObject<RandomRectanglePositionAllocator> ();
163  Ptr<UniformRandomVariable> xVar = CreateObject<UniformRandomVariable> ();
164  xVar->SetAttribute ("Min", DoubleValue ((i / 40.0) * 2000));
165  xVar->SetAttribute ("Max", DoubleValue ((i / 40.0 + 1) * 2000));
166  SSPosAllocator[i]->SetX (xVar);
167  Ptr<UniformRandomVariable> yVar = CreateObject<UniformRandomVariable> ();
168  yVar->SetAttribute ("Min", DoubleValue ((i / 40.0) * 2000));
169  yVar->SetAttribute ("Max", DoubleValue ((i / 40.0 + 1) * 2000));
170  SSPosAllocator[i]->SetY (yVar);
171  SSPosition[i]->SetAttribute ("PositionAllocator", PointerValue (SSPosAllocator[i]));
172  SSPosition[i]->SetAttribute ("Speed", StringValue ("ns3::UniformRandomVariable[Min=10.3|Max=40.7]"));
173  SSPosition[i]->SetAttribute ("Pause", StringValue ("ns3::ConstantRandomVariable[Constant=0.01]"));
174 
175  ss[i] = ssDevs.Get (i)->GetObject<SubscriberStationNetDevice> ();
177  ssNodes.Get (i)->AggregateObject (SSPosition[i]);
178 
179  }
180 
181  bs = bsDevs.Get (0)->GetObject<BaseStationNetDevice> ();
182 
183  CsmaHelper csmaASN_BS;
184  CsmaHelper csmaStreamer_ASN;
185 
186  // First LAN BS and ASN
187  NodeContainer LAN_ASN_BS;
188 
189  LAN_ASN_BS.Add (bsNodes.Get (0));
190 
191  LAN_ASN_BS.Add (ASNGW_Node.Get (0));
192 
193  csmaASN_BS.SetChannelAttribute ("DataRate", DataRateValue (DataRate (10000000)));
194  csmaASN_BS.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
195  csmaASN_BS.SetDeviceAttribute ("Mtu", UintegerValue (1500));
196  NetDeviceContainer LAN_ASN_BS_Devs = csmaASN_BS.Install (LAN_ASN_BS);
197 
198  NetDeviceContainer BS_CSMADevs;
199 
200  BS_CSMADevs.Add (LAN_ASN_BS_Devs.Get (0));
201 
202  NetDeviceContainer ASN_Devs1;
203  ASN_Devs1.Add (LAN_ASN_BS_Devs.Get (1));
204 
205  // Second LAN ASN-GW and Streamer
206 
207  NodeContainer LAN_ASN_STREAMER;
208  LAN_ASN_STREAMER.Add (ASNGW_Node.Get (0));
209  LAN_ASN_STREAMER.Add (Streamer_Node.Get (0));
210 
211  csmaStreamer_ASN.SetChannelAttribute ("DataRate", DataRateValue (DataRate (10000000)));
212  csmaStreamer_ASN.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
213  csmaStreamer_ASN.SetDeviceAttribute ("Mtu", UintegerValue (1500));
214 
215  NetDeviceContainer LAN_ASN_STREAMER_Devs = csmaStreamer_ASN.Install (LAN_ASN_STREAMER);
216 
217  NetDeviceContainer STREAMER_Devs;
218  NetDeviceContainer ASN_Devs2;
219  ASN_Devs2.Add (LAN_ASN_STREAMER_Devs.Get (0));
220  STREAMER_Devs.Add (LAN_ASN_STREAMER_Devs.Get (1));
221 
224  mobility.Install (bsNodes);
225  stack.Install (bsNodes);
226  mobility.Install (ssNodes);
227  stack.Install (ssNodes);
228  stack.Install (Streamer_Node);
229  stack.Install (ASNGW_Node);
230 
232 
233  address.SetBase ("10.1.0.0", "255.255.255.0");
234  bsDevsOne.Add (bs);
235  BSinterfaces = address.Assign (bsDevsOne);
236  SSinterfaces = address.Assign (ssDevs);
237 
238  address.SetBase ("11.1.1.0", "255.255.255.0");
239  Ipv4InterfaceContainer BSCSMAInterfaces = address.Assign (BS_CSMADevs);
240  Ipv4InterfaceContainer ASNCSMAInterfaces1 = address.Assign (ASN_Devs1);
241 
242  address.SetBase ("12.1.1.0", "255.255.255.0");
243  Ipv4InterfaceContainer ASNCSMAInterfaces2 = address.Assign (ASN_Devs2);
244  Ipv4InterfaceContainer StreamerCSMAInterfaces = address.Assign (STREAMER_Devs);
245 
246  Ipv4Address multicastSource ("12.1.1.2");
247  Ipv4Address multicastGroup ("224.30.10.81");
248 
249  Ipv4StaticRoutingHelper multicast;
250  // 1) Configure a (static) multicast route on ASNGW (multicastRouter)
251  Ptr<Node> multicastRouter = ASNGW_Node.Get (0); // The node in question
252  Ptr<NetDevice> inputIf = ASN_Devs2.Get (0); // The input NetDevice
253 
254 
255  multicast.AddMulticastRoute (multicastRouter, multicastSource, multicastGroup, inputIf, ASN_Devs1);
256 
257  // 2) Set up a default multicast route on the sender n0
258  Ptr<Node> sender = Streamer_Node.Get (0);
259  Ptr<NetDevice> senderIf = STREAMER_Devs.Get (0);
260  multicast.SetDefaultMulticastRoute (sender, senderIf);
261 
262  // 1) Configure a (static) multicast route on ASNGW (multicastRouter)
263  multicastRouter = bsNodes.Get (0); // The node in question
264  inputIf = BS_CSMADevs.Get (0); // The input NetDevice
265 
266  multicast.AddMulticastRoute (multicastRouter, multicastSource, multicastGroup, inputIf, bsDevsOne);
267 
268  uint16_t multicast_port = 100;
269 
270  for (int i = 0; i < nbSS; i++)
271  {
272  udpServer[i] = UdpServerHelper (multicast_port);
273  serverApps[i] = udpServer[i].Install (ssNodes.Get (i));
274  serverApps[i].Start (Seconds (6));
275  serverApps[i].Stop (Seconds (duration));
276  }
277 
278  udpClient = UdpTraceClientHelper (multicastGroup, multicast_port, "");
279 
280  clientApps = udpClient.Install (Streamer_Node.Get (0));
281  clientApps.Start (Seconds (6));
282  clientApps.Stop (Seconds (duration));
283 
284  IpcsClassifierRecord MulticastClassifier (Ipv4Address ("0.0.0.0"),
285  Ipv4Mask ("0.0.0.0"),
286  multicastGroup,
287  Ipv4Mask ("255.255.255.255"),
288  0,
289  65000,
290  multicast_port,
291  multicast_port,
292  17,
293  1);
294 
295  ServiceFlow MulticastServiceFlow = wimax.CreateServiceFlow (ServiceFlow::SF_DIRECTION_DOWN,
297  MulticastClassifier);
298 
299  bs->GetServiceFlowManager ()->AddMulticastServiceFlow (MulticastServiceFlow, WimaxPhy::MODULATION_TYPE_QPSK_12);
300 
301  Simulator::Stop (Seconds (duration + 0.1));
302  NS_LOG_INFO ("Starting simulation.....");
303  Simulator::Run ();
304 
305  for (int i = 0; i < nbSS; i++)
306  {
307  ss[i] = 0;
308  SSPosition[i] = 0;
309  SSPosAllocator[i] = 0;
310  }
311 
312  bs = 0;
313 
315  NS_LOG_INFO ("Done.");
316 
317  return 0;
318 }
holds a vector of ns3::Application pointers.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
void SetChannelAttribute(std::string n1, const AttributeValue &v1)
Definition: csma-helper.cc:71
An migration-based uplink scheduler.
Definition: wimax-helper.h:89
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Hold variables of type string.
Definition: string.h:41
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:258
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
serverApps
Definition: first.py:45
static void Run(void)
Run the simulation.
Definition: simulator.cc:226
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1022
aggregate IP/TCP/UDP functionality to existing Nodes.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:278
cmd
Definition: second.py:35
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)
stack
Definition: first.py:34
IpcsClassifierRecord class.
Ptr< BsServiceFlowManager > GetServiceFlowManager(void) const
channel
Definition: third.py:85
mobility
Definition: third.py:101
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> ...
Class for representing data rates.
Definition: data-rate.h:88
A simple scheduler - rtPS based scheduler.
Definition: wimax-helper.h:88
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:369
AttributeValue implementation for Time.
Definition: nstime.h:1076
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
LOG_INFO and above.
Definition: log.h:104
holds a vector of ns3::NetDevice pointers
Create a server application which waits for input UDP packets and uses the information carried into t...
Parse command-line arguments.
Definition: command-line.h:213
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:190
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<T>.
Definition: pointer.h:36
address
Definition: first.py:37
This class implements service flows as described by the IEEE-802.16 standard.
Definition: service-flow.h:39
void SetPosition(const Vector &position)
build a set of CsmaNetDevice objects
Definition: csma-helper.h:46
void SetDeviceAttribute(std::string n1, const AttributeValue &v1)
Definition: csma-helper.cc:65
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::CsmaChannel with the attributes configured by CsmaHelper::SetChannelAttri...
Definition: csma-helper.cc:217
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 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
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:234
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
ServiceFlow CreateServiceFlow(ServiceFlow::Direction direction, ServiceFlow::SchedulingType schedulinType, IpcsClassifierRecord classifier)
Creates a transport service flow.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
helps to manage and create WimaxNetDevice objects
Definition: wimax-helper.h:58
clientApps
Definition: first.py:54
#define MAXSS
SubscriberStationNetDevice subclass of WimaxNetDevice.
Definition: ss-net-device.h:48
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.
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 &#39;double&#39; or &#39;float&#39;...
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:185
A simple priority-based FCFS scheduler.
Definition: wimax-helper.h:87
bool verbose