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 
42 #include "ns3/core-module.h"
43 #include "ns3/internet-module.h"
44 #include "ns3/network-module.h"
45 #include "ns3/applications-module.h"
46 #include "ns3/wifi-module.h"
47 #include "ns3/mobility-module.h"
48 
49 using namespace ns3;
50 
51 NS_LOG_COMPONENT_DEFINE ("Test-block-ack");
52 
53 int main (int argc, char * argv[])
54 {
56  cmd.Parse (argc, argv);
57 
58  LogComponentEnable ("EdcaTxopN", LOG_LEVEL_DEBUG);
59  LogComponentEnable ("BlockAckManager", LOG_LEVEL_INFO);
60 
61  Ptr<Node> sta = CreateObject<Node> ();
62  Ptr<Node> ap = CreateObject<Node> ();
63 
66  phy.SetChannel (channel.Create ());
67 
70  /* disable fragmentation */
71  wifi.SetRemoteStationManager ("ns3::AarfWifiManager", "FragmentationThreshold", UintegerValue (2500));
72 
73  Ssid ssid ("My-network");
74 
75  mac.SetType ("ns3::StaWifiMac",
76  "QosSupported", BooleanValue (true),
77  "Ssid", SsidValue (ssid),
78  /* setting blockack threshold for sta's BE queue */
79  "BE_BlockAckThreshold", UintegerValue (2),
80  /* setting block inactivity timeout to 3*1024 = 3072 microseconds */
81  "BE_BlockAckInactivityTimeout", UintegerValue (3));
82  NetDeviceContainer staDevice = wifi.Install (phy, mac, sta);
83 
84  mac.SetType ("ns3::ApWifiMac",
85  "QosSupported", BooleanValue (true),
86  "Ssid", SsidValue (ssid),
87  "BE_BlockAckThreshold", UintegerValue (0));
88  NetDeviceContainer apDevice = wifi.Install (phy, mac, ap);
89 
90  /* Setting mobility model */
92 
93  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
94  "MinX", DoubleValue (0.0),
95  "MinY", DoubleValue (0.0),
96  "DeltaX", DoubleValue (5.0),
97  "DeltaY", DoubleValue (10.0),
98  "GridWidth", UintegerValue (3),
99  "LayoutType", StringValue ("RowFirst"));
100 
101  mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
102  "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
103  mobility.Install (sta);
104 
105  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
106  mobility.Install (ap);
107 
108  /* Internet stack*/
110  stack.Install (sta);
111  stack.Install (ap);
112 
114 
115  address.SetBase ("192.168.1.0", "255.255.255.0");
118  staIf = address.Assign (staDevice);
119  apIf = address.Assign (apDevice);
120 
121  /* Setting applications */
122 
123  uint16_t port = 9;
124 
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:34
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:683
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:201
#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:231
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
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer c) const
Definition: wifi-helper.cc:712
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:351
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
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:165
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:38
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:209
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
AttributeValue implementation for Ssid.
Definition: ssid.h:95
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