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 #include <vector>
65 
66 using namespace ns3;
67 
68 NS_LOG_COMPONENT_DEFINE ("WimaxMulticastSimulation");
69 
70 int 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, bsDevsOne;
82  Ipv4InterfaceContainer BSinterfaces;
83 
84  UdpTraceClientHelper udpClient;
86 
88  NodeContainer Streamer_Node;
89  NodeContainer ASNGW_Node;
90 
92  std::vector<Ptr<RandomWaypointMobilityModel> > SSPosition;
93  std::vector<Ptr<RandomRectanglePositionAllocator> > SSPosAllocator;
94 
95  // default values
96  int nbSS = 10, duration = 7, schedType = 0;
98 
99  CommandLine cmd (__FILE__);
100  cmd.AddValue ("nbSS", "number of subscriber station to create", nbSS);
101  cmd.AddValue ("scheduler", "type of scheduler to use with the netdevices", schedType);
102  cmd.AddValue ("duration", "duration of the simulation in seconds", duration);
103  cmd.AddValue ("verbose", "turn on all WimaxNetDevice log components", verbose);
104  cmd.Parse (argc, argv);
105 
106  LogComponentEnable ("UdpTraceClient", LOG_LEVEL_INFO);
107  LogComponentEnable ("UdpServer", LOG_LEVEL_INFO);
108 
109  switch (schedType)
110  {
111  case 0:
112  scheduler = WimaxHelper::SCHED_TYPE_SIMPLE;
113  break;
114  case 1:
115  scheduler = WimaxHelper::SCHED_TYPE_MBQOS;
116  break;
117  case 2:
118  scheduler = WimaxHelper::SCHED_TYPE_RTPS;
119  break;
120  default:
121  scheduler = WimaxHelper::SCHED_TYPE_SIMPLE;
122  }
123 
124  ss.resize (nbSS);
125  SSPosition.resize (nbSS);
126  SSPosAllocator.resize (nbSS);
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> ();
176  ss[i]->SetModulationType (WimaxPhy::MODULATION_TYPE_QAM16_12);
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  UdpServerHelper udpServerHelper = UdpServerHelper (multicast_port);
272  serverApps = udpServerHelper.Install (ssNodes);
273  serverApps.Start (Seconds (6));
274  serverApps.Stop (Seconds (duration));
275 
276  udpClient = UdpTraceClientHelper (multicastGroup, multicast_port, "");
277 
278  clientApps = udpClient.Install (Streamer_Node.Get (0));
279  clientApps.Start (Seconds (6));
280  clientApps.Stop (Seconds (duration));
281 
282  IpcsClassifierRecord MulticastClassifier (Ipv4Address ("0.0.0.0"),
283  Ipv4Mask ("0.0.0.0"),
284  multicastGroup,
285  Ipv4Mask ("255.255.255.255"),
286  0,
287  65000,
288  multicast_port,
289  multicast_port,
290  17,
291  1);
292 
293  ServiceFlow MulticastServiceFlow = wimax.CreateServiceFlow (ServiceFlow::SF_DIRECTION_DOWN,
295  MulticastClassifier);
296 
297  bs->GetServiceFlowManager ()->AddMulticastServiceFlow (MulticastServiceFlow, WimaxPhy::MODULATION_TYPE_QPSK_12);
298 
299  Simulator::Stop (Seconds (duration + 0.1));
300  NS_LOG_INFO ("Starting simulation.....");
301  Simulator::Run ();
302 
303  for (int i = 0; i < nbSS; i++)
304  {
305  ss[i] = 0;
306  SSPosition[i] = 0;
307  SSPosAllocator[i] = 0;
308  }
309 
310  bs = 0;
311 
313  NS_LOG_INFO ("Done.");
314 
315  return 0;
316 }
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition: net-device-container.h:42
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::BaseStationNetDevice
Definition: bs-net-device.h:51
ns3::DataRateValue
AttributeValue implementation for DataRate.
Definition: data-rate.h:298
ns3::CommandLine
Parse command-line arguments.
Definition: command-line.h:228
ns3::LOG_LEVEL_INFO
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition: log.h:107
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Ipv4AddressHelper
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Definition: ipv4-address-helper.h:48
ns3::WimaxPhy::MODULATION_TYPE_QPSK_12
@ MODULATION_TYPE_QPSK_12
Definition: wimax-phy.h:52
ns3::Object::GetObject
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
third.channel
channel
Definition: third.py:92
ns3::MobilityModel::SetPosition
void SetPosition(const Vector &position)
Definition: mobility-model.cc:88
ns3::LogComponentEnable
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:361
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
ns3::ServiceFlow::SF_TYPE_UGS
@ SF_TYPE_UGS
Definition: service-flow.h:65
ns3::PointerValue
Hold objects of type Ptr<T>.
Definition: pointer.h:37
ns3::ObjectBase::SetAttribute
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:185
ns3::CsmaHelper::Install
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::CsmaChannel with the attributes configured by CsmaHelper::SetChannelAttri...
Definition: csma-helper.cc:218
ns3::UdpTraceClientHelper
Create UdpTraceClient application which sends UDP packets based on a trace file of an MPEG4 stream.
Definition: udp-client-server-helper.h:159
ns3::WimaxHelper::SCHED_TYPE_SIMPLE
@ SCHED_TYPE_SIMPLE
A simple priority-based FCFS scheduler.
Definition: wimax-helper.h:87
ns3::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
ns3::NodeContainer::Create
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Definition: node-container.cc:98
ns3::CsmaHelper
build a set of CsmaNetDevice objects
Definition: csma-helper.h:47
ns3::UdpServerHelper
Create a server application which waits for input UDP packets and uses the information carried into t...
Definition: udp-client-server-helper.h:38
ns3::NodeContainer::Add
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
Definition: node-container.cc:114
ns3::Ipv4StaticRoutingHelper
Helper class that adds ns3::Ipv4StaticRouting objects.
Definition: ipv4-static-routing-helper.h:43
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::DataRate
Class for representing data rates.
Definition: data-rate.h:89
ns3::WimaxHelper::DEVICE_TYPE_BASE_STATION
@ DEVICE_TYPE_BASE_STATION
Base station(BS) device.
Definition: wimax-helper.h:68
ns3::UdpTraceClientHelper::Install
ApplicationContainer Install(NodeContainer c)
Definition: udp-client-server-helper.cc:133
ns3::WimaxHelper::DEVICE_TYPE_SUBSCRIBER_STATION
@ DEVICE_TYPE_SUBSCRIBER_STATION
Subscriber station(SS) device.
Definition: wimax-helper.h:67
ns3::WimaxHelper::Install
NetDeviceContainer Install(NodeContainer c, NetDeviceType type, PhyType phyType, SchedulerType schedulerType)
Definition: wimax-helper.cc:249
ns3::ServiceFlow::SF_DIRECTION_DOWN
@ SF_DIRECTION_DOWN
Definition: service-flow.h:45
first.stack
stack
Definition: first.py:41
ns3::Simulator::Stop
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:180
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
ns3::MilliSeconds
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1297
ns3::WimaxHelper
helps to manage and create WimaxNetDevice objects
Definition: wimax-helper.h:59
ns3::CsmaHelper::SetChannelAttribute
void SetChannelAttribute(std::string n1, const AttributeValue &v1)
Definition: csma-helper.cc:72
ns3::Object::AggregateObject
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:252
ns3::WimaxPhy::MODULATION_TYPE_QAM16_12
@ MODULATION_TYPE_QAM16_12
Definition: wimax-phy.h:54
ns3::Ipv4InterfaceContainer
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Definition: ipv4-interface-container.h:55
ns3::NodeContainer::Get
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Definition: node-container.cc:93
verbose
bool verbose
Definition: openflow-switch.cc:50
first.address
address
Definition: first.py:44
ns3::WimaxHelper::SCHED_TYPE_RTPS
@ SCHED_TYPE_RTPS
A simple scheduler - rtPS based scheduler.
Definition: wimax-helper.h:88
ns3::WimaxHelper::CreateServiceFlow
ServiceFlow CreateServiceFlow(ServiceFlow::Direction direction, ServiceFlow::SchedulingType schedulinType, IpcsClassifierRecord classifier)
Creates a transport service flow.
Definition: wimax-helper.cc:422
second.cmd
cmd
Definition: second.py:35
ns3::WimaxHelper::EnableLogComponents
static void EnableLogComponents(void)
Helper to enable all WimaxNetDevice log components with one statement.
Definition: wimax-helper.cc:363
ns3::SubscriberStationNetDevice
SubscriberStationNetDevice subclass of WimaxNetDevice.
Definition: ss-net-device.h:49
ns3::Simulator::Run
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
ns3::StringValue
Hold variables of type string.
Definition: string.h:41
ns3::SimpleOfdmWimaxChannel::COST231_PROPAGATION
@ COST231_PROPAGATION
Definition: simple-ofdm-wimax-channel.h:54
ns3::WimaxHelper::SIMPLE_PHY_TYPE_OFDM
@ SIMPLE_PHY_TYPE_OFDM
Definition: wimax-helper.h:78
first.clientApps
clientApps
Definition: first.py:61
ns3::Ipv4StaticRoutingHelper::AddMulticastRoute
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>
Definition: ipv4-static-routing-helper.cc:88
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
ns3::Simulator::Destroy
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
ns3::ApplicationContainer
holds a vector of ns3::Application pointers.
Definition: application-container.h:43
first.serverApps
serverApps
Definition: first.py:52
ns3::WimaxHelper::SCHED_TYPE_MBQOS
@ SCHED_TYPE_MBQOS
An migration-based uplink scheduler.
Definition: wimax-helper.h:89
ns3::TimeValue
AttributeValue implementation for Time.
Definition: nstime.h:1353
ns3::CsmaHelper::SetDeviceAttribute
void SetDeviceAttribute(std::string n1, const AttributeValue &v1)
Definition: csma-helper.cc:66
ns3::UdpServerHelper::Install
ApplicationContainer Install(NodeContainer c)
Create one UDP server application on each of the Nodes in the NodeContainer.
Definition: udp-client-server-helper.cc:47
ns3::NodeContainer
keep track of a set of node pointers.
Definition: node-container.h:39
ns3::Ipv4Mask
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:256
ns3::WimaxHelper::SchedulerType
SchedulerType
Scheduler Type Different implementations of uplink/downlink scheduler.
Definition: wimax-helper.h:86
ns3::ServiceFlow
This class implements service flows as described by the IEEE-802.16 standard.
Definition: service-flow.h:40
ns3::UintegerValue
Hold an unsigned integer type.
Definition: uinteger.h:44
ns3::Ipv4StaticRoutingHelper::SetDefaultMulticastRoute
void SetDefaultMulticastRoute(Ptr< Node > n, Ptr< NetDevice > nd)
Add a default route to the static routing protocol to forward packets out a particular interface.
Definition: ipv4-static-routing-helper.cc:163
ns3::InternetStackHelper
aggregate IP/TCP/UDP functionality to existing Nodes.
Definition: internet-stack-helper.h:88
ns3::NetDeviceContainer::Get
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
Definition: net-device-container.cc:62
ns3::NetDeviceContainer::Add
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Definition: net-device-container.cc:67
ns3::BaseStationNetDevice::GetServiceFlowManager
Ptr< BsServiceFlowManager > GetServiceFlowManager(void) const
Definition: bs-net-device.cc:453
ns3::MobilityHelper
Helper class used to assign positions and mobility models to nodes.
Definition: mobility-helper.h:43
third.mobility
mobility
Definition: third.py:108
ns3::IpcsClassifierRecord
IpcsClassifierRecord class.
Definition: ipcs-classifier-record.h:36