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/string.h"
22 #include "ns3/test.h"
23 #include "ns3/pointer.h"
24 #include "ns3/ssid.h"
25 #include "ns3/packet-sink.h"
26 #include "ns3/wifi-net-device.h"
27 #include "ns3/wifi-mac.h"
28 #include "ns3/wifi-mac-queue.h"
29 #include "ns3/qos-txop.h"
30 #include "ns3/yans-wifi-helper.h"
31 #include "ns3/mobility-helper.h"
32 #include "ns3/internet-stack-helper.h"
33 #include "ns3/ipv4-address-helper.h"
34 #include "ns3/packet-sink-helper.h"
35 #include "ns3/on-off-helper.h"
36 #include "ns3/traffic-control-helper.h"
37 #include "ns3/traffic-control-layer.h"
38 #include "ns3/llc-snap-header.h"
39 
40 using namespace ns3;
41 
42 NS_LOG_COMPONENT_DEFINE ("WifiAcMappingTest");
43 
51 {
52 public:
59  WifiAcMappingTest (uint8_t tos, uint8_t expectedQueue);
60  virtual void DoRun (void);
61 
62 private:
71  static void PacketEnqueuedInQueueDisc (uint8_t tos, uint16_t* count, Ptr<const QueueDiscItem> item);
80  static void PacketEnqueuedInWifiMacQueue (uint8_t tos, uint16_t* count, Ptr<const WifiMacQueueItem> item);
81  uint8_t m_tos;
82  uint16_t m_expectedQueue;
83  uint16_t m_QueueDiscCount[4];
84  uint16_t m_WifiMacQueueCount[4];
85 };
86 
87 WifiAcMappingTest::WifiAcMappingTest (uint8_t tos, uint8_t expectedQueue)
88  : TestCase ("User priority to Access Category mapping test. Checks that packets are "
89  "enqueued in the correct child queue disc of the mq root queue disc and "
90  "in the correct wifi MAC queue"),
91  m_tos (tos),
92  m_expectedQueue (expectedQueue)
93 {
94  for (uint8_t i = 0; i < 4; i++)
95  {
96  m_QueueDiscCount[i] = 0;
97  m_WifiMacQueueCount[i] = 0;
98  }
99 }
100 
101 void
103 {
104  uint8_t val;
105  if (item->GetUint8Value (QueueItem::IP_DSFIELD, val) && val == tos)
106  {
107  (*count)++;
108  }
109 }
110 
111 void
113 {
114  LlcSnapHeader llc;
115  Ptr<Packet> packet = item->GetPacket ()->Copy ();
116  packet->RemoveHeader (llc);
117 
118  if (llc.GetType () == Ipv4L3Protocol::PROT_NUMBER)
119  {
120  Ipv4Header iph;
121  packet->PeekHeader (iph);
122  if (iph.GetTos () == tos)
123  {
124  (*count)++;
125  }
126  }
127 }
128 
129 void
131 {
133  WifiMacHelper wifiMac;
134  YansWifiPhyHelper wifiPhy;
135  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
136  wifiPhy.SetChannel (wifiChannel.Create ());
137 
138  Ssid ssid = Ssid ("wifi-ac-mapping");
139  wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
140 
141  // Setup the AP, which will be the source of traffic for this test
142  NodeContainer ap;
143  ap.Create (1);
144  wifiMac.SetType ("ns3::ApWifiMac",
145  "QosSupported", BooleanValue (true),
146  "Ssid", SsidValue (ssid));
147 
148  NetDeviceContainer apDev = wifi.Install (wifiPhy, wifiMac, ap);
149 
150  // Setup one STA, which will be the sink for traffic in this test.
151  NodeContainer sta;
152  sta.Create (1);
153  wifiMac.SetType ("ns3::StaWifiMac",
154  "QosSupported", BooleanValue (true),
155  "Ssid", SsidValue (ssid));
156  NetDeviceContainer staDev = wifi.Install (wifiPhy, wifiMac, sta);
157 
158  // Our devices will have fixed positions
160  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
161  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
162  "MinX", DoubleValue (0.0),
163  "MinY", DoubleValue (0.0),
164  "DeltaX", DoubleValue (5.0),
165  "DeltaY", DoubleValue (10.0),
166  "GridWidth", UintegerValue (2),
167  "LayoutType", StringValue ("RowFirst"));
168  mobility.Install (sta);
169  mobility.Install (ap);
170 
171  // Now we install internet stacks on our devices
173  stack.Install (ap);
174  stack.Install (sta);
175 
177  uint16_t handle = tch.SetRootQueueDisc ("ns3::MqQueueDisc");
178  TrafficControlHelper::ClassIdList cls = tch.AddQueueDiscClasses (handle, 4, "ns3::QueueDiscClass");
179  tch.AddChildQueueDiscs (handle, cls, "ns3::FqCoDelQueueDisc");
180  tch.Install (apDev);
181  tch.Install (staDev);
182 
184  address.SetBase ("192.168.0.0", "255.255.255.0");
185  Ipv4InterfaceContainer staNodeInterface, apNodeInterface;
186  staNodeInterface = address.Assign (staDev);
187  apNodeInterface = address.Assign (apDev);
188 
189  uint16_t udpPort = 50000;
190 
191  PacketSinkHelper packetSink ("ns3::UdpSocketFactory",
192  InetSocketAddress (Ipv4Address::GetAny (), udpPort));
193  ApplicationContainer sinkApp = packetSink.Install (sta.Get (0));
194  sinkApp.Start (Seconds (0));
195  sinkApp.Stop (Seconds (4.0));
196 
197  // The packet source is an on-off application on the AP device
198  InetSocketAddress dest (staNodeInterface.GetAddress (0), udpPort);
199  dest.SetTos (m_tos);
200  OnOffHelper onoff ("ns3::UdpSocketFactory", dest);
201  onoff.SetConstantRate (DataRate ("5kbps"), 500);
202  ApplicationContainer sourceApp = onoff.Install (ap.Get (0));
203  sourceApp.Start (Seconds (1.0));
204  sourceApp.Stop (Seconds (4.0));
205 
206  // The first packet will be transmitted at time 1+(500*8)/5000 = 1.8s.
207  // The second packet will be transmitted at time 1.8+(500*8)/5000 = 2.6s.
208  // The third packet will be transmitted at time 2.6+(500*8)/5000 = 3.4s.
209 
210  Simulator::Stop (Seconds (5.0));
211 
212  Ptr<QueueDisc> root = ap.Get (0)->GetObject<TrafficControlLayer> ()->GetRootQueueDiscOnDevice (apDev.Get (0));
213  NS_TEST_ASSERT_MSG_EQ (root->GetNQueueDiscClasses (), 4, "The root queue disc should have 4 classes");
214  // Get the four child queue discs and connect their Enqueue trace to the PacketEnqueuedInQueueDisc
215  // method, which counts how many packets with the given ToS value have been enqueued
216  root->GetQueueDiscClass (0)->GetQueueDisc ()->TraceConnectWithoutContext ("Enqueue",
218 
219  root->GetQueueDiscClass (1)->GetQueueDisc ()->TraceConnectWithoutContext ("Enqueue",
221 
222  root->GetQueueDiscClass (2)->GetQueueDisc ()->TraceConnectWithoutContext ("Enqueue",
224 
225  root->GetQueueDiscClass (3)->GetQueueDisc ()->TraceConnectWithoutContext ("Enqueue",
227 
228  Ptr<WifiMac> apMac = DynamicCast<WifiNetDevice> (apDev.Get (0))->GetMac ();
229  PointerValue ptr;
230  // Get the four wifi mac queues and connect their Enqueue trace to the PacketEnqueuedInWifiMacQueue
231  // method, which counts how many packets with the given ToS value have been enqueued
232  apMac->GetAttribute ("BE_Txop", ptr);
233  ptr.Get<QosTxop> ()->GetWifiMacQueue ()->TraceConnectWithoutContext ("Enqueue",
235 
236  apMac->GetAttribute ("BK_Txop", ptr);
237  ptr.Get<QosTxop> ()->GetWifiMacQueue ()->TraceConnectWithoutContext ("Enqueue",
239 
240  apMac->GetAttribute ("VI_Txop", ptr);
241  ptr.Get<QosTxop> ()->GetWifiMacQueue ()->TraceConnectWithoutContext ("Enqueue",
243 
244  apMac->GetAttribute ("VO_Txop", ptr);
245  ptr.Get<QosTxop> ()->GetWifiMacQueue ()->TraceConnectWithoutContext ("Enqueue",
247 
248  Simulator::Run ();
249 
250  for (uint32_t i = 0; i < 4; i++)
251  {
252  if (i == m_expectedQueue)
253  {
254  NS_TEST_ASSERT_MSG_GT_OR_EQ (m_QueueDiscCount[i], 1, "There is no packet in the expected queue disc " << i);
255  NS_TEST_ASSERT_MSG_GT_OR_EQ (m_WifiMacQueueCount[i], 1, "There is no packet in the expected Wifi MAC queue " << i);
256  }
257  else
258  {
259  NS_TEST_ASSERT_MSG_EQ (m_QueueDiscCount[i], 0, "Unexpectedly, there is a packet in queue disc " << i);
260  NS_TEST_ASSERT_MSG_EQ (m_WifiMacQueueCount[i], 0, "Unexpectedly, there is a packet in Wifi MAC queue " << i);
261  }
262  }
263 
264  uint32_t totalOctetsThrough =
265  DynamicCast<PacketSink> (sinkApp.Get (0))->GetTotalRx ();
266 
267  // Check that the three packets have been received
268  NS_TEST_ASSERT_MSG_EQ (totalOctetsThrough, 1500, "Three packets should have been received");
269 
270  Simulator::Destroy ();
271 }
272 
280 {
281 public:
283 };
284 
286  : TestSuite ("wifi-ac-mapping", SYSTEM)
287 {
288  AddTestCase (new WifiAcMappingTest (0xb8, 2), TestCase::QUICK); // EF in AC_VI
289  AddTestCase (new WifiAcMappingTest (0x28, 1), TestCase::QUICK); // AF11 in AC_BK
290  AddTestCase (new WifiAcMappingTest (0x70, 0), TestCase::QUICK); // AF32 in AC_BE
291  AddTestCase (new WifiAcMappingTest (0xc0, 3), TestCase::QUICK); // CS7 in AC_VO
292 }
293 
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition: net-device-container.h:42
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::Ipv4Header
Packet header for IPv4.
Definition: ipv4-header.h:34
ns3::InetSocketAddress
an Inet address class
Definition: inet-socket-address.h:41
ns3::ApplicationContainer::Get
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
Definition: application-container.cc:62
ns3::YansWifiPhyHelper
Make it easy to create and manage PHY objects for the YANS model.
Definition: yans-wifi-helper.h:161
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
ns3::WifiMacQueueItem::GetPacket
Ptr< const Packet > GetPacket(void) const
Get the packet stored in this item.
Definition: wifi-mac-queue-item.cc:66
ns3::BooleanValue
AttributeValue implementation for Boolean.
Definition: boolean.h:37
ns3::Packet::PeekHeader
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:290
NS_TEST_ASSERT_MSG_GT_OR_EQ
#define NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg)
Test that an actual value is greater than or equal to a limit and report and abort if not.
Definition: test.h:1016
ns3::TrafficControlHelper::SetRootQueueDisc
uint16_t SetRootQueueDisc(const std::string &type, Args &&... args)
Helper function used to set a root queue disc of the given type and with the given attributes.
Definition: traffic-control-helper.h:362
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::ApplicationContainer::Stop
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Definition: application-container.cc:107
ns3::WifiHelper
helps to create WifiNetDevice objects
Definition: wifi-helper.h:323
ns3::Ipv4AddressHelper
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Definition: ipv4-address-helper.h:48
ns3::QueueItem::GetUint8Value
virtual bool GetUint8Value(Uint8Values field, uint8_t &value) const
Retrieve the value of a given field from the packet, if present.
Definition: queue-item.cc:57
WifiAcMappingTest::m_expectedQueue
uint16_t m_expectedQueue
expected queue disc index
Definition: wifi-ac-mapping-test-suite.cc:82
ns3::Object::GetObject
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
ns3::QueueDisc::GetQueueDiscClass
Ptr< QueueDiscClass > GetQueueDiscClass(std::size_t i) const
Get the i-th queue disc class.
Definition: queue-disc.cc:662
ns3::PointerValue
Hold objects of type Ptr<T>.
Definition: pointer.h:37
ns3::YansWifiPhyHelper::SetChannel
void SetChannel(Ptr< YansWifiChannel > channel)
Definition: yans-wifi-helper.cc:135
ns3::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
ns3::NodeContainer::Create
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Definition: node-container.cc:98
ns3::SsidValue
AttributeValue implementation for Ssid.
Definition: ssid.h:105
ns3::Ssid
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:36
ns3::OnOffHelper::SetConstantRate
void SetConstantRate(DataRate dataRate, uint32_t packetSize=512)
Helper function to set a constant rate source.
Definition: on-off-helper.cc:100
ns3::TestCase
encapsulates test code
Definition: test.h:1154
WifiAcMappingTest
Test for User priority to Access Category mapping.
Definition: wifi-ac-mapping-test-suite.cc:51
third.wifi
wifi
Definition: third.py:96
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::DataRate
Class for representing data rates.
Definition: data-rate.h:89
ns3::TrafficControlHelper::AddChildQueueDiscs
HandleList AddChildQueueDiscs(uint16_t handle, const ClassIdList &classes, const std::string &type, Args &&... args)
Helper function used to attach a child queue disc (of the given type and with the given attributes) t...
Definition: traffic-control-helper.h:401
ns3::YansWifiChannelHelper::Create
Ptr< YansWifiChannel > Create(void) const
Definition: yans-wifi-helper.cc:99
WifiAcMappingTestSuite::WifiAcMappingTestSuite
WifiAcMappingTestSuite()
Definition: wifi-ac-mapping-test-suite.cc:285
first.stack
stack
Definition: first.py:41
ns3::TrafficControlHelper::Install
QueueDiscContainer Install(NetDeviceContainer c)
Definition: traffic-control-helper.cc:248
WifiAcMappingTest::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: wifi-ac-mapping-test-suite.cc:130
ns3::ObjectBase::GetAttribute
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:223
ns3::OnOffHelper
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:43
WifiAcMappingTest::WifiAcMappingTest
WifiAcMappingTest(uint8_t tos, uint8_t expectedQueue)
Constructor for WifiAcMappingTest.
Definition: wifi-ac-mapping-test-suite.cc:87
ns3::Packet::RemoveHeader
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
ns3::Ipv4InterfaceContainer
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Definition: ipv4-interface-container.h:55
ns3::PointerValue::Get
Ptr< T > Get(void) const
Definition: pointer.h:201
ns3::NodeContainer::Get
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Definition: node-container.cc:93
first.address
address
Definition: first.py:44
WifiAcMappingTest::m_WifiMacQueueCount
uint16_t m_WifiMacQueueCount[4]
packet counter per Wi-Fi MAC queue
Definition: wifi-ac-mapping-test-suite.cc:84
WifiAcMappingTest::PacketEnqueuedInWifiMacQueue
static void PacketEnqueuedInWifiMacQueue(uint8_t tos, uint16_t *count, Ptr< const WifiMacQueueItem > item)
Function called whenever a packet is enqueued in a Wi-Fi MAC queue.
Definition: wifi-ac-mapping-test-suite.cc:112
ns3::QosTxop
Handle packet fragmentation and retransmissions for QoS data frames as well as MSDU aggregation (A-MS...
Definition: qos-txop.h:72
ns3::StringValue
Hold variables of type string.
Definition: string.h:41
ns3::PacketSinkHelper
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Definition: packet-sink-helper.h:36
WifiAcMappingTest::PacketEnqueuedInQueueDisc
static void PacketEnqueuedInQueueDisc(uint8_t tos, uint16_t *count, Ptr< const QueueDiscItem > item)
Function called whenever a packet is enqueued in a queue disc.
Definition: wifi-ac-mapping-test-suite.cc:102
ns3::TestSuite
A suite of tests to run.
Definition: test.h:1344
ns3::OnOffHelper::Install
ApplicationContainer Install(NodeContainer c) const
Install an ns3::OnOffApplication on each node of the input container configured with all the attribut...
Definition: on-off-helper.cc:59
NS_TEST_ASSERT_MSG_EQ
#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:166
ns3::TrafficControlLayer
Introspection did not find any typical Config paths.
Definition: traffic-control-layer.h:90
ns3::ApplicationContainer::Start
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
Definition: application-container.cc:87
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
ns3::MakeBoundCallback
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
Definition: callback.h:1703
ns3::TrafficControlHelper
Build a set of QueueDisc objects.
Definition: traffic-control-helper.h:120
ns3::Packet::Copy
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
ns3::Ipv4Header::GetTos
uint8_t GetTos(void) const
Definition: ipv4-header.cc:194
WifiAcMappingTestSuite
Access category mapping Test Suite.
Definition: wifi-ac-mapping-test-suite.cc:280
ns3::ApplicationContainer
holds a vector of ns3::Application pointers.
Definition: application-container.h:43
third.ssid
ssid
Definition: third.py:100
ns3::NodeContainer
keep track of a set of node pointers.
Definition: node-container.h:39
ns3::WifiMacHelper::SetType
void SetType(std::string type, Args &&... args)
Definition: wifi-mac-helper.h:130
ns3::Ipv4InterfaceContainer::GetAddress
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Definition: ipv4-interface-container.cc:59
ns3::UintegerValue
Hold an unsigned integer type.
Definition: uinteger.h:44
wifiAcMappingTestSuite
static WifiAcMappingTestSuite wifiAcMappingTestSuite
Definition: wifi-ac-mapping-test-suite.cc:294
ns3::YansWifiChannelHelper
manage and create wifi channel objects for the YANS model.
Definition: yans-wifi-helper.h:37
ns3::LlcSnapHeader
Header for the LLC/SNAP encapsulation.
Definition: llc-snap-header.h:43
ns3::WifiMacHelper
create MAC layers for a ns3::WifiNetDevice.
Definition: wifi-mac-helper.h:48
ns3::TrafficControlHelper::AddQueueDiscClasses
ClassIdList AddQueueDiscClasses(uint16_t handle, uint16_t count, const std::string &type, Args &&... args)
Helper function used to add the given number of queue disc classes (of the given type and with the gi...
Definition: traffic-control-helper.h:385
WifiAcMappingTest::m_tos
uint8_t m_tos
type of service
Definition: wifi-ac-mapping-test-suite.cc:81
ns3::ObjectBase::TraceConnectWithoutContext
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:293
ns3::QueueDisc::GetNQueueDiscClasses
std::size_t GetNQueueDiscClasses(void) const
Get the number of queue disc classes.
Definition: queue-disc.cc:669
ns3::LlcSnapHeader::GetType
uint16_t GetType(void)
Return the Ethertype.
Definition: llc-snap-header.cc:44
ns3::InetSocketAddress::SetTos
void SetTos(uint8_t tos)
Definition: inet-socket-address.cc:96
ns3::InternetStackHelper
aggregate IP/TCP/UDP functionality to existing Nodes.
Definition: internet-stack-helper.h:88
ns3::NetDeviceContainer::Get
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
Definition: net-device-container.cc:62
ns3::TrafficControlHelper::ClassIdList
std::vector< uint16_t > ClassIdList
Container type for Class IDs.
Definition: traffic-control-helper.h:180
ns3::MobilityHelper
Helper class used to assign positions and mobility models to nodes.
Definition: mobility-helper.h:43
third.mobility
mobility
Definition: third.py:108
ns3::PacketSinkHelper::Install
ApplicationContainer Install(NodeContainer c) const
Install an ns3::PacketSinkApplication on each node of the input container configured with all the att...
Definition: packet-sink-helper.cc:55
WifiAcMappingTest::m_QueueDiscCount
uint16_t m_QueueDiscCount[4]
packet counter per queue disc
Definition: wifi-ac-mapping-test-suite.cc:83