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"
50 .AddConstructor<HwmpProtocol> ()
51 .AddAttribute (
"RandomStart",
52 "Random delay at first proactive PREQ",
58 .AddAttribute (
"MaxQueueSize",
59 "Maximum number of packets we can store when resolving route",
61 MakeUintegerAccessor (
63 MakeUintegerChecker<uint16_t> (1)
65 .AddAttribute (
"Dot11MeshHWMPmaxPREQretries",
66 "Maximum number of retries before we suppose the destination to be unreachable",
68 MakeUintegerAccessor (
70 MakeUintegerChecker<uint8_t> (1)
72 .AddAttribute (
"Dot11MeshHWMPnetDiameterTraversalTime",
73 "Time we suppose the packet to go from one edge of the network to another",
79 .AddAttribute (
"Dot11MeshHWMPpreqMinInterval",
80 "Minimal interval between to successive PREQs",
86 .AddAttribute (
"Dot11MeshHWMPperrMinInterval",
87 "Minimal interval between to successive PREQs",
92 .AddAttribute (
"Dot11MeshHWMPactiveRootTimeout",
93 "Lifetime of poractive routing information",
99 .AddAttribute (
"Dot11MeshHWMPactivePathTimeout",
100 "Lifetime of reactive routing information",
106 .AddAttribute (
"Dot11MeshHWMPpathToRootInterval",
107 "Interval between two successive proactive PREQs",
113 .AddAttribute (
"Dot11MeshHWMPrannInterval",
114 "Lifetime of poractive routing information",
120 .AddAttribute (
"MaxTtl",
121 "Initial value of Time To Live field",
123 MakeUintegerAccessor (
125 MakeUintegerChecker<uint8_t> (2)
127 .AddAttribute (
"UnicastPerrThreshold",
128 "Maximum number of PERR receivers, when we send a PERR as a chain of unicasts",
130 MakeUintegerAccessor (
132 MakeUintegerChecker<uint8_t> (1)
134 .AddAttribute (
"UnicastPreqThreshold",
135 "Maximum number of PREQ receivers, when we send a PREQ as a chain of unicasts",
137 MakeUintegerAccessor (
139 MakeUintegerChecker<uint8_t> (1)
141 .AddAttribute (
"UnicastDataThreshold",
142 "Maximum number ofbroadcast receivers, when we send a broadcast as a chain of unicasts",
144 MakeUintegerAccessor (
146 MakeUintegerChecker<uint8_t> (1)
148 .AddAttribute (
"DoFlag",
149 "Destination only HWMP flag",
151 MakeBooleanAccessor (
153 MakeBooleanChecker ()
155 .AddAttribute (
"RfFlag",
156 "Reply and forward flag",
158 MakeBooleanAccessor (
160 MakeBooleanChecker ()
162 .AddTraceSource (
"RouteDiscoveryTime",
163 "The time of route discovery procedure",
176 m_randomStart (Seconds (0.1)),
177 m_maxQueueSize (255),
178 m_dot11MeshHWMPmaxPREQretries (3),
179 m_dot11MeshHWMPnetDiameterTraversalTime (MicroSeconds (1024*100)),
180 m_dot11MeshHWMPpreqMinInterval (MicroSeconds (1024*100)),
181 m_dot11MeshHWMPperrMinInterval (MicroSeconds (1024*100)),
182 m_dot11MeshHWMPactiveRootTimeout (MicroSeconds (1024*5000)),
183 m_dot11MeshHWMPactivePathTimeout (MicroSeconds (1024*5000)),
184 m_dot11MeshHWMPpathToRootInterval (MicroSeconds (1024*2000)),
185 m_dot11MeshHWMPrannInterval (MicroSeconds (1024*5000)),
188 m_unicastPerrThreshold (32),
189 m_unicastPreqThreshold (1),
190 m_unicastDataThreshold (1),
219 i->second.preqTimeout.Cancel ();
233 uint32_t sourceIface,
237 uint16_t protocolType,
248 NS_FATAL_ERROR (
"HWMP tag has come with a packet from upper layer. This must not occur...");
261 NS_FATAL_ERROR (
"HWMP tag is supposed to be here at this point.");
275 std::vector<uint16_t> channels;
278 bool shouldSend =
true;
279 for (std::vector<uint16_t>::const_iterator chan = channels.begin (); chan != channels.end (); chan++)
281 if ((*chan) == plugin->second->GetChannelId ())
290 channels.push_back (plugin->second->GetChannelId ());
292 for (std::vector<Mac48Address>::const_iterator i = receivers.begin (); i != receivers.end (); i++)
302 routeReply (
true, packetCopy, source, destination, protocolType, plugin->first);
308 return ForwardUnicast (sourceIface, source, destination, packet, protocolType, routeReply, tag.
GetTtl ());
319 NS_FATAL_ERROR (
"HWMP tag must exist when packet received from the network");
342 routeReply (
true, packet, source, destination, protocolType, result.
ifIndex);
374 uint32_t dst_seqno = 0;
377 dst_seqno = result.
seqnum;
382 i->second->RequestDestination (destination, originator_seqno, dst_seqno);
387 pkt.
dst = destination;
390 pkt.
reply = routeReply;
410 bool freshInfo (
true);
420 if (i->second.second <= preq.
GetMetric ())
473 NS_ASSERT (((*i)->IsDo ()) && ((*i)->IsRf ()));
506 if ((*i)->GetDestinationAddress () ==
GetAddress ())
528 if ((lifetime > 0) && ((int32_t)(result.
seqnum - (*i)->GetDestSeqNumber ()) >= 0))
531 (*i)->GetDestinationAddress (),
544 (*i)->SetFlags (
true,
false, (*i)->IsUsn ());
563 i->second->SendPreq (preq);
573 bool freshInfo (
true);
577 if ((int32_t)(i->second.first - sequence) > 0)
581 if (i->second.first == sequence)
641 HwmpProtocolMacMap::const_iterator prep_sender =
m_interfaces.find (result.ifIndex);
643 prep_sender->second->SendPrep (prep, result.retransmitter);
650 std::vector<FailedDestination> retval;
652 for (
unsigned int i = 0; i < destinations.size (); i++)
657 (result.
ifIndex != interface) ||
658 ((int32_t)(result.
seqnum - destinations[i].seqnum) > 0)
661 retval.push_back (destinations[i]);
664 if (retval.size () == 0)
676 uint32_t originatorDsn,
677 uint32_t destinationSN,
690 HwmpProtocolMacMap::const_iterator prep_sender =
m_interfaces.find (interface);
692 prep_sender->second->SendPrep (prep, retransmitter);
700 for (std::vector<
Ptr<NetDevice> >::const_iterator i = interfaces.begin (); i != interfaces.end (); i++)
749 std::map<Mac48Address, uint32_t,std::less<Mac48Address> >::const_iterator i =
m_lastDataSeqno.find (source);
756 if ((int32_t)(i->second - seqno) >= 0)
775 for (
unsigned int i = 0; i < destinations.size (); i++)
787 std::vector<Mac48Address> receivers_for_interface;
788 for (
unsigned int j = 0; j < perr.
receivers.size (); j++)
792 receivers_for_interface.push_back (perr.
receivers[j].second);
795 i->second->InitiatePerr (perr.
destinations, receivers_for_interface);
803 std::vector<Mac48Address> receivers_for_interface;
804 for (
unsigned int j = 0; j < perr.
receivers.size (); j++)
808 receivers_for_interface.push_back (perr.
receivers[j].second);
811 i->second->ForwardPerr (perr.
destinations, receivers_for_interface);
815 std::vector<std::pair<uint32_t, Mac48Address> >
819 for (
unsigned int i = 0; i < failedDest.size (); i++)
824 for (
unsigned int j = 0; j < precursors.size (); j++)
826 retval.push_back (precursors[j]);
830 for (
unsigned int i = 0; i < retval.size (); i++)
832 for (
unsigned int j = i+1; j < retval.size (); j++)
834 if (retval[i].second == retval[j].second)
836 retval.erase (retval.begin () + j);
842 std::vector<Mac48Address>
845 std::vector<Mac48Address> retval;
857 std::vector<Mac48Address>
860 std::vector<Mac48Address> retval;
889 for (std::vector<QueuedPacket>::iterator i =
m_rqueue.begin (); i !=
m_rqueue.end (); i++)
917 std::map<Mac48Address, PreqEvent>::iterator i =
m_preqTimeouts.find (dst);
927 while (packet.
pkt != 0)
948 while (packet.
pkt != 0)
969 std::map<Mac48Address, PreqEvent>::const_iterator i =
m_preqTimeouts.find (dst);
990 std::map<Mac48Address, PreqEvent>::iterator i =
m_preqTimeouts.find (dst);
999 while (packet.
pkt != 0)
1005 std::map<Mac48Address, PreqEvent>::iterator i =
m_preqTimeouts.find (dst);
1016 i->second->RequestDestination (dst, originator_seqno, dst_seqno);
1052 i->second->SendPreq (preq);
1123 os <<
"<Statistics "
1124 "txUnicast=\"" << txUnicast <<
"\" "
1125 "txBroadcast=\"" << txBroadcast <<
"\" "
1126 "txBytes=\"" << txBytes <<
"\" "
1127 "droppedTtl=\"" << droppedTtl <<
"\" "
1128 "totalQueued=\"" << totalQueued <<
"\" "
1129 "totalDropped=\"" << totalDropped <<
"\" "
1130 "initiatedPreq=\"" << initiatedPreq <<
"\" "
1131 "initiatedPrep=\"" << initiatedPrep <<
"\" "
1132 "initiatedPerr=\"" << initiatedPerr <<
"\"/>" << std::endl;
1138 "address=\"" <<
m_address <<
"\"" << std::endl <<
1148 "isRoot=\"" <<
m_isRoot <<
"\"" << std::endl <<
1149 "maxTtl=\"" << (uint16_t)
m_maxTtl <<
"\"" << std::endl <<
1153 "doFlag=\"" <<
m_doFlag <<
"\"" << std::endl <<
1154 "rfFlag=\"" <<
m_rfFlag <<
"\">" << std::endl;
1158 plugin->second->Report (os);
1160 os <<
"</Hwmp>" << std::endl;
1168 plugin->second->ResetStats ();