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