28#include "ns3/net-device.h"
30#include "ns3/object-vector.h"
31#include "ns3/packet.h"
32#include "ns3/pointer.h"
33#include "ns3/string.h"
34#include "ns3/trace-source-accessor.h"
35#include "ns3/traffic-control-layer.h"
50 TypeId(
"ns3::ArpL3Protocol")
52 .AddConstructor<ArpL3Protocol>()
53 .SetGroupName(
"Internet")
54 .AddAttribute(
"CacheList",
55 "The list of ARP caches",
58 MakeObjectVectorChecker<ArpCache>())
59 .AddAttribute(
"RequestJitter",
60 "The jitter in ms a node is allowed to wait "
61 "before sending an ARP request. Some jitter aims "
62 "to prevent collisions. By default, the model "
63 "will wait for a duration in ms defined by "
64 "a uniform random-variable between 0 and RequestJitter",
65 StringValue(
"ns3::UniformRandomVariable[Min=0.0|Max=10.0]"),
67 MakePointerChecker<RandomVariableStream>())
68 .AddTraceSource(
"Drop",
69 "Packet dropped because not enough room "
70 "in pending queue for a specific cache entry.",
72 "ns3::Packet::TracedCallback");
119 Ptr<Node> node = this->GetObject<Node>();
151 cache->SetDevice(device, interface);
165 if ((*i)->GetDevice() == device)
183 NS_LOG_FUNCTION(
this << device << p->GetSize() << protocol << from << to << packetType);
187 NS_LOG_LOGIC(
"ARP: received packet of size " << packet->GetSize());
199 uint32_t size = packet->RemoveHeader(arp);
207 << (arp.
IsRequest() ?
"request" :
"reply") <<
" from "
210 for (
uint32_t i = 0; i < cache->GetInterface()->GetNAddresses(); i++)
212 NS_LOG_LOGIC(cache->GetInterface()->GetAddress(i).GetLocal() <<
", ");
221 for (
uint32_t i = 0; i < cache->GetInterface()->GetNAddresses(); i++)
237 cache->GetInterface()->GetAddress(i).GetLocal() &&
243 if (entry !=
nullptr)
249 <<
" for waiting entry -- flush");
253 while (pending.first)
255 cache->GetInterface()->Send(pending.first,
267 <<
" for non-waiting entry -- drop");
295 NS_LOG_FUNCTION(
this << packet << destination << device << cache << hardwareDestination);
297 if (entry !=
nullptr)
304 <<
" expired -- send arp request");
315 <<
" expired -- send arp request");
325 NS_FATAL_ERROR(
"Test for possibly unreachable code-- please file a bug report, "
326 "with a test case, if this is ever hit");
334 <<
" valid -- drop");
336 packet->AddHeader(ipHeader);
342 <<
" valid -- send");
349 <<
" valid -- drop previous");
353 packet->AddHeader(ipHeader);
366 NS_LOG_LOGIC(
"Test for possibly unreachable code-- please file a bug report, with "
367 "a test case, if this is ever hit");
375 <<
" -- send arp request");
376 entry = cache->Add(destination);
399 <<
m_node->
GetId() <<
" || src: " << device->GetAddress() <<
" / " << source
400 <<
" || dst: " << device->
GetBroadcast() <<
" / " << to);
403 m_tc->Send(device, Create<ArpQueueDiscItem>(packet, device->GetBroadcast(),
PROT_NUMBER, arp));
415 <<
m_node->
GetId() <<
"|| src: " << cache->GetDevice()->GetAddress() <<
" / "
416 << myIp <<
" || dst: " << toMac <<
" / " << toIp);
417 arp.
SetReply(cache->GetDevice()->GetAddress(), myIp, toMac, toIp);
420 m_tc->Send(cache->GetDevice(), Create<ArpQueueDiscItem>(packet, toMac,
PROT_NUMBER, arp));
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.
Simulation virtual time values and global simulation resolution.
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,...
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)
#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 ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
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...