A Discrete-Event Network Simulator
API
csma-channel.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 Emmanuelle Laprise
3  * Copyright (c) 2012 Jeffrey Young
4  * Copyright (c) 2014 Murphy McCauley
5  * Copyright (c) 2017 Luciano Jerez Chaves
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation;
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Author: Emmanuelle Laprise<emmanuelle.laprise@bluekazoo.ca>
21  * Author: Jeff Young <jyoung9@gatech.edu>
22  * Author: Murphy McCauley <murphy.mccauley@gmail.com>
23  * Author: Luciano Jerez Chaves <ljerezchaves@gmail.com>
24  */
25 
26 #ifndef CSMA_CHANNEL_H
27 #define CSMA_CHANNEL_H
28 
29 #include "ns3/boolean.h"
30 #include "ns3/channel.h"
31 #include "ns3/data-rate.h"
32 #include "ns3/nstime.h"
33 #include "ns3/ptr.h"
34 
35 namespace ns3
36 {
37 
38 class Packet;
39 
40 class CsmaNetDevice;
41 
50 {
51  public:
53  bool active;
54 
55  CsmaDeviceRec();
56 
64 
69  CsmaDeviceRec(const CsmaDeviceRec& o);
70 
75  bool IsActive() const;
76 };
77 
92 class CsmaChannel : public Channel
93 {
94  public:
98  enum WireState
99  {
102  PROPAGATING
103  };
104 
109  static TypeId GetTypeId();
110 
114  CsmaChannel();
118  ~CsmaChannel() override;
119 
120  // Delete copy constructor and assignment operator to avoid misuse
121  CsmaChannel(const CsmaChannel&) = delete;
122  CsmaChannel& operator=(const CsmaChannel&) = delete;
123 
130  int32_t Attach(Ptr<CsmaNetDevice> device);
131 
143  bool Detach(Ptr<CsmaNetDevice> device);
144 
157  bool Detach(uint32_t deviceId);
158 
172  bool Reattach(uint32_t deviceId);
173 
186  bool Reattach(Ptr<CsmaNetDevice> device);
187 
202  bool TransmitStart(Ptr<const Packet> p, uint32_t srcId);
203 
220  bool TransmitEnd(uint32_t deviceId);
221 
231  void PropagationCompleteEvent(uint32_t deviceId);
232 
240  int32_t GetDeviceNum(Ptr<CsmaNetDevice> device);
241 
250  WireState GetState(uint32_t deviceId);
251 
261  bool IsBusy(uint32_t deviceId);
262 
272  bool IsActive(uint32_t deviceId);
273 
280  bool IsFullDuplex() const;
281 
286  uint32_t GetNumActDevices();
287 
292  std::size_t GetNDevices() const override;
293 
301  Ptr<NetDevice> GetDevice(std::size_t i) const override;
302 
311  Ptr<CsmaNetDevice> GetCsmaDevice(std::size_t i) const;
312 
320 
326  Time GetDelay();
327 
328  private:
333 
338 
343 
355  std::vector<CsmaDeviceRec> m_deviceList;
356 
363 
370  uint32_t m_currentSrc[2];
371 
377 
387  Ptr<Packet> GetCurrentPkt(uint32_t deviceId);
388 
397  void SetCurrentPkt(uint32_t deviceId, Ptr<Packet> pkt);
398 
408  uint32_t GetCurrentSrc(uint32_t deviceId);
409 
417  void SetCurrentSrc(uint32_t deviceId, uint32_t transmitterId);
418 
426  void SetState(uint32_t deviceId, WireState state);
427 };
428 
429 } // namespace ns3
430 
431 #endif /* CSMA_CHANNEL_H */
Abstract Channel Base Class.
Definition: channel.h:45
Csma Channel.
Definition: csma-channel.h:93
CsmaChannel & operator=(const CsmaChannel &)=delete
void PropagationCompleteEvent(uint32_t deviceId)
Indicates that the channel has finished propagating the current packet.
void SetState(uint32_t deviceId, WireState state)
Sets the state of the channel.
CsmaChannel(const CsmaChannel &)=delete
~CsmaChannel() override
Destroy a CsmaChannel.
Definition: csma-channel.cc:76
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:332
bool m_fullDuplex
Whether the channel is in full-duplex mode.
Definition: csma-channel.h:342
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.
bool IsBusy(uint32_t deviceId)
Indicates if the channel is busy.
int32_t GetDeviceNum(Ptr< CsmaNetDevice > device)
Time m_delay
The assigned speed-of-light delay of the channel.
Definition: csma-channel.h:337
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:42
WireState GetState(uint32_t deviceId)
Checks the state of the channel.
CsmaChannel()
Create a CsmaChannel.
Definition: csma-channel.cc:69
bool Detach(Ptr< CsmaNetDevice > device)
Detach a given netdevice from this channel.
bool TransmitEnd(uint32_t deviceId)
Indicates that the net device has finished transmitting the packet over the channel.
void SetCurrentPkt(uint32_t deviceId, Ptr< Packet > pkt)
Sets the current packet.
void SetCurrentSrc(uint32_t deviceId, uint32_t transmitterId)
Sets the current transmitter.
WireState m_state[2]
Current state of each subchannel.
Definition: csma-channel.h:376
std::vector< CsmaDeviceRec > m_deviceList
List of the net devices that have been or are currently connected to the channel.
Definition: csma-channel.h:355
Ptr< Packet > GetCurrentPkt(uint32_t deviceId)
Gets current packet.
int32_t Attach(Ptr< CsmaNetDevice > device)
Attach a given netdevice to this channel.
Definition: csma-channel.cc:83
bool IsFullDuplex() const
Indicates if channel is operating in full-duplex mode.
Ptr< NetDevice > GetDevice(std::size_t i) const override
uint32_t m_currentSrc[2]
Device Id of the source that is currently transmitting on the subchannel, or the last source to have ...
Definition: csma-channel.h:370
uint32_t GetCurrentSrc(uint32_t deviceId)
Gets current transmitter.
WireState
Current state of the channel.
Definition: csma-channel.h:99
@ PROPAGATING
Channel is BUSY, packet is propagating to all attached net devices.
Definition: csma-channel.h:102
@ IDLE
Channel is IDLE, no packet is being transmitted.
Definition: csma-channel.h:100
@ TRANSMITTING
Channel is BUSY, a packet is being written by a net device.
Definition: csma-channel.h:101
Ptr< Packet > m_currentPkt[2]
The Packet that is currently being transmitted on the subchannel (or the last packet to have been tra...
Definition: csma-channel.h:362
std::size_t GetNDevices() const override
CsmaNetDevice Record.
Definition: csma-channel.h:50
bool IsActive() const
Ptr< CsmaNetDevice > devicePtr
Pointer to the net device.
Definition: csma-channel.h:52
bool active
Is net device enabled to TX/RX.
Definition: csma-channel.h:53
Class for representing data rates.
Definition: data-rate.h:90
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:60
Every class exported by the ns3 library is enclosed in the ns3 namespace.