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 .SetGroupName (
"Internet")
50 .AddAttribute (
"CacheList",
51 "The list of ARP caches",
54 MakeObjectVectorChecker<ArpCache> ())
55 .AddAttribute (
"RequestJitter",
56 "The jitter in ms a node is allowed to wait "
57 "before sending an ARP request. Some jitter aims "
58 "to prevent collisions. By default, the model "
59 "will wait for a duration in ms defined by "
60 "a uniform random-variable between 0 and RequestJitter",
61 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=10.0]"),
63 MakePointerChecker<RandomVariableStream> ())
64 .AddTraceSource (
"Drop",
65 "Packet dropped because not enough room "
66 "in pending queue for a specific cache entry.",
68 "ns3::Packet::TracedCallback")
108 Ptr<Node>node = this->GetObject<Node> ();
153 if ((*i)->GetDevice () == device)
171 NS_LOG_LOGIC (
"ARP: received packet of size "<< packet->GetSize ());
183 uint32_t size = packet->RemoveHeader (arp);
190 " node="<<
m_node->
GetId ()<<
", got request from " <<
193 for (uint32_t i = 0; i < cache->GetInterface ()->GetNAddresses (); i++)
195 NS_LOG_LOGIC (cache->GetInterface ()->GetAddress (i).GetLocal () <<
", ");
204 for (uint32_t i = 0; i < cache->GetInterface ()->GetNAddresses (); i++)
207 cache->GetInterface ()->GetAddress (i).GetLocal ())
229 <<
" for waiting entry -- flush");
235 cache->GetInterface ()->Send (pending,
246 " for non-waiting entry -- drop");
272 NS_LOG_FUNCTION (
this << packet << destination << device << cache << hardwareDestination);
281 ", dead entry for " << destination <<
" expired -- send arp request");
288 ", alive entry for " << destination <<
" expired -- send arp request");
294 NS_FATAL_ERROR (
"Test for possibly unreachable code-- please file a bug report, with a test case, if this is ever hit");
302 ", dead entry for " << destination <<
" valid -- drop");
308 ", alive entry for " << destination <<
" valid -- send");
315 ", wait reply for " << destination <<
" valid -- drop previous");
321 else if (entry-> IsPermanent ())
324 ", permanent for " << destination <<
"valid -- send");
330 NS_LOG_LOGIC (
"Test for possibly unreachable code-- please file a bug report, with a test case, if this is ever hit");
338 ", no entry for " << destination <<
" -- send arp request");
339 entry = cache->
Add (destination);
360 " || src: " << device->GetAddress () <<
" / " << source <<
361 " || dst: " << device->GetBroadcast () <<
" / " << to);
362 arp.
SetRequest (device->GetAddress (), source, device->GetBroadcast (), to);
364 cache->GetDevice ()->Send (packet, device->GetBroadcast (),
PROT_NUMBER);
373 "|| src: " << cache->GetDevice ()->GetAddress () <<
375 " || dst: " << toMac <<
" / " << toIp);
376 arp.
SetReply (cache->GetDevice ()->GetAddress (), myIp, toMac, toIp);
379 cache->GetDevice ()->Send (packet, toMac,
PROT_NUMBER);
void Dispose(void)
Dispose of this Object.
void SetDevice(Ptr< NetDevice > device, Ptr< Ipv4Interface > interface)
Set the NetDevice and Ipv4Interface associated with the ArpCache.
Simulation virtual time values and 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)
Send an ARP reply to an host.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
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.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Hold variables of type string.
ArpCache::Entry * Lookup(Ipv4Address destination)
Do lookup in the ARP cache against an IP address.
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
PacketType
Packet types are used as they are in Linux.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
virtual void DoDispose(void)
Destructor implementation.
Ptr< ArpCache > CreateCache(Ptr< NetDevice > device, Ptr< Ipv4Interface > interface)
Create an ARP cache for the device/interface.
TracedCallback< Ptr< const Packet > > m_dropTrace
trace for packets dropped by ARP
void SendArpRequest(Ptr< const ArpCache >cache, Ipv4Address to)
Send an ARP request to an host.
virtual double GetValue(void)=0
Get the next random value as a double drawn from the distribution.
a polymophic address class
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
virtual void NotifyNewAggregate()
Notify all Objects aggregated to this one of a new Object being aggregated.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
virtual void DoDispose(void)
Destructor implementation.
void MarkWaitReply(Ptr< Packet > waiting)
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
bool IsExpired(void) const
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Address GetMacAddress(void) const
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Implement the Ipv4 layer.
static const uint16_t PROT_NUMBER
ARP protocol number (0x0806)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< Node > m_node
node the ARP L3 protocol is associated with
bool IsEqual(const Ipv4Address &other) const
Comparison operation between two Ipv4Addresses.
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)
Assign a fixed random variable stream number to the random variables used by this model...
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)
Set the node the ARP L3 protocol is associated with.
Ptr< RandomVariableStream > m_requestJitter
jitter to de-sync ARP requests
Ptr< Packet > DequeuePending(void)
A base class which provides memory management and object aggregation.
virtual void NotifyNewAggregate(void)
Notify all Objects aggregated to this one of a new Object being aggregated.
Container for a set of ns3::Object pointers.
CacheList m_cacheList
ARP cache container.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
void AddHeader(const Header &header)
Add header to this packet.
Ptr< ArpCache > FindCache(Ptr< NetDevice > device)
Finds the cache associated with a NetDevice.
static TypeId GetTypeId(void)
Get the type ID.