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#include "ns3/traced-callback.h"
16
17#include <list>
18
19namespace ns3
20{
21
22class NetDevice;
23class Packet;
24class Node;
25class ArpCache;
26class Ipv4InterfaceAddress;
27class Ipv4Address;
28class Ipv4Header;
29class TrafficControlLayer;
30
31/**
32 * @ingroup ipv4
33 *
34 * @brief The IPv4 representation of a network interface
35 *
36 * This class roughly corresponds to the struct in_device
37 * of Linux; the main purpose is to provide address-family
38 * specific information (addresses) about an interface.
39 *
40 * By default, Ipv4 interface are created in the "down" state
41 * no IP addresses. Before becoming usable, the user must
42 * add an address of some type and invoke Setup on them.
43 */
44class Ipv4Interface : public Object
45{
46 public:
47 /**
48 * @brief Get the type ID
49 * @return type ID
50 */
51 static TypeId GetTypeId();
52
54 ~Ipv4Interface() override;
55
56 // Delete copy constructor and assignment operator to avoid misuse
57 Ipv4Interface(const Ipv4Interface&) = delete;
59
60 /**
61 * @brief Set node associated with interface.
62 * @param node node
63 */
64 void SetNode(Ptr<Node> node);
65 /**
66 * @brief Set the NetDevice.
67 * @param device NetDevice
68 */
69 void SetDevice(Ptr<NetDevice> device);
70 /**
71 * @brief Set the TrafficControlLayer.
72 * @param tc TrafficControlLayer object
73 */
75 /**
76 * @brief Set ARP cache used by this interface
77 * @param arpCache the ARP cache
78 */
79 void SetArpCache(Ptr<ArpCache> arpCache);
80
81 /**
82 * @returns the underlying NetDevice. This method cannot return zero.
83 */
85
86 /**
87 * @return ARP cache used by this interface
88 */
90
91 /**
92 * @param metric configured routing metric (cost) of this interface
93 *
94 * Note: This is synonymous to the Metric value that ifconfig prints
95 * out. It is used by ns-3 global routing, but other routing daemons
96 * choose to ignore it.
97 */
98 void SetMetric(uint16_t metric);
99
100 /**
101 * @returns configured routing metric (cost) of this interface
102 *
103 * Note: This is synonymous to the Metric value that ifconfig prints
104 * out. It is used by ns-3 global routing, but other routing daemons
105 * may choose to ignore it.
106 */
107 uint16_t GetMetric() const;
108
109 /**
110 * These are IP interface states and may be distinct from
111 * NetDevice states, such as found in real implementations
112 * (where the device may be down but IP interface state is still up).
113 */
114 /**
115 * @returns true if this interface is enabled, false otherwise.
116 */
117 bool IsUp() const;
118
119 /**
120 * @returns true if this interface is disabled, false otherwise.
121 */
122 bool IsDown() const;
123
124 /**
125 * Enable this interface
126 */
127 void SetUp();
128
129 /**
130 * Disable this interface
131 */
132 void SetDown();
133
134 /**
135 * @returns true if this interface is enabled for IP forwarding of input datagrams
136 */
137 bool IsForwarding() const;
138
139 /**
140 * @param val Whether to enable or disable IP forwarding for input datagrams
141 */
142 void SetForwarding(bool val);
143
144 /**
145 * @param p packet to send
146 * @param hdr IPv4 header
147 * @param dest next hop address of packet.
148 *
149 * This method will eventually call the private
150 * SendTo method which must be implemented by subclasses.
151 */
152 void Send(Ptr<Packet> p, const Ipv4Header& hdr, Ipv4Address dest);
153
154 /**
155 * @param address The Ipv4InterfaceAddress to add to the interface
156 * @returns true if succeeded
157 */
158 bool AddAddress(Ipv4InterfaceAddress address);
159
160 /**
161 * @param index Index of Ipv4InterfaceAddress to return
162 * @returns The Ipv4InterfaceAddress address whose index is i
163 */
165
166 /**
167 * @returns the number of Ipv4InterfaceAddress stored on this interface
168 */
169 uint32_t GetNAddresses() const;
170
171 /**
172 * @param index Index of Ipv4InterfaceAddress to remove
173 * @returns The Ipv4InterfaceAddress address whose index is index
174 */
176
177 /**
178 * @brief Remove the given Ipv4 address from the interface.
179 * @param address The Ipv4 address to remove
180 * @returns The removed Ipv4 interface address
181 * @returns The null interface address if the interface did not contain the
182 * address or if loopback address was passed as argument
183 */
185
186 /**
187 * This callback is set when an address is removed from an interface with
188 * auto-generated Arp cache and it allow the neighbor cache helper to update
189 * neighbor's Arp cache
190 *
191 * @param removeAddressCallback Callback when remove an address.
192 */
194 Callback<void, Ptr<Ipv4Interface>, Ipv4InterfaceAddress> removeAddressCallback);
195
196 /**
197 * This callback is set when an address is added from an interface with
198 * auto-generated Arp cache and it allow the neighbor cache helper to update
199 * neighbor's Arp cache
200 *
201 * @param addAddressCallback Callback when remove an address.
202 */
204 Callback<void, Ptr<Ipv4Interface>, Ipv4InterfaceAddress> addAddressCallback);
205
206 protected:
207 void DoDispose() override;
208
209 private:
210 /**
211 * @brief Initialize interface.
212 */
213 void DoSetup();
214
215 /**
216 * @brief Container for the Ipv4InterfaceAddresses.
217 */
218 typedef std::list<Ipv4InterfaceAddress> Ipv4InterfaceAddressList;
219
220 /**
221 * @brief Container Iterator for the Ipv4InterfaceAddresses.
222 */
223 typedef std::list<Ipv4InterfaceAddress>::const_iterator Ipv4InterfaceAddressListCI;
224
225 /**
226 * @brief Const Container Iterator for the Ipv4InterfaceAddresses.
227 */
228 typedef std::list<Ipv4InterfaceAddress>::iterator Ipv4InterfaceAddressListI;
229
230 bool m_ifup; //!< The state of this interface
231 bool m_forwarding; //!< Forwarding state.
232 uint16_t m_metric; //!< Interface metric
234 Ptr<Node> m_node; //!< The associated node
235 Ptr<NetDevice> m_device; //!< The associated NetDevice
236 Ptr<TrafficControlLayer> m_tc; //!< The associated TrafficControlLayer
237 Ptr<ArpCache> m_cache; //!< ARP cache
239 m_removeAddressCallback; //!< remove address callback
241 m_addAddressCallback; //!< add address callback
242
243 /**
244 * The trace fired when the interface state changes.
245 * Includes state (true if interface is up) and the interface index.
246 */
248};
249
250} // namespace ns3
251
252#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
ns3::TracedCallback< bool, int32_t > m_interfaceStatus
The trace fired when the interface state changes.
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.
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:49
Every class exported by the ns3 library is enclosed in the ns3 namespace.