This is the implementation of the ICMP protocol as described in RFC 792. More...
#include "icmpv4-l4-protocol.h"
Public Member Functions | |
Icmpv4L4Protocol () | |
~Icmpv4L4Protocol () override | |
IpL4Protocol::DownTargetCallback | GetDownTarget () const override |
This method allows a caller to get the current down target callback set for this L4 protocol (IPv4 case) More... | |
IpL4Protocol::DownTargetCallback6 | GetDownTarget6 () const override |
This method allows a caller to get the current down target callback set for this L4 protocol (IPv6 case) More... | |
int | GetProtocolNumber () const override |
Get the protocol number. More... | |
IpL4Protocol::RxStatus | Receive (Ptr< Packet > p, const Ipv4Header &header, Ptr< Ipv4Interface > incomingInterface) override |
Receive method. More... | |
IpL4Protocol::RxStatus | Receive (Ptr< Packet > p, const Ipv6Header &header, Ptr< Ipv6Interface > incomingInterface) override |
Receive method. More... | |
void | SendDestUnreachFragNeeded (Ipv4Header header, Ptr< const Packet > orgData, uint16_t nextHopMtu) |
Send a Destination Unreachable - Fragmentation needed ICMP error. More... | |
void | SendDestUnreachPort (Ipv4Header header, Ptr< const Packet > orgData) |
Send a Time Exceeded ICMP error. More... | |
void | SendTimeExceededTtl (Ipv4Header header, Ptr< const Packet > orgData, bool isFragment) |
Send a Time Exceeded ICMP error. More... | |
void | SetDownTarget (IpL4Protocol::DownTargetCallback cb) override |
This method allows a caller to set the current down target callback set for this L4 protocol (IPv4 case) More... | |
void | SetDownTarget6 (IpL4Protocol::DownTargetCallback6 cb) override |
This method allows a caller to set the current down target callback set for this L4 protocol (IPv6 case) More... | |
void | SetNode (Ptr< Node > node) |
Set the node the protocol is associated with. More... | |
Public Member Functions inherited from ns3::IpL4Protocol | |
~IpL4Protocol () override | |
virtual void | ReceiveIcmp (Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo, Ipv4Address payloadSource, Ipv4Address payloadDestination, const uint8_t payload[8]) |
Called from lower-level layers to send the ICMP packet up in the stack. More... | |
virtual void | ReceiveIcmp (Ipv6Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo, Ipv6Address payloadSource, Ipv6Address payloadDestination, const uint8_t payload[8]) |
Called from lower-level layers to send the ICMPv6 packet up in the stack. More... | |
Public Member Functions inherited from ns3::Object | |
Object () | |
Constructor. More... | |
~Object () override | |
Destructor. More... | |
void | AggregateObject (Ptr< Object > other) |
Aggregate two Objects together. More... | |
void | Dispose () |
Dispose of this Object. More... | |
AggregateIterator | GetAggregateIterator () const |
Get an iterator to the Objects aggregated to this one. More... | |
TypeId | GetInstanceTypeId () const override |
Get the most derived TypeId for this Object. More... | |
template<typename T > | |
Ptr< T > | GetObject () const |
Get a pointer to the requested aggregated Object. More... | |
template<> | |
Ptr< Object > | GetObject () const |
Specialization of () for objects of type ns3::Object. More... | |
template<typename T > | |
Ptr< T > | GetObject (TypeId tid) const |
Get a pointer to the requested aggregated Object by TypeId. More... | |
template<> | |
Ptr< Object > | GetObject (TypeId tid) const |
Specialization of (TypeId tid) for objects of type ns3::Object. More... | |
void | Initialize () |
Invoke DoInitialize on all Objects aggregated to this one. More... | |
bool | IsInitialized () const |
Check if the object has been initialized. More... | |
Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter > | |
SimpleRefCount () | |
Default constructor. More... | |
SimpleRefCount (const SimpleRefCount &o[[maybe_unused]]) | |
Copy constructor. More... | |
uint32_t | GetReferenceCount () const |
Get the reference count of the object. More... | |
SimpleRefCount & | operator= (const SimpleRefCount &o[[maybe_unused]]) |
Assignment operator. More... | |
void | Ref () const |
Increment the reference count. More... | |
void | Unref () const |
Decrement the reference count. More... | |
Public Member Functions inherited from ns3::ObjectBase | |
virtual | ~ObjectBase () |
Virtual destructor. More... | |
void | GetAttribute (std::string name, AttributeValue &value) const |
Get the value of an attribute, raising fatal errors if unsuccessful. More... | |
bool | GetAttributeFailSafe (std::string name, AttributeValue &value) const |
Get the value of an attribute without raising errors. More... | |
void | SetAttribute (std::string name, const AttributeValue &value) |
Set a single attribute, raising fatal errors if unsuccessful. More... | |
bool | SetAttributeFailSafe (std::string name, const AttributeValue &value) |
Set a single attribute without raising errors. More... | |
bool | TraceConnect (std::string name, std::string context, const CallbackBase &cb) |
Connect a TraceSource to a Callback with a context. More... | |
bool | TraceConnectWithoutContext (std::string name, const CallbackBase &cb) |
Connect a TraceSource to a Callback without a context. More... | |
bool | TraceDisconnect (std::string name, std::string context, const CallbackBase &cb) |
Disconnect from a TraceSource a Callback previously connected with a context. More... | |
bool | TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb) |
Disconnect from a TraceSource a Callback previously connected without a context. More... | |
Static Public Member Functions | |
static uint16_t | GetStaticProtocolNumber () |
Get the protocol number. More... | |
static TypeId | GetTypeId () |
Get the type ID. More... | |
Static Public Member Functions inherited from ns3::IpL4Protocol | |
static TypeId | GetTypeId () |
Get the type ID. More... | |
Static Public Member Functions inherited from ns3::Object | |
static TypeId | GetTypeId () |
Register this type. More... | |
Static Public Member Functions inherited from ns3::ObjectBase | |
static TypeId | GetTypeId () |
Get the type ID. More... | |
Static Public Attributes | |
static const uint8_t | PROT_NUMBER = 1 |
ICMP protocol number (0x1) More... | |
Protected Member Functions | |
void | NotifyNewAggregate () override |
Notify all Objects aggregated to this one of a new Object being aggregated. More... | |
Protected Member Functions inherited from ns3::Object | |
Object (const Object &o) | |
Copy an Object. More... | |
virtual void | DoInitialize () |
Initialize() implementation. More... | |
Protected Member Functions inherited from ns3::ObjectBase | |
void | ConstructSelf (const AttributeConstructionList &attributes) |
Complete construction of ObjectBase; invoked by derived classes. More... | |
virtual void | NotifyConstructionCompleted () |
Notifier called once the ObjectBase is fully constructed. More... | |
Private Member Functions | |
void | DoDispose () override |
Destructor implementation. More... | |
void | Forward (Ipv4Address source, Icmpv4Header icmp, uint32_t info, Ipv4Header ipHeader, const uint8_t payload[8]) |
Forward the message to an L4 protocol. More... | |
void | HandleDestUnreach (Ptr< Packet > p, Icmpv4Header header, Ipv4Address source, Ipv4Address destination) |
Handles an incoming ICMP Destination Unreachable packet. More... | |
void | HandleEcho (Ptr< Packet > p, Icmpv4Header header, Ipv4Address source, Ipv4Address destination, uint8_t tos) |
Handles an incoming ICMP Echo packet. More... | |
void | HandleTimeExceeded (Ptr< Packet > p, Icmpv4Header icmp, Ipv4Address source, Ipv4Address destination) |
Handles an incoming ICMP Time Exceeded packet. More... | |
void | SendDestUnreach (Ipv4Header header, Ptr< const Packet > orgData, uint8_t code, uint16_t nextHopMtu) |
Send an ICMP Destination Unreachable packet. More... | |
void | SendMessage (Ptr< Packet > packet, Ipv4Address dest, uint8_t type, uint8_t code) |
Send a generic ICMP packet. More... | |
void | SendMessage (Ptr< Packet > packet, Ipv4Address source, Ipv4Address dest, uint8_t type, uint8_t code, Ptr< Ipv4Route > route) |
Send a generic ICMP packet. More... | |
Private Attributes | |
IpL4Protocol::DownTargetCallback | m_downTarget |
callback to Ipv4::Send More... | |
Ptr< Node > | m_node |
the node this protocol is associated with More... | |
Additional Inherited Members | |
Public Types inherited from ns3::IpL4Protocol | |
typedef Callback< void, Ptr< Packet >, Ipv4Address, Ipv4Address, uint8_t, Ptr< Ipv4Route > > | DownTargetCallback |
callback to send packets over IPv4 More... | |
typedef Callback< void, Ptr< Packet >, Ipv6Address, Ipv6Address, uint8_t, Ptr< Ipv6Route > > | DownTargetCallback6 |
callback to send packets over IPv6 More... | |
enum | RxStatus { RX_OK , RX_CSUM_FAILED , RX_ENDPOINT_CLOSED , RX_ENDPOINT_UNREACH } |
Rx status codes. More... | |
Related Functions inherited from ns3::ObjectBase | |
static TypeId | GetObjectIid () |
Ensure the TypeId for ObjectBase gets fully configured to anchor the inheritance tree properly. More... | |
This is the implementation of the ICMP protocol as described in RFC 792.
Definition at line 46 of file icmpv4-l4-protocol.h.
ns3::Icmpv4L4Protocol::Icmpv4L4Protocol | ( | ) |
Definition at line 55 of file icmpv4-l4-protocol.cc.
References NS_LOG_FUNCTION.
|
override |
Definition at line 61 of file icmpv4-l4-protocol.cc.
References m_node, NS_ASSERT, and NS_LOG_FUNCTION.
|
overrideprivatevirtual |
Destructor implementation.
This method is called by Dispose() or by the Object's destructor, whichever comes first.
Subclasses are expected to implement their real destruction code in an overridden version of this method and chain up to their parent's implementation once they are done. i.e, for simplicity, the destructor of every subclass should be empty and its content should be moved to the associated DoDispose() method.
It is safe to call GetObject() from within this method.
Reimplemented from ns3::Object.
Definition at line 361 of file icmpv4-l4-protocol.cc.
References ns3::Object::DoDispose(), m_downTarget, m_node, NS_LOG_FUNCTION, and ns3::Callback< R, UArgs >::Nullify().
|
private |
Forward the message to an L4 protocol.
source | the source |
icmp | the ICMP header |
info | info data (e.g., the target MTU) |
ipHeader | the IP header carried by ICMP |
payload | payload chunk carried by ICMP |
Definition at line 241 of file icmpv4-l4-protocol.cc.
References ns3::Icmpv4Header::GetCode(), ns3::Ipv4Header::GetDestination(), ns3::Object::GetObject(), ns3::Ipv4Header::GetProtocol(), ns3::Ipv4Header::GetSource(), ns3::Ipv4Header::GetTtl(), ns3::Icmpv4Header::GetType(), nsclick-simple-lan::ipv4, m_node, and NS_LOG_FUNCTION.
Referenced by HandleDestUnreach(), and HandleTimeExceeded().
|
overridevirtual |
This method allows a caller to get the current down target callback set for this L4 protocol (IPv4 case)
Implements ns3::IpL4Protocol.
Definition at line 383 of file icmpv4-l4-protocol.cc.
References m_downTarget, and NS_LOG_FUNCTION.
|
overridevirtual |
This method allows a caller to get the current down target callback set for this L4 protocol (IPv6 case)
Implements ns3::IpL4Protocol.
Definition at line 390 of file icmpv4-l4-protocol.cc.
References NS_LOG_FUNCTION.
|
overridevirtual |
Get the protocol number.
Implements ns3::IpL4Protocol.
Definition at line 110 of file icmpv4-l4-protocol.cc.
References NS_LOG_FUNCTION, and PROT_NUMBER.
|
static |
Get the protocol number.
Definition at line 103 of file icmpv4-l4-protocol.cc.
References NS_LOG_FUNCTION_NOARGS, and PROT_NUMBER.
Referenced by ns3::Ipv4L3ClickProtocol::GetIcmp(), and ns3::Ipv4L3Protocol::GetIcmp().
|
static |
Get the type ID.
Definition at line 46 of file icmpv4-l4-protocol.cc.
References ns3::TypeId::SetParent().
|
private |
Handles an incoming ICMP Destination Unreachable packet.
p | the packet |
header | the IP header |
source | the source address |
destination | the destination address |
Definition at line 265 of file icmpv4-l4-protocol.cc.
References Forward(), ns3::Icmpv4DestinationUnreachable::GetData(), ns3::Icmpv4DestinationUnreachable::GetHeader(), ns3::Icmpv4DestinationUnreachable::GetNextHopMtu(), NS_LOG_FUNCTION, and ns3::Packet::PeekHeader().
Referenced by Receive().
|
private |
Handles an incoming ICMP Echo packet.
p | the packet |
header | the IP header |
source | the source address |
destination | the destination address |
tos | the type of service |
Definition at line 222 of file icmpv4-l4-protocol.cc.
References ns3::Packet::AddHeader(), ns3::Icmpv4Header::ICMPV4_ECHO_REPLY, NS_LOG_FUNCTION, ns3::Packet::RemoveHeader(), ns3::Packet::ReplacePacketTag(), SendMessage(), and ns3::SocketIpTosTag::SetTos().
Referenced by Receive().
|
private |
Handles an incoming ICMP Time Exceeded packet.
p | the packet |
icmp | the ICMP header |
source | the source address |
destination | the destination address |
Definition at line 281 of file icmpv4-l4-protocol.cc.
References Forward(), ns3::Icmpv4TimeExceeded::GetData(), ns3::Icmpv4TimeExceeded::GetHeader(), NS_LOG_FUNCTION, and ns3::Packet::PeekHeader().
Referenced by Receive().
|
overrideprotectedvirtual |
Notify all Objects aggregated to this one of a new Object being aggregated.
This function must be implemented in the stack that needs to notify other stacks connected to the node of their presence in the node.
This method is invoked whenever two sets of Objects are aggregated together. It is invoked exactly once for each Object in both sets. This method can be overridden by subclasses who wish to be notified of aggregation events. These subclasses must chain up to their base class NotifyNewAggregate() method.
It is safe to call GetObject() and AggregateObject() from within this method.
Reimplemented from ns3::Object.
Definition at line 80 of file icmpv4-l4-protocol.cc.
References nsclick-simple-lan::ipv4, ns3::Callback< R, UArgs >::IsNull(), m_downTarget, m_node, ns3::MakeCallback(), ns3::Object::NotifyNewAggregate(), NS_LOG_FUNCTION, ns3::Ipv4::Send(), SetDownTarget(), and SetNode().
|
overridevirtual |
Receive method.
p | the packet |
header | the IPv4 header |
incomingInterface | the interface from which the packet is coming |
Implements ns3::IpL4Protocol.
Definition at line 298 of file icmpv4-l4-protocol.cc.
References ns3::Ipv4InterfaceAddress::GetAddress(), ns3::Ipv4Interface::GetAddress(), ns3::Ipv4InterfaceAddress::GetBroadcast(), ns3::Ipv4Header::GetDestination(), ns3::Ipv4Interface::GetNAddresses(), ns3::Ipv4Header::GetSource(), ns3::Ipv4Header::GetTos(), ns3::Icmpv4Header::GetType(), HandleDestUnreach(), HandleEcho(), HandleTimeExceeded(), ns3::Icmpv4Header::ICMPV4_DEST_UNREACH, ns3::Icmpv4Header::ICMPV4_ECHO, ns3::Icmpv4Header::ICMPV4_TIME_EXCEEDED, ns3::Ipv4Address::IsBroadcast(), ns3::Ipv4InterfaceAddress::IsInSameSubnet(), NS_LOG_DEBUG, NS_LOG_FUNCTION, ns3::Packet::RemoveHeader(), and ns3::IpL4Protocol::RX_OK.
|
overridevirtual |
Receive method.
p | the packet |
header | the IPv6 header |
incomingInterface | the interface from which the packet is coming |
Implements ns3::IpL4Protocol.
Definition at line 351 of file icmpv4-l4-protocol.cc.
References ns3::Ipv6Header::GetDestination(), ns3::Ipv6Header::GetSource(), NS_LOG_FUNCTION, and ns3::IpL4Protocol::RX_ENDPOINT_UNREACH.
|
private |
Send an ICMP Destination Unreachable packet.
header | the original IP header |
orgData | the original packet |
code | the ICMP code |
nextHopMtu | the next hop MTU |
Definition at line 181 of file icmpv4-l4-protocol.cc.
References ns3::Packet::AddHeader(), ns3::Ipv4Header::GetSource(), ns3::Icmpv4Header::ICMPV4_DEST_UNREACH, NS_LOG_FUNCTION, SendMessage(), ns3::Icmpv4DestinationUnreachable::SetData(), ns3::Icmpv4DestinationUnreachable::SetHeader(), and ns3::Icmpv4DestinationUnreachable::SetNextHopMtu().
Referenced by SendDestUnreachFragNeeded(), and SendDestUnreachPort().
void ns3::Icmpv4L4Protocol::SendDestUnreachFragNeeded | ( | Ipv4Header | header, |
Ptr< const Packet > | orgData, | ||
uint16_t | nextHopMtu | ||
) |
Send a Destination Unreachable - Fragmentation needed ICMP error.
header | the original IP header |
orgData | the original packet |
nextHopMtu | the next hop MTU |
Definition at line 165 of file icmpv4-l4-protocol.cc.
References ns3::Icmpv4DestinationUnreachable::ICMPV4_FRAG_NEEDED, NS_LOG_FUNCTION, and SendDestUnreach().
void ns3::Icmpv4L4Protocol::SendDestUnreachPort | ( | Ipv4Header | header, |
Ptr< const Packet > | orgData | ||
) |
Send a Time Exceeded ICMP error.
header | the original IP header |
orgData | the original packet |
Definition at line 174 of file icmpv4-l4-protocol.cc.
References ns3::Icmpv4DestinationUnreachable::ICMPV4_PORT_UNREACHABLE, NS_LOG_FUNCTION, and SendDestUnreach().
|
private |
Send a generic ICMP packet.
packet | the packet |
dest | the destination |
type | the ICMP type |
code | the ICMP code |
Definition at line 117 of file icmpv4-l4-protocol.cc.
References ns3::Object::GetObject(), nsclick-simple-lan::ipv4, m_node, NS_ASSERT, NS_LOG_FUNCTION, NS_LOG_LOGIC, NS_LOG_WARN, PROT_NUMBER, ns3::Ipv4Header::SetDestination(), ns3::Ipv4Header::SetProtocol(), and check-style-clang-format::type.
Referenced by HandleEcho(), SendDestUnreach(), and SendTimeExceededTtl().
|
private |
Send a generic ICMP packet.
packet | the packet |
source | the source |
dest | the destination |
type | the ICMP type |
code | the ICMP code |
route | the route to be used |
Definition at line 143 of file icmpv4-l4-protocol.cc.
References ns3::Packet::AddHeader(), ns3::Node::ChecksumEnabled(), ns3::Icmpv4Header::EnableChecksum(), m_downTarget, NS_LOG_FUNCTION, PROT_NUMBER, ns3::Icmpv4Header::SetCode(), ns3::Icmpv4Header::SetType(), and check-style-clang-format::type.
void ns3::Icmpv4L4Protocol::SendTimeExceededTtl | ( | Ipv4Header | header, |
Ptr< const Packet > | orgData, | ||
bool | isFragment | ||
) |
Send a Time Exceeded ICMP error.
header | the original IP header |
orgData | the original packet |
isFragment | true if the opcode must be FRAGMENT_REASSEMBLY |
Definition at line 197 of file icmpv4-l4-protocol.cc.
References ns3::Packet::AddHeader(), ns3::Ipv4Header::GetSource(), ns3::Icmpv4TimeExceeded::ICMPV4_FRAGMENT_REASSEMBLY, ns3::Icmpv4Header::ICMPV4_TIME_EXCEEDED, ns3::Icmpv4TimeExceeded::ICMPV4_TIME_TO_LIVE, NS_LOG_FUNCTION, SendMessage(), ns3::Icmpv4TimeExceeded::SetData(), and ns3::Icmpv4TimeExceeded::SetHeader().
|
overridevirtual |
This method allows a caller to set the current down target callback set for this L4 protocol (IPv4 case)
cb | current Callback for the L4 protocol |
Implements ns3::IpL4Protocol.
Definition at line 370 of file icmpv4-l4-protocol.cc.
References m_downTarget, and NS_LOG_FUNCTION.
Referenced by NotifyNewAggregate().
|
overridevirtual |
This method allows a caller to set the current down target callback set for this L4 protocol (IPv6 case)
cb | current Callback for the L4 protocol |
Implements ns3::IpL4Protocol.
Definition at line 377 of file icmpv4-l4-protocol.cc.
References NS_LOG_FUNCTION.
Set the node the protocol is associated with.
node | the node |
Definition at line 68 of file icmpv4-l4-protocol.cc.
References m_node, and NS_LOG_FUNCTION.
Referenced by NotifyNewAggregate().
|
private |
callback to Ipv4::Send
Definition at line 230 of file icmpv4-l4-protocol.h.
Referenced by DoDispose(), GetDownTarget(), NotifyNewAggregate(), SendMessage(), and SetDownTarget().
the node this protocol is associated with
Definition at line 229 of file icmpv4-l4-protocol.h.
Referenced by ~Icmpv4L4Protocol(), DoDispose(), Forward(), NotifyNewAggregate(), SendMessage(), and SetNode().
|
static |
ICMP protocol number (0x1)
Definition at line 54 of file icmpv4-l4-protocol.h.
Referenced by GetProtocolNumber(), GetStaticProtocolNumber(), ns3::V4TraceRoute::Receive(), SendMessage(), and ns3::V4TraceRoute::StartApplication().