A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 const* argv[])
54 {
55  LogComponentEnable ("EdcaTxopN", LOG_LEVEL_DEBUG);
56  LogComponentEnable ("BlockAckManager", LOG_LEVEL_INFO);
57 
58  Ptr<Node> sta = CreateObject<Node> ();
59  Ptr<Node> ap = CreateObject<Node> ();
60 
63  phy.SetChannel (channel.Create ());
64 
67  /* disable fragmentation */
68  wifi.SetRemoteStationManager ("ns3::AarfWifiManager", "FragmentationThreshold", UintegerValue (2500));
69 
70  Ssid ssid ("My-network");
71 
72  mac.SetType ("ns3::StaWifiMac",
73  "Ssid", SsidValue (ssid),
74  "ActiveProbing", BooleanValue (false));
75  /* setting blockack threshold for sta's BE queue */
77  /* setting block inactivity timeout to 3*1024 = 3072 microseconds */
78  //mac.SetBlockAckInactivityTimeoutForAc (AC_BE, 3);
79  NetDeviceContainer staDevice = wifi.Install (phy, mac, sta);
80 
81  mac.SetType ("ns3::ApWifiMac",
82  "Ssid", SsidValue (ssid));
84  NetDeviceContainer apDevice = wifi.Install (phy, mac, ap);
85 
86  /* Setting mobility model */
87  MobilityHelper mobility;
88 
89  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
90  "MinX", DoubleValue (0.0),
91  "MinY", DoubleValue (0.0),
92  "DeltaX", DoubleValue (5.0),
93  "DeltaY", DoubleValue (10.0),
94  "GridWidth", UintegerValue (3),
95  "LayoutType", StringValue ("RowFirst"));
96 
97  mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
98  "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
99  mobility.Install (sta);
100 
101  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
102  mobility.Install (ap);
103 
104  /* Internet stack*/
106  stack.Install (sta);
107  stack.Install (ap);
108 
110 
111  address.SetBase ("192.168.1.0", "255.255.255.0");
114  staIf = address.Assign (staDevice);
115  apIf = address.Assign (apDevice);
116 
117  /* Setting applications */
118 
119  uint16_t port = 9;
120 
121  DataRate dataRate ("1Mb/s");
122  OnOffHelper onOff ("ns3::UdpSocketFactory", Address (InetSocketAddress (apIf.GetAddress (0), port)));
123  onOff.SetAttribute ("DataRate", DataRateValue (dataRate));
124  onOff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.01]"));
125  onOff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=8]"));
126  onOff.SetAttribute ("PacketSize", UintegerValue (50));
127 
128  ApplicationContainer staApps = onOff.Install (sta);
129 
130  staApps.Start (Seconds (1.0));
131  staApps.Stop (Seconds (10.0));
132 
134 
135  Simulator::Stop (Seconds (10.0));
136 
137  phy.EnablePcap ("test-blockack-2", ap->GetId (), 0);
138  Simulator::Run ();
140 
141  return 0;
142 }