Mesh:Flame: added regression test
authorKirill Andreev <andreev@iitp.ru>
Tue, 01 Dec 2009 17:35:13 +0300
changeset 5826 d0765c1313c9
parent 5825 9e8c8a54772b
child 5827 ed0b2d9301a1
Mesh:Flame: added regression test
src/devices/mesh/flame/test/flame-regression-test-0-1.pcap
src/devices/mesh/flame/test/flame-regression-test-1-1.pcap
src/devices/mesh/flame/test/flame-regression-test-2-1.pcap
src/devices/mesh/flame/test/flame-regression.cc
src/devices/mesh/flame/test/flame-regression.h
src/devices/mesh/flame/test/regression.cc
src/devices/mesh/flame/wscript
Binary file src/devices/mesh/flame/test/flame-regression-test-0-1.pcap has changed
Binary file src/devices/mesh/flame/test/flame-regression-test-1-1.pcap has changed
Binary file src/devices/mesh/flame/test/flame-regression-test-2-1.pcap has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/mesh/flame/test/flame-regression.cc	Tue Dec 01 17:35:13 2009 +0300
@@ -0,0 +1,147 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 IITP RAS
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Authors: Kirill Andreev <andreev@iitp.ru>
+ */
+#include "ns3/mesh-helper.h"
+#include "ns3/simulator.h"
+#include "ns3/random-variable.h"
+#include "ns3/mobility-helper.h"
+#include "ns3/double.h"
+#include "ns3/uinteger.h"
+#include "ns3/string.h"
+#include "ns3/yans-wifi-helper.h"
+#include "ns3/internet-stack-helper.h"
+#include "ns3/ipv4-address-helper.h"
+#include "ns3/abort.h"
+#include "ns3/udp-echo-helper.h"
+#include "ns3/mobility-model.h"
+#include <sstream>
+
+#include "flame-regression.h"
+
+using namespace ns3;
+
+/// Set to true to rewrite reference traces, leave false to run regression test
+const bool WRITE_VECTORS = false;
+/// Unique PCAP file name prefix
+const char * const PREFIX = "flame-regression-test";
+
+
+FlameRegressionTest::FlameRegressionTest () : TestCase ("FLAME regression test"),
+  m_nodes (0),
+  m_time (Seconds (10))
+{
+}
+
+FlameRegressionTest::~FlameRegressionTest ()
+{
+  delete m_nodes;
+}
+
+bool
+FlameRegressionTest::DoRun ()
+{
+  SeedManager::SetSeed(12345);
+  CreateNodes ();
+  CreateDevices ();
+  InstallApplications ();
+
+  Simulator::Stop (m_time);
+  Simulator::Run ();
+  Simulator::Destroy ();
+  
+  if (!WRITE_VECTORS) CheckResults ();
+
+  delete m_nodes, m_nodes = 0;
+  return false;
+}
+
+void
+FlameRegressionTest::CreateNodes ()
+{
+  m_nodes = new NodeContainer;
+  m_nodes->Create (3);
+  MobilityHelper mobility;
+  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
+                                "MinX", DoubleValue (0.0),
+                                "MinY", DoubleValue (0.0),
+                                "DeltaX", DoubleValue (150),
+                                "DeltaY", DoubleValue (0),
+                                "GridWidth", UintegerValue (3),
+                                "LayoutType", StringValue ("RowFirst"));
+  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
+  mobility.Install (*m_nodes);
+}
+
+void
+FlameRegressionTest::CreateDevices ()
+{
+  // 1. setup WiFi
+  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
+  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
+  wifiPhy.SetChannel (wifiChannel.Create ());
+  // 2. setup mesh
+  MeshHelper mesh = MeshHelper::Default ();
+  mesh.SetStackInstaller ("ns3::FlameStack");
+  mesh.SetMacType ("RandomStart", TimeValue (Seconds(0.1)));
+  mesh.SetNumberOfInterfaces (1);
+  NetDeviceContainer meshDevices = mesh.Install (wifiPhy, *m_nodes);  
+  // 3. setup TCP/IP
+  InternetStackHelper internetStack;
+  internetStack.Install (*m_nodes);
+  Ipv4AddressHelper address;
+  address.SetBase ("10.1.1.0", "255.255.255.0");
+  m_interfaces = address.Assign (meshDevices);
+  // 4. write PCAP if needed
+  std::string prefix = (WRITE_VECTORS ? NS_TEST_SOURCEDIR : GetTempDir ()) + PREFIX;
+  wifiPhy.EnablePcapAll (prefix);
+
+}
+void
+FlameRegressionTest::InstallApplications ()
+{
+  UdpEchoServerHelper echoServer (9);
+  ApplicationContainer serverApps = echoServer.Install (m_nodes->Get (0));
+  serverApps.Start (Seconds (0.0));
+  serverApps.Stop (m_time);
+  UdpEchoClientHelper echoClient (m_interfaces.GetAddress (0), 9);
+  echoClient.SetAttribute ("MaxPackets", UintegerValue (300));
+  echoClient.SetAttribute ("Interval", TimeValue (Seconds(1.1)));
+  echoClient.SetAttribute ("PacketSize", UintegerValue (20));
+  ApplicationContainer clientApps = echoClient.Install (m_nodes->Get (2));
+  clientApps.Start (Seconds (1.0));
+  clientApps.Stop (m_time);
+}
+  
+void
+FlameRegressionTest::CheckResults ()
+{
+  for (int i = 0; i < 3; ++i)
+    {
+      std::ostringstream os1, os2;
+      // File naming conventions are hard-coded here.
+      os1 << NS_TEST_SOURCEDIR << PREFIX << "-" << i << "-1.pcap";
+      os2 << GetTempDir () << PREFIX << "-" << i << "-1.pcap";
+      
+      uint32_t sec(0), usec(0);
+      bool diff = PcapFile::Diff (os1.str(), os2.str(), sec, usec); // TODO support default PcapWriter snap length here
+      NS_TEST_EXPECT_MSG_EQ (diff, false, "PCAP traces " << os1.str() << " and " << os2.str() 
+                                       << " differ starting from " << sec << " s " << usec << " us");
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/mesh/flame/test/flame-regression.h	Tue Dec 01 17:35:13 2009 +0300
@@ -0,0 +1,77 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 IITP RAS
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Authors: Kirill Andreev <andreev@iitp.ru>
+ */
+
+#include "ns3/test.h"
+#include "ns3/nstime.h"
+#include "ns3/node-container.h"
+#include "ns3/ipv4-interface-container.h"
+#include "ns3/pcap-file.h"
+
+using namespace ns3;
+/**
+ * \ingroup flame
+ * \brief FLAME protocol regression test of three stations:
+ * \verbatim
+ * <-----------|----------->   Broadcast frame
+ *             |----------->|  Unicast frame
+ *           Source                   Destination
+ * <-----------|----------->|            |             ARP request
+ *             |<-----------|----------->|             ARP request
+ *             |            |<-----------|             ARP reply
+ *             |<-----------|            |             ARP reply
+ *             |----------->|            |             Data
+ *             |            |----------->|             Data
+ *             |            |<-----------|-----------> PATH_UPDATE (no broadcast was sent)
+ *             |<-----------|----------->|             PATH_UPDATE
+ * <-----------|----------->|            |             PATH_UPDATE
+ *             |            |<-----------|-----------> ARP request
+ *             |<-----------|----------->|             ARP request
+ * <-----------|----------->|            |             ARP request
+ *             |----------->|            |             ARP reply
+ *             |            |----------->|             ARP reply
+ *             |            |<-----------|             Data
+ *             |<-----------|            |             Data
+ *             |............|............|
+ *             After five seconds data is transmitted again as
+ *             broadcast, and PATH_UPDATE is sent
+ * \endverbatim
+ */
+class FlameRegressionTest : public TestCase
+{
+public:
+  FlameRegressionTest ();
+  virtual ~FlameRegressionTest();
+
+  virtual bool DoRun ();
+  void CheckResults ();
+
+private:
+  /// XXX It is important to have pointers here
+  NodeContainer * m_nodes;
+  /// Simulation time
+  Time m_time;
+  /// Needed to install applications
+  Ipv4InterfaceContainer m_interfaces;
+  
+  void CreateNodes ();
+  void CreateDevices ();
+  void InstallApplications ();
+};
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/mesh/flame/test/regression.cc	Tue Dec 01 17:35:13 2009 +0300
@@ -0,0 +1,32 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 IITP RAS
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Authors: Pavel Boyko <boyko@iitp.ru>
+ */
+
+#include "ns3/test.h"
+#include "flame-regression.h"
+
+using namespace ns3;
+class FlameRegressionSuite : public TestSuite
+{
+public:
+  FlameRegressionSuite () : TestSuite ("devices-mesh-flame-regression", SYSTEM) 
+  {
+    AddTestCase (new FlameRegressionTest);
+  }
+} g_flameRegressionSuite;
--- a/src/devices/mesh/flame/wscript	Tue Dec 01 17:09:50 2009 +0300
+++ b/src/devices/mesh/flame/wscript	Tue Dec 01 17:35:13 2009 +0300
@@ -8,6 +8,8 @@
         'flame-protocol-mac.cc',
         'flame-protocol.cc',
         'flame-test-suite.cc',
+        'test/flame-regression.cc',
+        'test/regression.cc',
         ]
     headers = bld.new_task_gen('ns3header')
     headers.module = 'flame'