A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("WimaxMulticastSimulation");
67 
68 #define MAXSS 1000
69 #define MAXDIST 10 // km
70 using namespace ns3;
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 
103  CommandLine cmd;
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 
222  MobilityHelper mobility;
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.
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
void SetChannelAttribute(std::string n1, const AttributeValue &v1)
Definition: csma-helper.cc:69
int main(int argc, char *argv[])
An migration-based uplink scheduler.
Definition: wimax-helper.h:90
holds a vector of std::pair of Ptr and interface index.
hold variables of type string
Definition: string.h:19
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:210
SchedulerType
Scheduler Type Different implementations of uplink/downlink scheduler.
Definition: wimax-helper.h:86
void SetModulationType(WimaxPhy::ModulationType modulationType)
Set the most efficient modulation and coding scheme (MCS) supported by the device.
static void Run(void)
Run the simulation until one of:
Definition: simulator.cc:157
aggregate IP/TCP/UDP functionality to existing Nodes.
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)
Definition: log.h:298
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)
a 3d vector
Definition: vector.h:31
tuple clientApps
Definition: first.py:53
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:71
A simple scheduler - rtPS based scheduler.
Definition: wimax-helper.h:89
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
hold objects of type ns3::Time
Definition: nstime.h:961
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:46
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...
void AggregateObject(Ptr< Object > other)
Definition: object.cc:243
Parse command-line arguments.
Definition: command-line.h:152
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
Ptr< BsServiceFlowManager > GetServiceFlowManager(void) const
tuple serverApps
Definition: first.py:44
keep track of a set of node pointers.
hold objects of type Ptr
Definition: pointer.h:33
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:38
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.
hold objects of type ns3::DataRate
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Definition: command-line.h:408
static void Stop(void)
If an event invokes this method, it will be the last event scheduled by the Simulator::run method bef...
Definition: simulator.cc:165
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
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:59
#define MAXSS
NS_LOG_COMPONENT_DEFINE("WimaxMulticastSimulation")
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.
Hold a floating point type.
Definition: double.h:41
void SetAttribute(std::string name, const AttributeValue &value)
Definition: object-base.cc:161
A simple priority-based FCFS scheduler.
Definition: wimax-helper.h:88
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
void LogComponentEnable(char const *name, enum LogLevel level)
Definition: log.cc:311
bool verbose