26 #include "ns3/simulator.h"
27 #include "ns3/packet.h"
28 #include "ns3/mesh-point-device.h"
29 #include "ns3/wifi-net-device.h"
30 #include "ns3/mesh-point-device.h"
31 #include "ns3/mesh-wifi-interface-mac.h"
32 #include "ns3/random-variable-stream.h"
36 #include "ns3/trace-source-accessor.h"
52 .AddConstructor<HwmpProtocol> ()
53 .AddAttribute (
"RandomStart",
54 "Random delay at first proactive PREQ",
60 .AddAttribute (
"MaxQueueSize",
61 "Maximum number of packets we can store when resolving route",
63 MakeUintegerAccessor (
65 MakeUintegerChecker<uint16_t> (1)
67 .AddAttribute (
"Dot11MeshHWMPmaxPREQretries",
68 "Maximum number of retries before we suppose the destination to be unreachable",
70 MakeUintegerAccessor (
72 MakeUintegerChecker<uint8_t> (1)
74 .AddAttribute (
"Dot11MeshHWMPnetDiameterTraversalTime",
75 "Time we suppose the packet to go from one edge of the network to another",
81 .AddAttribute (
"Dot11MeshHWMPpreqMinInterval",
82 "Minimal interval between to successive PREQs",
88 .AddAttribute (
"Dot11MeshHWMPperrMinInterval",
89 "Minimal interval between to successive PREQs",
94 .AddAttribute (
"Dot11MeshHWMPactiveRootTimeout",
95 "Lifetime of poractive routing information",
101 .AddAttribute (
"Dot11MeshHWMPactivePathTimeout",
102 "Lifetime of reactive routing information",
108 .AddAttribute (
"Dot11MeshHWMPpathToRootInterval",
109 "Interval between two successive proactive PREQs",
115 .AddAttribute (
"Dot11MeshHWMPrannInterval",
116 "Lifetime of poractive routing information",
122 .AddAttribute (
"MaxTtl",
123 "Initial value of Time To Live field",
125 MakeUintegerAccessor (
127 MakeUintegerChecker<uint8_t> (2)
129 .AddAttribute (
"UnicastPerrThreshold",
130 "Maximum number of PERR receivers, when we send a PERR as a chain of unicasts",
132 MakeUintegerAccessor (
134 MakeUintegerChecker<uint8_t> (1)
136 .AddAttribute (
"UnicastPreqThreshold",
137 "Maximum number of PREQ receivers, when we send a PREQ as a chain of unicasts",
139 MakeUintegerAccessor (
141 MakeUintegerChecker<uint8_t> (1)
143 .AddAttribute (
"UnicastDataThreshold",
144 "Maximum number ofbroadcast receivers, when we send a broadcast as a chain of unicasts",
146 MakeUintegerAccessor (
148 MakeUintegerChecker<uint8_t> (1)
150 .AddAttribute (
"DoFlag",
151 "Destination only HWMP flag",
153 MakeBooleanAccessor (
155 MakeBooleanChecker ()
157 .AddAttribute (
"RfFlag",
158 "Reply and forward flag",
160 MakeBooleanAccessor (
162 MakeBooleanChecker ()
164 .AddTraceSource (
"RouteDiscoveryTime",
165 "The time of route discovery procedure",
178 m_randomStart (Seconds (0.1)),
179 m_maxQueueSize (255),
180 m_dot11MeshHWMPmaxPREQretries (3),
181 m_dot11MeshHWMPnetDiameterTraversalTime (MicroSeconds (1024*100)),
182 m_dot11MeshHWMPpreqMinInterval (MicroSeconds (1024*100)),
183 m_dot11MeshHWMPperrMinInterval (MicroSeconds (1024*100)),
184 m_dot11MeshHWMPactiveRootTimeout (MicroSeconds (1024*5000)),
185 m_dot11MeshHWMPactivePathTimeout (MicroSeconds (1024*5000)),
186 m_dot11MeshHWMPpathToRootInterval (MicroSeconds (1024*2000)),
187 m_dot11MeshHWMPrannInterval (MicroSeconds (1024*5000)),
190 m_unicastPerrThreshold (32),
191 m_unicastPreqThreshold (1),
192 m_unicastDataThreshold (1),
221 i->second.preqTimeout.Cancel ();
235 uint32_t sourceIface,
239 uint16_t protocolType,
250 NS_FATAL_ERROR (
"HWMP tag has come with a packet from upper layer. This must not occur...");
263 NS_FATAL_ERROR (
"HWMP tag is supposed to be here at this point.");
277 std::vector<uint16_t> channels;
280 bool shouldSend =
true;
281 for (std::vector<uint16_t>::const_iterator chan = channels.begin (); chan != channels.end (); chan++)
283 if ((*chan) == plugin->second->GetChannelId ())
292 channels.push_back (plugin->second->GetChannelId ());
294 for (std::vector<Mac48Address>::const_iterator i = receivers.begin (); i != receivers.end (); i++)
304 routeReply (
true, packetCopy, source, destination, protocolType, plugin->first);
310 return ForwardUnicast (sourceIface, source, destination, packet, protocolType, routeReply, tag.
GetTtl ());
321 NS_FATAL_ERROR (
"HWMP tag must exist when packet received from the network");
334 result =
m_rtable->LookupProactive ();
344 routeReply (
true, packet, source, destination, protocolType, result.
ifIndex);
353 result =
m_rtable->LookupReactiveExpired (destination);
361 result =
m_rtable->LookupProactiveExpired ();
365 std::vector<FailedDestination> destinations =
m_rtable->GetUnreachableDestinations (result.
retransmitter);
372 result =
m_rtable->LookupReactiveExpired (destination);
376 uint32_t dst_seqno = 0;
379 dst_seqno = result.
seqnum;
384 i->second->RequestDestination (destination, originator_seqno, dst_seqno);
389 pkt.
dst = destination;
392 pkt.
reply = routeReply;
412 bool freshInfo (
true);
422 if (i->second.second <= preq.
GetMetric ())
453 (
m_rtable->LookupReactive (fromMp).metric > metric)
475 NS_ASSERT (((*i)->IsDo ()) && ((*i)->IsRf ()));
508 if ((*i)->GetDestinationAddress () ==
GetAddress ())
530 if ((lifetime > 0) && ((int32_t)(result.
seqnum - (*i)->GetDestSeqNumber ()) >= 0))
533 (*i)->GetDestinationAddress (),
542 m_rtable->AddPrecursor ((*i)->GetDestinationAddress (), interface, from,
546 (*i)->SetFlags (
true,
false, (*i)->IsUsn ());
565 i->second->SendPreq (preq);
575 bool freshInfo (
true);
579 if ((int32_t)(i->second.first - sequence) > 0)
583 if (i->second.first == sequence)
621 ((
m_rtable->LookupReactive (fromMp)).metric > metric)
643 HwmpProtocolMacMap::const_iterator prep_sender =
m_interfaces.find (result.ifIndex);
645 prep_sender->second->SendPrep (prep, result.retransmitter);
652 std::vector<FailedDestination> retval;
654 for (
unsigned int i = 0; i < destinations.size (); i++)
656 result =
m_rtable->LookupReactiveExpired (destinations[i].destination);
659 (result.
ifIndex != interface) ||
660 ((int32_t)(result.
seqnum - destinations[i].seqnum) > 0)
663 retval.push_back (destinations[i]);
666 if (retval.size () == 0)
678 uint32_t originatorDsn,
679 uint32_t destinationSN,
692 HwmpProtocolMacMap::const_iterator prep_sender =
m_interfaces.find (interface);
694 prep_sender->second->SendPrep (prep, retransmitter);
701 std::vector<Ptr<NetDevice> >
interfaces = mp->GetInterfaces ();
702 for (std::vector<
Ptr<NetDevice> >::const_iterator i = interfaces.begin (); i != interfaces.end (); i++)
718 mac->InstallPlugin (hwmpMac);
723 mp->SetRoutingProtocol (
this);
725 mp->AggregateObject (
this);
736 std::vector<FailedDestination> destinations =
m_rtable->GetUnreachableDestinations (peerAddress);
751 std::map<Mac48Address, uint32_t,std::less<Mac48Address> >::const_iterator i =
m_lastDataSeqno.find (source);
758 if ((int32_t)(i->second - seqno) >= 0)
777 for (
unsigned int i = 0; i < destinations.size (); i++)
780 m_rtable->DeleteReactivePath (destinations[i].destination);
789 std::vector<Mac48Address> receivers_for_interface;
790 for (
unsigned int j = 0; j < perr.
receivers.size (); j++)
794 receivers_for_interface.push_back (perr.
receivers[j].second);
797 i->second->InitiatePerr (perr.
destinations, receivers_for_interface);
805 std::vector<Mac48Address> receivers_for_interface;
806 for (
unsigned int j = 0; j < perr.
receivers.size (); j++)
810 receivers_for_interface.push_back (perr.
receivers[j].second);
813 i->second->ForwardPerr (perr.
destinations, receivers_for_interface);
817 std::vector<std::pair<uint32_t, Mac48Address> >
821 for (
unsigned int i = 0; i < failedDest.size (); i++)
824 m_rtable->DeleteReactivePath (failedDest[i].destination);
825 m_rtable->DeleteProactivePath (failedDest[i].destination);
826 for (
unsigned int j = 0; j < precursors.size (); j++)
828 retval.push_back (precursors[j]);
832 for (
unsigned int i = 0; i < retval.size (); i++)
834 for (
unsigned int j = i+1; j < retval.size (); j++)
836 if (retval[i].second == retval[j].second)
838 retval.erase (retval.begin () + j);
844 std::vector<Mac48Address>
847 std::vector<Mac48Address> retval;
859 std::vector<Mac48Address>
862 std::vector<Mac48Address> retval;
891 for (std::vector<QueuedPacket>::iterator i =
m_rqueue.begin (); i !=
m_rqueue.end (); i++)
919 std::map<Mac48Address, PreqEvent>::iterator i =
m_preqTimeouts.find (dst);
929 while (packet.
pkt != 0)
950 while (packet.
pkt != 0)
971 std::map<Mac48Address, PreqEvent>::const_iterator i =
m_preqTimeouts.find (dst);
988 result =
m_rtable->LookupProactive ();
992 std::map<Mac48Address, PreqEvent>::iterator i =
m_preqTimeouts.find (dst);
1001 while (packet.
pkt != 0)
1007 std::map<Mac48Address, PreqEvent>::iterator i =
m_preqTimeouts.find (dst);
1015 uint32_t dst_seqno =
m_rtable->LookupReactiveExpired (dst).seqnum;
1018 i->second->RequestDestination (dst, originator_seqno, dst_seqno);
1054 i->second->SendPreq (preq);
1125 os <<
"<Statistics "
1126 "txUnicast=\"" << txUnicast <<
"\" "
1127 "txBroadcast=\"" << txBroadcast <<
"\" "
1128 "txBytes=\"" << txBytes <<
"\" "
1129 "droppedTtl=\"" << droppedTtl <<
"\" "
1130 "totalQueued=\"" << totalQueued <<
"\" "
1131 "totalDropped=\"" << totalDropped <<
"\" "
1132 "initiatedPreq=\"" << initiatedPreq <<
"\" "
1133 "initiatedPrep=\"" << initiatedPrep <<
"\" "
1134 "initiatedPerr=\"" << initiatedPerr <<
"\"/>" << std::endl;
1140 "address=\"" <<
m_address <<
"\"" << std::endl <<
1150 "isRoot=\"" <<
m_isRoot <<
"\"" << std::endl <<
1151 "maxTtl=\"" << (uint16_t)
m_maxTtl <<
"\"" << std::endl <<
1155 "doFlag=\"" <<
m_doFlag <<
"\"" << std::endl <<
1156 "rfFlag=\"" <<
m_rfFlag <<
"\">" << std::endl;
1160 plugin->second->Report (os);
1162 os <<
"</Hwmp>" << std::endl;
1170 plugin->second->ResetStats ();
Time m_dot11MeshHWMPrannInterval
Structure of path error: IePerr and list of receivers: interfaces and MAC address.
void SetDestinationAddress(Mac48Address dest_address)
void SetPreqID(uint32_t id)
bool RequestRoute(uint32_t sourceIface, const Mac48Address source, const Mac48Address destination, Ptr< const Packet > packet, uint16_t protocolType, RouteReplyCallback routeReply)
Route request, inherited from MeshL2RoutingProtocol.
keep track of time values and allow control of global simulation resolution
#define NS_LOG_FUNCTION(parameters)
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
uint32_t GetDestinationSeqNumber() const
Hwmp tag implements interaction between HWMP protocol and MeshWifiMac.
void IncrementMetric(uint32_t metric)
static const uint32_t MAX_METRIC
Maximum (the best?) path metric.
void SetOriginatorSeqNumber(uint32_t originator_seq_number)
Route lookup result, return type of LookupXXX methods.
Time m_dot11MeshHWMPpreqMinInterval
Time m_dot11MeshHWMPperrMinInterval
void SendPrep(Mac48Address src, Mac48Address dst, Mac48Address retransmitter, uint32_t initMetric, uint32_t originatorDsn, uint32_t destinationSN, uint32_t lifetime, uint32_t interface)
forms a path error information element when list of destination fails on a given interface ...
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Time m_dot11MeshHWMPactiveRootTimeout
#define NS_ASSERT(condition)
void ForwardPathError(PathError perr)
Forwards a received path error.
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
See 7.3.2.97 of 802.11s draft 2.07.
uint32_t GetSize(void) const
Mac48Address GetDestinationAddress() const
Mac48Address src
src address
bool Install(Ptr< MeshPointDevice >)
Install HWMP on given mesh point.
void InitiatePathError(PathError perr)
Passes a self-generated PERR to interface-plugin.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
uint32_t CalculateMetric(Mac48Address peerAddress, Ptr< MeshWifiInterfaceMac > mac)
uint32_t GetLifetime() const
void ReactivePathResolved(Mac48Address dst)
void SetOriginatorAddress(Mac48Address originator_address)
std::map< Mac48Address, std::pair< uint32_t, uint32_t > > m_hwmpSeqnoMetricDatabase
keeps HWMP seqno (first in pair) and HWMP metric (second in pair) for each address ...
void SetAddress(Mac48Address retransmitter)
#define NS_FATAL_ERROR(msg)
fatal error handling
uint8_t m_unicastDataThreshold
TracedCallback< Time > m_routeDiscoveryTimeCallback
Route discovery time:
void SetLifetime(uint32_t lifetime)
void ReceivePrep(IePrep prep, Mac48Address from, uint32_t interface, Mac48Address fromMp, uint32_t metric)
forms a path error information element when list of destination fails on a given interface ...
void SendProactivePreq()
Proactive Preq routines:
bool DropDataFrame(uint32_t seqno, Mac48Address source)
MAC-plugin asks whether the frame can be dropped.
QueuedPacket DequeueFirstPacket()
Ptr< T > CreateObject(void)
std::vector< std::pair< uint32_t, Mac48Address > > PrecursorList
Path precursor = {MAC, interface ID}.
Mac48Address GetOriginatorAddress() const
Ptr< Packet > pkt
the packet
Routing table for HWMP – 802.11s routing protocol.
void Print(std::ostream &os) const
std::vector< Mac48Address > GetPreqReceivers(uint32_t interface)
double GetSeconds(void) const
bool RemoveRoutingStuff(uint32_t fromIface, const Mac48Address source, const Mac48Address destination, Ptr< Packet > packet, uint16_t &protocolType)
Cleanup packet from all tags.
Mac48Address GetOriginatorAddress() const
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Time GetPerrMinInterval()
Ptr< MeshPointDevice > GetMeshPoint() const
Each mesh protocol must be installed on the mesh point to work.
uint8_t m_unicastPerrThreshold
std::vector< QueuedPacket > m_rqueue
Packet Queue.
std::vector< std::pair< uint32_t, Mac48Address > > GetPerrReceivers(std::vector< FailedDestination > failedDest)
int64_t GetMicroSeconds(void) const
void RetryPathDiscovery(Mac48Address dst, uint8_t numOfRetry)
Generates PREQ retry when retry timeout has expired and route is still unresolved.
Ptr< MeshPointDevice > m_mp
Host mesh point.
void IncrementMetric(uint32_t metric)
hold objects of type ns3::Time
void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
See 7.3.2.96 of 802.11s draft 2.07.
Hold an unsigned integer type.
bool ForwardUnicast(uint32_t sourceIface, const Mac48Address source, const Mac48Address destination, Ptr< Packet > packet, uint16_t protocolType, RouteReplyCallback routeReply, uint32_t ttl)
Like RequestRoute, but for unicast packets.
Packet waiting its routing information.
Hold together all Wifi-related objects.
NS_LOG_COMPONENT_DEFINE("HwmpProtocol")
static Mac48Address GetBroadcast(void)
void ProactivePathResolved()
HwmpProtocolMacMap m_interfaces
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
uint32_t GetOriginatorSeqNumber() const
uint32_t GetActivePathLifetime()
Ptr< HwmpRtable > m_rtable
Routing table.
void SetOriginatorAddress(Mac48Address originator_address)
void SetLifetime(uint32_t lifetime)
static TypeId GetTypeId()
uint8_t m_unicastPreqThreshold
void ReceivePreq(IePreq preq, Mac48Address from, uint32_t interface, Mac48Address fromMp, uint32_t metric)
forms a path error information element when list of destination fails on a given interface ...
Time m_randomStart
Random start in Proactive PREQ propagation.
Mac48Address GetAddress()
static Mac48Address ConvertFrom(const Address &address)
Ptr< Packet > Copy(void) const
void SetOriginatorSeqNumber(uint32_t originator_seq_number)
uint16_t protocol
protocol number
void SetMetric(uint32_t metric)
uint8_t m_dot11MeshHWMPmaxPREQretries
void AddDestinationAddressElement(bool doFlag, bool rfFlag, Mac48Address dest_address, uint32_t dest_seq_number)
Add a destination address unit: flags, destination and sequence number.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
void DelDestinationAddressElement(Mac48Address dest_address)
Delete a destination address unit by destination.
PathError MakePathError(std::vector< FailedDestination > destinations)
forms a path error information element when list of destination fails on a given interface ...
std::vector< std::pair< uint32_t, Mac48Address > > receivers
list of PathError receivers (in case of unicast PERR)
bool IsNeedNotPrep() const
uint32_t GetNextHwmpSeqno()
uint8_t GetDestCount() const
static Time Now(void)
Return the "current simulation time".
std::vector< Ptr< DestinationAddressUnit > > GetDestinationList()
Get all destinations, which are stored in PREQ:
RouteReplyCallback reply
how to reply
Interface for L2 mesh routing protocol and mesh point communication.
void Report(std::ostream &) const
Statistics:
Mac48Address dst
dst address
Ptr< UniformRandomVariable > m_coefficient
Random variable for random start time.
uint8_t GetUnicastPerrThreshold()
EventId m_proactivePreqTimer
Random start in Proactive PREQ propagation.
Mac48Address retransmitter
Time m_dot11MeshHWMPactivePathTimeout
std::vector< Mac48Address > GetBroadcastReceivers(uint32_t interface)
std::vector< FailedDestination > destinations
destination list: Mac48Address and sequence number
Time m_dot11MeshHWMPpathToRootInterval
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
#define NS_LOG_DEBUG(msg)
Callback< std::vector< Mac48Address >, uint32_t > m_neighboursCallback
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::cancel method.
uint32_t GetLifetime() const
std::map< Mac48Address, uint32_t > m_lastDataSeqno
keeps HWMP seqno (first in pair) and HWMP metric (second in pair) for each address ...
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
QueuedPacket DequeueFirstPacketByDst(Mac48Address dst)
Time GetPreqMinInterval()
uint32_t GetMetric() const
void SetSeqno(uint32_t seqno)
uint32_t inInterface
incoming device interface ID. (if packet has come from upper layers, this is Mesh point ID) ...
bool QueuePacket(QueuedPacket packet)
uint32_t GetMetric() const
bool ShouldSendPreq(Mac48Address dst)
checks when the last path discovery procedure was started for a given destination.
Hold a floating point type.
void SetDestinationSeqNumber(uint32_t dest_seq_number)
void SetHopcount(uint8_t hopcount)
void PeerLinkStatus(Mac48Address meshPontAddress, Mac48Address peerAddress, uint32_t interface, bool status)
void SetAttribute(std::string name, const AttributeValue &value)
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Basic MAC of mesh point Wi-Fi interface.
void SetHopcount(uint8_t hopcount)
std::map< Mac48Address, PreqEvent > m_preqTimeouts
Random start in Proactive PREQ propagation.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Time m_dot11MeshHWMPnetDiameterTraversalTime
void ReceivePerr(std::vector< FailedDestination >, Mac48Address from, uint32_t interface, Mac48Address fromMp)
forms a path error information element when list of destination fails on a given interface ...
void SetNeighboursCallback(Callback< std::vector< Mac48Address >, uint32_t > cb)
This callback is used to obtain active neighbours on a given interface.
virtual void DoInitialize()
This method is called only once by Object::Initialize.