PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/s2016/ns3-routing/ns-3/src/test/ns3wifi/wifi-msdu-aggregator-test-suite.cc

https://gitlab.com/pmaddi/cs433
C++ | 211 lines | 123 code | 28 blank | 60 comment | 1 complexity | 9e5fc4cf5eaa36c215f9d216f9f24757 MD5 | raw file
  1. /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
  2. /*
  3. * Copyright (c) 2010 Dean Armstrong
  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: Dean Armstrong <deanarm@gmail.com>
  19. */
  20. #include "ns3/test.h"
  21. #include "ns3/simulator.h"
  22. #include "ns3/log.h"
  23. #include "ns3/boolean.h"
  24. #include "ns3/string.h"
  25. #include "ns3/double.h"
  26. #include "ns3/ssid.h"
  27. #include "ns3/data-rate.h"
  28. #include "ns3/inet-socket-address.h"
  29. #include "ns3/packet-sink.h"
  30. #include "ns3/wifi-helper.h"
  31. #include "ns3/qos-wifi-mac-helper.h"
  32. #include "ns3/yans-wifi-helper.h"
  33. #include "ns3/mobility-helper.h"
  34. #include "ns3/internet-stack-helper.h"
  35. #include "ns3/ipv4-address-helper.h"
  36. #include "ns3/packet-sink-helper.h"
  37. #include "ns3/on-off-helper.h"
  38. NS_LOG_COMPONENT_DEFINE ("WifiMsduAggregatorThroughputTest");
  39. using namespace ns3;
  40. class WifiMsduAggregatorThroughputTest : public TestCase
  41. {
  42. public:
  43. WifiMsduAggregatorThroughputTest ();
  44. virtual bool DoRun (void);
  45. private:
  46. bool m_writeResults;
  47. };
  48. WifiMsduAggregatorThroughputTest::WifiMsduAggregatorThroughputTest ()
  49. : TestCase ("MsduAggregator throughput test"),
  50. m_writeResults (false)
  51. {
  52. }
  53. bool
  54. WifiMsduAggregatorThroughputTest::DoRun (void)
  55. {
  56. WifiHelper wifi = WifiHelper::Default ();
  57. QosWifiMacHelper wifiMac = QosWifiMacHelper::Default ();
  58. YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
  59. YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
  60. wifiPhy.SetChannel (wifiChannel.Create ());
  61. Ssid ssid = Ssid ("wifi-amsdu-throughput");
  62. // It may seem a little farcical running an 802.11n aggregation
  63. // scenario with 802.11b rates (transmit rate fixed to 1 Mbps, no
  64. // less), but this approach tests the bit we need to without unduly
  65. // increasing the complexity of the simulation.
  66. std::string phyMode ("DsssRate1Mbps");
  67. wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
  68. wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
  69. "DataMode", StringValue (phyMode),
  70. "ControlMode", StringValue (phyMode));
  71. // Setup the AP, which will be the source of traffic for this test
  72. // and thus has an aggregator on AC_BE.
  73. NodeContainer ap;
  74. ap.Create (1);
  75. wifiMac.SetType ("ns3::QapWifiMac",
  76. "Ssid", SsidValue (ssid),
  77. "BeaconGeneration", BooleanValue (true),
  78. "BeaconInterval", TimeValue (MicroSeconds (102400)));
  79. wifiMac.SetMsduAggregatorForAc (AC_BE, "ns3::MsduStandardAggregator",
  80. "MaxAmsduSize", UintegerValue (4000));
  81. NetDeviceContainer apDev = wifi.Install (wifiPhy, wifiMac, ap);
  82. // Setup one STA, which will be the sink for traffic in this test.
  83. NodeContainer sta;
  84. sta.Create (1);
  85. wifiMac.SetType ("ns3::QstaWifiMac",
  86. "Ssid", SsidValue (ssid),
  87. "ActiveProbing", BooleanValue (false));
  88. NetDeviceContainer staDev = wifi.Install (wifiPhy, wifiMac, sta);
  89. // Our devices will have fixed positions
  90. MobilityHelper mobility;
  91. mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
  92. mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
  93. "MinX", DoubleValue (0.0),
  94. "MinY", DoubleValue (0.0),
  95. "DeltaX", DoubleValue (5.0),
  96. "DeltaY", DoubleValue (10.0),
  97. "GridWidth", UintegerValue (2),
  98. "LayoutType", StringValue ("RowFirst"));
  99. mobility.Install (sta);
  100. mobility.Install (ap);
  101. // Now we install internet stacks on our devices
  102. InternetStackHelper stack;
  103. stack.Install (ap);
  104. stack.Install (sta);
  105. Ipv4AddressHelper address;
  106. address.SetBase ("192.168.0.0", "255.255.255.0");
  107. Ipv4InterfaceContainer staNodeInterface, apNodeInterface;
  108. staNodeInterface = address.Assign (staDev);
  109. apNodeInterface = address.Assign (apDev);
  110. // The applications for this test will see a unidirectional UDP
  111. // stream from the AP to the STA. The following UDP port will be
  112. // used (arbitrary choice).
  113. uint16_t udpPort = 50000;
  114. // The packet sink application is on the STA device, and is running
  115. // right from the start. The traffic source will turn on at 1 second
  116. // and then off at 9 seconds, so we turn the sink off at 9 seconds
  117. // too in order to measure throughput in a fixed window.
  118. PacketSinkHelper packetSink ("ns3::UdpSocketFactory",
  119. InetSocketAddress(Ipv4Address::GetAny(),
  120. udpPort));
  121. ApplicationContainer sinkApp = packetSink.Install (sta.Get (0));
  122. sinkApp.Start (Seconds (0));
  123. sinkApp.Stop (Seconds (9.0));
  124. // The packet source is an on-off application on the AP
  125. // device. Given that we have fixed the transmit rate at 1 Mbps
  126. // above, a 1 Mbps stream at the transport layer should be sufficent
  127. // to determine whether aggregation is working or not.
  128. //
  129. // We configure this traffic stream to operate between 1 and 9 seconds.
  130. OnOffHelper onoff ("ns3::UdpSocketFactory",
  131. InetSocketAddress (staNodeInterface.GetAddress (0),
  132. udpPort));
  133. onoff.SetAttribute ("DataRate", DataRateValue(DataRate("1Mbps")));
  134. onoff.SetAttribute ("PacketSize", UintegerValue(100));
  135. onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
  136. onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
  137. ApplicationContainer sourceApp = onoff.Install (ap.Get (0));
  138. sourceApp.Start (Seconds (1.0));
  139. sourceApp.Stop (Seconds (9.0));
  140. // Enable tracing at the AP
  141. if (m_writeResults)
  142. {
  143. wifiPhy.EnablePcap ("wifi-amsdu-throughput", sta.Get (0)->GetId (), 0);
  144. }
  145. Simulator::Stop (Seconds (10.0));
  146. Simulator::Run ();
  147. Simulator::Destroy ();
  148. // Now the simulation is complete we note the total number of octets
  149. // receive at the packet sink so that we can shortly test that this
  150. // is plausible.
  151. uint32_t totalOctetsThrough =
  152. DynamicCast<PacketSink>(sinkApp.Get (0))->GetTotalRx ();
  153. // Check that throughput was acceptable. This threshold is set based
  154. // on inspection of a trace where things are working. Basically, we
  155. // there get 26 UDP packets (of size 100, as specified above)
  156. // aggregated per A-MSDU, for which the complete frame exchange
  157. // (including RTS/CTS and plus medium access) takes around 32
  158. // ms. Over the eight seconds of the test this means we expect about
  159. // 650 kilobytes, so a pass threshold of 600000 seems to provide a
  160. // fair amount of margin to account for reduced utilisation around
  161. // stream startup, and contention around AP beacon transmission.
  162. //
  163. // If aggregation is turned off, then we get about 350 kilobytes in
  164. // the same test, so we'll definitely catch the major failures.
  165. NS_TEST_ASSERT_MSG_GT(totalOctetsThrough, 600000,
  166. "A-MSDU test fails for low throughput of "
  167. << totalOctetsThrough << " octets");
  168. return false;
  169. }
  170. // For now the MSDU Aggregator Test Suite contains only the one test
  171. // that is defined in this file, so it's class definition and
  172. // instantiation can live here.
  173. class WifiMsduAggregatorTestSuite : public TestSuite
  174. {
  175. public:
  176. WifiMsduAggregatorTestSuite ();
  177. };
  178. WifiMsduAggregatorTestSuite::WifiMsduAggregatorTestSuite ()
  179. : TestSuite ("ns3-wifi-msdu-aggregator", SYSTEM)
  180. {
  181. AddTestCase (new WifiMsduAggregatorThroughputTest);
  182. }
  183. WifiMsduAggregatorTestSuite wifiMsduAggregatorTestSuite;