A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv4-interface.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005,2006,2007 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors:
7 * Mathieu Lacage <mathieu.lacage@sophia.inria.fr>,
8 * Tom Henderson <tomh@tomh.org>
9 */
10#ifndef IPV4_INTERFACE_H
11#define IPV4_INTERFACE_H
12
13#include "ns3/object.h"
14#include "ns3/ptr.h"
15
16#include <list>
17
18namespace ns3
19{
20
21class NetDevice;
22class Packet;
23class Node;
24class ArpCache;
25class Ipv4InterfaceAddress;
26class Ipv4Address;
27class Ipv4Header;
28class TrafficControlLayer;
29
30/**
31 * @ingroup ipv4
32 *
33 * @brief The IPv4 representation of a network interface
34 *
35 * This class roughly corresponds to the struct in_device
36 * of Linux; the main purpose is to provide address-family
37 * specific information (addresses) about an interface.
38 *
39 * By default, Ipv4 interface are created in the "down" state
40 * no IP addresses. Before becoming usable, the user must
41 * add an address of some type and invoke Setup on them.
42 */
43class Ipv4Interface : public Object
44{
45 public:
46 /**
47 * @brief Get the type ID
48 * @return type ID
49 */
50 static TypeId GetTypeId();
51
53 ~Ipv4Interface() override;
54
55 // Delete copy constructor and assignment operator to avoid misuse
56 Ipv4Interface(const Ipv4Interface&) = delete;
58
59 /**
60 * @brief Set node associated with interface.
61 * @param node node
62 */
63 void SetNode(Ptr<Node> node);
64 /**
65 * @brief Set the NetDevice.
66 * @param device NetDevice
67 */
68 void SetDevice(Ptr<NetDevice> device);
69 /**
70 * @brief Set the TrafficControlLayer.
71 * @param tc TrafficControlLayer object
72 */
74 /**
75 * @brief Set ARP cache used by this interface
76 * @param arpCache the ARP cache
77 */
78 void SetArpCache(Ptr<ArpCache> arpCache);
79
80 /**
81 * @returns the underlying NetDevice. This method cannot return zero.
82 */
84
85 /**
86 * @return ARP cache used by this interface
87 */
89
90 /**
91 * @param metric configured routing metric (cost) of this interface
92 *
93 * Note: This is synonymous to the Metric value that ifconfig prints
94 * out. It is used by ns-3 global routing, but other routing daemons
95 * choose to ignore it.
96 */
97 void SetMetric(uint16_t metric);
98
99 /**
100 * @returns configured routing metric (cost) of this interface
101 *
102 * Note: This is synonymous to the Metric value that ifconfig prints
103 * out. It is used by ns-3 global routing, but other routing daemons
104 * may choose to ignore it.
105 */
106 uint16_t GetMetric() const;
107
108 /**
109 * These are IP interface states and may be distinct from
110 * NetDevice states, such as found in real implementations
111 * (where the device may be down but IP interface state is still up).
112 */
113 /**
114 * @returns true if this interface is enabled, false otherwise.
115 */
116 bool IsUp() const;
117
118 /**
119 * @returns true if this interface is disabled, false otherwise.
120 */
121 bool IsDown() const;
122
123 /**
124 * Enable this interface
125 */
126 void SetUp();
127
128 /**
129 * Disable this interface
130 */
131 void SetDown();
132
133 /**
134 * @returns true if this interface is enabled for IP forwarding of input datagrams
135 */
136 bool IsForwarding() const;
137
138 /**
139 * @param val Whether to enable or disable IP forwarding for input datagrams
140 */
141 void SetForwarding(bool val);
142
143 /**
144 * @param p packet to send
145 * @param hdr IPv4 header
146 * @param dest next hop address of packet.
147 *
148 * This method will eventually call the private
149 * SendTo method which must be implemented by subclasses.
150 */
151 void Send(Ptr<Packet> p, const Ipv4Header& hdr, Ipv4Address dest);
152
153 /**
154 * @param address The Ipv4InterfaceAddress to add to the interface
155 * @returns true if succeeded
156 */
157 bool AddAddress(Ipv4InterfaceAddress address);
158
159 /**
160 * @param index Index of Ipv4InterfaceAddress to return
161 * @returns The Ipv4InterfaceAddress address whose index is i
162 */
164
165 /**
166 * @returns the number of Ipv4InterfaceAddress stored on this interface
167 */
168 uint32_t GetNAddresses() const;
169
170 /**
171 * @param index Index of Ipv4InterfaceAddress to remove
172 * @returns The Ipv4InterfaceAddress address whose index is index
173 */
175
176 /**
177 * @brief Remove the given Ipv4 address from the interface.
178 * @param address The Ipv4 address to remove
179 * @returns The removed Ipv4 interface address
180 * @returns The null interface address if the interface did not contain the
181 * address or if loopback address was passed as argument
182 */
184
185 /**
186 * This callback is set when an address is removed from an interface with
187 * auto-generated Arp cache and it allow the neighbor cache helper to update
188 * neighbor's Arp cache
189 *
190 * @param removeAddressCallback Callback when remove an address.
191 */
193 Callback<void, Ptr<Ipv4Interface>, Ipv4InterfaceAddress> removeAddressCallback);
194
195 /**
196 * This callback is set when an address is added from an interface with
197 * auto-generated Arp cache and it allow the neighbor cache helper to update
198 * neighbor's Arp cache
199 *
200 * @param addAddressCallback Callback when remove an address.
201 */
203 Callback<void, Ptr<Ipv4Interface>, Ipv4InterfaceAddress> addAddressCallback);
204
205 protected:
206 void DoDispose() override;
207
208 private:
209 /**
210 * @brief Initialize interface.
211 */
212 void DoSetup();
213
214 /**
215 * @brief Container for the Ipv4InterfaceAddresses.
216 */
217 typedef std::list<Ipv4InterfaceAddress> Ipv4InterfaceAddressList;
218
219 /**
220 * @brief Container Iterator for the Ipv4InterfaceAddresses.
221 */
222 typedef std::list<Ipv4InterfaceAddress>::const_iterator Ipv4InterfaceAddressListCI;
223
224 /**
225 * @brief Const Container Iterator for the Ipv4InterfaceAddresses.
226 */
227 typedef std::list<Ipv4InterfaceAddress>::iterator Ipv4InterfaceAddressListI;
228
229 bool m_ifup; //!< The state of this interface
230 bool m_forwarding; //!< Forwarding state.
231 uint16_t m_metric; //!< Interface metric
233 Ptr<Node> m_node; //!< The associated node
234 Ptr<NetDevice> m_device; //!< The associated NetDevice
235 Ptr<TrafficControlLayer> m_tc; //!< The associated TrafficControlLayer
236 Ptr<ArpCache> m_cache; //!< ARP cache
238 m_removeAddressCallback; //!< remove address callback
240 m_addAddressCallback; //!< add address callback
241};
242
243} // namespace ns3
244
245#endif
Callback template class.
Definition callback.h:422
Ipv4 addresses are stored in host order in this class.
Packet header for IPv4.
Definition ipv4-header.h:23
a class to store IPv4 address information on an interface
The IPv4 representation of a network interface.
static TypeId GetTypeId()
Get the type ID.
uint32_t GetNAddresses() const
Ptr< Node > m_node
The associated node.
void SetArpCache(Ptr< ArpCache > arpCache)
Set ARP cache used by this interface.
Ipv4Interface()
By default, Ipv4 interface are created in the "down" state with no IP addresses.
~Ipv4Interface() override
Ipv4Interface(const Ipv4Interface &)=delete
void RemoveAddressCallback(Callback< void, Ptr< Ipv4Interface >, Ipv4InterfaceAddress > removeAddressCallback)
This callback is set when an address is removed from an interface with auto-generated Arp cache and i...
void SetNode(Ptr< Node > node)
Set node associated with interface.
Ipv4InterfaceAddress GetAddress(uint32_t index) const
Ptr< TrafficControlLayer > m_tc
The associated TrafficControlLayer.
bool AddAddress(Ipv4InterfaceAddress address)
void SetTrafficControl(Ptr< TrafficControlLayer > tc)
Set the TrafficControlLayer.
bool m_forwarding
Forwarding state.
std::list< Ipv4InterfaceAddress >::const_iterator Ipv4InterfaceAddressListCI
Container Iterator for the Ipv4InterfaceAddresses.
uint16_t GetMetric() const
Ptr< NetDevice > m_device
The associated NetDevice.
bool IsUp() const
These are IP interface states and may be distinct from NetDevice states, such as found in real implem...
void SetUp()
Enable this interface.
Ptr< ArpCache > GetArpCache() const
void SetDevice(Ptr< NetDevice > device)
Set the NetDevice.
void DoSetup()
Initialize interface.
Ptr< NetDevice > GetDevice() const
Ipv4InterfaceAddressList m_ifaddrs
Address list.
Callback< void, Ptr< Ipv4Interface >, Ipv4InterfaceAddress > m_addAddressCallback
add address callback
uint16_t m_metric
Interface metric.
void SetDown()
Disable this interface.
bool IsForwarding() const
void AddAddressCallback(Callback< void, Ptr< Ipv4Interface >, Ipv4InterfaceAddress > addAddressCallback)
This callback is set when an address is added from an interface with auto-generated Arp cache and it ...
void DoDispose() override
Destructor implementation.
Ptr< ArpCache > m_cache
ARP cache.
Callback< void, Ptr< Ipv4Interface >, Ipv4InterfaceAddress > m_removeAddressCallback
remove address callback
void Send(Ptr< Packet > p, const Ipv4Header &hdr, Ipv4Address dest)
bool m_ifup
The state of this interface.
std::list< Ipv4InterfaceAddress >::iterator Ipv4InterfaceAddressListI
Const Container Iterator for the Ipv4InterfaceAddresses.
std::list< Ipv4InterfaceAddress > Ipv4InterfaceAddressList
Container for the Ipv4InterfaceAddresses.
void SetForwarding(bool val)
Ipv4Interface & operator=(const Ipv4Interface &)=delete
void SetMetric(uint16_t metric)
Ipv4InterfaceAddress RemoveAddress(uint32_t index)
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.