Add utest for Bug 730
authorSébastien Deronne <sebastien.deronne@gmail.com>
Sat, 15 Aug 2015 13:15:03 +0200
changeset 11581 e205cbdadc69
parent 11580 4bf4b6dfdf64
child 11582 60fd364fb2a5
Add utest for Bug 730
src/wifi/test/wifi-test.cc
src/wifi/wscript
--- a/src/wifi/test/wifi-test.cc	Sat Aug 15 13:14:14 2015 +0200
+++ b/src/wifi/test/wifi-test.cc	Sat Aug 15 13:15:03 2015 +0200
@@ -18,29 +18,28 @@
  *
  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
  *          Quincy Tse <quincy.tse@nicta.com.au> (Case for Bug 991)
+ *          Sébastien Deronne <sebastien.deronne@gmail.com> (Case for bug 730)
  */
 
+#include "ns3/nqos-wifi-mac-helper.h"
+#include "ns3/yans-wifi-helper.h"
+#include "ns3/internet-stack-helper.h"
+#include "ns3/ipv4-address-helper.h"
+#include "ns3/packet-sink-helper.h"
+#include "ns3/on-off-helper.h"
+#include "ns3/mobility-helper.h"
 #include "ns3/wifi-net-device.h"
-#include "ns3/yans-wifi-channel.h"
 #include "ns3/adhoc-wifi-mac.h"
-#include "ns3/yans-wifi-phy.h"
-#include "ns3/arf-wifi-manager.h"
 #include "ns3/propagation-delay-model.h"
 #include "ns3/propagation-loss-model.h"
-#include "ns3/error-rate-model.h"
 #include "ns3/yans-error-rate-model.h"
 #include "ns3/constant-position-mobility-model.h"
-#include "ns3/node.h"
-#include "ns3/simulator.h"
 #include "ns3/test.h"
-#include "ns3/object-factory.h"
-#include "ns3/dca-txop.h"
-#include "ns3/mac-rx-middle.h"
 #include "ns3/pointer.h"
 #include "ns3/rng-seed-manager.h"
-#include "ns3/edca-txop-n.h"
 #include "ns3/config.h"
 #include "ns3/boolean.h"
+#include "ns3/string.h"
 
 using namespace ns3;
 
@@ -483,6 +482,147 @@
 
 
 //-----------------------------------------------------------------------------
+/**
+ * Make sure that when changing the fragmentation threshold during the simulation,
+ * the TCP transmission does not unexpectedly stop.
+ *
+ * The scenario considers a TCP transmission between a 802.11b station and a 802.11b
+ * access point. After the simulation has begun, the fragmentation threshold is set at
+ * a value lower than the packet size. It then checks whether the TCP transmission
+ * continues after the fragmentation threshold modification.
+ *
+ * See \bugid{730}
+ */
+
+class Bug730TestCase : public TestCase
+{
+public:
+  Bug730TestCase ();
+  virtual ~Bug730TestCase ();
+
+  virtual void DoRun (void);
+
+
+private:
+  void Receive (std::string context, Ptr<const Packet> p, const Address &adr);
+
+  uint32_t m_received;
+};
+
+Bug730TestCase::Bug730TestCase ()
+  : TestCase ("Test case for Bug 730"),
+    m_received (0)
+{
+}
+
+Bug730TestCase::~Bug730TestCase ()
+{
+}
+
+void
+Bug730TestCase::Receive (std::string context, Ptr<const Packet> p, const Address &adr)
+{
+  if ((p->GetSize () == 1460) && (Simulator::Now () > Seconds (20)))
+    {
+      m_received++;
+    }
+}
+
+void
+Bug730TestCase::DoRun (void)
+{
+  m_received = 0;
+
+  Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2304"));
+  Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (2));
+  Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1460));
+
+  NodeContainer wifiStaNode;
+  wifiStaNode.Create (1);
+
+  NodeContainer wifiApNode;
+  wifiApNode.Create (1);
+
+  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
+  YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
+  phy.SetChannel (channel.Create ());
+
+  WifiHelper wifi = WifiHelper::Default ();
+  wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
+  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
+                                "DataMode", StringValue ("DsssRate1Mbps"),
+                                "ControlMode", StringValue ("DsssRate1Mbps"));
+
+  NqosWifiMacHelper mac = NqosWifiMacHelper::Default ();
+  Ssid ssid = Ssid ("ns-3-ssid");
+  mac.SetType ("ns3::StaWifiMac",
+               "Ssid", SsidValue (ssid),
+               "ActiveProbing", BooleanValue (false));
+
+  NetDeviceContainer staDevices;
+  staDevices = wifi.Install (phy, mac, wifiStaNode);
+
+  mac.SetType ("ns3::ApWifiMac",
+               "Ssid", SsidValue (ssid),
+               "BeaconGeneration", BooleanValue (true));
+
+  NetDeviceContainer apDevices;
+  apDevices = wifi.Install (phy, mac, wifiApNode);
+
+  MobilityHelper mobility;
+  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
+
+  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
+  positionAlloc->Add (Vector (1.0, 0.0, 0.0));
+  mobility.SetPositionAllocator (positionAlloc);
+
+  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
+  mobility.Install (wifiApNode);
+  mobility.Install (wifiStaNode);
+
+  InternetStackHelper stack;
+  stack.Install (wifiApNode);
+  stack.Install (wifiStaNode);
+
+  Ipv4AddressHelper address;
+  address.SetBase ("10.1.1.0", "255.255.255.0");
+  Ipv4InterfaceContainer StaInterface;
+  StaInterface = address.Assign (staDevices);
+  Ipv4InterfaceContainer ApInterface;
+  ApInterface = address.Assign (apDevices);
+
+  Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), 21));
+  PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", sinkLocalAddress);
+  ApplicationContainer sinkApp = sinkHelper.Install (wifiApNode.Get (0));
+  sinkApp.Start (Seconds (1.0));
+  sinkApp.Stop (Seconds (51.0));
+
+  OnOffHelper sourceHelper ("ns3::TcpSocketFactory", Address ());
+  sourceHelper.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
+  sourceHelper.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
+  AddressValue remoteAddress (InetSocketAddress (ApInterface.GetAddress (0), 21));
+  sourceHelper.SetAttribute ("Remote", remoteAddress);
+  sourceHelper.SetAttribute ("PacketSize", UintegerValue (1460));
+  sourceHelper.SetAttribute ("DataRate", StringValue ("10Mb/s"));
+  ApplicationContainer sourceApp;
+  sourceApp.Add (sourceHelper.Install (wifiStaNode.Get (0)));
+  sourceApp.Start (Seconds (1.0));
+  sourceApp.Stop (Seconds (51.0));
+
+  Config::Connect ("/NodeList/*/ApplicationList/0/$ns3::PacketSink/Rx", MakeCallback (&Bug730TestCase::Receive, this));
+
+  Simulator::Schedule (Seconds (10.0), Config::Set, "/NodeList/0/DeviceList/0/RemoteStationManager/FragmentationThreshold", StringValue ("800"));
+
+  Simulator::Stop (Seconds (55));
+  Simulator::Run ();
+  Simulator::Destroy ();
+
+  bool result = (m_received > 0);
+  NS_TEST_ASSERT_MSG_EQ (result, true, "packet reception unexpectedly stopped after adapting fragmentation threshold!");
+}
+
+
+//-----------------------------------------------------------------------------
 class WifiTestSuite : public TestSuite
 {
 public:
@@ -496,6 +636,7 @@
   AddTestCase (new QosUtilsIsOldPacketTest, TestCase::QUICK);
   AddTestCase (new InterferenceHelperSequenceTest, TestCase::QUICK); //Bug 991
   AddTestCase (new Bug555TestCase, TestCase::QUICK); //Bug 555
+  AddTestCase (new Bug730TestCase, TestCase::QUICK); //Bug 730
 }
 
 static WifiTestSuite g_wifiTestSuite;
--- a/src/wifi/wscript	Sat Aug 15 13:14:14 2015 +0200
+++ b/src/wifi/wscript	Sat Aug 15 13:15:03 2015 +0200
@@ -1,7 +1,7 @@
 ## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
 
 def build(bld):
-    obj = bld.create_ns3_module('wifi', ['network', 'propagation', 'energy'])
+    obj = bld.create_ns3_module('wifi', ['network', 'internet', 'applications', 'propagation', 'energy'])
     obj.source = [
         'model/wifi-information-element.cc',
         'model/wifi-information-element-vector.cc',