A Discrete-Event Network Simulator
API
arp-l3-protocol.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 #ifndef ARP_L3_PROTOCOL_H
20 #define ARP_L3_PROTOCOL_H
21 
22 #include "ns3/address.h"
23 #include "ns3/ipv4-header.h"
24 #include "ns3/net-device.h"
25 #include "ns3/ptr.h"
26 #include "ns3/random-variable-stream.h"
27 #include "ns3/traced-callback.h"
28 
29 #include <list>
30 
31 namespace ns3
32 {
33 
34 class ArpCache;
35 class NetDevice;
36 class Node;
37 class Packet;
38 class Ipv4Interface;
39 class TrafficControlLayer;
40 
54 class ArpL3Protocol : public Object
55 {
56  public:
61  static TypeId GetTypeId();
62  static const uint16_t PROT_NUMBER;
63 
64  ArpL3Protocol();
65  ~ArpL3Protocol() override;
66 
67  // Delete copy constructor and assignment operator to avoid misuse
68  ArpL3Protocol(const ArpL3Protocol&) = delete;
70 
75  void SetNode(Ptr<Node> node);
76 
82 
90 
100  void Receive(Ptr<NetDevice> device,
102  uint16_t protocol,
103  const Address& from,
104  const Address& to,
105  NetDevice::PacketType packetType);
116  bool Lookup(Ptr<Packet> p,
117  const Ipv4Header& ipHeader,
118  Ipv4Address destination,
119  Ptr<NetDevice> device,
120  Ptr<ArpCache> cache,
121  Address* hardwareDestination);
122 
131  int64_t AssignStreams(int64_t stream);
132 
133  protected:
134  void DoDispose() override;
135  /*
136  * This function will notify other components connected to the node that a new stack member is
137  * now connected This will be used to notify Layer 3 protocol of layer 4 protocol stack to
138  * connect them together.
139  */
140  void NotifyNewAggregate() override;
141 
142  private:
143  typedef std::list<Ptr<ArpCache>> CacheList;
144 
151 
165  void SendArpReply(Ptr<const ArpCache> cache, Ipv4Address myIp, Ipv4Address toIp, Address toMac);
166 
172 };
173 
174 } // namespace ns3
175 
176 #endif /* ARP_L3_PROTOCOL_H */
a polymophic address class
Definition: address.h:100
An implementation of the ARP protocol.
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
ArpL3Protocol & operator=(const ArpL3Protocol &)=delete
std::list< Ptr< ArpCache > > CacheList
container of the ARP caches
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.
ArpL3Protocol(const ArpL3Protocol &)=delete
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:43
Packet header for IPv4.
Definition: ipv4-header.h:34
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:300
A base class which provides memory management and object aggregation.
Definition: object.h:89
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:60
Every class exported by the ns3 library is enclosed in the ns3 namespace.