A Discrete-Event Network Simulator
API
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
57using namespace ns3;
58
59NS_LOG_COMPONENT_DEFINE ("WimaxSimpleExample");
60
61int main (int argc, char *argv[])
62{
63 bool verbose = false;
64
65 int duration = 7, schedType = 0;
66 WimaxHelper::SchedulerType scheduler = WimaxHelper::SCHED_TYPE_SIMPLE;
67
68 CommandLine cmd (__FILE__);
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);
75 switch (schedType)
76 {
77 case 0:
78 scheduler = WimaxHelper::SCHED_TYPE_SIMPLE;
79 break;
80 case 1:
81 scheduler = WimaxHelper::SCHED_TYPE_MBQOS;
82 break;
83 case 2:
84 scheduler = WimaxHelper::SCHED_TYPE_RTPS;
85 break;
86 default:
87 scheduler = WimaxHelper::SCHED_TYPE_SIMPLE;
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,
101 WimaxHelper::DEVICE_TYPE_SUBSCRIBER_STATION,
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
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);
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
199 Simulator::Destroy ();
200 NS_LOG_INFO ("Done.");
201
202 return 0;
203}
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:53
Parse command-line arguments.
Definition: command-line.h:229
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:41
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:256
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(void) const
Definition: node.cc:109
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
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:74
This class implements service flows as described by the IEEE-802.16 standard.
Definition: service-flow.h:40
SubscriberStationNetDevice subclass of WimaxNetDevice.
Definition: ss-net-device.h:49
AttributeValue implementation for Time.
Definition: nstime.h:1308
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:44
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
static void EnableLogComponents(void)
Helper to enable all WimaxNetDevice log components with one statement.
NetDeviceContainer Install(NodeContainer c, NetDeviceType type, PhyType phyType, SchedulerType schedulerType)
ServiceFlow CreateServiceFlow(ServiceFlow::Direction direction, ServiceFlow::SchedulingType schedulinType, IpcsClassifierRecord classifier)
Creates a transport service flow.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
address
Definition: first.py:44
serverApps
Definition: first.py:52
clientApps
Definition: first.py:61
stack
Definition: first.py:41
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition: log.h:107
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:361
cmd
Definition: second.py:35
bool verbose