20#define NS_LOG_APPEND_CONTEXT \
21 if (GetObject<Node>()) \
23 std::clog << "[node " << GetObject<Node>()->GetId() << "] "; \
31#include "ns3/assert.h"
32#include "ns3/fatal-error.h"
33#include "ns3/icmpv4-l4-protocol.h"
34#include "ns3/ip-l4-protocol.h"
35#include "ns3/ipv4-address.h"
36#include "ns3/ipv4-header.h"
37#include "ns3/ipv4-interface.h"
38#include "ns3/ipv4-l3-protocol.h"
39#include "ns3/ipv4-route.h"
41#include "ns3/node-list.h"
43#include "ns3/object-vector.h"
44#include "ns3/pointer.h"
46#include "ns3/trace-source-accessor.h"
47#include "ns3/udp-header.h"
48#include "ns3/uinteger.h"
71 .AddAttribute(
"OptionNumber",
72 "The Dsr option number.",
76 .AddTraceSource(
"Drop",
79 "ns3::Packet::TracedCallback")
81 "Receive DSR packet.",
83 "ns3::dsr::DsrOptionSRHeader::TracedCallback");
129std::vector<Ipv4Address>
158 std::reverse(
vec.begin(),
vec.end());
182 for (
auto i =
vec.begin();
i !=
vec.end(); ++
i)
191 NS_LOG_DEBUG(
"next hop address not found, route corrupted");
217 NS_LOG_DEBUG(
"next hop address not found, route corrupted");
256 for (
auto i =
vec.begin();
i !=
vec.end(); ++
i)
267 for (
auto i =
vec.begin();
i !=
vec.end(); ++
i)
284 for (
auto i =
vec.begin();
i !=
vec.end(); ++
i)
300 std::vector<Ipv4Address>
vec2(
vec);
311 for (
auto j =
vec.begin();
j !=
vec.end(); ++
j)
315 if ((
j + 1) !=
vec.end())
322 else if (
j == (
vec.end() - 1))
340 if (ipv4->GetAddress(1, 0).GetLocal() == address)
524 NS_LOG_DEBUG(
"Discard the packet since it was originated from same source address");
542 p->CopyData(buf,
sizeof(buf));
547 NS_LOG_DEBUG(
"Discard the packet, malformed header since two many ip addresses in route");
561 p->RemoveHeader(
rreq);
563 uint8_t length =
rreq.GetLength();
624 NS_LOG_DEBUG(
"Our node address is already seen in the route, drop the request");
716 if (dsr->IsLinkCache())
754 if (nextHop ==
"0.0.0.0")
763 dsr->SendPacketFromBuffer(
sourceRoute, nextHop, protocol);
765 dsr->CancelRreqTimer(dst,
true);
779 return rreq.GetSerializedSize();
803 for (
auto j =
ip.begin();
j !=
ip.end(); ++
j)
827 if (dsr->IsLinkCache())
838 NS_LOG_LOGIC(
"We have added the route and search send buffer for packet with "
859 if (nextHop ==
"0.0.0.0")
868 dsr->SendPacketFromBuffer(
sourceRoute, nextHop, protocol);
870 dsr->CancelRreqTimer(dst,
true);
920 return rreq.GetSerializedSize();
938 p->RemoveHeader(
rerr);
946 uint16_t length =
rreq.GetLength();
963 NS_LOG_DEBUG(
"The RREQ and newUnreach header length " << length);
971 uint16_t length =
rreq.GetLength();
990 dsr->ScheduleInterRequest(
interP);
993 return rreq.GetSerializedSize();
1006 .SetGroupName(
"Dsr")
1052 p->CopyData(buf,
sizeof(buf));
1058 p->RemoveHeader(
rrep);
1065 std::vector<Ipv4Address>
nodeList =
rrep.GetNodesAddress();
1095 if (dsr->IsLinkCache())
1107 "We have added the route and search send buffer for packet with destination "
1119 if (nextHop ==
"0.0.0.0")
1127 dsr->CancelRreqTimer(dst,
true);
1131 dsr->SendPacketFromBuffer(
sourceRoute, nextHop, protocol);
1141 uint8_t length =
rrep.GetLength() -
1145 if (length % 2 != 0)
1162 NS_LOG_DEBUG(
"The route destination after cut " << dst);
1168 if (dsr->IsLinkCache())
1178 dsr->CancelRreqTimer(dst,
true);
1195 NS_LOG_DEBUG(
"The nextHop address " << nextHop <<
" and the source in the route reply "
1207 length =
rrep.GetLength();
1219 return rrep.GetSerializedSize();
1229 .SetGroupName(
"Dsr")
1272 p->CopyData(buf,
sizeof(buf));
1302 NS_LOG_LOGIC(
"We process promiscuous receipt data packet");
1314 NS_LOG_DEBUG(
"Process the promiscuously received packet");
1340 NS_LOG_DEBUG(
"We find one previously received passive entry");
1355 dsr->PassiveEntryCheck(packet,
1378 auto data =
new uint8_t[size];
1379 p->CopyData(
data, size);
1386 NS_LOG_LOGIC(
"Remove the ack request header and add ack header to the packet");
1431 if (length % 2 != 0)
1452 NS_LOG_DEBUG(
"The next address of source route option "
1454 <<
" and the segments left : " << (
uint32_t)segsLeft);
1466 if (nextHop ==
"0.0.0.0")
1488 dsr->ForwardPacket(
dsrP,
1507 .SetGroupName(
"Dsr")
1549 auto data =
new uint8_t[size];
1550 p->CopyData(
data, size);
1617 p->CopyData(buf,
sizeof(buf));
1648 if (length % 2 != 0)
1666 NS_LOG_INFO(
"This is the destination of the error, send error request");
1667 dsr->SendErrorRequest(
rerr, protocol);
1698 static TypeId tid =
TypeId(
"ns3::dsr::DsrOptionAckReq")
1700 .SetGroupName(
"Dsr")
1758 return ackReq.GetSerializedSize();
1768 .SetGroupName(
"Dsr")
1813 p->RemoveHeader(
ack);
1825 dsr->UpdateRouteEntry(
realDst);
1830 return ack.GetSerializedSize();
Ipv4 addresses are stored in host order in this class.
Access to the IPv4 forwarding table, interfaces, and configuration.
static uint32_t GetNNodes()
static Ptr< Node > GetNode(uint32_t n)
A base class which provides memory management and object aggregation.
Smart pointer class similar to boost::intrusive_ptr.
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer.
void SetTtl(uint8_t ttl)
Set the tag's TTL.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
uint8_t Process(Ptr< Packet > packet, Ptr< Packet > dsrP, Ipv4Address ipv4Address, Ipv4Address source, const Ipv4Header &ipv4Header, uint8_t protocol, bool &isPromisc, Ipv4Address promiscSource) override
Process method.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
static const uint8_t OPT_NUMBER
The Dsr Ack option number.
static TypeId GetTypeId()
Get the type ID.
uint8_t GetOptionNumber() const override
Get the option number.
static TypeId GetTypeId()
Get the type ID.
uint8_t GetOptionNumber() const override
Get the option number.
uint8_t Process(Ptr< Packet > packet, Ptr< Packet > dsrP, Ipv4Address ipv4Address, Ipv4Address source, const Ipv4Header &ipv4Header, uint8_t protocol, bool &isPromisc, Ipv4Address promiscSource) override
Process method.
~DsrOptionAckReq() override
static const uint8_t OPT_NUMBER
Dsr ack request option number.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
uint8_t GetOptionNumber() const override
Get the option number.
static TypeId GetTypeId()
Get the type ID.
~DsrOptionPad1() override
uint8_t Process(Ptr< Packet > packet, Ptr< Packet > dsrP, Ipv4Address ipv4Address, Ipv4Address source, const Ipv4Header &ipv4Header, uint8_t protocol, bool &isPromisc, Ipv4Address promiscSource) override
Process method.
static const uint8_t OPT_NUMBER
Pad1 option number.
static const uint8_t OPT_NUMBER
PadN option number.
uint8_t Process(Ptr< Packet > packet, Ptr< Packet > dsrP, Ipv4Address ipv4Address, Ipv4Address source, const Ipv4Header &ipv4Header, uint8_t protocol, bool &isPromisc, Ipv4Address promiscSource) override
Process method.
static TypeId GetTypeId()
Get the type ID.
uint8_t GetOptionNumber() const override
Get the option number.
~DsrOptionPadn() override
uint8_t DoSendError(Ptr< Packet > p, DsrOptionRerrUnreachHeader &rerr, uint32_t rerrSize, Ipv4Address ipv4Address, uint8_t protocol)
Do Send error message.
static const uint8_t OPT_NUMBER
Dsr Route Error option number.
static TypeId GetTypeId()
Get the type ID.
~DsrOptionRerr() override
uint8_t Process(Ptr< Packet > packet, Ptr< Packet > dsrP, Ipv4Address ipv4Address, Ipv4Address source, const Ipv4Header &ipv4Header, uint8_t protocol, bool &isPromisc, Ipv4Address promiscSource) override
Process method.
uint8_t GetOptionNumber() const override
Get the option number.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
static const uint8_t OPT_NUMBER
Router alert option number.
static TypeId GetTypeId()
Get the type ID.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
uint8_t GetOptionNumber() const override
Get the option number.
~DsrOptionRrep() override
uint8_t Process(Ptr< Packet > packet, Ptr< Packet > dsrP, Ipv4Address ipv4Address, Ipv4Address source, const Ipv4Header &ipv4Header, uint8_t protocol, bool &isPromisc, Ipv4Address promiscSource) override
Process method.
static TypeId GetTypeId()
Get the type ID.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
static const uint8_t OPT_NUMBER
Rreq option number.
uint8_t Process(Ptr< Packet > packet, Ptr< Packet > dsrP, Ipv4Address ipv4Address, Ipv4Address source, const Ipv4Header &ipv4Header, uint8_t protocol, bool &isPromisc, Ipv4Address promiscSource) override
Process method.
uint8_t GetOptionNumber() const override
Get the option number.
~DsrOptionRreq() override
Destructor.
DsrOptionRreq()
Constructor.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
static const uint8_t OPT_NUMBER
Source Route option number.
uint8_t Process(Ptr< Packet > packet, Ptr< Packet > dsrP, Ipv4Address ipv4Address, Ipv4Address source, const Ipv4Header &ipv4Header, uint8_t protocol, bool &isPromisc, Ipv4Address promiscSource) override
Process method.
uint8_t GetOptionNumber() const override
Get the option number.
static TypeId GetTypeId()
Get the type ID.
Introspection did not find any typical Config paths.
Ipv4Address SearchNextHop(Ipv4Address ipv4Address, std::vector< Ipv4Address > &vec)
Search for the next hop in the route.
Ipv4Address ReverseSearchNextTwoHop(Ipv4Address ipv4Address, std::vector< Ipv4Address > &vec)
Reverse search for the next two hop in the route.
TracedCallback< Ptr< const Packet > > m_dropTrace
Drop trace callback.
Ptr< Node > GetNodeWithAddress(Ipv4Address ipv4Address)
Get the node object with Ipv4Address.
Ptr< Node > GetNode() const
Get the node.
Time ActiveRouteTimeout
The active route timeout value.
bool CheckDuplicates(Ipv4Address ipv4Address, std::vector< Ipv4Address > &vec)
Check if the route already contains the node ip address.
void SetNode(Ptr< Node > node)
Set the node.
virtual uint8_t GetOptionNumber() const =0
Get the option number.
~DsrOptions() override
Destructor.
std::vector< Ipv4Address > m_finalRoute
The vector of final Ipv4 address.
void PrintVector(std::vector< Ipv4Address > &vec)
Print out the elements in the route vector.
bool IfDuplicates(std::vector< Ipv4Address > &vec, std::vector< Ipv4Address > &vec2)
Check if the two vectors contain duplicate or not.
bool ReverseRoutes(std::vector< Ipv4Address > &vec)
Reverse the routes.
void RemoveDuplicates(std::vector< Ipv4Address > &vec)
Remove the duplicates from the route.
uint32_t GetIDfromIP(Ipv4Address address)
Get the node id with Ipv4Address.
static TypeId GetTypeId()
Get the type identificator.
std::vector< Ipv4Address > CutRoute(Ipv4Address ipv4Address, std::vector< Ipv4Address > &nodeList)
Cut the route from ipv4Address to the end of the route vector.
bool ContainAddressAfter(Ipv4Address ipv4Address, Ipv4Address destAddress, std::vector< Ipv4Address > &nodeList)
Search for the ipv4 address in the node list.
TracedCallback< const DsrOptionSRHeader & > m_rxPacketTrace
The receive trace back, only triggered when final destination receive data packet.
Ipv4Address ReverseSearchNextHop(Ipv4Address ipv4Address, std::vector< Ipv4Address > &vec)
Reverse search for the next hop in the route.
Ptr< Ipv4Route > m_ipv4Route
The ipv4 route.
virtual Ptr< Ipv4Route > SetRoute(Ipv4Address nextHop, Ipv4Address srcAddress)
Set the route to use for data packets, used by the option headers when sending data/control packets.
Ptr< Node > m_node
the node
DsrRouteCacheEntry class for entries in the route cache.
std::vector< Ipv4Address > IP_VECTOR
Define the vector to hold Ip address.
bool CancelPassiveTimer(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t segsLeft)
Cancel the passive timer.
bool PassiveEntryCheck(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t segsLeft, uint16_t fragmentOffset, uint16_t identification, bool saveEntry)
Find the same passive entry.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#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_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.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)