|
|
| 1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 |
/* |
2 |
/* |
| 3 |
* Copyright (c) 2007 Emmanuelle Laprise |
3 |
* Copyright (c) 2007 Emmanuelle Laprise |
|
|
4 |
* Copyright (c) 2012 Jeffrey Young |
| 5 |
* Copyright (c) 2014 Murphy McCauley |
| 6 |
* Copyright (c) 2017 Luciano Jerez Chaves |
| 4 |
* |
7 |
* |
| 5 |
* This program is free software; you can redistribute it and/or modify |
8 |
* This program is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License version 2 as |
9 |
* it under the terms of the GNU General Public License version 2 as |
|
|
| 16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 |
* |
20 |
* |
| 18 |
* Author: Emmanuelle Laprise<emmanuelle.laprise@bluekazoo.ca> |
21 |
* Author: Emmanuelle Laprise<emmanuelle.laprise@bluekazoo.ca> |
|
|
22 |
* Author: Jeff Young <jyoung9@gatech.edu> |
| 23 |
* Author: Murphy McCauley <murphy.mccauley@gmail.com> |
| 24 |
* Author: Luciano Jerez Chaves <luciano@lrc.ic.unicamp.br> |
| 19 |
*/ |
25 |
*/ |
| 20 |
|
26 |
|
| 21 |
#ifndef CSMA_CHANNEL_H |
27 |
#ifndef CSMA_CHANNEL_H |
|
|
| 25 |
#include "ns3/ptr.h" |
31 |
#include "ns3/ptr.h" |
| 26 |
#include "ns3/nstime.h" |
32 |
#include "ns3/nstime.h" |
| 27 |
#include "ns3/data-rate.h" |
33 |
#include "ns3/data-rate.h" |
|
|
34 |
#include "ns3/boolean.h" |
| 28 |
|
35 |
|
| 29 |
namespace ns3 { |
36 |
namespace ns3 { |
| 30 |
|
37 |
|
|
|
| 34 |
|
41 |
|
| 35 |
/** |
42 |
/** |
| 36 |
* \ingroup csma |
43 |
* \ingroup csma |
| 37 |
* \brief CsmaNetDevice Record |
44 |
* \brief CsmaNetDevice Record |
| 38 |
* |
45 |
* |
| 39 |
* Stores the information related to each net device that is |
46 |
* Stores the information related to each net device that is |
| 40 |
* connected to the channel. |
47 |
* connected to the channel. |
| 41 |
*/ |
48 |
*/ |
| 42 |
class CsmaDeviceRec { |
49 |
class CsmaDeviceRec |
|
|
50 |
{ |
| 43 |
public: |
51 |
public: |
| 44 |
Ptr< CsmaNetDevice > devicePtr; //!< Pointer to the net device |
52 |
Ptr< CsmaNetDevice > devicePtr; //!< Pointer to the net device |
| 45 |
bool active; //!< Is net device enabled to TX/RX |
53 |
bool active; //!< Is net device enabled to TX/RX |
| 46 |
|
54 |
|
| 47 |
CsmaDeviceRec(); |
55 |
CsmaDeviceRec (); |
| 48 |
|
56 |
|
| 49 |
/** |
57 |
/** |
| 50 |
* \brief Constructor |
58 |
* \brief Constructor |
|
|
| 52 |
* |
60 |
* |
| 53 |
* \param device the device to record |
61 |
* \param device the device to record |
| 54 |
*/ |
62 |
*/ |
| 55 |
CsmaDeviceRec(Ptr< CsmaNetDevice > device); |
63 |
CsmaDeviceRec (Ptr< CsmaNetDevice > device); |
| 56 |
|
64 |
|
| 57 |
/** |
65 |
/** |
| 58 |
* Copy constructor |
66 |
* Copy constructor |
|
|
| 69 |
|
77 |
|
| 70 |
/** |
78 |
/** |
| 71 |
* Current state of the channel |
79 |
* Current state of the channel |
| 72 |
*/ |
80 |
*/ |
| 73 |
enum WireState |
81 |
enum WireState |
| 74 |
{ |
82 |
{ |
| 75 |
IDLE, /**< Channel is IDLE, no packet is being transmitted */ |
83 |
IDLE, /**< Channel is IDLE, no packet is being transmitted */ |
|
|
| 85 |
* when many nodes are connected to one wire. It uses a single busy |
93 |
* when many nodes are connected to one wire. It uses a single busy |
| 86 |
* flag to indicate if the channel is currently in use. It does not |
94 |
* flag to indicate if the channel is currently in use. It does not |
| 87 |
* take into account the distances between stations or the speed of |
95 |
* take into account the distances between stations or the speed of |
| 88 |
* light to determine collisions. |
96 |
* light to determine collisions. Optionally, it allows for full- |
|
|
97 |
* duplex operation when there are only two attached nodes. To |
| 98 |
* implement full-duplex, we internally keep two TX "subchannels" |
| 99 |
* (one for each attached node). When in half-duplex mode, only |
| 100 |
* the first subchannel is used. |
| 89 |
*/ |
101 |
*/ |
| 90 |
class CsmaChannel : public Channel |
102 |
class CsmaChannel : public Channel |
| 91 |
{ |
103 |
{ |
| 92 |
public: |
104 |
public: |
| 93 |
|
|
|
| 94 |
/** |
105 |
/** |
| 95 |
* \brief Get the type ID. |
106 |
* \brief Get the type ID. |
| 96 |
* \return the object TypeId |
107 |
* \return the object TypeId |
|
|
| 148 |
* or transmit packets. The net device must have been previously |
159 |
* or transmit packets. The net device must have been previously |
| 149 |
* attached to the channel using the attach function. |
160 |
* attached to the channel using the attach function. |
| 150 |
* |
161 |
* |
| 151 |
* \param deviceId The device ID assigned to the net device when it |
162 |
* \param deviceId The deviceID assigned to the net device when it |
| 152 |
* was connected to the channel |
163 |
* was connected to the channel |
| 153 |
* \return True if the device is found and is not attached to the |
164 |
* \return True if the device is found and is not attached to the |
| 154 |
* channel, false if the device is currently connected to the |
165 |
* channel, false if the device is currently connected to the |
|
|
| 197 |
* packet p as the m_currentPkt, the packet being currently |
208 |
* packet p as the m_currentPkt, the packet being currently |
| 198 |
* transmitting. |
209 |
* transmitting. |
| 199 |
* |
210 |
* |
|
|
211 |
* \param deviceId The deviceID assigned to the net device when it |
| 212 |
* was connected to the channel |
| 213 |
* |
| 200 |
* \return Returns true unless the source was detached before it |
214 |
* \return Returns true unless the source was detached before it |
| 201 |
* completed its transmission. |
215 |
* completed its transmission. |
| 202 |
*/ |
216 |
*/ |
| 203 |
bool TransmitEnd (); |
217 |
bool TransmitEnd (uint32_t deviceId); |
| 204 |
|
218 |
|
| 205 |
/** |
219 |
/** |
| 206 |
* \brief Indicates that the channel has finished propagating the |
220 |
* \brief Indicates that the channel has finished propagating the |
| 207 |
* current packet. The channel is released and becomes free. |
221 |
* current packet. The channel is released and becomes free. |
| 208 |
* |
222 |
* |
| 209 |
* Calls the receive function of every active net device that is |
223 |
* \param deviceId The deviceID assigned to the net device when it |
|
|
224 |
* was connected to the channel |
| 225 |
* |
| 226 |
* Calls the receive function of the other net device that is |
| 210 |
* attached to the channel. |
227 |
* attached to the channel. |
| 211 |
*/ |
228 |
*/ |
| 212 |
void PropagationCompleteEvent (); |
229 |
void PropagationCompleteEvent (uint32_t deviceId); |
| 213 |
|
230 |
|
| 214 |
/** |
231 |
/** |
| 215 |
* \return Returns the device number assigned to a net device by the |
232 |
* \return Returns the device number assigned to a net device by the |
|
|
| 221 |
int32_t GetDeviceNum (Ptr<CsmaNetDevice> device); |
238 |
int32_t GetDeviceNum (Ptr<CsmaNetDevice> device); |
| 222 |
|
239 |
|
| 223 |
/** |
240 |
/** |
|
|
241 |
* \brief Checks the state of the channel. |
| 242 |
* |
| 243 |
* \param deviceId The deviceID assigned to the net device when it |
| 244 |
* was connected to the channel |
| 224 |
* \return Returns the state of the channel (IDLE -- free, |
245 |
* \return Returns the state of the channel (IDLE -- free, |
| 225 |
* TRANSMITTING -- busy, PROPAGATING - busy ) |
246 |
* TRANSMITTING -- busy, PROPAGATING - busy ) |
| 226 |
*/ |
247 |
*/ |
| 227 |
WireState GetState (); |
248 |
WireState GetState (uint32_t deviceId); |
| 228 |
|
249 |
|
| 229 |
/** |
250 |
/** |
| 230 |
* \brief Indicates if the channel is busy. The channel will only |
251 |
* \brief Indicates if the channel is busy. The channel will only |
| 231 |
* accept new packets for transmission if it is not busy. |
252 |
* accept new packets for transmission if it is not busy. |
| 232 |
* |
253 |
* |
|
|
254 |
* \param deviceId The deviceID assigned to the net device when it |
| 255 |
* was connected to the channel |
| 233 |
* \return Returns true if the channel is busy and false if it is |
256 |
* \return Returns true if the channel is busy and false if it is |
| 234 |
* free. |
257 |
* free. |
| 235 |
*/ |
258 |
*/ |
| 236 |
bool IsBusy (); |
259 |
bool IsBusy (uint32_t deviceId); |
| 237 |
|
260 |
|
| 238 |
/** |
261 |
/** |
| 239 |
* \brief Indicates if a net device is currently attached or |
262 |
* \brief Indicates if a net device is currently attached or |
| 240 |
* detached from the channel. |
263 |
* detached from the channel. |
| 241 |
* |
264 |
* |
| 242 |
* \param deviceId The ID that was assigned to the net device when |
265 |
* \param deviceId The deviceID assigned to the net device when it |
| 243 |
* it was attached to the channel. |
266 |
* was connected to the channel |
| 244 |
* \return Returns true if the net device is attached to the |
267 |
* \return Returns true if the net device is attached to the |
| 245 |
* channel, false otherwise. |
268 |
* channel, false otherwise. |
| 246 |
*/ |
269 |
*/ |
| 247 |
bool IsActive (uint32_t deviceId); |
270 |
bool IsActive (uint32_t deviceId); |
| 248 |
|
271 |
|
| 249 |
/** |
272 |
/** |
|
|
273 |
* \brief Indicates if channel is operating in full-duplex mode. |
| 274 |
* |
| 275 |
* \return Returns true if channel is in full-duplex mode, false if in |
| 276 |
* half-duplex mode. |
| 277 |
*/ |
| 278 |
bool IsFullDuplex (void) const; |
| 279 |
|
| 280 |
/** |
| 250 |
* \return Returns the number of net devices that are currently |
281 |
* \return Returns the number of net devices that are currently |
| 251 |
* attached to the channel. |
282 |
* attached to the channel. |
| 252 |
*/ |
283 |
*/ |
|
|
| 319 |
Time m_delay; |
350 |
Time m_delay; |
| 320 |
|
351 |
|
| 321 |
/** |
352 |
/** |
|
|
353 |
* Whether the channel is in full-duplex mode. |
| 354 |
*/ |
| 355 |
bool m_fullDuplex; |
| 356 |
|
| 357 |
/** |
| 322 |
* List of the net devices that have been or are currently connected |
358 |
* List of the net devices that have been or are currently connected |
| 323 |
* to the channel. |
359 |
* to the channel. |
| 324 |
* |
360 |
* |
|
|
| 332 |
std::vector<CsmaDeviceRec> m_deviceList; |
368 |
std::vector<CsmaDeviceRec> m_deviceList; |
| 333 |
|
369 |
|
| 334 |
/** |
370 |
/** |
| 335 |
* The Packet that is currently being transmitted on the channel (or last |
371 |
* The Packet that is currently being transmitted on the subchannel (or the |
| 336 |
* packet to have been transmitted on the channel if the channel is |
372 |
* last packet to have been transmitted if the subchannel is free). |
| 337 |
* free.) |
373 |
* In half-duplex mode, only the first subchannel is used. |
| 338 |
*/ |
374 |
*/ |
| 339 |
Ptr<Packet> m_currentPkt; |
375 |
Ptr<Packet> m_currentPkt[2]; |
| 340 |
|
376 |
|
| 341 |
/** |
377 |
/** |
| 342 |
* Device Id of the source that is currently transmitting on the |
378 |
* Device Id of the source that is currently transmitting on the |
|
|
379 |
* subchannel, or the last source to have transmitted a packet on the |
| 380 |
* subchannel, if it is not currently busy. |
| 381 |
* In half-duplex mode, only the first subchannel is used. |
| 382 |
*/ |
| 383 |
uint32_t m_currentSrc[2]; |
| 384 |
|
| 385 |
/** |
| 386 |
* Current state of each subchannel. |
| 387 |
* In half-duplex mode, only the first subchannel is used. |
| 388 |
*/ |
| 389 |
WireState m_state[2]; |
| 390 |
|
| 391 |
/** |
| 392 |
* \brief Gets current packet |
| 393 |
* |
| 394 |
* \param deviceId The deviceID assigned to the net device when it |
| 395 |
* was connected to the channel |
| 396 |
* \return Device Id of the source that is currently transmitting on the |
| 397 |
* subchannel or the last source to have transmitted a packet on the |
| 398 |
* subchannel, if it is not currently busy. |
| 399 |
*/ |
| 400 |
Ptr<Packet> GetCurrentPkt (uint32_t deviceId); |
| 401 |
|
| 402 |
/** |
| 403 |
* \brief Sets the current packet |
| 404 |
* |
| 405 |
* \param deviceId The deviceID assigned to the net device when it |
| 406 |
* was connected to the channel |
| 407 |
* \param The Packet that is current being transmitted by deviceId (or last |
| 408 |
* packet to have been transmitted on the channel if the channel is free.) |
| 409 |
*/ |
| 410 |
void SetCurrentPkt (uint32_t deviceId, Ptr<Packet> pkt); |
| 411 |
|
| 412 |
/** |
| 413 |
* \brief Gets current transmitter |
| 414 |
* |
| 415 |
* \param deviceId The deviceID assigned to the net device when it |
| 416 |
* was connected to the channel |
| 417 |
* \return Device Id of the source that is currently transmitting on the |
| 343 |
* channel. Or last source to have transmitted a packet on the |
418 |
* channel. Or last source to have transmitted a packet on the |
| 344 |
* channel, if the channel is currently not busy. |
419 |
* channel, if the channel is currently not busy. |
| 345 |
*/ |
420 |
*/ |
| 346 |
uint32_t m_currentSrc; |
421 |
uint32_t GetCurrentSrc (uint32_t deviceId); |
| 347 |
|
422 |
|
| 348 |
/** |
423 |
/** |
| 349 |
* Current state of the channel |
424 |
* \brief Sets the current transmitter |
|
|
425 |
* |
| 426 |
* \param deviceId The deviceID assigned to the net device when it |
| 427 |
* was connected to the channel |
| 428 |
* \param transmitterId The ID of the transmitting device. |
| 350 |
*/ |
429 |
*/ |
| 351 |
WireState m_state; |
430 |
void SetCurrentSrc (uint32_t deviceId, uint32_t transmitterId); |
|
|
431 |
|
| 432 |
/** |
| 433 |
* \brief Sets the state of the channel |
| 434 |
* |
| 435 |
* \param deviceId The deviceID assigned to the net device when it |
| 436 |
* was connected to the channel |
| 437 |
* \param state The new channel state. |
| 438 |
*/ |
| 439 |
void SetState (uint32_t deviceId, WireState state); |
| 440 |
|
| 352 |
}; |
441 |
}; |
| 353 |
|
442 |
|
| 354 |
} // namespace ns3 |
443 |
} // namespace ns3 |