|
mathieu@234
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
mathieu@234
|
2 |
/*
|
|
mathieu@234
|
3 |
* Copyright (c) 2005,2006 INRIA
|
|
mathieu@234
|
4 |
*
|
|
mathieu@234
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
mathieu@234
|
6 |
* it under the terms of the GNU General Public License version 2 as
|
|
mathieu@234
|
7 |
* published by the Free Software Foundation;
|
|
mathieu@234
|
8 |
*
|
|
mathieu@234
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
mathieu@234
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
mathieu@234
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
mathieu@234
|
12 |
* GNU General Public License for more details.
|
|
mathieu@234
|
13 |
*
|
|
mathieu@234
|
14 |
* You should have received a copy of the GNU General Public License
|
|
mathieu@234
|
15 |
* along with this program; if not, write to the Free Software
|
|
mathieu@234
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
mathieu@234
|
17 |
*
|
|
mathieu@234
|
18 |
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
|
emmanuelle@975
|
19 |
* Modified by Emmanuelle Laprise to remove dependance on LLC headers
|
|
mathieu@234
|
20 |
*/
|
|
mathieu@234
|
21 |
#ifndef NET_DEVICE_H
|
|
mathieu@234
|
22 |
#define NET_DEVICE_H
|
|
mathieu@234
|
23 |
|
|
mathieu@234
|
24 |
#include <string>
|
|
mathieu@234
|
25 |
#include <stdint.h>
|
|
mathieu@234
|
26 |
#include "ns3/callback.h"
|
|
mathieu@710
|
27 |
#include "ns3/object.h"
|
|
mathieu@582
|
28 |
#include "ns3/ptr.h"
|
|
mathieu@1161
|
29 |
#include "address.h"
|
|
craigdo@1443
|
30 |
#include "ipv4-address.h"
|
|
vincent@3852
|
31 |
#include "ipv6-address.h"
|
|
mathieu@234
|
32 |
|
|
mathieu@234
|
33 |
namespace ns3 {
|
|
mathieu@234
|
34 |
|
|
mathieu@728
|
35 |
class Node;
|
|
mathieu@402
|
36 |
class Channel;
|
|
mathieu@1866
|
37 |
class Packet;
|
|
mathieu@234
|
38 |
|
|
mathieu@234
|
39 |
/**
|
|
tomh@3183
|
40 |
* \ingroup node
|
|
tomh@3183
|
41 |
* \defgroup netdevice NetDevice
|
|
tomh@3183
|
42 |
*/
|
|
tomh@3183
|
43 |
/**
|
|
mathieu@3222
|
44 |
* \ingroup netdevice
|
|
tomh@3183
|
45 |
*
|
|
mathieu@234
|
46 |
* \brief Network layer to device interface
|
|
mathieu@234
|
47 |
*
|
|
mathieu@234
|
48 |
* This interface defines the API which the IP and ARP
|
|
mathieu@234
|
49 |
* layers need to access to manage an instance of a network device
|
|
mathieu@234
|
50 |
* layer. It currently does not support MAC-level
|
|
mathieu@234
|
51 |
* multicast but this should not be too hard to add by adding
|
|
mathieu@234
|
52 |
* extra methods to register MAC multicast addresses to
|
|
mathieu@234
|
53 |
* filter out unwanted packets before handing them to the
|
|
mathieu@234
|
54 |
* higher layers.
|
|
mathieu@234
|
55 |
*
|
|
mathieu@234
|
56 |
* In Linux, this interface is analogous to the interface
|
|
mathieu@234
|
57 |
* just above dev_queue_xmit() (i.e., IP packet is fully
|
|
mathieu@234
|
58 |
* constructed with destination MAC address already selected).
|
|
mathieu@234
|
59 |
*
|
|
mathieu@234
|
60 |
* If you want to write a new MAC layer, you need to subclass
|
|
Craig@378
|
61 |
* this base class and implement your own version of the
|
|
mathieu@234
|
62 |
* NetDevice::SendTo method.
|
|
mathieu@234
|
63 |
*/
|
|
mathieu@710
|
64 |
class NetDevice : public Object
|
|
mathieu@469
|
65 |
{
|
|
mathieu@469
|
66 |
public:
|
|
mathieu@2251
|
67 |
static TypeId GetTypeId (void);
|
|
mathieu@487
|
68 |
virtual ~NetDevice();
|
|
tomh@345
|
69 |
|
|
mathieu@2470
|
70 |
/**
|
|
mathieu@2470
|
71 |
* \param name name of the device (e.g. "eth0")
|
|
mathieu@2470
|
72 |
*/
|
|
mathieu@2470
|
73 |
virtual void SetName(const std::string name) = 0;
|
|
mathieu@2470
|
74 |
/**
|
|
mathieu@2470
|
75 |
* \return name name of the device (e.g. "eth0")
|
|
mathieu@2470
|
76 |
*/
|
|
mathieu@2470
|
77 |
virtual std::string GetName(void) const = 0;
|
|
mathieu@2470
|
78 |
/**
|
|
mathieu@2470
|
79 |
* \param index ifIndex of the device
|
|
mathieu@2470
|
80 |
*/
|
|
mathieu@2470
|
81 |
virtual void SetIfIndex(const uint32_t index) = 0;
|
|
mathieu@2470
|
82 |
/**
|
|
mathieu@2470
|
83 |
* \return index ifIndex of the device
|
|
mathieu@2470
|
84 |
*/
|
|
mathieu@2470
|
85 |
virtual uint32_t GetIfIndex(void) const = 0;
|
|
mathieu@2470
|
86 |
|
|
tomh@345
|
87 |
|
|
mathieu@234
|
88 |
/**
|
|
mathieu@402
|
89 |
* \return the channel this NetDevice is connected to. The value
|
|
mathieu@402
|
90 |
* returned can be zero if the NetDevice is not yet connected
|
|
mathieu@402
|
91 |
* to any channel.
|
|
mathieu@402
|
92 |
*/
|
|
mathieu@2470
|
93 |
virtual Ptr<Channel> GetChannel (void) const = 0;
|
|
mathieu@402
|
94 |
|
|
mathieu@402
|
95 |
/**
|
|
mathieu@1161
|
96 |
* \return the current Address of this interface.
|
|
mathieu@234
|
97 |
*/
|
|
mathieu@2470
|
98 |
virtual Address GetAddress (void) const = 0;
|
|
mathieu@234
|
99 |
/**
|
|
mathieu@234
|
100 |
* \param mtu MTU value, in bytes, to set for the device
|
|
mathieu@234
|
101 |
* \return whether the MTU value was within legal bounds
|
|
mathieu@234
|
102 |
*
|
|
mathieu@234
|
103 |
* Override for default MTU defined on a per-type basis.
|
|
mathieu@234
|
104 |
*/
|
|
mathieu@2470
|
105 |
virtual bool SetMtu (const uint16_t mtu) = 0;
|
|
mathieu@234
|
106 |
/**
|
|
mathieu@234
|
107 |
* \return the link-level MTU in bytes for this interface.
|
|
mathieu@234
|
108 |
*
|
|
mathieu@234
|
109 |
* This value is typically used by the IP layer to perform
|
|
mathieu@234
|
110 |
* IP fragmentation when needed.
|
|
mathieu@234
|
111 |
*/
|
|
mathieu@2470
|
112 |
virtual uint16_t GetMtu (void) const = 0;
|
|
tomh@535
|
113 |
/**
|
|
mathieu@234
|
114 |
* \return true if link is up; false otherwise
|
|
mathieu@234
|
115 |
*/
|
|
mathieu@2470
|
116 |
virtual bool IsLinkUp (void) const = 0;
|
|
mathieu@234
|
117 |
/**
|
|
mathieu@234
|
118 |
* \param callback the callback to invoke
|
|
mathieu@234
|
119 |
*
|
|
mathieu@234
|
120 |
* Register a callback invoked whenever the link
|
|
mathieu@234
|
121 |
* status changes to UP. This callback is typically used
|
|
mathieu@234
|
122 |
* by the IP/ARP layer to flush the ARP cache
|
|
mathieu@234
|
123 |
* whenever the link goes up.
|
|
mathieu@234
|
124 |
*/
|
|
mathieu@2470
|
125 |
virtual void SetLinkChangeCallback (Callback<void> callback) = 0;
|
|
mathieu@234
|
126 |
/**
|
|
mathieu@234
|
127 |
* \return true if this interface supports a broadcast address,
|
|
mathieu@234
|
128 |
* false otherwise.
|
|
mathieu@234
|
129 |
*/
|
|
mathieu@2470
|
130 |
virtual bool IsBroadcast (void) const = 0;
|
|
mathieu@234
|
131 |
/**
|
|
mathieu@234
|
132 |
* \return the broadcast address supported by
|
|
mathieu@234
|
133 |
* this netdevice.
|
|
mathieu@234
|
134 |
*
|
|
mathieu@234
|
135 |
* Calling this method is invalid if IsBroadcast returns
|
|
mathieu@234
|
136 |
* not true.
|
|
mathieu@234
|
137 |
*/
|
|
mathieu@2470
|
138 |
virtual Address GetBroadcast (void) const = 0;
|
|
craigdo@1441
|
139 |
|
|
mathieu@234
|
140 |
/**
|
|
mathieu@234
|
141 |
* \return value of m_isMulticast flag
|
|
mathieu@234
|
142 |
*/
|
|
mathieu@2470
|
143 |
virtual bool IsMulticast (void) const = 0;
|
|
craigdo@1441
|
144 |
|
|
craigdo@1441
|
145 |
/**
|
|
craigdo@1443
|
146 |
* \brief Make and return a MAC multicast address using the provided
|
|
craigdo@1443
|
147 |
* multicast group
|
|
craigdo@1443
|
148 |
*
|
|
craigdo@1443
|
149 |
* RFC 1112 says that an Ipv4 host group address is mapped to an Ethernet
|
|
craigdo@1443
|
150 |
* multicast address by placing the low-order 23-bits of the IP address into
|
|
craigdo@1443
|
151 |
* the low-order 23 bits of the Ethernet multicast address
|
|
craigdo@1443
|
152 |
* 01-00-5E-00-00-00 (hex). Similar RFCs exist for Ipv6 and Eui64 mappings.
|
|
craigdo@1443
|
153 |
* This method performs the multicast address creation function appropriate
|
|
craigdo@1443
|
154 |
* to the underlying MAC address of the device. This MAC address is
|
|
craigdo@1443
|
155 |
* encapsulated in an abstract Address to avoid dependencies on the exact
|
|
craigdo@1443
|
156 |
* MAC address format.
|
|
craigdo@1443
|
157 |
*
|
|
craigdo@3841
|
158 |
* A default imlementation of GetMulticast is provided, but this
|
|
craigdo@1443
|
159 |
* method simply NS_ASSERTS. In the case of net devices that do not support
|
|
craigdo@1443
|
160 |
* multicast, clients are expected to test NetDevice::IsMulticast and avoid
|
|
craigdo@1443
|
161 |
* attempting to map multicast packets. Subclasses of NetDevice that do
|
|
craigdo@1443
|
162 |
* support multicasting are expected to override this method and provide an
|
|
craigdo@1443
|
163 |
* implementation appropriate to the particular device.
|
|
craigdo@1443
|
164 |
*
|
|
craigdo@1443
|
165 |
* \param multicastGroup The IP address for the multicast group destination
|
|
craigdo@1443
|
166 |
* of the packet.
|
|
craigdo@1443
|
167 |
* \return The MAC multicast Address used to send packets to the provided
|
|
craigdo@1443
|
168 |
* multicast group.
|
|
craigdo@1443
|
169 |
*
|
|
craigdo@1443
|
170 |
* \warning Calling this method is invalid if IsMulticast returns not true.
|
|
craigdo@1443
|
171 |
* \see Ipv4Address
|
|
craigdo@1443
|
172 |
* \see Address
|
|
craigdo@1443
|
173 |
* \see NetDevice::IsMulticast
|
|
craigdo@1443
|
174 |
*/
|
|
craigdo@3841
|
175 |
virtual Address GetMulticast (Ipv4Address multicastGroup) const = 0;
|
|
mathieu@2470
|
176 |
|
|
vincent@3852
|
177 |
/**
|
|
vincent@3852
|
178 |
* \brief Get the MAC multicast address corresponding
|
|
vincent@3852
|
179 |
* to the IPv6 address provided.
|
|
vincent@3852
|
180 |
* \param addr IPv6 address
|
|
vincent@3852
|
181 |
* \return the MAC multicast address
|
|
vincent@3852
|
182 |
* \warning Calling this method is invalid if IsMulticast returns not true.
|
|
vincent@3852
|
183 |
*/
|
|
vincent@3852
|
184 |
virtual Address GetMulticast (Ipv6Address addr) const = 0;
|
|
vincent@3852
|
185 |
|
|
mathieu@234
|
186 |
/**
|
|
mathieu@234
|
187 |
* \return value of m_isPointToPoint flag
|
|
mathieu@234
|
188 |
*/
|
|
mathieu@2470
|
189 |
virtual bool IsPointToPoint (void) const = 0;
|
|
mathieu@234
|
190 |
/**
|
|
tomh@2191
|
191 |
* \param packet packet sent from above down to Network Device
|
|
mathieu@234
|
192 |
* \param dest mac address of the destination (already resolved)
|
|
mathieu@234
|
193 |
* \param protocolNumber identifies the type of payload contained in
|
|
mathieu@234
|
194 |
* this packet. Used to call the right L3Protocol when the packet
|
|
mathieu@234
|
195 |
* is received.
|
|
mathieu@234
|
196 |
*
|
|
mathieu@234
|
197 |
* Called from higher layer to send packet into Network Device
|
|
mathieu@1161
|
198 |
* to the specified destination Address
|
|
mathieu@234
|
199 |
*
|
|
mathieu@234
|
200 |
* \return whether the Send operation succeeded
|
|
mathieu@234
|
201 |
*/
|
|
mathieu@2470
|
202 |
virtual bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) = 0;
|
|
tomh@535
|
203 |
/**
|
|
gjc@3442
|
204 |
* \param packet packet sent from above down to Network Device
|
|
gjc@3442
|
205 |
* \param source source mac address (so called "MAC spoofing")
|
|
gjc@3442
|
206 |
* \param dest mac address of the destination (already resolved)
|
|
gjc@3442
|
207 |
* \param protocolNumber identifies the type of payload contained in
|
|
gjc@3442
|
208 |
* this packet. Used to call the right L3Protocol when the packet
|
|
gjc@3442
|
209 |
* is received.
|
|
gjc@3442
|
210 |
*
|
|
gjc@3442
|
211 |
* Called from higher layer to send packet into Network Device
|
|
gjc@3442
|
212 |
* with the specified source and destination Addresses.
|
|
gjc@3442
|
213 |
*
|
|
gjc@3442
|
214 |
* \return whether the Send operation succeeded
|
|
gjc@3442
|
215 |
*/
|
|
gjc@3480
|
216 |
virtual bool SendFrom(Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber) = 0;
|
|
gjc@3442
|
217 |
/**
|
|
tomh@535
|
218 |
* \returns the node base class which contains this network
|
|
tomh@535
|
219 |
* interface.
|
|
tomh@535
|
220 |
*
|
|
tomh@535
|
221 |
* When a subclass needs to get access to the underlying node
|
|
tomh@535
|
222 |
* base class to print the nodeid for example, it can invoke
|
|
tomh@535
|
223 |
* this method.
|
|
tomh@535
|
224 |
*/
|
|
mathieu@2470
|
225 |
virtual Ptr<Node> GetNode (void) const = 0;
|
|
mathieu@234
|
226 |
|
|
mathieu@3310
|
227 |
/**
|
|
mathieu@3310
|
228 |
* \param node the node associated to this netdevice.
|
|
mathieu@3310
|
229 |
*
|
|
mathieu@3310
|
230 |
* This method is called from ns3::Node::AddDevice.
|
|
mathieu@3310
|
231 |
*/
|
|
mathieu@2600
|
232 |
virtual void SetNode (Ptr<Node> node) = 0;
|
|
mathieu@2600
|
233 |
|
|
mathieu@597
|
234 |
/**
|
|
mathieu@597
|
235 |
* \returns true if ARP is needed, false otherwise.
|
|
mathieu@597
|
236 |
*
|
|
mathieu@597
|
237 |
* Called by higher-layers to check if this NetDevice requires
|
|
mathieu@597
|
238 |
* ARP to be used.
|
|
mathieu@597
|
239 |
*/
|
|
mathieu@2470
|
240 |
virtual bool NeedsArp (void) const = 0;
|
|
mathieu@445
|
241 |
|
|
gjc@3448
|
242 |
|
|
craigdo@3827
|
243 |
/**
|
|
craigdo@3827
|
244 |
* Packet types are used as they are in Linux. GCC name resolution on
|
|
craigdo@3827
|
245 |
* typedef enum {} PacketType is broken for the foreseeable future, so
|
|
craigdo@3827
|
246 |
* if you need to use ns-3 PacketType in a driver that also uses the
|
|
craigdo@3827
|
247 |
* Linux packet types you're hosed unless we define a shadow type,
|
|
craigdo@3827
|
248 |
* which we do here.
|
|
craigdo@3827
|
249 |
*/
|
|
gjc@3448
|
250 |
enum PacketType
|
|
gjc@3448
|
251 |
{
|
|
craigdo@3827
|
252 |
PACKET_HOST = 1, /**< Packet addressed oo us */
|
|
craigdo@3827
|
253 |
NS3_PACKET_HOST = PACKET_HOST,
|
|
craigdo@3827
|
254 |
PACKET_BROADCAST, /**< Packet addressed to all */
|
|
craigdo@3827
|
255 |
NS3_PACKET_BROADCAST = PACKET_BROADCAST,
|
|
craigdo@3827
|
256 |
PACKET_MULTICAST, /**< Packet addressed to multicast group */
|
|
craigdo@3827
|
257 |
NS3_PACKET_MULTICAST = PACKET_MULTICAST,
|
|
craigdo@3827
|
258 |
PACKET_OTHERHOST, /**< Packet addressed to someone else */
|
|
craigdo@3827
|
259 |
NS3_PACKET_OTHERHOST = PACKET_OTHERHOST,
|
|
gjc@3448
|
260 |
};
|
|
gjc@3448
|
261 |
|
|
mathieu@597
|
262 |
/**
|
|
mathieu@1186
|
263 |
* \param device a pointer to the net device which is calling this callback
|
|
mathieu@1186
|
264 |
* \param packet the packet received
|
|
mathieu@1186
|
265 |
* \param protocol the 16 bit protocol number associated with this packet.
|
|
mathieu@1186
|
266 |
* This protocol number is expected to be the same protocol number
|
|
mathieu@1186
|
267 |
* given to the Send method by the user on the sender side.
|
|
gjc@3448
|
268 |
* \param sender the address of the sender
|
|
mathieu@1186
|
269 |
* \returns true if the callback could handle the packet successfully, false
|
|
mathieu@1186
|
270 |
* otherwise.
|
|
mathieu@1186
|
271 |
*/
|
|
mathieu@3548
|
272 |
typedef Callback<bool,Ptr<NetDevice>,Ptr<const Packet>,uint16_t,const Address &> ReceiveCallback;
|
|
mathieu@1186
|
273 |
|
|
mathieu@1186
|
274 |
/**
|
|
mathieu@597
|
275 |
* \param cb callback to invoke whenever a packet has been received and must
|
|
mathieu@597
|
276 |
* be forwarded to the higher layers.
|
|
mathieu@1186
|
277 |
*
|
|
mathieu@597
|
278 |
*/
|
|
mathieu@2470
|
279 |
virtual void SetReceiveCallback (ReceiveCallback cb) = 0;
|
|
mathieu@451
|
280 |
|
|
gjc@3460
|
281 |
|
|
gjc@3460
|
282 |
/**
|
|
gjc@3460
|
283 |
* \param device a pointer to the net device which is calling this callback
|
|
gjc@3460
|
284 |
* \param packet the packet received
|
|
gjc@3460
|
285 |
* \param protocol the 16 bit protocol number associated with this packet.
|
|
gjc@3460
|
286 |
* This protocol number is expected to be the same protocol number
|
|
gjc@3460
|
287 |
* given to the Send method by the user on the sender side.
|
|
gjc@3460
|
288 |
* \param sender the address of the sender
|
|
gjc@3460
|
289 |
* \param receiver the address of the receiver
|
|
gjc@3460
|
290 |
* \param packetType type of packet received (broadcast/multicast/unicast/otherhost)
|
|
gjc@3460
|
291 |
* \returns true if the callback could handle the packet successfully, false
|
|
gjc@3460
|
292 |
* otherwise.
|
|
gjc@3460
|
293 |
*/
|
|
mathieu@3548
|
294 |
typedef Callback< bool, Ptr<NetDevice>, Ptr<const Packet>, uint16_t,
|
|
mathieu@3550
|
295 |
const Address &, const Address &, enum PacketType > PromiscReceiveCallback;
|
|
gjc@3460
|
296 |
|
|
gjc@3460
|
297 |
/**
|
|
gjc@3460
|
298 |
* \param cb callback to invoke whenever a packet has been received in promiscuous mode and must
|
|
gjc@3460
|
299 |
* be forwarded to the higher layers.
|
|
gjc@3460
|
300 |
*
|
|
gjc@3460
|
301 |
* Enables netdevice promiscuous mode and sets the callback that
|
|
gjc@3460
|
302 |
* will handle promiscuous mode packets. Note, promiscuous mode
|
|
gjc@3460
|
303 |
* packets means _all_ packets, including those packets that can be
|
|
gjc@3460
|
304 |
* sensed by the netdevice but which are intended to be received by
|
|
gjc@3460
|
305 |
* other hosts.
|
|
gjc@3460
|
306 |
*/
|
|
gjc@3480
|
307 |
virtual void SetPromiscReceiveCallback (PromiscReceiveCallback cb) = 0;
|
|
gjc@3460
|
308 |
|
|
gjc@3460
|
309 |
/**
|
|
tomh@3698
|
310 |
* \return true if this interface supports a bridging mode, false otherwise.
|
|
gjc@3460
|
311 |
*/
|
|
mathieu@3584
|
312 |
virtual bool SupportsSendFrom (void) const = 0;
|
|
gjc@3460
|
313 |
|
|
mathieu@234
|
314 |
};
|
|
mathieu@234
|
315 |
|
|
mathieu@2470
|
316 |
} // namespace ns3
|
|
mathieu@2470
|
317 |
|
|
mathieu@2470
|
318 |
#endif /* NET_DEVICE_H */
|