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];
87  ApplicationContainer serverApps[MAXSS];
88  UdpTraceClientHelper udpClient;
89  ApplicationContainer clientApps;
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;
223  InternetStackHelper stack;
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 
231  Ipv4AddressHelper address;
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 
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 }