|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
2 |
/* |
3 |
* Copyright (c) 2004 Francisco J. Ros |
3 |
* Copyright (c) 2004 Francisco J. Ros |
4 |
* Copyright (c) 2007 INESC Porto |
4 |
* Copyright (c) 2007 INESC Porto |
5 |
* |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
6 |
* This program is free software; you can redistribute it and/or modify |
|
141 |
namespace ns3 { |
141 |
namespace ns3 { |
142 |
|
142 |
|
143 |
NS_LOG_COMPONENT_DEFINE ("OlsrRoutingProtocol"); |
143 |
NS_LOG_COMPONENT_DEFINE ("OlsrRoutingProtocol"); |
144 |
|
144 |
|
145 |
namespace olsr { |
145 |
namespace olsr { |
146 |
|
146 |
|
147 |
/********** OLSR class **********/ |
147 |
/********** OLSR class **********/ |
148 |
|
148 |
|
149 |
NS_OBJECT_ENSURE_REGISTERED (RoutingProtocol); |
149 |
NS_OBJECT_ENSURE_REGISTERED (RoutingProtocol); |
150 |
|
150 |
|
151 |
TypeId |
151 |
TypeId |
152 |
RoutingProtocol::GetTypeId (void) |
152 |
RoutingProtocol::GetTypeId (void) |
153 |
{ |
153 |
{ |
154 |
static TypeId tid = TypeId ("ns3::olsr::RoutingProtocol") |
154 |
static TypeId tid = TypeId ("ns3::olsr::RoutingProtocol") |
|
195 |
|
195 |
|
196 |
RoutingProtocol::RoutingProtocol () |
196 |
RoutingProtocol::RoutingProtocol () |
197 |
: m_routingTableAssociation (0), |
197 |
: m_routingTableAssociation (0), |
198 |
m_ipv4 (0), |
198 |
m_ipv4 (0), |
199 |
m_helloTimer (Timer::CANCEL_ON_DESTROY), |
199 |
m_helloTimer (Timer::CANCEL_ON_DESTROY), |
200 |
m_tcTimer (Timer::CANCEL_ON_DESTROY), |
200 |
m_tcTimer (Timer::CANCEL_ON_DESTROY), |
201 |
m_midTimer (Timer::CANCEL_ON_DESTROY), |
201 |
m_midTimer (Timer::CANCEL_ON_DESTROY), |
202 |
m_hnaTimer (Timer::CANCEL_ON_DESTROY), |
202 |
m_hnaTimer (Timer::CANCEL_ON_DESTROY), |
203 |
m_queuedMessagesTimer (Timer::CANCEL_ON_DESTROY) |
203 |
m_queuedMessagesTimer (Timer::CANCEL_ON_DESTROY) |
204 |
{ |
204 |
{ |
205 |
m_uniformRandomVariable = CreateObject<UniformRandomVariable> (); |
205 |
m_uniformRandomVariable = CreateObject<UniformRandomVariable> (); |
206 |
|
206 |
|
|
256 |
std::ostream* os = stream->GetStream (); |
256 |
std::ostream* os = stream->GetStream (); |
257 |
|
257 |
|
258 |
*os << "Node: " << m_ipv4->GetObject<Node> ()->GetId () |
258 |
*os << "Node: " << m_ipv4->GetObject<Node> ()->GetId () |
259 |
<< ", Time: " << Now().As (Time::S) |
259 |
<< ", Time: " << Now ().As (Time::S) |
260 |
<< ", Local time: " << GetObject<Node> ()->GetLocalTime ().As (Time::S) |
260 |
<< ", Local time: " << GetObject<Node> ()->GetLocalTime ().As (Time::S) |
261 |
<< ", OLSR Routing table" << std::endl; |
261 |
<< ", OLSR Routing table" << std::endl; |
262 |
|
262 |
|
|
319 |
{ |
319 |
{ |
320 |
Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal (); |
320 |
Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal (); |
321 |
if (addr == loopback) |
321 |
if (addr == loopback) |
322 |
continue; |
322 |
{ |
|
|
323 |
continue; |
324 |
} |
323 |
|
325 |
|
324 |
if (addr != m_mainAddress) |
326 |
if (addr != m_mainAddress) |
325 |
{ |
327 |
{ |
|
333 |
NS_ASSERT (GetMainAddress (addr) == m_mainAddress); |
335 |
NS_ASSERT (GetMainAddress (addr) == m_mainAddress); |
334 |
} |
336 |
} |
335 |
|
337 |
|
336 |
if(m_interfaceExclusions.find (i) != m_interfaceExclusions.end ()) |
338 |
if (m_interfaceExclusions.find (i) != m_interfaceExclusions.end ()) |
337 |
continue; |
339 |
{ |
|
|
340 |
continue; |
341 |
} |
338 |
|
342 |
|
339 |
// Create a socket to listen only on this interface |
343 |
// Create a socket to listen only on this interface |
340 |
Ptr<Socket> socket = Socket::CreateSocket (GetObject<Node> (), |
344 |
Ptr<Socket> socket = Socket::CreateSocket (GetObject<Node> (), |
341 |
UdpSocketFactory::GetTypeId ()); |
345 |
UdpSocketFactory::GetTypeId ()); |
342 |
socket->SetAllowBroadcast (true); |
346 |
socket->SetAllowBroadcast (true); |
343 |
InetSocketAddress inetAddr (m_ipv4->GetAddress (i, 0).GetLocal (), OLSR_PORT_NUMBER); |
347 |
InetSocketAddress inetAddr (m_ipv4->GetAddress (i, 0).GetLocal (), OLSR_PORT_NUMBER); |
|
352 |
canRunOlsr = true; |
356 |
canRunOlsr = true; |
353 |
} |
357 |
} |
354 |
|
358 |
|
355 |
if(canRunOlsr) |
359 |
if (canRunOlsr) |
356 |
{ |
360 |
{ |
357 |
HelloTimerExpire (); |
361 |
HelloTimerExpire (); |
358 |
TcTimerExpire (); |
362 |
TcTimerExpire (); |
|
406 |
{ |
410 |
{ |
407 |
MessageHeader messageHeader; |
411 |
MessageHeader messageHeader; |
408 |
if (packet->RemoveHeader (messageHeader) == 0) |
412 |
if (packet->RemoveHeader (messageHeader) == 0) |
409 |
NS_ASSERT (false); |
413 |
{ |
|
|
414 |
NS_ASSERT (false); |
415 |
} |
410 |
|
416 |
|
411 |
sizeLeft -= messageHeader.GetSerializedSize (); |
417 |
sizeLeft -= messageHeader.GetSerializedSize (); |
412 |
|
418 |
|
|
481 |
<< "s OLSR node " << m_mainAddress |
487 |
<< "s OLSR node " << m_mainAddress |
482 |
<< " received HNA message of size " << messageHeader.GetSerializedSize ()); |
488 |
<< " received HNA message of size " << messageHeader.GetSerializedSize ()); |
483 |
ProcessHna (messageHeader, senderIfaceAddr); |
489 |
ProcessHna (messageHeader, senderIfaceAddr); |
484 |
break; |
490 |
break; |
485 |
|
491 |
|
486 |
default: |
492 |
default: |
487 |
NS_LOG_DEBUG ("OLSR message type " << |
493 |
NS_LOG_DEBUG ("OLSR message type " << |
|
542 |
const NeighborTuple *nb_tuple = |
548 |
const NeighborTuple *nb_tuple = |
543 |
m_state.FindNeighborTuple (nb2hop_tuple.neighborMainAddr); |
549 |
m_state.FindNeighborTuple (nb2hop_tuple.neighborMainAddr); |
544 |
if (nb_tuple == NULL) |
550 |
if (nb_tuple == NULL) |
545 |
degree++; |
551 |
{ |
|
|
552 |
degree++; |
553 |
} |
546 |
} |
554 |
} |
547 |
} |
555 |
} |
548 |
return degree; |
556 |
return degree; |
|
556 |
/// \param neighborMainAddr Neighbor main address. |
564 |
/// \param neighborMainAddr Neighbor main address. |
557 |
/// \param N2 Reference to the 2-hop neighbor set. |
565 |
/// \param N2 Reference to the 2-hop neighbor set. |
558 |
/// |
566 |
/// |
559 |
void |
567 |
void |
560 |
CoverTwoHopNeighbors (Ipv4Address neighborMainAddr, TwoHopNeighborSet & N2) |
568 |
CoverTwoHopNeighbors (Ipv4Address neighborMainAddr, TwoHopNeighborSet & N2) |
561 |
{ |
569 |
{ |
562 |
// first gather all 2-hop neighbors to be removed |
570 |
// first gather all 2-hop neighbors to be removed |
|
676 |
next++; |
684 |
next++; |
677 |
os << iter->neighborMainAddr << "->" << iter->twoHopNeighborAddr; |
685 |
os << iter->neighborMainAddr << "->" << iter->twoHopNeighborAddr; |
678 |
if (next != N2.end ()) |
686 |
if (next != N2.end ()) |
679 |
os << ", "; |
687 |
{ |
|
|
688 |
os << ", "; |
689 |
} |
680 |
} |
690 |
} |
681 |
os << "]"; |
691 |
os << "]"; |
682 |
NS_LOG_DEBUG ("N2: " << os.str ()); |
692 |
NS_LOG_DEBUG ("N2: " << os.str ()); |
|
741 |
{ |
751 |
{ |
742 |
if (coveredTwoHopNeighbors.find (twoHopNeigh->twoHopNeighborAddr) != coveredTwoHopNeighbors.end ()) |
752 |
if (coveredTwoHopNeighbors.find (twoHopNeigh->twoHopNeighborAddr) != coveredTwoHopNeighbors.end ()) |
743 |
{ |
753 |
{ |
744 |
// This works correctly only because it is known that twoHopNeigh is reachable by exactly one neighbor, |
754 |
// This works correctly only because it is known that twoHopNeigh is reachable by exactly one neighbor, |
745 |
// so only one record in N2 exists for each of them. This record is erased here. |
755 |
// so only one record in N2 exists for each of them. This record is erased here. |
746 |
NS_LOG_LOGIC ("2-hop neigh. " << twoHopNeigh->twoHopNeighborAddr << " is already covered by an MPR."); |
756 |
NS_LOG_LOGIC ("2-hop neigh. " << twoHopNeigh->twoHopNeighborAddr << " is already covered by an MPR."); |
747 |
twoHopNeigh = N2.erase (twoHopNeigh); |
757 |
twoHopNeigh = N2.erase (twoHopNeigh); |
|
768 |
next++; |
778 |
next++; |
769 |
os << iter->neighborMainAddr << "->" << iter->twoHopNeighborAddr; |
779 |
os << iter->neighborMainAddr << "->" << iter->twoHopNeighborAddr; |
770 |
if (next != N2.end ()) |
780 |
if (next != N2.end ()) |
771 |
os << ", "; |
781 |
{ |
|
|
782 |
os << ", "; |
783 |
} |
772 |
} |
784 |
} |
773 |
os << "]"; |
785 |
os << "]"; |
774 |
NS_LOG_DEBUG ("Step 4 iteration: N2=" << os.str ()); |
786 |
NS_LOG_DEBUG ("Step 4 iteration: N2=" << os.str ()); |
|
790 |
{ |
802 |
{ |
791 |
TwoHopNeighborTuple const &nb2hop_tuple = *it2; |
803 |
TwoHopNeighborTuple const &nb2hop_tuple = *it2; |
792 |
if (nb_tuple.neighborMainAddr == nb2hop_tuple.neighborMainAddr) |
804 |
if (nb_tuple.neighborMainAddr == nb2hop_tuple.neighborMainAddr) |
793 |
r++; |
805 |
{ |
|
|
806 |
r++; |
807 |
} |
794 |
} |
808 |
} |
795 |
rs.insert (r); |
809 |
rs.insert (r); |
796 |
reachability[r].push_back (&nb_tuple); |
810 |
reachability[r].push_back (&nb_tuple); |
|
860 |
next++; |
874 |
next++; |
861 |
os << *iter; |
875 |
os << *iter; |
862 |
if (next != mprSet.end ()) |
876 |
if (next != mprSet.end ()) |
863 |
os << ", "; |
877 |
{ |
|
|
878 |
os << ", "; |
879 |
} |
864 |
} |
880 |
} |
865 |
os << "]"; |
881 |
os << "]"; |
866 |
NS_LOG_DEBUG ("Computed MPR set for node " << m_mainAddress << ": " << os.str ()); |
882 |
NS_LOG_DEBUG ("Computed MPR set for node " << m_mainAddress << ": " << os.str ()); |
|
877 |
m_state.FindIfaceAssocTuple (iface_addr); |
893 |
m_state.FindIfaceAssocTuple (iface_addr); |
878 |
|
894 |
|
879 |
if (tuple != NULL) |
895 |
if (tuple != NULL) |
880 |
return tuple->mainAddr; |
896 |
{ |
|
|
897 |
return tuple->mainAddr; |
898 |
} |
881 |
else |
899 |
else |
882 |
return iface_addr; |
900 |
{ |
|
|
901 |
return iface_addr; |
902 |
} |
883 |
} |
903 |
} |
884 |
|
904 |
|
885 |
void |
905 |
void |
|
1083 |
} |
1103 |
} |
1084 |
|
1104 |
|
1085 |
if (!added) |
1105 |
if (!added) |
1086 |
break; |
1106 |
{ |
|
|
1107 |
break; |
1108 |
} |
1087 |
} |
1109 |
} |
1088 |
|
1110 |
|
1089 |
// 4. For each entry in the multiple interface association base |
1111 |
// 4. For each entry in the multiple interface association base |
|
1164 |
for (routeIndex = 0; routeIndex < m_hnaRoutingTable->GetNRoutes (); routeIndex++) |
1186 |
for (routeIndex = 0; routeIndex < m_hnaRoutingTable->GetNRoutes (); routeIndex++) |
1165 |
{ |
1187 |
{ |
1166 |
Ipv4RoutingTableEntry route = m_hnaRoutingTable->GetRoute (routeIndex); |
1188 |
Ipv4RoutingTableEntry route = m_hnaRoutingTable->GetRoute (routeIndex); |
1167 |
if (route.GetDestNetwork () == tuple.networkAddr && |
1189 |
if (route.GetDestNetwork () == tuple.networkAddr |
1168 |
route.GetDestNetworkMask () == tuple.netmask) |
1190 |
&& route.GetDestNetworkMask () == tuple.netmask) |
1169 |
{ |
1191 |
{ |
1170 |
break; |
1192 |
break; |
1171 |
} |
1193 |
} |
|
1175 |
{ |
1197 |
{ |
1176 |
addRoute = true; |
1198 |
addRoute = true; |
1177 |
} |
1199 |
} |
1178 |
else if(gatewayEntryExists && m_hnaRoutingTable->GetMetric (routeIndex) > gatewayEntry.distance) |
1200 |
else if (gatewayEntryExists && m_hnaRoutingTable->GetMetric (routeIndex) > gatewayEntry.distance) |
1179 |
{ |
1201 |
{ |
1180 |
m_hnaRoutingTable->RemoveRoute (routeIndex); |
1202 |
m_hnaRoutingTable->RemoveRoute (routeIndex); |
1181 |
addRoute = true; |
1203 |
addRoute = true; |
1182 |
} |
1204 |
} |
1183 |
|
1205 |
|
1184 |
if(addRoute && gatewayEntryExists) |
1206 |
if (addRoute && gatewayEntryExists) |
1185 |
{ |
1207 |
{ |
1186 |
m_hnaRoutingTable->AddNetworkRouteTo (tuple.networkAddr, |
1208 |
m_hnaRoutingTable->AddNetworkRouteTo (tuple.networkAddr, |
1187 |
tuple.netmask, |
1209 |
tuple.netmask, |
|
1262 |
// 1-hop neighborhood of this node, the message MUST be discarded. |
1284 |
// 1-hop neighborhood of this node, the message MUST be discarded. |
1263 |
const LinkTuple *link_tuple = m_state.FindSymLinkTuple (senderIface, now); |
1285 |
const LinkTuple *link_tuple = m_state.FindSymLinkTuple (senderIface, now); |
1264 |
if (link_tuple == NULL) |
1286 |
if (link_tuple == NULL) |
1265 |
return; |
1287 |
{ |
|
|
1288 |
return; |
1289 |
} |
1266 |
|
1290 |
|
1267 |
// 2. If there exist some tuple in the topology set where: |
1291 |
// 2. If there exist some tuple in the topology set where: |
1268 |
// T_last_addr == originator address AND |
1292 |
// T_last_addr == originator address AND |
|
1272 |
const TopologyTuple *topologyTuple = |
1296 |
const TopologyTuple *topologyTuple = |
1273 |
m_state.FindNewerTopologyTuple (msg.GetOriginatorAddress (), tc.ansn); |
1297 |
m_state.FindNewerTopologyTuple (msg.GetOriginatorAddress (), tc.ansn); |
1274 |
if (topologyTuple != NULL) |
1298 |
if (topologyTuple != NULL) |
1275 |
return; |
1299 |
{ |
|
|
1300 |
return; |
1301 |
} |
1276 |
|
1302 |
|
1277 |
// 3. All tuples in the topology set where: |
1303 |
// 3. All tuples in the topology set where: |
1278 |
// T_last_addr == originator address AND |
1304 |
// T_last_addr == originator address AND |
|
1306 |
// T_last_addr = originator address, |
1332 |
// T_last_addr = originator address, |
1307 |
// T_seq = ANSN, |
1333 |
// T_seq = ANSN, |
1308 |
// T_time = current time + validity time. |
1334 |
// T_time = current time + validity time. |
1309 |
TopologyTuple topologyTuple;; |
1335 |
TopologyTuple topologyTuple; |
1310 |
topologyTuple.destAddr = addr; |
1336 |
topologyTuple.destAddr = addr; |
1311 |
topologyTuple.lastAddr = msg.GetOriginatorAddress (); |
1337 |
topologyTuple.lastAddr = msg.GetOriginatorAddress (); |
1312 |
topologyTuple.sequenceNumber = tc.ansn; |
1338 |
topologyTuple.sequenceNumber = tc.ansn; |
|
1419 |
// 1-hop neighborhood of this node, the message MUST be discarded. |
1445 |
// 1-hop neighborhood of this node, the message MUST be discarded. |
1420 |
const LinkTuple *link_tuple = m_state.FindSymLinkTuple (senderIface, now); |
1446 |
const LinkTuple *link_tuple = m_state.FindSymLinkTuple (senderIface, now); |
1421 |
if (link_tuple == NULL) |
1447 |
if (link_tuple == NULL) |
1422 |
return; |
1448 |
{ |
|
|
1449 |
return; |
1450 |
} |
1423 |
|
1451 |
|
1424 |
// 2. Otherwise, for each (network address, netmask) pair in the |
1452 |
// 2. Otherwise, for each (network address, netmask) pair in the |
1425 |
// message: |
1453 |
// message: |
|
1435 |
// A_netmask == netmask |
1463 |
// A_netmask == netmask |
1436 |
// then the holding time for that tuple MUST be set to: |
1464 |
// then the holding time for that tuple MUST be set to: |
1437 |
// A_time = current time + validity time |
1465 |
// A_time = current time + validity time |
1438 |
if(tuple != NULL) |
1466 |
if (tuple != NULL) |
1439 |
{ |
1467 |
{ |
1440 |
tuple->expirationTime = now + msg.GetVTime (); |
1468 |
tuple->expirationTime = now + msg.GetVTime (); |
1441 |
} |
1469 |
} |
|
1476 |
// 1-hop neighborhood the message must not be forwarded |
1504 |
// 1-hop neighborhood the message must not be forwarded |
1477 |
const LinkTuple *linkTuple = m_state.FindSymLinkTuple (senderAddress, now); |
1505 |
const LinkTuple *linkTuple = m_state.FindSymLinkTuple (senderAddress, now); |
1478 |
if (linkTuple == NULL) |
1506 |
if (linkTuple == NULL) |
1479 |
return; |
1507 |
{ |
|
|
1508 |
return; |
1509 |
} |
1480 |
|
1510 |
|
1481 |
// If the message has already been considered for forwarding, |
1511 |
// If the message has already been considered for forwarding, |
1482 |
// it must not be retransmitted again |
1512 |
// it must not be retransmitted again |
|
1542 |
} |
1572 |
} |
1543 |
|
1573 |
|
1544 |
void |
1574 |
void |
1545 |
RoutingProtocol::SendPacket (Ptr<Packet> packet, |
1575 |
RoutingProtocol::SendPacket (Ptr<Packet> packet, |
1546 |
const MessageList &containedMessages) |
1576 |
const MessageList &containedMessages) |
1547 |
{ |
1577 |
{ |
1548 |
NS_LOG_DEBUG ("OLSR node " << m_mainAddress << " sending a OLSR packet"); |
1578 |
NS_LOG_DEBUG ("OLSR node " << m_mainAddress << " sending a OLSR packet"); |
|
1760 |
{ |
1790 |
{ |
1761 |
Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal (); |
1791 |
Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal (); |
1762 |
if (addr != m_mainAddress && addr != loopback && m_interfaceExclusions.find (i) == m_interfaceExclusions.end ()) |
1792 |
if (addr != m_mainAddress && addr != loopback && m_interfaceExclusions.find (i) == m_interfaceExclusions.end ()) |
1763 |
mid.interfaceAddresses.push_back (addr); |
1793 |
{ |
|
|
1794 |
mid.interfaceAddresses.push_back (addr); |
1795 |
} |
1764 |
} |
1796 |
} |
1765 |
if (mid.interfaceAddresses.size () == 0) |
1797 |
if (mid.interfaceAddresses.size () == 0) |
1766 |
return; |
1798 |
{ |
|
|
1799 |
return; |
1800 |
} |
1767 |
|
1801 |
|
1768 |
msg.SetVTime (OLSR_MID_HOLD_TIME); |
1802 |
msg.SetVTime (OLSR_MID_HOLD_TIME); |
1769 |
msg.SetOriginatorAddress (m_mainAddress); |
1803 |
msg.SetOriginatorAddress (m_mainAddress); |
|
1935 |
const char *linkTypeName; |
1969 |
const char *linkTypeName; |
1936 |
switch (lt) |
1970 |
switch (lt) |
1937 |
{ |
1971 |
{ |
1938 |
case OLSR_UNSPEC_LINK: linkTypeName = "UNSPEC_LINK"; break; |
1972 |
case OLSR_UNSPEC_LINK: |
1939 |
case OLSR_ASYM_LINK: linkTypeName = "ASYM_LINK"; break; |
1973 |
linkTypeName = "UNSPEC_LINK"; |
1940 |
case OLSR_SYM_LINK: linkTypeName = "SYM_LINK"; break; |
1974 |
break; |
1941 |
case OLSR_LOST_LINK: linkTypeName = "LOST_LINK"; break; |
1975 |
case OLSR_ASYM_LINK: |
|
|
1976 |
linkTypeName = "ASYM_LINK"; |
1977 |
break; |
1978 |
case OLSR_SYM_LINK: |
1979 |
linkTypeName = "SYM_LINK"; |
1980 |
break; |
1981 |
case OLSR_LOST_LINK: |
1982 |
linkTypeName = "LOST_LINK"; |
1983 |
break; |
1942 |
/* no default, since lt must be in 0..3, covered above |
1984 |
/* no default, since lt must be in 0..3, covered above |
1943 |
default: linkTypeName = "(invalid value!)"; |
1985 |
default: linkTypeName = "(invalid value!)"; |
1944 |
*/ |
1986 |
*/ |
|
1947 |
const char *neighborTypeName; |
1989 |
const char *neighborTypeName; |
1948 |
switch (nt) |
1990 |
switch (nt) |
1949 |
{ |
1991 |
{ |
1950 |
case OLSR_NOT_NEIGH: neighborTypeName = "NOT_NEIGH"; break; |
1992 |
case OLSR_NOT_NEIGH: |
1951 |
case OLSR_SYM_NEIGH: neighborTypeName = "SYM_NEIGH"; break; |
1993 |
neighborTypeName = "NOT_NEIGH"; |
1952 |
case OLSR_MPR_NEIGH: neighborTypeName = "MPR_NEIGH"; break; |
1994 |
break; |
1953 |
default: neighborTypeName = "(invalid value!)"; |
1995 |
case OLSR_SYM_NEIGH: |
|
|
1996 |
neighborTypeName = "SYM_NEIGH"; |
1997 |
break; |
1998 |
case OLSR_MPR_NEIGH: |
1999 |
neighborTypeName = "MPR_NEIGH"; |
2000 |
break; |
2001 |
default: |
2002 |
neighborTypeName = "(invalid value!)"; |
1954 |
} |
2003 |
} |
1955 |
|
2004 |
|
1956 |
NS_LOG_DEBUG ("Looking at HELLO link messages with Link Type " |
2005 |
NS_LOG_DEBUG ("Looking at HELLO link messages with Link Type " |
|
1960 |
#endif // NS3_LOG_ENABLE |
2009 |
#endif // NS3_LOG_ENABLE |
1961 |
|
2010 |
|
1962 |
// We must not process invalid advertised links |
2011 |
// We must not process invalid advertised links |
1963 |
if ((lt == OLSR_SYM_LINK && nt == OLSR_NOT_NEIGH) || |
2012 |
if ((lt == OLSR_SYM_LINK && nt == OLSR_NOT_NEIGH) |
1964 |
(nt != OLSR_SYM_NEIGH && nt != OLSR_MPR_NEIGH |
2013 |
|| (nt != OLSR_SYM_NEIGH && nt != OLSR_MPR_NEIGH |
1965 |
&& nt != OLSR_NOT_NEIGH)) |
2014 |
&& nt != OLSR_NOT_NEIGH)) |
1966 |
{ |
2015 |
{ |
1967 |
NS_LOG_LOGIC ("HELLO link code is invalid => IGNORING"); |
2016 |
NS_LOG_LOGIC ("HELLO link code is invalid => IGNORING"); |
1968 |
continue; |
2017 |
continue; |
|
2206 |
/// \param p the packet which couldn't be delivered by the MAC layer. |
2255 |
/// \param p the packet which couldn't be delivered by the MAC layer. |
2207 |
/// |
2256 |
/// |
2208 |
void |
2257 |
void |
2209 |
OLSR::mac_failed (Ptr<Packet> p) { |
2258 |
OLSR::mac_failed (Ptr<Packet> p) |
|
|
2259 |
{ |
2210 |
double now = Simulator::Now (); |
2260 |
double now = Simulator::Now (); |
2211 |
struct hdr_ip* ih = HDR_IP (p); |
2261 |
struct hdr_ip* ih = HDR_IP (p); |
2212 |
struct hdr_cmn* ch = HDR_CMN (p); |
2262 |
struct hdr_cmn* ch = HDR_CMN (p); |
|
2216 |
OLSR::node_id (ra_addr ()), |
2266 |
OLSR::node_id (ra_addr ()), |
2217 |
OLSR::node_id (ch->next_hop ())); |
2267 |
OLSR::node_id (ch->next_hop ())); |
2218 |
|
2268 |
|
2219 |
if ((u_int32_t)ih->daddr () == IP_BROADCAST) { |
2269 |
if ((u_int32_t)ih->daddr () == IP_BROADCAST) |
|
|
2270 |
{ |
2220 |
drop (p, DROP_RTR_MAC_CALLBACK); |
2271 |
drop (p, DROP_RTR_MAC_CALLBACK); |
2221 |
return; |
2272 |
return; |
2222 |
} |
2273 |
} |
2223 |
|
2274 |
|
2224 |
OLSR_link_tuple* link_tuple = state_.find_link_tuple (ch->next_hop ()); |
2275 |
OLSR_link_tuple* link_tuple = state_.find_link_tuple (ch->next_hop ()); |
2225 |
if (link_tuple != NULL) { |
2276 |
if (link_tuple != NULL) |
|
|
2277 |
{ |
2226 |
link_tuple->lost_time () = now + OLSR_NEIGHB_HOLD_TIME; |
2278 |
link_tuple->lost_time () = now + OLSR_NEIGHB_HOLD_TIME; |
2227 |
link_tuple->time () = now + OLSR_NEIGHB_HOLD_TIME; |
2279 |
link_tuple->time () = now + OLSR_NEIGHB_HOLD_TIME; |
2228 |
nb_loss (link_tuple); |
2280 |
nb_loss (link_tuple); |
|
2592 |
else if (tuple->symTime < now) |
2644 |
else if (tuple->symTime < now) |
2593 |
{ |
2645 |
{ |
2594 |
if (m_linkTupleTimerFirstTime) |
2646 |
if (m_linkTupleTimerFirstTime) |
2595 |
m_linkTupleTimerFirstTime = false; |
2647 |
{ |
|
|
2648 |
m_linkTupleTimerFirstTime = false; |
2649 |
} |
2596 |
else |
2650 |
else |
2597 |
NeighborLoss (*tuple); |
2651 |
{ |
|
|
2652 |
NeighborLoss (*tuple); |
2653 |
} |
2598 |
|
2654 |
|
2599 |
m_events.Track (Simulator::Schedule (DELAY (tuple->time), |
2655 |
m_events.Track (Simulator::Schedule (DELAY (tuple->time), |
2600 |
&RoutingProtocol::LinkTupleTimerExpire, this, |
2656 |
&RoutingProtocol::LinkTupleTimerExpire, this, |
|
2731 |
m_table.find (dest); |
2787 |
m_table.find (dest); |
2732 |
// If there is no route to "dest", return NULL |
2788 |
// If there is no route to "dest", return NULL |
2733 |
if (it == m_table.end ()) |
2789 |
if (it == m_table.end ()) |
2734 |
return false; |
2790 |
{ |
|
|
2791 |
return false; |
2792 |
} |
2735 |
outEntry = it->second; |
2793 |
outEntry = it->second; |
2736 |
return true; |
2794 |
return true; |
2737 |
} |
2795 |
} |
|
2744 |
while (outEntry.destAddr != outEntry.nextAddr) |
2802 |
while (outEntry.destAddr != outEntry.nextAddr) |
2745 |
{ |
2803 |
{ |
2746 |
if (not Lookup (outEntry.nextAddr, outEntry)) |
2804 |
if (not Lookup (outEntry.nextAddr, outEntry)) |
2747 |
return false; |
2805 |
{ |
|
|
2806 |
return false; |
2807 |
} |
2748 |
} |
2808 |
} |
2749 |
return true; |
2809 |
return true; |
2750 |
} |
2810 |
} |
|
2768 |
if (oif && m_ipv4->GetInterfaceForDevice (oif) != static_cast<int> (interfaceIdx)) |
2828 |
if (oif && m_ipv4->GetInterfaceForDevice (oif) != static_cast<int> (interfaceIdx)) |
2769 |
{ |
2829 |
{ |
2770 |
// We do not attempt to perform a constrained routing search |
2830 |
// We do not attempt to perform a constrained routing search |
2771 |
// if the caller specifies the oif; we just enforce that |
2831 |
// if the caller specifies the oif; we just enforce that |
2772 |
// that the found route matches the requested outbound interface |
2832 |
// that the found route matches the requested outbound interface |
2773 |
NS_LOG_DEBUG ("Olsr node " << m_mainAddress |
2833 |
NS_LOG_DEBUG ("Olsr node " << m_mainAddress |
2774 |
<< ": RouteOutput for dest=" << header.GetDestination () |
2834 |
<< ": RouteOutput for dest=" << header.GetDestination () |
2775 |
<< " Route interface " << interfaceIdx |
2835 |
<< " Route interface " << interfaceIdx |
2776 |
<< " does not match requested output interface " |
2836 |
<< " does not match requested output interface " |
|
2781 |
rtentry = Create<Ipv4Route> (); |
2841 |
rtentry = Create<Ipv4Route> (); |
2782 |
rtentry->SetDestination (header.GetDestination ()); |
2842 |
rtentry->SetDestination (header.GetDestination ()); |
2783 |
// the source address is the interface address that matches |
2843 |
// the source address is the interface address that matches |
2784 |
// the destination address (when multiple are present on the |
2844 |
// the destination address (when multiple are present on the |
2785 |
// outgoing interface, one is selected via scoping rules) |
2845 |
// outgoing interface, one is selected via scoping rules) |
2786 |
NS_ASSERT (m_ipv4); |
2846 |
NS_ASSERT (m_ipv4); |
2787 |
uint32_t numOifAddresses = m_ipv4->GetNAddresses (interfaceIdx); |
2847 |
uint32_t numOifAddresses = m_ipv4->GetNAddresses (interfaceIdx); |
2788 |
NS_ASSERT (numOifAddresses > 0); |
2848 |
NS_ASSERT (numOifAddresses > 0); |
2789 |
Ipv4InterfaceAddress ifAddr; |
2849 |
Ipv4InterfaceAddress ifAddr; |
2790 |
if (numOifAddresses == 1) { |
2850 |
if (numOifAddresses == 1) |
|
|
2851 |
{ |
2791 |
ifAddr = m_ipv4->GetAddress (interfaceIdx, 0); |
2852 |
ifAddr = m_ipv4->GetAddress (interfaceIdx, 0); |
2792 |
} else { |
2853 |
} |
|
|
2854 |
else |
2855 |
{ |
2793 |
/// \todo Implment IP aliasing and OLSR |
2856 |
/// \todo Implment IP aliasing and OLSR |
2794 |
NS_FATAL_ERROR ("XXX Not implemented yet: IP aliasing and OLSR"); |
2857 |
NS_FATAL_ERROR ("XXX Not implemented yet: IP aliasing and OLSR"); |
2795 |
} |
2858 |
} |
|
2797 |
rtentry->SetGateway (entry2.nextAddr); |
2860 |
rtentry->SetGateway (entry2.nextAddr); |
2798 |
rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIdx)); |
2861 |
rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIdx)); |
2799 |
sockerr = Socket::ERROR_NOTERROR; |
2862 |
sockerr = Socket::ERROR_NOTERROR; |
2800 |
NS_LOG_DEBUG ("Olsr node " << m_mainAddress |
2863 |
NS_LOG_DEBUG ("Olsr node " << m_mainAddress |
2801 |
<< ": RouteOutput for dest=" << header.GetDestination () |
2864 |
<< ": RouteOutput for dest=" << header.GetDestination () |
2802 |
<< " --> nextHop=" << entry2.nextAddr |
2865 |
<< " --> nextHop=" << entry2.nextAddr |
2803 |
<< " interface=" << entry2.interface); |
2866 |
<< " interface=" << entry2.interface); |
|
2805 |
found = true; |
2868 |
found = true; |
2806 |
} |
2869 |
} |
2807 |
else |
2870 |
else |
2808 |
{ |
2871 |
{ |
2809 |
rtentry = m_hnaRoutingTable->RouteOutput (p, header, oif, sockerr); |
2872 |
rtentry = m_hnaRoutingTable->RouteOutput (p, header, oif, sockerr); |
2810 |
|
2873 |
|
2811 |
if (rtentry) |
2874 |
if (rtentry) |
|
2817 |
|
2880 |
|
2818 |
if (!found) |
2881 |
if (!found) |
2819 |
{ |
2882 |
{ |
2820 |
NS_LOG_DEBUG ("Olsr node " << m_mainAddress |
2883 |
NS_LOG_DEBUG ("Olsr node " << m_mainAddress |
2821 |
<< ": RouteOutput for dest=" << header.GetDestination () |
2884 |
<< ": RouteOutput for dest=" << header.GetDestination () |
2822 |
<< " No route to host"); |
2885 |
<< " No route to host"); |
2823 |
sockerr = Socket::ERROR_NOROUTETOHOST; |
2886 |
sockerr = Socket::ERROR_NOROUTETOHOST; |
|
2825 |
return rtentry; |
2888 |
return rtentry; |
2826 |
} |
2889 |
} |
2827 |
|
2890 |
|
2828 |
bool RoutingProtocol::RouteInput (Ptr<const Packet> p, |
2891 |
bool RoutingProtocol::RouteInput (Ptr<const Packet> p, |
2829 |
const Ipv4Header &header, Ptr<const NetDevice> idev, |
2892 |
const Ipv4Header &header, Ptr<const NetDevice> idev, |
2830 |
UnicastForwardCallback ucb, MulticastForwardCallback mcb, |
2893 |
UnicastForwardCallback ucb, MulticastForwardCallback mcb, |
2831 |
LocalDeliverCallback lcb, ErrorCallback ecb) |
2894 |
LocalDeliverCallback lcb, ErrorCallback ecb) |
|
2838 |
// Consume self-originated packets |
2901 |
// Consume self-originated packets |
2839 |
if (IsMyOwnAddress (origin) == true) |
2902 |
if (IsMyOwnAddress (origin) == true) |
2840 |
{ |
2903 |
{ |
2841 |
return true; |
2904 |
return true; |
2842 |
} |
2905 |
} |
2843 |
|
2906 |
|
2844 |
// Local delivery |
2907 |
// Local delivery |
|
2855 |
else |
2918 |
else |
2856 |
{ |
2919 |
{ |
2857 |
// The local delivery callback is null. This may be a multicast |
2920 |
// The local delivery callback is null. This may be a multicast |
2858 |
// or broadcast packet, so return false so that another |
2921 |
// or broadcast packet, so return false so that another |
2859 |
// multicast routing protocol can handle it. It should be possible |
2922 |
// multicast routing protocol can handle it. It should be possible |
2860 |
// to extend this to explicitly check whether it is a unicast |
2923 |
// to extend this to explicitly check whether it is a unicast |
2861 |
// packet, and invoke the error callback if so |
2924 |
// packet, and invoke the error callback if so |
|
2865 |
|
2928 |
|
2866 |
// Forwarding |
2929 |
// Forwarding |
2867 |
Ptr<Ipv4Route> rtentry; |
2930 |
Ptr<Ipv4Route> rtentry; |
2868 |
RoutingTableEntry entry1, entry2; |
2931 |
RoutingTableEntry entry1, entry2; |
2869 |
if (Lookup (header.GetDestination (), entry1)) |
2932 |
if (Lookup (header.GetDestination (), entry1)) |
2870 |
{ |
2933 |
{ |
2871 |
bool foundSendEntry = FindSendEntry (entry1, entry2); |
2934 |
bool foundSendEntry = FindSendEntry (entry1, entry2); |
2872 |
if (!foundSendEntry) |
2935 |
if (!foundSendEntry) |
2873 |
NS_FATAL_ERROR ("FindSendEntry failure"); |
2936 |
{ |
|
|
2937 |
NS_FATAL_ERROR ("FindSendEntry failure"); |
2938 |
} |
2874 |
rtentry = Create<Ipv4Route> (); |
2939 |
rtentry = Create<Ipv4Route> (); |
2875 |
rtentry->SetDestination (header.GetDestination ()); |
2940 |
rtentry->SetDestination (header.GetDestination ()); |
2876 |
uint32_t interfaceIdx = entry2.interface; |
2941 |
uint32_t interfaceIdx = entry2.interface; |
|
2881 |
uint32_t numOifAddresses = m_ipv4->GetNAddresses (interfaceIdx); |
2946 |
uint32_t numOifAddresses = m_ipv4->GetNAddresses (interfaceIdx); |
2882 |
NS_ASSERT (numOifAddresses > 0); |
2947 |
NS_ASSERT (numOifAddresses > 0); |
2883 |
Ipv4InterfaceAddress ifAddr; |
2948 |
Ipv4InterfaceAddress ifAddr; |
2884 |
if (numOifAddresses == 1) { |
2949 |
if (numOifAddresses == 1) |
|
|
2950 |
{ |
2885 |
ifAddr = m_ipv4->GetAddress (interfaceIdx, 0); |
2951 |
ifAddr = m_ipv4->GetAddress (interfaceIdx, 0); |
2886 |
} else { |
2952 |
} |
|
|
2953 |
else |
2954 |
{ |
2887 |
/// \todo Implment IP aliasing and OLSR |
2955 |
/// \todo Implment IP aliasing and OLSR |
2888 |
NS_FATAL_ERROR ("XXX Not implemented yet: IP aliasing and OLSR"); |
2956 |
NS_FATAL_ERROR ("XXX Not implemented yet: IP aliasing and OLSR"); |
2889 |
} |
2957 |
} |
|
2901 |
} |
2969 |
} |
2902 |
else |
2970 |
else |
2903 |
{ |
2971 |
{ |
2904 |
if(m_hnaRoutingTable->RouteInput (p, header, idev, ucb, mcb, lcb, ecb)) |
2972 |
if (m_hnaRoutingTable->RouteInput (p, header, idev, ucb, mcb, lcb, ecb)) |
2905 |
{ |
2973 |
{ |
2906 |
return true; |
2974 |
return true; |
2907 |
} |
2975 |
} |
|
2909 |
{ |
2977 |
{ |
2910 |
|
2978 |
|
2911 |
#ifdef NS3_LOG_ENABLE |
2979 |
#ifdef NS3_LOG_ENABLE |
2912 |
NS_LOG_DEBUG ("Olsr node " << m_mainAddress |
2980 |
NS_LOG_DEBUG ("Olsr node " << m_mainAddress |
2913 |
<< ": RouteInput for dest=" << header.GetDestination () |
2981 |
<< ": RouteInput for dest=" << header.GetDestination () |
2914 |
<< " --> NOT FOUND; ** Dumping routing table..."); |
2982 |
<< " --> NOT FOUND; ** Dumping routing table..."); |
2915 |
|
2983 |
|
|
2927 |
} |
2995 |
} |
2928 |
} |
2996 |
} |
2929 |
} |
2997 |
} |
2930 |
void |
2998 |
void |
2931 |
RoutingProtocol::NotifyInterfaceUp (uint32_t i) |
2999 |
RoutingProtocol::NotifyInterfaceUp (uint32_t i) |
2932 |
{} |
3000 |
{ |
2933 |
void |
3001 |
} |
|
|
3002 |
void |
2934 |
RoutingProtocol::NotifyInterfaceDown (uint32_t i) |
3003 |
RoutingProtocol::NotifyInterfaceDown (uint32_t i) |
2935 |
{} |
3004 |
{ |
2936 |
void |
3005 |
} |
|
|
3006 |
void |
2937 |
RoutingProtocol::NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address) |
3007 |
RoutingProtocol::NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address) |
2938 |
{} |
3008 |
{ |
2939 |
void |
3009 |
} |
|
|
3010 |
void |
2940 |
RoutingProtocol::NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address) |
3011 |
RoutingProtocol::NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address) |
2941 |
{} |
3012 |
{ |
|
|
3013 |
} |
2942 |
|
3014 |
|
2943 |
|
3015 |
|
2944 |
void |
3016 |
void |
|
3040 |
iter != m_state.GetTwoHopNeighbors ().end (); iter++) |
3112 |
iter != m_state.GetTwoHopNeighbors ().end (); iter++) |
3041 |
{ |
3113 |
{ |
3042 |
if (now < iter->expirationTime) |
3114 |
if (now < iter->expirationTime) |
3043 |
{ |
3115 |
{ |
3044 |
NS_LOG_DEBUG (" " << *iter); |
3116 |
NS_LOG_DEBUG (" " << *iter); |
3045 |
} |
3117 |
} |
3046 |
} |
3118 |
} |