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"
35 #include "ns3/traffic-control-layer.h"
50 .AddConstructor<ArpL3Protocol> ()
51 .SetGroupName (
"Internet")
52 .AddAttribute (
"CacheList",
53 "The list of ARP caches",
56 MakeObjectVectorChecker<ArpCache> ())
57 .AddAttribute (
"RequestJitter",
58 "The jitter in ms a node is allowed to wait "
59 "before sending an ARP request. Some jitter aims "
60 "to prevent collisions. By default, the model "
61 "will wait for a duration in ms defined by "
62 "a uniform random-variable between 0 and RequestJitter",
63 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=10.0]"),
65 MakePointerChecker<RandomVariableStream> ())
66 .AddTraceSource (
"Drop",
67 "Packet dropped because not enough room "
68 "in pending queue for a specific cache entry.",
70 "ns3::Packet::TracedCallback")
118 Ptr<Node>node = this->GetObject<Node> ();
150 cache->SetDevice (device, interface);
164 if ((*i)->GetDevice () == device)
203 (arp.
IsRequest () ?
"request" :
"reply") <<
206 "; we have addresses: ");
207 for (uint32_t i = 0; i < cache->
GetInterface ()->GetNAddresses (); i++)
218 for (uint32_t i = 0; i < cache->
GetInterface ()->GetNAddresses (); i++)
243 <<
" for waiting entry -- flush");
247 while (pending.first != 0)
260 " for non-waiting entry -- drop");
286 NS_LOG_FUNCTION (
this << packet << destination << device << cache << hardwareDestination);
295 ", dead entry for " << destination <<
" expired -- send arp request");
302 ", alive entry for " << destination <<
" expired -- send arp request");
308 NS_FATAL_ERROR (
"Test for possibly unreachable code-- please file a bug report, with a test case, if this is ever hit");
316 ", dead entry for " << destination <<
" valid -- drop");
324 ", alive entry for " << destination <<
" valid -- send");
331 ", wait reply for " << destination <<
" valid -- drop previous");
339 else if (entry-> IsPermanent ())
342 ", permanent for " << destination <<
"valid -- send");
348 NS_LOG_LOGIC (
"Test for possibly unreachable code-- please file a bug report, with a test case, if this is ever hit");
356 ", no entry for " << destination <<
" -- send arp request");
357 entry = cache->
Add (destination);
376 " || src: " << device->GetAddress () <<
" / " << source <<
380 m_tc->Send (device, Create<ArpQueueDiscItem> (packet, device->GetBroadcast (),
PROT_NUMBER, arp));
389 "|| src: " << cache->GetDevice ()->GetAddress () <<
391 " || dst: " << toMac <<
" / " << toIp);
392 arp.
SetReply (cache->GetDevice ()->GetAddress (), myIp, toMac, toIp);
395 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)
Ipv4PayloadHeaderPair DequeuePending(void)
void MarkAlive(Address macAddress)
void MarkWaitReply(Ipv4PayloadHeaderPair waiting)
Address GetMacAddress(void) const
bool IsExpired(void) const
Ptr< Ipv4Interface > GetInterface(void) const
Returns the Ipv4Interface that this ARP cache is associated with.
ArpCache::Entry * Add(Ipv4Address to)
Add an Ipv4Address to this ARP cache.
void Flush(void)
Clear the ArpCache of all entries.
ArpCache::Entry * Lookup(Ipv4Address destination)
Do lookup in the ARP cache against an IP address.
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.
virtual void DoDispose(void)
Destructor implementation.
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.
static TypeId GetTypeId(void)
Get the type ID.
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.
virtual void NotifyNewAggregate()
Notify all Objects aggregated to this one of a new Object being aggregated.
void SetNode(Ptr< Node > node)
Set the node the ARP L3 protocol is associated with.
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.
void SendArpRequest(Ptr< const ArpCache >cache, Ipv4Address to)
Send an ARP request to an host.
Ptr< Node > m_node
node the ARP L3 protocol is associated with
TracedCallback< Ptr< const Packet > > m_dropTrace
trace for packets dropped by ARP
Ipv4 addresses are stored in host order in this class.
static Ipv4Address GetBroadcast(void)
Ipv4Address GetLocal(void) const
Get the local address.
Ipv4InterfaceAddress GetAddress(uint32_t index) const
void Send(Ptr< Packet > p, const Ipv4Header &hdr, Ipv4Address dest)
Implement the IPv4 layer.
virtual Address GetAddress(void) const =0
virtual bool IsBroadcast(void) const =0
virtual void AddLinkChangeCallback(Callback< void > callback)=0
PacketType
Packet types are used as they are in Linux.
uint32_t GetId(void) const
A base class which provides memory management and object aggregation.
virtual void DoDispose(void)
Destructor implementation.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
void Dispose(void)
Dispose of this Object.
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.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
void AddHeader(const Header &header)
Add header to this packet.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
virtual double GetValue(void)=0
Get the next random value as a double drawn from the distribution.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
static EventId Schedule(Time const &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,...
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.
#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, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...