Fix Bug 780 (problem in RoutingTableComputation with asymetric links), while adding debugging methods to OLSR. Thanks Abdul Jabbar, Pavel Boyko, and Tom Henderson for test case and debug code.
authorGustavo J. A. M. Carneiro <gjc@inescporto.pt>
Mon, 21 Dec 2009 16:07:08 +0000
changeset 5867 8c65da328ae9
parent 5866 75a2025fb72c
child 5868 ed1e2ad4c0b9
Fix Bug 780 (problem in RoutingTableComputation with asymetric links), while adding debugging methods to OLSR. Thanks Abdul Jabbar, Pavel Boyko, and Tom Henderson for test case and debug code.
src/routing/olsr/olsr-repositories.h
src/routing/olsr/olsr-routing-protocol.cc
src/routing/olsr/olsr-routing-protocol.h
src/routing/olsr/olsr.h
src/routing/olsr/test/bug780-0-0.pcap
src/routing/olsr/test/bug780-1-0.pcap
src/routing/olsr/test/bug780-2-0.pcap
src/routing/olsr/test/bug780-test.cc
src/routing/olsr/test/bug780-test.h
src/routing/olsr/test/regression-test-suite.cc
src/routing/olsr/wscript
--- a/src/routing/olsr/olsr-repositories.h	Sun Dec 20 18:24:46 2009 +0100
+++ b/src/routing/olsr/olsr-repositories.h	Mon Dec 21 16:07:08 2009 +0000
@@ -94,7 +94,8 @@
      << ", neighborIfaceAddr=" << tuple.neighborIfaceAddr
      << ", symTime=" << tuple.symTime
      << ", asymTime=" << tuple.asymTime
-     << ", expTime=" << tuple.time;
+     << ", expTime=" << tuple.time
+     << ")";
   return os;
 }
 
--- a/src/routing/olsr/olsr-routing-protocol.cc	Sun Dec 20 18:24:46 2009 +0100
+++ b/src/routing/olsr/olsr-routing-protocol.cc	Mon Dec 21 16:07:08 2009 +0000
@@ -140,7 +140,7 @@
 namespace ns3 {
 namespace olsr {
 
-NS_LOG_COMPONENT_DEFINE ("OlsrAgent");
+NS_LOG_COMPONENT_DEFINE ("OlsrRoutingProtocol");
 
 
 /********** OLSR class **********/
@@ -894,7 +894,7 @@
       NS_LOG_LOGIC ("Looking at two-hop neighbor tuple: " << nb2hop_tuple);
 
       // a 2-hop neighbor which is not a neighbor node or the node itself
-      if (m_state.FindNeighborTuple (nb2hop_tuple.twoHopNeighborAddr))
+      if (m_state.FindSymNeighborTuple (nb2hop_tuple.twoHopNeighborAddr))
         {
           NS_LOG_LOGIC ("Two-hop neighbor tuple is also neighbor; skipped.");
           continue;
@@ -2641,12 +2641,15 @@
       rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIdx));
       sockerr = Socket::ERROR_NOTERROR;
       NS_LOG_DEBUG ("Olsr node " << m_mainAddress 
-                    << ": RouteRequest for dest=" << header.GetDestination ()
+                    << ": RouteOutput for dest=" << header.GetDestination ()
                     << " --> nextHop=" << entry2.nextAddr
                     << " interface=" << entry2.interface);      NS_LOG_DEBUG ("Found route to " << rtentry->GetDestination () << " via nh " << rtentry->GetGateway () << " with source addr " << rtentry->GetSource () << " and output dev " << rtentry->GetOutputDevice());
     }
   else
     { 
+      NS_LOG_DEBUG ("Olsr node " << m_mainAddress 
+                    << ": RouteOutput for dest=" << header.GetDestination ()
+                    << " No route to host");
       sockerr = Socket::ERROR_NOROUTETOHOST;
     }
   return rtentry;
@@ -2706,7 +2709,7 @@
       rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIdx));
       
       NS_LOG_DEBUG ("Olsr node " << m_mainAddress
-                    << ": RouteRequest for dest=" << header.GetDestination ()
+                    << ": RouteInput for dest=" << header.GetDestination ()
                     << " --> nextHop=" << entry2.nextAddr
                     << " interface=" << entry2.interface);
       
@@ -2717,7 +2720,7 @@
     {
 #ifdef NS3_LOG_ENABLE
       NS_LOG_DEBUG ("Olsr node " << m_mainAddress 
-                    << ": RouteRequest for dest=" << header.GetDestination ()
+                    << ": RouteInput for dest=" << header.GetDestination ()
                     << " --> NOT FOUND; ** Dumping routing table...");      for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator iter = m_table.begin ();
            iter != m_table.end (); iter++)
         {           NS_LOG_DEBUG ("dest=" << iter->first << " --> next=" << iter->second.nextAddr                 
@@ -2956,6 +2959,36 @@
   return false;
 }
 
+void
+RoutingProtocol::Dump (void)
+{
+  Time now = Simulator::Now ();
+  
+#ifdef NS3_LOG_ENABLE
+  NS_LOG_DEBUG ("Dumping for node with main address " << m_mainAddress);
+  NS_LOG_DEBUG (" Neighbor set");
+  for (NeighborSet::const_iterator iter = m_state.GetNeighbors ().begin ();
+         iter != m_state.GetNeighbors ().end (); iter++)
+    {
+      NS_LOG_DEBUG ("  " << *iter);
+    }
+  NS_LOG_DEBUG (" Two-hop neighbor set");
+  for (TwoHopNeighborSet::const_iterator iter = m_state.GetTwoHopNeighbors ().begin ();
+         iter != m_state.GetTwoHopNeighbors ().end (); iter++)
+    {
+      if (now < iter->expirationTime)
+        { 
+          NS_LOG_DEBUG ("  " << *iter);
+        }
+    }
+  NS_LOG_DEBUG (" Routing table");
+  for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator iter = m_table.begin (); iter != m_table.end (); iter++)
+    {
+      NS_LOG_DEBUG ("  dest=" << iter->first << " --> next=" << iter->second.nextAddr << " via interface " << iter->second.interface);
+    }
+  NS_LOG_DEBUG ("");
+#endif  //NS3_LOG_ENABLE
+}
 
 }} // namespace olsr, ns3
 
--- a/src/routing/olsr/olsr-routing-protocol.h	Sun Dec 20 18:24:46 2009 +0100
+++ b/src/routing/olsr/olsr-routing-protocol.h	Mon Dec 21 16:07:08 2009 +0000
@@ -81,6 +81,8 @@
 
   void SetMainInterface (uint32_t interface);
 
+  void Dump (void);
+
 protected:
   virtual void DoStart (void);
 private:
--- a/src/routing/olsr/olsr.h	Sun Dec 20 18:24:46 2009 +0100
+++ b/src/routing/olsr/olsr.h	Mon Dec 21 16:07:08 2009 +0000
@@ -49,10 +49,10 @@
  * node); or ns3::OlsrHelper::InstallAll (void);
  *
  * In addition, the behavior of OLSR can be modified by changing certain
- * attributes.  The method ns3::OlsrHelper::SetAgent () can be used
+ * attributes.  The method ns3::OlsrHelper::Set () can be used
  * to set OLSR attributes.  These include HelloInterval, TcInterval,
  * MidInterval, Willingness.  Other parameters are defined as macros
- * in olsr-agent-impl.cc.
+ * in olsr-routing-protocol.cc.
  */
 
 
Binary file src/routing/olsr/test/bug780-0-0.pcap has changed
Binary file src/routing/olsr/test/bug780-1-0.pcap has changed
Binary file src/routing/olsr/test/bug780-2-0.pcap has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/routing/olsr/test/bug780-test.cc	Mon Dec 21 16:07:08 2009 +0000
@@ -0,0 +1,198 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/* 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
+ *
+ */
+
+#include <fstream>
+#include <iostream>
+
+#include "ns3/test.h"
+#include "ns3/olsr-helper.h"
+#include "ns3/ipv4-list-routing-helper.h"
+#include "ns3/wifi-helper.h"
+#include "ns3/yans-wifi-helper.h"
+#include "ns3/nqos-wifi-mac-helper.h"
+#include "ns3/constant-velocity-mobility-model.h"
+#include "ns3/mobility-helper.h"
+#include "ns3/olsr-routing-protocol.h"
+#include "ns3/internet-stack-helper.h"
+#include "ns3/log.h"
+#include "ns3/config.h"
+#include "ns3/double.h"
+#include "ns3/string.h"
+#include "ns3/boolean.h"
+#include "ns3/ipv4-address-helper.h"
+#include "ns3/ipv4-interface-container.h"
+#include "ns3/internet-stack-helper.h"
+#include "ns3/v4ping-helper.h"
+#include "ns3/pcap-file.h"
+
+#include "bug780-test.h"
+
+/// Set to true to rewrite reference traces, leave false to run regression tests
+namespace 
+{
+  const bool WRITE_VECTORS = false;
+}
+
+
+namespace ns3
+{
+namespace olsr
+{
+
+const char * const Bug780Test::PREFIX = "bug780";
+
+static void
+SetVelocity (Ptr<Node> node, Vector vel)
+{
+  Ptr<ConstantVelocityMobilityModel> mobility =
+    node->GetObject<ConstantVelocityMobilityModel> ();
+  mobility->SetVelocity (vel);
+}
+
+
+Bug780Test::Bug780Test() : 
+  TestCase ("Test OLSR bug 780"),
+  m_time (Seconds (200.0))
+{
+}
+
+Bug780Test::~Bug780Test()
+{
+}
+
+bool
+Bug780Test::DoRun ()
+{
+  SeedManager::SetSeed(123);
+  CreateNodes ();
+  
+  Simulator::Stop (m_time);
+  Simulator::Run ();
+  Simulator::Destroy ();
+  
+  if (!WRITE_VECTORS)
+    {
+      CheckResults ();  
+    }
+  return GetErrorStatus ();
+}
+
+void
+Bug780Test::CreateNodes (void)
+{
+  int nWifis = 3;
+  double SimTime = 200.0;
+  std::string phyMode ("wifib-1mbs");
+
+  //sending one packets per sec
+  // Fix non-unicast data rate to be the same as that of unicast
+  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold",
+                      StringValue ("400"));
+
+  NodeContainer adhocNodes;
+  adhocNodes.Create (nWifis);
+
+  WifiHelper wifi;
+  YansWifiPhyHelper wifiPhy =  YansWifiPhyHelper::Default ();
+  YansWifiChannelHelper wifiChannel;
+  wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
+  wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel");
+  wifiPhy.SetChannel (wifiChannel.Create ());
+
+  // Add a non-QoS upper mac, and disable rate control
+  NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
+  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
+      "DataMode",StringValue(phyMode),
+      "ControlMode",StringValue(phyMode));
+
+  //set the tx range to 300
+  wifiPhy.Set ("TxPowerStart",DoubleValue (-0.1615));
+  wifiPhy.Set ("TxPowerEnd", DoubleValue (-0.1615));
+
+  // Set it to adhoc mode
+  wifiMac.SetType ("ns3::AdhocWifiMac");
+  NetDeviceContainer adhocDevices = wifi.Install (wifiPhy, wifiMac, adhocNodes);
+
+  OlsrHelper olsr;
+
+  InternetStackHelper internet;
+  internet.SetRoutingHelper (olsr);
+  internet.Install (adhocNodes);
+
+  Ipv4AddressHelper addressAdhoc;
+  addressAdhoc.SetBase ("10.1.1.0", "255.255.255.0");
+  Ipv4InterfaceContainer adhocInterfaces;
+  adhocInterfaces = addressAdhoc.Assign (adhocDevices);
+
+  MobilityHelper mobilityAdhoc;
+
+  Ptr<ListPositionAllocator> positionAlloc_Adhoc =
+    CreateObject<ListPositionAllocator>();
+  double distance = 0.0;
+  for (uint32_t i = 0;i <= adhocNodes.GetN();i++)
+    {
+      positionAlloc_Adhoc->Add(Vector(distance,0.0,0.0));
+      distance += 250.0;
+    }
+
+  mobilityAdhoc.SetMobilityModel ("ns3::ConstantVelocityMobilityModel");
+  mobilityAdhoc.SetPositionAllocator(positionAlloc_Adhoc);
+  mobilityAdhoc.Install (adhocNodes);
+
+  //At 50 sec node 3 moves towards node 2
+  Simulator::Schedule (Seconds (50.0), &SetVelocity, adhocNodes.Get(2),Vector(-5.0,0.0,0.0));
+  //AT 100 sec set node 3 with zero velocity
+  Simulator::Schedule (Seconds (100.0), &SetVelocity, adhocNodes.Get(2) ,Vector(0.0,0.0,0.0));
+  //Move node2 away from node 3
+  Simulator::Schedule (Seconds (100.0), &SetVelocity, adhocNodes.Get(1),Vector(5.0,0.0,0.0));
+  //AT 150 sec set node 2 with zero velocity
+  Simulator::Schedule (Seconds (150.0), &SetVelocity, adhocNodes.Get(1), Vector(0.0,0.0,0.0));
+
+
+  // Ping 10.1.1.1 -> 10.1.1.2
+  V4PingHelper ping (adhocInterfaces.GetAddress (1));
+  ping.SetAttribute ("Verbose", BooleanValue (true));
+
+  ApplicationContainer p = ping.Install (adhocNodes.Get (0));
+  p.Start (Seconds (50));
+  p.Stop (Seconds (SimTime) - Seconds(0.001));
+
+  // pcap
+  std::string prefix = (WRITE_VECTORS ? NS_TEST_SOURCEDIR : GetTempDir ()) + PREFIX;
+  wifiPhy.EnablePcapAll (prefix);
+}
+
+void
+Bug780Test::CheckResults ()
+{
+  for (uint32_t i = 0; i < 2; ++i)
+    {
+      std::ostringstream os1, os2;
+      // File naming conventions are hard-coded here.
+      os1 << NS_TEST_SOURCEDIR << PREFIX << "-" << i << "-0.pcap";
+      os2 << GetTempDir () << PREFIX << "-" << i << "-0.pcap";
+      
+      uint32_t sec(0), usec(0);
+      bool diff = PcapFile::Diff (os1.str(), os2.str(), sec, usec);
+      NS_TEST_EXPECT_MSG_EQ (diff, false, "PCAP traces " << os1.str() << " and " << os2.str() 
+                                       << " differ starting from " << sec << " s " << usec << " us");
+    }
+}
+
+} // namespace olsr
+} // namespace ns3
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/routing/olsr/test/bug780-test.h	Mon Dec 21 16:07:08 2009 +0000
@@ -0,0 +1,49 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * 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>
+ */
+
+#ifndef BUG780_REGRESSIONTEST_H_
+#define BUG780_REGRESSIONTEST_H_
+#include "ns3/test.h"
+#include "ns3/nstime.h"
+#include "ns3/node-container.h"
+
+namespace ns3
+{
+namespace olsr
+{
+class Bug780Test : public TestCase
+{
+public:
+  Bug780Test (); 
+  ~Bug780Test ();
+private:
+  /// Unique PCAP files prefix for this test
+  static const char * const PREFIX;
+  /// Total simulation time
+  const Time m_time;
+  /// Create & configure test network
+  void CreateNodes ();
+  /// Compare traces with reference ones
+  void CheckResults ();
+  /// Go
+  bool DoRun ();
+};
+
+}
+}
+#endif
--- a/src/routing/olsr/test/regression-test-suite.cc	Sun Dec 20 18:24:46 2009 +0100
+++ b/src/routing/olsr/test/regression-test-suite.cc	Mon Dec 21 16:07:08 2009 +0000
@@ -20,6 +20,7 @@
 
 #include "hello-regression-test.h"
 #include "tc-regression-test.h"
+#include "bug780-test.h"
 
 namespace ns3 {
 namespace olsr {
@@ -31,6 +32,7 @@
   {
     AddTestCase (new HelloRegressionTest);
     AddTestCase (new TcRegressionTest);
+    AddTestCase (new Bug780Test);
   }
 } g_olsrRegressionTestSuite;
 
--- a/src/routing/olsr/wscript	Sun Dec 20 18:24:46 2009 +0100
+++ b/src/routing/olsr/wscript	Mon Dec 21 16:07:08 2009 +0000
@@ -10,6 +10,7 @@
         'test/regression-test-suite.cc',
         'test/hello-regression-test.cc',
         'test/tc-regression-test.cc',
+        'test/bug780-test.cc',
         ]
 
     headers = bld.new_task_gen('ns3header')