A Discrete-Event Network Simulator
API
wifi-ac-mapping-test-suite.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 Universita' degli Studi di Napoli Federico II
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: Stefano Avallone <stavallo@unina.it>
19  */
20 
21 #include "ns3/test.h"
22 #include "ns3/simulator.h"
23 #include "ns3/log.h"
24 #include "ns3/uinteger.h"
25 #include "ns3/boolean.h"
26 #include "ns3/string.h"
27 #include "ns3/double.h"
28 #include "ns3/pointer.h"
29 #include "ns3/ssid.h"
30 #include "ns3/data-rate.h"
31 #include "ns3/inet-socket-address.h"
32 #include "ns3/packet-sink.h"
33 #include "ns3/wifi-helper.h"
34 #include "ns3/wifi-net-device.h"
35 #include "ns3/wifi-mac.h"
36 #include "ns3/wifi-mac-queue.h"
37 #include "ns3/edca-txop-n.h"
38 #include "ns3/yans-wifi-helper.h"
39 #include "ns3/mobility-helper.h"
40 #include "ns3/internet-stack-helper.h"
41 #include "ns3/ipv4-address-helper.h"
42 #include "ns3/packet-sink-helper.h"
43 #include "ns3/on-off-helper.h"
44 
45 using namespace ns3;
46 
47 NS_LOG_COMPONENT_DEFINE ("WifiAcMappingTest");
48 
50 {
51 public:
52  WifiAcMappingTest (uint8_t tos, uint8_t expectedQueue);
53  virtual void DoRun (void);
54 
55 private:
56  uint8_t m_tos;
57  uint8_t m_expectedQueue;
58 };
59 
60 WifiAcMappingTest::WifiAcMappingTest (uint8_t tos, uint8_t expectedQueue)
61  : TestCase ("User priority to Access Category mapping test"),
62  m_tos (tos),
63  m_expectedQueue (expectedQueue)
64 {
65 }
66 
67 void
69 {
71  WifiMacHelper wifiMac;
72  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
73  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
74  wifiPhy.SetChannel (wifiChannel.Create ());
75 
76  Ssid ssid = Ssid ("wifi-ac-mapping");
77  wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
78 
79  // Setup the AP, which will be the source of traffic for this test
80  NodeContainer ap;
81  ap.Create (1);
82  wifiMac.SetType ("ns3::ApWifiMac",
83  "QosSupported", BooleanValue (true),
84  "Ssid", SsidValue (ssid));
85 
86  NetDeviceContainer apDev = wifi.Install (wifiPhy, wifiMac, ap);
87 
88  // Setup one STA, which will be the sink for traffic in this test.
89  NodeContainer sta;
90  sta.Create (1);
91  wifiMac.SetType ("ns3::StaWifiMac",
92  "QosSupported", BooleanValue (true),
93  "Ssid", SsidValue (ssid));
94  NetDeviceContainer staDev = wifi.Install (wifiPhy, wifiMac, sta);
95 
96  // Our devices will have fixed positions
98  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
99  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
100  "MinX", DoubleValue (0.0),
101  "MinY", DoubleValue (0.0),
102  "DeltaX", DoubleValue (5.0),
103  "DeltaY", DoubleValue (10.0),
104  "GridWidth", UintegerValue (2),
105  "LayoutType", StringValue ("RowFirst"));
106  mobility.Install (sta);
107  mobility.Install (ap);
108 
109  // Now we install internet stacks on our devices
111  stack.Install (ap);
112  stack.Install (sta);
113 
115  address.SetBase ("192.168.0.0", "255.255.255.0");
116  Ipv4InterfaceContainer staNodeInterface, apNodeInterface;
117  staNodeInterface = address.Assign (staDev);
118  apNodeInterface = address.Assign (apDev);
119 
120  uint16_t udpPort = 50000;
121 
122  PacketSinkHelper packetSink ("ns3::UdpSocketFactory",
123  InetSocketAddress (Ipv4Address::GetAny (), udpPort));
124  ApplicationContainer sinkApp = packetSink.Install (sta.Get (0));
125  sinkApp.Start (Seconds (0));
126  sinkApp.Stop (Seconds (3.0));
127 
128  // The packet source is an on-off application on the AP device
129  InetSocketAddress dest (staNodeInterface.GetAddress (0), udpPort);
130  dest.SetTos (m_tos);
131  OnOffHelper onoff ("ns3::UdpSocketFactory", dest);
132  onoff.SetConstantRate (DataRate ("5kbps"), 500);
133  ApplicationContainer sourceApp = onoff.Install (ap.Get (0));
134  sourceApp.Start (Seconds (1.0));
135  sourceApp.Stop (Seconds (3.0));
136 
137  // The first packet will be transmitted at time 1+(500*8)/5000 = 1.8s.
138  // Let this packet be transmitted successfully, so that the AP can resolve
139  // the IP address of the station and get its MAC address.
140  // The second packet will be transmitted at time 1.8+(500*8)/5000 = 2.6s.
141  // Put the AP in sleep mode at time 2.0s, so that the second packet remains
142  // in a wifi mac queue and we can discover the queue it has been sent to.
143  Ptr<WifiPhy> apPhy = DynamicCast<WifiNetDevice> (apDev.Get (0))->GetPhy ();
144  Simulator::ScheduleWithContext (ap.Get (0)->GetId (), Seconds (2.0),
145  &WifiPhy::SetSleepMode, apPhy);
146 
147  Simulator::Stop (Seconds (4.0));
148 
149  Ptr<WifiMac> apMac = DynamicCast<WifiNetDevice> (apDev.Get (0))->GetMac ();
150  PointerValue ptr;
151  Ptr<WifiMacQueue> queues[4];
152  // Get the four wifi mac queues and set their MaxDelay attribute to a large
153  // value, so that packets are not removed by the Cleanup method
154  apMac->GetAttribute ("BE_EdcaTxopN", ptr);
155  queues[0] = ptr.Get<EdcaTxopN> ()->GetEdcaQueue ();
156  queues[0]->SetAttribute ("MaxDelay", TimeValue (Seconds (10.0)));
157 
158  apMac->GetAttribute ("BK_EdcaTxopN", ptr);
159  queues[1] = ptr.Get<EdcaTxopN> ()->GetEdcaQueue ();
160  queues[1]->SetAttribute ("MaxDelay", TimeValue (Seconds (10.0)));
161 
162  apMac->GetAttribute ("VI_EdcaTxopN", ptr);
163  queues[2] = ptr.Get<EdcaTxopN> ()->GetEdcaQueue ();
164  queues[2]->SetAttribute ("MaxDelay", TimeValue (Seconds (10.0)));
165 
166  apMac->GetAttribute ("VO_EdcaTxopN", ptr);
167  queues[3] = ptr.Get<EdcaTxopN> ()->GetEdcaQueue ();
168  queues[3]->SetAttribute ("MaxDelay", TimeValue (Seconds (10.0)));
169 
170 
171  Simulator::Run ();
172 
173  for (uint32_t i = 0; i < 4; i++)
174  {
175  if (i == m_expectedQueue)
176  {
177  NS_TEST_ASSERT_MSG_EQ (queues[i]->GetSize (), 1, "There is no packet in the expected queue " << i);
178  }
179  else
180  {
181  NS_TEST_ASSERT_MSG_EQ (queues[i]->GetSize (), 0, "Unexpectedly, there is a packet in queue " << i);
182  }
183  }
184 
185  uint32_t totalOctetsThrough =
186  DynamicCast<PacketSink>(sinkApp.Get (0))->GetTotalRx ();
187 
188  // Check that the first packet has been received
189  NS_TEST_ASSERT_MSG_EQ (totalOctetsThrough, 500, "A single packet should have been received");
190 
191  Simulator::Destroy ();
192 }
193 
194 
196 {
197 public:
199 };
200 
202  : TestSuite ("ns3-wifi-ac-mapping", SYSTEM)
203 {
204  AddTestCase (new WifiAcMappingTest (0xb8, 2), TestCase::QUICK); // EF in AC_VI
205  AddTestCase (new WifiAcMappingTest (0x28, 1), TestCase::QUICK); // AF11 in AC_BK
206  AddTestCase (new WifiAcMappingTest (0x70, 0), TestCase::QUICK); // AF32 in AC_BE
207  AddTestCase (new WifiAcMappingTest (0xc0, 3), TestCase::QUICK); // CS7 in AC_VO
208 }
209 
holds a vector of ns3::Application pointers.
WifiAcMappingTest(uint8_t tos, uint8_t expectedQueue)
Ptr< T > Get(void) const
Definition: pointer.h:194
an Inet address class
AttributeValue implementation for Boolean.
Definition: boolean.h:34
holds a vector of std::pair of Ptr and interface index.
Ptr< YansWifiChannel > Create(void) const
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
Hold variables of type string.
Definition: string.h:41
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Make it easy to create and manage PHY objects for the yans model.
A suite of tests to run.
Definition: test.h:1333
#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.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
encapsulates test code
Definition: test.h:1147
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
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer c) const
Definition: wifi-helper.cc:712
Class for representing data rates.
Definition: data-rate.h:88
void SetChannel(Ptr< YansWifiChannel > channel)
This queue contains packets for a particular access class.
Definition: edca-txop-n.h:86
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
tuple mobility
Definition: third.py:101
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
AttributeValue implementation for Time.
Definition: nstime.h:957
Hold an unsigned integer type.
Definition: uinteger.h:44
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition: test.h:161
holds a vector of ns3::NetDevice pointers
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetConstantRate(DataRate dataRate, uint32_t packetSize=512)
Helper function to set a constant rate source.
keep track of a set of node pointers.
Ptr< Application > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Hold objects of type Ptr.
Definition: pointer.h:36
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.
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:229
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...
uint32_t GetId(void) const
Definition: node.cc:107
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
static WifiAcMappingTestSuite wifiAcMappingTestSuite
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
AttributeValue implementation for Ssid.
Definition: ssid.h:95
ApplicationContainer Install(NodeContainer c) const
Install an ns3::PacketSinkApplication on each node of the input container configured with all the att...
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
tuple wifi
Definition: third.py:89
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
tuple address
Definition: first.py:37
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
virtual void DoRun(void)
Implementation to actually run this TestCase.
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:191
ApplicationContainer Install(NodeContainer c) const
Install an ns3::OnOffApplication on each node of the input container configured with all the attribut...
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