A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
csma-channel.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 Emmanuelle Laprise
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 * Author: Emmanuelle Laprise<emmanuelle.laprise@bluekazoo.ca>
18 */
19
20#ifndef CSMA_CHANNEL_H
21#define CSMA_CHANNEL_H
22
23#include "ns3/channel.h"
24#include "ns3/data-rate.h"
25#include "ns3/nstime.h"
26#include "ns3/ptr.h"
27
28namespace ns3
29{
30
31class Packet;
32
33class CsmaNetDevice;
34
35/**
36 * \ingroup csma
37 * \brief CsmaNetDevice Record
38 *
39 * Stores the information related to each net device that is
40 * connected to the channel.
41 */
43{
44 public:
45 Ptr<CsmaNetDevice> devicePtr; //!< Pointer to the net device
46 bool active; //!< Is net device enabled to TX/RX
47
49
50 /**
51 * \brief Constructor
52 * Builds a record of the given NetDevice, its status is initialized to enabled.
53 *
54 * \param device the device to record
55 */
57
58 /**
59 * Copy constructor
60 * \param o the object to copy
61 */
63
64 /**
65 * \return If the net device pointed to by the devicePtr is active
66 * and ready to RX/TX.
67 */
68 bool IsActive() const;
69};
70
71/**
72 * Current state of the channel
73 */
75{
76 IDLE, /**< Channel is IDLE, no packet is being transmitted */
77 TRANSMITTING, /**< Channel is BUSY, a packet is being written by a net device */
78 PROPAGATING /**< Channel is BUSY, packet is propagating to all attached net devices */
79};
80
81/**
82 * \ingroup csma
83 * \brief Csma Channel.
84 *
85 * This class represents a simple Csma channel that can be used
86 * when many nodes are connected to one wire. It uses a single busy
87 * flag to indicate if the channel is currently in use. It does not
88 * take into account the distances between stations or the speed of
89 * light to determine collisions.
90 */
91class CsmaChannel : public Channel
92{
93 public:
94 /**
95 * \brief Get the type ID.
96 * \return the object TypeId
97 */
98 static TypeId GetTypeId();
99
100 /**
101 * \brief Create a CsmaChannel
102 */
103 CsmaChannel();
104 /**
105 * \brief Destroy a CsmaChannel
106 */
107 ~CsmaChannel() override;
108
109 // Delete copy constructor and assignment operator to avoid misuse
110 CsmaChannel(const CsmaChannel&) = delete;
112
113 /**
114 * \brief Attach a given netdevice to this channel
115 *
116 * \param device Device pointer to the netdevice to attach to the channel
117 * \return The assigned device number
118 */
120
121 /**
122 * \brief Detach a given netdevice from this channel
123 *
124 * The net device is marked as inactive and it is not allowed to
125 * receive or transmit packets
126 *
127 * \param device Device pointer to the netdevice to detach from the channel
128 * \return True if the device is found and attached to the channel,
129 * false if the device is not currently connected to the channel or
130 * can't be found.
131 */
132 bool Detach(Ptr<CsmaNetDevice> device);
133
134 /**
135 * \brief Detach a given netdevice from this channel
136 *
137 * The net device is marked as inactive and it is not allowed to
138 * receive or transmit packets
139 *
140 * \param deviceId The deviceID assigned to the net device when it
141 * was connected to the channel
142 * \return True if the device is found and attached to the channel,
143 * false if the device is not currently connected to the channel or
144 * can't be found.
145 */
146 bool Detach(uint32_t deviceId);
147
148 /**
149 * \brief Reattach a previously detached net device to the channel
150 *
151 * The net device is marked as active. It is now allowed to receive
152 * or transmit packets. The net device must have been previously
153 * attached to the channel using the attach function.
154 *
155 * \param deviceId The device ID assigned to the net device when it
156 * was connected to the channel
157 * \return True if the device is found and is not attached to the
158 * channel, false if the device is currently connected to the
159 * channel or can't be found.
160 */
161 bool Reattach(uint32_t deviceId);
162
163 /**
164 * \brief Reattach a previously detached net device to the channel
165 *
166 * The net device is marked as active. It is now allowed to receive
167 * or transmit packets. The net device must have been previously
168 * attached to the channel using the attach function.
169 *
170 * \param device Device pointer to the netdevice to detach from the channel
171 * \return True if the device is found and is not attached to the
172 * channel, false if the device is currently connected to the
173 * channel or can't be found.
174 */
175 bool Reattach(Ptr<CsmaNetDevice> device);
176
177 /**
178 * \brief Start transmitting a packet over the channel
179 *
180 * If the srcId belongs to a net device that is connected to the
181 * channel, packet transmission begins, and the channel becomes busy
182 * until the packet has completely reached all destinations.
183 *
184 * \param p A reference to the packet that will be transmitted over
185 * the channel
186 * \param srcId The device Id of the net device that wants to
187 * transmit on the channel.
188 * \return True if the channel is not busy and the transmitting net
189 * device is currently active.
190 */
192
193 /**
194 * \brief Indicates that the net device has finished transmitting
195 * the packet over the channel
196 *
197 * The channel will stay busy until the packet has completely
198 * propagated to all net devices attached to the channel. The
199 * TransmitEnd function schedules the PropagationCompleteEvent which
200 * will free the channel for further transmissions. Stores the
201 * packet p as the m_currentPkt, the packet being currently
202 * transmitting.
203 *
204 * \return Returns true unless the source was detached before it
205 * completed its transmission.
206 */
207 bool TransmitEnd();
208
209 /**
210 * \brief Indicates that the channel has finished propagating the
211 * current packet. The channel is released and becomes free.
212 *
213 * Calls the receive function of every active net device that is
214 * attached to the channel.
215 */
217
218 /**
219 * \return Returns the device number assigned to a net device by the
220 * channel
221 *
222 * \param device Device pointer to the netdevice for which the device
223 * number is needed
224 */
226
227 /**
228 * \return Returns the state of the channel (IDLE -- free,
229 * TRANSMITTING -- busy, PROPAGATING - busy )
230 */
232
233 /**
234 * \brief Indicates if the channel is busy. The channel will only
235 * accept new packets for transmission if it is not busy.
236 *
237 * \return Returns true if the channel is busy and false if it is
238 * free.
239 */
240 bool IsBusy();
241
242 /**
243 * \brief Indicates if a net device is currently attached or
244 * detached from the channel.
245 *
246 * \param deviceId The ID that was assigned to the net device when
247 * it was attached to the channel.
248 * \return Returns true if the net device is attached to the
249 * channel, false otherwise.
250 */
251 bool IsActive(uint32_t deviceId);
252
253 /**
254 * \return Returns the number of net devices that are currently
255 * attached to the channel.
256 */
258
259 /**
260 * \return Returns the total number of devices including devices
261 * that have been detached from the channel.
262 */
263 std::size_t GetNDevices() const override;
264
265 /**
266 * \return Get a NetDevice pointer to a connected network device.
267 *
268 * \param i The index of the net device.
269 * \return Returns the pointer to the net device that is associated
270 * with deviceId i.
271 */
272 Ptr<NetDevice> GetDevice(std::size_t i) const override;
273
274 /**
275 * \return Get a CsmaNetDevice pointer to a connected network device.
276 *
277 * \param i The deviceId of the net device for which we want the
278 * pointer.
279 * \return Returns the pointer to the net device that is associated
280 * with deviceId i.
281 */
282 Ptr<CsmaNetDevice> GetCsmaDevice(std::size_t i) const;
283
284 /**
285 * Get the assigned data rate of the channel
286 *
287 * \return Returns the DataRate to be used by device transmitters.
288 * with deviceId i.
289 */
291
292 /**
293 * Get the assigned speed-of-light delay of the channel
294 *
295 * \return Returns the delay used by the channel.
296 */
297 Time GetDelay();
298
299 private:
300 /**
301 * The assigned data rate of the channel
302 */
304
305 /**
306 * The assigned speed-of-light delay of the channel
307 */
309
310 /**
311 * List of the net devices that have been or are currently connected
312 * to the channel.
313 *
314 * Devices are nor removed from this list, they are marked as
315 * inactive. Otherwise the assigned device IDs will not refer to the
316 * correct NetDevice. The DeviceIds are used so that it is possible
317 * to have a number to refer to an entry in the list so that the
318 * whole list does not have to be searched when making sure that a
319 * source is attached to a channel when it is transmitting data.
320 */
321 std::vector<CsmaDeviceRec> m_deviceList;
322
323 /**
324 * The Packet that is currently being transmitted on the channel (or last
325 * packet to have been transmitted on the channel if the channel is
326 * free.)
327 */
329
330 /**
331 * Device Id of the source that is currently transmitting on the
332 * channel. Or last source to have transmitted a packet on the
333 * channel, if the channel is currently not busy.
334 */
336
337 /**
338 * Current state of the channel
339 */
341};
342
343} // namespace ns3
344
345#endif /* CSMA_CHANNEL_H */
Abstract Channel Base Class.
Definition: channel.h:45
Csma Channel.
Definition: csma-channel.h:92
CsmaChannel(const CsmaChannel &)=delete
~CsmaChannel() override
Destroy a CsmaChannel.
Definition: csma-channel.cc:65
Ptr< CsmaNetDevice > GetCsmaDevice(std::size_t i) const
uint32_t GetNumActDevices()
DataRate m_bps
The assigned data rate of the channel.
Definition: csma-channel.h:303
DataRate GetDataRate()
Get the assigned data rate of the channel.
bool Reattach(uint32_t deviceId)
Reattach a previously detached net device to the channel.
bool IsActive(uint32_t deviceId)
Indicates if a net device is currently attached or detached from the channel.
Time GetDelay()
Get the assigned speed-of-light delay of the channel.
int32_t GetDeviceNum(Ptr< CsmaNetDevice > device)
bool TransmitEnd()
Indicates that the net device has finished transmitting the packet over the channel.
Time m_delay
The assigned speed-of-light delay of the channel.
Definition: csma-channel.h:308
Ptr< const Packet > m_currentPkt
The Packet that is currently being transmitted on the channel (or last packet to have been transmitte...
Definition: csma-channel.h:328
bool TransmitStart(Ptr< const Packet > p, uint32_t srcId)
Start transmitting a packet over the channel.
static TypeId GetTypeId()
Get the type ID.
Definition: csma-channel.cc:36
WireState m_state
Current state of the channel.
Definition: csma-channel.h:340
CsmaChannel & operator=(const CsmaChannel &)=delete
CsmaChannel()
Create a CsmaChannel.
Definition: csma-channel.cc:57
bool Detach(Ptr< CsmaNetDevice > device)
Detach a given netdevice from this channel.
std::vector< CsmaDeviceRec > m_deviceList
List of the net devices that have been or are currently connected to the channel.
Definition: csma-channel.h:321
void PropagationCompleteEvent()
Indicates that the channel has finished propagating the current packet.
int32_t Attach(Ptr< CsmaNetDevice > device)
Attach a given netdevice to this channel.
Definition: csma-channel.cc:72
Ptr< NetDevice > GetDevice(std::size_t i) const override
bool IsBusy()
Indicates if the channel is busy.
WireState GetState()
uint32_t m_currentSrc
Device Id of the source that is currently transmitting on the channel.
Definition: csma-channel.h:335
std::size_t GetNDevices() const override
CsmaNetDevice Record.
Definition: csma-channel.h:43
bool IsActive() const
Ptr< CsmaNetDevice > devicePtr
Pointer to the net device.
Definition: csma-channel.h:45
bool active
Is net device enabled to TX/RX.
Definition: csma-channel.h:46
Class for representing data rates.
Definition: data-rate.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.
WireState
Current state of the channel.
Definition: csma-channel.h:75
@ TRANSMITTING
Channel is BUSY, a packet is being written by a net device.
Definition: csma-channel.h:77
@ PROPAGATING
Channel is BUSY, packet is propagating to all attached net devices.
Definition: csma-channel.h:78
@ IDLE
Channel is IDLE, no packet is being transmitted.
Definition: csma-channel.h:76