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