A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
point-to-point-channel.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
7#ifndef POINT_TO_POINT_CHANNEL_H
8#define POINT_TO_POINT_CHANNEL_H
9
10#include "ns3/channel.h"
11#include "ns3/data-rate.h"
12#include "ns3/nstime.h"
13#include "ns3/ptr.h"
14#include "ns3/traced-callback.h"
15
16#include <list>
17
18namespace ns3
19{
20
21class PointToPointNetDevice;
22class Packet;
23
24/**
25 * \ingroup point-to-point
26 * \brief Simple Point To Point Channel.
27 *
28 * This class represents a very simple point to point channel. Think full
29 * duplex RS-232 or RS-422 with null modem and no handshaking. There is no
30 * multi-drop capability on this channel -- there can be a maximum of two
31 * point-to-point net devices connected.
32 *
33 * There are two "wires" in the channel. The first device connected gets the
34 * [0] wire to transmit on. The second device gets the [1] wire. There is a
35 * state (IDLE, TRANSMITTING) associated with each wire.
36 *
37 * \see Attach
38 * \see TransmitStart
39 */
41{
42 public:
43 /**
44 * \brief Get the TypeId
45 *
46 * \return The TypeId for this class
47 */
48 static TypeId GetTypeId();
49
50 /**
51 * \brief Create a PointToPointChannel
52 *
53 * By default, you get a channel that has an "infinitely" fast
54 * transmission speed and zero delay.
55 */
57
58 /**
59 * \brief Attach a given netdevice to this channel
60 * \param device pointer to the netdevice to attach to the channel
61 */
63
64 /**
65 * \brief Transmit a packet over this channel
66 * \param p Packet to transmit
67 * \param src Source PointToPointNetDevice
68 * \param txTime Transmit time to apply
69 * \returns true if successful (currently always true)
70 */
72
73 /**
74 * \brief Get number of devices on this channel
75 * \returns number of devices on this channel
76 */
77 std::size_t GetNDevices() const override;
78
79 /**
80 * \brief Get PointToPointNetDevice corresponding to index i on this channel
81 * \param i Index number of the device requested
82 * \returns Ptr to PointToPointNetDevice requested
83 */
85
86 /**
87 * \brief Get NetDevice corresponding to index i on this channel
88 * \param i Index number of the device requested
89 * \returns Ptr to NetDevice requested
90 */
91 Ptr<NetDevice> GetDevice(std::size_t i) const override;
92
93 protected:
94 /**
95 * \brief Get the delay associated with this channel
96 * \returns Time delay
97 */
98 Time GetDelay() const;
99
100 /**
101 * \brief Check to make sure the link is initialized
102 * \returns true if initialized, asserts otherwise
103 */
104 bool IsInitialized() const;
105
106 /**
107 * \brief Get the net-device source
108 * \param i the link requested
109 * \returns Ptr to PointToPointNetDevice source for the
110 * specified link
111 */
113
114 /**
115 * \brief Get the net-device destination
116 * \param i the link requested
117 * \returns Ptr to PointToPointNetDevice destination for
118 * the specified link
119 */
121
122 /**
123 * TracedCallback signature for packet transmission animation events.
124 *
125 * \param [in] packet The packet being transmitted.
126 * \param [in] txDevice the TransmitTing NetDevice.
127 * \param [in] rxDevice the Receiving NetDevice.
128 * \param [in] duration The amount of time to transmit the packet.
129 * \param [in] lastBitTime Last bit receive time (relative to now)
130 * \deprecated The non-const \c Ptr<NetDevice> argument is deprecated
131 * and will be changed to \c Ptr<const NetDevice> in a future release.
132 */
133 // NS_DEPRECATED() - tag for future removal
135 Ptr<NetDevice> txDevice,
136 Ptr<NetDevice> rxDevice,
137 Time duration,
138 Time lastBitTime);
139
140 private:
141 /** Each point to point link has exactly two net devices. */
142 static const std::size_t N_DEVICES = 2;
143
144 Time m_delay; //!< Propagation delay
145 std::size_t m_nDevices; //!< Devices of this channel
146
147 /**
148 * The trace source for the packet transmission animation events that the
149 * device can fire.
150 * Arguments to the callback are the packet, transmitting
151 * net device, receiving net device, transmission time and
152 * packet receipt time.
153 *
154 * \see class CallBackTraceSource
155 * \deprecated The non-const \c Ptr<NetDevice> argument is deprecated
156 * and will be changed to \c Ptr<const NetDevice> in a future release.
157 */
158 // NS_DEPRECATED() - tag for future removal
159 TracedCallback<Ptr<const Packet>, // Packet being transmitted
160 Ptr<NetDevice>, // Transmitting NetDevice
161 Ptr<NetDevice>, // Receiving NetDevice
162 Time, // Amount of time to transmit the pkt
163 Time // Last bit receive time (relative to now)
164 >
166
167 /** \brief Wire states
168 *
169 */
171 {
172 /** Initializing state */
174 /** Idle state (no transmission from NetDevice) */
176 /** Transmitting state (data being transmitted from NetDevice. */
178 /** Propagating state (data is being propagated in the channel. */
180 };
181
182 /**
183 * \brief Wire model for the PointToPointChannel
184 */
185 class Link
186 {
187 public:
188 /** \brief Create the link, it will be in INITIALIZING state
189 *
190 */
191 Link() = default;
192
193 WireState m_state{INITIALIZING}; //!< State of the link
194 Ptr<PointToPointNetDevice> m_src; //!< First NetDevice
195 Ptr<PointToPointNetDevice> m_dst; //!< Second NetDevice
196 };
197
198 Link m_link[N_DEVICES]; //!< Link model
199};
200
201} // namespace ns3
202
203#endif /* POINT_TO_POINT_CHANNEL_H */
Abstract Channel Base Class.
Definition channel.h:34
Simple Point To Point Channel.
Time GetDelay() const
Get the delay associated with this channel.
static TypeId GetTypeId()
Get the TypeId.
Link m_link[N_DEVICES]
Link model.
std::size_t m_nDevices
Devices of this channel.
void Attach(Ptr< PointToPointNetDevice > device)
Attach a given netdevice to this channel.
Ptr< PointToPointNetDevice > GetSource(uint32_t i) const
Get the net-device source.
std::size_t GetNDevices() const override
Get number of devices on this channel.
Ptr< NetDevice > GetDevice(std::size_t i) const override
Get NetDevice corresponding to index i on this channel.
PointToPointChannel()
Create a PointToPointChannel.
Ptr< PointToPointNetDevice > GetDestination(uint32_t i) const
Get the net-device destination.
@ PROPAGATING
Propagating state (data is being propagated in the channel.
@ TRANSMITTING
Transmitting state (data being transmitted from NetDevice.
@ IDLE
Idle state (no transmission from NetDevice)
@ INITIALIZING
Initializing state.
Ptr< PointToPointNetDevice > GetPointToPointDevice(std::size_t i) const
Get PointToPointNetDevice corresponding to index i on this channel.
bool IsInitialized() const
Check to make sure the link is initialized.
TracedCallback< Ptr< const Packet >, Ptr< NetDevice >, Ptr< NetDevice >, Time, Time > m_txrxPointToPoint
The trace source for the packet transmission animation events that the device can fire.
Time m_delay
Propagation delay.
virtual bool TransmitStart(Ptr< const Packet > p, Ptr< PointToPointNetDevice > src, Time txTime)
Transmit a packet over this channel.
static const std::size_t N_DEVICES
Each point to point link has exactly two net devices.
void(* TxRxAnimationCallback)(Ptr< const Packet > packet, Ptr< NetDevice > txDevice, Ptr< NetDevice > rxDevice, Time duration, Time lastBitTime)
TracedCallback signature for packet transmission animation events.
Smart pointer class similar to boost::intrusive_ptr.
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.