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/core-module.h"
46 #include "ns3/global-route-manager.h"
47 #include "ns3/internet-module.h"
48 #include "ns3/ipcs-classifier-record.h"
49 #include "ns3/mobility-module.h"
50 #include "ns3/network-module.h"
51 #include "ns3/service-flow.h"
52 #include "ns3/wimax-module.h"
53 
54 #include <iostream>
55 
56 using namespace ns3;
57 
58 NS_LOG_COMPONENT_DEFINE("WimaxSimpleExample");
59 
60 int
61 main(int argc, char* argv[])
62 {
63  bool verbose = false;
64 
65  int duration = 7;
66  int schedType = 0;
68 
69  CommandLine cmd(__FILE__);
70  cmd.AddValue("scheduler", "type of scheduler to use with the network devices", schedType);
71  cmd.AddValue("duration", "duration of the simulation in seconds", duration);
72  cmd.AddValue("verbose", "turn on all WimaxNetDevice log components", verbose);
73  cmd.Parse(argc, argv);
74  LogComponentEnable("UdpClient", LOG_LEVEL_INFO);
75  LogComponentEnable("UdpServer", LOG_LEVEL_INFO);
76  switch (schedType)
77  {
78  case 0:
80  break;
81  case 1:
83  break;
84  case 2:
85  scheduler = WimaxHelper::SCHED_TYPE_RTPS;
86  break;
87  default:
89  }
90 
91  NodeContainer ssNodes;
92  NodeContainer bsNodes;
93 
94  ssNodes.Create(2);
95  bsNodes.Create(1);
96 
97  WimaxHelper wimax;
98 
99  NetDeviceContainer ssDevs;
100  NetDeviceContainer bsDevs;
101 
102  ssDevs = wimax.Install(ssNodes,
105  scheduler);
106  bsDevs = wimax.Install(bsNodes,
109  scheduler);
110 
111  wimax.EnableAscii("bs-devices", bsDevs);
112  wimax.EnableAscii("ss-devices", ssDevs);
113 
115 
116  for (int i = 0; i < 2; i++)
117  {
118  ss[i] = ssDevs.Get(i)->GetObject<SubscriberStationNetDevice>();
119  ss[i]->SetModulationType(WimaxPhy::MODULATION_TYPE_QAM16_12);
120  }
121 
123 
124  bs = bsDevs.Get(0)->GetObject<BaseStationNetDevice>();
125 
127  stack.Install(bsNodes);
128  stack.Install(ssNodes);
129 
131  address.SetBase("10.1.1.0", "255.255.255.0");
132 
133  Ipv4InterfaceContainer SSinterfaces = address.Assign(ssDevs);
134  Ipv4InterfaceContainer BSinterface = address.Assign(bsDevs);
135 
136  if (verbose)
137  {
138  WimaxHelper::EnableLogComponents(); // Turn on all wimax logging
139  }
140  /*------------------------------*/
141  UdpServerHelper udpServer;
143  UdpClientHelper udpClient;
145 
146  udpServer = UdpServerHelper(100);
147 
148  serverApps = udpServer.Install(ssNodes.Get(0));
149  serverApps.Start(Seconds(6));
150  serverApps.Stop(Seconds(duration));
151 
152  udpClient = UdpClientHelper(SSinterfaces.GetAddress(0), 100);
153  udpClient.SetAttribute("MaxPackets", UintegerValue(1200));
154  udpClient.SetAttribute("Interval", TimeValue(Seconds(0.5)));
155  udpClient.SetAttribute("PacketSize", UintegerValue(1024));
156 
157  clientApps = udpClient.Install(ssNodes.Get(1));
158  clientApps.Start(Seconds(6));
159  clientApps.Stop(Seconds(duration));
160 
161  Simulator::Stop(Seconds(duration + 0.1));
162 
163  wimax.EnablePcap("wimax-simple-ss0", ssNodes.Get(0)->GetId(), ss[0]->GetIfIndex());
164  wimax.EnablePcap("wimax-simple-ss1", ssNodes.Get(1)->GetId(), ss[1]->GetIfIndex());
165  wimax.EnablePcap("wimax-simple-bs0", bsNodes.Get(0)->GetId(), bs->GetIfIndex());
166 
167  IpcsClassifierRecord DlClassifierUgs(Ipv4Address("0.0.0.0"),
168  Ipv4Mask("0.0.0.0"),
169  SSinterfaces.GetAddress(0),
170  Ipv4Mask("255.255.255.255"),
171  0,
172  65000,
173  100,
174  100,
175  17,
176  1);
179  DlClassifierUgs);
180 
181  IpcsClassifierRecord UlClassifierUgs(SSinterfaces.GetAddress(1),
182  Ipv4Mask("255.255.255.255"),
183  Ipv4Address("0.0.0.0"),
184  Ipv4Mask("0.0.0.0"),
185  0,
186  65000,
187  100,
188  100,
189  17,
190  1);
193  UlClassifierUgs);
194  ss[0]->AddServiceFlow(DlServiceFlowUgs);
195  ss[1]->AddServiceFlow(UlServiceFlowUgs);
196 
197  NS_LOG_INFO("Starting simulation.....");
198  Simulator::Run();
199 
200  ss[0] = nullptr;
201  ss[1] = nullptr;
202  bs = nullptr;
203 
205  NS_LOG_INFO("Done.");
206 
207  return 0;
208 }
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:42
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:257
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:77
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:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:186
SubscriberStationNetDevice subclass of WimaxNetDevice.
Definition: ss-net-device.h:50
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:1326
address
Definition: first.py:47
serverApps
Definition: first.py:54
clientApps
Definition: first.py:64
stack
Definition: first.py:44
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:302
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition: log.h:104
cmd
Definition: second.py:40
bool verbose