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