|
79 |
#define OLSR_DUP_HOLD_TIME Seconds (30) |
79 |
#define OLSR_DUP_HOLD_TIME Seconds (30) |
80 |
/// MID holding time. |
80 |
/// MID holding time. |
81 |
#define OLSR_MID_HOLD_TIME (Scalar (3) * m_midInterval) |
81 |
#define OLSR_MID_HOLD_TIME (Scalar (3) * m_midInterval) |
|
|
82 |
/// HNA holding time. |
83 |
#define OLSR_HNA_HOLD_TIME (Scalar (3) * m_hnaInterval) |
82 |
|
84 |
|
83 |
|
85 |
|
84 |
/********** Link types **********/ |
86 |
/********** Link types **********/ |
Lines 165-170
RoutingProtocol::GetTypeId (void)
|
Link Here
|
---|
|
165 |
TimeValue (Seconds (5)), |
167 |
TimeValue (Seconds (5)), |
166 |
MakeTimeAccessor (&RoutingProtocol::m_midInterval), |
168 |
MakeTimeAccessor (&RoutingProtocol::m_midInterval), |
167 |
MakeTimeChecker ()) |
169 |
MakeTimeChecker ()) |
|
|
170 |
.AddAttribute ("HnaInterval", "HNA messages emission interval. Normally it is equal to TcInterval.", |
171 |
TimeValue (Seconds (5)), |
172 |
MakeTimeAccessor (&RoutingProtocol::m_hnaInterval), |
173 |
MakeTimeChecker ()) |
168 |
.AddAttribute ("Willingness", "Willingness of a node to carry and forward traffic for other nodes.", |
174 |
.AddAttribute ("Willingness", "Willingness of a node to carry and forward traffic for other nodes.", |
169 |
EnumValue (OLSR_WILL_DEFAULT), |
175 |
EnumValue (OLSR_WILL_DEFAULT), |
170 |
MakeEnumAccessor (&RoutingProtocol::m_willingness), |
176 |
MakeEnumAccessor (&RoutingProtocol::m_willingness), |
Lines 189-194
RoutingProtocol::RoutingProtocol ()
|
Link Here
|
---|
|
189 |
m_helloTimer (Timer::CANCEL_ON_DESTROY), |
195 |
m_helloTimer (Timer::CANCEL_ON_DESTROY), |
190 |
m_tcTimer (Timer::CANCEL_ON_DESTROY), |
196 |
m_tcTimer (Timer::CANCEL_ON_DESTROY), |
191 |
m_midTimer (Timer::CANCEL_ON_DESTROY), |
197 |
m_midTimer (Timer::CANCEL_ON_DESTROY), |
|
|
198 |
m_hnaTimer (Timer::CANCEL_ON_DESTROY), |
192 |
m_queuedMessagesTimer (Timer::CANCEL_ON_DESTROY) |
199 |
m_queuedMessagesTimer (Timer::CANCEL_ON_DESTROY) |
193 |
{} |
200 |
{} |
194 |
|
201 |
|
Lines 204-209
RoutingProtocol::SetIpv4 (Ptr<Ipv4> ipv4
|
Link Here
|
---|
|
204 |
m_helloTimer.SetFunction (&RoutingProtocol::HelloTimerExpire, this); |
211 |
m_helloTimer.SetFunction (&RoutingProtocol::HelloTimerExpire, this); |
205 |
m_tcTimer.SetFunction (&RoutingProtocol::TcTimerExpire, this); |
212 |
m_tcTimer.SetFunction (&RoutingProtocol::TcTimerExpire, this); |
206 |
m_midTimer.SetFunction (&RoutingProtocol::MidTimerExpire, this); |
213 |
m_midTimer.SetFunction (&RoutingProtocol::MidTimerExpire, this); |
|
|
214 |
m_hnaTimer.SetFunction (&RoutingProtocol::HnaTimerExpire, this); |
207 |
m_queuedMessagesTimer.SetFunction (&RoutingProtocol::SendQueuedMessages, this); |
215 |
m_queuedMessagesTimer.SetFunction (&RoutingProtocol::SendQueuedMessages, this); |
208 |
|
216 |
|
209 |
m_packetSequenceNumber = OLSR_MAX_SEQ_NUM; |
217 |
m_packetSequenceNumber = OLSR_MAX_SEQ_NUM; |
Lines 284-289
void RoutingProtocol::DoStart ()
|
Link Here
|
---|
|
284 |
HelloTimerExpire (); |
292 |
HelloTimerExpire (); |
285 |
TcTimerExpire (); |
293 |
TcTimerExpire (); |
286 |
MidTimerExpire (); |
294 |
MidTimerExpire (); |
|
|
295 |
HnaTimerExpire (); |
287 |
|
296 |
|
288 |
NS_LOG_DEBUG ("OLSR on node " << m_mainAddress << " started"); |
297 |
NS_LOG_DEBUG ("OLSR on node " << m_mainAddress << " started"); |
289 |
} |
298 |
} |
Lines 398-403
RoutingProtocol::RecvOlsr (Ptr<Socket> s
|
Link Here
|
---|
|
398 |
ProcessMid (messageHeader, senderIfaceAddr); |
407 |
ProcessMid (messageHeader, senderIfaceAddr); |
399 |
break; |
408 |
break; |
400 |
|
409 |
|
|
|
410 |
case olsr::MessageHeader::HNA_MESSAGE: |
411 |
NS_LOG_DEBUG (Simulator::Now ().GetSeconds () |
412 |
<< "s OLSR node " << m_mainAddress |
413 |
<< " received HNA message of size " << messageHeader.GetSerializedSize ()); |
414 |
ProcessHna (messageHeader, senderIfaceAddr); |
415 |
break; |
401 |
default: |
416 |
default: |
402 |
NS_LOG_DEBUG ("OLSR message type " << |
417 |
NS_LOG_DEBUG ("OLSR message type " << |
403 |
int (messageHeader.GetMessageType ()) << |
418 |
int (messageHeader.GetMessageType ()) << |
Lines 1038-1043
RoutingProtocol::RoutingTableComputation
|
Link Here
|
---|
|
1038 |
entry1.distance); |
1053 |
entry1.distance); |
1039 |
} |
1054 |
} |
1040 |
} |
1055 |
} |
|
|
1056 |
|
1057 |
// 5. For each tuple in the association set, |
1058 |
// If there is no entry in the routing table with: |
1059 |
// R_dest_addr == A_network_addr/A_netmask |
1060 |
// then a new routing entry is created. |
1061 |
const AssociationSet &associationSet = m_state.GetAssociationSet (); |
1062 |
for (AssociationSet::const_iterator it = associationSet.begin (); |
1063 |
it != associationSet.end (); it++) |
1064 |
{ |
1065 |
AssociationTuple const &tuple = *it; |
1066 |
RoutingTableEntry entry1, entry2; |
1067 |
|
1068 |
bool have_entry1 = Lookup (tuple.networkAddr.CombineMask (tuple.netmask), entry1); |
1069 |
bool have_entry2 = Lookup (tuple.gatewayAddr, entry2); |
1070 |
bool to_add = false; |
1071 |
|
1072 |
if (!have_entry1) |
1073 |
{ |
1074 |
to_add = true; |
1075 |
} |
1076 |
else if(have_entry2 && entry1.distance > entry2.distance) |
1077 |
{ |
1078 |
RemoveEntry(tuple.networkAddr.CombineMask (tuple.netmask)); |
1079 |
to_add = true; |
1080 |
} |
1081 |
|
1082 |
if(to_add == true) |
1083 |
{ |
1084 |
AddEntry (tuple.networkAddr.CombineMask (tuple.netmask), |
1085 |
entry2.nextAddr, |
1086 |
entry2.interface, |
1087 |
entry2.distance); |
1088 |
} |
1089 |
} |
1041 |
|
1090 |
|
1042 |
NS_LOG_DEBUG ("Node " << m_mainAddress << ": RoutingTableComputation end."); |
1091 |
NS_LOG_DEBUG ("Node " << m_mainAddress << ": RoutingTableComputation end."); |
1043 |
m_routingTableChanged (GetSize ()); |
1092 |
m_routingTableChanged (GetSize ()); |
Lines 1280-1285
RoutingProtocol::ProcessMid (const olsr:
|
Link Here
|
---|
|
1280 |
NS_LOG_DEBUG ("Node " << m_mainAddress << " ProcessMid from " << senderIface << " -> END."); |
1329 |
NS_LOG_DEBUG ("Node " << m_mainAddress << " ProcessMid from " << senderIface << " -> END."); |
1281 |
} |
1330 |
} |
1282 |
|
1331 |
|
|
|
1332 |
/// |
1333 |
/// \brief Processes a HNA message following RFC 3626 specification. |
1334 |
/// |
1335 |
/// The Host Network Association Set is updated (if needed) with the information |
1336 |
/// of the received HNA message. |
1337 |
/// |
1338 |
/// \param msg the %OLSR message which contains the HNA message. |
1339 |
/// \param sender_iface the address of the interface where the message was sent from. |
1340 |
/// |
1341 |
void |
1342 |
RoutingProtocol::ProcessHna (const olsr::MessageHeader &msg, |
1343 |
const Ipv4Address &senderIface) |
1344 |
{ |
1345 |
const olsr::MessageHeader::Hna &hna = msg.GetHna (); |
1346 |
Time now = Simulator::Now (); |
1347 |
|
1348 |
// 1. If the sender interface of this message is not in the symmetric |
1349 |
// 1-hop neighborhood of this node, the message MUST be discarded. |
1350 |
const LinkTuple *link_tuple = m_state.FindSymLinkTuple (senderIface, now); |
1351 |
if (link_tuple == NULL) |
1352 |
return; |
1353 |
|
1354 |
// 2. Otherwise, for each (network address, netmask) pair in the |
1355 |
// message: |
1356 |
|
1357 |
for (std::vector<olsr::MessageHeader::Hna::Association>::const_iterator it = hna.associations.begin(); |
1358 |
it != hna.associations.end() ; it++) |
1359 |
{ |
1360 |
AssociationTuple *tuple = m_state.FindAssociationTuple(msg.GetOriginatorAddress(),it->address,it->mask); |
1361 |
|
1362 |
// 2.1 if an entry in the association set already exists, where: |
1363 |
// A_gateway_addr == originator address |
1364 |
// A_network_addr == network address |
1365 |
// A_netmask == netmask |
1366 |
// then the holding time for that tuple MUST be set to: |
1367 |
// A_time = current time + validity time |
1368 |
|
1369 |
if(tuple != NULL) |
1370 |
{ |
1371 |
tuple->expirationTime = now + msg.GetVTime (); |
1372 |
} |
1373 |
|
1374 |
// 2.2 otherwise, a new tuple MUST be recorded with: |
1375 |
// A_gateway_addr = originator address |
1376 |
// A_network_addr = network address |
1377 |
// A_netmask = netmask |
1378 |
// A_time = current time + validity time |
1379 |
|
1380 |
else |
1381 |
{ |
1382 |
const AssociationTuple &assocTuple = (AssociationTuple){msg.GetOriginatorAddress(),it->address,it->mask,now + msg.GetVTime ()}; |
1383 |
|
1384 |
AddAssociationTuple (assocTuple); |
1385 |
|
1386 |
//Schedule Association Tuple deletion |
1387 |
Simulator::Schedule (DELAY (assocTuple.expirationTime), |
1388 |
&RoutingProtocol::AssociationTupleTimerExpire, this, |
1389 |
assocTuple.gatewayAddr,assocTuple.networkAddr,assocTuple.netmask); |
1390 |
} |
1391 |
|
1392 |
} |
1393 |
} |
1283 |
|
1394 |
|
1284 |
/// |
1395 |
/// |
1285 |
/// \brief OLSR's default forwarding algorithm. |
1396 |
/// \brief OLSR's default forwarding algorithm. |
Lines 1622-1627
RoutingProtocol::SendMid ()
|
Link Here
|
---|
|
1622 |
} |
1733 |
} |
1623 |
|
1734 |
|
1624 |
/// |
1735 |
/// |
|
|
1736 |
/// \brief Creates a new %OLSR HNA message which is buffered for being sent later on. |
1737 |
/// |
1738 |
void |
1739 |
RoutingProtocol::SendHna () |
1740 |
{ |
1741 |
olsr::MessageHeader msg; |
1742 |
|
1743 |
msg.SetVTime (OLSR_HNA_HOLD_TIME); |
1744 |
msg.SetOriginatorAddress (m_mainAddress); |
1745 |
msg.SetTimeToLive (255); |
1746 |
msg.SetHopCount (0); |
1747 |
msg.SetMessageSequenceNumber (GetMessageSequenceNumber ()); |
1748 |
olsr::MessageHeader::Hna &hna = msg.GetHna (); |
1749 |
|
1750 |
std::vector<olsr::MessageHeader::Hna::Association> |
1751 |
&associations = hna.associations; |
1752 |
|
1753 |
// Pack all host-network associations into the packet's associations vector |
1754 |
for (Associations::const_iterator it = m_state.GetHostNetAssocSet ().begin (); |
1755 |
it != m_state.GetHostNetAssocSet ().end (); it++) |
1756 |
{ |
1757 |
associations.push_back((olsr::MessageHeader::Hna::Association){it->networkAddr,it->netmask}); |
1758 |
} |
1759 |
|
1760 |
if(associations.size () == 0) |
1761 |
return; |
1762 |
|
1763 |
QueueMessage (msg, JITTER); |
1764 |
} |
1765 |
|
1766 |
/// |
1767 |
/// \brief Injects a (networkAddr, netmask) tuple for which the node |
1768 |
/// can generate an HNA message for |
1769 |
/// |
1770 |
void |
1771 |
RoutingProtocol::InjectRoute (Ipv4Address networkAddr, Ipv4Mask netmask) |
1772 |
{ |
1773 |
m_state.InsertHostNetAssociation ((Association) {networkAddr, netmask}); |
1774 |
} |
1775 |
|
1776 |
/// |
1625 |
/// \brief Updates Link Set according to a new received HELLO message (following RFC 3626 |
1777 |
/// \brief Updates Link Set according to a new received HELLO message (following RFC 3626 |
1626 |
/// specification). Neighbor Set is also updated if needed. |
1778 |
/// specification). Neighbor Set is also updated if needed. |
1627 |
void |
1779 |
void |
Lines 2301-2306
RoutingProtocol::RemoveIfaceAssocTuple (
|
Link Here
|
---|
|
2301 |
m_state.EraseIfaceAssocTuple (tuple); |
2453 |
m_state.EraseIfaceAssocTuple (tuple); |
2302 |
} |
2454 |
} |
2303 |
|
2455 |
|
|
|
2456 |
/// |
2457 |
/// \brief Adds a host network association tuple to the Association Set. |
2458 |
/// |
2459 |
/// \param tuple the host network association tuple to be added. |
2460 |
/// |
2461 |
void |
2462 |
RoutingProtocol::AddAssociationTuple (const AssociationTuple &tuple) |
2463 |
{ |
2464 |
m_state.InsertAssociationTuple (tuple); |
2465 |
} |
2466 |
|
2467 |
/// |
2468 |
/// \brief Removes a host network association tuple from the Association Set. |
2469 |
/// |
2470 |
/// \param tuple the host network association tuple to be removed. |
2471 |
/// |
2472 |
void |
2473 |
RoutingProtocol::RemoveAssociationTuple (const AssociationTuple &tuple) |
2474 |
{ |
2475 |
m_state.EraseAssociationTuple (tuple); |
2476 |
} |
2477 |
|
2304 |
|
2478 |
|
2305 |
uint16_t RoutingProtocol::GetPacketSequenceNumber () |
2479 |
uint16_t RoutingProtocol::GetPacketSequenceNumber () |
2306 |
{ |
2480 |
{ |
Lines 2347-2353
RoutingProtocol::TcTimerExpire ()
|
Link Here
|
---|
|
2347 |
|
2521 |
|
2348 |
/// |
2522 |
/// |
2349 |
/// \brief Sends a MID message (if the node has more than one interface) and resets the MID timer. |
2523 |
/// \brief Sends a MID message (if the node has more than one interface) and resets the MID timer. |
2350 |
/// \warning Currently it does nothing because there is no support for multiple interfaces. |
|
|
2351 |
/// \param e The event which has expired. |
2524 |
/// \param e The event which has expired. |
2352 |
/// |
2525 |
/// |
2353 |
void |
2526 |
void |
Lines 2358-2363
RoutingProtocol::MidTimerExpire ()
|
Link Here
|
---|
|
2358 |
} |
2531 |
} |
2359 |
|
2532 |
|
2360 |
/// |
2533 |
/// |
|
|
2534 |
/// \brief Sends an HNA message (if the node implements support for non-OLSR interfaces). |
2535 |
/// \warning Currently it does nothing because there is no support for mixed interfaces. |
2536 |
/// \param e The event which has expired. |
2537 |
/// |
2538 |
void |
2539 |
RoutingProtocol::HnaTimerExpire () |
2540 |
{ |
2541 |
SendHna (); |
2542 |
m_hnaTimer.Schedule (m_hnaInterval); |
2543 |
} |
2544 |
|
2545 |
/// |
2361 |
/// \brief Removes tuple if expired. Else timer is rescheduled to expire at tuple.expirationTime. |
2546 |
/// \brief Removes tuple if expired. Else timer is rescheduled to expire at tuple.expirationTime. |
2362 |
/// |
2547 |
/// |
2363 |
/// The task of actually removing the tuple is left to the OLSR agent. |
2548 |
/// The task of actually removing the tuple is left to the OLSR agent. |
Lines 2538-2543
RoutingProtocol::IfaceAssocTupleTimerExp
|
Link Here
|
---|
|
2538 |
} |
2723 |
} |
2539 |
|
2724 |
|
2540 |
/// |
2725 |
/// |
|
|
2726 |
/// \brief Removes tuple_ if expired. Else timer is rescheduled to expire at tuple_->time(). |
2727 |
/// \warning Actually this is never invoked because there is no support for mixed interfaces. |
2728 |
/// \param e The event which has expired. |
2729 |
/// |
2730 |
void |
2731 |
RoutingProtocol::AssociationTupleTimerExpire (Ipv4Address gatewayAddr, Ipv4Address networkAddr, Ipv4Mask netmask) |
2732 |
{ |
2733 |
AssociationTuple *tuple = m_state.FindAssociationTuple (gatewayAddr, networkAddr, netmask); |
2734 |
if (tuple == NULL) |
2735 |
{ |
2736 |
return; |
2737 |
} |
2738 |
if (tuple->expirationTime < Simulator::Now ()) |
2739 |
{ |
2740 |
RemoveAssociationTuple (*tuple); |
2741 |
} |
2742 |
else |
2743 |
{ |
2744 |
m_events.Track (Simulator::Schedule (DELAY (tuple->expirationTime), |
2745 |
&RoutingProtocol::AssociationTupleTimerExpire, |
2746 |
this, gatewayAddr, networkAddr, netmask)); |
2747 |
} |
2748 |
} |
2749 |
|
2750 |
/// |
2541 |
/// \brief Clears the routing table and frees the memory assigned to each one of its entries. |
2751 |
/// \brief Clears the routing table and frees the memory assigned to each one of its entries. |
2542 |
/// |
2752 |
/// |
2543 |
void |
2753 |
void |