An implementation of the ARP protocol. More...
#include "arp-l3-protocol.h"
Public Member Functions | |
ArpL3Protocol () | |
ArpL3Protocol (const ArpL3Protocol &)=delete | |
virtual | ~ArpL3Protocol () |
int64_t | AssignStreams (int64_t stream) |
Assign a fixed random variable stream number to the random variables used by this model. More... | |
Ptr< ArpCache > | CreateCache (Ptr< NetDevice > device, Ptr< Ipv4Interface > interface) |
Create an ARP cache for the device/interface. More... | |
bool | Lookup (Ptr< Packet > p, const Ipv4Header &ipHeader, Ipv4Address destination, Ptr< NetDevice > device, Ptr< ArpCache > cache, Address *hardwareDestination) |
Perform an ARP lookup. More... | |
ArpL3Protocol & | operator= (const ArpL3Protocol &)=delete |
void | Receive (Ptr< NetDevice > device, Ptr< const Packet > p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType) |
Receive a packet. More... | |
void | SetNode (Ptr< Node > node) |
Set the node the ARP L3 protocol is associated with. More... | |
void | SetTrafficControl (Ptr< TrafficControlLayer > tc) |
Set the TrafficControlLayer. More... | |
Public Member Functions inherited from ns3::Object | |
Object () | |
Constructor. More... | |
virtual | ~Object () |
Destructor. More... | |
void | AggregateObject (Ptr< Object > other) |
Aggregate two Objects together. More... | |
void | Dispose (void) |
Dispose of this Object. More... | |
AggregateIterator | GetAggregateIterator (void) const |
Get an iterator to the Objects aggregated to this one. More... | |
virtual TypeId | GetInstanceTypeId (void) const |
Get the most derived TypeId for this 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... | |
template<typename T > | |
Ptr< T > | GetObject (void) const |
Get a pointer to the requested aggregated Object. More... | |
void | Initialize (void) |
Invoke DoInitialize on all Objects aggregated to this one. More... | |
bool | IsInitialized (void) 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 (void) const |
Get the reference count of the object. More... | |
SimpleRefCount & | operator= ([[maybe_unused]] const SimpleRefCount &o) |
Assignment operator. More... | |
void | Ref (void) const |
Increment the reference count. More... | |
void | Unref (void) 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 erros. 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 TypeId | GetTypeId (void) |
Get the type ID. More... | |
Static Public Member Functions inherited from ns3::Object | |
static TypeId | GetTypeId (void) |
Register this type. More... | |
Static Public Member Functions inherited from ns3::ObjectBase | |
static TypeId | GetTypeId (void) |
Get the type ID. More... | |
Static Public Attributes | |
static const uint16_t | PROT_NUMBER = 0x0806 |
ARP protocol number (0x0806) More... | |
Protected Member Functions | |
virtual void | DoDispose (void) |
Destructor implementation. More... | |
virtual void | NotifyNewAggregate () |
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 (void) |
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 (void) |
Notifier called once the ObjectBase is fully constructed. More... | |
Private Types | |
typedef std::list< Ptr< ArpCache > > | CacheList |
container of the ARP caches More... | |
Private Member Functions | |
Ptr< ArpCache > | FindCache (Ptr< NetDevice > device) |
Finds the cache associated with a NetDevice. More... | |
void | SendArpReply (Ptr< const ArpCache > cache, Ipv4Address myIp, Ipv4Address toIp, Address toMac) |
Send an ARP reply to an host. More... | |
void | SendArpRequest (Ptr< const ArpCache >cache, Ipv4Address to) |
Send an ARP request to an host. More... | |
Private Attributes | |
CacheList | m_cacheList |
ARP cache container. More... | |
TracedCallback< Ptr< const Packet > > | m_dropTrace |
trace for packets dropped by ARP More... | |
Ptr< Node > | m_node |
node the ARP L3 protocol is associated with More... | |
Ptr< RandomVariableStream > | m_requestJitter |
jitter to de-sync ARP requests More... | |
Ptr< TrafficControlLayer > | m_tc |
The associated TrafficControlLayer. More... | |
Additional Inherited Members | |
Related Functions inherited from ns3::ObjectBase | |
static TypeId | GetObjectIid (void) |
Ensure the TypeId for ObjectBase gets fully configured to anchor the inheritance tree properly. More... | |
An implementation of the ARP protocol.
ns3::ArpL3Protocol is accessible through the following paths with Config::Set and Config::Connect:
Size of this type is 104 bytes (on a 64-bit architecture).
Definition at line 53 of file arp-l3-protocol.h.
|
private |
container of the ARP caches
Definition at line 134 of file arp-l3-protocol.h.
ns3::ArpL3Protocol::ArpL3Protocol | ( | ) |
Definition at line 75 of file arp-l3-protocol.cc.
References NS_LOG_FUNCTION.
|
virtual |
Definition at line 81 of file arp-l3-protocol.cc.
References NS_LOG_FUNCTION.
|
delete |
int64_t ns3::ArpL3Protocol::AssignStreams | ( | int64_t | stream | ) |
Assign a fixed random variable stream number to the random variables used by this model.
Return the number of streams (possibly zero) that have been assigned.
stream | first stream index to use |
Definition at line 87 of file arp-l3-protocol.cc.
References m_requestJitter, NS_LOG_FUNCTION, and ns3::RandomVariableStream::SetStream().
Ptr< ArpCache > ns3::ArpL3Protocol::CreateCache | ( | Ptr< NetDevice > | device, |
Ptr< Ipv4Interface > | interface | ||
) |
Create an ARP cache for the device/interface.
device | the NetDevice |
interface | the Ipv4Interface |
Definition at line 145 of file arp-l3-protocol.cc.
References ns3::NetDevice::AddLinkChangeCallback(), ns3::ArpCache::Flush(), ns3::Object::GetObject(), ns3::NetDevice::IsBroadcast(), m_cacheList, m_node, ns3::MakeCallback(), NS_ASSERT, NS_LOG_FUNCTION, and SendArpRequest().
|
protectedvirtual |
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 130 of file arp-l3-protocol.cc.
References ns3::Object::Dispose(), ns3::Object::DoDispose(), m_cacheList, m_node, m_tc, and NS_LOG_FUNCTION.
Finds the cache associated with a NetDevice.
device | the NetDevice |
Definition at line 159 of file arp-l3-protocol.cc.
References m_cacheList, NS_ASSERT, and NS_LOG_FUNCTION.
Referenced by Receive().
|
static |
Get the type ID.
Definition at line 46 of file arp-l3-protocol.cc.
References m_cacheList, m_dropTrace, m_requestJitter, ns3::MakeObjectVectorAccessor(), ns3::MakePointerAccessor(), ns3::MakeTraceSourceAccessor(), and ns3::TypeId::SetParent().
bool ns3::ArpL3Protocol::Lookup | ( | Ptr< Packet > | p, |
const Ipv4Header & | ipHeader, | ||
Ipv4Address | destination, | ||
Ptr< NetDevice > | device, | ||
Ptr< ArpCache > | cache, | ||
Address * | hardwareDestination | ||
) |
Perform an ARP lookup.
p | the packet |
ipHeader | the IPv4 header |
destination | destination IP address |
device | outgoing device |
cache | ARP cache |
hardwareDestination | filled with the destination MAC address (if the entry exists) |
Definition at line 281 of file arp-l3-protocol.cc.
References ns3::ArpCache::Add(), ns3::Packet::AddHeader(), ns3::Node::GetId(), ns3::ArpCache::Entry::GetMacAddress(), ns3::RandomVariableStream::GetValue(), ns3::ArpCache::Entry::IsAlive(), ns3::ArpCache::Entry::IsDead(), ns3::ArpCache::Entry::IsExpired(), ns3::ArpCache::Entry::IsWaitReply(), ns3::ArpCache::Lookup(), m_dropTrace, m_node, m_requestJitter, ns3::ArpCache::Entry::MarkWaitReply(), ns3::MilliSeconds(), NS_FATAL_ERROR, NS_LOG_FUNCTION, NS_LOG_LOGIC, ns3::Simulator::Schedule(), SendArpRequest(), and ns3::ArpCache::Entry::UpdateWaitReply().
|
protectedvirtual |
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 113 of file arp-l3-protocol.cc.
References m_node, ns3::Object::NotifyNewAggregate(), NS_LOG_FUNCTION, and SetNode().
|
delete |
void ns3::ArpL3Protocol::Receive | ( | Ptr< NetDevice > | device, |
Ptr< const Packet > | p, | ||
uint16_t | protocol, | ||
const Address & | from, | ||
const Address & | to, | ||
NetDevice::PacketType | packetType | ||
) |
Receive a packet.
device | the source NetDevice |
p | the packet |
protocol | the protocol |
from | the source address |
to | the destination address |
packetType | type of packet (i.e., unicast, multicast, etc.) |
Definition at line 175 of file arp-l3-protocol.cc.
References ns3::Packet::Copy(), ns3::ArpCache::Entry::DequeuePending(), FindCache(), ns3::Ipv4Interface::GetAddress(), ns3::NetDevice::GetAddress(), ns3::ArpHeader::GetDestinationHardwareAddress(), ns3::ArpHeader::GetDestinationIpv4Address(), ns3::Node::GetId(), ns3::ArpCache::GetInterface(), ns3::Ipv4InterfaceAddress::GetLocal(), ns3::Packet::GetSize(), ns3::ArpHeader::GetSourceHardwareAddress(), ns3::ArpHeader::GetSourceIpv4Address(), ns3::ArpHeader::IsReply(), ns3::ArpHeader::IsRequest(), ns3::ArpCache::Entry::IsWaitReply(), ns3::ArpCache::Lookup(), m_dropTrace, m_node, ns3::ArpCache::Entry::MarkAlive(), NS_LOG_FUNCTION, NS_LOG_LOGIC, ns3::Packet::RemoveHeader(), ns3::Ipv4Interface::Send(), and SendArpReply().
Referenced by ns3::Ipv4L3Protocol::AddInterface().
|
private |
Send an ARP reply to an host.
cache | the ARP cache to use |
myIp | the source IP address |
toIp | the destination IP |
toMac | the destination MAC address |
Definition at line 384 of file arp-l3-protocol.cc.
References ns3::Node::GetId(), m_node, m_tc, NS_ASSERT, NS_LOG_FUNCTION, NS_LOG_LOGIC, PROT_NUMBER, and ns3::ArpHeader::SetReply().
Referenced by Receive().
|
private |
Send an ARP request to an host.
cache | the ARP cache to use |
to | the destination IP |
Definition at line 365 of file arp-l3-protocol.cc.
References ns3::Ipv4Address::GetBroadcast(), ns3::Node::GetId(), ns3::Object::GetObject(), ns3::Ipv4InterfaceAddress::GLOBAL, m_node, m_tc, NS_ASSERT, NS_LOG_FUNCTION, NS_LOG_LOGIC, PROT_NUMBER, and ns3::ArpHeader::SetRequest().
Referenced by CreateCache(), and Lookup().
Set the node the ARP L3 protocol is associated with.
node | the node |
Definition at line 95 of file arp-l3-protocol.cc.
References m_node, and NS_LOG_FUNCTION.
Referenced by NotifyNewAggregate().
void ns3::ArpL3Protocol::SetTrafficControl | ( | Ptr< TrafficControlLayer > | tc | ) |
Set the TrafficControlLayer.
tc | TrafficControlLayer object |
Definition at line 102 of file arp-l3-protocol.cc.
References m_tc, and NS_LOG_FUNCTION.
|
private |
ARP cache container.
Definition at line 158 of file arp-l3-protocol.h.
Referenced by CreateCache(), DoDispose(), FindCache(), and GetTypeId().
|
private |
trace for packets dropped by ARP
Definition at line 160 of file arp-l3-protocol.h.
Referenced by GetTypeId(), Lookup(), and Receive().
node the ARP L3 protocol is associated with
Definition at line 159 of file arp-l3-protocol.h.
Referenced by CreateCache(), DoDispose(), Lookup(), NotifyNewAggregate(), Receive(), SendArpReply(), SendArpRequest(), and SetNode().
|
private |
jitter to de-sync ARP requests
Definition at line 161 of file arp-l3-protocol.h.
Referenced by AssignStreams(), GetTypeId(), and Lookup().
|
private |
The associated TrafficControlLayer.
Definition at line 162 of file arp-l3-protocol.h.
Referenced by DoDispose(), SendArpReply(), SendArpRequest(), and SetTrafficControl().
|
static |
ARP protocol number (0x0806)
Definition at line 61 of file arp-l3-protocol.h.
Referenced by ns3::Ipv4L3Protocol::AddInterface(), SendArpReply(), and SendArpRequest().