20 #include "ns3/packet.h"
23 #include "ns3/net-device.h"
24 #include "ns3/object-vector.h"
25 #include "ns3/trace-source-accessor.h"
26 #include "ns3/pointer.h"
27 #include "ns3/string.h"
48 .AddConstructor<ArpL3Protocol> ()
49 .AddAttribute (
"CacheList",
50 "The list of ARP caches",
53 MakeObjectVectorChecker<ArpCache> ())
54 .AddAttribute (
"RequestJitter",
"The jitter in ms a node is allowed to wait before sending an ARP request. Some jitter aims to prevent collisions. By default, the model will wait for a duration in ms defined by a uniform random-variable between 0 and RequestJitter",
55 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=10.0]"),
57 MakePointerChecker<RandomVariableStream> ())
58 .AddTraceSource (
"Drop",
59 "Packet dropped because not enough room in pending queue for a specific cache entry.",
100 Ptr<Node>node = this->GetObject<Node> ();
145 if ((*i)->GetDevice () == device)
163 NS_LOG_LOGIC (
"ARP: received packet of size "<< packet->GetSize ());
175 uint32_t size = packet->RemoveHeader (arp);
182 " node="<<
m_node->
GetId ()<<
", got request from " <<
185 for (uint32_t i = 0; i < cache->GetInterface ()->GetNAddresses (); i++)
187 NS_LOG_LOGIC (cache->GetInterface ()->GetAddress (i).GetLocal () <<
", ");
195 for (uint32_t i = 0; i < cache->GetInterface ()->GetNAddresses (); i++)
198 cache->GetInterface ()->GetAddress (i).GetLocal ())
220 <<
" for waiting entry -- flush");
226 cache->GetInterface ()->Send (pending,
237 " for non-waiting entry -- drop");
263 NS_LOG_FUNCTION (
this << packet << destination << device << cache << hardwareDestination);
272 ", dead entry for " << destination <<
" expired -- send arp request");
279 ", alive entry for " << destination <<
" expired -- send arp request");
285 NS_FATAL_ERROR (
"Test for possibly unreachable code-- please file a bug report, with a test case, if this is ever hit");
293 ", dead entry for " << destination <<
" valid -- drop");
299 ", alive entry for " << destination <<
" valid -- send");
306 ", wait reply for " << destination <<
" valid -- drop previous");
318 ", no entry for " << destination <<
" -- send arp request");
319 entry = cache->
Add (destination);
340 " || src: " << device->GetAddress () <<
" / " << source <<
341 " || dst: " << device->GetBroadcast () <<
" / " << to);
342 arp.
SetRequest (device->GetAddress (), source, device->GetBroadcast (), to);
344 cache->GetDevice ()->Send (packet, device->GetBroadcast (),
PROT_NUMBER);
353 "|| src: " << cache->GetDevice ()->GetAddress () <<
355 " || dst: " << toMac <<
" / " << toIp);
356 arp.
SetReply (cache->GetDevice ()->GetAddress (), myIp, toMac, toIp);
359 cache->GetDevice ()->Send (packet, toMac,
PROT_NUMBER);
void SetDevice(Ptr< NetDevice > device, Ptr< Ipv4Interface > interface)
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberContainer)
keep track of time values and allow control of global simulation resolution
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)
#define NS_LOG_FUNCTION(parameters)
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
ArpCache::Entry * Add(Ipv4Address to)
Add an Ipv4Address to this ARP cache.
hold variables of type string
ArpCache::Entry * Lookup(Ipv4Address destination)
Do lookup in the ARP cache against an IP address.
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
uint32_t GetSize(void) const
virtual void DoDispose(void)
Ptr< ArpCache > CreateCache(Ptr< NetDevice > device, Ptr< Ipv4Interface > interface)
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
TracedCallback< Ptr< const Packet > > m_dropTrace
void SendArpRequest(Ptr< const ArpCache >cache, Ipv4Address to)
virtual double GetValue(void)=0
Returns a random double from the underlying distribution.
#define NS_FATAL_ERROR(msg)
fatal error handling
a polymophic address class
virtual void NotifyNewAggregate()
virtual void DoDispose(void)
void MarkWaitReply(Ptr< Packet > waiting)
NS_OBJECT_ENSURE_REGISTERED(AntennaModel)
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
bool IsExpired(void) const
#define NS_LOG_LOGIC(msg)
Address GetMacAddress(void) const
virtual void NotifyNewAggregate(void)
Ptr< Packet > Copy(void) const
Implement the Ipv4 layer.
static const uint16_t PROT_NUMBER
bool IsEqual(const Ipv4Address &other) const
Comparison operation between two Ipv4Addresses.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
void MarkAlive(Address macAddress)
A record that that holds information about an ArpCache entry.
void Flush(void)
Clear the ArpCache of all entries.
int64_t AssignStreams(int64_t stream)
bool UpdateWaitReply(Ptr< Packet > waiting)
Ipv4 addresses are stored in host order in this class.
uint32_t GetId(void) const
bool Lookup(Ptr< Packet > p, Ipv4Address destination, Ptr< NetDevice > device, Ptr< ArpCache > cache, Address *hardwareDestination)
Perform an ARP lookup.
void SetNode(Ptr< Node > node)
Ptr< RandomVariableStream > m_requestJitter
Ptr< Packet > DequeuePending(void)
a base class which provides memory management and object aggregation
contain a set of ns3::Object pointers.
Ptr< T > GetObject(void) const
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
void AddHeader(const Header &header)
Ptr< ArpCache > FindCache(Ptr< NetDevice > device)
static TypeId GetTypeId(void)