A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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 "ipv4-header.h"
23
24#include "ns3/address.h"
25#include "ns3/net-device.h"
26#include "ns3/ptr.h"
27#include "ns3/random-variable-stream.h"
28#include "ns3/traced-callback.h"
29
30#include <list>
31
32namespace ns3
33{
34
35class ArpCache;
36class NetDevice;
37class Node;
38class Packet;
39class Ipv4Interface;
40class TrafficControlLayer;
41
42/**
43 * \ingroup ipv4
44 * \defgroup arp ARP protocol.
45 *
46 * The ARP protocol and its associated tables are responsible
47 * for the IPv4 - MAC address translation.
48 * Each NetDevice has its own ARP table.
49 */
50
51/**
52 * \ingroup arp
53 * \brief An implementation of the ARP protocol.
54 */
55class ArpL3Protocol : public Object
56{
57 public:
58 /**
59 * \brief Get the type ID.
60 * \return the object TypeId
61 */
62 static TypeId GetTypeId();
63 static const uint16_t PROT_NUMBER; //!< ARP protocol number (0x0806)
64
66 ~ArpL3Protocol() override;
67
68 // Delete copy constructor and assignment operator to avoid misuse
69 ArpL3Protocol(const ArpL3Protocol&) = delete;
71
72 /**
73 * \brief Set the node the ARP L3 protocol is associated with
74 * \param node the node
75 */
76 void SetNode(Ptr<Node> node);
77
78 /**
79 * \brief Set the TrafficControlLayer.
80 * \param tc TrafficControlLayer object
81 */
83
84 /**
85 * \brief Create an ARP cache for the device/interface
86 * \param device the NetDevice
87 * \param interface the Ipv4Interface
88 * \returns a smart pointer to the ARP cache
89 */
91
92 /**
93 * \brief Receive a packet
94 * \param device the source NetDevice
95 * \param p the packet
96 * \param protocol the protocol
97 * \param from the source address
98 * \param to the destination address
99 * \param packetType type of packet (i.e., unicast, multicast, etc.)
100 */
101 void Receive(Ptr<NetDevice> device,
103 uint16_t protocol,
104 const Address& from,
105 const Address& to,
106 NetDevice::PacketType packetType);
107 /**
108 * \brief Perform an ARP lookup
109 * \param p the packet
110 * \param ipHeader the IPv4 header
111 * \param destination destination IP address
112 * \param device outgoing device
113 * \param cache ARP cache
114 * \param hardwareDestination filled with the destination MAC address (if the entry exists)
115 * \return true if there is a matching ARP Entry
116 */
117 bool Lookup(Ptr<Packet> p,
118 const Ipv4Header& ipHeader,
119 Ipv4Address destination,
120 Ptr<NetDevice> device,
121 Ptr<ArpCache> cache,
122 Address* hardwareDestination);
123
124 /**
125 * Assign a fixed random variable stream number to the random variables
126 * used by this model. Return the number of streams (possibly zero) that
127 * have been assigned.
128 *
129 * \param stream first stream index to use
130 * \return the number of stream indices assigned by this model
131 */
132 int64_t AssignStreams(int64_t stream);
133
134 protected:
135 void DoDispose() override;
136 /*
137 * This function will notify other components connected to the node that a new stack member is
138 * now connected This will be used to notify Layer 3 protocol of layer 4 protocol stack to
139 * connect them together.
140 */
141 void NotifyNewAggregate() override;
142
143 private:
144 typedef std::list<Ptr<ArpCache>> CacheList; //!< container of the ARP caches
145
146 /**
147 * \brief Finds the cache associated with a NetDevice
148 * \param device the NetDevice
149 * \returns the ARP cache, or null if no cache is found
150 */
152
153 /**
154 * \brief Send an ARP request to an host
155 * \param cache the ARP cache to use
156 * \param to the destination IP
157 */
159 /**
160 * \brief Send an ARP reply to an host
161 * \param cache the ARP cache to use
162 * \param myIp the source IP address
163 * \param toIp the destination IP
164 * \param toMac the destination MAC address
165 */
166 void SendArpReply(Ptr<const ArpCache> cache, Ipv4Address myIp, Ipv4Address toIp, Address toMac);
167
168 CacheList m_cacheList; //!< ARP cache container
169 Ptr<Node> m_node; //!< node the ARP L3 protocol is associated with
170 TracedCallback<Ptr<const Packet>> m_dropTrace; //!< trace for packets dropped by ARP
171 Ptr<RandomVariableStream> m_requestJitter; //!< jitter to de-sync ARP requests
172 Ptr<TrafficControlLayer> m_tc; //!< The associated TrafficControlLayer
173};
174
175} // namespace ns3
176
177#endif /* ARP_L3_PROTOCOL_H */
a polymophic address class
Definition: address.h:101
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
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 & operator=(const ArpL3Protocol &)=delete
ArpL3Protocol(const ArpL3Protocol &)=delete
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
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
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.