diff --git a/examples/mesh.cc b/examples/mesh.cc index 74d336139..8983b0830 100644 --- a/examples/mesh.cc +++ b/examples/mesh.cc @@ -59,7 +59,7 @@ main (int argc, char *argv[]) cmd.Parse (argc, argv); NS_LOG_DEBUG ("Grid:" << xSize << "*" << ySize); - + SeedManager::SetSeed(1); // Creating nodes NodeContainer nodes; nodes.Create (ySize*xSize); @@ -101,8 +101,8 @@ main (int argc, char *argv[]) serverApps.Start (Seconds (1.0)); serverApps.Stop (Seconds (10.0)); UdpEchoClientHelper echoClient (interfaces.GetAddress (0), 9); - echoClient.SetAttribute ("MaxPackets", UintegerValue (1000)); - echoClient.SetAttribute ("Interval", TimeValue (Seconds (0.001))); + echoClient.SetAttribute ("MaxPackets", UintegerValue (10000)); + echoClient.SetAttribute ("Interval", TimeValue (Seconds (0.01))); echoClient.SetAttribute ("PacketSize", UintegerValue (1024)); ApplicationContainer clientApps = echoClient.Install (nodes.Get (1)); clientApps.Start (Seconds (2.0)); diff --git a/src/devices/mesh/dot11s/hwmp-mac-plugin.cc b/src/devices/mesh/dot11s/hwmp-mac-plugin.cc index 58c0da6de..23da2cd30 100644 --- a/src/devices/mesh/dot11s/hwmp-mac-plugin.cc +++ b/src/devices/mesh/dot11s/hwmp-mac-plugin.cc @@ -102,7 +102,7 @@ HwmpMacPlugin::Receive (Ptr packet, const WifiMacHeader & header) if (preq.GetTtl () == 0) return false; preq.DecrementTtl (); - m_protocol->ReceivePreq (preq, header.GetAddr2 (), m_ifIndex); + m_protocol->ReceivePreq (preq, header.GetAddr2 (), m_ifIndex, m_parent->GetLinkMetric(header.GetAddr2 ())); return false; } case WifiMeshMultihopActionHeader::PATH_REPLY: @@ -112,7 +112,7 @@ HwmpMacPlugin::Receive (Ptr packet, const WifiMacHeader & header) if(prep.GetTtl () == 0) return false; prep.DecrementTtl (); - m_protocol->ReceivePrep (prep, header.GetAddr2 (), m_ifIndex); + m_protocol->ReceivePrep (prep, header.GetAddr2 (), m_ifIndex, m_parent->GetLinkMetric(header.GetAddr2 ())); return false; } case WifiMeshMultihopActionHeader::PATH_ERROR: @@ -309,5 +309,10 @@ HwmpMacPlugin::SendPerr(IePerr perr, std::vector receivers) } SendOnePerr (); } +uint32_t +HwmpMacPlugin::GetLinkMetric(Mac48Address peerAddress) +{ + return m_parent->GetLinkMetric(peerAddress); +} } //namespace dot11s }//namespace ns3 diff --git a/src/devices/mesh/dot11s/hwmp-mac-plugin.h b/src/devices/mesh/dot11s/hwmp-mac-plugin.h index 55ebba39c..b20e76d87 100644 --- a/src/devices/mesh/dot11s/hwmp-mac-plugin.h +++ b/src/devices/mesh/dot11s/hwmp-mac-plugin.h @@ -69,6 +69,9 @@ private: /// Sends one PREQ when PreqMinInterval after last PREQ expires (if any PREQ exists in rhe queue) void SendOnePreq (); void SendOnePerr (); + /// Returns metric to HWMP protocol, needed only by metrics to add + //peer as routing entry + uint32_t GetLinkMetric (Mac48Address peerAddress); private: Ptr m_parent; uint32_t m_ifIndex; diff --git a/src/devices/mesh/dot11s/hwmp-protocol.cc b/src/devices/mesh/dot11s/hwmp-protocol.cc index 9fa083025..7eb4a18ca 100644 --- a/src/devices/mesh/dot11s/hwmp-protocol.cc +++ b/src/devices/mesh/dot11s/hwmp-protocol.cc @@ -114,9 +114,15 @@ HwmpProtocol::GetTypeId () ) .AddAttribute ("unicastPreqThreshold", "Maximum number of PREQ receivers, when we send a PREQ as a chain of unicasts", - UintegerValue (0), + UintegerValue (1), MakeUintegerAccessor (&HwmpProtocol::m_unicastPreqThreshold), - MakeUintegerChecker (0) + MakeUintegerChecker (1) + ) + .AddAttribute ("unicastDataThreshold", + "Maximum number ofbroadcast receivers, when we send a broadcast as a chain of unicasts", + UintegerValue (32), + MakeUintegerAccessor (&HwmpProtocol::m_unicastDataThreshold), + MakeUintegerChecker (1) ) .AddAttribute ("isRoot", "Root mesh point", @@ -200,10 +206,23 @@ HwmpProtocol::RequestRoute ( } if (destination == Mac48Address::GetBroadcast ()) { - packet->RemovePacketTag (tag); + NS_ASSERT(packet->RemovePacketTag (tag)); + for(HwmpPluginMap::const_iterator plugin = m_interfaces.begin (); plugin != m_interfaces.end (); plugin ++) + { + std::vector receivers = GetBroadcastReceivers (plugin->first); + for (std::vector::const_iterator i = receivers.begin (); i != receivers.end(); i ++) + { + Ptr packet_copy = packet->Copy(); + tag.SetAddress (*i); + packet_copy->AddPacketTag (tag); + routeReply (true, packet_copy, source, destination, protocolType, plugin->first); + } + } +#if 0 tag.SetAddress (Mac48Address::GetBroadcast ()); packet->AddPacketTag(tag); routeReply (true, packet, source, destination, protocolType, HwmpRtable::INTERFACE_ANY); +#endif } else return ForwardUnicast(sourceIface, source, destination, packet, protocolType, routeReply); @@ -269,7 +288,7 @@ HwmpProtocol::ForwardUnicast(uint32_t sourceIface, const Mac48Address source, c return true; } void -HwmpProtocol::ReceivePreq (IePreq preq, Mac48Address from, uint32_t interface) +HwmpProtocol::ReceivePreq (IePreq preq, Mac48Address from, uint32_t interface, uint32_t metric) { preq.IncrementMetric (1); //acceptance cretirea: @@ -284,14 +303,13 @@ HwmpProtocol::ReceivePreq (IePreq preq, Mac48Address from, uint32_t interface) if (i->second > preq.GetOriginatorSeqNumber ()) return; if (i->second == preq.GetOriginatorSeqNumber ()) - { - //find metric - std::map::iterator j = - m_lastHwmpMetric.find (preq.GetOriginatorAddress()); - NS_ASSERT (j != m_lastHwmpSeqno.end()); - if (j->second <= preq.GetMetric ()) - return; - } + { + //find metric + std::map::iterator j = m_lastHwmpMetric.find (preq.GetOriginatorAddress()); + NS_ASSERT (j != m_lastHwmpSeqno.end()); + if (j->second <= preq.GetMetric ()) + return; + } m_lastHwmpSeqno[preq.GetOriginatorAddress ()] = preq.GetOriginatorSeqNumber(); m_lastHwmpMetric[preq.GetOriginatorAddress ()] = preq.GetMetric(); } @@ -389,9 +407,9 @@ HwmpProtocol::ReceivePreq (IePreq preq, Mac48Address from, uint32_t interface) i->second->SendPreq (preq); } void -HwmpProtocol::ReceivePrep (IePrep prep, Mac48Address from, uint32_t interface) +HwmpProtocol::ReceivePrep (IePrep prep, Mac48Address from, uint32_t interface, uint32_t metric) { - prep.IncrementMetric (1); + prep.IncrementMetric (metric); //acceptance cretirea: std::map::iterator i = m_lastHwmpSeqno.find (prep.GetOriginatorAddress()); if (i == m_lastHwmpSeqno.end ()) @@ -507,8 +525,10 @@ HwmpProtocol::PeerLinkStatus(Mac48Address meshPointAddress, Mac48Address peerAdd if(status) { HwmpRtable::LookupResult result = m_rtable->LookupReactive(meshPointAddress); + HwmpPluginMap::iterator i = m_interfaces.find(interface); + NS_ASSERT(i != m_interfaces.end ()); if(result.retransmitter == Mac48Address::GetBroadcast ()) - m_rtable->AddReactivePath(meshPointAddress, peerAddress, interface, 1, Seconds (0), 0); + m_rtable->AddReactivePath(meshPointAddress, peerAddress, interface, 1, Seconds (0), i->second->GetLinkMetric(peerAddress)); } else { @@ -588,6 +608,19 @@ HwmpProtocol::GetPreqReceivers (uint32_t interface) } return retval; } +std::vector +HwmpProtocol::GetBroadcastReceivers (uint32_t interface) +{ + std::vector retval; + if(!m_neighboursCallback.IsNull ()) retval = m_neighboursCallback (interface); + if (retval.size() >= m_unicastDataThreshold) + { + retval.clear (); + retval.push_back (Mac48Address::GetBroadcast ()); + } + return retval; +} + bool HwmpProtocol::QueuePacket (QueuedPacket packet) { diff --git a/src/devices/mesh/dot11s/hwmp-protocol.h b/src/devices/mesh/dot11s/hwmp-protocol.h index f86262c7a..c9c4fd242 100644 --- a/src/devices/mesh/dot11s/hwmp-protocol.h +++ b/src/devices/mesh/dot11s/hwmp-protocol.h @@ -77,8 +77,8 @@ private: ///\name Interaction with HWMP MAC plugin //\{ - void ReceivePreq(IePreq preq, Mac48Address from, uint32_t interface); - void ReceivePrep(IePrep prep, Mac48Address from, uint32_t interface); + void ReceivePreq(IePreq preq, Mac48Address from, uint32_t interface, uint32_t metric); + void ReceivePrep(IePrep prep, Mac48Address from, uint32_t interface, uint32_t metric); void ReceivePerr(IePerr perr, Mac48Address from, uint32_t interface); void SendPrep ( Mac48Address src, @@ -97,7 +97,9 @@ private: /// \return list of addresses where a PERR should be sent to std::vector GetPreqReceivers (uint32_t interface); - + /// \return list of addresses where a broadcast should be + //retransmitted + std::vector GetBroadcastReceivers (uint32_t interface); /** * \brief MAC-plugin asks wether the frame can be dropeed. Protocol automatically updates seqno. * @@ -188,6 +190,7 @@ private: uint8_t m_maxTtl; uint8_t m_unicastPerrThreshold; uint8_t m_unicastPreqThreshold; + uint8_t m_unicastDataThreshold; bool m_doFlag; bool m_rfFlag; //\} diff --git a/src/devices/mesh/dot11s/ie-dot11s-preq.cc b/src/devices/mesh/dot11s/ie-dot11s-preq.cc index 3e8055f06..1b9ba4276 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-preq.cc +++ b/src/devices/mesh/dot11s/ie-dot11s-preq.cc @@ -337,6 +337,7 @@ IePreq::PrintInformation (std::ostream &os) const os << " metric = " << m_metric << "\n"; os << " seqno = " << m_originatorSeqNumber << "\n"; os << " lifetime = " << m_lifetime << "\n"; + os << " preq ID = " <GetDestinationAddress () << "\n"; diff --git a/src/devices/mesh/mesh-point-device.cc b/src/devices/mesh/mesh-point-device.cc index 185da3966..07a810d2c 100644 --- a/src/devices/mesh/mesh-point-device.cc +++ b/src/devices/mesh/mesh-point-device.cc @@ -82,14 +82,13 @@ MeshPointDevice::ReceiveFromDevice (Ptr incomingPort, PtrGetUid ()); const Mac48Address src48 = Mac48Address::ConvertFrom (src); const Mac48Address dst48 = Mac48Address::ConvertFrom (dst); - NS_LOG_UNCOND("SRC="< packet, const Address& dest, uint16_t protocolNumber) { const Mac48Address dst48 = Mac48Address::ConvertFrom (dest); + NS_LOG_DEBUG("SEND:, DST = "< packet, WifiMacHeader const *hdr) } } } - // Filter frame through all installed plugins for (PluginList::iterator i = m_plugins.begin (); i != m_plugins.end(); ++i) { @@ -596,6 +595,10 @@ MeshWifiInterfaceMac::Receive (Ptr packet, WifiMacHeader const *hdr) if (hdr->IsData ()) ForwardUp (packet, hdr->GetAddr4(), hdr->GetAddr3()); } - +uint32_t +MeshWifiInterfaceMac::GetLinkMetric (Mac48Address peerAddress) +{ + return 1; +} } // namespace ns3 diff --git a/src/devices/mesh/mesh-wifi-interface-mac.h b/src/devices/mesh/mesh-wifi-interface-mac.h index de13faea2..8648c85cf 100644 --- a/src/devices/mesh/mesh-wifi-interface-mac.h +++ b/src/devices/mesh/mesh-wifi-interface-mac.h @@ -146,7 +146,7 @@ public: bool CheckSupportedRates(SupportedRates rates) const; /// \return list of supported bitrates SupportedRates GetSupportedRates () const; - + uint32_t GetLinkMetric(Mac48Address peerAddress); private: /// Frame receive handler void Receive (Ptr packet, WifiMacHeader const *hdr);