Fixed proactive mode. 1 root works
authorKirill Andreev <andreev@iitp.ru>
Thu, 16 Apr 2009 14:53:21 +0400
changeset 4963 869399fad0b6
parent 4962 00ee1735c339
child 4964 9107f67330f3
Fixed proactive mode. 1 root works
examples/mesh.cc
src/devices/mesh/dot11s/dot11s-helper.cc
src/devices/mesh/dot11s/dot11s-helper.h
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/dot11s/hwmp-rtable.cc
--- a/examples/mesh.cc	Wed Apr 15 20:15:10 2009 +0400
+++ b/examples/mesh.cc	Thu Apr 16 14:53:21 2009 +0400
@@ -49,6 +49,7 @@
   uint32_t  nIfaces         = 2;
   bool      chan            = true;
   bool      pcap            = false;
+  uint64_t  seed            =1;
   
   // Command line arguments
   CommandLine cmd;
@@ -62,10 +63,11 @@
   cmd.AddValue ("interfaces", "Number of radio interfaces used by each mesh point. [1]", nIfaces);
   cmd.AddValue ("channels",   "Use different frequency channels for different interfaces. [0]", chan);
   cmd.AddValue ("pcap",   "Enable PCAP traces on interfaces. [0]", pcap);
+  cmd.AddValue ("seed",   "Seed value", seed);
   
   cmd.Parse (argc, argv);
   NS_LOG_DEBUG ("Grid:" << xSize << "*" << ySize);
-  SeedManager::SetSeed(1);
+  SeedManager::SetSeed(seed);
   // Creating nodes
   NodeContainer nodes;
   nodes.Create (ySize*xSize);
@@ -78,7 +80,9 @@
   // Install mesh point devices & protocols
   MeshWifiHelper mesh;
   mesh.SetSpreadInterfaceChannels (chan);
-  NetDeviceContainer meshDevices = mesh.Install (wifiPhy, nodes, nIfaces);
+  std::vector<uint32_t> roots;
+  //roots.push_back(xSize-1);
+  NetDeviceContainer meshDevices = mesh.Install (wifiPhy, nodes, roots, nIfaces);
   
   // Setup mobility
   MobilityHelper mobility;
@@ -104,14 +108,14 @@
   // Install applications
   UdpEchoServerHelper echoServer (9);
   ApplicationContainer serverApps = echoServer.Install (nodes.Get (0));
-  serverApps.Start (Seconds (0.0));
+  serverApps.Start (Seconds (7.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 (0.0));
+  clientApps.Start (Seconds (7.0));
   clientApps.Stop (Seconds (totalTime));
   
   // Enable PCAP trace
--- a/src/devices/mesh/dot11s/dot11s-helper.cc	Wed Apr 15 20:15:10 2009 +0400
+++ b/src/devices/mesh/dot11s/dot11s-helper.cc	Thu Apr 16 14:53:21 2009 +0400
@@ -91,10 +91,10 @@
 }
   
 NetDeviceContainer
-MeshWifiHelper::Install (const WifiPhyHelper &phyHelper, NodeContainer c, uint32_t nInterfaces) const
+MeshWifiHelper::Install (const WifiPhyHelper &phyHelper, NodeContainer c,  std::vector<uint32_t> roots, uint32_t nInterfaces) const
 {
   NetDeviceContainer devices;
-  
+  uint32_t node_index = 0;
   for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
   {
     Ptr<Node> node = *i;
@@ -140,16 +140,21 @@
     
     pmp->SetPeerLinkStatusCallback(MakeCallback(&HwmpProtocol::PeerLinkStatus, hwmp));
     hwmp->SetNeighboursCallback(MakeCallback(&PeerManagementProtocol::GetActiveLinks, pmp));
-    
+    // Setting root mesh point
+    for(std::vector<uint32_t>::const_iterator root_iterator = roots.begin (); root_iterator != roots.end (); root_iterator ++)
+      //if(*root_iterator == i.GetDistanceFrom(c.Begin ()))
+      if(*root_iterator == node_index)
+        hwmp->SetRoot ();
     devices.Add (mp);
+    node_index ++;
   }
   return devices;
 }
 
 NetDeviceContainer
-MeshWifiHelper::Install (const WifiPhyHelper &phy, Ptr<Node> node, uint32_t nInterfaces) const
+MeshWifiHelper::Install (const WifiPhyHelper &phy, Ptr<Node> node,  std::vector<uint32_t> roots, uint32_t nInterfaces) const
 {
-  return Install (phy, NodeContainer (node), nInterfaces);
+  return Install (phy, NodeContainer (node), roots, nInterfaces);
 }
   
 } // namespace dot11s
--- a/src/devices/mesh/dot11s/dot11s-helper.h	Wed Apr 15 20:15:10 2009 +0400
+++ b/src/devices/mesh/dot11s/dot11s-helper.h	Thu Apr 16 14:53:21 2009 +0400
@@ -62,21 +62,23 @@
    * 
    * \param phy                 Wifi PHY helper
    * \param nodes               List of nodes to install
+   * \param roots               List of root mesh points
    * \param nInterfaces         Number of mesh point radio interfaces (= WiFi NICs)
    * 
    * \return list of created mesh point devices, see MeshPointDevice
    */
-  NetDeviceContainer Install (const WifiPhyHelper &phyHelper, NodeContainer c, uint32_t nInterfaces = 1) const;
+  NetDeviceContainer Install (const WifiPhyHelper &phyHelper, NodeContainer c, std::vector<uint32_t> roots = std::vector<uint32_t> (), uint32_t nInterfaces = 1) const;
   /** 
    * \brief Install 802.11s mesh device & protocols on given node
    * 
    * \param phy                 Wifi PHY helper
    * \param node                Node to install
+   * \param roots               List of root mesh points
    * \param nInterfaces         Number of mesh point radio interfaces (= WiFi NICs)
    * 
    * \return list of created mesh point devices, see MeshPointDevice
    */ 
-  NetDeviceContainer Install (const WifiPhyHelper &phy, Ptr<Node> node, uint32_t nInterfaces = 1) const;
+  NetDeviceContainer Install (const WifiPhyHelper &phy, Ptr<Node> node,  std::vector<uint32_t> roots = std::vector<uint32_t> (), uint32_t nInterfaces = 1) const;
   
 private:
   Ssid m_ssid;
--- a/src/devices/mesh/dot11s/hwmp-mac-plugin.cc	Wed Apr 15 20:15:10 2009 +0400
+++ b/src/devices/mesh/dot11s/hwmp-mac-plugin.cc	Thu Apr 16 14:53:21 2009 +0400
@@ -151,6 +151,12 @@
 void
 HwmpMacPlugin::SendPreq(IePreq preq)
 {
+  if(m_myPreq == m_preqQueue.end ())
+  {
+    m_preqQueue.push_back (preq);
+    m_myPreq = m_preqQueue.end ();
+  }
+  else
   m_preqQueue.push_back (preq);
   SendOnePreq ();
 }
@@ -223,6 +229,8 @@
   }
   //erase queue
   m_preqQueue.erase (m_preqQueue.begin());
+  if(m_preqQueue.size () == 0)
+    m_myPreq = m_preqQueue.end ();
 }
 void
 HwmpMacPlugin::SendOnePerr()
--- a/src/devices/mesh/dot11s/hwmp-protocol.cc	Wed Apr 15 20:15:10 2009 +0400
+++ b/src/devices/mesh/dot11s/hwmp-protocol.cc	Thu Apr 16 14:53:21 2009 +0400
@@ -84,7 +84,7 @@
         )
     .AddAttribute ("dot11MeshHWMPpathToRootInterval",
         "Interval between two successive proactive PREQs",
-        TimeValue (MicroSeconds (1024*5000)),
+        TimeValue (MicroSeconds (1024*2000)),
         MakeTimeAccessor (&HwmpProtocol::m_dot11MeshHWMPpathToRootInterval),
         MakeTimeChecker ()
         )
@@ -124,12 +124,6 @@
         MakeUintegerAccessor (&HwmpProtocol::m_unicastDataThreshold),
         MakeUintegerChecker<uint8_t> (1)
         )
-  .AddAttribute ("isRoot",
-        "Root mesh point",
-        BooleanValue (false),
-        MakeUintegerAccessor (&HwmpProtocol::m_isRoot),
-        MakeUintegerChecker<bool> ()
-        )
   .AddAttribute ("doFlag",
         "Destination only HWMP flag",
         BooleanValue (true),
@@ -149,7 +143,8 @@
     m_dataSeqno (1),
     m_hwmpSeqno (1),
     m_preqId (0),
-    m_rtable (CreateObject<HwmpRtable> ())
+    m_rtable (CreateObject<HwmpRtable> ()),
+    m_isRoot(false)
 {
 }
 
@@ -266,15 +261,12 @@
     //2.  If there was no reactive path, we lookup expired proactive
     //    path. If exist - start path error procedure towards path to
     //    root
-    //3.  If and only if we are a root station - we queue packet
-    if((result.retransmitter == Mac48Address::GetBroadcast ()) && (!m_isRoot))
+    if(result.retransmitter == Mac48Address::GetBroadcast ())
       result = m_rtable->LookupProactiveExpired ();
-    if((result.retransmitter == Mac48Address::GetBroadcast ()) && (!m_isRoot))
+    if(result.retransmitter == Mac48Address::GetBroadcast ())
       return false;
     std::vector<IePerr::FailedDestination> destinations = m_rtable->GetUnreachableDestinations (result.retransmitter);
     MakePathError (destinations);
-    if(!m_isRoot)
-      return false;
   }
   //Request a destination:
   result = m_rtable->LookupReactiveExpired (destination);
@@ -452,9 +444,15 @@
         prep.GetMetric (),
         MicroSeconds(prep.GetLifetime () * 1024),
         prep.GetOriginatorSeqNumber ());
-    m_rtable->AddPrecursor (prep.GetOriginatorAddress (), interface, result.retransmitter);
+    if(result.retransmitter != Mac48Address::GetBroadcast ())
+      m_rtable->AddPrecursor (prep.GetOriginatorAddress (), interface, result.retransmitter);
     ReactivePathResolved (prep.GetOriginatorAddress ());
   }
+  if(prep.GetDestinationAddress () == GetAddress ())
+  {
+    NS_LOG_DEBUG("I am "<<GetAddress ()<<", resolved "<<prep.GetOriginatorAddress ());
+    return;
+  }
   if (result.retransmitter == Mac48Address::GetBroadcast ())
     //try to look for default route
     result = m_rtable->LookupProactive ();
@@ -783,6 +781,7 @@
 void
 HwmpProtocol::SetRoot ()
 {
+  NS_LOG_UNCOND("ROOT IS"<<m_address);
   SendProactivePreq ();
   m_isRoot = true;
 }
@@ -800,14 +799,16 @@
   preq.SetTTL (m_maxTtl);
   if (m_preqId == 0xffffffff)
     m_preqId = 0;
-  preq.SetLifetime (m_dot11MeshHWMPpathToRootInterval.GetMicroSeconds () /1024);
+  preq.SetLifetime (m_dot11MeshHWMPactiveRootTimeout.GetMicroSeconds () /1024);
   //\attention: do not forget to set originator address, sequence
   //number and preq ID in HWMP-MAC plugin
   preq.AddDestinationAddressElement (true, true, Mac48Address::GetBroadcast (), 0);
   preq.SetOriginatorAddress(GetAddress ());
+  preq.SetPreqID (GetNextPreqId ());
+  preq.SetOriginatorSeqNumber (GetNextHwmpSeqno ());
   for(HwmpPluginMap::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i ++)
     i->second->SendPreq(preq);
-  m_proactivePreqTimer = Simulator::Schedule (m_dot11MeshHWMPactiveRootTimeout, &HwmpProtocol::SendProactivePreq, this);
+  m_proactivePreqTimer = Simulator::Schedule (m_dot11MeshHWMPpathToRootInterval, &HwmpProtocol::SendProactivePreq, this);
 }
 bool
 HwmpProtocol::GetDoFlag ()
--- a/src/devices/mesh/dot11s/hwmp-protocol.h	Wed Apr 15 20:15:10 2009 +0400
+++ b/src/devices/mesh/dot11s/hwmp-protocol.h	Thu Apr 16 14:53:21 2009 +0400
@@ -68,6 +68,11 @@
   //given interface
   ///\param interface is the interface ID
   void SetNeighboursCallback(Callback<std::vector<Mac48Address>, uint32_t> cb);
+  ///\name Proactive PREQ mechanism:
+  ///\{
+  void SetRoot ();
+  void UnsetRoot ();
+  ///\}
 private:
   friend class HwmpMacPlugin;
   
@@ -139,8 +144,6 @@
   
   ///\name Proactive Preq routines:
   //\{
-  void SetRoot ();
-  void UnsetRoot ();
   void SendProactivePreq ();
   //\}
   ///\return address of MeshPointDevice
--- a/src/devices/mesh/dot11s/hwmp-rtable.cc	Wed Apr 15 20:15:10 2009 +0400
+++ b/src/devices/mesh/dot11s/hwmp-rtable.cc	Thu Apr 16 14:53:21 2009 +0400
@@ -98,7 +98,6 @@
   uint32_t seqnum
 )
 {
-  NS_ASSERT(false);
   m_root.root = root;
   m_root.retransmitter = retransmitter;
   m_root.metric = metric;