A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
wimax-simple.cc
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,
102  WimaxHelper::SIMPLE_PHY_TYPE_OFDM,
103  scheduler);
104  bsDevs = wimax.Install (bsNodes, WimaxHelper::DEVICE_TYPE_BASE_STATION, WimaxHelper::SIMPLE_PHY_TYPE_OFDM, 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> ();
114  ss[i]->SetModulationType (WimaxPhy::MODULATION_TYPE_QAM16_12);
115  }
116 
118 
119  bs = bsDevs.Get (0)->GetObject<BaseStationNetDevice> ();
120 
121  InternetStackHelper stack;
122  stack.Install (bsNodes);
123  stack.Install (ssNodes);
124 
125  Ipv4AddressHelper address;
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;
137  ApplicationContainer serverApps;
138  UdpClientHelper udpClient;
139  ApplicationContainer clientApps;
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);
172  ServiceFlow DlServiceFlowUgs = wimax.CreateServiceFlow (ServiceFlow::SF_DIRECTION_DOWN,
173  ServiceFlow::SF_TYPE_RTPS,
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);
186  ServiceFlow UlServiceFlowUgs = wimax.CreateServiceFlow (ServiceFlow::SF_DIRECTION_UP,
187  ServiceFlow::SF_TYPE_RTPS,
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:59
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:210
void SetModulationType(WimaxPhy::ModulationType modulationType)
Set the most efficient modulation and coding scheme (MCS) supported by the device.
static void Run(void)
Definition: simulator.cc:157
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
aggregate IP/TCP/UDP functionality to existing Nodes.
#define NS_LOG_INFO(msg)
Definition: log.h:264
NetDeviceContainer Install(NodeContainer c, NetDeviceType type, PhyType phyType, SchedulerType schedulerType)
ApplicationContainer Install(NodeContainer c)
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:700
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...
parse command-line argumentsInstances of this class can be used to parse command-line arguments: user...
Definition: command-line.h:50
static void Destroy(void)
Definition: simulator.cc:121
void SetAttribute(std::string name, const AttributeValue &value)
virtual uint32_t GetIfIndex(void) const
keep track of a set of node pointers.
void Install(std::string nodeName) const
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...
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Definition: nstime.h:586
ApplicationContainer Install(NodeContainer c)
uint32_t GetId(void) const
Definition: node.cc:105
void AddValue(const std::string &name, const std::string &help, T &value)
Definition: command-line.h:134
static void Stop(void)
Definition: simulator.cc:164
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
void Parse(int argc, char *argv[]) const
Definition: command-line.cc:84
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
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.
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)
void AddServiceFlow(ServiceFlow *sf)
adds a new service flow
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)
Definition: log.cc:311
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const