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 {
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.SetChannel (channel.Create ());
78 
81  /* disable fragmentation */
82  wifi.SetRemoteStationManager ("ns3::AarfWifiManager", "FragmentationThreshold", UintegerValue (2500));
83 
84  Ssid ssid ("My-network");
85 
86  mac.SetType ("ns3::StaWifiMac",
87  "QosSupported", BooleanValue (true),
88  "Ssid", SsidValue (ssid),
89  /* setting blockack threshold for sta's BE queue */
90  "BE_BlockAckThreshold", UintegerValue (2),
91  /* setting block inactivity timeout to 3*1024 = 3072 microseconds */
92  "BE_BlockAckInactivityTimeout", UintegerValue (3));
93  NetDeviceContainer staDevice = wifi.Install (phy, mac, sta);
94 
95  mac.SetType ("ns3::ApWifiMac",
96  "QosSupported", BooleanValue (true),
97  "Ssid", SsidValue (ssid),
98  "BE_BlockAckThreshold", UintegerValue (0));
99  NetDeviceContainer apDevice = wifi.Install (phy, mac, ap);
100 
101  /* Setting mobility model */
103 
104  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
105  "MinX", DoubleValue (0.0),
106  "MinY", DoubleValue (0.0),
107  "DeltaX", DoubleValue (5.0),
108  "DeltaY", DoubleValue (10.0),
109  "GridWidth", UintegerValue (3),
110  "LayoutType", StringValue ("RowFirst"));
111 
112  mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
113  "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
114  mobility.Install (sta);
115 
116  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
117  mobility.Install (ap);
118 
119  /* Internet stack*/
121  stack.Install (sta);
122  stack.Install (ap);
123 
125 
126  address.SetBase ("192.168.1.0", "255.255.255.0");
129  staIf = address.Assign (staDevice);
130  apIf = address.Assign (apDevice);
131 
132  /* Setting applications */
133 
134  uint16_t port = 9;
135  DataRate dataRate ("1Mb/s");
136  OnOffHelper onOff ("ns3::UdpSocketFactory", Address (InetSocketAddress (apIf.GetAddress (0), port)));
137  onOff.SetAttribute ("DataRate", DataRateValue (dataRate));
138  onOff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.01]"));
139  onOff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=8]"));
140  onOff.SetAttribute ("PacketSize", UintegerValue (50));
141 
142  ApplicationContainer staApps = onOff.Install (sta);
143 
144  staApps.Start (Seconds (1.0));
145  staApps.Stop (Seconds (10.0));
146 
148 
149  Simulator::Stop (Seconds (10.0));
150 
151  phy.EnablePcap ("test-blockack", ap->GetId (), 0);
152  Simulator::Run ();
154 
155  return 0;
156 }
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:226
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
aggregate IP/TCP/UDP functionality to existing Nodes.
cmd
Definition: second.py:35
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
helps to create WifiNetDevice objects
Definition: wifi-helper.h:230
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:34
uint16_t port
Definition: dsdv-manet.cc:45
a polymophic address class
Definition: address.h:90
channel
Definition: third.py:85
mobility
Definition: third.py:101
phy
Definition: third.py:86
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:369
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Hold an unsigned integer type.
Definition: uinteger.h:44
ssid
Definition: third.py:93
LOG_INFO and above.
Definition: log.h:104
holds a vector of ns3::NetDevice pointers
mac
Definition: third.py:92
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:213
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:190
Every class exported by the ns3 library is enclosed in the ns3 namespace.
address
Definition: first.py:37
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:89
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:101
AttributeValue implementation for DataRate.
Definition: data-rate.h:242
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:234
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
AttributeValue implementation for Ssid.
Definition: ssid.h:110
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
a 2d rectangle
Definition: rectangle.h:34
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.