|
mathieu@522
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
mathieu@522
|
2 |
/*
|
|
mathieu@522
|
3 |
* Copyright (c) 2007 INRIA
|
|
mathieu@522
|
4 |
*
|
|
mathieu@522
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
mathieu@522
|
6 |
* it under the terms of the GNU General Public License version 2 as
|
|
mathieu@522
|
7 |
* published by the Free Software Foundation;
|
|
mathieu@522
|
8 |
*
|
|
mathieu@522
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
mathieu@522
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
mathieu@522
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
mathieu@522
|
12 |
* GNU General Public License for more details.
|
|
mathieu@522
|
13 |
*
|
|
mathieu@522
|
14 |
* You should have received a copy of the GNU General Public License
|
|
mathieu@522
|
15 |
* along with this program; if not, write to the Free Software
|
|
mathieu@522
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
mathieu@522
|
17 |
*
|
|
mathieu@522
|
18 |
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
|
mathieu@522
|
19 |
*/
|
|
mathieu@752
|
20 |
#ifndef IPV4_H
|
|
mathieu@752
|
21 |
#define IPV4_H
|
|
mathieu@522
|
22 |
|
|
mathieu@522
|
23 |
#include <stdint.h>
|
|
mathieu@710
|
24 |
#include "ns3/object.h"
|
|
tomh@4472
|
25 |
#include "ns3/socket.h"
|
|
gjc@983
|
26 |
#include "ns3/callback.h"
|
|
tomh@4472
|
27 |
#include "ipv4-address.h"
|
|
tomh@4472
|
28 |
#include "ipv4-interface-address.h"
|
|
mathieu@522
|
29 |
|
|
mathieu@522
|
30 |
namespace ns3 {
|
|
mathieu@522
|
31 |
|
|
tomh@1316
|
32 |
class Node;
|
|
mathieu@522
|
33 |
class NetDevice;
|
|
mathieu@522
|
34 |
class Packet;
|
|
mathieu@4560
|
35 |
class Ipv4RoutingProtocol;
|
|
gjc@983
|
36 |
|
|
gjc@985
|
37 |
/**
|
|
tomh@3183
|
38 |
* \ingroup node
|
|
tomh@3183
|
39 |
* \defgroup ipv4 Ipv4
|
|
tomh@4701
|
40 |
*/
|
|
tomh@4701
|
41 |
/**
|
|
tomh@4701
|
42 |
* \ingroup ipv4
|
|
tomh@4472
|
43 |
* \brief Access to the Ipv4 forwarding table, interfaces, and configuration
|
|
tomh@3183
|
44 |
*
|
|
tomh@4472
|
45 |
* This class defines the API to manipulate the following aspects of
|
|
tomh@4472
|
46 |
* the Ipv4 implementation:
|
|
tomh@4472
|
47 |
* -# set/get an Ipv4RoutingProtocol
|
|
tomh@4472
|
48 |
* -# register a NetDevice for use by the Ipv4 layer (basically, to
|
|
tomh@4472
|
49 |
* create Ipv4-related state such as addressing and neighbor cache that
|
|
tomh@4472
|
50 |
* is associated with a NetDevice)
|
|
tomh@4472
|
51 |
* -# manipulate the status of the NetDevice from the Ipv4 perspective,
|
|
tomh@4472
|
52 |
* such as marking it as Up or Down,
|
|
tomh@4472
|
53 |
* -# adding, deleting, and getting addresses associated to the Ipv4
|
|
tomh@4472
|
54 |
* interfaces.
|
|
tomh@4472
|
55 |
* -# exporting Ipv4 configuration attributes
|
|
tomh@4472
|
56 |
*
|
|
tomh@4472
|
57 |
* Each NetDevice has conceptually a single Ipv4 interface associated
|
|
tomh@4472
|
58 |
* with it (the corresponding structure in the Linux Ipv4 implementation
|
|
tomh@4472
|
59 |
* is struct in_device). Each interface may have one or more Ipv4
|
|
tomh@4472
|
60 |
* addresses associated with it. Each Ipv4 address may have different
|
|
tomh@4472
|
61 |
* subnet mask, scope, etc., so all of this per-address information
|
|
tomh@4472
|
62 |
* is stored in an Ipv4InterfaceAddress class (the corresponding
|
|
tomh@4472
|
63 |
* structure in Linux is struct in_ifaddr)
|
|
gjc@985
|
64 |
*
|
|
tomh@4472
|
65 |
* Ipv4 attributes such as whether IP forwarding is enabled and disabled
|
|
tomh@4472
|
66 |
* are also stored in this class
|
|
craigdo@1444
|
67 |
*
|
|
tomh@4472
|
68 |
* TO DO: Add API to allow access to the Ipv4 neighbor table
|
|
craigdo@1444
|
69 |
*
|
|
craigdo@1444
|
70 |
* \see Ipv4RoutingProtocol
|
|
tomh@4472
|
71 |
* \see Ipv4InterfaceAddress
|
|
raj@633
|
72 |
*/
|
|
mathieu@752
|
73 |
class Ipv4 : public Object
|
|
mathieu@522
|
74 |
{
|
|
mathieu@522
|
75 |
public:
|
|
mathieu@2251
|
76 |
static TypeId GetTypeId (void);
|
|
mathieu@752
|
77 |
Ipv4 ();
|
|
mathieu@752
|
78 |
virtual ~Ipv4 ();
|
|
gjc@983
|
79 |
|
|
gjc@985
|
80 |
/**
|
|
tomh@4472
|
81 |
* \brief Register a new routing protocol to be used by this Ipv4 stack
|
|
tomh@4472
|
82 |
*
|
|
tomh@4472
|
83 |
* This call will replace any routing protocol that has been previously
|
|
tomh@4472
|
84 |
* registered. If you want to add multiple routing protocols, you must
|
|
tomh@4472
|
85 |
* add them to a Ipv4ListRoutingProtocol directly.
|
|
gjc@985
|
86 |
*
|
|
tomh@4481
|
87 |
* \param routingProtocol smart pointer to Ipv4RoutingProtocol object
|
|
gjc@985
|
88 |
*/
|
|
tomh@4472
|
89 |
virtual void SetRoutingProtocol (Ptr<Ipv4RoutingProtocol> routingProtocol) = 0;
|
|
mathieu@522
|
90 |
|
|
mathieu@522
|
91 |
/**
|
|
tomh@4472
|
92 |
* \brief Get the routing protocol to be used by this Ipv4 stack
|
|
mathieu@522
|
93 |
*
|
|
tomh@4472
|
94 |
* \returns smart pointer to Ipv4RoutingProtocol object, or null pointer if none
|
|
mathieu@522
|
95 |
*/
|
|
tomh@4472
|
96 |
virtual Ptr<Ipv4RoutingProtocol> GetRoutingProtocol (void) const = 0;
|
|
mathieu@522
|
97 |
|
|
mathieu@522
|
98 |
/**
|
|
tomh@4472
|
99 |
* \param device device to add to the list of Ipv4 interfaces
|
|
mathieu@638
|
100 |
* which can be used as output interfaces during packet forwarding.
|
|
tomh@4472
|
101 |
* \returns the index of the Ipv4 interface added.
|
|
mathieu@522
|
102 |
*
|
|
mathieu@638
|
103 |
* Once a device has been added, it can never be removed: if you want
|
|
mathieu@755
|
104 |
* to disable it, you can invoke Ipv4::SetDown which will
|
|
mathieu@522
|
105 |
* make sure that it is never used during packet forwarding.
|
|
mathieu@522
|
106 |
*/
|
|
mathieu@568
|
107 |
virtual uint32_t AddInterface (Ptr<NetDevice> device) = 0;
|
|
craigdo@1444
|
108 |
|
|
mathieu@522
|
109 |
/**
|
|
mathieu@522
|
110 |
* \returns the number of interfaces added by the user.
|
|
mathieu@522
|
111 |
*/
|
|
tomh@4377
|
112 |
virtual uint32_t GetNInterfaces (void) const = 0;
|
|
mathieu@522
|
113 |
|
|
tomh@540
|
114 |
/**
|
|
tomh@4472
|
115 |
* \brief Return the interface number of the interface that has been
|
|
craigdo@1440
|
116 |
* assigned the specified IP address.
|
|
craigdo@1440
|
117 |
*
|
|
tomh@4472
|
118 |
* \param address The IP address being searched for
|
|
tomh@4472
|
119 |
* \returns The interface number of the Ipv4 interface with the given
|
|
tomh@4472
|
120 |
* address or -1 if not found.
|
|
tomh@4472
|
121 |
*
|
|
tomh@4472
|
122 |
* Each IP interface has one or more IP addresses associated with it.
|
|
tomh@4472
|
123 |
* This method searches the list of interfaces for one that holds a
|
|
tomh@4472
|
124 |
* particular address. This call takes an IP address as a parameter and
|
|
tomh@4472
|
125 |
* returns the interface number of the first interface that has been assigned
|
|
tomh@4472
|
126 |
* that address, or -1 if not found. There must be an exact match.
|
|
craigdo@1440
|
127 |
*/
|
|
tomh@4472
|
128 |
virtual int32_t GetInterfaceForAddress (Ipv4Address address) const = 0;
|
|
craigdo@1440
|
129 |
|
|
craigdo@1440
|
130 |
/**
|
|
tomh@4472
|
131 |
* \brief Return the interface number of first interface found that
|
|
tomh@4472
|
132 |
* has an Ipv4 address within the prefix specified by the input
|
|
tomh@4472
|
133 |
* address and mask parameters
|
|
tomh@4472
|
134 |
*
|
|
tomh@4481
|
135 |
* \param address The IP address assigned to the interface of interest.
|
|
tomh@4481
|
136 |
* \param mask The IP prefix to use in the mask
|
|
tomh@4472
|
137 |
* \returns The interface number of the Ipv4 interface with the given
|
|
tomh@4472
|
138 |
* address or -1 if not found.
|
|
craigdo@1440
|
139 |
*
|
|
tomh@4472
|
140 |
* Each IP interface has one or more IP addresses associated with it.
|
|
tomh@4472
|
141 |
* This method searches the list of interfaces for the first one found
|
|
tomh@4472
|
142 |
* that holds an address that is included within the prefix
|
|
tomh@4472
|
143 |
* formed by the input address and mask parameters. The value -1 is
|
|
tomh@4472
|
144 |
* returned if no match is found.
|
|
craigdo@1440
|
145 |
*/
|
|
tomh@4472
|
146 |
virtual int32_t GetInterfaceForPrefix (Ipv4Address address,
|
|
craigdo@1440
|
147 |
Ipv4Mask mask) const = 0;
|
|
craigdo@1440
|
148 |
|
|
craigdo@1440
|
149 |
/**
|
|
tomh@4472
|
150 |
* \param interface The interface number of an Ipv4 interface.
|
|
tomh@4472
|
151 |
* \returns The NetDevice associated with the Ipv4 interface number.
|
|
craigdo@2711
|
152 |
*/
|
|
tomh@4472
|
153 |
virtual Ptr<NetDevice> GetNetDevice (uint32_t interface) = 0;
|
|
craigdo@2711
|
154 |
|
|
craigdo@2711
|
155 |
/**
|
|
tomh@4472
|
156 |
* \param device The NetDevice for an Ipv4Interface
|
|
tomh@4472
|
157 |
* \returns The interface number of an Ipv4 interface or -1 if not found.
|
|
tomh@540
|
158 |
*/
|
|
tomh@4472
|
159 |
virtual int32_t GetInterfaceForDevice (Ptr<const NetDevice> device) const = 0;
|
|
craigdo@1428
|
160 |
|
|
craigdo@1428
|
161 |
/**
|
|
tomh@4373
|
162 |
* \param interface Interface number of an Ipv4 interface
|
|
tomh@4373
|
163 |
* \param address Ipv4InterfaceAddress address to associate with the underlying Ipv4 interface
|
|
tomh@4563
|
164 |
* \returns true if the operation succeeded
|
|
tomh@4373
|
165 |
*/
|
|
tomh@4563
|
166 |
virtual bool AddAddress (uint32_t interface, Ipv4InterfaceAddress address) = 0;
|
|
tomh@4373
|
167 |
|
|
tomh@4373
|
168 |
/**
|
|
tomh@4373
|
169 |
* \param interface Interface number of an Ipv4 interface
|
|
tomh@4373
|
170 |
* \returns the number of Ipv4InterfaceAddress entries for the interface.
|
|
tomh@4373
|
171 |
*/
|
|
tomh@4373
|
172 |
virtual uint32_t GetNAddresses (uint32_t interface) const = 0;
|
|
tomh@4373
|
173 |
|
|
tomh@4373
|
174 |
/**
|
|
tomh@4563
|
175 |
* Because addresses can be removed, the addressIndex is not guaranteed
|
|
tomh@4563
|
176 |
* to be static across calls to this method.
|
|
tomh@4563
|
177 |
*
|
|
tomh@4373
|
178 |
* \param interface Interface number of an Ipv4 interface
|
|
tomh@4472
|
179 |
* \param addressIndex index of Ipv4InterfaceAddress
|
|
tomh@4373
|
180 |
* \returns the Ipv4InterfaceAddress associated to the interface and addresIndex
|
|
tomh@4373
|
181 |
*/
|
|
tomh@4373
|
182 |
virtual Ipv4InterfaceAddress GetAddress (uint32_t interface, uint32_t addressIndex) const = 0;
|
|
tomh@4373
|
183 |
|
|
tomh@4373
|
184 |
/**
|
|
tomh@4563
|
185 |
* Remove the address at addressIndex on named interface. The addressIndex
|
|
tomh@4563
|
186 |
* for all higher indices will decrement by one after this method is called;
|
|
tomh@4563
|
187 |
* so, for example, to remove 5 addresses from an interface i, one could
|
|
tomh@4563
|
188 |
* call RemoveAddress (i, 0); 5 times.
|
|
tomh@4563
|
189 |
*
|
|
tomh@4563
|
190 |
* \param interface Interface number of an Ipv4 interface
|
|
tomh@4563
|
191 |
* \param addressIndex index of Ipv4InterfaceAddress to remove
|
|
tomh@4563
|
192 |
* \returns true if the operation succeeded
|
|
tomh@4563
|
193 |
*/
|
|
tomh@4563
|
194 |
virtual bool RemoveAddress (uint32_t interface, uint32_t addressIndex) = 0;
|
|
tomh@4563
|
195 |
|
|
tomh@4563
|
196 |
/**
|
|
tomh@4472
|
197 |
* \param interface The interface number of an Ipv4 interface
|
|
tomh@1776
|
198 |
* \param metric routing metric (cost) associated to the underlying
|
|
tomh@4472
|
199 |
* Ipv4 interface
|
|
tomh@1776
|
200 |
*/
|
|
tomh@4472
|
201 |
virtual void SetMetric (uint32_t interface, uint16_t metric) = 0;
|
|
tomh@1776
|
202 |
|
|
tomh@1776
|
203 |
/**
|
|
tomh@4472
|
204 |
* \param interface The interface number of an Ipv4 interface
|
|
tomh@1776
|
205 |
* \returns routing metric (cost) associated to the underlying
|
|
tomh@4472
|
206 |
* Ipv4 interface
|
|
tomh@1776
|
207 |
*/
|
|
tomh@4472
|
208 |
virtual uint16_t GetMetric (uint32_t interface) const = 0;
|
|
tomh@1776
|
209 |
|
|
tomh@1776
|
210 |
/**
|
|
tomh@4472
|
211 |
* \param interface Interface number of Ipv4 interface
|
|
tomh@4472
|
212 |
* \returns the Maximum Transmission Unit (in bytes) associated
|
|
tomh@4472
|
213 |
* to the underlying Ipv4 interface
|
|
craigdo@1434
|
214 |
*/
|
|
tomh@4472
|
215 |
virtual uint16_t GetMtu (uint32_t interface) const = 0;
|
|
craigdo@1444
|
216 |
|
|
mathieu@638
|
217 |
/**
|
|
tomh@4472
|
218 |
* \param interface Interface number of Ipv4 interface
|
|
mathieu@638
|
219 |
* \returns true if the underlying interface is in the "up" state,
|
|
mathieu@638
|
220 |
* false otherwise.
|
|
mathieu@638
|
221 |
*/
|
|
tomh@4472
|
222 |
virtual bool IsUp (uint32_t interface) const = 0;
|
|
craigdo@1444
|
223 |
|
|
mathieu@638
|
224 |
/**
|
|
tomh@4481
|
225 |
* \param interface Interface number of Ipv4 interface
|
|
mathieu@638
|
226 |
*
|
|
mathieu@638
|
227 |
* Set the interface into the "up" state. In this state, it is
|
|
tomh@4472
|
228 |
* considered valid during Ipv4 forwarding.
|
|
mathieu@638
|
229 |
*/
|
|
tomh@4472
|
230 |
virtual void SetUp (uint32_t interface) = 0;
|
|
craigdo@1444
|
231 |
|
|
mathieu@638
|
232 |
/**
|
|
tomh@4472
|
233 |
* \param interface Interface number of Ipv4 interface
|
|
mathieu@638
|
234 |
*
|
|
mathieu@638
|
235 |
* Set the interface into the "down" state. In this state, it is
|
|
tomh@4472
|
236 |
* ignored during Ipv4 forwarding.
|
|
mathieu@638
|
237 |
*/
|
|
tomh@4472
|
238 |
virtual void SetDown (uint32_t interface) = 0;
|
|
mathieu@522
|
239 |
|
|
tomh@4607
|
240 |
/**
|
|
tomh@4607
|
241 |
* \param interface Interface number of Ipv4 interface
|
|
tomh@4607
|
242 |
* \returns true if IP forwarding enabled for input datagrams on this device
|
|
tomh@4607
|
243 |
*/
|
|
tomh@4607
|
244 |
virtual bool IsForwarding (uint32_t interface) const = 0;
|
|
tomh@4607
|
245 |
|
|
tomh@4607
|
246 |
/**
|
|
tomh@4607
|
247 |
* \param interface Interface number of Ipv4 interface
|
|
tomh@4607
|
248 |
* \param val Value to set the forwarding flag
|
|
tomh@4607
|
249 |
*
|
|
tomh@4607
|
250 |
* If set to true, IP forwarding is enabled for input datagrams on this device
|
|
tomh@4607
|
251 |
*/
|
|
tomh@4607
|
252 |
virtual void SetForwarding (uint32_t interface, bool val) = 0;
|
|
tomh@4607
|
253 |
|
|
tomh@4472
|
254 |
static const uint32_t IF_ANY = 0xffffffff;
|
|
tomh@4472
|
255 |
|
|
tomh@4472
|
256 |
private:
|
|
tomh@4472
|
257 |
// Indirect the Ipv4 attributes through private pure virtual methods
|
|
tomh@4472
|
258 |
virtual void SetIpForward (bool forward) = 0;
|
|
tomh@4472
|
259 |
virtual bool GetIpForward (void) const = 0;
|
|
craigdo@1452
|
260 |
};
|
|
tomh@1316
|
261 |
|
|
mathieu@522
|
262 |
} // namespace ns3
|
|
mathieu@522
|
263 |
|
|
mathieu@752
|
264 |
#endif /* IPV4_H */
|