A Discrete-Event Network Simulator
API
wimax-simple.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 2
23 // subscriber station (SS).
24 
25 // +-----+
26 // | SS0 |
27 // +-----+
28 // 10.1.1.1
29 // -------
30 // ((*))
31 //
32 // 10.1.1.7
33 // +------------+
34 // |Base Station| ==((*))
35 // +------------+
36 //
37 // ((*))
38 // -------
39 // 10.1.1.2
40 // +-----+
41 // | SS1 |
42 // +-----+
43 
44 #include "ns3/applications-module.h"
45 #include "ns3/config-store-module.h"
46 #include "ns3/core-module.h"
47 #include "ns3/global-route-manager.h"
48 #include "ns3/internet-module.h"
49 #include "ns3/ipcs-classifier-record.h"
50 #include "ns3/mobility-module.h"
51 #include "ns3/network-module.h"
52 #include "ns3/service-flow.h"
53 #include "ns3/wimax-module.h"
54 
55 #include <iostream>
56 
57 using namespace ns3;
58 
59 NS_LOG_COMPONENT_DEFINE("WimaxSimpleExample");
60 
61 int
62 main(int argc, char* argv[])
63 {
64  bool verbose = false;
65 
66  int duration = 7;
67  int schedType = 0;
69 
70  CommandLine cmd(__FILE__);
71  cmd.AddValue("scheduler", "type of scheduler to use with the network devices", schedType);
72  cmd.AddValue("duration", "duration of the simulation in seconds", duration);
73  cmd.AddValue("verbose", "turn on all WimaxNetDevice log components", verbose);
74  cmd.Parse(argc, argv);
75  LogComponentEnable("UdpClient", LOG_LEVEL_INFO);
76  LogComponentEnable("UdpServer", LOG_LEVEL_INFO);
77  switch (schedType)
78  {
79  case 0:
81  break;
82  case 1:
84  break;
85  case 2:
86  scheduler = WimaxHelper::SCHED_TYPE_RTPS;
87  break;
88  default:
90  }
91 
92  NodeContainer ssNodes;
93  NodeContainer bsNodes;
94 
95  ssNodes.Create(2);
96  bsNodes.Create(1);
97 
98  WimaxHelper wimax;
99 
100  NetDeviceContainer ssDevs;
101  NetDeviceContainer bsDevs;
102 
103  ssDevs = wimax.Install(ssNodes,
106  scheduler);
107  bsDevs = wimax.Install(bsNodes,
110  scheduler);
111 
112  wimax.EnableAscii("bs-devices", bsDevs);
113  wimax.EnableAscii("ss-devices", ssDevs);
114 
116 
117  for (int i = 0; i < 2; i++)
118  {
119  ss[i] = ssDevs.Get(i)->GetObject<SubscriberStationNetDevice>();
120  ss[i]->SetModulationType(WimaxPhy::MODULATION_TYPE_QAM16_12);
121  }
122 
124 
125  bs = bsDevs.Get(0)->GetObject<BaseStationNetDevice>();
126 
128  stack.Install(bsNodes);
129  stack.Install(ssNodes);
130 
132  address.SetBase("10.1.1.0", "255.255.255.0");
133 
134  Ipv4InterfaceContainer SSinterfaces = address.Assign(ssDevs);
135  Ipv4InterfaceContainer BSinterface = address.Assign(bsDevs);
136 
137  if (verbose)
138  {
139  WimaxHelper::EnableLogComponents(); // Turn on all wimax logging
140  }
141  /*------------------------------*/
142  UdpServerHelper udpServer;
144  UdpClientHelper udpClient;
146 
147  udpServer = UdpServerHelper(100);
148 
149  serverApps = udpServer.Install(ssNodes.Get(0));
150  serverApps.Start(Seconds(6));
151  serverApps.Stop(Seconds(duration));
152 
153  udpClient = UdpClientHelper(SSinterfaces.GetAddress(0), 100);
154  udpClient.SetAttribute("MaxPackets", UintegerValue(1200));
155  udpClient.SetAttribute("Interval", TimeValue(Seconds(0.5)));
156  udpClient.SetAttribute("PacketSize", UintegerValue(1024));
157 
158  clientApps = udpClient.Install(ssNodes.Get(1));
159  clientApps.Start(Seconds(6));
160  clientApps.Stop(Seconds(duration));
161 
162  Simulator::Stop(Seconds(duration + 0.1));
163 
164  wimax.EnablePcap("wimax-simple-ss0", ssNodes.Get(0)->GetId(), ss[0]->GetIfIndex());
165  wimax.EnablePcap("wimax-simple-ss1", ssNodes.Get(1)->GetId(), ss[1]->GetIfIndex());
166  wimax.EnablePcap("wimax-simple-bs0", bsNodes.Get(0)->GetId(), bs->GetIfIndex());
167 
168  IpcsClassifierRecord DlClassifierUgs(Ipv4Address("0.0.0.0"),
169  Ipv4Mask("0.0.0.0"),
170  SSinterfaces.GetAddress(0),
171  Ipv4Mask("255.255.255.255"),
172  0,
173  65000,
174  100,
175  100,
176  17,
177  1);
180  DlClassifierUgs);
181 
182  IpcsClassifierRecord UlClassifierUgs(SSinterfaces.GetAddress(1),
183  Ipv4Mask("255.255.255.255"),
184  Ipv4Address("0.0.0.0"),
185  Ipv4Mask("0.0.0.0"),
186  0,
187  65000,
188  100,
189  100,
190  17,
191  1);
194  UlClassifierUgs);
195  ss[0]->AddServiceFlow(DlServiceFlowUgs);
196  ss[1]->AddServiceFlow(UlServiceFlowUgs);
197 
198  NS_LOG_INFO("Starting simulation.....");
199  Simulator::Run();
200 
201  ss[0] = nullptr;
202  ss[1] = nullptr;
203  bs = nullptr;
204 
206  NS_LOG_INFO("Done.");
207 
208  return 0;
209 }
holds a vector of ns3::Application pointers.
void EnableAscii(std::string prefix, Ptr< NetDevice > nd, bool explicitFilename=false)
Enable ascii trace output on the indicated net device.
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
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.
uint32_t GetId() const
Definition: node.cc:117
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
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
bool verbose