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 }
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition: net-device-container.h:42
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::InetSocketAddress
an Inet address class
Definition: inet-socket-address.h:41
ns3::DataRateValue
AttributeValue implementation for DataRate.
Definition: data-rate.h:298
ns3::YansWifiChannelHelper::Default
static YansWifiChannelHelper Default(void)
Create a channel helper in a default working state.
Definition: yans-wifi-helper.cc:41
ns3::YansWifiPhyHelper
Make it easy to create and manage PHY objects for the YANS model.
Definition: yans-wifi-helper.h:161
ns3::CommandLine
Parse command-line arguments.
Definition: command-line.h:228
ns3::BooleanValue
AttributeValue implementation for Boolean.
Definition: boolean.h:37
ns3::LOG_LEVEL_INFO
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition: log.h:107
ns3::Node::GetId
uint32_t GetId(void) const
Definition: node.cc:109
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::ApplicationContainer::Stop
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Definition: application-container.cc:107
ns3::WifiHelper
helps to create WifiNetDevice objects
Definition: wifi-helper.h:327
ns3::Ipv4AddressHelper
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Definition: ipv4-address-helper.h:48
ns3::RectangleValue
AttributeValue implementation for Rectangle.
Definition: rectangle.h:97
third.channel
channel
Definition: third.py:92
ns3::LogComponentEnable
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:361
ns3::WifiPhyHelper::DLT_IEEE802_11_RADIO
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
Definition: wifi-helper.h:180
third.mac
mac
Definition: third.py:99
ns3::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
ns3::SsidValue
AttributeValue implementation for Ssid.
Definition: ssid.h:105
ns3::Ssid
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:36
third.wifi
wifi
Definition: third.py:96
ns3::Ptr< Node >
ns3::DataRate
Class for representing data rates.
Definition: data-rate.h:89
ns3::Ipv4GlobalRoutingHelper::PopulateRoutingTables
static void PopulateRoutingTables(void)
Build a routing database and initialize the routing tables of the nodes in the simulation.
Definition: ipv4-global-routing-helper.cc:61
first.stack
stack
Definition: first.py:41
ns3::Simulator::Stop
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:180
ns3::Address
a polymophic address class
Definition: address.h:91
ns3::OnOffHelper
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:43
ns3::Ipv4InterfaceContainer
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Definition: ipv4-interface-container.h:55
first.address
address
Definition: first.py:44
second.cmd
cmd
Definition: second.py:35
ns3::Rectangle
a 2d rectangle
Definition: rectangle.h:35
ns3::LOG_LEVEL_DEBUG
@ LOG_LEVEL_DEBUG
LOG_DEBUG and above.
Definition: log.h:104
ns3::Simulator::Run
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
ns3::StringValue
Hold variables of type string.
Definition: string.h:41
ns3::ApplicationContainer::Start
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
Definition: application-container.cc:87
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
ns3::Simulator::Destroy
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
ns3::ApplicationContainer
holds a vector of ns3::Application pointers.
Definition: application-container.h:43
third.ssid
ssid
Definition: third.py:100
ns3::Ipv4InterfaceContainer::GetAddress
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Definition: ipv4-interface-container.cc:59
ns3::UintegerValue
Hold an unsigned integer type.
Definition: uinteger.h:44
ns3::YansWifiChannelHelper
manage and create wifi channel objects for the YANS model.
Definition: yans-wifi-helper.h:37
ns3::WifiMacHelper
create MAC layers for a ns3::WifiNetDevice.
Definition: wifi-mac-helper.h:48
ns3::InternetStackHelper
aggregate IP/TCP/UDP functionality to existing Nodes.
Definition: internet-stack-helper.h:88
ns3::MobilityHelper
Helper class used to assign positions and mobility models to nodes.
Definition: mobility-helper.h:43
third.mobility
mobility
Definition: third.py:108
third.phy
phy
Definition: third.py:93
port
uint16_t port
Definition: dsdv-manet.cc:45