More than one root works
authorKirill Andreev <andreev@iitp.ru>
Thu, 16 Apr 2009 15:21:09 +0400
changeset 4964 9107f67330f3
parent 4963 869399fad0b6
child 4965 e6e44c9415e7
More than one root works
examples/mesh.cc
src/devices/mesh/dot11s/hwmp-mac-plugin.cc
src/devices/mesh/dot11s/hwmp-protocol.cc
src/devices/mesh/dot11s/hwmp-protocol.h
src/devices/mesh/mesh-wifi-interface-mac.cc
--- a/examples/mesh.cc	Thu Apr 16 14:53:21 2009 +0400
+++ b/examples/mesh.cc	Thu Apr 16 15:21:09 2009 +0400
@@ -82,6 +82,7 @@
   mesh.SetSpreadInterfaceChannels (chan);
   std::vector<uint32_t> roots;
   //roots.push_back(xSize-1);
+  //roots.push_back(xSize*ySize-xSize);
   NetDeviceContainer meshDevices = mesh.Install (wifiPhy, nodes, roots, nIfaces);
   
   // Setup mobility
@@ -108,14 +109,14 @@
   // Install applications
   UdpEchoServerHelper echoServer (9);
   ApplicationContainer serverApps = echoServer.Install (nodes.Get (0));
-  serverApps.Start (Seconds (7.0));
+  serverApps.Start (Seconds (0.0));
   serverApps.Stop (Seconds (totalTime));
   UdpEchoClientHelper echoClient (interfaces.GetAddress (0), 9);
   echoClient.SetAttribute ("MaxPackets", UintegerValue ((uint32_t)(totalTime*(1/packetInterval))));
   echoClient.SetAttribute ("Interval", TimeValue (Seconds (packetInterval)));
   echoClient.SetAttribute ("PacketSize", UintegerValue (packetSize));
   ApplicationContainer clientApps = echoClient.Install (nodes.Get (xSize*ySize-1));
-  clientApps.Start (Seconds (7.0));
+  clientApps.Start (Seconds (0.0));
   clientApps.Stop (Seconds (totalTime));
   
   // Enable PCAP trace
--- a/src/devices/mesh/dot11s/hwmp-mac-plugin.cc	Thu Apr 16 14:53:21 2009 +0400
+++ b/src/devices/mesh/dot11s/hwmp-mac-plugin.cc	Thu Apr 16 15:21:09 2009 +0400
@@ -73,7 +73,10 @@
     };
     tag.SetSeqno (meshHdr.GetMeshSeqno ());
     if(meshHdr.GetMeshTtl () == 0)
+    {
+      NS_ASSERT(false);
       return false;
+    }
     tag.SetTtl (meshHdr.GetMeshTtl () - 1);
     if(m_protocol->GetAddress() != destination)
       packet->AddPacketTag(tag);
--- a/src/devices/mesh/dot11s/hwmp-protocol.cc	Thu Apr 16 14:53:21 2009 +0400
+++ b/src/devices/mesh/dot11s/hwmp-protocol.cc	Thu Apr 16 15:21:09 2009 +0400
@@ -30,6 +30,7 @@
 #include "ns3/wifi-net-device.h"
 #include "ns3/mesh-point-device.h"
 #include "ns3/mesh-wifi-interface-mac.h"
+#include "ns3/random-variable.h"
 #include "ie-dot11s-preq.h"
 #include "ie-dot11s-prep.h"
 #include "ie-dot11s-perr.h"
@@ -135,8 +136,12 @@
         BooleanValue (false),
         MakeUintegerAccessor (&HwmpProtocol::m_rfFlag),
         MakeUintegerChecker<bool> ()
+        )
+  .AddAttribute ("RandomStart", "Random delay at first proactive PREQ",
+        TimeValue (Seconds (0.1)),
+        MakeTimeAccessor (&HwmpProtocol::m_randomStart),
+        MakeTimeChecker ()
         );
-
   return tid;
 }
 HwmpProtocol::HwmpProtocol ():
@@ -326,14 +331,20 @@
           //per destination flags DO and RF
           NS_ASSERT (preq.GetDestCount() == 1);
           NS_ASSERT (((*i)->IsDo()) && ((*i)->IsRf()));
-          m_rtable->AddProactivePath (
-              preq.GetMetric (),
-              preq.GetOriginatorAddress (),
-              from,
-              interface,
-              MicroSeconds (preq.GetLifetime () * 1024),
-              preq.GetOriginatorSeqNumber ()
-              );
+          //Add proactive path only if it is the better then existed
+          //before
+          if(
+              ((m_rtable->LookupProactive ()).retransmitter == Mac48Address::GetBroadcast ()) ||
+              ((m_rtable->LookupProactive ()).metric > preq.GetMetric ())
+            )
+            m_rtable->AddProactivePath (
+                preq.GetMetric (),
+                preq.GetOriginatorAddress (),
+                from,
+                interface,
+                MicroSeconds (preq.GetLifetime () * 1024),
+                preq.GetOriginatorSeqNumber ()
+                );
           ProactivePathResolved ();
           if (!preq.IsNeedNotPrep ())
               SendPrep (
@@ -781,7 +792,10 @@
 void
 HwmpProtocol::SetRoot ()
 {
-  NS_LOG_UNCOND("ROOT IS"<<m_address);
+  UniformVariable coefficient (0.0, m_randomStart.GetSeconds());
+  Time randomStart = Seconds (coefficient.GetValue());
+  m_proactivePreqTimer = Simulator::Schedule (randomStart, &HwmpProtocol::SendProactivePreq, this);
+  NS_LOG_UNCOND("ROOT IS: "<<m_address);
   SendProactivePreq ();
   m_isRoot = true;
 }
--- a/src/devices/mesh/dot11s/hwmp-protocol.h	Thu Apr 16 14:53:21 2009 +0400
+++ b/src/devices/mesh/dot11s/hwmp-protocol.h	Thu Apr 16 15:21:09 2009 +0400
@@ -172,11 +172,12 @@
   //\{
   std::map<Mac48Address, EventId> m_preqTimeouts;
   EventId m_proactivePreqTimer;
+  //Random start in Proactive PREQ propagation
+  Time m_randomStart;
   //\}
   
   /// Packet Queue
-  std::vector<QueuedPacket> m_rqueue;
-  
+  std::vector<QueuedPacket> m_rqueue; 
 private:
   ///\name HWMP-protocol parameters (attributes of GetTypeId)
   //\{
--- a/src/devices/mesh/mesh-wifi-interface-mac.cc	Thu Apr 16 14:53:21 2009 +0400
+++ b/src/devices/mesh/mesh-wifi-interface-mac.cc	Thu Apr 16 15:21:09 2009 +0400
@@ -41,26 +41,26 @@
 MeshWifiInterfaceMac::GetTypeId ()
 {
   static TypeId tid = TypeId ("ns3::MeshWifiInterfaceMac")
-                      .SetParent<WifiMac> ()
-                      .AddConstructor<MeshWifiInterfaceMac> ()
-                      .AddAttribute ("BeaconInterval", "Beacon Interval",
-                                     TimeValue (Seconds (1.0)),
-                                     MakeTimeAccessor (&MeshWifiInterfaceMac::m_beaconInterval),
-                                     MakeTimeChecker ()
-                                    )
-                      .AddAttribute ("RandomStart", "Window when beacon generating starts (uniform random) in seconds",
-                                     TimeValue (Seconds (0.1)),
-                                     MakeTimeAccessor (&MeshWifiInterfaceMac::m_randomStart),
-                                     MakeTimeChecker ()
-                                    )
-                      .AddAttribute ("BeaconGeneration", "Enable/Disable Beaconing.",
-                                     BooleanValue (true),
-                                     MakeBooleanAccessor (
-                                       &MeshWifiInterfaceMac::SetBeaconGeneration,
-                                       &MeshWifiInterfaceMac::GetBeaconGeneration
-                                     ),
-                                     MakeBooleanChecker ()
-                                    );
+    .SetParent<WifiMac> ()
+    .AddConstructor<MeshWifiInterfaceMac> ()
+    .AddAttribute ("BeaconInterval", "Beacon Interval",
+        TimeValue (Seconds (1.0)),
+        MakeTimeAccessor (&MeshWifiInterfaceMac::m_beaconInterval),
+        MakeTimeChecker ()
+        )
+    .AddAttribute ("RandomStart", "Window when beacon generating starts (uniform random) in seconds",
+        TimeValue (Seconds (0.1)),
+        MakeTimeAccessor (&MeshWifiInterfaceMac::m_randomStart),
+        MakeTimeChecker ()
+        )
+    .AddAttribute ("BeaconGeneration", "Enable/Disable Beaconing.",
+        BooleanValue (true),
+        MakeBooleanAccessor (
+          &MeshWifiInterfaceMac::SetBeaconGeneration,
+          &MeshWifiInterfaceMac::GetBeaconGeneration
+          ),
+        MakeBooleanChecker ()
+        );
   return tid;
 }