31 #define NS_LOG_APPEND_CONTEXT \ 32 if (GetObject<Node> ()) { std::clog << "[node " << GetObject<Node> ()->GetId () << "] "; } 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" 50 #include "ns3/ipv4-packet-info-tag.h" 60 #define DELAY(time) (((time) < (Simulator::Now ())) ? Seconds (0.000001) : \ 61 (time - Simulator::Now () + Seconds (0.000001))) 70 #define OLSR_REFRESH_INTERVAL m_helloInterval 76 #define OLSR_NEIGHB_HOLD_TIME Time (3 * OLSR_REFRESH_INTERVAL) 77 #define OLSR_TOP_HOLD_TIME Time (3 * m_tcInterval) 79 #define OLSR_DUP_HOLD_TIME Seconds (30) 81 #define OLSR_MID_HOLD_TIME Time (3 * m_midInterval) 83 #define OLSR_HNA_HOLD_TIME Time (3 * m_hnaInterval) 89 #define OLSR_UNSPEC_LINK 0 90 #define OLSR_ASYM_LINK 1 92 #define OLSR_SYM_LINK 2 94 #define OLSR_LOST_LINK 3 100 #define OLSR_NOT_NEIGH 0 101 #define OLSR_SYM_NEIGH 1 103 #define OLSR_MPR_NEIGH 2 110 #define OLSR_WILL_NEVER 0 111 #define OLSR_WILL_LOW 1 113 #define OLSR_WILL_DEFAULT 3 115 #define OLSR_WILL_HIGH 6 117 #define OLSR_WILL_ALWAYS 7 124 #define OLSR_MAXJITTER (m_helloInterval.GetSeconds () / 4) 125 #define OLSR_MAX_SEQ_NUM 65535 127 #define JITTER (Seconds (m_uniformRandomVariable->GetValue (0, OLSR_MAXJITTER))) 132 #define OLSR_MAX_MSGS 64 135 #define OLSR_MAX_HELLOS 12 138 #define OLSR_MAX_ADDRS 64 157 static TypeId tid =
TypeId (
"ns3::olsr::RoutingProtocol")
159 .SetGroupName (
"Olsr")
161 .AddAttribute (
"HelloInterval",
"HELLO messages emission interval.",
165 .AddAttribute (
"TcInterval",
"TC messages emission interval.",
169 .AddAttribute (
"MidInterval",
"MID messages emission interval. Normally it is equal to TcInterval.",
173 .AddAttribute (
"HnaInterval",
"HNA messages emission interval. Normally it is equal to TcInterval.",
177 .AddAttribute (
"Willingness",
"Willingness of a node to carry and forward traffic for other nodes.",
185 .AddTraceSource (
"Rx",
"Receive OLSR packet.",
187 "ns3::olsr::RoutingProtocol::PacketTxRxTracedCallback")
188 .AddTraceSource (
"Tx",
"Send OLSR packet.",
190 "ns3::olsr::RoutingProtocol::PacketTxRxTracedCallback")
191 .AddTraceSource (
"RoutingTableChanged",
"The OLSR routing table has changed.",
193 "ns3::olsr::RoutingProtocol::TableChangeTracedCallback")
200 : m_routingTableAssociation (0),
202 m_helloTimer (
Timer::CANCEL_ON_DESTROY),
203 m_tcTimer (
Timer::CANCEL_ON_DESTROY),
204 m_midTimer (
Timer::CANCEL_ON_DESTROY),
205 m_hnaTimer (
Timer::CANCEL_ON_DESTROY),
206 m_queuedMessagesTimer (
Timer::CANCEL_ON_DESTROY)
261 iter->first->
Close ();
274 *os <<
"Node: " <<
m_ipv4->GetObject<
Node> ()->GetId ()
275 <<
", Time: " <<
Now ().
As (unit)
276 <<
", Local time: " << GetObject<Node> ()->GetLocalTime ().As (unit)
277 <<
", OLSR Routing table" << std::endl;
279 *os <<
"Destination\t\tNextHop\t\tInterface\tDistance\n";
281 for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator iter =
m_table.begin ();
282 iter !=
m_table.end (); iter++)
284 *os << iter->first <<
"\t\t";
285 *os << iter->second.nextAddr <<
"\t\t";
292 *os << iter->second.interface <<
"\t\t";
294 *os << iter->second.distance <<
"\t";
301 *os <<
" HNA Routing Table: ";
306 *os <<
" HNA Routing Table: empty" << std::endl;
315 for (uint32_t i = 0; i <
m_ipv4->GetNInterfaces (); i++)
319 if (addr != loopback)
333 bool canRunOlsr =
false;
334 for (uint32_t i = 0; i <
m_ipv4->GetNInterfaces (); i++)
337 if (addr == loopback)
383 if (socket->
Bind (inetAddr))
421 receivedPacket = socket->
RecvFrom (sourceAddress);
426 NS_ABORT_MSG (
"No incoming interface on OLSR message, aborting.");
428 uint32_t incomingIf = interfaceInfo.
GetRecvIf ();
429 Ptr<Node> node = this->GetObject<Node> ();
431 uint32_t recvInterfaceIndex =
m_ipv4->GetInterfaceForDevice (dev);
442 int32_t interfaceForAddress =
m_ipv4->GetInterfaceForAddress (senderIfaceAddr);
443 if (interfaceForAddress != -1)
449 Ipv4Address receiverIfaceAddr =
m_ipv4->GetAddress (recvInterfaceIndex, 0).GetLocal ();
452 << senderIfaceAddr <<
" to " << receiverIfaceAddr);
461 packet->RemoveHeader (olsrPacketHeader);
470 if (packet->RemoveHeader (messageHeader) == 0)
481 messages.push_back (messageHeader);
486 for (MessageList::const_iterator messageIter = messages.begin ();
487 messageIter != messages.end (); messageIter++)
502 bool do_forwarding =
true;
519 if (duplicated == NULL)
527 ProcessHello (messageHeader, receiverIfaceAddr, senderIfaceAddr);
534 ProcessTc (messageHeader, senderIfaceAddr);
558 NS_LOG_DEBUG (
"OLSR message is duplicated, not reading it.");
562 for (std::vector<Ipv4Address>::const_iterator it = duplicated->
ifaceList.begin ();
563 it != duplicated->
ifaceList.end (); it++)
565 if (*it == receiverIfaceAddr)
567 do_forwarding =
false;
581 receiverIfaceAddr, inetSourceAddr.
GetIpv4 ());
608 if (nb_tuple == NULL)
629 std::set<Ipv4Address> toRemove;
630 for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin (); twoHopNeigh != N2.end (); twoHopNeigh++)
632 if (twoHopNeigh->neighborMainAddr == neighborMainAddr)
634 toRemove.insert (twoHopNeigh->twoHopNeighborAddr);
638 for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin (); twoHopNeigh != N2.end (); )
640 if (toRemove.find (twoHopNeigh->twoHopNeighborAddr) != toRemove.end ())
642 twoHopNeigh = N2.erase (twoHopNeigh);
669 N.push_back (*neighbor);
693 for (NeighborSet::const_iterator neigh = N.begin ();
694 neigh != N.end (); neigh++)
696 if (neigh->neighborMainAddr == twoHopNeigh->neighborMainAddr)
718 for (NeighborSet::const_iterator neigh = N.begin ();
719 neigh != N.end (); neigh++)
721 if (neigh->neighborMainAddr == twoHopNeigh->twoHopNeighborAddr)
730 N2.push_back (*twoHopNeigh);
734 #ifdef NS3_LOG_ENABLE 736 std::ostringstream os;
738 for (TwoHopNeighborSet::const_iterator iter = N2.begin ();
739 iter != N2.end (); iter++)
741 TwoHopNeighborSet::const_iterator next = iter;
743 os << iter->neighborMainAddr <<
"->" << iter->twoHopNeighborAddr;
744 if (next != N2.end ())
752 #endif //NS3_LOG_ENABLE 756 for (NeighborSet::const_iterator neighbor = N.begin (); neighbor != N.end (); neighbor++)
760 mprSet.insert (neighbor->neighborMainAddr);
772 std::set<Ipv4Address> coveredTwoHopNeighbors;
773 for (TwoHopNeighborSet::const_iterator twoHopNeigh = N2.begin (); twoHopNeigh != N2.end (); twoHopNeigh++)
777 for (TwoHopNeighborSet::const_iterator otherTwoHopNeigh = N2.begin (); otherTwoHopNeigh != N2.end (); otherTwoHopNeigh++)
779 if (otherTwoHopNeigh->twoHopNeighborAddr == twoHopNeigh->twoHopNeighborAddr
780 && otherTwoHopNeigh->neighborMainAddr != twoHopNeigh->neighborMainAddr)
788 NS_LOG_LOGIC (
"Neighbor " << twoHopNeigh->neighborMainAddr
789 <<
" is the only that can reach 2-hop neigh. " 790 << twoHopNeigh->twoHopNeighborAddr
791 <<
" => select as MPR.");
793 mprSet.insert (twoHopNeigh->neighborMainAddr);
796 for (TwoHopNeighborSet::const_iterator otherTwoHopNeigh = N2.begin ();
797 otherTwoHopNeigh != N2.end (); otherTwoHopNeigh++)
799 if (otherTwoHopNeigh->neighborMainAddr == twoHopNeigh->neighborMainAddr)
801 coveredTwoHopNeighbors.insert (otherTwoHopNeigh->twoHopNeighborAddr);
807 for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin ();
808 twoHopNeigh != N2.end (); )
810 if (coveredTwoHopNeighbors.find (twoHopNeigh->twoHopNeighborAddr) != coveredTwoHopNeighbors.end ())
814 NS_LOG_LOGIC (
"2-hop neigh. " << twoHopNeigh->twoHopNeighborAddr <<
" is already covered by an MPR.");
815 twoHopNeigh = N2.erase (twoHopNeigh);
825 while (N2.begin () != N2.end ())
828 #ifdef NS3_LOG_ENABLE 830 std::ostringstream os;
832 for (TwoHopNeighborSet::const_iterator iter = N2.begin ();
833 iter != N2.end (); iter++)
835 TwoHopNeighborSet::const_iterator next = iter;
837 os << iter->neighborMainAddr <<
"->" << iter->twoHopNeighborAddr;
838 if (next != N2.end ())
846 #endif //NS3_LOG_ENABLE 853 std::map<int, std::vector<const NeighborTuple *> > reachability;
855 for (NeighborSet::iterator it = N.begin (); it != N.end (); it++)
859 for (TwoHopNeighborSet::iterator it2 = N2.begin (); it2 != N2.end (); it2++)
868 reachability[r].push_back (&nb_tuple);
881 for (std::set<int>::iterator it = rs.begin (); it != rs.end (); it++)
888 for (std::vector<const NeighborTuple *>::iterator it2 = reachability[r].begin ();
889 it2 != reachability[r].end (); it2++)
918 mprSet.insert (
max->neighborMainAddr);
920 NS_LOG_LOGIC (N2.size () <<
" 2-hop neighbors left to cover!");
924 #ifdef NS3_LOG_ENABLE 926 std::ostringstream os;
928 for (MprSet::const_iterator iter = mprSet.begin ();
929 iter != mprSet.end (); iter++)
931 MprSet::const_iterator next = iter;
934 if (next != mprSet.end ())
942 #endif //NS3_LOG_ENABLE 967 <<
": RoutingTableComputation begin...");
975 for (NeighborSet::const_iterator it = neighborSet.begin ();
976 it != neighborSet.end (); it++)
979 NS_LOG_DEBUG (
"Looking at neighbor tuple: " << nb_tuple);
982 bool nb_main_addr =
false;
985 for (LinkSet::const_iterator it2 = linkSet.begin ();
986 it2 != linkSet.end (); it2++)
995 <<
" => adding routing table entry to neighbor");
1003 nb_main_addr =
true;
1024 if (!nb_main_addr && lt != NULL)
1026 NS_LOG_LOGIC (
"no R_dest_addr is equal to the main address of the neighbor " 1027 "=> adding additional routing entry");
1042 for (TwoHopNeighborSet::const_iterator it = twoHopNeighbors.begin ();
1043 it != twoHopNeighbors.end (); it++)
1047 NS_LOG_LOGIC (
"Looking at two-hop neighbor tuple: " << nb2hop_tuple);
1052 NS_LOG_LOGIC (
"Two-hop neighbor tuple is also neighbor; skipped.");
1065 bool nb2hopOk =
false;
1066 for (NeighborSet::const_iterator neighbor = neighborSet.begin ();
1067 neighbor != neighborSet.end (); neighbor++)
1078 NS_LOG_LOGIC (
"Two-hop neighbor tuple skipped: 2-hop neighbor " 1081 <<
", which was not found in the Neighbor Set.");
1100 NS_LOG_LOGIC (
"Adding routing entry for two-hop neighbor.");
1108 NS_LOG_LOGIC (
"NOT adding routing entry for two-hop neighbor (" 1110 <<
" not found in the routing table)");
1114 for (uint32_t h = 2;; h++)
1125 for (TopologySet::const_iterator it = topology.begin ();
1126 it != topology.end (); it++)
1129 NS_LOG_LOGIC (
"Looking at topology tuple: " << topology_tuple);
1132 bool have_destAddrEntry =
Lookup (topology_tuple.
destAddr, destAddrEntry);
1133 bool have_lastAddrEntry =
Lookup (topology_tuple.
lastAddr, lastAddrEntry);
1134 if (!have_destAddrEntry && have_lastAddrEntry && lastAddrEntry.
distance == h)
1136 NS_LOG_LOGIC (
"Adding routing table entry based on the topology tuple.");
1155 NS_LOG_LOGIC (
"NOT adding routing table entry based on the topology tuple: " 1156 "have_destAddrEntry=" << have_destAddrEntry
1157 <<
" have_lastAddrEntry=" << have_lastAddrEntry
1158 <<
" lastAddrEntry.distance=" << (
int) lastAddrEntry.
distance 1159 <<
" (h=" << h <<
")");
1175 for (IfaceAssocSet::const_iterator it = ifaceAssocSet.begin ();
1176 it != ifaceAssocSet.end (); it++)
1182 if (have_entry1 && !have_entry2)
1210 for (AssociationSet::const_iterator it = associationSet.begin ();
1211 it != associationSet.end (); it++)
1218 bool goToNextAssociationTuple =
false;
1220 NS_LOG_DEBUG (
"Nb local associations: " << localHnaAssociations.size ());
1221 for (Associations::const_iterator assocIterator = localHnaAssociations.begin ();
1222 assocIterator != localHnaAssociations.end (); assocIterator++)
1224 Association const &localHnaAssoc = *assocIterator;
1227 NS_LOG_DEBUG (
"HNA association received from another GW is part of local HNA associations: no route added for network " 1229 goToNextAssociationTuple =
true;
1232 if (goToNextAssociationTuple)
1240 bool addRoute =
false;
1242 uint32_t routeIndex = 0;
1244 for (routeIndex = 0; routeIndex <
m_hnaRoutingTable->GetNRoutes (); routeIndex++)
1264 if (addRoute && gatewayEntryExists)
1289 LinkSensing (msg, hello, receiverIface, senderIface);
1291 #ifdef NS3_LOG_ENABLE 1295 <<
" ** BEGIN dump Link Set for OLSR Node " <<
m_mainAddress);
1296 for (LinkSet::const_iterator link = links.begin (); link != links.end (); link++)
1304 <<
" ** BEGIN dump Neighbor Set for OLSR Node " <<
m_mainAddress);
1305 for (NeighborSet::const_iterator neighbor = neighbors.begin (); neighbor != neighbors.end (); neighbor++)
1311 #endif // NS3_LOG_ENABLE 1316 #ifdef NS3_LOG_ENABLE 1320 <<
" ** BEGIN dump TwoHopNeighbor Set for OLSR Node " <<
m_mainAddress);
1321 for (TwoHopNeighborSet::const_iterator tuple = twoHopNeighbors.begin ();
1322 tuple != twoHopNeighbors.end (); tuple++)
1328 #endif // NS3_LOG_ENABLE 1344 if (link_tuple == NULL)
1356 if (topologyTuple != NULL)
1369 for (std::vector<Ipv4Address>::const_iterator i = tc.
neighborAddresses.begin ();
1381 if (topologyTuple != NULL)
1409 #ifdef NS3_LOG_ENABLE 1413 <<
" ** BEGIN dump TopologySet for OLSR Node " <<
m_mainAddress);
1414 for (TopologySet::const_iterator tuple = topology.begin ();
1415 tuple != topology.end (); tuple++)
1421 #endif // NS3_LOG_ENABLE 1435 if (linkTuple == NULL)
1438 ": the sender interface of this message is not in the " 1439 "symmetric 1-hop neighborhood of this node," 1440 " the message MUST be discarded.");
1448 bool updated =
false;
1450 for (IfaceAssocSet::iterator tuple = ifaceAssoc.begin ();
1451 tuple != ifaceAssoc.end (); tuple++)
1453 if (tuple->ifaceAddr == *i
1457 tuple->time = now + msg.
GetVTime ();
1479 for (NeighborSet::iterator neighbor = neighbors.begin (); neighbor != neighbors.end (); neighbor++)
1481 neighbor->neighborMainAddr =
GetMainAddress (neighbor->neighborMainAddr);
1485 for (TwoHopNeighborSet::iterator twoHopNeighbor = twoHopNeighbors.begin ();
1486 twoHopNeighbor != twoHopNeighbors.end (); twoHopNeighbor++)
1488 twoHopNeighbor->neighborMainAddr =
GetMainAddress (twoHopNeighbor->neighborMainAddr);
1489 twoHopNeighbor->twoHopNeighborAddr =
GetMainAddress (twoHopNeighbor->twoHopNeighborAddr);
1505 if (link_tuple == NULL)
1513 for (std::vector<olsr::MessageHeader::Hna::Association>::const_iterator it = hna.
associations.begin ();
1564 if (linkTuple == NULL)
1581 bool retransmitted =
false;
1586 if (mprselTuple != NULL)
1593 retransmitted =
true;
1598 if (duplicated != NULL)
1602 duplicated->
ifaceList.push_back (localIface);
1612 newDup.
ifaceList.push_back (localIface);
1661 int numMessages = 0;
1667 for (std::vector<olsr::MessageHeader>::const_iterator message =
m_queuedMessages.begin ();
1674 msglist.push_back (*message);
1681 packet = Create<Packet> ();
1711 std::vector<olsr::MessageHeader::Hello::LinkMessage>
1715 for (LinkSet::const_iterator link_tuple = links.begin ();
1716 link_tuple != links.end (); link_tuple++)
1719 && link_tuple->time >= now))
1724 uint8_t link_type, nb_type = 0xff;
1727 if (link_tuple->symTime >= now)
1731 else if (link_tuple->asymTime >= now)
1744 <<
" to be MPR_NEIGH.");
1753 if (nb_tuple->neighborMainAddr ==
GetMainAddress (link_tuple->neighborIfaceAddr))
1758 <<
" to be SYM_NEIGH.");
1765 <<
" to be NOT_NEIGH.");
1769 NS_FATAL_ERROR (
"There is a neighbor tuple with an unknown status!\n");
1783 linkMessage.
linkCode = (link_type & 0x03) | ((nb_type << 2) & 0x0f);
1785 (link_tuple->neighborIfaceAddr);
1794 linkMessages.push_back (linkMessage);
1797 <<
" (with " <<
int (linkMessages.size ()) <<
" link messages)");
1848 for (uint32_t i = 0; i <
m_ipv4->GetNInterfaces (); i++)
1883 std::vector<olsr::MessageHeader::Hna::Association> &associations = hna.
associations;
1887 for (Associations::const_iterator it = localHnaAssociations.begin ();
1888 it != localHnaAssociations.end (); it++)
1891 associations.push_back (assoc);
1894 if (associations.size () == 0)
1909 for (Associations::const_iterator assocIterator = localHnaAssociations.begin ();
1910 assocIterator != localHnaAssociations.end (); assocIterator++)
1912 Association const &localHnaAssoc = *assocIterator;
1915 NS_LOG_INFO (
"HNA association for network " << networkAddr <<
"/" << netmask <<
" already exists.");
1920 NS_LOG_INFO (
"Adding HNA association for network " << networkAddr <<
"/" << netmask <<
".");
1927 NS_LOG_INFO (
"Removing HNA association for network " << networkAddr <<
"/" << netmask <<
".");
1938 NS_LOG_INFO (
"Removing HNA entries coming from the old routing table association.");
1957 NS_LOG_DEBUG (
"Nb local associations before adding some entries from" 1972 NS_LOG_DEBUG (
"Nb local associations after having added some entries from " 1992 bool updated =
false;
1993 bool created =
false;
1995 <<
": LinkSensing(receiverIface=" << receiverIface
1996 <<
", senderIface=" << senderIface <<
") BEGIN");
2000 if (link_tuple == NULL)
2010 NS_LOG_LOGIC (
"Existing link tuple did not exist => creating new one");
2014 NS_LOG_LOGIC (
"Existing link tuple already exists => will update it");
2018 link_tuple->asymTime = now + msg.
GetVTime ();
2019 for (std::vector<olsr::MessageHeader::Hello::LinkMessage>::const_iterator linkMessage =
2024 int lt = linkMessage->linkCode & 0x03;
2025 int nt = (linkMessage->linkCode >> 2) & 0x03;
2027 #ifdef NS3_LOG_ENABLE 2028 const char *linkTypeName;
2032 linkTypeName =
"UNSPEC_LINK";
2035 linkTypeName =
"ASYM_LINK";
2038 linkTypeName =
"SYM_LINK";
2041 linkTypeName =
"LOST_LINK";
2044 linkTypeName =
"(invalid value!)";
2048 const char *neighborTypeName;
2052 neighborTypeName =
"NOT_NEIGH";
2055 neighborTypeName =
"SYM_NEIGH";
2058 neighborTypeName =
"MPR_NEIGH";
2061 neighborTypeName =
"(invalid value!)";
2064 NS_LOG_DEBUG (
"Looking at HELLO link messages with Link Type " 2065 << lt <<
" (" << linkTypeName
2066 <<
") and Neighbor Type " << nt
2067 <<
" (" << neighborTypeName <<
")");
2068 #endif // NS3_LOG_ENABLE 2075 NS_LOG_LOGIC (
"HELLO link code is invalid => IGNORING");
2079 for (std::vector<Ipv4Address>::const_iterator neighIfaceAddr =
2080 linkMessage->neighborInterfaceAddresses.begin ();
2081 neighIfaceAddr != linkMessage->neighborInterfaceAddresses.end ();
2085 if (*neighIfaceAddr == receiverIface)
2090 link_tuple->symTime = now -
Seconds (1);
2095 NS_LOG_DEBUG (*link_tuple <<
": link is SYM or ASYM => should become SYM now" 2096 " (symTime being increased to " << now + msg.
GetVTime ());
2097 link_tuple->symTime = now + msg.
GetVTime ();
2109 NS_LOG_DEBUG (
" \\-> *neighIfaceAddr (" << *neighIfaceAddr
2110 <<
" != receiverIface (" << receiverIface <<
") => IGNORING!");
2113 NS_LOG_DEBUG (
"Link tuple updated: " <<
int (updated));
2115 link_tuple->time =
std::max (link_tuple->time, link_tuple->asymTime);
2128 link_tuple->neighborIfaceAddr));
2131 <<
": LinkSensing END");
2139 if (nb_tuple != NULL)
2153 for (LinkSet::const_iterator link_tuple =
m_state.
GetLinks ().begin ();
2156 NS_LOG_LOGIC (
"Looking at link tuple: " << *link_tuple);
2160 "GetMainAddress (link_tuple->neighborIfaceAddr) != msg.GetOriginatorAddress ()");
2161 NS_LOG_LOGIC (
"(GetMainAddress(" << link_tuple->neighborIfaceAddr <<
"): " 2167 if (link_tuple->symTime < now)
2173 typedef std::vector<olsr::MessageHeader::Hello::LinkMessage> LinkMessageVec;
2174 for (LinkMessageVec::const_iterator linkMessage = hello.
linkMessages.begin ();
2175 linkMessage != hello.
linkMessages.end (); linkMessage++)
2177 int neighborType = (linkMessage->linkCode >> 2) & 0x3;
2178 #ifdef NS3_LOG_ENABLE 2179 const char *neighborTypeNames[3] = {
"NOT_NEIGH",
"SYM_NEIGH",
"MPR_NEIGH" };
2180 const char *neighborTypeName = ((neighborType < 3) ?
2181 neighborTypeNames[neighborType]
2182 :
"(invalid value)");
2183 NS_LOG_DEBUG (
"Looking at Link Message from HELLO message: neighborType=" 2184 << neighborType <<
" (" << neighborTypeName <<
")");
2185 #endif // NS3_LOG_ENABLE 2187 for (std::vector<Ipv4Address>::const_iterator nb2hop_addr_iter =
2188 linkMessage->neighborInterfaceAddresses.begin ();
2189 nb2hop_addr_iter != linkMessage->neighborInterfaceAddresses.end ();
2193 NS_LOG_DEBUG (
"Looking at 2-hop neighbor address from HELLO message: " 2194 << *nb2hop_addr_iter
2195 <<
" (main address is " << nb2hop_addr <<
")");
2203 NS_LOG_LOGIC (
"Ignoring 2-hop neighbor (it is the node itself)");
2211 << (nb2hop_tuple ?
" (refreshing existing entry)" :
""));
2212 if (nb2hop_tuple == NULL)
2237 NS_LOG_LOGIC (
"2-hop neighbor is NOT_NEIGH => deleting matching 2-hop neighbor state");
2242 NS_LOG_LOGIC (
"*** WARNING *** Ignoring link message (inside HELLO) with bad" 2243 " neighbor type value: " << neighborType);
2260 typedef std::vector<olsr::MessageHeader::Hello::LinkMessage> LinkMessageVec;
2261 for (LinkMessageVec::const_iterator linkMessage = hello.
linkMessages.begin ();
2265 int nt = linkMessage->linkCode >> 2;
2268 NS_LOG_DEBUG (
"Processing a link message with neighbor type MPR_NEIGH");
2270 for (std::vector<Ipv4Address>::const_iterator nb_iface_addr =
2271 linkMessage->neighborInterfaceAddresses.begin ();
2272 nb_iface_addr != linkMessage->neighborInterfaceAddresses.end ();
2277 NS_LOG_DEBUG (
"Adding entry to mpr selector set for neighbor " << *nb_iface_addr);
2282 if (existing_mprsel_tuple == NULL)
2320 struct hdr_ip* ih = HDR_IP (p);
2321 struct hdr_cmn* ch = HDR_CMN (p);
2323 debug (
"%f: Node %d MAC Layer detects a breakage on link to %d\n",
2325 OLSR::node_id (ra_addr ()),
2326 OLSR::node_id (ch->next_hop ()));
2328 if ((uint32_t)ih->daddr () == IP_BROADCAST)
2330 drop (p, DROP_RTR_MAC_CALLBACK);
2334 OLSR_link_tuple* link_tuple = state_.find_link_tuple (ch->next_hop ());
2335 if (link_tuple != NULL)
2339 nb_loss (link_tuple);
2341 drop (p, DROP_RTR_MAC_CALLBACK);
2409 <<
" LinkTuple " << tuple <<
" REMOVED.");
2422 <<
" LinkTuple " << tuple <<
" UPDATED.");
2427 if (nb_tuple == NULL)
2433 if (nb_tuple != NULL)
2435 int statusBefore = nb_tuple->
status;
2437 bool hasSymmetricLink =
false;
2440 for (LinkSet::const_iterator it = linkSet.begin ();
2441 it != linkSet.end (); it++)
2447 hasSymmetricLink =
true;
2452 if (hasSymmetricLink)
2455 NS_LOG_DEBUG (*nb_tuple <<
"->status = STATUS_SYM; changed:" 2456 <<
int (statusBefore != nb_tuple->
status));
2461 NS_LOG_DEBUG (*nb_tuple <<
"->status = STATUS_NOT_SYM; changed:" 2462 <<
int (statusBefore != nb_tuple->
status));
2467 NS_LOG_WARN (
"ERROR! Wanted to update a NeighborTuple but none was found!");
2641 NS_LOG_DEBUG (
"Not sending any TC, no one selected me as MPR.");
2662 NS_LOG_DEBUG (
"Not sending any HNA, no associations to advertise.");
2699 if (tuple->
time < now)
2703 else if (tuple->
symTime < now)
2716 neighborIfaceAddr));
2722 neighborIfaceAddr));
2743 this, neighborMainAddr, twoHopNeighborAddr));
2823 this, gatewayAddr, networkAddr, netmask));
2845 std::map<Ipv4Address, RoutingTableEntry>::const_iterator it =
2852 outEntry = it->second;
2882 if (!foundSendEntry)
2886 uint32_t interfaceIdx = entry2.
interface;
2887 if (oif &&
m_ipv4->GetInterfaceForDevice (oif) !=
static_cast<int> (interfaceIdx))
2894 <<
" Route interface " << interfaceIdx
2895 <<
" does not match requested output interface " 2896 <<
m_ipv4->GetInterfaceForDevice (oif));
2900 rtentry = Create<Ipv4Route> ();
2906 uint32_t numOifAddresses =
m_ipv4->GetNAddresses (interfaceIdx);
2909 if (numOifAddresses == 1)
2911 ifAddr =
m_ipv4->GetAddress (interfaceIdx, 0);
2916 NS_FATAL_ERROR (
"XXX Not implemented yet: IP aliasing and OLSR");
2918 rtentry->SetSource (ifAddr.
GetLocal ());
2919 rtentry->SetGateway (entry2.
nextAddr);
2920 rtentry->SetOutputDevice (
m_ipv4->GetNetDevice (interfaceIdx));
2924 <<
" --> nextHop=" << entry2.
nextAddr 2926 NS_LOG_DEBUG (
"Found route to " << rtentry->GetDestination () <<
" via nh " << rtentry->GetGateway () <<
" with source addr " << rtentry->GetSource () <<
" and output dev " << rtentry->GetOutputDevice ());
2936 NS_LOG_DEBUG (
"Found route to " << rtentry->GetDestination () <<
" via nh " << rtentry->GetGateway () <<
" with source addr " << rtentry->GetSource () <<
" and output dev " << rtentry->GetOutputDevice ());
2944 <<
" No route to host");
2968 uint32_t iif =
m_ipv4->GetInterfaceForDevice (idev);
2969 if (
m_ipv4->IsDestinationAddress (dst, iif))
2974 lcb (p, header, iif);
2996 if (!foundSendEntry)
3000 rtentry = Create<Ipv4Route> ();
3002 uint32_t interfaceIdx = entry2.
interface;
3007 uint32_t numOifAddresses =
m_ipv4->GetNAddresses (interfaceIdx);
3010 if (numOifAddresses == 1)
3012 ifAddr =
m_ipv4->GetAddress (interfaceIdx, 0);
3017 NS_FATAL_ERROR (
"XXX Not implemented yet: IP aliasing and OLSR");
3025 <<
" --> nextHop=" << entry2.
nextAddr 3028 ucb (rtentry, p, header);
3033 NS_LOG_LOGIC (
"No dynamic route, check network routes");
3041 #ifdef NS3_LOG_ENABLE 3044 <<
" --> NOT FOUND; ** Dumping routing table...");
3046 for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator iter =
m_table.begin ();
3047 iter !=
m_table.end (); iter++)
3049 NS_LOG_DEBUG (
"dest=" << iter->first <<
" --> next=" << iter->second.nextAddr
3050 <<
" via interface " << iter->second.interface);
3054 #endif // NS3_LOG_ENABLE 3109 for (uint32_t i = 0; i <
m_ipv4->GetNInterfaces (); i++)
3111 for (uint32_t j = 0; j <
m_ipv4->GetNAddresses (i); j++)
3113 if (
m_ipv4->GetAddress (i,j).GetLocal () == interfaceAddress)
3115 AddEntry (dest, next, i, distance);
3121 AddEntry (dest, next, 0, distance);
3125 std::vector<RoutingTableEntry>
3128 std::vector<RoutingTableEntry> retval;
3129 for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator iter =
m_table.begin ();
3130 iter !=
m_table.end (); iter++)
3132 retval.push_back (iter->second);
3199 #ifdef NS3_LOG_ENABLE 3212 if (now < iter->expirationTime)
3218 for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator iter =
m_table.begin (); iter !=
m_table.end (); iter++)
3220 NS_LOG_DEBUG (
" dest=" << iter->first <<
" --> next=" << iter->second.nextAddr <<
" via interface " << iter->second.interface);
3223 #endif //NS3_LOG_ENABLE std::vector< TopologyTuple > TopologySet
Topology Set type.
void HnaTimerExpire(void)
Sends an HNA message (if the node has associated hosts/networks) and reschedules the HNA timer...
Ipv4Address networkAddr
Network Address of network reachable through gatewayAddr.
static TypeId GetTypeId(void)
Get the type ID.
std::set< uint32_t > m_interfaceExclusions
Set of interfaces excluded by OSLR.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
#define JITTER
Random number between [0-OLSR_MAXJITTER] used to jitter OLSR packet transmission. ...
An OLSR's routing table entry.
uint32_t distance
Distance in hops to the destination.
#define OLSR_MPR_NEIGH
Asymmetric neighbor type.
Simulation virtual time values and global simulation resolution.
IfaceAssocSet & GetIfaceAssocSetMutable()
Gets a mutable reference to the interface association set.
void AddTopologyTuple(const TopologyTuple &tuple)
Adds a topology tuple to the Topology Set.
static Ipv4Address GetAny(void)
#define OLSR_MAX_SEQ_NUM
Maximum allowed sequence number.
Smart pointer class similar to boost::intrusive_ptr.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
const TopologySet & GetTopologySet() const
Gets the topology set.
TwoHopNeighborTuple * FindTwoHopNeighborTuple(const Ipv4Address &neighbor, const Ipv4Address &twoHopNeighbor)
Finds a 2-hop neighbor tuple.
void IfaceAssocTupleTimerExpire(Ipv4Address ifaceAddr)
Removes interface association tuple_ if expired.
uint16_t sequenceNumber
Sequence number.
const TwoHopNeighborSet & GetTwoHopNeighbors() const
Gets the 2-hop neighbor set.
void RemoveMprSelectorTuple(const MprSelectorTuple &tuple)
Removes an MPR selector tuple from the MPR Selector Set.
Timer m_helloTimer
Timer for the HELLO message.
#define OLSR_WILL_DEFAULT
Willingness for forwarding packets from other nodes: medium.
void Clear(void)
Clears the routing table and frees the memory assigned to each one of its entries.
void MidTimerExpire(void)
Sends a MID message (if the node has more than one interface) and resets the MID timer.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
std::vector< Association > Associations
Association Set type.
Time m_midInterval
MID messages' emission interval.
uint32_t GetId(void) const
A simple virtual Timer class.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
#define OLSR_DUP_HOLD_TIME
Dup holding time.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
void EraseMprSelectorTuples(const Ipv4Address &mainAddr)
Erases all MPR selector tuples belonging to the same address.
uint16_t m_messageSequenceNumber
Messages sequence number counter.
virtual bool SetAllowBroadcast(bool allowBroadcast)=0
Configure whether broadcast datagram transmissions are allowed.
void InsertAssociationTuple(const AssociationTuple &tuple)
Inserts a known association tuple.
Ipv4Address destAddr
Address of the destination node.
a class to represent an Ipv4 address mask
#define OLSR_TOP_HOLD_TIME
Top holding time.
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
virtual int ShutdownSend(void)=0
void LinkTupleUpdated(const LinkTuple &tuple, uint8_t willingness)
This function is invoked when a link tuple is updated.
uint32_t GetRecvIf(void) const
Get the tag's receiving interface.
void InsertNeighborTuple(const NeighborTuple &tuple)
Inserts a neighbor tuple.
uint16_t m_ansn
Advertised Neighbor Set sequence number.
MprSet GetMprSet() const
Gets the MPR set.
const NeighborSet & GetNeighbors(void) const
Get the one hop neighbors.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
#define OLSR_WILL_ALWAYS
Willingness for forwarding packets from other nodes: always.
void SetMprSet(MprSet mprSet)
Sets the MPR set to the one specified.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
void AddEntry(const Ipv4Address &dest, const Ipv4Address &next, uint32_t interface, uint32_t distance)
Adds a new entry into the routing table.
Ptr< const Ipv4StaticRouting > GetRoutingTableAssociation(void) const
Returns the internal HNA table.
bool m_linkTupleTimerFirstTime
Flag to indicate if it is the first time the LinkTupleTimer fires.
void TcTimerExpire(void)
Sends a TC message (if there exists any MPR selector) and reschedules the TC timer.
virtual void NotifyInterfaceUp(uint32_t interface)
void SendQueuedMessages(void)
Creates as many OLSR packets as needed in order to send all buffered OLSR messages.
const IfaceAssocSet & GetIfaceAssocSet() const
Gets the interface association set.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
void DupTupleTimerExpire(Ipv4Address address, uint16_t sequenceNumber)
Removes tuple if expired.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
bool FindMprAddress(const Ipv4Address &address)
Checks if there's an MPR with a specific address.
uint16_t GetPacketSequenceNumber(void)
Increments packet sequence number and returns the new value.
Time time
Time at which this tuple expires and must be removed.
enum ns3::olsr::NeighborTuple::Status status
Status of the link.
Timer m_queuedMessagesTimer
timer for throttling outgoing messages
virtual void DoDispose(void)
Destructor implementation.
void InsertMprSelectorTuple(const MprSelectorTuple &tuple)
Inserts a MPR selector tuple.
void AddHostNetworkAssociation(Ipv4Address networkAddr, Ipv4Mask netmask)
Injects the specified (networkAddr, netmask) tuple in the list of local HNA associations to be sent b...
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Ipv4Address m_mainAddress
the node main address.
TimeWithUnit As(const enum Unit unit) const
Attach a unit to a Time, to facilitate output in a specific unit.
Time expirationTime
Time at which this tuple expires and must be removed.
Ipv4Address GetDestNetwork(void) const
NeighborTuple * FindNeighborTuple(const Ipv4Address &mainAddr)
Finds a neighbor tuple.
#define OLSR_WILL_LOW
Willingness for forwarding packets from other nodes: low.
Ipv4Mask netmask
IPv4 Network mask.
void LinkTupleTimerExpire(Ipv4Address neighborIfaceAddr)
Removes tuple_ if expired.
void EraseIfaceAssocTuple(const IfaceAssocTuple &tuple)
Erases a interface association tuple.
void SetMainInterface(uint32_t interface)
Set the OLSR main address to the first address on the indicated interface.
SocketErrno
Enumeration of the possible errors returned by a socket.
Ipv4Mask netmask
Netmask of network reachable through gatewayAddr.
void Nb2hopTupleTimerExpire(Ipv4Address neighborMainAddr, Ipv4Address twoHopNeighborAddr)
Removes 2_hop neighbor tuple_ if expired.
void RemoveAssociationTuple(const AssociationTuple &tuple)
Removes a host network association tuple to the Association Set.
void ProcessTc(const olsr::MessageHeader &msg, const Ipv4Address &senderIface)
Processes a TC message following RFC 3626 specification.
#define OLSR_NEIGHB_HOLD_TIME
Neighbor holding time.
LinkTuple * FindSymLinkTuple(const Ipv4Address &ifaceAddr, Time time)
Finds a symmetrical link tuple.
void MprComputation(void)
Computates MPR set of a node following RFC 3626 hints.
const NeighborSet & GetNeighbors() const
Gets the neighbor set.
a polymophic address class
LinkTuple * FindLinkTuple(const Ipv4Address &ifaceAddr)
Finds a link tuple.
void SendMid(void)
Creates a new OLSR MID message which is buffered for being sent later on.
void LinkSensing(const olsr::MessageHeader &msg, const olsr::MessageHeader::Hello &hello, const Ipv4Address &receiverIface, const Ipv4Address &senderIface)
Updates Link Set according to a new received HELLO message (following RFC 3626 specification).
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
void SendHna(void)
Creates a new OLSR HNA message which is buffered for being sent later on.
void EraseDuplicateTuple(const DuplicateTuple &tuple)
Erases a duplicate tuple.
void EraseTopologyTuple(const TopologyTuple &tuple)
Erases a topology tuple.
void MprSelTupleTimerExpire(Ipv4Address mainAddr)
Removes MPR selector tuple_ if expired.
#define OLSR_SYM_LINK
Symmetric link type.
void SetSource(Ipv4Address src)
std::map< Ipv4Address, RoutingTableEntry > m_table
Data structure for the routing table.
const NeighborTuple * FindSymNeighborTuple(const Ipv4Address &mainAddr) const
Finds a symmetrical neighbor tuple.
TracedCallback< const PacketHeader &, const MessageList & > m_rxPacketTrace
Rx packet trace.
void RemoveIfaceAssocTuple(const IfaceAssocTuple &tuple)
Removed an interface association tuple to the Interface Association Set.
void SetRecvPktInfo(bool flag)
Enable/Disable receive packet information to socket.
const LinkSet & GetLinks() const
Gets the Link set.
EventGarbageCollector m_events
Running events.
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print the Routing Table entries.
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
Ipv4Address lastAddr
Main address of a node which is a neighbor of the destination.
const MprSelectorSet & GetMprSelectors() const
Gets the MPR selectors.
Ipv4Mask GetDestNetworkMask(void) const
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
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 EraseOlderTopologyTuples(const Ipv4Address &lastAddr, uint16_t ansn)
Erases a topology tuple.
void RemoveHostNetworkAssociation(Ipv4Address networkAddr, Ipv4Mask netmask)
Removes the specified (networkAddr, netmask) tuple from the list of local HNA associations to be sent...
Hold variables of type enum.
std::map< Ptr< Socket >, Ipv4InterfaceAddress > m_sendSockets
Container of sockets and the interfaces they are opened onto.
Ipv4Address mainAddr
Main address of the node.
TopologyTuple * FindTopologyTuple(const Ipv4Address &destAddr, const Ipv4Address &lastAddr)
Finds a topology tuple.
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].
AttributeValue implementation for Time.
Ipv4Address mainAddr
Main address of a node which have selected this node as a MPR.
void SendPacket(Ptr< Packet > packet, const MessageList &containedMessages)
Send an OLSR message.
void Schedule(void)
Schedule a new event using the currently-configured delay, function, and arguments.
void SetGateway(Ipv4Address gw)
OLSR routing protocol for IPv4.
bool FindSendEntry(const RoutingTableEntry &entry, RoutingTableEntry &outEntry) const
Finds the appropriate entry which must be used in order to forward a data packet to a next hop (given...
void ProcessHello(const olsr::MessageHeader &msg, const Ipv4Address &receiverIface, const Ipv4Address &senderIface)
Processes a HELLO message following RFC 3626 specification.
std::string PrintMprSelectorSet() const
Prints the MPR selector sets.
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
#define DELAY(time)
Gets the delay between a given time and the current time.
Unit
The unit to use to interpret a number representing time.
IfaceAssocTuple * FindIfaceAssocTuple(const Ipv4Address &ifaceAddr)
Finds a interface association tuple.
void AddAssociationTuple(const AssociationTuple &tuple)
Adds a host network association tuple to the Association Set.
Ptr< Ipv4StaticRouting > m_hnaRoutingTable
Routing table for HNA routes.
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)
Timer m_tcTimer
Timer for the TC message.
Ptr< Socket > m_recvSocket
Receiving socket.
void InsertDuplicateTuple(const DuplicateTuple &tuple)
Inserts a duplicate tuple.
std::vector< LinkTuple > LinkSet
Link Set type.
void RemoveDuplicateTuple(const DuplicateTuple &tuple)
Removes a duplicate tuple from the Duplicate Set.
Time symTime
The link is considered bidirectional until this time.
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)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
void EraseLinkTuple(const LinkTuple &tuple)
Erases a link tuple.
void CoverTwoHopNeighbors(Ipv4Address neighborMainAddr, TwoHopNeighborSet &N2)
Remove all covered 2-hop neighbors from N2 set.
Time m_helloInterval
HELLO messages' emission interval.
const Associations & GetAssociations() const
Gets the association set the node has.
void SetDelay(const Time &delay)
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
const MprSelectorSet & GetMprSelectors(void) const
Gets the MPR selectors.
#define OLSR_UNSPEC_LINK
Unspecified link type.
#define OLSR_NOT_NEIGH
Not neighbor type.
#define OLSR_ASYM_LINK
Asymmetric link type.
void SetRoutingTableAssociation(Ptr< Ipv4StaticRouting > routingTable)
Associates the specified Ipv4StaticRouting routing table to the OLSR routing protocol.
Ipv4Address destAddr
Main address of the destination.
std::vector< IfaceAssocTuple > IfaceAssocSet
Interface Association Set type.
AssociationTuple * FindAssociationTuple(const Ipv4Address &gatewayAddr, const Ipv4Address &networkAddr, const Ipv4Mask &netmask)
Finds an association tuple.
void TopologyTupleTimerExpire(Ipv4Address destAddr, Ipv4Address lastAddr)
Removes topology tuple_ if expired.
Time m_tcInterval
TC messages' emission interval.
void AddTwoHopNeighborTuple(const TwoHopNeighborTuple &tuple)
Adds a 2-hop neighbor tuple to the 2-hop Neighbor Set.
const AssociationSet & GetAssociationSet() const
Gets the association set known to the node.
std::vector< Ipv4Address > FindNeighborInterfaces(const Ipv4Address &neighborMainAddr) const
Returns a vector of all interfaces of a given neighbor, with the exception of the "main" one...
void AssociationTupleTimerExpire(Ipv4Address gatewayAddr, Ipv4Address networkAddr, Ipv4Mask netmask)
Removes association tuple_ if expired.
void NeighborLoss(const LinkTuple &tuple)
Performs all actions needed when a neighbor loss occurs.
void RemoveTopologyTuple(const TopologyTuple &tuple)
Removes a topology tuple to 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 InsertIfaceAssocTuple(const IfaceAssocTuple &tuple)
Inserts a interface association tuple.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
virtual void DoDispose(void)
Destructor implementation.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
void RecvOlsr(Ptr< Socket > socket)
Receive an OLSR message.
Ipv4Address neighborMainAddr
Main address of a neighbor node.
uint32_t GetInterface(void) const
Ipv4Address twoHopNeighborAddr
Main address of a 2-hop neighbor with a symmetric link to nb_main_addr.
bool IsMyOwnAddress(const Ipv4Address &a) const
Check that address is one of my interfaces.
bool Lookup(const Ipv4Address &dest, RoutingTableEntry &outEntry) const
Looks up an entry for the specified destination address.
static TypeId GetTypeId(void)
Get the type ID.
uint16_t GetPort(void) const
This class encapsulates all data structures needed for maintaining internal state of an OLSR node...
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
const TopologySet & GetTopologySet(void) const
Gets the topology set.
std::vector< RoutingTableEntry > GetRoutingTableEntries(void) const
Get the routing table entries.
Ptr< Ipv4StaticRouting > m_routingTableAssociation
Associations from an Ipv4StaticRouting instance.
void AddNeighborTuple(const NeighborTuple &tuple)
Adds a neighbor tuple to the Neighbor Set.
void SendHello(void)
Creates a new OLSR HELLO message which is buffered for being sent later on.
MprSelectorTuple * FindMprSelectorTuple(const Ipv4Address &mainAddr)
Finds a MPR selector tuple.
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.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
std::vector< MessageHeader > MessageList
void EraseAssociationTuple(const AssociationTuple &tuple)
Erases a known association tuple.
void SendTc(void)
Creates a new OLSR TC message which is buffered for being sent later on.
Ipv4Address localIfaceAddr
Interface address of the local node.
static Time Now(void)
Return the current simulation virtual time.
void SetOutputDevice(Ptr< NetDevice > outputDevice)
Equivalent in Linux to dst_entry.dev.
Time time
Time at which this tuple expires and must be removed.
virtual void NotifyInterfaceDown(uint32_t interface)
Ipv4Address GetSubnetDirectedBroadcast(Ipv4Mask const &mask) const
Generate subnet-directed broadcast address corresponding to mask.
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...
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
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.
bool IsRunning(void) const
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.
double max(double x, double y)
int Degree(NeighborTuple const &tuple)
This auxiliary function (defined in RFC 3626) is used for calculating the MPR Set.
#define OLSR_WILL_HIGH
Willingness for forwarding packets from other nodes: high.
uint32_t interface
Interface index.
Ipv4 addresses are stored in host order in this class.
std::vector< NeighborTuple > NeighborSet
Neighbor Set type.
void EraseAssociation(const Association &tuple)
Erases an association.
Ptr< Ipv4 > m_ipv4
IPv4 object the routing is linked to.
uint32_t GetSize(void) const
Returns the routing table size.
void HelloTimerExpire(void)
Sends a HELLO message and reschedules the HELLO timer.
a class to store IPv4 address information on an interface
Ipv4Address GetMainAddress(Ipv4Address iface_addr) const
Gets the main address associated with a given interface address.
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 (...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
DuplicateTuple * FindDuplicateTuple(const Ipv4Address &address, uint16_t sequenceNumber)
Finds a duplicate tuple.
void InsertTwoHopNeighborTuple(const TwoHopNeighborTuple &tuple)
Inserts a 2-hop neighbor tuple.
Ipv4Address ifaceAddr
Interface address of a node.
#define OLSR_LOST_LINK
Lost link type.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Ipv4Address nextAddr
Address of the next hop.
TracedCallback< const PacketHeader &, const MessageList & > m_txPacketTrace
Tx packet trace.
std::set< Ipv4Address > MprSet
MPR Set type.
#define OLSR_SYM_NEIGH
Symmetric neighbor type.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Timer m_midTimer
Timer for the MID message.
Time Seconds(double value)
Construct a Time in the indicated unit.
static const uint16_t OLSR_PORT_NUMBER
port number (698)
#define OLSR_MID_HOLD_TIME
MID holding time.
std::vector< TwoHopNeighborTuple > TwoHopNeighborSet
2-hop Neighbor Set type.
void EraseTwoHopNeighborTuple(const TwoHopNeighborTuple &tuple)
Erases a 2-hop neighbor tuple.
void Track(EventId event)
Tracks a new event.
uint16_t GetMessageSequenceNumber(void)
Increments message sequence number and returns the new value.
Ptr< const AttributeChecker > MakeEnumChecker(int v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
static std::string FindName(Ptr< Object > object)
Given a pointer to an object, look to see if that object has a name associated with it and...
Ipv4Address GetLocal(void) const
Get the local address.
Abstract base class for IPv4 routing protocols.
#define OLSR_WILL_NEVER
Willingness for forwarding packets from other nodes: never.
#define OLSR_MAX_MSGS
Maximum number of messages per packet.
void LinkTupleAdded(const LinkTuple &tuple, uint8_t willingness)
Adds a link tuple.
void SetInterfaceExclusions(std::set< uint32_t > exceptions)
Set the interfaces to be excluded.
LinkTuple & InsertLinkTuple(const LinkTuple &tuple)
Inserts a link tuple.
Time m_hnaInterval
HNA messages' emission interval.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
void Dump(void)
Dump the neighbor table, two-hop neighbor table, and routing table to logging output (NS_LOG_DEBUG lo...
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Ipv4Address neighborMainAddr
Main address of a neighbor.
Timer m_hnaTimer
Timer for the HNA message.
std::vector< MprSelectorTuple > MprSelectorSet
MPR Selector Set type.
virtual void DoInitialize(void)
Initialize() implementation.
void EraseNeighborTuple(const NeighborTuple &neighborTuple)
Erases a neighbor tuple.
const TwoHopNeighborSet & GetTwoHopNeighbors(void) const
Get the two hop neighbors.
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.
Ipv4Address address
Originator address of the message.
TopologyTuple * FindNewerTopologyTuple(const Ipv4Address &lastAddr, uint16_t ansn)
Finds a topology tuple.
void RemoveNeighborTuple(const NeighborTuple &tuple)
Removes a neighbor tuple from the Neighbor Set.
virtual Ptr< Ipv4 > GetIpv4(void) const
virtual int Close(void)=0
Close a socket.
bool IsNull(void) const
Check for null implementation.
Ipv4Address gatewayAddr
Main address of the gateway.
OlsrState m_state
Internal state with all needed data structs.
const OlsrState & GetOlsrState(void) const
Gets the underlying OLSR state object.
virtual ~RoutingProtocol(void)
void RoutingTableComputation(void)
Creates the routing table of the node following RFC 3626 hints.
void AddMprSelectorTuple(const MprSelectorTuple &tuple)
Adds an MPR selector tuple to the MPR Selector Set.
TracedCallback< uint32_t > m_routingTableChanged
Routing table chanes challback.
Ipv4Address neighborIfaceAddr
Interface address of the neighbor node.
#define OLSR_HNA_HOLD_TIME
HNA holding time.
Ipv4Address networkAddr
IPv4 Network address.
a unique identifier for an interface.
An Interface Association Tuple.
bool retransmitted
Indicates whether the message has been retransmitted or not.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
void EraseMprSelectorTuple(const MprSelectorTuple &tuple)
Erases a MPR selector tuple.
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
void InsertAssociation(const Association &tuple)
Inserts an association tuple.
uint16_t sequenceNumber
Message sequence number.
std::vector< AssociationTuple > AssociationSet
Association Set type.
void AddHeader(const Header &header)
Add header to this packet.
virtual void SetIpTtl(uint8_t ipTtl)
Manually set IP Time to Live field.
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)
Ipv4Address GetIpv4(void) const
Time expirationTime
Time at which this tuple expires and must be removed.
void EraseTwoHopNeighborTuples(const Ipv4Address &neighbor)
Erases the 2-hop neighbor tuples with the same 1-hop neighbor.
void IncrementAnsn(void)
Increments the ANSN counter.
void InsertTopologyTuple(const TopologyTuple &tuple)
Inserts a topology tuple.
MprSet GetMprSet(void) const
Gets the MPR set.
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.