A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
wimax-simple.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 //
23 // Default network topology includes a base station (BS) and 2
24 // subscriber station (SS).
25 
26 // +-----+
27 // | SS0 |
28 // +-----+
29 // 10.1.1.1
30 // -------
31 // ((*))
32 //
33 // 10.1.1.7
34 // +------------+
35 // |Base Station| ==((*))
36 // +------------+
37 //
38 // ((*))
39 // -------
40 // 10.1.1.2
41 // +-----+
42 // | SS1 |
43 // +-----+
44 
45 #include "ns3/core-module.h"
46 #include "ns3/network-module.h"
47 #include "ns3/applications-module.h"
48 #include "ns3/mobility-module.h"
49 #include "ns3/config-store-module.h"
50 #include "ns3/wimax-module.h"
51 #include "ns3/internet-module.h"
52 #include "ns3/global-route-manager.h"
53 #include "ns3/ipcs-classifier-record.h"
54 #include "ns3/service-flow.h"
55 #include <iostream>
56 
57 NS_LOG_COMPONENT_DEFINE ("WimaxSimpleExample");
58 
59 using namespace ns3;
60 
61 int main (int argc, char *argv[])
62 {
63  bool verbose = false;
64 
65  int duration = 7, schedType = 0;
67 
68  CommandLine cmd;
69  cmd.AddValue ("scheduler", "type of scheduler to use with the network devices", schedType);
70  cmd.AddValue ("duration", "duration of the simulation in seconds", duration);
71  cmd.AddValue ("verbose", "turn on all WimaxNetDevice log components", verbose);
72  cmd.Parse (argc, argv);
73  LogComponentEnable ("UdpClient", LOG_LEVEL_INFO);
74  LogComponentEnable ("UdpServer", LOG_LEVEL_INFO);
75  switch (schedType)
76  {
77  case 0:
79  break;
80  case 1:
82  break;
83  case 2:
84  scheduler = WimaxHelper::SCHED_TYPE_RTPS;
85  break;
86  default:
88  }
89 
90  NodeContainer ssNodes;
91  NodeContainer bsNodes;
92 
93  ssNodes.Create (2);
94  bsNodes.Create (1);
95 
96  WimaxHelper wimax;
97 
98  NetDeviceContainer ssDevs, bsDevs;
99 
100  ssDevs = wimax.Install (ssNodes,
103  scheduler);
105 
106  wimax.EnableAscii ("bs-devices", bsDevs);
107  wimax.EnableAscii ("ss-devices", ssDevs);
108 
110 
111  for (int i = 0; i < 2; i++)
112  {
113  ss[i] = ssDevs.Get (i)->GetObject<SubscriberStationNetDevice> ();
115  }
116 
118 
119  bs = bsDevs.Get (0)->GetObject<BaseStationNetDevice> ();
120 
122  stack.Install (bsNodes);
123  stack.Install (ssNodes);
124 
126  address.SetBase ("10.1.1.0", "255.255.255.0");
127 
128  Ipv4InterfaceContainer SSinterfaces = address.Assign (ssDevs);
129  Ipv4InterfaceContainer BSinterface = address.Assign (bsDevs);
130 
131  if (verbose)
132  {
133  wimax.EnableLogComponents (); // Turn on all wimax logging
134  }
135  /*------------------------------*/
136  UdpServerHelper udpServer;
138  UdpClientHelper udpClient;
140 
141  udpServer = UdpServerHelper (100);
142 
143  serverApps = udpServer.Install (ssNodes.Get (0));
144  serverApps.Start (Seconds (6));
145  serverApps.Stop (Seconds (duration));
146 
147  udpClient = UdpClientHelper (SSinterfaces.GetAddress (0), 100);
148  udpClient.SetAttribute ("MaxPackets", UintegerValue (1200));
149  udpClient.SetAttribute ("Interval", TimeValue (Seconds (0.5)));
150  udpClient.SetAttribute ("PacketSize", UintegerValue (1024));
151 
152  clientApps = udpClient.Install (ssNodes.Get (1));
153  clientApps.Start (Seconds (6));
154  clientApps.Stop (Seconds (duration));
155 
156  Simulator::Stop (Seconds (duration + 0.1));
157 
158  wimax.EnablePcap ("wimax-simple-ss0", ssNodes.Get (0)->GetId (), ss[0]->GetIfIndex ());
159  wimax.EnablePcap ("wimax-simple-ss1", ssNodes.Get (1)->GetId (), ss[1]->GetIfIndex ());
160  wimax.EnablePcap ("wimax-simple-bs0", bsNodes.Get (0)->GetId (), bs->GetIfIndex ());
161 
162  IpcsClassifierRecord DlClassifierUgs (Ipv4Address ("0.0.0.0"),
163  Ipv4Mask ("0.0.0.0"),
164  SSinterfaces.GetAddress (0),
165  Ipv4Mask ("255.255.255.255"),
166  0,
167  65000,
168  100,
169  100,
170  17,
171  1);
174  DlClassifierUgs);
175 
176  IpcsClassifierRecord UlClassifierUgs (SSinterfaces.GetAddress (1),
177  Ipv4Mask ("255.255.255.255"),
178  Ipv4Address ("0.0.0.0"),
179  Ipv4Mask ("0.0.0.0"),
180  0,
181  65000,
182  100,
183  100,
184  17,
185  1);
188  UlClassifierUgs);
189  ss[0]->AddServiceFlow (DlServiceFlowUgs);
190  ss[1]->AddServiceFlow (UlServiceFlowUgs);
191 
192  NS_LOG_INFO ("Starting simulation.....");
193  Simulator::Run ();
194 
195  ss[0] = 0;
196  ss[1] = 0;
197  bs = 0;
198 
200  NS_LOG_INFO ("Done.");
201 
202  return 0;
203 }
holds a vector of ns3::Application pointers.
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
An migration-based uplink scheduler.
Definition: wimax-helper.h:90
holds a vector of std::pair of Ptr and interface index.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:222
SchedulerType
Scheduler Type Different implementations of uplink/downlink scheduler.
Definition: wimax-helper.h:86
void SetModulationType(WimaxPhy::ModulationType modulationType)
Set the most efficient modulation and coding scheme (MCS) supported by the device.
static void Run(void)
Run the simulation until one of:
Definition: simulator.cc:157
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
aggregate IP/TCP/UDP functionality to existing Nodes.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:223
NetDeviceContainer Install(NodeContainer c, NetDeviceType type, PhyType phyType, SchedulerType schedulerType)
ApplicationContainer Install(NodeContainer c)
tuple clientApps
Definition: first.py:53
A simple scheduler - rtPS based scheduler.
Definition: wimax-helper.h:89
Create a client application which sends UDP packets carrying a 32bit sequence number and a 64 bit tim...
hold objects of type ns3::Time
Definition: nstime.h:1008
Hold an unsigned integer type.
Definition: uinteger.h:46
holds a vector of ns3::NetDevice pointers
Create a server application which waits for input UDP packets and uses the information carried into t...
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
int main(int argc, char *argv[])
Definition: wimax-simple.cc:61
Parse command-line arguments.
Definition: command-line.h:177
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
tuple serverApps
Definition: first.py:44
void SetAttribute(std::string name, const AttributeValue &value)
Record an attribute to be set in each Application after it is is created.
virtual uint32_t GetIfIndex(void) const
keep track of a set of node pointers.
This class implements service flows as described by the IEEE-802.16 standard.
Definition: service-flow.h:39
tuple stack
Definition: first.py:34
void EnableAscii(std::string prefix, Ptr< NetDevice > nd, bool explicitFilename=false)
Enable ascii trace output on the indicated net device.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
ApplicationContainer Install(NodeContainer c)
Create one UDP server application on each of the Nodes in the NodeContainer.
uint32_t GetId(void) const
Definition: node.cc:106
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Definition: command-line.h:435
static void Stop(void)
If an event invokes this method, it will be the last event scheduled by the Simulator::run method bef...
Definition: simulator.cc:165
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
ServiceFlow CreateServiceFlow(ServiceFlow::Direction direction, ServiceFlow::SchedulingType schedulinType, IpcsClassifierRecord classifier)
Creates a transport service flow.
helps to manage and create WimaxNetDevice objects
Definition: wimax-helper.h:59
void Parse(int argc, char *argv[])
Parse the program arguments.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
tuple address
Definition: first.py:37
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
static void EnableLogComponents(void)
Helper to enable all WimaxNetDevice log components with one statement.
void AddServiceFlow(ServiceFlow *sf)
adds a new service flow
A simple priority-based FCFS scheduler.
Definition: wimax-helper.h:88
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:318
bool verbose
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const