#include "csma-channel.h"
Public Types | |
enum | WireState { IDLE , TRANSMITTING , PROPAGATING } |
Current state of the channel. More... | |
Public Member Functions | |
CsmaChannel () | |
Create a CsmaChannel. More... | |
CsmaChannel (const CsmaChannel &)=delete | |
~CsmaChannel () override | |
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< CsmaNetDevice > | GetCsmaDevice (std::size_t i) const |
DataRate | GetDataRate () |
Get the assigned data rate of the channel. More... | |
Time | GetDelay () |
Get the assigned speed-of-light delay of the channel. More... | |
Ptr< NetDevice > | GetDevice (std::size_t i) const override |
int32_t | GetDeviceNum (Ptr< CsmaNetDevice > device) |
std::size_t | GetNDevices () const override |
uint32_t | GetNumActDevices () |
WireState | GetState (uint32_t deviceId) |
Checks the state of the channel. More... | |
bool | IsActive (uint32_t deviceId) |
Indicates if a net device is currently attached or detached from the channel. More... | |
bool | IsBusy (uint32_t deviceId) |
Indicates if the channel is busy. More... | |
bool | IsFullDuplex () const |
Indicates if channel is operating in full-duplex mode. More... | |
CsmaChannel & | operator= (const CsmaChannel &)=delete |
void | PropagationCompleteEvent (uint32_t deviceId) |
Indicates that the channel has finished propagating the current packet. More... | |
bool | Reattach (Ptr< CsmaNetDevice > device) |
Reattach a previously detached net device to the channel. More... | |
bool | Reattach (uint32_t deviceId) |
Reattach a previously detached net device to the channel. More... | |
bool | TransmitEnd (uint32_t deviceId) |
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... | |
![]() | |
Channel () | |
~Channel () override | |
uint32_t | GetId () const |
![]() | |
Object () | |
Constructor. More... | |
~Object () override | |
Destructor. More... | |
void | AggregateObject (Ptr< Object > other) |
Aggregate two Objects together. More... | |
void | Dispose () |
Dispose of this Object. More... | |
AggregateIterator | GetAggregateIterator () const |
Get an iterator to the Objects aggregated to this one. More... | |
TypeId | GetInstanceTypeId () const override |
Get the most derived TypeId for this Object. More... | |
template<typename T > | |
Ptr< T > | GetObject () const |
Get a pointer to the requested aggregated Object. More... | |
template<> | |
Ptr< Object > | GetObject () const |
Specialization of () for objects of type ns3::Object. More... | |
template<typename T > | |
Ptr< T > | GetObject (TypeId tid) const |
Get a pointer to the requested aggregated Object by TypeId. More... | |
template<> | |
Ptr< Object > | GetObject (TypeId tid) const |
Specialization of (TypeId tid) for objects of type ns3::Object. More... | |
void | Initialize () |
Invoke DoInitialize on all Objects aggregated to this one. More... | |
bool | IsInitialized () const |
Check if the object has been initialized. More... | |
![]() | |
SimpleRefCount () | |
Default constructor. More... | |
SimpleRefCount (const SimpleRefCount &o[[maybe_unused]]) | |
Copy constructor. More... | |
uint32_t | GetReferenceCount () const |
Get the reference count of the object. More... | |
SimpleRefCount & | operator= (const SimpleRefCount &o[[maybe_unused]]) |
Assignment operator. More... | |
void | Ref () const |
Increment the reference count. More... | |
void | Unref () const |
Decrement the reference count. More... | |
![]() | |
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 errors. 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 () |
Get the type ID. More... | |
![]() | |
static TypeId | GetTypeId () |
Get the type ID. More... | |
![]() | |
static TypeId | GetTypeId () |
Register this type. More... | |
![]() | |
static TypeId | GetTypeId () |
Get the type ID. More... | |
Private Member Functions | |
Ptr< Packet > | GetCurrentPkt (uint32_t deviceId) |
Gets current packet. More... | |
uint32_t | GetCurrentSrc (uint32_t deviceId) |
Gets current transmitter. More... | |
void | SetCurrentPkt (uint32_t deviceId, Ptr< Packet > pkt) |
Sets the current packet. More... | |
void | SetCurrentSrc (uint32_t deviceId, uint32_t transmitterId) |
Sets the current transmitter. More... | |
void | SetState (uint32_t deviceId, WireState state) |
Sets the state of the channel. More... | |
Private Attributes | |
DataRate | m_bps |
The assigned data rate of the channel. More... | |
Ptr< Packet > | m_currentPkt [2] |
The Packet that is currently being transmitted on the subchannel (or the last packet to have been transmitted if the subchannel is free). More... | |
uint32_t | m_currentSrc [2] |
Device Id of the source that is currently transmitting on the subchannel, or the last source to have transmitted a packet on the subchannel, if it is not currently busy. More... | |
Time | m_delay |
The assigned speed-of-light delay of the channel. More... | |
std::vector< CsmaDeviceRec > | m_deviceList |
List of the net devices that have been or are currently connected to the channel. More... | |
bool | m_fullDuplex |
Whether the channel is in full-duplex mode. More... | |
WireState | m_state [2] |
Current state of each subchannel. More... | |
Additional Inherited Members | |
![]() | |
Object (const Object &o) | |
Copy an Object. More... | |
virtual void | DoDispose () |
Destructor implementation. More... | |
virtual void | DoInitialize () |
Initialize() implementation. More... | |
virtual void | NotifyNewAggregate () |
Notify all Objects aggregated to this one of a new Object being aggregated. More... | |
![]() | |
void | ConstructSelf (const AttributeConstructionList &attributes) |
Complete construction of ObjectBase; invoked by derived classes. More... | |
virtual void | NotifyConstructionCompleted () |
Notifier called once the ObjectBase is fully constructed. More... | |
![]() | |
static TypeId | GetObjectIid () |
Ensure the TypeId for ObjectBase gets fully configured to anchor the inheritance tree properly. More... | |
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. Optionally, it allows for full- duplex operation when there are only two attached nodes. To implement full-duplex, we internally keep two TX "subchannels" (one for each attached node). When in half-duplex mode, only the first subchannel is used.
ns3::CsmaChannel is accessible through the following paths with Config::Set and Config::Connect:
DataRate
Time
+9.22337e+18ns:+9.22337e+18ns No TraceSources are defined for this type.
Size of this type is 112 bytes (on a 64-bit architecture).
Definition at line 92 of file csma-channel.h.
Current state of the channel.
Enumerator | |
---|---|
IDLE | Channel is IDLE, no packet is being transmitted. |
TRANSMITTING | Channel is BUSY, a packet is being written by a net device. |
PROPAGATING | Channel is BUSY, packet is propagating to all attached net devices. |
Definition at line 98 of file csma-channel.h.
ns3::CsmaChannel::CsmaChannel | ( | ) |
Create a CsmaChannel.
Definition at line 69 of file csma-channel.cc.
References m_deviceList, and NS_LOG_FUNCTION_NOARGS.
|
override |
Destroy a CsmaChannel.
Definition at line 76 of file csma-channel.cc.
References m_deviceList, and NS_LOG_FUNCTION.
|
delete |
int32_t ns3::CsmaChannel::Attach | ( | Ptr< CsmaNetDevice > | device | ) |
Attach a given netdevice to this channel.
device | Device pointer to the netdevice to attach to the channel |
Definition at line 83 of file csma-channel.cc.
References IDLE, m_deviceList, m_fullDuplex, NS_ASSERT, NS_LOG_DEBUG, NS_LOG_FUNCTION, SetCurrentSrc(), and SetState().
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
device | Device pointer to the netdevice to detach from the channel |
Definition at line 182 of file csma-channel.cc.
References m_deviceList, NS_ASSERT, and NS_LOG_FUNCTION.
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
deviceId | The deviceID assigned to the net device when it was connected to the channel |
Definition at line 153 of file csma-channel.cc.
References GetCurrentSrc(), GetState(), m_deviceList, NS_LOG_FUNCTION, NS_LOG_WARN, and TRANSMITTING.
Ptr< CsmaNetDevice > ns3::CsmaChannel::GetCsmaDevice | ( | std::size_t | i | ) | const |
i | The deviceId of the net device for which we want the pointer. |
Definition at line 327 of file csma-channel.cc.
References m_deviceList.
Referenced by GetDevice().
Gets current packet.
deviceId | The ID that was assigned to the net device when it was attached to the channel. |
Definition at line 393 of file csma-channel.cc.
References m_currentPkt, and m_fullDuplex.
Referenced by PropagationCompleteEvent(), and TransmitEnd().
|
private |
Gets current transmitter.
deviceId | The ID that was assigned to the net device when it was attached to the channel. |
Definition at line 405 of file csma-channel.cc.
References m_currentSrc, and m_fullDuplex.
Referenced by Detach(), and TransmitEnd().
DataRate ns3::CsmaChannel::GetDataRate | ( | ) |
Get the assigned data rate of the channel.
Definition at line 369 of file csma-channel.cc.
References m_bps.
Time ns3::CsmaChannel::GetDelay | ( | ) |
Get the assigned speed-of-light delay of the channel.
Definition at line 375 of file csma-channel.cc.
References m_delay.
i | The index of the net device. |
Implements ns3::Channel.
Definition at line 387 of file csma-channel.cc.
References GetCsmaDevice().
int32_t ns3::CsmaChannel::GetDeviceNum | ( | Ptr< CsmaNetDevice > | device | ) |
device | Device pointer to the netdevice for which the device number is needed |
Definition at line 333 of file csma-channel.cc.
References m_deviceList.
|
overridevirtual |
Implements ns3::Channel.
Definition at line 321 of file csma-channel.cc.
References m_deviceList.
uint32_t ns3::CsmaChannel::GetNumActDevices | ( | ) |
Definition at line 306 of file csma-channel.cc.
References m_deviceList.
CsmaChannel::WireState ns3::CsmaChannel::GetState | ( | uint32_t | deviceId | ) |
Checks the state of the channel.
deviceId | The ID that was assigned to the net device when it was attached to the channel. |
Definition at line 381 of file csma-channel.cc.
References m_fullDuplex, and m_state.
Referenced by Detach(), IsBusy(), PropagationCompleteEvent(), TransmitEnd(), and TransmitStart().
|
static |
Get the type ID.
Definition at line 42 of file csma-channel.cc.
References ns3::TypeId::ATTR_CONSTRUCT, m_bps, m_delay, m_fullDuplex, ns3::MakeBooleanAccessor(), ns3::MakeBooleanChecker(), ns3::MakeTimeAccessor(), ns3::MakeTimeChecker(), ns3::Seconds(), and ns3::TypeId::SetParent().
bool ns3::CsmaChannel::IsActive | ( | uint32_t | deviceId | ) |
Indicates if a net device is currently attached or detached from the channel.
deviceId | The ID that was assigned to the net device when it was attached to the channel. |
Definition at line 226 of file csma-channel.cc.
References m_deviceList.
Referenced by TransmitEnd(), and TransmitStart().
bool ns3::CsmaChannel::IsBusy | ( | uint32_t | deviceId | ) |
Indicates if the channel is busy.
The channel will only accept new packets for transmission if it is not busy.
deviceId | The ID that was assigned to the net device when it was attached to the channel. |
Definition at line 356 of file csma-channel.cc.
References GetState(), and IDLE.
bool ns3::CsmaChannel::IsFullDuplex | ( | ) | const |
Indicates if channel is operating in full-duplex mode.
Definition at line 232 of file csma-channel.cc.
References m_fullDuplex.
Referenced by TransmitEnd().
|
delete |
void ns3::CsmaChannel::PropagationCompleteEvent | ( | uint32_t | deviceId | ) |
Indicates that the channel has finished propagating the current packet.
The channel is released and becomes free.
deviceId | The ID that was assigned to the net device when it was attached to the channel. Calls the receive function of the other net device that is attached to the channel. |
Definition at line 296 of file csma-channel.cc.
References GetCurrentPkt(), GetState(), IDLE, NS_ASSERT, NS_LOG_FUNCTION, NS_LOG_INFO, PROPAGATING, and SetState().
Referenced by TransmitEnd().
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.
device | Device pointer to the netdevice to detach from the channel |
Definition at line 107 of file csma-channel.cc.
References m_deviceList, NS_ASSERT, and NS_LOG_FUNCTION.
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.
deviceId | The device ID assigned to the net device when it was connected to the channel |
Definition at line 132 of file csma-channel.cc.
References m_deviceList, and NS_LOG_FUNCTION.
Sets the current packet.
deviceId | The ID that was assigned to the net device when it was attached to the channel. |
The | Packet that is current being transmitted by deviceId (or last packet to have been transmitted on the channel if the channel is free.) |
Definition at line 399 of file csma-channel.cc.
References m_currentPkt, and m_fullDuplex.
Referenced by TransmitStart().
|
private |
Sets the current transmitter.
deviceId | The ID that was assigned to the net device when it was attached to the channel. |
transmitterId | The ID of the transmitting device. |
Definition at line 411 of file csma-channel.cc.
References m_currentSrc, and m_fullDuplex.
Referenced by Attach(), and TransmitStart().
|
private |
Sets the state of the channel.
deviceId | The ID that was assigned to the net device when it was attached to the channel. |
state | The new channel state. |
Definition at line 417 of file csma-channel.cc.
References m_fullDuplex, and m_state.
Referenced by Attach(), PropagationCompleteEvent(), TransmitEnd(), and TransmitStart().
bool ns3::CsmaChannel::TransmitEnd | ( | uint32_t | deviceId | ) |
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.
deviceId | The ID that was assigned to the net device when it was attached to the channel. |
Definition at line 238 of file csma-channel.cc.
References ns3::Time::As(), ns3::Copy(), GetCurrentPkt(), GetCurrentSrc(), GetState(), IsActive(), IsFullDuplex(), m_delay, m_deviceList, NS_ASSERT, NS_LOG_ERROR, NS_LOG_FUNCTION, NS_LOG_INFO, NS_LOG_LOGIC, PROPAGATING, PropagationCompleteEvent(), ns3::CsmaNetDevice::Receive(), ns3::Time::S, ns3::Simulator::Schedule(), ns3::Simulator::ScheduleWithContext(), SetState(), and TRANSMITTING.
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.
p | A reference to the packet that will be transmitted over the channel |
srcId | The device Id of the net device that wants to transmit on the channel. |
Definition at line 200 of file csma-channel.cc.
References ns3::Packet::Copy(), GetState(), ns3::Packet::GetUid(), IDLE, IsActive(), NS_LOG_ERROR, NS_LOG_FUNCTION, NS_LOG_INFO, NS_LOG_LOGIC, NS_LOG_WARN, SetCurrentPkt(), SetCurrentSrc(), SetState(), and TRANSMITTING.
|
private |
The assigned data rate of the channel.
Definition at line 332 of file csma-channel.h.
Referenced by GetDataRate(), and GetTypeId().
The Packet that is currently being transmitted on the subchannel (or the last packet to have been transmitted if the subchannel is free).
In half-duplex mode, only the first subchannel is used.
Definition at line 362 of file csma-channel.h.
Referenced by GetCurrentPkt(), and SetCurrentPkt().
|
private |
Device Id of the source that is currently transmitting on the subchannel, or the last source to have transmitted a packet on the subchannel, if it is not currently busy.
In half-duplex mode, only the first subchannel is used.
Definition at line 370 of file csma-channel.h.
Referenced by GetCurrentSrc(), and SetCurrentSrc().
|
private |
The assigned speed-of-light delay of the channel.
Definition at line 337 of file csma-channel.h.
Referenced by GetDelay(), GetTypeId(), and TransmitEnd().
|
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 355 of file csma-channel.h.
Referenced by CsmaChannel(), ~CsmaChannel(), Attach(), Detach(), GetCsmaDevice(), GetDeviceNum(), GetNDevices(), GetNumActDevices(), IsActive(), Reattach(), and TransmitEnd().
|
private |
Whether the channel is in full-duplex mode.
Definition at line 342 of file csma-channel.h.
Referenced by Attach(), GetCurrentPkt(), GetCurrentSrc(), GetState(), GetTypeId(), IsFullDuplex(), SetCurrentPkt(), SetCurrentSrc(), and SetState().
|
private |
Current state of each subchannel.
In half-duplex mode, only the first subchannel is used.
Definition at line 376 of file csma-channel.h.
Referenced by GetState(), and SetState().