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 
21 /**
22  * This is a simple example in order to show how 802.11e compressed block ack mechanism could be used.
23  *
24  * Network topology:
25  *
26  *  Wifi 192.168.1.0
27  *
28  *        AP
29  *   *    *
30  *   |    |
31  *   n1   n2
32  *
33  * In this example a QoS sta sends UDP datagram packets to access point. On the access point
34  * there is no application installed so it replies to every packet with an ICMP frame. However
35  * our attention is on originator sta n1. We have set blockAckThreshold (minimum number of packets to use
36  * block ack) to 2 so if there are in the BestEffort queue more than 2 packets a block ack will be
37  * negotiated. We also set a timeout for block ack inactivity to 3 blocks of 1024 microseconds. This timer is
38  * reset when:
39  *    - the originator receives a block ack frame.
40  *    - the recipient receives a block ack request or a MPDU with ack policy Block Ack.
41  */
42 
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 
main(int argc,char * argv[])64 int main (int argc, char * argv[])
65 {
66   CommandLine cmd (__FILE__);
67   cmd.Parse (argc, argv);
68 
69   LogComponentEnable ("QosTxop", LOG_LEVEL_DEBUG);
70   LogComponentEnable ("BlockAckManager", LOG_LEVEL_INFO);
71 
72   Ptr<Node> sta = CreateObject<Node> ();
73   Ptr<Node> ap = CreateObject<Node> ();
74 
75   YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
76   YansWifiPhyHelper phy;
77   phy.SetPcapDataLinkType (WifiPhyHelper::DLT_IEEE802_11_RADIO);
78   phy.SetChannel (channel.Create ());
79 
80   WifiHelper wifi;
81   WifiMacHelper mac;
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 */
103   MobilityHelper mobility;
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*/
121   InternetStackHelper stack;
122   stack.Install (sta);
123   stack.Install (ap);
124 
125   Ipv4AddressHelper address;
126 
127   address.SetBase ("192.168.1.0", "255.255.255.0");
128   Ipv4InterfaceContainer staIf;
129   Ipv4InterfaceContainer apIf;
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 
148   Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
149 
150   Simulator::Stop (Seconds (10.0));
151 
152   phy.EnablePcap ("test-blockack", ap->GetId (), 0);
153   Simulator::Run ();
154   Simulator::Destroy ();
155 
156   return 0;
157 }
158