17#include "ns3/net-device.h"
19#include "ns3/object-vector.h"
20#include "ns3/packet.h"
21#include "ns3/pointer.h"
22#include "ns3/string.h"
23#include "ns3/trace-source-accessor.h"
24#include "ns3/traffic-control-layer.h"
39 TypeId(
"ns3::ArpL3Protocol")
41 .AddConstructor<ArpL3Protocol>()
42 .SetGroupName(
"Internet")
43 .AddAttribute(
"CacheList",
44 "The list of ARP caches",
48 .AddAttribute(
"RequestJitter",
49 "The jitter in ms a node is allowed to wait "
50 "before sending an ARP request. Some jitter aims "
51 "to prevent collisions. By default, the model "
52 "will wait for a duration in ms defined by "
53 "a uniform random-variable between 0 and RequestJitter",
54 StringValue(
"ns3::UniformRandomVariable[Min=0.0|Max=10.0]"),
57 .AddTraceSource(
"Drop",
58 "Packet dropped because not enough room "
59 "in pending queue for a specific cache entry.",
61 "ns3::Packet::TracedCallback");
140 cache->SetDevice(device, interface);
154 if ((*i)->GetDevice() == device)
172 NS_LOG_FUNCTION(
this << device << p->GetSize() << protocol << from << to << packetType);
176 NS_LOG_LOGIC(
"ARP: received packet of size " << packet->GetSize());
188 uint32_t size = packet->RemoveHeader(arp);
196 << (arp.
IsRequest() ?
"request" :
"reply") <<
" from "
199 for (
uint32_t i = 0; i < cache->GetInterface()->GetNAddresses(); i++)
201 NS_LOG_LOGIC(cache->GetInterface()->GetAddress(i).GetLocal() <<
", ");
210 for (
uint32_t i = 0; i < cache->GetInterface()->GetNAddresses(); i++)
226 cache->GetInterface()->GetAddress(i).GetLocal() &&
232 if (entry !=
nullptr)
238 <<
" for waiting entry -- flush");
242 while (pending.first)
244 cache->GetInterface()->Send(pending.first,
256 <<
" for non-waiting entry -- drop");
284 NS_LOG_FUNCTION(
this << packet << destination << device << cache << hardwareDestination);
286 if (entry !=
nullptr)
293 <<
" expired -- send arp request");
304 <<
" expired -- send arp request");
314 NS_FATAL_ERROR(
"Test for possibly unreachable code-- please file a bug report, "
315 "with a test case, if this is ever hit");
323 <<
" valid -- drop");
325 packet->AddHeader(ipHeader);
331 <<
" valid -- send");
338 <<
" valid -- drop previous");
342 packet->AddHeader(ipHeader);
355 NS_LOG_LOGIC(
"Test for possibly unreachable code-- please file a bug report, with "
356 "a test case, if this is ever hit");
364 <<
" -- send arp request");
365 entry = cache->Add(destination);
388 <<
m_node->
GetId() <<
" || src: " << device->GetAddress() <<
" / " << source
389 <<
" || dst: " << device->
GetBroadcast() <<
" / " << to);
404 <<
m_node->
GetId() <<
"|| src: " << cache->GetDevice()->GetAddress() <<
" / "
405 << myIp <<
" || dst: " << toMac <<
" / " << toIp);
406 arp.
SetReply(cache->GetDevice()->GetAddress(), myIp, toMac, toIp);
a polymophic address class
A record that that holds information about an ArpCache entry.
bool UpdateWaitReply(Ipv4PayloadHeaderPair waiting)
Address GetMacAddress() const
void MarkAlive(Address macAddress)
void MarkWaitReply(Ipv4PayloadHeaderPair waiting)
Ipv4PayloadHeaderPair DequeuePending()
void Flush()
Clear the ArpCache of all entries.
std::pair< Ptr< Packet >, Ipv4Header > Ipv4PayloadHeaderPair
Pair of a packet and an Ipv4 header.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Ptr< RandomVariableStream > m_requestJitter
jitter to de-sync ARP requests
bool Lookup(Ptr< Packet > p, const Ipv4Header &ipHeader, Ipv4Address destination, Ptr< NetDevice > device, Ptr< ArpCache > cache, Address *hardwareDestination)
Perform an ARP lookup.
void Receive(Ptr< NetDevice > device, Ptr< const Packet > p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Receive a packet.
void SendArpReply(Ptr< const ArpCache > cache, Ipv4Address myIp, Ipv4Address toIp, Address toMac)
Send an ARP reply to an host.
Ptr< TrafficControlLayer > m_tc
The associated TrafficControlLayer.
CacheList m_cacheList
ARP cache container.
Ptr< ArpCache > FindCache(Ptr< NetDevice > device)
Finds the cache associated with a NetDevice.
void SendArpRequest(Ptr< const ArpCache > cache, Ipv4Address to)
Send an ARP request to an host.
void SetNode(Ptr< Node > node)
Set the node the ARP L3 protocol is associated with.
void DoDispose() override
Destructor implementation.
static const uint16_t PROT_NUMBER
ARP protocol number (0x0806)
void SetTrafficControl(Ptr< TrafficControlLayer > tc)
Set the TrafficControlLayer.
Ptr< ArpCache > CreateCache(Ptr< NetDevice > device, Ptr< Ipv4Interface > interface)
Create an ARP cache for the device/interface.
Ptr< Node > m_node
node the ARP L3 protocol is associated with
void NotifyNewAggregate() override
Notify all Objects aggregated to this one of a new Object being aggregated.
TracedCallback< Ptr< const Packet > > m_dropTrace
trace for packets dropped by ARP
~ArpL3Protocol() override
static TypeId GetTypeId()
Get the type ID.
Ipv4 addresses are stored in host order in this class.
static Ipv4Address GetBroadcast()
Implement the IPv4 layer.
PacketType
Packet types are used as they are in Linux.
A base class which provides memory management and object aggregation.
virtual void NotifyNewAggregate()
Notify all Objects aggregated to this one of a new Object being aggregated.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
virtual void DoDispose()
Destructor implementation.
Smart pointer class similar to boost::intrusive_ptr.
virtual double GetValue()=0
Get the next random value drawn from the distribution.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Hold variables of type string.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Ptr< const AttributeChecker > MakeObjectVectorChecker()
ObjectPtrContainerValue ObjectVectorValue
ObjectVectorValue is an alias for ObjectPtrContainerValue.
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
#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_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#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.
Time MilliSeconds(uint64_t 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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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...