18#define NS_LOG_APPEND_CONTEXT \
19 if (GetObject<Node>()) \
21 std::clog << "[node " << GetObject<Node>()->GetId() << "] "; \
28#include "ns3/boolean.h"
30#include "ns3/inet-socket-address.h"
31#include "ns3/ipv4-header.h"
32#include "ns3/ipv4-packet-info-tag.h"
33#include "ns3/ipv4-route.h"
34#include "ns3/ipv4-routing-protocol.h"
35#include "ns3/ipv4-routing-table-entry.h"
38#include "ns3/simulator.h"
39#include "ns3/socket-factory.h"
40#include "ns3/trace-source-accessor.h"
41#include "ns3/udp-socket-factory.h"
42#include "ns3/uinteger.h"
56 (((time) < (Simulator::Now())) ? Seconds(0.000001) \
57 : (time - Simulator::Now() + Seconds(0.000001)))
64#define OLSR_REFRESH_INTERVAL m_helloInterval
69#define OLSR_NEIGHB_HOLD_TIME Time(3 * OLSR_REFRESH_INTERVAL)
71#define OLSR_TOP_HOLD_TIME Time(3 * m_tcInterval)
73#define OLSR_DUP_HOLD_TIME Seconds(30)
75#define OLSR_MID_HOLD_TIME Time(3 * m_midInterval)
77#define OLSR_HNA_HOLD_TIME Time(3 * m_hnaInterval)
82#define OLSR_MAXJITTER (m_helloInterval.GetSeconds() / 4)
84#define OLSR_MAX_SEQ_NUM 65535
86#define JITTER (Seconds(m_uniformRandomVariable->GetValue(0, OLSR_MAXJITTER)))
89#define OLSR_MAX_MSGS 64
92#define OLSR_MAX_HELLOS 12
95#define OLSR_MAX_ADDRS 64
132 return (os <<
"UNSPEC_LINK");
134 return (os <<
"ASYM_LINK");
136 return (os <<
"SYM_LINK");
138 return (os <<
"LOST_LINK");
140 return (os <<
"Unknown link type");
170 return (os <<
"NOT_NEIGH");
172 return (os <<
"SYM_NEIGH");
174 return (os <<
"MPR_NEIGH");
176 return (os <<
"Unknown neighbor type");
191 TypeId(
"ns3::olsr::RoutingProtocol")
193 .SetGroupName(
"Olsr")
195 .AddAttribute(
"HelloInterval",
196 "HELLO messages emission interval.",
200 .AddAttribute(
"TcInterval",
201 "TC messages emission interval.",
205 .AddAttribute(
"MidInterval",
206 "MID messages emission interval. Normally it is equal to TcInterval.",
210 .AddAttribute(
"HnaInterval",
211 "HNA messages emission interval. Normally it is equal to TcInterval.",
215 .AddAttribute(
"Willingness",
216 "Willingness of a node to carry and forward traffic for other nodes.",
229 .AddTraceSource(
"Rx",
230 "Receive OLSR packet.",
232 "ns3::olsr::RoutingProtocol::PacketTxRxTracedCallback")
233 .AddTraceSource(
"Tx",
236 "ns3::olsr::RoutingProtocol::PacketTxRxTracedCallback")
237 .AddTraceSource(
"RoutingTableChanged",
238 "The OLSR routing table has changed.",
240 "ns3::olsr::RoutingProtocol::TableChangeTracedCallback");
245 : m_routingTableAssociation(nullptr),
247 m_helloTimer(
Timer::CANCEL_ON_DESTROY),
248 m_tcTimer(
Timer::CANCEL_ON_DESTROY),
249 m_midTimer(
Timer::CANCEL_ON_DESTROY),
250 m_hnaTimer(
Timer::CANCEL_ON_DESTROY),
251 m_queuedMessagesTimer(
Timer::CANCEL_ON_DESTROY)
311 std::ostream* os = stream->GetStream();
316 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
318 *os <<
"Node: " <<
m_ipv4->GetObject<
Node>()->GetId() <<
", Time: " <<
Now().
As(unit)
319 <<
", Local time: " <<
m_ipv4->GetObject<
Node>()->GetLocalTime().As(unit)
320 <<
", OLSR Routing table" << std::endl;
322 *os << std::setw(16) <<
"Destination";
323 *os << std::setw(16) <<
"NextHop";
324 *os << std::setw(16) <<
"Interface";
325 *os <<
"Distance" << std::endl;
329 std::ostringstream
dest;
330 std::ostringstream nextHop;
332 nextHop <<
iter->second.nextAddr;
333 *os << std::setw(16) <<
dest.str();
334 *os << std::setw(16) << nextHop.str();
335 *os << std::setw(16);
342 *os <<
iter->second.interface;
344 *os <<
iter->second.distance << std::endl;
351 *os <<
"HNA Routing Table:" << std::endl;
356 *os <<
"HNA Routing Table: empty" << std::endl << std::endl;
429 socket->SetAllowBroadcast(
true);
433 socket->BindToNetDevice(
m_ipv4->GetNetDevice(
i));
438 socket->SetRecvPktInfo(
true);
479 NS_ABORT_MSG(
"No incoming interface on OLSR message, aborting.");
575 <<
" OLSR node " <<
m_mainAddress <<
" received HELLO message of size "
582 <<
" OLSR node " <<
m_mainAddress <<
" received TC message of size "
589 <<
" OLSR node " <<
m_mainAddress <<
" received MID message of size "
595 <<
" OLSR node " <<
m_mainAddress <<
" received HNA message of size "
602 <<
" not implemented");
607 NS_LOG_DEBUG(
"OLSR message is duplicated, not reading it.");
684 if (
twoHopNeigh->neighborMainAddr == neighborMainAddr)
721 N.push_back(*neighbor);
779 std::ostringstream os;
785 os <<
iter->neighborMainAddr <<
"->" <<
iter->twoHopNeighborAddr;
786 if (next !=
N2.end())
798 for (
auto neighbor =
N.begin(); neighbor !=
N.end(); neighbor++)
802 mprSet.insert(neighbor->neighborMainAddr);
805 CoverTwoHopNeighbors(neighbor->neighborMainAddr,
N2);
831 <<
" is the only that can reach 2-hop neigh. "
832 <<
twoHopNeigh->twoHopNeighborAddr <<
" => select as MPR.");
857 <<
" is already covered by an MPR.");
868 while (
N2.begin() !=
N2.end())
872 std::ostringstream os;
878 os <<
iter->neighborMainAddr <<
"->" <<
iter->twoHopNeighborAddr;
879 if (next !=
N2.end())
893 std::map<int, std::vector<const NeighborTuple*>>
reachability;
895 for (
auto it =
N.begin();
it !=
N.end();
it++)
921 for (
auto it =
rs.begin();
it !=
rs.end();
it++)
965 std::ostringstream os;
990 if (
tuple !=
nullptr)
1004 <<
" : Node " <<
m_mainAddress <<
": RoutingTableComputation begin...");
1032 <<
" => adding routing table entry to neighbor");
1047 <<
"; neighborMainAddr = " <<
nb_tuple.neighborMainAddr
1064 NS_LOG_LOGIC(
"no R_dest_addr is equal to the main address of the neighbor "
1065 "=> adding additional routing entry");
1086 NS_LOG_LOGIC(
"Two-hop neighbor tuple is also neighbor; skipped.");
1102 if (neighbor->neighborMainAddr ==
nb2hop_tuple.neighborMainAddr &&
1111 NS_LOG_LOGIC(
"Two-hop neighbor tuple skipped: 2-hop neighbor "
1112 <<
nb2hop_tuple.twoHopNeighborAddr <<
" is attached to neighbor "
1114 <<
", which was not found in the Neighbor Set.");
1133 NS_LOG_LOGIC(
"Adding routing entry for two-hop neighbor.");
1138 NS_LOG_LOGIC(
"NOT adding routing entry for two-hop neighbor ("
1139 <<
nb2hop_tuple.twoHopNeighborAddr <<
" not found in the routing table)");
1154 for (
auto it = topology.begin();
it != topology.end();
it++)
1165 NS_LOG_LOGIC(
"Adding routing table entry based on the topology tuple.");
1184 NS_LOG_LOGIC(
"NOT adding routing table entry based on the topology tuple: "
1185 "have_destAddrEntry="
1187 <<
" lastAddrEntry.distance=" << (
int)
lastAddrEntry.distance
1188 <<
" (h=" <<
h <<
")");
1254 NS_LOG_DEBUG(
"HNA association received from another GW is part of local HNA "
1255 "associations: no route added for network "
1256 <<
tuple.networkAddr <<
"/" <<
tuple.netmask);
1275 if (
route.GetDestNetwork() ==
tuple.networkAddr &&
1318#ifdef NS3_LOG_ENABLE
1322 <<
" ** BEGIN dump Link Set for OLSR Node " <<
m_mainAddress);
1323 for (
auto link = links.begin(); link != links.end(); link++)
1331 <<
" ** BEGIN dump Neighbor Set for OLSR Node " <<
m_mainAddress);
1343#ifdef NS3_LOG_ENABLE
1347 <<
" ** BEGIN dump TwoHopNeighbor Set for OLSR Node " <<
m_mainAddress);
1432#ifdef NS3_LOG_ENABLE
1436 <<
" ** BEGIN dump TopologySet for OLSR Node " <<
m_mainAddress);
1459 <<
": the sender interface of this message is not in the "
1460 "symmetric 1-hop neighborhood of this node,"
1461 " the message MUST be discarded.");
1472 if (
tuple->ifaceAddr == *
i &&
tuple->mainAddr ==
msg.GetOriginatorAddress())
1475 tuple->time = now +
msg.GetVTime();
1483 tuple.mainAddr =
msg.GetOriginatorAddress();
1501 neighbor->neighborMainAddr =
GetMainAddress(neighbor->neighborMainAddr);
1542 if (
tuple !=
nullptr)
1557 now +
msg.GetVTime()};
1593 <<
" does not forward a message received"
1595 <<
olsrMessage.GetOriginatorAddress() <<
" because it is duplicated");
1602 bool retransmitted =
false;
1614 retransmitted =
true;
1632 newDup.retransmitted = retransmitted;
1664 packet->AddHeader(header);
1691 p->AddHeader(*message);
1692 packet->AddAtEnd(p);
1704 if (packet->GetSize())
1722 msg.SetTimeToLive(1);
1730 std::vector<olsr::MessageHeader::Hello::LinkMessage>& linkMessages = hello.
linkMessages;
1762 <<
" to be MPR_NEIGH.");
1777 <<
" to be SYM_NEIGH.");
1785 <<
" to be NOT_NEIGH.");
1789 NS_FATAL_ERROR(
"There is a neighbor tuple with an unknown status!\n");
1808 std::vector<Ipv4Address> interfaces =
1817 NS_LOG_DEBUG(
"OLSR HELLO message size: " <<
int(
msg.GetSerializedSize()) <<
" (with "
1818 <<
int(linkMessages.size()) <<
" link messages)");
1831 msg.SetTimeToLive(255);
1886 msg.SetTimeToLive(255);
1900 msg.SetTimeToLive(255);
1905 std::vector<olsr::MessageHeader::Hna::Association>& associations = hna.
associations;
1912 associations.push_back(
assoc);
1915 if (associations.empty())
1937 NS_LOG_INFO(
"HNA association for network " << networkAddr <<
"/" << netmask
1938 <<
" already exists.");
1943 NS_LOG_INFO(
"Adding HNA association for network " << networkAddr <<
"/" << netmask <<
".");
1950 NS_LOG_INFO(
"Removing HNA association for network " << networkAddr <<
"/" << netmask <<
".");
1961 NS_LOG_INFO(
"Removing HNA entries coming from the old routing table association.");
1980 NS_LOG_DEBUG(
"Nb local associations before adding some entries from"
1981 " the associated routing table: "
1996 NS_LOG_DEBUG(
"Nb local associations after having added some entries from "
1997 "the associated routing table: "
2035 NS_LOG_LOGIC(
"Existing link tuple did not exist => creating new one");
2039 NS_LOG_LOGIC(
"Existing link tuple already exists => will update it");
2050 NS_LOG_DEBUG(
"Looking at HELLO link messages with Link Type "
2058 NS_LOG_LOGIC(
"HELLO link code is invalid => IGNORING");
2078 " (symTime being increased to "
2079 << now +
msg.GetVTime());
2094 <<
") => IGNORING!");
2144 "Link tuple ignored: "
2145 "GetMainAddress (link_tuple->neighborIfaceAddr) != msg.GetOriginatorAddress ()");
2149 <<
"; msg.GetOriginatorAddress (): " <<
msg.GetOriginatorAddress());
2164 "Looking at Link Message from HELLO message: neighborType=" <<
neighborType);
2171 NS_LOG_DEBUG(
"Looking at 2-hop neighbor address from HELLO message: "
2181 NS_LOG_LOGIC(
"Ignoring 2-hop neighbor (it is the node itself)");
2189 << (
nb2hop_tuple ?
" (refreshing existing entry)" :
""));
2217 "2-hop neighbor is NOT_NEIGH => deleting matching 2-hop neighbor state");
2222 NS_LOG_LOGIC(
"*** WARNING *** Ignoring link message (inside HELLO) with bad"
2223 " neighbor type value: "
2247 NS_LOG_DEBUG(
"Processing a link message with neighbor type MPR_NEIGH");
2255 NS_LOG_DEBUG(
"Adding entry to mpr selector set for neighbor "
2302 debug(
"%f: Node %d MAC Layer detects a breakage on link to %d\n",
2305 OLSR::node_id (
ch->next_hop ()));
2328 <<
tuple.neighborIfaceAddr <<
" -> neighbor loss.");
2365 nb_tuple.willingness = willingness;
2438 NS_LOG_WARN(
"ERROR! Wanted to update a NeighborTuple but none was found!");
2614 NS_LOG_DEBUG(
"Not sending any TC, no one selected me as MPR.");
2635 NS_LOG_DEBUG(
"Not sending any HNA, no associations to advertise.");
2644 if (
tuple ==
nullptr)
2669 if (
tuple ==
nullptr)
2673 if (
tuple->time < now)
2677 else if (
tuple->symTime < now)
2691 neighborIfaceAddr));
2698 neighborIfaceAddr));
2708 if (
tuple ==
nullptr)
2722 twoHopNeighborAddr));
2730 if (
tuple ==
nullptr)
2751 if (
tuple ==
nullptr)
2773 if (
tuple ==
nullptr)
2796 if (
tuple ==
nullptr)
2885 <<
" does not match requested output interface "
2886 <<
m_ipv4->GetInterfaceForDevice(oif));
2914 <<
" interface=" <<
entry2.interface);
2916 <<
rtentry->GetGateway() <<
" with source addr "
2917 <<
rtentry->GetSource() <<
" and output dev "
2918 <<
rtentry->GetOutputDevice());
2929 <<
rtentry->GetGateway() <<
" with source addr "
2930 <<
rtentry->GetSource() <<
" and output dev "
2931 <<
rtentry->GetOutputDevice());
2968 if (
m_ipv4->IsDestinationAddress(dst,
iif))
3025 <<
" interface=" <<
entry2.interface);
3032 NS_LOG_LOGIC(
"No dynamic route, check network routes");
3039#ifdef NS3_LOG_ENABLE
3042 <<
" --> NOT FOUND; ** Dumping routing table...");
3047 <<
" via interface " <<
iter->second.interface);
3092 entry.nextAddr = next;
3093 entry.interface = interface;
3094 entry.distance = distance;
3124std::vector<RoutingTableEntry>
3127 std::vector<RoutingTableEntry>
retval;
3196#ifdef NS3_LOG_ENABLE
3218 <<
" via interface " <<
iter->second.interface);
a polymophic address class
Hold variables of type enum.
void Track(EventId event)
Tracks a new event.
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
Ipv4 addresses are stored in host order in this class.
Ipv4Address GetSubnetDirectedBroadcast(const Ipv4Mask &mask) const
Generate subnet-directed broadcast address corresponding to mask.
static Ipv4Address GetAny()
a class to store IPv4 address information on an interface
Ipv4Address GetAddress() const
Get the local address.
Ipv4Address GetLocal() const
Get the local address.
a class to represent an Ipv4 address mask
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
Abstract base class for IPv4 routing protocols.
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
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,...
virtual void DoDispose()
Destructor implementation.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now()
Return the current simulation virtual time.
virtual bool SetAllowBroadcast(bool allowBroadcast)=0
Configure whether broadcast datagram transmissions are allowed.
void SetRecvPktInfo(bool flag)
Enable/Disable receive packet information to socket.
virtual int ShutdownSend()=0
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
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 int Close()=0
Close a socket.
SocketErrno
Enumeration of the possible errors returned by a socket.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
Simulation virtual time values and global simulation resolution.
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Unit
The unit to use to interpret a number representing time.
AttributeValue implementation for Time.
A simple virtual Timer class.
void SetDelay(const Time &delay)
void Schedule()
Schedule a new event using the currently-configured delay, function, and arguments.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
static TypeId GetTypeId()
Get the type ID.
This class encapsulates all data structures needed for maintaining internal state of an OLSR node.
MprSet GetMprSet() const
Gets the MPR set.
void EraseAssociation(const Association &tuple)
Erases an association.
const NeighborSet & GetNeighbors() const
Gets the neighbor set.
void EraseIfaceAssocTuple(const IfaceAssocTuple &tuple)
Erases a interface association tuple.
void InsertTopologyTuple(const TopologyTuple &tuple)
Inserts a topology tuple.
IfaceAssocTuple * FindIfaceAssocTuple(const Ipv4Address &ifaceAddr)
Finds a interface association tuple.
std::string PrintMprSelectorSet() const
Prints the MPR selector sets.
TwoHopNeighborTuple * FindTwoHopNeighborTuple(const Ipv4Address &neighbor, const Ipv4Address &twoHopNeighbor)
Finds a 2-hop neighbor tuple.
void EraseTwoHopNeighborTuples(const Ipv4Address &neighbor)
Erases the 2-hop neighbor tuples with the same 1-hop neighbor.
void InsertAssociation(const Association &tuple)
Inserts an association tuple.
LinkTuple * FindSymLinkTuple(const Ipv4Address &ifaceAddr, Time time)
Finds a symmetrical link tuple.
const NeighborTuple * FindSymNeighborTuple(const Ipv4Address &mainAddr) const
Finds a symmetrical neighbor tuple.
IfaceAssocSet & GetIfaceAssocSetMutable()
Gets a mutable reference to the interface association set.
void EraseNeighborTuple(const NeighborTuple &neighborTuple)
Erases a neighbor tuple.
TopologyTuple * FindNewerTopologyTuple(const Ipv4Address &lastAddr, uint16_t ansn)
Finds a topology tuple.
void InsertDuplicateTuple(const DuplicateTuple &tuple)
Inserts a duplicate tuple.
const TopologySet & GetTopologySet() const
Gets the topology set.
const LinkSet & GetLinks() const
Gets the Link set.
void EraseMprSelectorTuples(const Ipv4Address &mainAddr)
Erases all MPR selector tuples belonging to the same address.
const TwoHopNeighborSet & GetTwoHopNeighbors() const
Gets the 2-hop neighbor set.
MprSelectorTuple * FindMprSelectorTuple(const Ipv4Address &mainAddr)
Finds a MPR selector tuple.
void SetMprSet(MprSet mprSet)
Sets the MPR set to the one specified.
void EraseAssociationTuple(const AssociationTuple &tuple)
Erases a known association tuple.
void InsertNeighborTuple(const NeighborTuple &tuple)
Inserts a neighbor tuple.
TopologyTuple * FindTopologyTuple(const Ipv4Address &destAddr, const Ipv4Address &lastAddr)
Finds a topology tuple.
AssociationTuple * FindAssociationTuple(const Ipv4Address &gatewayAddr, const Ipv4Address &networkAddr, const Ipv4Mask &netmask)
Finds an association tuple.
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.
bool FindMprAddress(const Ipv4Address &address)
Checks if there's an MPR with a specific address.
void EraseLinkTuple(const LinkTuple &tuple)
Erases a link tuple.
DuplicateTuple * FindDuplicateTuple(const Ipv4Address &address, uint16_t sequenceNumber)
Finds a duplicate tuple.
void InsertTwoHopNeighborTuple(const TwoHopNeighborTuple &tuple)
Inserts a 2-hop neighbor tuple.
const AssociationSet & GetAssociationSet() const
Gets the association set known to the node.
LinkTuple * FindLinkTuple(const Ipv4Address &ifaceAddr)
Finds a link tuple.
const IfaceAssocSet & GetIfaceAssocSet() const
Gets the interface association set.
const Associations & GetAssociations() const
Gets the association set the node has.
void InsertAssociationTuple(const AssociationTuple &tuple)
Inserts a known association tuple.
void InsertMprSelectorTuple(const MprSelectorTuple &tuple)
Inserts a MPR selector tuple.
LinkTuple & InsertLinkTuple(const LinkTuple &tuple)
Inserts a link tuple.
void EraseTwoHopNeighborTuple(const TwoHopNeighborTuple &tuple)
Erases a 2-hop neighbor tuple.
void InsertIfaceAssocTuple(const IfaceAssocTuple &tuple)
Inserts a interface association tuple.
void EraseTopologyTuple(const TopologyTuple &tuple)
Erases a topology tuple.
NeighborTuple * FindNeighborTuple(const Ipv4Address &mainAddr)
Finds a neighbor tuple.
void EraseOlderTopologyTuples(const Ipv4Address &lastAddr, uint16_t ansn)
Erases a topology tuple.
void EraseDuplicateTuple(const DuplicateTuple &tuple)
Erases a duplicate tuple.
const MprSelectorSet & GetMprSelectors() const
Gets the MPR selectors.
void EraseMprSelectorTuple(const MprSelectorTuple &tuple)
Erases a MPR selector tuple.
OLSR routing protocol for IPv4.
void SendHna()
Creates a new OLSR HNA message which is buffered for being sent later on.
void RemoveHostNetworkAssociation(Ipv4Address networkAddr, Ipv4Mask netmask)
Removes the specified (networkAddr, netmask) tuple from the list of local HNA associations to be sent...
OlsrState m_state
Internal state with all needed data structs.
void AddTwoHopNeighborTuple(const TwoHopNeighborTuple &tuple)
Adds a 2-hop neighbor tuple to the 2-hop Neighbor Set.
Time m_hnaInterval
HNA messages' emission interval.
const MprSelectorSet & GetMprSelectors() const
Gets the MPR selectors.
void SendQueuedMessages()
Creates as many OLSR packets as needed in order to send all buffered OLSR messages.
uint16_t m_messageSequenceNumber
Messages sequence number counter.
const TwoHopNeighborSet & GetTwoHopNeighbors() const
Get the two hop neighbors.
olsr::MessageList m_queuedMessages
A list of pending messages which are buffered awaiting for being sent.
void RemoveLinkTuple(const LinkTuple &tuple)
Removes a link tuple from the Link Set.
void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override
void NotifyInterfaceUp(uint32_t interface) override
TracedCallback< uint32_t > m_routingTableChanged
Routing table changes callback.
void QueueMessage(const olsr::MessageHeader &message, Time delay)
Enqueues an OLSR message which will be sent with a delay of (0, delay].
void LinkTupleAdded(const LinkTuple &tuple, Willingness willingness)
Adds a link tuple.
void AddNeighborTuple(const NeighborTuple &tuple)
Adds a neighbor tuple to the Neighbor Set.
std::map< Ptr< Socket >, Ipv4InterfaceAddress > m_sendSockets
Container of sockets and the interfaces they are opened onto.
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).
void SendPacket(Ptr< Packet > packet, const MessageList &containedMessages)
Send an OLSR message.
Timer m_tcTimer
Timer for the TC message.
void AddHostNetworkAssociation(Ipv4Address networkAddr, Ipv4Mask netmask)
Injects the specified (networkAddr, netmask) tuple in the list of local HNA associations to be sent b...
const NeighborSet & GetNeighbors() const
Get the one hop neighbors.
Ptr< Ipv4StaticRouting > m_hnaRoutingTable
Routing table for HNA routes.
void SendHello()
Creates a new OLSR HELLO message which is buffered for being sent later on.
void DoDispose() override
Destructor implementation.
bool IsMyOwnAddress(const Ipv4Address &a) const
Check that address is one of my interfaces.
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...
bool RouteInput(Ptr< const Packet > p, const Ipv4Header &header, Ptr< const NetDevice > idev, const UnicastForwardCallback &ucb, const MulticastForwardCallback &mcb, const LocalDeliverCallback &lcb, const ErrorCallback &ecb) override
Route an input packet (to be forwarded or locally delivered)
void LinkTupleTimerExpire(Ipv4Address neighborIfaceAddr)
Removes tuple_ if expired.
void MprSelTupleTimerExpire(Ipv4Address mainAddr)
Removes MPR selector tuple_ if expired.
void RemoveTopologyTuple(const TopologyTuple &tuple)
Removes a topology tuple to the Topology Set.
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...
void AddTopologyTuple(const TopologyTuple &tuple)
Adds a topology tuple to the Topology Set.
void ProcessTc(const olsr::MessageHeader &msg, const Ipv4Address &senderIface)
Processes a TC message following RFC 3626 specification.
void SetRoutingTableAssociation(Ptr< Ipv4StaticRouting > routingTable)
Associates the specified Ipv4StaticRouting routing table to the OLSR routing protocol.
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 (...
MprSet GetMprSet() const
Gets the MPR set.
Ipv4Address m_mainAddress
the node main address.
Ptr< UniformRandomVariable > m_uniformRandomVariable
Provides uniform random variables.
void Nb2hopTupleTimerExpire(Ipv4Address neighborMainAddr, Ipv4Address twoHopNeighborAddr)
Removes 2_hop neighbor tuple_ if expired.
void HelloTimerExpire()
Sends a HELLO message and reschedules the HELLO timer.
void AssociationTupleTimerExpire(Ipv4Address gatewayAddr, Ipv4Address networkAddr, Ipv4Mask netmask)
Removes association tuple_ if expired.
static const uint16_t OLSR_PORT_NUMBER
port number (698)
uint32_t GetSize() const
Returns the routing table size.
void SetMainInterface(uint32_t interface)
Set the OLSR main address to the first address on the indicated interface.
void RoutingTableComputation()
Creates the routing table of the node following RFC 3626 hints.
void SendMid()
Creates a new OLSR MID message which is buffered for being sent later on.
void AddEntry(const Ipv4Address &dest, const Ipv4Address &next, uint32_t interface, uint32_t distance)
Adds a new entry into the routing table.
void HnaTimerExpire()
Sends an HNA message (if the node has associated hosts/networks) and reschedules the HNA timer.
void AddIfaceAssocTuple(const IfaceAssocTuple &tuple)
Adds an interface association tuple to the Interface Association Set.
void RemoveDuplicateTuple(const DuplicateTuple &tuple)
Removes a duplicate tuple from the Duplicate Set.
const TopologySet & GetTopologySet() const
Gets the topology set.
void SendTc()
Creates a new OLSR TC message which is buffered for being sent later on.
void DupTupleTimerExpire(Ipv4Address address, uint16_t sequenceNumber)
Removes tuple if expired.
Ipv4Address GetMainAddress(Ipv4Address iface_addr) const
Gets the main address associated with a given interface address.
Timer m_midTimer
Timer for the MID message.
EventGarbageCollector m_events
Running events.
void SetIpv4(Ptr< Ipv4 > ipv4) override
bool Lookup(const Ipv4Address &dest, RoutingTableEntry &outEntry) const
Looks up an entry for the specified destination address.
void ProcessMid(const olsr::MessageHeader &msg, const Ipv4Address &senderIface)
Processes a MID message following RFC 3626 specification.
Ptr< const Ipv4StaticRouting > GetRoutingTableAssociation() const
Returns the internal HNA table.
Timer m_queuedMessagesTimer
timer for throttling outgoing messages
Willingness m_willingness
Willingness for forwarding packets on behalf of other nodes.
uint16_t m_ansn
Advertised Neighbor Set sequence number.
void RemoveIfaceAssocTuple(const IfaceAssocTuple &tuple)
Removed an interface association tuple to the Interface Association Set.
void NotifyInterfaceDown(uint32_t interface) override
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override
Time m_midInterval
MID messages' emission interval.
void Clear()
Clears the routing table and frees the memory assigned to each one of its entries.
void TopologyTupleTimerExpire(Ipv4Address destAddr, Ipv4Address lastAddr)
Removes topology tuple_ if expired.
void MprComputation()
Computes MPR set of a node following RFC 3626 hints.
void ProcessHello(const olsr::MessageHeader &msg, const Ipv4Address &receiverIface, const Ipv4Address &senderIface)
Processes a HELLO message following RFC 3626 specification.
static TypeId GetTypeId()
Get the type ID.
std::map< Ipv4Address, RoutingTableEntry > m_table
Data structure for the routing table.
void RemoveEntry(const Ipv4Address &dest)
Deletes the entry whose destination address is given.
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...
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
uint16_t m_packetSequenceNumber
Packets sequence number counter.
Timer m_helloTimer
Timer for the HELLO message.
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const override
Print the Routing Table entries.
~RoutingProtocol() override
int Degree(const NeighborTuple &tuple)
This auxiliary function (defined in RFC 3626) is used for calculating the MPR Set.
void RemoveMprSelectorTuple(const MprSelectorTuple &tuple)
Removes an MPR selector tuple from the MPR Selector Set.
void ProcessHna(const olsr::MessageHeader &msg, const Ipv4Address &senderIface)
Processes a HNA message following RFC 3626 specification.
Ptr< Socket > m_recvSocket
Receiving socket.
uint16_t GetPacketSequenceNumber()
Increments packet sequence number and returns the new value.
void DoInitialize() override
Initialize() implementation.
TracedCallback< const PacketHeader &, const MessageList & > m_txPacketTrace
Tx packet trace.
void IncrementAnsn()
Increments the ANSN counter.
Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr) override
Query routing cache for an existing route, for an outbound packet.
void SetInterfaceExclusions(std::set< uint32_t > exceptions)
Set the interfaces to be excluded.
void ForwardDefault(olsr::MessageHeader olsrMessage, DuplicateTuple *duplicated, const Ipv4Address &localIface, const Ipv4Address &senderAddress)
OLSR's default forwarding algorithm.
Time m_helloInterval
HELLO messages' emission interval.
Timer m_hnaTimer
Timer for the HNA message.
std::vector< RoutingTableEntry > GetRoutingTableEntries() const
Get the routing table entries.
void LinkTupleUpdated(const LinkTuple &tuple, Willingness willingness)
This function is invoked when a link tuple is updated.
void AddAssociationTuple(const AssociationTuple &tuple)
Adds a host network association tuple to the Association Set.
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.
TracedCallback< const PacketHeader &, const MessageList & > m_rxPacketTrace
Rx packet trace.
void Dump()
Dump the neighbor table, two-hop neighbor table, and routing table to logging output (NS_LOG_DEBUG lo...
void MidTimerExpire()
Sends a MID message (if the node has more than one interface) and resets the MID timer.
void RemoveTwoHopNeighborTuple(const TwoHopNeighborTuple &tuple)
Removes a 2-hop neighbor tuple from the 2-hop Neighbor Set.
void RemoveAssociationTuple(const AssociationTuple &tuple)
Removes a host network association tuple to the Association Set.
Time m_tcInterval
TC messages' emission interval.
bool UsesNonOlsrOutgoingInterface(const Ipv4RoutingTableEntry &route)
Tests whether or not the specified route uses a non-OLSR outgoing interface.
Ptr< Ipv4StaticRouting > m_routingTableAssociation
Associations from an Ipv4StaticRouting instance.
bool m_linkTupleTimerFirstTime
Flag to indicate if it is the first time the LinkTupleTimer fires.
const OlsrState & GetOlsrState() const
Gets the underlying OLSR state object.
uint16_t GetMessageSequenceNumber()
Increments message sequence number and returns the new value.
void RemoveNeighborTuple(const NeighborTuple &tuple)
Removes a neighbor tuple from the Neighbor Set.
void IfaceAssocTupleTimerExpire(Ipv4Address ifaceAddr)
Removes interface association tuple_ if expired.
void RecvOlsr(Ptr< Socket > socket)
Receive an OLSR message.
std::set< uint32_t > m_interfaceExclusions
Set of interfaces excluded by OSLR.
void NeighborLoss(const LinkTuple &tuple)
Performs all actions needed when a neighbor loss occurs.
Ptr< Ipv4 > m_ipv4
IPv4 object the routing is linked to.
void AddMprSelectorTuple(const MprSelectorTuple &tuple)
Adds an MPR selector tuple to the MPR Selector Set.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
NeighborType
OLSR neighbor types.
Willingness
Willingness for forwarding packets from other nodes.
@ UNSPEC_LINK
Unspecified link type.
@ LOST_LINK
Lost link type.
@ ASYM_LINK
Asymmetric link type.
@ SYM_LINK
Symmetric link type.
@ SYM_NEIGH
Symmetric neighbor type.
@ NOT_NEIGH
Not neighbor type.
@ MPR_NEIGH
Asymmetric neighbor type.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Time Now()
create an ns3::Time instance which contains the current simulation time.
Time Seconds(double value)
Construct a Time in the indicated unit.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
void CoverTwoHopNeighbors(Ipv4Address neighborMainAddr, TwoHopNeighborSet &N2)
Remove all covered 2-hop neighbors from N2 set.
std::ostream & operator<<(std::ostream &os, const PacketHeader &packet)
std::vector< MprSelectorTuple > MprSelectorSet
MPR Selector Set type.
std::vector< AssociationTuple > AssociationSet
Association Set type.
std::vector< TwoHopNeighborTuple > TwoHopNeighborSet
2-hop Neighbor Set type.
std::vector< LinkTuple > LinkSet
Link Set type.
std::vector< Association > Associations
Association Set type.
std::vector< TopologyTuple > TopologySet
Topology Set type.
std::set< Ipv4Address > MprSet
MPR Set type.
std::vector< NeighborTuple > NeighborSet
Neighbor Set type.
std::vector< MessageHeader > MessageList
std::vector< IfaceAssocTuple > IfaceAssocSet
Interface Association Set type.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Ptr< const AttributeChecker > MakeEnumChecker(T v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
#define JITTER
Random number between [0-OLSR_MAXJITTER] used to jitter OLSR packet transmission.
#define OLSR_HNA_HOLD_TIME
HNA holding time.
#define OLSR_NEIGHB_HOLD_TIME
Neighbor holding time.
#define OLSR_MAX_SEQ_NUM
Maximum allowed sequence number.
#define OLSR_TOP_HOLD_TIME
Top holding time.
#define OLSR_MID_HOLD_TIME
MID holding time.
#define OLSR_DUP_HOLD_TIME
Dup holding time.
#define OLSR_MAX_MSGS
Maximum number of messages per packet.
#define DELAY(time)
Gets the delay between a given time and the current time.
Time expirationTime
Time at which this tuple expires and must be removed.
Ipv4Address address
Originator address of the message.
An Interface Association Tuple.
Ipv4Address ifaceAddr
Interface address of a node.
Ipv4Address mainAddr
Main address of the node.
Ipv4Address neighborIfaceAddr
Interface address of the neighbor node.
Ipv4Address mainAddr
Main address of a node which have selected this node as a MPR.
Ipv4Address neighborMainAddr
Main address of a neighbor node.
Willingness willingness
A value between 0 and 7 specifying the node's willingness to carry traffic on behalf of other nodes.
Status status
Status of the link.
An OLSR's routing table entry.
Ipv4Address destAddr
Address of the destination node.
Ipv4Address destAddr
Main address of the destination.
Time expirationTime
Time at which this tuple expires and must be removed.
Ipv4Address neighborMainAddr
Main address of a neighbor.