31 #define NS_LOG_APPEND_CONTEXT \
32 if (GetObject<Node> ()) { std::clog << "[node " << GetObject<Node> ()->GetId () << "] "; }
35 #include "olsr-routing-protocol.h"
36 #include "ns3/socket-factory.h"
37 #include "ns3/udp-socket-factory.h"
38 #include "ns3/simulator.h"
40 #include "ns3/names.h"
41 #include "ns3/inet-socket-address.h"
42 #include "ns3/ipv4-routing-protocol.h"
43 #include "ns3/ipv4-routing-table-entry.h"
44 #include "ns3/ipv4-route.h"
45 #include "ns3/boolean.h"
46 #include "ns3/uinteger.h"
48 #include "ns3/trace-source-accessor.h"
49 #include "ns3/ipv4-header.h"
59 #define DELAY(time) (((time) < (Simulator::Now ())) ? Seconds (0.000001) : \
60 (time - Simulator::Now () + Seconds (0.000001)))
69 #define OLSR_REFRESH_INTERVAL m_helloInterval
75 #define OLSR_NEIGHB_HOLD_TIME Time (3 * OLSR_REFRESH_INTERVAL)
76 #define OLSR_TOP_HOLD_TIME Time (3 * m_tcInterval)
78 #define OLSR_DUP_HOLD_TIME Seconds (30)
80 #define OLSR_MID_HOLD_TIME Time (3 * m_midInterval)
82 #define OLSR_HNA_HOLD_TIME Time (3 * m_hnaInterval)
88 #define OLSR_UNSPEC_LINK 0
89 #define OLSR_ASYM_LINK 1
91 #define OLSR_SYM_LINK 2
93 #define OLSR_LOST_LINK 3
99 #define OLSR_NOT_NEIGH 0
100 #define OLSR_SYM_NEIGH 1
102 #define OLSR_MPR_NEIGH 2
109 #define OLSR_WILL_NEVER 0
110 #define OLSR_WILL_LOW 1
112 #define OLSR_WILL_DEFAULT 3
114 #define OLSR_WILL_HIGH 6
116 #define OLSR_WILL_ALWAYS 7
123 #define OLSR_MAXJITTER (m_helloInterval.GetSeconds () / 4)
124 #define OLSR_MAX_SEQ_NUM 65535
126 #define JITTER (Seconds (m_uniformRandomVariable->GetValue (0, OLSR_MAXJITTER)))
130 #define OLSR_PORT_NUMBER 698
131 #define OLSR_MAX_MSGS 64
135 #define OLSR_MAX_HELLOS 12
138 #define OLSR_MAX_ADDRS 64
149 NS_OBJECT_ENSURE_REGISTERED (RoutingProtocol);
152 RoutingProtocol::GetTypeId (
void)
154 static TypeId tid = TypeId (
"ns3::olsr::RoutingProtocol")
155 .SetParent<Ipv4RoutingProtocol> ()
156 .AddConstructor<RoutingProtocol> ()
157 .AddAttribute (
"HelloInterval",
"HELLO messages emission interval.",
161 .AddAttribute (
"TcInterval",
"TC messages emission interval.",
165 .AddAttribute (
"MidInterval",
"MID messages emission interval. Normally it is equal to TcInterval.",
169 .AddAttribute (
"HnaInterval",
"HNA messages emission interval. Normally it is equal to TcInterval.",
173 .AddAttribute (
"Willingness",
"Willingness of a node to carry and forward traffic for other nodes.",
174 EnumValue (OLSR_WILL_DEFAULT),
176 MakeEnumChecker (OLSR_WILL_NEVER,
"never",
177 OLSR_WILL_LOW,
"low",
178 OLSR_WILL_DEFAULT,
"default",
179 OLSR_WILL_HIGH,
"high",
180 OLSR_WILL_ALWAYS,
"always"))
181 .AddTraceSource (
"Rx",
"Receive OLSR packet.",
183 .AddTraceSource (
"Tx",
"Send OLSR packet.",
185 .AddTraceSource (
"RoutingTableChanged",
"The OLSR routing table has changed.",
192 RoutingProtocol::RoutingProtocol ()
193 : m_routingTableAssociation (0),
195 m_helloTimer (Timer::CANCEL_ON_DESTROY),
196 m_tcTimer (Timer::CANCEL_ON_DESTROY),
197 m_midTimer (Timer::CANCEL_ON_DESTROY),
198 m_hnaTimer (Timer::CANCEL_ON_DESTROY),
199 m_queuedMessagesTimer (Timer::CANCEL_ON_DESTROY)
201 m_uniformRandomVariable = CreateObject<UniformRandomVariable> ();
203 m_hnaRoutingTable = Create<Ipv4StaticRouting> ();
206 RoutingProtocol::~RoutingProtocol ()
224 m_ansn = OLSR_MAX_SEQ_NUM;
226 m_linkTupleTimerFirstTime =
true;
230 m_hnaRoutingTable->SetIpv4 (ipv4);
236 m_hnaRoutingTable = 0;
237 m_routingTableAssociation = 0;
240 iter != m_socketAddresses.end (); iter++)
242 iter->first->Close ();
244 m_socketAddresses.clear ();
253 *os <<
"Destination\t\tNextHop\t\tInterface\tDistance\n";
255 for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator iter =
m_table.begin ();
256 iter !=
m_table.end (); iter++)
258 *os << iter->first <<
"\t\t";
259 *os << iter->second.nextAddr <<
"\t\t";
260 if (
Names::FindName (m_ipv4->GetNetDevice (iter->second.interface)) !=
"")
262 *os <<
Names::FindName (m_ipv4->GetNetDevice (iter->second.interface)) <<
"\t\t";
266 *os << iter->second.interface <<
"\t\t";
268 *os << iter->second.distance <<
"\t";
272 *os <<
" HNA Routing Table:\n";
273 m_hnaRoutingTable->PrintRoutingTable (stream);
281 for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
284 Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal ();
285 if (addr != loopback)
287 m_mainAddress = addr;
295 NS_LOG_DEBUG (
"Starting OLSR on node " << m_mainAddress);
299 bool canRunOlsr =
false;
300 for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
302 Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal ();
303 if (addr == loopback)
306 if (addr != m_mainAddress)
318 if(m_interfaceExclusions.find (i) != m_interfaceExclusions.end ())
323 UdpSocketFactory::GetTypeId ());
325 InetSocketAddress inetAddr (m_ipv4->GetAddress (i, 0).GetLocal (), OLSR_PORT_NUMBER);
327 if (socket->
Bind (inetAddr))
332 m_socketAddresses[socket] = m_ipv4->GetAddress (i, 0);
344 NS_LOG_DEBUG (
"OLSR on node " << m_mainAddress <<
" started");
350 m_mainAddress = m_ipv4->GetAddress (interface, 0).GetLocal ();
353 void RoutingProtocol::SetInterfaceExclusions (std::set<uint32_t> exceptions)
355 m_interfaceExclusions = exceptions;
365 receivedPacket = socket->
RecvFrom (sourceAddress);
369 Ipv4Address receiverIfaceAddr = m_socketAddresses[socket].GetLocal ();
371 NS_LOG_DEBUG (
"OLSR node " << m_mainAddress <<
" received a OLSR packet from "
372 << senderIfaceAddr <<
" to " << receiverIfaceAddr);
381 packet->RemoveHeader (olsrPacketHeader);
383 uint32_t sizeLeft = olsrPacketHeader.GetPacketLength () - olsrPacketHeader.
GetSerializedSize ();
385 MessageList messages;
390 if (packet->RemoveHeader (messageHeader) == 0)
396 << std::dec <<
int (messageHeader.GetMessageType ())
397 <<
" TTL=" <<
int (messageHeader.GetTimeToLive ())
398 <<
" origAddr=" << messageHeader.GetOriginatorAddress ());
399 messages.push_back (messageHeader);
402 m_rxPacketTrace (olsrPacketHeader, messages);
404 for (MessageList::const_iterator messageIter = messages.begin ();
405 messageIter != messages.end (); messageIter++)
407 const MessageHeader &messageHeader = *messageIter;
411 if (messageHeader.GetTimeToLive () == 0
412 || messageHeader.GetOriginatorAddress () == m_mainAddress)
414 packet->RemoveAtStart (messageHeader.GetSerializedSize ()
415 - messageHeader.GetSerializedSize ());
420 bool do_forwarding =
true;
421 DuplicateTuple *duplicated =
m_state.FindDuplicateTuple
422 (messageHeader.GetOriginatorAddress (),
423 messageHeader.GetMessageSequenceNumber ());
437 if (duplicated == NULL)
439 switch (messageHeader.GetMessageType ())
441 case olsr::MessageHeader::HELLO_MESSAGE:
443 <<
"s OLSR node " << m_mainAddress
444 <<
" received HELLO message of size " << messageHeader.GetSerializedSize ());
445 ProcessHello (messageHeader, receiverIfaceAddr, senderIfaceAddr);
448 case olsr::MessageHeader::TC_MESSAGE:
450 <<
"s OLSR node " << m_mainAddress
451 <<
" received TC message of size " << messageHeader.GetSerializedSize ());
452 ProcessTc (messageHeader, senderIfaceAddr);
455 case olsr::MessageHeader::MID_MESSAGE:
457 <<
"s OLSR node " << m_mainAddress
458 <<
" received MID message of size " << messageHeader.GetSerializedSize ());
461 case olsr::MessageHeader::HNA_MESSAGE:
463 <<
"s OLSR node " << m_mainAddress
464 <<
" received HNA message of size " << messageHeader.GetSerializedSize ());
470 int (messageHeader.GetMessageType ()) <<
476 NS_LOG_DEBUG (
"OLSR message is duplicated, not reading it.");
480 for (std::vector<Ipv4Address>::const_iterator it = duplicated->ifaceList.begin ();
481 it != duplicated->ifaceList.end (); it++)
483 if (*it == receiverIfaceAddr)
485 do_forwarding =
false;
496 if (messageHeader.GetMessageType () != olsr::MessageHeader::HELLO_MESSAGE)
499 receiverIfaceAddr, inetSourceAddr.
GetIpv4 ());
518 for (TwoHopNeighborSet::const_iterator it =
m_state.GetTwoHopNeighbors ().begin ();
519 it !=
m_state.GetTwoHopNeighbors ().end (); it++)
526 if (nb_tuple == NULL)
541 std::set<Ipv4Address> toRemove;
542 for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin (); twoHopNeigh != N2.end (); twoHopNeigh++)
544 if (twoHopNeigh->neighborMainAddr == neighborMainAddr)
546 toRemove.insert (twoHopNeigh->twoHopNeighborAddr);
550 for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin (); twoHopNeigh != N2.end (); )
552 if (toRemove.find (twoHopNeigh->twoHopNeighborAddr) != toRemove.end ())
554 twoHopNeigh = N2.erase (twoHopNeigh);
579 for (NeighborSet::const_iterator neighbor =
m_state.GetNeighbors ().begin ();
580 neighbor !=
m_state.GetNeighbors ().end (); neighbor++)
582 if (neighbor->status == NeighborTuple::STATUS_SYM)
584 N.push_back (*neighbor);
594 TwoHopNeighborSet N2;
595 for (TwoHopNeighborSet::const_iterator twoHopNeigh =
m_state.GetTwoHopNeighbors ().begin ();
596 twoHopNeigh !=
m_state.GetTwoHopNeighbors ().end (); twoHopNeigh++)
600 if (twoHopNeigh->twoHopNeighborAddr == m_mainAddress)
608 for (NeighborSet::const_iterator neigh = N.begin ();
609 neigh != N.end (); neigh++)
611 if (neigh->neighborMainAddr == twoHopNeigh->neighborMainAddr)
613 if (neigh->willingness == OLSR_WILL_NEVER)
633 for (NeighborSet::const_iterator neigh = N.begin ();
634 neigh != N.end (); neigh++)
636 if (neigh->neighborMainAddr == twoHopNeigh->twoHopNeighborAddr)
645 N2.push_back (*twoHopNeigh);
649 #ifdef NS3_LOG_ENABLE
651 std::ostringstream os;
653 for (TwoHopNeighborSet::const_iterator iter = N2.begin ();
654 iter != N2.end (); iter++)
656 TwoHopNeighborSet::const_iterator next = iter;
658 os << iter->neighborMainAddr <<
"->" << iter->twoHopNeighborAddr;
659 if (next != N2.end ())
665 #endif //NS3_LOG_ENABLE
669 for (NeighborSet::const_iterator neighbor = N.begin (); neighbor != N.end (); neighbor++)
671 if (neighbor->willingness == OLSR_WILL_ALWAYS)
673 mprSet.insert (neighbor->neighborMainAddr);
676 CoverTwoHopNeighbors (neighbor->neighborMainAddr, N2);
685 std::set<Ipv4Address> coveredTwoHopNeighbors;
686 for (TwoHopNeighborSet::const_iterator twoHopNeigh = N2.begin (); twoHopNeigh != N2.end (); twoHopNeigh++)
690 for (TwoHopNeighborSet::const_iterator otherTwoHopNeigh = N2.begin (); otherTwoHopNeigh != N2.end (); otherTwoHopNeigh++)
692 if (otherTwoHopNeigh->twoHopNeighborAddr == twoHopNeigh->twoHopNeighborAddr
693 && otherTwoHopNeigh->neighborMainAddr != twoHopNeigh->neighborMainAddr)
701 NS_LOG_LOGIC (
"Neighbor " << twoHopNeigh->neighborMainAddr
702 <<
" is the only that can reach 2-hop neigh. "
703 << twoHopNeigh->twoHopNeighborAddr
704 <<
" => select as MPR.");
706 mprSet.insert (twoHopNeigh->neighborMainAddr);
709 for (TwoHopNeighborSet::const_iterator otherTwoHopNeigh = N2.begin ();
710 otherTwoHopNeigh != N2.end (); otherTwoHopNeigh++)
712 if (otherTwoHopNeigh->neighborMainAddr == twoHopNeigh->neighborMainAddr)
714 coveredTwoHopNeighbors.insert (otherTwoHopNeigh->twoHopNeighborAddr);
720 for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin ();
721 twoHopNeigh != N2.end (); )
723 if (coveredTwoHopNeighbors.find (twoHopNeigh->twoHopNeighborAddr) != coveredTwoHopNeighbors.end ())
727 NS_LOG_LOGIC (
"2-hop neigh. " << twoHopNeigh->twoHopNeighborAddr <<
" is already covered by an MPR.");
728 twoHopNeigh = N2.erase (twoHopNeigh);
738 while (N2.begin () != N2.end ())
741 #ifdef NS3_LOG_ENABLE
743 std::ostringstream os;
745 for (TwoHopNeighborSet::const_iterator iter = N2.begin ();
746 iter != N2.end (); iter++)
748 TwoHopNeighborSet::const_iterator next = iter;
750 os << iter->neighborMainAddr <<
"->" << iter->twoHopNeighborAddr;
751 if (next != N2.end ())
757 #endif //NS3_LOG_ENABLE
764 std::map<int, std::vector<const NeighborTuple *> > reachability;
766 for (NeighborSet::iterator it = N.begin (); it != N.end (); it++)
770 for (TwoHopNeighborSet::iterator it2 = N2.begin (); it2 != N2.end (); it2++)
777 reachability[r].push_back (&nb_tuple);
790 for (std::set<int>::iterator it = rs.begin (); it != rs.end (); it++)
797 for (std::vector<const NeighborTuple *>::iterator it2 = reachability[r].begin ();
798 it2 != reachability[r].end (); it2++)
829 NS_LOG_LOGIC (N2.size () <<
" 2-hop neighbors left to cover!");
833 #ifdef NS3_LOG_ENABLE
835 std::ostringstream os;
837 for (MprSet::const_iterator iter = mprSet.begin ();
838 iter != mprSet.end (); iter++)
840 MprSet::const_iterator next = iter;
843 if (next != mprSet.end ())
847 NS_LOG_DEBUG (
"Computed MPR set for node " << m_mainAddress <<
": " << os.str ());
849 #endif //NS3_LOG_ENABLE
864 m_state.FindIfaceAssocTuple (iface_addr);
879 <<
": RoutingTableComputation begin...");
886 const NeighborSet &neighborSet =
m_state.GetNeighbors ();
887 for (NeighborSet::const_iterator it = neighborSet.begin ();
888 it != neighborSet.end (); it++)
891 NS_LOG_DEBUG (
"Looking at neighbor tuple: " << nb_tuple);
892 if (nb_tuple.status == NeighborTuple::STATUS_SYM)
894 bool nb_main_addr =
false;
896 const LinkSet &linkSet =
m_state.GetLinks ();
897 for (LinkSet::const_iterator it2 = linkSet.begin ();
898 it2 != linkSet.end (); it2++)
907 <<
" => adding routing table entry to neighbor");
936 if (!nb_main_addr && lt != NULL)
938 NS_LOG_LOGIC (
"no R_dest_addr is equal to the main address of the neighbor "
939 "=> adding additional routing entry");
953 const TwoHopNeighborSet &twoHopNeighbors =
m_state.GetTwoHopNeighbors ();
954 for (TwoHopNeighborSet::const_iterator it = twoHopNeighbors.begin ();
955 it != twoHopNeighbors.end (); it++)
959 NS_LOG_LOGIC (
"Looking at two-hop neighbor tuple: " << nb2hop_tuple);
964 NS_LOG_LOGIC (
"Two-hop neighbor tuple is also neighbor; skipped.");
977 bool nb2hopOk =
false;
978 for (NeighborSet::const_iterator neighbor = neighborSet.begin ();
979 neighbor != neighborSet.end (); neighbor++)
982 && neighbor->willingness != OLSR_WILL_NEVER)
990 NS_LOG_LOGIC (
"Two-hop neighbor tuple skipped: 2-hop neighbor "
993 <<
", which was not found in the Neighbor Set.");
1012 NS_LOG_LOGIC (
"Adding routing entry for two-hop neighbor.");
1020 NS_LOG_LOGIC (
"NOT adding routing entry for two-hop neighbor ("
1022 <<
" not found in the routing table)");
1026 for (uint32_t h = 2;; h++)
1036 const TopologySet &topology =
m_state.GetTopologySet ();
1037 for (TopologySet::const_iterator it = topology.begin ();
1038 it != topology.end (); it++)
1041 NS_LOG_LOGIC (
"Looking at topology tuple: " << topology_tuple);
1044 bool have_destAddrEntry =
Lookup (topology_tuple.
destAddr, destAddrEntry);
1045 bool have_lastAddrEntry =
Lookup (topology_tuple.
lastAddr, lastAddrEntry);
1046 if (!have_destAddrEntry && have_lastAddrEntry && lastAddrEntry.
distance == h)
1048 NS_LOG_LOGIC (
"Adding routing table entry based on the topology tuple.");
1067 NS_LOG_LOGIC (
"NOT adding routing table entry based on the topology tuple: "
1068 "have_destAddrEntry=" << have_destAddrEntry
1069 <<
" have_lastAddrEntry=" << have_lastAddrEntry
1070 <<
" lastAddrEntry.distance=" << (
int) lastAddrEntry.
distance
1071 <<
" (h=" << h <<
")");
1084 const IfaceAssocSet &ifaceAssocSet =
m_state.GetIfaceAssocSet ();
1085 for (IfaceAssocSet::const_iterator it = ifaceAssocSet.begin ();
1086 it != ifaceAssocSet.end (); it++)
1092 if (have_entry1 && !have_entry2)
1112 const AssociationSet &associationSet =
m_state.GetAssociationSet ();
1115 for (uint32_t i = 0; i < m_hnaRoutingTable->GetNRoutes (); i++)
1117 m_hnaRoutingTable->RemoveRoute (0);
1120 for (AssociationSet::const_iterator it = associationSet.begin ();
1121 it != associationSet.end (); it++)
1128 bool goToNextAssociationTuple =
false;
1129 const Associations &localHnaAssociations =
m_state.GetAssociations ();
1130 NS_LOG_DEBUG (
"Nb local associations: " << localHnaAssociations.size ());
1131 for (Associations::const_iterator assocIterator = localHnaAssociations.begin ();
1132 assocIterator != localHnaAssociations.end (); assocIterator++)
1134 Association const &localHnaAssoc = *assocIterator;
1135 if (localHnaAssoc.networkAddr == tuple.
networkAddr && localHnaAssoc.netmask == tuple.
netmask)
1137 NS_LOG_DEBUG (
"HNA association received from another GW is part of local HNA associations: no route added for network "
1139 goToNextAssociationTuple =
true;
1142 if (goToNextAssociationTuple)
1150 bool addRoute =
false;
1152 uint32_t routeIndex = 0;
1154 for (routeIndex = 0; routeIndex < m_hnaRoutingTable->GetNRoutes (); routeIndex++)
1164 if (routeIndex == m_hnaRoutingTable->GetNRoutes ())
1168 else if(gatewayEntryExists && m_hnaRoutingTable->GetMetric (routeIndex) > gatewayEntry.
distance)
1170 m_hnaRoutingTable->RemoveRoute (routeIndex);
1174 if(addRoute && gatewayEntryExists)
1176 m_hnaRoutingTable->AddNetworkRouteTo (tuple.
networkAddr,
1185 NS_LOG_DEBUG (
"Node " << m_mainAddress <<
": RoutingTableComputation end.");
1186 m_routingTableChanged (GetSize ());
1209 LinkSensing (msg, hello, receiverIface, senderIface);
1211 #ifdef NS3_LOG_ENABLE
1213 const LinkSet &links =
m_state.GetLinks ();
1215 <<
"s ** BEGIN dump Link Set for OLSR Node " << m_mainAddress);
1216 for (LinkSet::const_iterator link = links.begin (); link != links.end (); link++)
1220 NS_LOG_DEBUG (
"** END dump Link Set for OLSR Node " << m_mainAddress);
1222 const NeighborSet &neighbors =
m_state.GetNeighbors ();
1224 <<
"s ** BEGIN dump Neighbor Set for OLSR Node " << m_mainAddress);
1225 for (NeighborSet::const_iterator neighbor = neighbors.begin (); neighbor != neighbors.end (); neighbor++)
1229 NS_LOG_DEBUG (
"** END dump Neighbor Set for OLSR Node " << m_mainAddress);
1231 #endif // NS3_LOG_ENABLE
1236 #ifdef NS3_LOG_ENABLE
1238 const TwoHopNeighborSet &twoHopNeighbors =
m_state.GetTwoHopNeighbors ();
1240 <<
"s ** BEGIN dump TwoHopNeighbor Set for OLSR Node " << m_mainAddress);
1241 for (TwoHopNeighborSet::const_iterator tuple = twoHopNeighbors.begin ();
1242 tuple != twoHopNeighbors.end (); tuple++)
1246 NS_LOG_DEBUG (
"** END dump TwoHopNeighbor Set for OLSR Node " << m_mainAddress);
1248 #endif // NS3_LOG_ENABLE
1273 if (link_tuple == NULL)
1282 m_state.FindNewerTopologyTuple (msg.GetOriginatorAddress (), tc.ansn);
1283 if (topologyTuple != NULL)
1290 m_state.EraseOlderTopologyTuples (msg.GetOriginatorAddress (), tc.ansn);
1294 for (std::vector<Ipv4Address>::const_iterator i = tc.neighborAddresses.begin ();
1295 i != tc.neighborAddresses.end (); i++)
1304 m_state.FindTopologyTuple (addr, msg.GetOriginatorAddress ());
1306 if (topologyTuple != NULL)
1320 topologyTuple.
lastAddr = msg.GetOriginatorAddress ();
1334 #ifdef NS3_LOG_ENABLE
1336 const TopologySet &topology =
m_state.GetTopologySet ();
1338 <<
"s ** BEGIN dump TopologySet for OLSR Node " << m_mainAddress);
1339 for (TopologySet::const_iterator tuple = topology.begin ();
1340 tuple != topology.end (); tuple++)
1344 NS_LOG_DEBUG (
"** END dump TopologySet Set for OLSR Node " << m_mainAddress);
1346 #endif // NS3_LOG_ENABLE
1365 NS_LOG_DEBUG (
"Node " << m_mainAddress <<
" ProcessMid from " << senderIface);
1369 if (linkTuple == NULL)
1372 ": the sender interface of this message is not in the "
1373 "symmetric 1-hop neighborhood of this node,"
1374 " the message MUST be discarded.");
1379 for (std::vector<Ipv4Address>::const_iterator i = mid.interfaceAddresses.begin ();
1380 i != mid.interfaceAddresses.end (); i++)
1382 bool updated =
false;
1383 IfaceAssocSet &ifaceAssoc =
m_state.GetIfaceAssocSetMutable ();
1384 for (IfaceAssocSet::iterator tuple = ifaceAssoc.begin ();
1385 tuple != ifaceAssoc.end (); tuple++)
1387 if (tuple->ifaceAddr == *i
1388 && tuple->mainAddr == msg.GetOriginatorAddress ())
1391 tuple->time = now + msg.GetVTime ();
1399 tuple.
mainAddr = msg.GetOriginatorAddress ();
1400 tuple.
time = now + msg.GetVTime ();
1412 NeighborSet &neighbors =
m_state.GetNeighbors ();
1413 for (NeighborSet::iterator neighbor = neighbors.begin (); neighbor != neighbors.end (); neighbor++)
1415 neighbor->neighborMainAddr =
GetMainAddress (neighbor->neighborMainAddr);
1418 TwoHopNeighborSet &twoHopNeighbors =
m_state.GetTwoHopNeighbors ();
1419 for (TwoHopNeighborSet::iterator twoHopNeighbor = twoHopNeighbors.begin ();
1420 twoHopNeighbor != twoHopNeighbors.end (); twoHopNeighbor++)
1422 twoHopNeighbor->neighborMainAddr =
GetMainAddress (twoHopNeighbor->neighborMainAddr);
1423 twoHopNeighbor->twoHopNeighborAddr =
GetMainAddress (twoHopNeighbor->twoHopNeighborAddr);
1425 NS_LOG_DEBUG (
"Node " << m_mainAddress <<
" ProcessMid from " << senderIface <<
" -> END.");
1448 if (link_tuple == NULL)
1454 for (std::vector<olsr::MessageHeader::Hna::Association>::const_iterator it = hna.associations.begin ();
1455 it != hna.associations.end (); it++)
1478 msg.GetOriginatorAddress (),
1481 now + msg.GetVTime ()
1515 const LinkTuple *linkTuple =
m_state.FindSymLinkTuple (senderAddress, now);
1516 if (linkTuple == NULL)
1524 " from " << olsrMessage.GetOriginatorAddress () <<
" because it is duplicated");
1531 bool retransmitted =
false;
1532 if (olsrMessage.GetTimeToLive () > 1)
1536 if (mprselTuple != NULL)
1538 olsrMessage.SetTimeToLive (olsrMessage.GetTimeToLive () - 1);
1539 olsrMessage.SetHopCount (olsrMessage.GetHopCount () + 1);
1543 retransmitted =
true;
1548 if (duplicated != NULL)
1552 duplicated->
ifaceList.push_back (localIface);
1558 newDup.
address = olsrMessage.GetOriginatorAddress ();
1562 newDup.
ifaceList.push_back (localIface);
1584 if (not m_queuedMessagesTimer.
IsRunning ())
1586 m_queuedMessagesTimer.
SetDelay (delay);
1593 const MessageList &containedMessages)
1595 NS_LOG_DEBUG (
"OLSR node " << m_mainAddress <<
" sending a OLSR packet");
1604 m_txPacketTrace (header, containedMessages);
1608 m_socketAddresses.begin (); i != m_socketAddresses.end (); i++)
1626 int numMessages = 0;
1628 NS_LOG_DEBUG (
"Olsr node " << m_mainAddress <<
": SendQueuedMessages");
1630 MessageList msglist;
1632 for (std::vector<olsr::MessageHeader>::const_iterator message =
m_queuedMessages.begin ();
1639 msglist.push_back (*message);
1640 if (++numMessages == OLSR_MAX_MSGS)
1642 SendPacket (packet, msglist);
1646 packet = Create<Packet> ();
1652 SendPacket (packet, msglist);
1669 msg.SetVTime (OLSR_NEIGHB_HOLD_TIME);
1670 msg.SetOriginatorAddress (m_mainAddress);
1671 msg.SetTimeToLive (1);
1672 msg.SetHopCount (0);
1679 std::vector<olsr::MessageHeader::Hello::LinkMessage>
1680 &linkMessages = hello.linkMessages;
1682 const LinkSet &links =
m_state.GetLinks ();
1683 for (LinkSet::const_iterator link_tuple = links.begin ();
1684 link_tuple != links.end (); link_tuple++)
1686 if (!(
GetMainAddress (link_tuple->localIfaceAddr) == m_mainAddress
1687 && link_tuple->time >= now))
1692 uint8_t link_type, nb_type = 0xff;
1695 if (link_tuple->symTime >= now)
1697 link_type = OLSR_SYM_LINK;
1699 else if (link_tuple->asymTime >= now)
1701 link_type = OLSR_ASYM_LINK;
1705 link_type = OLSR_LOST_LINK;
1710 nb_type = OLSR_MPR_NEIGH;
1712 <<
" to be MPR_NEIGH.");
1717 for (NeighborSet::const_iterator nb_tuple =
m_state.GetNeighbors ().begin ();
1718 nb_tuple !=
m_state.GetNeighbors ().end ();
1721 if (nb_tuple->neighborMainAddr ==
GetMainAddress (link_tuple->neighborIfaceAddr))
1723 if (nb_tuple->status == NeighborTuple::STATUS_SYM)
1726 <<
" to be SYM_NEIGH.");
1727 nb_type = OLSR_SYM_NEIGH;
1729 else if (nb_tuple->status == NeighborTuple::STATUS_NOT_SYM)
1731 nb_type = OLSR_NOT_NEIGH;
1733 <<
" to be NOT_NEIGH.");
1737 NS_FATAL_ERROR (
"There is a neighbor tuple with an unknown status!\n");
1751 linkMessage.linkCode = (link_type & 0x03) | ((nb_type << 2) & 0x0f);
1752 linkMessage.neighborInterfaceAddresses.push_back
1753 (link_tuple->neighborIfaceAddr);
1755 std::vector<Ipv4Address> interfaces =
1756 m_state.FindNeighborInterfaces (link_tuple->neighborIfaceAddr);
1758 linkMessage.neighborInterfaceAddresses.insert
1759 (linkMessage.neighborInterfaceAddresses.end (),
1760 interfaces.begin (), interfaces.end ());
1762 linkMessages.push_back (linkMessage);
1765 <<
" (with " <<
int (linkMessages.size ()) <<
" link messages)");
1779 msg.SetVTime (OLSR_TOP_HOLD_TIME);
1780 msg.SetOriginatorAddress (m_mainAddress);
1781 msg.SetTimeToLive (255);
1782 msg.SetHopCount (0);
1788 for (MprSelectorSet::const_iterator mprsel_tuple =
m_state.GetMprSelectors ().begin ();
1789 mprsel_tuple !=
m_state.GetMprSelectors ().end (); mprsel_tuple++)
1791 tc.neighborAddresses.push_back (mprsel_tuple->mainAddr);
1822 for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
1824 Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal ();
1825 if (addr != m_mainAddress && addr != loopback && m_interfaceExclusions.find (i) == m_interfaceExclusions.end ())
1826 mid.interfaceAddresses.push_back (addr);
1828 if (mid.interfaceAddresses.size () == 0)
1831 msg.SetVTime (OLSR_MID_HOLD_TIME);
1832 msg.SetOriginatorAddress (m_mainAddress);
1833 msg.SetTimeToLive (255);
1834 msg.SetHopCount (0);
1849 msg.SetVTime (OLSR_HNA_HOLD_TIME);
1850 msg.SetOriginatorAddress (m_mainAddress);
1851 msg.SetTimeToLive (255);
1852 msg.SetHopCount (0);
1856 std::vector<olsr::MessageHeader::Hna::Association> &associations = hna.associations;
1859 const Associations &localHnaAssociations =
m_state.GetAssociations ();
1860 for (Associations::const_iterator it = localHnaAssociations.begin ();
1861 it != localHnaAssociations.end (); it++)
1864 associations.push_back (assoc);
1867 if (associations.size () == 0)
1886 const Associations &localHnaAssociations =
m_state.GetAssociations ();
1887 for (Associations::const_iterator assocIterator = localHnaAssociations.begin ();
1888 assocIterator != localHnaAssociations.end (); assocIterator++)
1890 Association const &localHnaAssoc = *assocIterator;
1891 if (localHnaAssoc.networkAddr == networkAddr && localHnaAssoc.netmask == netmask)
1893 NS_LOG_INFO (
"HNA association for network " << networkAddr <<
"/" << netmask <<
" already exists.");
1898 NS_LOG_INFO (
"Adding HNA association for network " << networkAddr <<
"/" << netmask <<
".");
1910 NS_LOG_INFO (
"Removing HNA association for network " << networkAddr <<
"/" << netmask <<
".");
1929 if (m_routingTableAssociation != 0)
1931 NS_LOG_INFO (
"Removing HNA entries coming from the old routing table association.");
1932 for (uint32_t i = 0; i < m_routingTableAssociation->GetNRoutes (); i++)
1945 m_routingTableAssociation = routingTable;
1950 NS_LOG_DEBUG (
"Nb local associations before adding some entries from"
1951 " the associated routing table: " <<
m_state.GetAssociations ().size ());
1952 for (uint32_t i = 0; i < m_routingTableAssociation->GetNRoutes (); i++)
1965 NS_LOG_DEBUG (
"Nb local associations after having added some entries from "
1966 "the associated routing table: " <<
m_state.GetAssociations ().size ());
1977 std::set<uint32_t>::const_iterator ci = m_interfaceExclusions.find (route.
GetInterface ());
1980 return ci != m_interfaceExclusions.end ();
1993 bool updated =
false;
1994 bool created =
false;
1996 <<
": LinkSensing(receiverIface=" << receiverIface
1997 <<
", senderIface=" << senderIface <<
") BEGIN");
2001 if (link_tuple == NULL)
2008 newLinkTuple.
time = now + msg.GetVTime ();
2009 link_tuple = &
m_state.InsertLinkTuple (newLinkTuple);
2011 NS_LOG_LOGIC (
"Existing link tuple did not exist => creating new one");
2015 NS_LOG_LOGIC (
"Existing link tuple already exists => will update it");
2019 link_tuple->asymTime = now + msg.GetVTime ();
2020 for (std::vector<olsr::MessageHeader::Hello::LinkMessage>::const_iterator linkMessage =
2021 hello.linkMessages.begin ();
2022 linkMessage != hello.linkMessages.end ();
2025 int lt = linkMessage->linkCode & 0x03;
2026 int nt = (linkMessage->linkCode >> 2) & 0x03;
2028 #ifdef NS3_LOG_ENABLE
2029 const char *linkTypeName;
2032 case OLSR_UNSPEC_LINK: linkTypeName =
"UNSPEC_LINK";
break;
2033 case OLSR_ASYM_LINK: linkTypeName =
"ASYM_LINK";
break;
2034 case OLSR_SYM_LINK: linkTypeName =
"SYM_LINK";
break;
2035 case OLSR_LOST_LINK: linkTypeName =
"LOST_LINK";
break;
2036 default: linkTypeName =
"(invalid value!)";
2039 const char *neighborTypeName;
2042 case OLSR_NOT_NEIGH: neighborTypeName =
"NOT_NEIGH";
break;
2043 case OLSR_SYM_NEIGH: neighborTypeName =
"SYM_NEIGH";
break;
2044 case OLSR_MPR_NEIGH: neighborTypeName =
"MPR_NEIGH";
break;
2045 default: neighborTypeName =
"(invalid value!)";
2048 NS_LOG_DEBUG (
"Looking at HELLO link messages with Link Type "
2049 << lt <<
" (" << linkTypeName
2050 <<
") and Neighbor Type " << nt
2051 <<
" (" << neighborTypeName <<
")");
2052 #endif // NS3_LOG_ENABLE
2055 if ((lt == OLSR_SYM_LINK && nt == OLSR_NOT_NEIGH) ||
2056 (nt != OLSR_SYM_NEIGH && nt != OLSR_MPR_NEIGH
2057 && nt != OLSR_NOT_NEIGH))
2059 NS_LOG_LOGIC (
"HELLO link code is invalid => IGNORING");
2063 for (std::vector<Ipv4Address>::const_iterator neighIfaceAddr =
2064 linkMessage->neighborInterfaceAddresses.begin ();
2065 neighIfaceAddr != linkMessage->neighborInterfaceAddresses.end ();
2069 if (*neighIfaceAddr == receiverIface)
2071 if (lt == OLSR_LOST_LINK)
2074 link_tuple->symTime = now -
Seconds (1);
2077 else if (lt == OLSR_SYM_LINK || lt == OLSR_ASYM_LINK)
2079 NS_LOG_DEBUG (*link_tuple <<
": link is SYM or ASYM => should become SYM now"
2080 " (symTime being increased to " << now + msg.GetVTime ());
2081 link_tuple->symTime = now + msg.GetVTime ();
2082 link_tuple->time = link_tuple->symTime + OLSR_NEIGHB_HOLD_TIME;
2093 NS_LOG_DEBUG (
" \\-> *neighIfaceAddr (" << *neighIfaceAddr
2094 <<
" != receiverIface (" << receiverIface <<
") => IGNORING!");
2097 NS_LOG_DEBUG (
"Link tuple updated: " <<
int (updated));
2099 link_tuple->time = std::max (link_tuple->time, link_tuple->asymTime);
2107 if (created && link_tuple != NULL)
2109 LinkTupleAdded (*link_tuple, hello.willingness);
2112 link_tuple->neighborIfaceAddr));
2115 <<
": LinkSensing END");
2126 if (nb_tuple != NULL)
2142 NS_LOG_DEBUG (
"Olsr node " << m_mainAddress <<
": PopulateTwoHopNeighborSet BEGIN");
2144 for (LinkSet::const_iterator link_tuple =
m_state.GetLinks ().begin ();
2145 link_tuple !=
m_state.GetLinks ().end (); link_tuple++)
2147 NS_LOG_LOGIC (
"Looking at link tuple: " << *link_tuple);
2148 if (
GetMainAddress (link_tuple->neighborIfaceAddr) != msg.GetOriginatorAddress ())
2151 "GetMainAddress (link_tuple->neighborIfaceAddr) != msg.GetOriginatorAddress ()");
2152 NS_LOG_LOGIC (
"(GetMainAddress(" << link_tuple->neighborIfaceAddr <<
"): "
2154 <<
"; msg.GetOriginatorAddress (): " << msg.GetOriginatorAddress ());
2158 if (link_tuple->symTime < now)
2164 typedef std::vector<olsr::MessageHeader::Hello::LinkMessage> LinkMessageVec;
2165 for (LinkMessageVec::const_iterator linkMessage = hello.linkMessages.begin ();
2166 linkMessage != hello.linkMessages.end (); linkMessage++)
2168 int neighborType = (linkMessage->linkCode >> 2) & 0x3;
2169 #ifdef NS3_LOG_ENABLE
2170 const char *neighborTypeNames[3] = {
"NOT_NEIGH",
"SYM_NEIGH",
"MPR_NEIGH" };
2171 const char *neighborTypeName = ((neighborType < 3) ?
2172 neighborTypeNames[neighborType]
2173 :
"(invalid value)");
2174 NS_LOG_DEBUG (
"Looking at Link Message from HELLO message: neighborType="
2175 << neighborType <<
" (" << neighborTypeName <<
")");
2176 #endif // NS3_LOG_ENABLE
2178 for (std::vector<Ipv4Address>::const_iterator nb2hop_addr_iter =
2179 linkMessage->neighborInterfaceAddresses.begin ();
2180 nb2hop_addr_iter != linkMessage->neighborInterfaceAddresses.end ();
2184 NS_LOG_DEBUG (
"Looking at 2-hop neighbor address from HELLO message: "
2185 << *nb2hop_addr_iter
2186 <<
" (main address is " << nb2hop_addr <<
")");
2187 if (neighborType == OLSR_SYM_NEIGH || neighborType == OLSR_MPR_NEIGH)
2192 if (nb2hop_addr == m_mainAddress)
2194 NS_LOG_LOGIC (
"Ignoring 2-hop neighbor (it is the node itself)");
2200 m_state.FindTwoHopNeighborTuple (msg.GetOriginatorAddress (), nb2hop_addr);
2202 << (nb2hop_tuple ?
" (refreshing existing entry)" :
""));
2203 if (nb2hop_tuple == NULL)
2221 else if (neighborType == OLSR_NOT_NEIGH)
2228 NS_LOG_LOGIC (
"2-hop neighbor is NOT_NEIGH => deleting matching 2-hop neighbor state");
2229 m_state.EraseTwoHopNeighborTuples (msg.GetOriginatorAddress (), nb2hop_addr);
2233 NS_LOG_LOGIC (
"*** WARNING *** Ignoring link message (inside HELLO) with bad"
2234 " neighbor type value: " << neighborType);
2240 NS_LOG_DEBUG (
"Olsr node " << m_mainAddress <<
": PopulateTwoHopNeighborSet END");
2256 typedef std::vector<olsr::MessageHeader::Hello::LinkMessage> LinkMessageVec;
2257 for (LinkMessageVec::const_iterator linkMessage = hello.linkMessages.begin ();
2258 linkMessage != hello.linkMessages.end ();
2261 int nt = linkMessage->linkCode >> 2;
2262 if (nt == OLSR_MPR_NEIGH)
2264 NS_LOG_DEBUG (
"Processing a link message with neighbor type MPR_NEIGH");
2266 for (std::vector<Ipv4Address>::const_iterator nb_iface_addr =
2267 linkMessage->neighborInterfaceAddresses.begin ();
2268 nb_iface_addr != linkMessage->neighborInterfaceAddresses.end ();
2273 NS_LOG_DEBUG (
"Adding entry to mpr selector set for neighbor " << *nb_iface_addr);
2277 m_state.FindMprSelectorTuple (msg.GetOriginatorAddress ());
2278 if (existing_mprsel_tuple == NULL)
2282 mprsel_tuple.
mainAddr = msg.GetOriginatorAddress ();
2300 NS_LOG_DEBUG (
"Computed MPR selector set for node " << m_mainAddress <<
": " <<
m_state.PrintMprSelectorSet ());
2315 struct hdr_ip* ih = HDR_IP (p);
2316 struct hdr_cmn* ch = HDR_CMN (p);
2318 debug (
"%f: Node %d MAC Layer detects a breakage on link to %d\n",
2320 OLSR::node_id (ra_addr ()),
2321 OLSR::node_id (ch->next_hop ()));
2323 if ((u_int32_t)ih->daddr () == IP_BROADCAST) {
2324 drop (p, DROP_RTR_MAC_CALLBACK);
2328 OLSR_link_tuple* link_tuple = state_.find_link_tuple (ch->next_hop ());
2329 if (link_tuple != NULL) {
2330 link_tuple->lost_time () = now + OLSR_NEIGHB_HOLD_TIME;
2331 link_tuple->time () = now + OLSR_NEIGHB_HOLD_TIME;
2332 nb_loss (link_tuple);
2334 drop (p, DROP_RTR_MAC_CALLBACK);
2352 <<
"s: OLSR Node " << m_mainAddress
2375 m_state.InsertDuplicateTuple (tuple);
2391 m_state.EraseDuplicateTuple (tuple);
2395 RoutingProtocol::LinkTupleAdded (
const LinkTuple &tuple, uint8_t willingness)
2404 nb_tuple.status = NeighborTuple::STATUS_SYM;
2408 nb_tuple.status = NeighborTuple::STATUS_NOT_SYM;
2423 <<
"s: OLSR Node " << m_mainAddress
2424 <<
" LinkTuple " << tuple <<
" REMOVED.");
2426 m_state.EraseLinkTuple (tuple);
2443 <<
"s: OLSR Node " << m_mainAddress
2444 <<
" LinkTuple " << tuple <<
" UPDATED.");
2449 if (nb_tuple == NULL)
2451 LinkTupleAdded (tuple, willingness);
2455 if (nb_tuple != NULL)
2457 #ifdef NS3_LOG_ENABLE
2458 int statusBefore = nb_tuple->status;
2459 #endif // NS3_LOG_ENABLE
2461 bool hasSymmetricLink =
false;
2463 const LinkSet &linkSet =
m_state.GetLinks ();
2464 for (LinkSet::const_iterator it = linkSet.begin ();
2465 it != linkSet.end (); it++)
2471 hasSymmetricLink =
true;
2476 if (hasSymmetricLink)
2478 nb_tuple->status = NeighborTuple::STATUS_SYM;
2479 NS_LOG_DEBUG (*nb_tuple <<
"->status = STATUS_SYM; changed:"
2480 <<
int (statusBefore != nb_tuple->status));
2484 nb_tuple->status = NeighborTuple::STATUS_NOT_SYM;
2485 NS_LOG_DEBUG (*nb_tuple <<
"->status = STATUS_NOT_SYM; changed:"
2486 <<
int (statusBefore != nb_tuple->status));
2491 NS_LOG_WARN (
"ERROR! Wanted to update a NeighborTuple but none was found!");
2509 m_state.InsertNeighborTuple (tuple);
2527 m_state.EraseNeighborTuple (tuple);
2545 m_state.InsertTwoHopNeighborTuple (tuple);
2562 m_state.EraseTwoHopNeighborTuple (tuple);
2566 RoutingProtocol::IncrementAnsn ()
2586 m_state.InsertMprSelectorTuple (tuple);
2605 m_state.EraseMprSelectorTuple (tuple);
2624 m_state.InsertTopologyTuple (tuple);
2642 m_state.EraseTopologyTuple (tuple);
2659 m_state.InsertIfaceAssocTuple (tuple);
2676 m_state.EraseIfaceAssocTuple (tuple);
2687 m_state.InsertAssociationTuple (tuple);
2698 m_state.EraseAssociationTuple (tuple);
2735 if (
m_state.GetMprSelectors ().size () > 0)
2741 NS_LOG_DEBUG (
"Not sending any TC, no one selected me as MPR.");
2763 if (
m_state.GetAssociations ().size () > 0)
2769 NS_LOG_DEBUG (
"Not sending any HNA, no associations to advertise.");
2785 m_state.FindDuplicateTuple (address, sequenceNumber);
2798 address, sequenceNumber));
2824 if (tuple->
time < now)
2828 else if (tuple->
symTime < now)
2830 if (m_linkTupleTimerFirstTime)
2831 m_linkTupleTimerFirstTime =
false;
2837 neighborIfaceAddr));
2843 neighborIfaceAddr));
2858 tuple =
m_state.FindTwoHopNeighborTuple (neighborMainAddr, twoHopNeighborAddr);
2871 this, neighborMainAddr, twoHopNeighborAddr));
2972 this, gatewayAddr, networkAddr, netmask));
3007 std::map<Ipv4Address, RoutingTableEntry>::const_iterator it =
3012 outEntry = it->second;
3056 if (!foundSendEntry)
3060 uint32_t interfaceIdx = entry2.
interface;
3061 if (oif && m_ipv4->GetInterfaceForDevice (oif) !=
static_cast<int> (interfaceIdx))
3068 <<
" Route interface " << interfaceIdx
3069 <<
" does not match requested output interface "
3070 << m_ipv4->GetInterfaceForDevice (oif));
3071 sockerr = Socket::ERROR_NOROUTETOHOST;
3074 rtentry = Create<Ipv4Route> ();
3080 uint32_t numOifAddresses = m_ipv4->GetNAddresses (interfaceIdx);
3083 if (numOifAddresses == 1) {
3084 ifAddr = m_ipv4->GetAddress (interfaceIdx, 0);
3086 NS_FATAL_ERROR (
"XXX Not implemented yet: IP aliasing and OLSR");
3088 rtentry->SetSource (ifAddr.GetLocal ());
3089 rtentry->SetGateway (entry2.
nextAddr);
3090 rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIdx));
3091 sockerr = Socket::ERROR_NOTERROR;
3094 <<
" --> nextHop=" << entry2.
nextAddr
3096 NS_LOG_DEBUG (
"Found route to " << rtentry->GetDestination () <<
" via nh " << rtentry->GetGateway () <<
" with source addr " << rtentry->GetSource () <<
" and output dev " << rtentry->GetOutputDevice ());
3101 rtentry = m_hnaRoutingTable->RouteOutput (p, header, oif, sockerr);
3106 NS_LOG_DEBUG (
"Found route to " << rtentry->GetDestination () <<
" via nh " << rtentry->GetGateway () <<
" with source addr " << rtentry->GetSource () <<
" and output dev " << rtentry->GetOutputDevice ());
3114 <<
" No route to host");
3115 sockerr = Socket::ERROR_NOROUTETOHOST;
3137 NS_ASSERT (m_ipv4->GetInterfaceForDevice (idev) >= 0);
3138 uint32_t iif = m_ipv4->GetInterfaceForDevice (idev);
3139 if (m_ipv4->IsDestinationAddress (dst, iif))
3144 lcb (p, header, iif);
3164 if (!foundSendEntry)
3166 rtentry = Create<Ipv4Route> ();
3168 uint32_t interfaceIdx = entry2.
interface;
3173 uint32_t numOifAddresses = m_ipv4->GetNAddresses (interfaceIdx);
3176 if (numOifAddresses == 1) {
3177 ifAddr = m_ipv4->GetAddress (interfaceIdx, 0);
3179 NS_FATAL_ERROR (
"XXX Not implemented yet: IP aliasing and OLSR");
3181 rtentry->
SetSource (ifAddr.GetLocal ());
3187 <<
" --> nextHop=" << entry2.
nextAddr
3190 ucb (rtentry, p, header);
3195 if(m_hnaRoutingTable->RouteInput (p, header, idev, ucb, mcb, lcb, ecb))
3202 #ifdef NS3_LOG_ENABLE
3205 <<
" --> NOT FOUND; ** Dumping routing table...");
3207 for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator iter =
m_table.begin ();
3208 iter !=
m_table.end (); iter++)
3210 NS_LOG_DEBUG (
"dest=" << iter->first <<
" --> next=" << iter->second.nextAddr
3211 <<
" via interface " << iter->second.interface);
3215 #endif // NS3_LOG_ENABLE
3251 NS_LOG_FUNCTION (
this << dest << next << interface << distance << m_mainAddress);
3270 NS_LOG_FUNCTION (
this << dest << next << interfaceAddress << distance << m_mainAddress);
3276 for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
3278 for (uint32_t j = 0; j < m_ipv4->GetNAddresses (i); j++)
3280 if (m_ipv4->GetAddress (i,j).GetLocal () == interfaceAddress)
3282 AddEntry (dest, next, i, distance);
3288 AddEntry (dest, next, 0, distance);
3292 std::vector<RoutingTableEntry>
3295 std::vector<RoutingTableEntry> retval;
3296 for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator iter =
m_table.begin ();
3297 iter !=
m_table.end (); iter++)
3299 retval.push_back (iter->second);
3316 m_socketAddresses.begin (); j != m_socketAddresses.end (); ++j)
3319 if (a == iface.GetLocal ())
3330 #ifdef NS3_LOG_ENABLE
3332 NS_LOG_DEBUG (
"Dumping for node with main address " << m_mainAddress);
3334 for (NeighborSet::const_iterator iter =
m_state.GetNeighbors ().begin ();
3335 iter !=
m_state.GetNeighbors ().end (); iter++)
3340 for (TwoHopNeighborSet::const_iterator iter =
m_state.GetTwoHopNeighbors ().begin ();
3341 iter !=
m_state.GetTwoHopNeighbors ().end (); iter++)
3343 if (now < iter->expirationTime)
3349 for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator iter =
m_table.begin (); iter !=
m_table.end (); iter++)
3351 NS_LOG_DEBUG (
" dest=" << iter->first <<
" --> next=" << iter->second.nextAddr <<
" via interface " << iter->second.interface);
3354 #endif //NS3_LOG_ENABLE
Ipv4Address networkAddr
Network Address of network reachable through gatewayAddr.
An OLSR's routing table entry.
uint32_t distance
Distance in hops to the destination.
void HelloTimerExpire()
Sends a HELLO message and reschedules the HELLO timer.
void AddTopologyTuple(const TopologyTuple &tuple)
Adds a topology tuple to the Topology Set.
Ipv4Address GetIpv4(void) const
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
void IfaceAssocTupleTimerExpire(Ipv4Address ifaceAddr)
Removes tuple_ if expired. Else timer is rescheduled to expire at tuple_->time(). ...
uint16_t sequenceNumber
Sequence number.
void RemoveMprSelectorTuple(const MprSelectorTuple &tuple)
Removes an MPR selector tuple from the MPR Selector Set.
uint16_t GetPacketSequenceNumber()
Increments packet sequence number and returns the new value.
Time m_midInterval
MID messages' emission interval.
void Clear()
Clears the routing table and frees the memory assigned to each one of its entries.
uint16_t m_messageSequenceNumber
Messages sequence number counter.
virtual bool SetAllowBroadcast(bool allowBroadcast)=0
Configure whether broadcast datagram transmissions are allowed.
Ipv4Address destAddr
Address of the destination node.
a class to represent an Ipv4 address mask
void HnaTimerExpire()
Sends an HNA message (if the node has associated hosts/networks) and reschedules the HNA timer...
void LinkTupleUpdated(const LinkTuple &tuple, uint8_t willingness)
This function is invoked when a link tuple is updated. Its aim is to also update the corresponding ne...
void LinkSensing(const olsr::MessageHeader &msg, const olsr::MessageHeader::Hello &hello, const Ipv4Address &receiverIface, const Ipv4Address &sender_iface)
Updates Link Set according to a new received HELLO message (following RFC 3626 specification). Neighbor Set is also updated if needed.
uint16_t m_ansn
Advertised Neighbor Set sequence number.
#define NS_ASSERT(condition)
Ipv4Address GetDestNetwork(void) const
#define NS_LOG_COMPONENT_DEFINE(name)
void AddEntry(const Ipv4Address &dest, const Ipv4Address &next, uint32_t interface, uint32_t distance)
Adds a new entry into the routing table.
uint32_t GetSize(void) const
virtual void NotifyInterfaceUp(uint32_t interface)
void SendTc()
Creates a new OLSR TC message which is buffered for being sent later on.
int64_t AssignStreams(int64_t stream)
virtual void DoDispose(void)
void DupTupleTimerExpire(Ipv4Address address, uint16_t sequenceNumber)
Removes tuple if expired. Else timer is rescheduled to expire at tuple.expirationTime.
Time time
Time at which this tuple expires and must be removed.
void AddHostNetworkAssociation(Ipv4Address networkAddr, Ipv4Mask netmask)
Inject Association to be sent in HNA message.
#define NS_LOG_FUNCTION_NOARGS()
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Time expirationTime
Time at which this tuple expires and must be removed.
void LinkTupleTimerExpire(Ipv4Address neighborIfaceAddr)
Removes tuple_ if expired. Else if symmetric time has expired then it is assumed a neighbor loss and ...
void SetMainInterface(uint32_t interface)
Set the OLSR main address to the first address on the indicated interface.
Ipv4Mask netmask
Netmask of network reachable through gatewayAddr.
void Nb2hopTupleTimerExpire(Ipv4Address neighborMainAddr, Ipv4Address twoHopNeighborAddr)
Removes tuple_ if expired. Else the timer is rescheduled to expire at tuple_->time().
void RemoveAssociationTuple(const AssociationTuple &tuple)
Removes a host network association tuple from the Association Set.
#define NS_FATAL_ERROR(msg)
fatal error handling
void ProcessTc(const olsr::MessageHeader &msg, const Ipv4Address &senderIface)
Processes a TC message following RFC 3626 specification.
Ipv4Address GetSubnetDirectedBroadcast(Ipv4Mask const &mask) const
Generate subnet-directed broadcast address corresponding to mask.
a polymophic address class
bool IsRunning(void) const
void MprSelTupleTimerExpire(Ipv4Address mainAddr)
Removes tuple_ if expired. Else the timer is rescheduled to expire at tuple_->time().
void SetSource(Ipv4Address src)
std::map< Ipv4Address, RoutingTableEntry > m_table
Data structure for the routing table.
void RemoveIfaceAssocTuple(const IfaceAssocTuple &tuple)
Removes an interface association tuple from the Interface Association Set.
uint32_t GetInterface(void) const
double GetSeconds(void) const
void AddAtEnd(Ptr< const Packet > packet)
Ipv4Address lastAddr
Main address of a node which is a neighbor of the destination.
uint8_t m_willingness
Willingness for forwarding packets on behalf of other nodes.
void PopulateNeighborSet(const olsr::MessageHeader &msg, const olsr::MessageHeader::Hello &hello)
Updates the Neighbor Set according to the information contained in a new received HELLO message (foll...
Time expirationTime
Time at which this tuple expires and must be removed.
void RemoveHostNetworkAssociation(Ipv4Address networkAddr, Ipv4Mask netmask)
Removes Association sent in HNA message.
Ipv4Address mainAddr
Main address of the node.
void AddIfaceAssocTuple(const IfaceAssocTuple &tuple)
Adds an interface association tuple to the Interface Association Set.
void QueueMessage(const olsr::MessageHeader &message, Time delay)
Enques an OLSR message which will be sent with a delay of (0, delay].
Ipv4Address mainAddr
Main address of a node which have selected this node as a MPR.
void SetGateway(Ipv4Address gw)
void ProcessHello(const olsr::MessageHeader &msg, const Ipv4Address &receiverIface, const Ipv4Address &senderIface)
Processes a HELLO message following RFC 3626 specification.
void AddAssociationTuple(const AssociationTuple &tuple)
Adds a host network association tuple to the Association Set.
Time expirationTime
Time at which this tuple expires and must be removed.
virtual bool RouteInput(Ptr< const Packet > p, const Ipv4Header &header, Ptr< const NetDevice > idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb)
Route an input packet (to be forwarded or locally delivered)
void MprComputation()
Computates MPR set of a node following RFC 3626 hints.
void RemoveDuplicateTuple(const DuplicateTuple &tuple)
Removes a duplicate tuple from the Duplicate Set.
Time symTime
The link is considered bidirectional until this time.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
void CoverTwoHopNeighbors(Ipv4Address neighborMainAddr, TwoHopNeighborSet &N2)
Remove all covered 2-hop neighbors from N2 set. This is a helper function used by MprComputation algo...
Time m_helloInterval
HELLO messages' emission interval.
void SetDelay(const Time &delay)
#define NS_LOG_LOGIC(msg)
void SetRoutingTableAssociation(Ptr< Ipv4StaticRouting > routingTable)
Inject Associations from an Ipv4StaticRouting instance.
Ipv4Address destAddr
Main address of the destination.
void SetMprSet(MprSet mprSet)
MprSet is set by routing protocol after MprCompute.
void TopologyTupleTimerExpire(Ipv4Address destAddr, Ipv4Address lastAddr)
Removes tuple_ if expired. Else the timer is rescheduled to expire at tuple_->time().
Time m_tcInterval
TC messages' emission interval.
void AddTwoHopNeighborTuple(const TwoHopNeighborTuple &tuple)
Adds a 2-hop neighbor tuple to the 2-hop Neighbor Set.
void AssociationTupleTimerExpire(Ipv4Address gatewayAddr, Ipv4Address networkAddr, Ipv4Mask netmask)
Removes tuple_ if expired. Else timer is rescheduled to expire at tuple_->time(). ...
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream) const
Print the Routing Table entries.
void NeighborLoss(const LinkTuple &tuple)
Performs all actions needed when a neighbor loss occurs.
void RemoveTopologyTuple(const TopologyTuple &tuple)
Removes a topology tuple from the Topology Set.
uint8_t willingness
A value between 0 and 7 specifying the node's willingness to carry traffic on behalf of other nodes...
Time expirationTime
Time at which this tuple expires and must be removed.
void SendMid()
Creates a new OLSR MID message which is buffered for being sent later on.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
static InetSocketAddress ConvertFrom(const Address &address)
Ipv4Address neighborMainAddr
Main address of a neighbor node.
Ipv4Address twoHopNeighborAddr
Main address of a 2-hop neighbor with a symmetric link to nb_main_addr.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
void MidTimerExpire()
Sends a MID message (if the node has more than one interface) and resets the MID timer.
void AddNeighborTuple(const NeighborTuple &tuple)
Adds a neighbor tuple to the Neighbor Set.
void SendHello()
Creates a new OLSR HELLO message which is buffered for being sent later on.
void RemoveLinkTuple(const LinkTuple &tuple)
Removes a link tuple from the Link Set.
bool UsesNonOlsrOutgoingInterface(const Ipv4RoutingTableEntry &route)
Tests whether or not the specified route uses a non-OLSR outgoing interface. Returns true if the outg...
bool Lookup(const Ipv4Address &dest, RoutingTableEntry &outEntry) const
Looks up an entry for the specified destination address.
Ipv4Address localIfaceAddr
Interface address of the local node.
void SetOutputDevice(Ptr< NetDevice > outputDevice)
Time time
Time at which this tuple expires and must be removed.
virtual void NotifyInterfaceDown(uint32_t interface)
uint16_t m_packetSequenceNumber
Packets sequence number counter.
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
void PopulateTwoHopNeighborSet(const olsr::MessageHeader &msg, const olsr::MessageHeader::Hello &hello)
Updates the 2-hop Neighbor Set according to the information contained in a new received HELLO message...
Ipv4Address GetMainAddress(Ipv4Address iface_addr) const
Gets the main address associated with a given interface address.
void RoutingTableComputation()
Creates the routing table of the node following RFC 3626 hints.
void RemoveTwoHopNeighborTuple(const TwoHopNeighborTuple &tuple)
Removes a 2-hop neighbor tuple from the 2-hop Neighbor Set.
void RemoveEntry(const Ipv4Address &dest)
Deletes the entry whose destination address is given.
void ForwardDefault(olsr::MessageHeader olsrMessage, DuplicateTuple *duplicated, const Ipv4Address &localIface, const Ipv4Address &senderAddress)
OLSR's default forwarding algorithm.
void ProcessHna(const olsr::MessageHeader &msg, const Ipv4Address &senderIface)
Processes a HNA message following RFC 3626 specification.
virtual Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr)
Query routing cache for an existing route, for an outbound packet.
int Degree(NeighborTuple const &tuple)
This auxiliary function (defined in RFC 3626) is used for calculating the MPR Set.
uint32_t interface
Interface index.
Ipv4 addresses are stored in host order in this class.
bool IsMyOwnAddress(const Ipv4Address &a) const
Check that address is one of my interfaces.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
uint32_t GetId(void) const
a class to store IPv4 address information on an interface
virtual void SetIpv4(Ptr< Ipv4 > ipv4)
void PopulateMprSelectorSet(const olsr::MessageHeader &msg, const olsr::MessageHeader::Hello &hello)
Updates the MPR Selector Set according to the information contained in a new received HELLO message (...
void SendQueuedMessages()
Creates as many OLSR packets as needed in order to send all buffered OLSR messages.
Ipv4Address ifaceAddr
Interface address of a node.
Ipv4Address nextAddr
Address of the next hop.
#define NS_LOG_DEBUG(msg)
void SendHna()
Creates a new OLSR HNA message which is buffered for being sent later on.
void Track(EventId event)
Tracks a new event.
static std::string FindName(Ptr< Object > object)
Time m_hnaInterval
HNA messages' emission interval.
uint16_t GetPort(void) const
Ipv4Address neighborMainAddr
Main address of a neighbor.
virtual void DoInitialize(void)
std::vector< RoutingTableEntry > GetRoutingTableEntries() const
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)=0
Read a single packet from the socket and retrieve the sender address.
void AddDuplicateTuple(const DuplicateTuple &tuple)
Adds a duplicate tuple to the Duplicate Set.
void TcTimerExpire()
Sends a TC message (if there exists any MPR selector) and reschedules the TC timer.
Ipv4Address address
Originator address of the message.
void RemoveNeighborTuple(const NeighborTuple &tuple)
Removes a neighbor tuple from the Neighbor Set.
uint16_t GetMessageSequenceNumber()
Increments message sequence number and returns the new value.
Ipv4Address gatewayAddr
Main address of the gateway.
OlsrState m_state
Internal state with all needed data structs.
void AddMprSelectorTuple(const MprSelectorTuple &tuple)
Adds an MPR selector tuple to the MPR Selector Set.
Ipv4Address neighborIfaceAddr
Interface address of the neighbor node.
Ipv4Mask GetDestNetworkMask(void) const
An Interface Association Tuple.
bool retransmitted
Indicates whether the message has been retransmitted or not.
The type "list of interface addresses".
virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
std::ostream * GetStream(void)
uint16_t sequenceNumber
Message sequence number.
void AddHeader(const Header &header)
olsr::MessageList m_queuedMessages
A list of pending messages which are buffered awaiting for being sent.
Ptr< UniformRandomVariable > m_uniformRandomVariable
Provides uniform random variables.
void SetDestination(Ipv4Address dest)
bool FindSendEntry(const RoutingTableEntry &entry, RoutingTableEntry &outEntry) const
Finds the appropiate entry which must be used in order to forward a data packet to a next hop (given ...
Time expirationTime
Time at which this tuple expires and must be removed.
std::vector< Ipv4Address > ifaceList
List of interfaces which the message has been received on.
void ProcessMid(const olsr::MessageHeader &msg, const Ipv4Address &senderIface)
Processes a MID message following RFC 3626 specification.