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