A Discrete-Event Network Simulator
API
wifi-blockack.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 MIRKO BANCHI
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: Mirko Banchi <mk.banchi@gmail.com>
19  */
20 
43 #include "ns3/command-line.h"
44 #include "ns3/uinteger.h"
45 #include "ns3/boolean.h"
46 #include "ns3/double.h"
47 #include "ns3/string.h"
48 #include "ns3/log.h"
49 #include "ns3/yans-wifi-helper.h"
50 #include "ns3/ssid.h"
51 #include "ns3/mobility-helper.h"
52 #include "ns3/on-off-helper.h"
53 #include "ns3/yans-wifi-channel.h"
54 #include "ns3/mobility-model.h"
55 #include "ns3/rectangle.h"
56 #include "ns3/internet-stack-helper.h"
57 #include "ns3/ipv4-address-helper.h"
58 #include "ns3/ipv4-global-routing-helper.h"
59 
60 using namespace ns3;
61 
62 NS_LOG_COMPONENT_DEFINE ("Test-block-ack");
63 
64 int main (int argc, char * argv[])
65 {
66  CommandLine cmd (__FILE__);
67  cmd.Parse (argc, argv);
68 
70  LogComponentEnable ("BlockAckManager", LOG_LEVEL_INFO);
71 
72  Ptr<Node> sta = CreateObject<Node> ();
73  Ptr<Node> ap = CreateObject<Node> ();
74 
77  phy.SetPcapDataLinkType (WifiPhyHelper::DLT_IEEE802_11_RADIO);
78  phy.SetChannel (channel.Create ());
79 
82  /* disable fragmentation */
83  wifi.SetRemoteStationManager ("ns3::AarfWifiManager", "FragmentationThreshold", UintegerValue (2500));
84 
85  Ssid ssid ("My-network");
86 
87  mac.SetType ("ns3::StaWifiMac",
88  "QosSupported", BooleanValue (true),
89  "Ssid", SsidValue (ssid),
90  /* setting blockack threshold for sta's BE queue */
91  "BE_BlockAckThreshold", UintegerValue (2),
92  /* setting block inactivity timeout to 3*1024 = 3072 microseconds */
93  "BE_BlockAckInactivityTimeout", UintegerValue (3));
94  NetDeviceContainer staDevice = wifi.Install (phy, mac, sta);
95 
96  mac.SetType ("ns3::ApWifiMac",
97  "QosSupported", BooleanValue (true),
98  "Ssid", SsidValue (ssid),
99  "BE_BlockAckThreshold", UintegerValue (0));
100  NetDeviceContainer apDevice = wifi.Install (phy, mac, ap);
101 
102  /* Setting mobility model */
104 
105  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
106  "MinX", DoubleValue (0.0),
107  "MinY", DoubleValue (0.0),
108  "DeltaX", DoubleValue (5.0),
109  "DeltaY", DoubleValue (10.0),
110  "GridWidth", UintegerValue (3),
111  "LayoutType", StringValue ("RowFirst"));
112 
113  mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
114  "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
115  mobility.Install (sta);
116 
117  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
118  mobility.Install (ap);
119 
120  /* Internet stack*/
122  stack.Install (sta);
123  stack.Install (ap);
124 
126 
127  address.SetBase ("192.168.1.0", "255.255.255.0");
130  staIf = address.Assign (staDevice);
131  apIf = address.Assign (apDevice);
132 
133  /* Setting applications */
134 
135  uint16_t port = 9;
136  DataRate dataRate ("1Mb/s");
137  OnOffHelper onOff ("ns3::UdpSocketFactory", Address (InetSocketAddress (apIf.GetAddress (0), port)));
138  onOff.SetAttribute ("DataRate", DataRateValue (dataRate));
139  onOff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.01]"));
140  onOff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=8]"));
141  onOff.SetAttribute ("PacketSize", UintegerValue (50));
142 
143  ApplicationContainer staApps = onOff.Install (sta);
144 
145  staApps.Start (Seconds (1.0));
146  staApps.Stop (Seconds (10.0));
147 
149 
150  Simulator::Stop (Seconds (10.0));
151 
152  phy.EnablePcap ("test-blockack", ap->GetId (), 0);
153  Simulator::Run ();
155 
156  return 0;
157 }
holds a vector of ns3::Application pointers.
an Inet address class
AttributeValue implementation for Boolean.
Definition: boolean.h:36
holds a vector of std::pair of Ptr<Ipv4> and interface index.
static void PopulateRoutingTables(void)
Build a routing database and initialize the routing tables of the nodes in the simulation.
Hold variables of type string.
Definition: string.h:41
Make it easy to create and manage PHY objects for the YANS model.
static YansWifiChannelHelper Default(void)
Create a channel helper in a default working state.
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
aggregate IP/TCP/UDP functionality to existing Nodes.
cmd
Definition: second.py:35
helps to create WifiNetDevice objects
Definition: wifi-helper.h:326
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:42
stack
Definition: first.py:41
uint16_t port
Definition: dsdv-manet.cc:45
a polymophic address class
Definition: address.h:90
channel
Definition: third.py:92
mobility
Definition: third.py:108
phy
Definition: third.py:93
AttributeValue implementation for Rectangle.
Definition: rectangle.h:97
Class for representing data rates.
Definition: data-rate.h:88
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:361
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Hold an unsigned integer type.
Definition: uinteger.h:44
ssid
Definition: third.py:100
LOG_INFO and above.
Definition: log.h:107
holds a vector of ns3::NetDevice pointers
mac
Definition: third.py:99
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 arguments.
Definition: command-line.h:227
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
Every class exported by the ns3 library is enclosed in the ns3 namespace.
address
Definition: first.py:44
manage and create wifi channel objects for the YANS model.
create MAC layers for a ns3::WifiNetDevice.
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:35
wifi
Definition: third.py:96
Helper class used to assign positions and mobility models to nodes.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
LOG_DEBUG and above.
Definition: log.h:104
AttributeValue implementation for DataRate.
Definition: data-rate.h:298
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:180
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
AttributeValue implementation for Ssid.
Definition: ssid.h:105
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
Include Radiotap link layer information.
Definition: wifi-helper.h:180
a 2d rectangle
Definition: rectangle.h:34
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.