A Discrete-Event Network Simulator
API
wimax-ipv4.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007,2008, 2009 INRIA, UDcast
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
18  * <amine.ismail@udcast.com>
19  */
20 
21 //
22 // Default network topology includes a base station (BS) and some number of
23 // subscriber station (SS) specified by the variable nbSS (defaults to six).
24 // The SSs are grouped into two groups: senders and receivers. SSs from 0 to
25 // nbSS/2 are designed as senders and SSs from (nbSS/2 + 1) to nbSS-1 will
26 // designed as receivers.
27 // Each SS creates 3 transport connection with the BS. the fist one has as QoS
28 // scheduling type UGS, the second one rtPS and the third one BE.
29 // Senders SSs send some stamped IP packets with variable bitrate to receiver SSs
30 // through the BS station. receiver SSs receive the IP packets analyze them and
31 // based on a sequence number decide if all the packets are coorectly received
32 
33 // +-----+ +-----+ +-----+
34 // | SS0 | | SS1 | | SS2 |
35 // +-----+ +-----+ +-----+
36 // 10.1.1.1 10.1.1.2 10.1.1.3
37 // -------- -------- -------
38 // ((*)) ((*)) ((*))
39 //
40 // 10.1.1.7
41 // +------------+
42 // |Base Station| ==((*))
43 // +------------+
44 //
45 // ((*)) ((*)) ((*))
46 // ------- -------- --------
47 // 10.1.1.4 10.1.1.5 10.1.1.6
48 // +-----+ +-----+ +-----+
49 // | SS3 | | SS4 | | SS5 |
50 // +-----+ +-----+ +-----+
51 
52 #include "ns3/applications-module.h"
53 #include "ns3/config-store-module.h"
54 #include "ns3/core-module.h"
55 #include "ns3/global-route-manager.h"
56 #include "ns3/internet-module.h"
57 #include "ns3/mobility-module.h"
58 #include "ns3/network-module.h"
59 #include "ns3/wimax-module.h"
60 
61 #include <iostream>
62 
63 using namespace ns3;
64 
65 NS_LOG_COMPONENT_DEFINE("wimaxIpV4Simulation");
66 
67 int
68 main(int argc, char* argv[])
69 {
70  // default values
71  int nbSS = 4;
72  int duration = 7;
73  int schedType = 0;
74  bool verbose = false;
76  LogComponentEnable("UdpClient", LOG_LEVEL_INFO);
77  LogComponentEnable("UdpServer", LOG_LEVEL_INFO);
78 
79  CommandLine cmd(__FILE__);
80  cmd.AddValue("nbSS", "number of subscriber station to create", nbSS);
81  cmd.AddValue("scheduler", "type of scheduler to use with the network devices", schedType);
82  cmd.AddValue("duration", "duration of the simulation in seconds", duration);
83  cmd.AddValue("verbose", "turn on all WimaxNetDevice log components", verbose);
84  cmd.Parse(argc, argv);
85 
86  switch (schedType)
87  {
88  case 0:
90  break;
91  case 1:
93  break;
94  case 2:
95  scheduler = WimaxHelper::SCHED_TYPE_RTPS;
96  break;
97  default:
99  }
100 
101  NodeContainer ssNodes;
102  NodeContainer bsNodes;
103 
104  ssNodes.Create(nbSS);
105  bsNodes.Create(1);
106 
107  WimaxHelper wimax;
108 
109  NetDeviceContainer ssDevs;
110  NetDeviceContainer bsDevs;
111 
112  ssDevs = wimax.Install(ssNodes,
115  scheduler);
116  bsDevs = wimax.Install(bsNodes,
119  scheduler);
120 
122 
123  for (int i = 0; i < nbSS; i++)
124  {
125  ss[i] = ssDevs.Get(i)->GetObject<SubscriberStationNetDevice>();
126  ss[i]->SetModulationType(WimaxPhy::MODULATION_TYPE_QAM16_12);
127  }
128 
130  bs = bsDevs.Get(0)->GetObject<BaseStationNetDevice>();
131 
133  mobility.Install(bsNodes);
134  mobility.Install(ssNodes);
135 
137  stack.Install(bsNodes);
138  stack.Install(ssNodes);
139 
141  address.SetBase("10.1.1.0", "255.255.255.0");
142 
143  Ipv4InterfaceContainer SSinterfaces = address.Assign(ssDevs);
144  Ipv4InterfaceContainer BSinterface = address.Assign(bsDevs);
145  if (verbose)
146  {
147  WimaxHelper::EnableLogComponents(); // Turn on all wimax logging
148  }
149  /*------------------------------*/
150  UdpServerHelper* udpServer = new UdpServerHelper[nbSS / 2];
152  UdpClientHelper* udpClient = new UdpClientHelper[nbSS / 2];
154 
155  for (int i = 0; i < nbSS / 2; i++)
156  {
157  // set server port to 100+(i*10)
158  udpServer[i] = UdpServerHelper(100 + (i * 10));
159  serverApps[i] = udpServer[i].Install(ssNodes.Get(i));
160  serverApps[i].Start(Seconds(6));
161  serverApps[i].Stop(Seconds(duration));
162 
163  udpClient[i] = UdpClientHelper(SSinterfaces.GetAddress(i), 100 + (i * 10));
164  udpClient[i].SetAttribute("MaxPackets", UintegerValue(1200));
165  udpClient[i].SetAttribute("Interval", TimeValue(Seconds(0.12)));
166  udpClient[i].SetAttribute("PacketSize", UintegerValue(800));
167 
168  clientApps[i] = udpClient[i].Install(ssNodes.Get(i + (nbSS / 2)));
169  clientApps[i].Start(Seconds(6));
170  clientApps[i].Stop(Seconds(duration));
171  }
172 
173  Simulator::Stop(Seconds(duration + 0.1));
174  /*
175  * Setup 1 transport connections between each SS and the BS
176  */
177  for (int i = 0; i < nbSS / 2; i++)
178  {
179  IpcsClassifierRecord DlClassifierBe(Ipv4Address("0.0.0.0"),
180  Ipv4Mask("0.0.0.0"),
181  SSinterfaces.GetAddress(i),
182  Ipv4Mask("255.255.255.255"),
183  0,
184  65000,
185  100 + (i * 10),
186  100 + (i * 10),
187  17,
188  1);
191  DlClassifierBe);
192  ss[i]->AddServiceFlow(DlServiceFlowBe);
193  IpcsClassifierRecord ulClassifierBe(SSinterfaces.GetAddress(i + (nbSS / 2)),
194  Ipv4Mask("255.255.255.255"),
195  Ipv4Address("0.0.0.0"),
196  Ipv4Mask("0.0.0.0"),
197  0,
198  65000,
199  100 + (i * 10),
200  100 + (i * 10),
201  17,
202  1);
205  ulClassifierBe);
206  ss[i + (nbSS / 2)]->AddServiceFlow(ulServiceFlowBe);
207  }
208 
209  NS_LOG_INFO("Starting simulation.....");
210  Simulator::Run();
211 
212  delete[] clientApps;
213  delete[] udpClient;
214  delete[] serverApps;
215  delete[] udpServer;
216  for (int i = 0; i < nbSS; i++)
217  {
218  ss[i] = nullptr;
219  }
220  delete[] ss;
221 
222  bs = nullptr;
223 
225  NS_LOG_INFO("Done.");
226 
227  return 0;
228 }
holds a vector of ns3::Application pointers.
BaseStation NetDevice.
Definition: bs-net-device.h:54
Parse command-line arguments.
Definition: command-line.h:232
aggregate IP/TCP/UDP functionality to existing Nodes.
IpcsClassifierRecord class.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:43
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:258
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
This class implements service flows as described by the IEEE-802.16 standard.
Definition: service-flow.h:43
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:140
static void Run()
Run the simulation.
Definition: simulator.cc:176
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:184
SubscriberStationNetDevice subclass of WimaxNetDevice.
Definition: ss-net-device.h:50
AttributeValue implementation for Time.
Definition: nstime.h:1423
Create a client application which sends UDP packets carrying a 32bit sequence number and a 64 bit tim...
void SetAttribute(std::string name, const AttributeValue &value)
Record an attribute to be set in each Application after it is is created.
ApplicationContainer Install(NodeContainer c)
Create a server application which waits for input UDP packets and uses the information carried into t...
ApplicationContainer Install(NodeContainer c)
Create one UDP server application on each of the Nodes in the NodeContainer.
Hold an unsigned integer type.
Definition: uinteger.h:45
helps to manage and create WimaxNetDevice objects
Definition: wimax-helper.h:59
SchedulerType
Scheduler Type Different implementations of uplink/downlink scheduler.
Definition: wimax-helper.h:86
@ SCHED_TYPE_RTPS
A simple scheduler - rtPS based scheduler.
Definition: wimax-helper.h:88
@ SCHED_TYPE_MBQOS
An migration-based uplink scheduler.
Definition: wimax-helper.h:89
@ SCHED_TYPE_SIMPLE
A simple priority-based FCFS scheduler.
Definition: wimax-helper.h:87
@ DEVICE_TYPE_SUBSCRIBER_STATION
Subscriber station(SS) device.
Definition: wimax-helper.h:67
@ DEVICE_TYPE_BASE_STATION
Base station(BS) device.
Definition: wimax-helper.h:68
NetDeviceContainer Install(NodeContainer c, NetDeviceType type, PhyType phyType, SchedulerType schedulerType)
static void EnableLogComponents()
Helper to enable all WimaxNetDevice log components with one statement.
ServiceFlow CreateServiceFlow(ServiceFlow::Direction direction, ServiceFlow::SchedulingType schedulinType, IpcsClassifierRecord classifier)
Creates a transport service flow.
@ MODULATION_TYPE_QAM16_12
Definition: wimax-phy.h:58
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
address
Definition: first.py:40
serverApps
Definition: first.py:48
clientApps
Definition: first.py:58
stack
Definition: first.py:37
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:305
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition: log.h:107
cmd
Definition: second.py:33
mobility
Definition: third.py:96
bool verbose