A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
point-to-point-net-device.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007, 2008 University of Washington
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
18#ifndef POINT_TO_POINT_NET_DEVICE_H
19#define POINT_TO_POINT_NET_DEVICE_H
20
21#include "ns3/address.h"
22#include "ns3/callback.h"
23#include "ns3/data-rate.h"
24#include "ns3/mac48-address.h"
25#include "ns3/net-device.h"
26#include "ns3/node.h"
27#include "ns3/nstime.h"
28#include "ns3/packet.h"
29#include "ns3/ptr.h"
30#include "ns3/queue-fwd.h"
31#include "ns3/traced-callback.h"
32
33#include <cstring>
34
35namespace ns3
36{
37
38class PointToPointChannel;
39class ErrorModel;
40
41/**
42 * \defgroup point-to-point Point-To-Point Network Device
43 * This section documents the API of the ns-3 point-to-point module. For a
44 * functional description, please refer to the ns-3 manual here:
45 * http://www.nsnam.org/docs/models/html/point-to-point.html
46 *
47 * Be sure to read the manual BEFORE going down to the API.
48 */
49
50/**
51 * \ingroup point-to-point
52 * \class PointToPointNetDevice
53 * \brief A Device for a Point to Point Network Link.
54 *
55 * This PointToPointNetDevice class specializes the NetDevice abstract
56 * base class. Together with a PointToPointChannel (and a peer
57 * PointToPointNetDevice), the class models, with some level of
58 * abstraction, a generic point-to-point or serial link.
59 * Key parameters or objects that can be specified for this device
60 * include a queue, data rate, and interframe transmission gap (the
61 * propagation delay is set in the PointToPointChannel).
62 */
64{
65 public:
66 /**
67 * \brief Get the TypeId
68 *
69 * \return The TypeId for this class
70 */
71 static TypeId GetTypeId();
72
73 /**
74 * Construct a PointToPointNetDevice
75 *
76 * This is the constructor for the PointToPointNetDevice. It takes as a
77 * parameter a pointer to the Node to which this device is connected,
78 * as well as an optional DataRate object.
79 */
81
82 /**
83 * Destroy a PointToPointNetDevice
84 *
85 * This is the destructor for the PointToPointNetDevice.
86 */
87 ~PointToPointNetDevice() override;
88
89 // Delete copy constructor and assignment operator to avoid misuse
92
93 /**
94 * Set the Data Rate used for transmission of packets. The data rate is
95 * set in the Attach () method from the corresponding field in the channel
96 * to which the device is attached. It can be overridden using this method.
97 *
98 * \param bps the data rate at which this object operates
99 */
100 void SetDataRate(DataRate bps);
101
102 /**
103 * Set the interframe gap used to separate packets. The interframe gap
104 * defines the minimum space required between packets sent by this device.
105 *
106 * \param t the interframe gap time
107 */
108 void SetInterframeGap(Time t);
109
110 /**
111 * Attach the device to a channel.
112 *
113 * \param ch Ptr to the channel to which this object is being attached.
114 * \return true if the operation was successful (always true actually)
115 */
117
118 /**
119 * Attach a queue to the PointToPointNetDevice.
120 *
121 * The PointToPointNetDevice "owns" a queue that implements a queueing
122 * method such as DropTailQueue or RedQueue
123 *
124 * \param queue Ptr to the new queue.
125 */
126 void SetQueue(Ptr<Queue<Packet>> queue);
127
128 /**
129 * Get a copy of the attached Queue.
130 *
131 * \returns Ptr to the queue.
132 */
134
135 /**
136 * Attach a receive ErrorModel to the PointToPointNetDevice.
137 *
138 * The PointToPointNetDevice may optionally include an ErrorModel in
139 * the packet receive chain.
140 *
141 * \param em Ptr to the ErrorModel.
142 */
144
145 /**
146 * Receive a packet from a connected PointToPointChannel.
147 *
148 * The PointToPointNetDevice receives packets from its connected channel
149 * and forwards them up the protocol stack. This is the public method
150 * used by the channel to indicate that the last bit of a packet has
151 * arrived at the device.
152 *
153 * \param p Ptr to the received packet.
154 */
155 void Receive(Ptr<Packet> p);
156
157 // The remaining methods are documented in ns3::NetDevice*
158
159 void SetIfIndex(const uint32_t index) override;
160 uint32_t GetIfIndex() const override;
161
162 Ptr<Channel> GetChannel() const override;
163
164 void SetAddress(Address address) override;
165 Address GetAddress() const override;
166
167 bool SetMtu(const uint16_t mtu) override;
168 uint16_t GetMtu() const override;
169
170 bool IsLinkUp() const override;
171
172 void AddLinkChangeCallback(Callback<void> callback) override;
173
174 bool IsBroadcast() const override;
175 Address GetBroadcast() const override;
176
177 bool IsMulticast() const override;
178 Address GetMulticast(Ipv4Address multicastGroup) const override;
179
180 bool IsPointToPoint() const override;
181 bool IsBridge() const override;
182
183 bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) override;
184 bool SendFrom(Ptr<Packet> packet,
185 const Address& source,
186 const Address& dest,
187 uint16_t protocolNumber) override;
188
189 Ptr<Node> GetNode() const override;
190 void SetNode(Ptr<Node> node) override;
191
192 bool NeedsArp() const override;
193
195
196 Address GetMulticast(Ipv6Address addr) const override;
197
199 bool SupportsSendFrom() const override;
200
201 protected:
202 /**
203 * \brief Handler for MPI receive event
204 *
205 * \param p Packet received
206 */
208
209 private:
210 /**
211 * \brief Dispose of the object
212 */
213 void DoDispose() override;
214
215 /**
216 * \returns the address of the remote device connected to this device
217 * through the point to point channel.
218 */
219 Address GetRemote() const;
220
221 /**
222 * Adds the necessary headers and trailers to a packet of data in order to
223 * respect the protocol implemented by the agent.
224 * \param p packet
225 * \param protocolNumber protocol number
226 */
227 void AddHeader(Ptr<Packet> p, uint16_t protocolNumber);
228
229 /**
230 * Removes, from a packet of data, all headers and trailers that
231 * relate to the protocol implemented by the agent
232 * \param p Packet whose headers need to be processed
233 * \param param An integer parameter that can be set by the function
234 * \return Returns true if the packet should be forwarded up the
235 * protocol stack.
236 */
237 bool ProcessHeader(Ptr<Packet> p, uint16_t& param);
238
239 /**
240 * Start Sending a Packet Down the Wire.
241 *
242 * The TransmitStart method is the method that is used internally in the
243 * PointToPointNetDevice to begin the process of sending a packet out on
244 * the channel. The corresponding method is called on the channel to let
245 * it know that the physical device this class represents has virtually
246 * started sending signals. An event is scheduled for the time at which
247 * the bits have been completely transmitted.
248 *
249 * \see PointToPointChannel::TransmitStart ()
250 * \see TransmitComplete()
251 * \param p a reference to the packet to send
252 * \returns true if success, false on failure
253 */
255
256 /**
257 * Stop Sending a Packet Down the Wire and Begin the Interframe Gap.
258 *
259 * The TransmitComplete method is used internally to finish the process
260 * of sending a packet out on the channel.
261 */
262 void TransmitComplete();
263
264 /**
265 * \brief Make the link up and running
266 *
267 * It calls also the linkChange callback.
268 */
269 void NotifyLinkUp();
270
271 /**
272 * Enumeration of the states of the transmit machine of the net device.
273 */
275 {
276 READY, /**< The transmitter is ready to begin transmission of a packet */
277 BUSY /**< The transmitter is busy transmitting a packet */
278 };
279
280 /**
281 * The state of the Net Device transmit state machine.
282 */
284
285 /**
286 * The data rate that the Net Device uses to simulate packet transmission
287 * timing.
288 */
290
291 /**
292 * The interframe gap that the Net Device uses to throttle packet
293 * transmission
294 */
296
297 /**
298 * The PointToPointChannel to which this PointToPointNetDevice has been
299 * attached.
300 */
302
303 /**
304 * The Queue which this PointToPointNetDevice uses as a packet source.
305 * Management of this Queue has been delegated to the PointToPointNetDevice
306 * and it has the responsibility for deletion.
307 * \see class DropTailQueue
308 */
310
311 /**
312 * Error model for receive packet events
313 */
315
316 /**
317 * The trace source fired when packets come into the "top" of the device
318 * at the L3/L2 transition, before being queued for transmission.
319 */
321
322 /**
323 * The trace source fired when packets coming into the "top" of the device
324 * at the L3/L2 transition are dropped before being queued for transmission.
325 */
327
328 /**
329 * The trace source fired for packets successfully received by the device
330 * immediately before being forwarded up to higher layers (at the L2/L3
331 * transition). This is a promiscuous trace (which doesn't mean a lot here
332 * in the point-to-point device).
333 */
335
336 /**
337 * The trace source fired for packets successfully received by the device
338 * immediately before being forwarded up to higher layers (at the L2/L3
339 * transition). This is a non-promiscuous trace (which doesn't mean a lot
340 * here in the point-to-point device).
341 */
343
344 /**
345 * The trace source fired for packets successfully received by the device
346 * but are dropped before being forwarded up to higher layers (at the L2/L3
347 * transition).
348 */
350
351 /**
352 * The trace source fired when a packet begins the transmission process on
353 * the medium.
354 */
356
357 /**
358 * The trace source fired when a packet ends the transmission process on
359 * the medium.
360 */
362
363 /**
364 * The trace source fired when the phy layer drops a packet before it tries
365 * to transmit it.
366 */
368
369 /**
370 * The trace source fired when a packet begins the reception process from
371 * the medium -- when the simulated first bit(s) arrive.
372 */
374
375 /**
376 * The trace source fired when a packet ends the reception process from
377 * the medium.
378 */
380
381 /**
382 * The trace source fired when the phy layer drops a packet it has received.
383 * This happens if the receiver is not enabled or the error model is active
384 * and indicates that the packet is corrupt.
385 */
387
388 /**
389 * A trace source that emulates a non-promiscuous protocol sniffer connected
390 * to the device. Unlike your average everyday sniffer, this trace source
391 * will not fire on PACKET_OTHERHOST events.
392 *
393 * On the transmit size, this trace hook will fire after a packet is dequeued
394 * from the device queue for transmission. In Linux, for example, this would
395 * correspond to the point just before a device \c hard_start_xmit where
396 * \c dev_queue_xmit_nit is called to dispatch the packet to the PF_PACKET
397 * ETH_P_ALL handlers.
398 *
399 * On the receive side, this trace hook will fire when a packet is received,
400 * just before the receive callback is executed. In Linux, for example,
401 * this would correspond to the point at which the packet is dispatched to
402 * packet sniffers in \c netif_receive_skb.
403 */
405
406 /**
407 * A trace source that emulates a promiscuous mode protocol sniffer connected
408 * to the device. This trace source fire on packets destined for any host
409 * just like your average everyday packet sniffer.
410 *
411 * On the transmit size, this trace hook will fire after a packet is dequeued
412 * from the device queue for transmission. In Linux, for example, this would
413 * correspond to the point just before a device \c hard_start_xmit where
414 * \c dev_queue_xmit_nit is called to dispatch the packet to the PF_PACKET
415 * ETH_P_ALL handlers.
416 *
417 * On the receive side, this trace hook will fire when a packet is received,
418 * just before the receive callback is executed. In Linux, for example,
419 * this would correspond to the point at which the packet is dispatched to
420 * packet sniffers in \c netif_receive_skb.
421 */
423
424 Ptr<Node> m_node; //!< Node owning this NetDevice
425 Mac48Address m_address; //!< Mac48Address of this NetDevice
428 // (promisc data)
429 uint32_t m_ifIndex; //!< Index of the interface
430 bool m_linkUp; //!< Identify if the link is up or not
431 TracedCallback<> m_linkChangeCallbacks; //!< Callback for the link change event
432
433 static const uint16_t DEFAULT_MTU = 1500; //!< Default MTU
434
435 /**
436 * \brief The Maximum Transmission Unit
437 *
438 * This corresponds to the maximum
439 * number of bytes that can be transmitted as seen from higher layers.
440 * This corresponds to the 1500 byte MTU size often seen on IP over
441 * Ethernet.
442 */
444
445 Ptr<Packet> m_currentPkt; //!< Current packet processed
446
447 /**
448 * \brief PPP to Ethernet protocol number mapping
449 * \param protocol A PPP protocol number
450 * \return The corresponding Ethernet protocol number
451 */
452 static uint16_t PppToEther(uint16_t protocol);
453
454 /**
455 * \brief Ethernet to PPP protocol number mapping
456 * \param protocol An Ethernet protocol number
457 * \return The corresponding PPP protocol number
458 */
459 static uint16_t EtherToPpp(uint16_t protocol);
460};
461
462} // namespace ns3
463
464#endif /* POINT_TO_POINT_NET_DEVICE_H */
a polymophic address class
Definition: address.h:101
Callback template class.
Definition: callback.h:438
Class for representing data rates.
Definition: data-rate.h:89
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Describes an IPv6 address.
Definition: ipv6-address.h:49
an EUI-48 address
Definition: mac48-address.h:46
Network layer to device interface.
Definition: net-device.h:98
A Device for a Point to Point Network Link.
void AddHeader(Ptr< Packet > p, uint16_t protocolNumber)
Adds the necessary headers and trailers to a packet of data in order to respect the protocol implemen...
static const uint16_t DEFAULT_MTU
Default MTU.
Ptr< Node > GetNode() const override
TracedCallback< Ptr< const Packet > > m_phyRxEndTrace
The trace source fired when a packet ends the reception process from the medium.
Address GetMulticast(Ipv4Address multicastGroup) const override
Make and return a MAC multicast address using the provided multicast group.
Address GetBroadcast() const override
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
PointToPointNetDevice()
Construct a PointToPointNetDevice.
Ptr< PointToPointChannel > m_channel
The PointToPointChannel to which this PointToPointNetDevice has been attached.
DataRate m_bps
The data rate that the Net Device uses to simulate packet transmission timing.
bool TransmitStart(Ptr< Packet > p)
Start Sending a Packet Down the Wire.
TracedCallback< Ptr< const Packet > > m_macRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
The trace source fired for packets successfully received by the device but are dropped before being f...
TracedCallback m_linkChangeCallbacks
Callback for the link change event.
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets come into the "top" of the device at the L3/L2 transition,...
bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber) override
void SetNode(Ptr< Node > node) override
void SetQueue(Ptr< Queue< Packet > > queue)
Attach a queue to the PointToPointNetDevice.
void SetIfIndex(const uint32_t index) override
void AddLinkChangeCallback(Callback< void > callback) override
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
bool IsPointToPoint() const override
Return true if the net device is on a point-to-point link.
bool Attach(Ptr< PointToPointChannel > ch)
Attach the device to a channel.
static uint16_t EtherToPpp(uint16_t protocol)
Ethernet to PPP protocol number mapping.
void SetReceiveErrorModel(Ptr< ErrorModel > em)
Attach a receive ErrorModel to the PointToPointNetDevice.
TracedCallback< Ptr< const Packet > > m_phyTxDropTrace
The trace source fired when the phy layer drops a packet before it tries to transmit it.
Ptr< ErrorModel > m_receiveErrorModel
Error model for receive packet events.
void SetInterframeGap(Time t)
Set the interframe gap used to separate packets.
void SetReceiveCallback(NetDevice::ReceiveCallback cb) override
bool m_linkUp
Identify if the link is up or not.
PointToPointNetDevice(const PointToPointNetDevice &)=delete
uint16_t GetMtu() const override
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received.
void NotifyLinkUp()
Make the link up and running.
Ptr< Queue< Packet > > GetQueue() const
Get a copy of the attached Queue.
TxMachineState
Enumeration of the states of the transmit machine of the net device.
@ READY
The transmitter is ready to begin transmission of a packet.
@ BUSY
The transmitter is busy transmitting a packet.
static uint16_t PppToEther(uint16_t protocol)
PPP to Ethernet protocol number mapping.
Address GetAddress() const override
bool IsBridge() const override
Return true if the net device is acting as a bridge.
Ptr< Channel > GetChannel() const override
TracedCallback< Ptr< const Packet > > m_phyTxBeginTrace
The trace source fired when a packet begins the transmission process on the medium.
void DoDispose() override
Dispose of the object.
void SetAddress(Address address) override
Set the address of this interface.
void TransmitComplete()
Stop Sending a Packet Down the Wire and Begin the Interframe Gap.
~PointToPointNetDevice() override
Destroy a PointToPointNetDevice.
static TypeId GetTypeId()
Get the TypeId.
Mac48Address m_address
Mac48Address of this NetDevice.
uint32_t GetIfIndex() const override
Time m_tInterframeGap
The interframe gap that the Net Device uses to throttle packet transmission.
Ptr< Packet > m_currentPkt
Current packet processed.
bool ProcessHeader(Ptr< Packet > p, uint16_t &param)
Removes, from a packet of data, all headers and trailers that relate to the protocol implemented by t...
void Receive(Ptr< Packet > p)
Receive a packet from a connected PointToPointChannel.
TracedCallback< Ptr< const Packet > > m_phyRxBeginTrace
The trace source fired when a packet begins the reception process from the medium – when the simulate...
Ptr< Queue< Packet > > m_queue
The Queue which this PointToPointNetDevice uses as a packet source.
PointToPointNetDevice & operator=(const PointToPointNetDevice &)=delete
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
A trace source that emulates a promiscuous mode protocol sniffer connected to the device.
TracedCallback< Ptr< const Packet > > m_phyTxEndTrace
The trace source fired when a packet ends the transmission process on the medium.
TxMachineState m_txMachineState
The state of the Net Device transmit state machine.
void DoMpiReceive(Ptr< Packet > p)
Handler for MPI receive event.
void SetDataRate(DataRate bps)
Set the Data Rate used for transmission of packets.
uint32_t m_mtu
The Maximum Transmission Unit.
Ptr< Node > m_node
Node owning this NetDevice.
TracedCallback< Ptr< const Packet > > m_snifferTrace
A trace source that emulates a non-promiscuous protocol sniffer connected to the device.
bool SetMtu(const uint16_t mtu) override
TracedCallback< Ptr< const Packet > > m_macTxDropTrace
The trace source fired when packets coming into the "top" of the device at the L3/L2 transition are d...
NetDevice::PromiscReceiveCallback m_promiscCallback
Receive callback.
NetDevice::ReceiveCallback m_rxCallback
Receive callback.
void SetPromiscReceiveCallback(PromiscReceiveCallback cb) override
uint32_t m_ifIndex
Index of the interface.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Template class for packet Queues.
Definition: queue.h:268
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.