A Discrete-Event Network Simulator
API
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 
28 namespace ns3
29 {
30 
31 class Packet;
32 
33 class CsmaNetDevice;
34 
43 {
44  public:
46  bool active;
47 
48  CsmaDeviceRec();
49 
57 
62  CsmaDeviceRec(const CsmaDeviceRec& o);
63 
68  bool IsActive() const;
69 };
70 
75 {
76  IDLE,
79 };
80 
91 class CsmaChannel : public Channel
92 {
93  public:
98  static TypeId GetTypeId();
99 
103  CsmaChannel();
107  ~CsmaChannel() override;
108 
109  // Delete copy constructor and assignment operator to avoid misuse
110  CsmaChannel(const CsmaChannel&) = delete;
111  CsmaChannel& operator=(const CsmaChannel&) = delete;
112 
119  int32_t Attach(Ptr<CsmaNetDevice> device);
120 
132  bool Detach(Ptr<CsmaNetDevice> device);
133 
146  bool Detach(uint32_t deviceId);
147 
161  bool Reattach(uint32_t deviceId);
162 
175  bool Reattach(Ptr<CsmaNetDevice> device);
176 
191  bool TransmitStart(Ptr<const Packet> p, uint32_t srcId);
192 
207  bool TransmitEnd();
208 
217 
225  int32_t GetDeviceNum(Ptr<CsmaNetDevice> device);
226 
232 
240  bool IsBusy();
241 
251  bool IsActive(uint32_t deviceId);
252 
257  uint32_t GetNumActDevices();
258 
263  std::size_t GetNDevices() const override;
264 
272  Ptr<NetDevice> GetDevice(std::size_t i) const override;
273 
282  Ptr<CsmaNetDevice> GetCsmaDevice(std::size_t i) const;
283 
291 
297  Time GetDelay();
298 
299  private:
304 
309 
321  std::vector<CsmaDeviceRec> m_deviceList;
322 
329 
335  uint32_t m_currentSrc;
336 
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 & operator=(const CsmaChannel &)=delete
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()
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