A Discrete-Event Network Simulator
API
ns3::CsmaChannel Class Reference

Csma Channel. More...

#include "csma-channel.h"

+ Inheritance diagram for ns3::CsmaChannel:
+ Collaboration diagram for ns3::CsmaChannel:

Public Member Functions

 CsmaChannel ()
 Create a CsmaChannel. More...
 
virtual ~CsmaChannel ()
 Destroy a CsmaChannel. More...
 
int32_t Attach (Ptr< CsmaNetDevice > device)
 Attach a given netdevice to this channel. More...
 
bool Detach (Ptr< CsmaNetDevice > device)
 Detach a given netdevice from this channel. More...
 
bool Detach (uint32_t deviceId)
 Detach a given netdevice from this channel. More...
 
Ptr< CsmaNetDeviceGetCsmaDevice (std::size_t i) const
 
DataRate GetDataRate (void)
 Get the assigned data rate of the channel. More...
 
Time GetDelay (void)
 Get the assigned speed-of-light delay of the channel. More...
 
virtual Ptr< NetDeviceGetDevice (std::size_t i) const
 
int32_t GetDeviceNum (Ptr< CsmaNetDevice > device)
 
virtual std::size_t GetNDevices (void) const
 
uint32_t GetNumActDevices (void)
 
WireState GetState ()
 
bool IsActive (uint32_t deviceId)
 Indicates if a net device is currently attached or detached from the channel. More...
 
bool IsBusy ()
 Indicates if the channel is busy. More...
 
void PropagationCompleteEvent ()
 Indicates that the channel has finished propagating the current packet. More...
 
bool Reattach (uint32_t deviceId)
 Reattach a previously detached net device to the channel. More...
 
bool Reattach (Ptr< CsmaNetDevice > device)
 Reattach a previously detached net device to the channel. More...
 
bool TransmitEnd ()
 Indicates that the net device has finished transmitting the packet over the channel. More...
 
bool TransmitStart (Ptr< const Packet > p, uint32_t srcId)
 Start transmitting a packet over the channel. More...
 
- Public Member Functions inherited from ns3::Channel
 Channel ()
 
virtual ~Channel ()
 
uint32_t GetId (void) const
 
- Public Member Functions inherited from ns3::Object
 Object ()
 Constructor. More...
 
virtual ~Object ()
 Destructor. More...
 
void AggregateObject (Ptr< Object > other)
 Aggregate two Objects together. More...
 
void Dispose (void)
 Dispose of this Object. More...
 
AggregateIterator GetAggregateIterator (void) const
 Get an iterator to the Objects aggregated to this one. More...
 
virtual TypeId GetInstanceTypeId (void) const
 Get the most derived TypeId for this Object. More...
 
template<typename T >
Ptr< T > GetObject (void) const
 Get a pointer to the requested aggregated Object. More...
 
template<typename T >
Ptr< T > GetObject (TypeId tid) const
 Get a pointer to the requested aggregated Object by TypeId. More...
 
void Initialize (void)
 Invoke DoInitialize on all Objects aggregated to this one. More...
 
bool IsInitialized (void) const
 Check if the object has been initialized. More...
 
- Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter >
 SimpleRefCount ()
 Default constructor. More...
 
 SimpleRefCount (const SimpleRefCount &o)
 Copy constructor. More...
 
uint32_t GetReferenceCount (void) const
 Get the reference count of the object. More...
 
SimpleRefCountoperator= (const SimpleRefCount &o)
 Assignment operator. More...
 
void Ref (void) const
 Increment the reference count. More...
 
void Unref (void) const
 Decrement the reference count. More...
 
- Public Member Functions inherited from ns3::ObjectBase
virtual ~ObjectBase ()
 Virtual destructor. More...
 
void GetAttribute (std::string name, AttributeValue &value) const
 Get the value of an attribute, raising fatal errors if unsuccessful. More...
 
bool GetAttributeFailSafe (std::string name, AttributeValue &value) const
 Get the value of an attribute without raising erros. More...
 
void SetAttribute (std::string name, const AttributeValue &value)
 Set a single attribute, raising fatal errors if unsuccessful. More...
 
bool SetAttributeFailSafe (std::string name, const AttributeValue &value)
 Set a single attribute without raising errors. More...
 
bool TraceConnect (std::string name, std::string context, const CallbackBase &cb)
 Connect a TraceSource to a Callback with a context. More...
 
bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb)
 Connect a TraceSource to a Callback without a context. More...
 
bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected with a context. More...
 
bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected without a context. More...
 

Static Public Member Functions

static TypeId GetTypeId (void)
 Get the type ID. More...
 
- Static Public Member Functions inherited from ns3::Channel
static TypeId GetTypeId (void)
 Get the type ID. More...
 
- Static Public Member Functions inherited from ns3::Object
static TypeId GetTypeId (void)
 Register this type. More...
 
- Static Public Member Functions inherited from ns3::ObjectBase
static TypeId GetTypeId (void)
 Get the type ID. More...
 

Private Member Functions

 CsmaChannel (CsmaChannel const &o)
 Copy constructor is declared but not implemented. More...
 
CsmaChanneloperator= (CsmaChannel const &o)
 Operator = is declared but not implemented. More...
 

Private Attributes

DataRate m_bps
 The assigned data rate of the channel. More...
 
Ptr< Packetm_currentPkt
 The Packet that is currently being transmitted on the channel (or last packet to have been transmitted on the channel if the channel is free.) More...
 
uint32_t m_currentSrc
 Device Id of the source that is currently transmitting on the channel. More...
 
Time m_delay
 The assigned speed-of-light delay of the channel. More...
 
std::vector< CsmaDeviceRecm_deviceList
 List of the net devices that have been or are currently connected to the channel. More...
 
WireState m_state
 Current state of the channel. More...
 

Additional Inherited Members

- Protected Member Functions inherited from ns3::Object
 Object (const Object &o)
 Copy an Object. More...
 
virtual void DoDispose (void)
 Destructor implementation. More...
 
virtual void DoInitialize (void)
 Initialize() implementation. More...
 
virtual void NotifyNewAggregate (void)
 Notify all Objects aggregated to this one of a new Object being aggregated. More...
 
- Protected Member Functions inherited from ns3::ObjectBase
void ConstructSelf (const AttributeConstructionList &attributes)
 Complete construction of ObjectBase; invoked by derived classes. More...
 
virtual void NotifyConstructionCompleted (void)
 Notifier called once the ObjectBase is fully constructed. More...
 

Detailed Description

Csma Channel.


This class represents a simple Csma channel that can be used when many nodes are connected to one wire. It uses a single busy flag to indicate if the channel is currently in use. It does not take into account the distances between stations or the speed of light to determine collisions.

Config Paths

ns3::CsmaChannel is accessible through the following paths with Config::Set and Config::Connect:

  • "/NodeList/[i]/DeviceList/[i]/$ns3::WifiNetDevice/Channel/$ns3::CsmaChannel"
  • "/NodeList/[i]/DeviceList/[i]/$ns3::WaveNetDevice/Channel/$ns3::CsmaChannel"
  • "/ChannelList/[i]/$ns3::CsmaChannel"

Attributes

  • DataRate: The transmission data rate to be provided to devices connected to the channel
    • Set with class: DataRateValue
    • Underlying type: DataRate
    • Initial value: 4294967295bps
    • Flags: construct write read
  • Delay: Transmission delay through the channel
    • Set with class: ns3::TimeValue
    • Underlying type: Time –9223372036854775808.0ns:+9223372036854775807.0ns
    • Initial value: +0.0ns
    • Flags: construct write read

Attributes defined in parent class ns3::Channel

  • Id: The id (unique integer) of this Channel.

No TraceSources are defined for this type.
Size of this type is 88 bytes (on a 64-bit architecture).

Definition at line 90 of file csma-channel.h.

Constructor & Destructor Documentation

◆ CsmaChannel() [1/2]

ns3::CsmaChannel::CsmaChannel ( )

Create a CsmaChannel.

Definition at line 53 of file csma-channel.cc.

References ns3::IDLE, m_deviceList, m_state, and NS_LOG_FUNCTION_NOARGS.

◆ ~CsmaChannel()

ns3::CsmaChannel::~CsmaChannel ( )
virtual

Destroy a CsmaChannel.

Definition at line 62 of file csma-channel.cc.

References m_deviceList, and NS_LOG_FUNCTION.

◆ CsmaChannel() [2/2]

ns3::CsmaChannel::CsmaChannel ( CsmaChannel const &  o)
private

Copy constructor is declared but not implemented.

This disables the copy constructor for CsmaChannel objects.

Parameters
oobject to copy

Member Function Documentation

◆ Attach()

int32_t ns3::CsmaChannel::Attach ( Ptr< CsmaNetDevice device)

Attach a given netdevice to this channel.

Parameters
deviceDevice pointer to the netdevice to attach to the channel
Returns
The assigned device number

Definition at line 69 of file csma-channel.cc.

References m_deviceList, NS_ASSERT, and NS_LOG_FUNCTION.

◆ Detach() [1/2]

bool ns3::CsmaChannel::Detach ( Ptr< CsmaNetDevice device)

Detach a given netdevice from this channel.

The net device is marked as inactive and it is not allowed to receive or transmit packets

Parameters
deviceDevice pointer to the netdevice to detach from the channel
Returns
True if the device is found and attached to the channel, false if the device is not currently connected to the channel or can't be found.

Definition at line 155 of file csma-channel.cc.

References m_deviceList, NS_ASSERT, and NS_LOG_FUNCTION.

◆ Detach() [2/2]

bool ns3::CsmaChannel::Detach ( uint32_t  deviceId)

Detach a given netdevice from this channel.

The net device is marked as inactive and it is not allowed to receive or transmit packets

Parameters
deviceIdThe deviceID assigned to the net device when it was connected to the channel
Returns
True if the device is found and attached to the channel, false if the device is not currently connected to the channel or can't be found.

Definition at line 127 of file csma-channel.cc.

References m_currentSrc, m_deviceList, m_state, NS_LOG_FUNCTION, NS_LOG_WARN, and ns3::TRANSMITTING.

◆ GetCsmaDevice()

Ptr< CsmaNetDevice > ns3::CsmaChannel::GetCsmaDevice ( std::size_t  i) const
Returns
Get a CsmaNetDevice pointer to a connected network device.
Parameters
iThe deviceId of the net device for which we want the pointer.
Returns
Returns the pointer to the net device that is associated with deviceId i.

Definition at line 278 of file csma-channel.cc.

References m_deviceList.

Referenced by GetDevice().

+ Here is the caller graph for this function:

◆ GetDataRate()

DataRate ns3::CsmaChannel::GetDataRate ( void  )

Get the assigned data rate of the channel.

Returns
Returns the DataRate to be used by device transmitters. with deviceId i.

Definition at line 320 of file csma-channel.cc.

References m_bps.

◆ GetDelay()

Time ns3::CsmaChannel::GetDelay ( void  )

Get the assigned speed-of-light delay of the channel.

Returns
Returns the delay used by the channel.

Definition at line 326 of file csma-channel.cc.

References m_delay.

◆ GetDevice()

Ptr< NetDevice > ns3::CsmaChannel::GetDevice ( std::size_t  i) const
virtual
Returns
Get a NetDevice pointer to a connected network device.
Parameters
iThe index of the net device.
Returns
Returns the pointer to the net device that is associated with deviceId i.

Implements ns3::Channel.

Definition at line 338 of file csma-channel.cc.

References GetCsmaDevice().

+ Here is the call graph for this function:

◆ GetDeviceNum()

int32_t ns3::CsmaChannel::GetDeviceNum ( Ptr< CsmaNetDevice device)
Returns
Returns the device number assigned to a net device by the channel
Parameters
deviceDevice pointer to the netdevice for which the device number is needed

Definition at line 284 of file csma-channel.cc.

References m_deviceList.

◆ GetNDevices()

std::size_t ns3::CsmaChannel::GetNDevices ( void  ) const
virtual
Returns
Returns the total number of devices including devices that have been detached from the channel.

Implements ns3::Channel.

Definition at line 272 of file csma-channel.cc.

References m_deviceList.

◆ GetNumActDevices()

uint32_t ns3::CsmaChannel::GetNumActDevices ( void  )
Returns
Returns the number of net devices that are currently attached to the channel.

Definition at line 257 of file csma-channel.cc.

References m_deviceList.

◆ GetState()

WireState ns3::CsmaChannel::GetState ( void  )
Returns
Returns the state of the channel (IDLE – free, TRANSMITTING – busy, PROPAGATING - busy )

Definition at line 332 of file csma-channel.cc.

References m_state.

◆ GetTypeId()

TypeId ns3::CsmaChannel::GetTypeId ( void  )
static

Get the type ID.

Returns
the object TypeId

Definition at line 34 of file csma-channel.cc.

References m_bps, m_delay, ns3::MakeDataRateAccessor(), ns3::MakeDataRateChecker(), ns3::MakeTimeAccessor(), ns3::MakeTimeChecker(), ns3::Seconds(), and ns3::TypeId::SetParent().

+ Here is the call graph for this function:

◆ IsActive()

bool ns3::CsmaChannel::IsActive ( uint32_t  deviceId)

Indicates if a net device is currently attached or detached from the channel.

Parameters
deviceIdThe ID that was assigned to the net device when it was attached to the channel.
Returns
Returns true if the net device is attached to the channel, false otherwise.

Definition at line 198 of file csma-channel.cc.

References m_deviceList.

Referenced by TransmitEnd(), and TransmitStart().

+ Here is the caller graph for this function:

◆ IsBusy()

bool ns3::CsmaChannel::IsBusy ( void  )

Indicates if the channel is busy.

The channel will only accept new packets for transmission if it is not busy.

Returns
Returns true if the channel is busy and false if it is free.

Definition at line 307 of file csma-channel.cc.

References ns3::IDLE, and m_state.

◆ operator=()

CsmaChannel& ns3::CsmaChannel::operator= ( CsmaChannel const &  o)
private

Operator = is declared but not implemented.

This disables the assignment operator for CsmaChannel objects.

Parameters
oobject to copy
Returns
the copied object

◆ PropagationCompleteEvent()

void ns3::CsmaChannel::PropagationCompleteEvent ( )

Indicates that the channel has finished propagating the current packet.

The channel is released and becomes free.

Calls the receive function of every active net device that is attached to the channel.

Definition at line 247 of file csma-channel.cc.

References ns3::Packet::GetUid(), ns3::IDLE, m_currentPkt, m_state, NS_ASSERT, NS_LOG_FUNCTION, NS_LOG_INFO, and ns3::PROPAGATING.

Referenced by TransmitEnd().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Reattach() [1/2]

bool ns3::CsmaChannel::Reattach ( uint32_t  deviceId)

Reattach a previously detached net device to the channel.

The net device is marked as active. It is now allowed to receive or transmit packets. The net device must have been previously attached to the channel using the attach function.

Parameters
deviceIdThe device ID assigned to the net device when it was connected to the channel
Returns
True if the device is found and is not attached to the channel, false if the device is currently connected to the channel or can't be found.

Definition at line 106 of file csma-channel.cc.

References m_deviceList, and NS_LOG_FUNCTION.

◆ Reattach() [2/2]

bool ns3::CsmaChannel::Reattach ( Ptr< CsmaNetDevice device)

Reattach a previously detached net device to the channel.

The net device is marked as active. It is now allowed to receive or transmit packets. The net device must have been previously attached to the channel using the attach function.

Parameters
deviceDevice pointer to the netdevice to detach from the channel
Returns
True if the device is found and is not attached to the channel, false if the device is currently connected to the channel or can't be found.

Definition at line 81 of file csma-channel.cc.

References m_deviceList, NS_ASSERT, and NS_LOG_FUNCTION.

◆ TransmitEnd()

bool ns3::CsmaChannel::TransmitEnd ( )

Indicates that the net device has finished transmitting the packet over the channel.

The channel will stay busy until the packet has completely propagated to all net devices attached to the channel. The TransmitEnd function schedules the PropagationCompleteEvent which will free the channel for further transmissions. Stores the packet p as the m_currentPkt, the packet being currently transmitting.

Returns
Returns true unless the source was detached before it completed its transmission.

Definition at line 204 of file csma-channel.cc.

References ns3::Packet::Copy(), ns3::Time::GetSeconds(), ns3::Packet::GetUid(), IsActive(), m_currentPkt, m_currentSrc, m_delay, m_deviceList, m_state, NS_ASSERT, NS_LOG_ERROR, NS_LOG_FUNCTION, NS_LOG_INFO, NS_LOG_LOGIC(), ns3::PROPAGATING, PropagationCompleteEvent(), ns3::CsmaNetDevice::Receive(), ns3::Simulator::Schedule(), ns3::Simulator::ScheduleWithContext(), and ns3::TRANSMITTING.

+ Here is the call graph for this function:

◆ TransmitStart()

bool ns3::CsmaChannel::TransmitStart ( Ptr< const Packet p,
uint32_t  srcId 
)

Start transmitting a packet over the channel.

If the srcId belongs to a net device that is connected to the channel, packet transmission begins, and the channel becomes busy until the packet has completely reached all destinations.

Parameters
pA reference to the packet that will be transmitted over the channel
srcIdThe device Id of the net device that wants to transmit on the channel.
Returns
True if the channel is not busy and the transmitting net device is currently active.

Definition at line 173 of file csma-channel.cc.

References ns3::Packet::Copy(), ns3::Packet::GetUid(), ns3::IDLE, IsActive(), m_currentPkt, m_currentSrc, m_state, NS_LOG_ERROR, NS_LOG_FUNCTION, NS_LOG_INFO, NS_LOG_LOGIC(), NS_LOG_WARN, and ns3::TRANSMITTING.

+ Here is the call graph for this function:

Member Data Documentation

◆ m_bps

DataRate ns3::CsmaChannel::m_bps
private

The assigned data rate of the channel.

Definition at line 314 of file csma-channel.h.

Referenced by GetDataRate(), and GetTypeId().

◆ m_currentPkt

Ptr<Packet> ns3::CsmaChannel::m_currentPkt
private

The Packet that is currently being transmitted on the channel (or last packet to have been transmitted on the channel if the channel is free.)

Definition at line 339 of file csma-channel.h.

Referenced by PropagationCompleteEvent(), TransmitEnd(), and TransmitStart().

◆ m_currentSrc

uint32_t ns3::CsmaChannel::m_currentSrc
private

Device Id of the source that is currently transmitting on the channel.

Or last source to have transmitted a packet on the channel, if the channel is currently not busy.

Definition at line 346 of file csma-channel.h.

Referenced by Detach(), TransmitEnd(), and TransmitStart().

◆ m_delay

Time ns3::CsmaChannel::m_delay
private

The assigned speed-of-light delay of the channel.

Definition at line 319 of file csma-channel.h.

Referenced by GetDelay(), GetTypeId(), and TransmitEnd().

◆ m_deviceList

std::vector<CsmaDeviceRec> ns3::CsmaChannel::m_deviceList
private

List of the net devices that have been or are currently connected to the channel.

Devices are nor removed from this list, they are marked as inactive. Otherwise the assigned device IDs will not refer to the correct NetDevice. The DeviceIds are used so that it is possible to have a number to refer to an entry in the list so that the whole list does not have to be searched when making sure that a source is attached to a channel when it is transmitting data.

Definition at line 332 of file csma-channel.h.

Referenced by Attach(), CsmaChannel(), Detach(), GetCsmaDevice(), GetDeviceNum(), GetNDevices(), GetNumActDevices(), IsActive(), Reattach(), TransmitEnd(), and ~CsmaChannel().

◆ m_state

WireState ns3::CsmaChannel::m_state
private

Current state of the channel.

Definition at line 351 of file csma-channel.h.

Referenced by CsmaChannel(), Detach(), GetState(), IsBusy(), PropagationCompleteEvent(), TransmitEnd(), and TransmitStart().


The documentation for this class was generated from the following files: