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