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/core-module.h"
44 #include "ns3/internet-module.h"
45 #include "ns3/network-module.h"
46 #include "ns3/applications-module.h"
47 #include "ns3/wifi-module.h"
48 #include "ns3/mobility-module.h"
49 
50 using namespace ns3;
51 
52 NS_LOG_COMPONENT_DEFINE ("Test-block-ack");
53 
54 int main (int argc, char * argv[])
55 {
57  cmd.Parse (argc, argv);
58 
59  LogComponentEnable ("EdcaTxopN", LOG_LEVEL_DEBUG);
60  LogComponentEnable ("BlockAckManager", LOG_LEVEL_INFO);
61 
62  Ptr<Node> sta = CreateObject<Node> ();
63  Ptr<Node> ap = CreateObject<Node> ();
64 
67  phy.SetChannel (channel.Create ());
68 
71  /* disable fragmentation */
72  wifi.SetRemoteStationManager ("ns3::AarfWifiManager", "FragmentationThreshold", UintegerValue (2500));
73 
74  Ssid ssid ("My-network");
75 
76  mac.SetType ("ns3::StaWifiMac",
77  "QosSupported", BooleanValue (true),
78  "Ssid", SsidValue (ssid),
79  /* setting blockack threshold for sta's BE queue */
80  "BE_BlockAckThreshold", UintegerValue (2),
81  /* setting block inactivity timeout to 3*1024 = 3072 microseconds */
82  "BE_BlockAckInactivityTimeout", UintegerValue (3));
83  NetDeviceContainer staDevice = wifi.Install (phy, mac, sta);
84 
85  mac.SetType ("ns3::ApWifiMac",
86  "QosSupported", BooleanValue (true),
87  "Ssid", SsidValue (ssid),
88  "BE_BlockAckThreshold", UintegerValue (0));
89  NetDeviceContainer apDevice = wifi.Install (phy, mac, ap);
90 
91  /* Setting mobility model */
93 
94  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
95  "MinX", DoubleValue (0.0),
96  "MinY", DoubleValue (0.0),
97  "DeltaX", DoubleValue (5.0),
98  "DeltaY", DoubleValue (10.0),
99  "GridWidth", UintegerValue (3),
100  "LayoutType", StringValue ("RowFirst"));
101 
102  mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
103  "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
104  mobility.Install (sta);
105 
106  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
107  mobility.Install (ap);
108 
109  /* Internet stack*/
111  stack.Install (sta);
112  stack.Install (ap);
113 
115 
116  address.SetBase ("192.168.1.0", "255.255.255.0");
119  staIf = address.Assign (staDevice);
120  apIf = address.Assign (apDevice);
121 
122  /* Setting applications */
123 
124  uint16_t port = 9;
125  DataRate dataRate ("1Mb/s");
126  OnOffHelper onOff ("ns3::UdpSocketFactory", Address (InetSocketAddress (apIf.GetAddress (0), port)));
127  onOff.SetAttribute ("DataRate", DataRateValue (dataRate));
128  onOff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.01]"));
129  onOff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=8]"));
130  onOff.SetAttribute ("PacketSize", UintegerValue (50));
131 
132  ApplicationContainer staApps = onOff.Install (sta);
133 
134  staApps.Start (Seconds (1.0));
135  staApps.Stop (Seconds (10.0));
136 
138 
139  Simulator::Stop (Seconds (10.0));
140 
141  phy.EnablePcap ("test-blockack-2", ap->GetId (), 0);
142  Simulator::Run ();
144 
145  return 0;
146 }
tuple channel
Definition: third.py:85
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 and interface index.
void SetRemoteStationManager(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Definition: wifi-helper.cc:719
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:201
aggregate IP/TCP/UDP functionality to existing Nodes.
LOG_INFO and above.
Definition: log.h:103
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
helps to create WifiNetDevice objects
Definition: wifi-helper.h:213
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:42
tuple cmd
Definition: second.py:35
uint16_t port
Definition: dsdv-manet.cc:44
a polymophic address class
Definition: address.h:90
AttributeValue implementation for Rectangle.
Definition: rectangle.h:97
Class for representing data rates.
Definition: data-rate.h:88
void SetChannel(Ptr< YansWifiChannel > channel)
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:369
tuple mobility
Definition: third.py:101
tuple phy
Definition: third.py:86
Hold an unsigned integer type.
Definition: uinteger.h:44
holds a vector of ns3::NetDevice pointers
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer::Iterator first, NodeContainer::Iterator last) const
Definition: wifi-helper.cc:748
tuple 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:205
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:190
LOG_DEBUG and above.
Definition: log.h:100
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
tuple ssid
Definition: third.py:93
manage and create wifi channel objects for the yans model.
create MAC layers for a ns3::WifiNetDevice.
tuple stack
Definition: first.py:34
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:35
virtual void SetType(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue(), std::string n10="", const AttributeValue &v10=EmptyAttributeValue())
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...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
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:993
AttributeValue implementation for Ssid.
Definition: ssid.h:117
void Parse(int argc, char *argv[])
Parse the program arguments.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
tuple wifi
Definition: third.py:89
tuple address
Definition: first.py:37
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
This class can be used to hold variables of floating point type such as 'double' or 'float'...
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.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const