DESERT 4.0.0
CsmaCa Class Reference

#include <uw-csma-ca.h>

Inheritance diagram for CsmaCa:
Inheritance graph
Collaboration diagram for CsmaCa:
Collaboration graph

Classes

class  CsmaCaTimer
 

Public Member Functions

 CsmaCa ()
 
virtual ~CsmaCa ()
 
virtual int command (int argc, const char *const *argv)
 

Protected Member Functions

virtual void recvFromUpperLayers (Packet *p)
 
virtual void Mac2PhyStartTx (Packet *p)
 
virtual void Phy2MacEndTx (const Packet *p)
 
virtual void Phy2MacStartRx (const Packet *p)
 
virtual void Phy2MacEndRx (Packet *p)
 
virtual void dropPacket (Packet *p, csma_ca_pkt_type_t type, char *reason)
 
csma_ca_states_t getState ()
 
void updateState (csma_ca_states_t s)
 
csma_ca_log_level_t getLogLevel ()
 
int getQueueSize ()
 
time_t getEpoch ()
 
string getLogFile ()
 
virtual void state_Wait_CTS ()
 
virtual void state_Wait_Data ()
 
virtual void state_Idle ()
 
virtual void state_Backoff (int tx_time)
 
virtual int stateRxData (Packet *p)
 
virtual int stateRxRTS (hdr_ca_RTS *rts, int mac_src, int mac_dst)
 
virtual int stateRxCTS (hdr_ca_CTS *cts, int mac_src, int mac_dst)
 
virtual int stateRxACK (Packet *ack)
 
virtual void stateTxCTS ()
 
virtual int stateTxData ()
 
virtual void state_Wait_ACK ()
 
virtual void stateTxAck (int mac_dst)
 
virtual void initializeLog ()
 

Protected Attributes

CsmaCaTimer backoff_timer
 
CsmaCaTimer cts_timer
 
CsmaCaTimer data_timer
 
CsmaCaTimer ack_timer
 

Private Member Functions

void printonLog (csma_ca_log_level_t level, string log)
 
void extractDataPacket ()
 
int txData ()
 
int txRTS (int mac_dest)
 
int txCTS (int mac_dest)
 
int txAck ()
 
void data_timer_fired ()
 
void backoff_timer_fired ()
 
void cts_timer_fired ()
 
void ack_timer_fired ()
 
int computeTxTime ()
 
void buildRTShdr (hdr_ca_RTS **rts, uint8_t tx_time)
 
void buildCTShdr (hdr_ca_CTS **cts, uint8_t tx_time)
 
Packet * buildPacket (int mac_dest, csma_ca_pkt_type_t type, uint8_t tx_time)
 

Private Attributes

int max_queue_size
 
int data_size
 
int bitrate
 
int backoff_delta
 
int backoff_max
 
int cts_wait_val
 
int data_wait_val
 
int ack_wait_val
 
int actual_mac_data_src
 
int actual_expected_tx_time
 
Packet * actual_data_packet
 
std::queue< Packet * > data_q
 
ack_modes_t ack_mode
 
csma_ca_states_t state
 
csma_ca_states_t previous_state
 
std::ofstream outLog
 
csma_ca_log_level_t log_level
 
string logfile
 
int n_rts_rx
 
int n_cts_rx
 
int data_pkt_dropped
 
int cts_pkt_dropped
 
int rts_pkt_dropped
 
int ack_pkt_dropped
 

Detailed Description

Class that describes a CsmaAloha module

Constructor & Destructor Documentation

◆ CsmaCa()

◆ ~CsmaCa()

CsmaCa::~CsmaCa ( )
virtual

Member Function Documentation

◆ ack_timer_fired()

void CsmaCa::ack_timer_fired ( )
private

ACK timer is expired

References CSMA_CA_WAIT_ACK, state, and state_Idle().

Here is the call graph for this function:

◆ backoff_timer_fired()

void CsmaCa::backoff_timer_fired ( )
private

backoff timer is expired

References CSMA_CA_BACKOFF, getState(), and state_Idle().

Here is the call graph for this function:

◆ buildCTShdr()

void CsmaCa::buildCTShdr ( hdr_ca_CTS **  cts,
uint8_t  tx_time 
)
private

Build an CTS header

Parameters
hdr_ca_CTS**pointer to CTS header to be built
uint8_texpected tx time of DATA packet

Referenced by buildPacket().

◆ buildPacket()

Packet * CsmaCa::buildPacket ( int  mac_dest,
csma_ca_pkt_type_t  type,
uint8_t  tx_time 
)
private

Build a generic packet

Parameters
intMAC destination
csma_ca_pkt_type_ttype of packet to build
uint8_texpected tx time of DATA packet

References buildCTShdr(), buildRTShdr(), CSMA_CA_ACK, CSMA_CA_CTS, CSMA_CA_RTS, PT_CA_ACK, PT_CA_CTS, and PT_CA_RTS.

Referenced by stateTxAck(), txCTS(), and txRTS().

Here is the call graph for this function:

◆ buildRTShdr()

void CsmaCa::buildRTShdr ( hdr_ca_RTS **  rts,
uint8_t  tx_time 
)
private

Build an RTS header

Parameters
hdr_ca_RTS**pointer to RTS header to be built
uint8_texpected tx time of DATA packet

Referenced by buildPacket().

◆ command()

int CsmaCa::command ( int  argc,
const char *const *  argv 
)
virtual

TCL command interpreter. It implements the following OTcl methods:

Parameters
argcNumber of arguments in argv.
argvArray of strings which are the command parameters (Note that argv[0] is the name of the object).
Returns
TCL_OK or TCL_ERROR whether the command has been dispatched successfully or not.

References ack_mode, CSMA_CA_ACK_MODE, CSMA_CA_NO_ACK_MODE, cts_pkt_dropped, data_pkt_dropped, getQueueSize(), initializeLog(), n_cts_rx, n_rts_rx, and rts_pkt_dropped.

Here is the call graph for this function:

◆ computeTxTime()

int CsmaCa::computeTxTime ( )
inlineprivate

Compute transmission time of a packet using known bitrate

Returns
int tranmission time

References bitrate, and data_size.

Referenced by txRTS().

◆ cts_timer_fired()

void CsmaCa::cts_timer_fired ( )
private

CTS timer is expired

References CSMA_CA_WAIT_CTS, getState(), and state_Backoff().

Here is the call graph for this function:

◆ data_timer_fired()

void CsmaCa::data_timer_fired ( )
private

data timer is expired

References CSMA_CA_WAIT_DATA, getState(), and state_Idle().

Here is the call graph for this function:

◆ dropPacket()

void CsmaCa::dropPacket ( Packet *  p,
csma_ca_pkt_type_t  type,
char *  reason 
)
protectedvirtual

Drop the packet logging the reason and incrementing the counters

Parameters
Packet*Pointer to packet to be ack_pkt_dropped
csma_ca_pkt_type_ttype of the packet dropped
char*Reason for drop

References ack_pkt_dropped, CSMA_CA_ACK, CSMA_CA_CTS, CSMA_CA_DATA, CSMA_CA_RTS, cts_pkt_dropped, data_pkt_dropped, and rts_pkt_dropped.

Referenced by Phy2MacEndRx(), and recvFromUpperLayers().

◆ extractDataPacket()

void CsmaCa::extractDataPacket ( )
private

Extract data packet from queue

References actual_data_packet, data_q, and txRTS().

Referenced by state_Idle().

Here is the call graph for this function:

◆ getEpoch()

time_t CsmaCa::getEpoch ( )
inlineprotected

Return the system epoch

Returns
time_t epoch

Referenced by printonLog().

◆ getLogFile()

string CsmaCa::getLogFile ( )
inlineprotected

Return name of the log file

Returns
string file name

References logfile.

Referenced by printonLog().

◆ getLogLevel()

csma_ca_log_level_t CsmaCa::getLogLevel ( )
inlineprotected

Return the current log level of the protocol

Returns
csma_ca_log_t log level

References log_level.

Referenced by printonLog().

◆ getQueueSize()

int CsmaCa::getQueueSize ( )
inlineprotected

Return the size of the data packet queue

Returns
int queue size

References data_q.

Referenced by command(), and recvFromUpperLayers().

◆ getState()

csma_ca_states_t CsmaCa::getState ( )
inlineprotected

Get the state of the protocol

Returns
csma_ca_state_t Current state

References state.

Referenced by backoff_timer_fired(), cts_timer_fired(), data_timer_fired(), stateRxCTS(), stateRxData(), and stateRxRTS().

◆ initializeLog()

void CsmaCa::initializeLog ( )
protectedvirtual

Initializes the protocol at the beginning of the simulation. This method is called by a command in tcl.

References logfile, and outLog.

Referenced by command().

◆ Mac2PhyStartTx()

void CsmaCa::Mac2PhyStartTx ( Packet *  p)
protectedvirtual

Pass the packet to the PHY layer

Parameters
Packet*Pointer to an object of type Packet that represent the Packet to transmit

Referenced by stateTxAck(), txCTS(), txData(), and txRTS().

◆ Phy2MacEndRx()

void CsmaCa::Phy2MacEndRx ( Packet *  p)
protectedvirtual

Method called when the Phy Layer finish to receive a Packet

Parameters
Packet*Pointer to an object of type Packet that represent the Packet received

References CSMA_CA_ACK, CSMA_CA_CTS, CSMA_CA_DATA, CSMA_CA_RTS, dropPacket(), n_cts_rx, n_rts_rx, PT_CA_ACK, PT_CA_CTS, PT_CA_RTS, stateRxACK(), stateRxCTS(), stateRxData(), and stateRxRTS().

Here is the call graph for this function:

◆ Phy2MacEndTx()

void CsmaCa::Phy2MacEndTx ( const Packet *  p)
protectedvirtual

Method called when the PHY layer finish to transmit the packet.

Parameters
Packet*Pointer to an object of type Packet that represent the Packet transmitted

References ack_mode, actual_data_packet, CSMA_CA_ACK_MODE, PT_CA_ACK, PT_CA_CTS, PT_CA_RTS, state_Idle(), state_Wait_ACK(), state_Wait_CTS(), and state_Wait_Data().

Here is the call graph for this function:

◆ Phy2MacStartRx()

void CsmaCa::Phy2MacStartRx ( const Packet *  p)
protectedvirtual

Method called when the Phy Layer start to receive a Packet

Parameters
constPacket* Pointer to an object of type Packet that represent the Packet that is in reception

◆ printonLog()

void CsmaCa::printonLog ( csma_ca_log_level_t  level,
string  log 
)
private

Print a message on log file

Parameters
csma_ca_log_level_tlog level of the message
stringActual message

References getEpoch(), getLogFile(), getLogLevel(), log_level_string, and outLog.

Here is the call graph for this function:

◆ recvFromUpperLayers()

void CsmaCa::recvFromUpperLayers ( Packet *  p)
protectedvirtual

Receives the packet from the upper layer (e.g. IP)

Parameters
Packet*pointer to the packet received

References CSMA_CA_DATA, CSMA_CA_IDLE, data_q, dropPacket(), getQueueSize(), max_queue_size, state, and state_Idle().

Here is the call graph for this function:

◆ state_Backoff()

void CsmaCa::state_Backoff ( int  tx_time)
protectedvirtual

Backoff state

Parameters
intTransmission time sent on over-heared RTS

References backoff_delta, backoff_max, backoff_timer, CSMA_CA_BACKOFF, and updateState().

Referenced by cts_timer_fired(), and stateRxCTS().

Here is the call graph for this function:

◆ state_Idle()

void CsmaCa::state_Idle ( )
protectedvirtual

Protocol in IDLE state

References CSMA_CA_IDLE, data_q, extractDataPacket(), and updateState().

Referenced by ack_timer_fired(), backoff_timer_fired(), data_timer_fired(), Phy2MacEndTx(), recvFromUpperLayers(), stateRxACK(), stateRxData(), and stateTxCTS().

Here is the call graph for this function:

◆ state_Wait_ACK()

void CsmaCa::state_Wait_ACK ( )
protectedvirtual

Wait for an ACK after a data transmission

References ack_timer, ack_wait_val, CSMA_CA_WAIT_ACK, and updateState().

Referenced by Phy2MacEndTx().

Here is the call graph for this function:

◆ state_Wait_CTS()

void CsmaCa::state_Wait_CTS ( )
protectedvirtual

Waiting for CTS packet

References CSMA_CA_WAIT_CTS, cts_timer, cts_wait_val, and updateState().

Referenced by Phy2MacEndTx().

Here is the call graph for this function:

◆ state_Wait_Data()

void CsmaCa::state_Wait_Data ( )
protectedvirtual

Waiting for DATA packet

References CSMA_CA_WAIT_DATA, data_timer, data_wait_val, and updateState().

Referenced by Phy2MacEndTx().

Here is the call graph for this function:

◆ stateRxACK()

int CsmaCa::stateRxACK ( Packet *  ack)
protectedvirtual

Reception of an ACK packet

Parameters
hdr_ca_ACK*pointer to RTS header in packet
intsource MAC of packet
intdestination MAC of the packet

References ack_timer, CSMA_CA_WAIT_ACK, state, and state_Idle().

Referenced by Phy2MacEndRx().

Here is the call graph for this function:

◆ stateRxCTS()

int CsmaCa::stateRxCTS ( hdr_ca_CTS cts,
int  mac_src,
int  mac_dst 
)
protectedvirtual

Reception of an CTS packet

Parameters
hdr_ca_CTS*pointer to RTS header in packet
intsource MAC of packet
intdestination MAC of the packet

References CSMA_CA_IDLE, CSMA_CA_WAIT_CTS, cts_timer, hdr_ca_CTS::get_tx_time(), getState(), state_Backoff(), and stateTxData().

Referenced by Phy2MacEndRx().

Here is the call graph for this function:

◆ stateRxData()

int CsmaCa::stateRxData ( Packet *  p)
protectedvirtual

Transmit a data packet

Parameters
Packet*Pointer to data packet to be transmitted

References ack_mode, CSMA_CA_ACK_MODE, CSMA_CA_WAIT_DATA, data_timer, getState(), state_Idle(), and stateTxAck().

Referenced by Phy2MacEndRx().

Here is the call graph for this function:

◆ stateRxRTS()

int CsmaCa::stateRxRTS ( hdr_ca_RTS rts,
int  mac_src,
int  mac_dst 
)
protectedvirtual

Reception of an RTS packet

Parameters
hdr_ca_RTS*pointer to RTS header in packet
intsource MAC of packet
intdestination MAC of the packet

References actual_expected_tx_time, actual_mac_data_src, backoff_timer, CSMA_CA_BACKOFF, CSMA_CA_IDLE, hdr_ca_RTS::get_tx_time(), getState(), and stateTxCTS().

Referenced by Phy2MacEndRx().

Here is the call graph for this function:

◆ stateTxAck()

void CsmaCa::stateTxAck ( int  mac_dst)
protectedvirtual

Tranmission of an ACK

Parameters
intdestination MAC address

References buildPacket(), CSMA_CA_ACK, CSMA_CA_TX_ACK, Mac2PhyStartTx(), and updateState().

Referenced by stateRxData().

Here is the call graph for this function:

◆ stateTxCTS()

void CsmaCa::stateTxCTS ( )
protectedvirtual

Transmission of a CTS packet

References actual_mac_data_src, CSMA_CA_TX_CTS, state_Idle(), txCTS(), and updateState().

Referenced by stateRxRTS().

Here is the call graph for this function:

◆ stateTxData()

int CsmaCa::stateTxData ( )
protectedvirtual

Transmission of a DATA packet

References CSMA_CA_TX_DATA, txData(), and updateState().

Referenced by stateRxCTS().

Here is the call graph for this function:

◆ txAck()

int CsmaCa::txAck ( )
private

Actually transmit an ACK

◆ txCTS()

int CsmaCa::txCTS ( int  mac_dest)
private

Actually transmit a CTS packet

Parameters
intdestination MAC

References actual_expected_tx_time, buildPacket(), CSMA_CA_CTS, and Mac2PhyStartTx().

Referenced by stateTxCTS().

Here is the call graph for this function:

◆ txData()

int CsmaCa::txData ( )
private

Actually transmit a DATA packet

References actual_data_packet, and Mac2PhyStartTx().

Referenced by stateTxData().

Here is the call graph for this function:

◆ txRTS()

int CsmaCa::txRTS ( int  mac_dest)
private

Actually transmit a RTS packet

Parameters
intdestination MAC

References buildPacket(), computeTxTime(), CSMA_CA_RTS, and Mac2PhyStartTx().

Referenced by extractDataPacket().

Here is the call graph for this function:

◆ updateState()

void CsmaCa::updateState ( csma_ca_states_t  s)
inlineprotected

Update the state of the protocol

Parameters
csma_ca_state_tnew state

References previous_state, and state.

Referenced by state_Backoff(), state_Idle(), state_Wait_ACK(), state_Wait_CTS(), state_Wait_Data(), stateTxAck(), stateTxCTS(), and stateTxData().

Member Data Documentation

◆ ack_mode

ack_modes_t CsmaCa::ack_mode
private

ACK mode (configurable

Referenced by command(), Phy2MacEndTx(), and stateRxData().

◆ ack_pkt_dropped

int CsmaCa::ack_pkt_dropped
private

ACK packet dropped

Referenced by dropPacket().

◆ ack_timer

CsmaCaTimer CsmaCa::ack_timer
protected

ACK timer

Referenced by state_Wait_ACK(), and stateRxACK().

◆ ack_wait_val

int CsmaCa::ack_wait_val
private

Timer duration of ACK

Referenced by CsmaCa(), and state_Wait_ACK().

◆ actual_data_packet

Packet* CsmaCa::actual_data_packet
private

Pointer to DATA packet we are handling

Referenced by extractDataPacket(), Phy2MacEndTx(), and txData().

◆ actual_expected_tx_time

int CsmaCa::actual_expected_tx_time
private

Tx time of DATA packet we are handling

Referenced by stateRxRTS(), and txCTS().

◆ actual_mac_data_src

int CsmaCa::actual_mac_data_src
private

Source MAC of DATA packet we are handling

Referenced by stateRxRTS(), and stateTxCTS().

◆ backoff_delta

int CsmaCa::backoff_delta
private

Delta value (configurable) to be added to backoff

Referenced by CsmaCa(), and state_Backoff().

◆ backoff_max

int CsmaCa::backoff_max
private

Maximum value in range of backoff

Referenced by CsmaCa(), and state_Backoff().

◆ backoff_timer

CsmaCaTimer CsmaCa::backoff_timer
protected

Backoff timer

Referenced by state_Backoff(), and stateRxRTS().

◆ bitrate

int CsmaCa::bitrate
private

Bit rate adopted

Referenced by computeTxTime(), and CsmaCa().

◆ cts_pkt_dropped

int CsmaCa::cts_pkt_dropped
private

CTS packet dropped

Referenced by command(), and dropPacket().

◆ cts_timer

CsmaCaTimer CsmaCa::cts_timer
protected

CTS timer

Referenced by state_Wait_CTS(), and stateRxCTS().

◆ cts_wait_val

int CsmaCa::cts_wait_val
private

Timer duration of CTS

Referenced by CsmaCa(), and state_Wait_CTS().

◆ data_pkt_dropped

int CsmaCa::data_pkt_dropped
private

DATA packet dropped

Referenced by command(), and dropPacket().

◆ data_q

std::queue<Packet *> CsmaCa::data_q
private

Size of DATA packet

Referenced by extractDataPacket(), getQueueSize(), recvFromUpperLayers(), and state_Idle().

◆ data_size

int CsmaCa::data_size
private

Size of DATA packet

Referenced by computeTxTime(), and CsmaCa().

◆ data_timer

CsmaCaTimer CsmaCa::data_timer
protected

Data timer

Referenced by state_Wait_Data(), and stateRxData().

◆ data_wait_val

int CsmaCa::data_wait_val
private

Timer duration of DATA

Referenced by CsmaCa(), and state_Wait_Data().

◆ log_level

csma_ca_log_level_t CsmaCa::log_level
private

Current log level chosen for protocol

Referenced by getLogLevel().

◆ logfile

string CsmaCa::logfile
private

File name of log

Referenced by getLogFile(), and initializeLog().

◆ max_queue_size

int CsmaCa::max_queue_size
private

Maximum dimension of Queue

Referenced by CsmaCa(), and recvFromUpperLayers().

◆ n_cts_rx

int CsmaCa::n_cts_rx
private

CTS received

Referenced by command(), and Phy2MacEndRx().

◆ n_rts_rx

int CsmaCa::n_rts_rx
private

RTS received

Referenced by command(), and Phy2MacEndRx().

◆ outLog

std::ofstream CsmaCa::outLog
private

Stdout stream of log

Referenced by initializeLog(), and printonLog().

◆ previous_state

csma_ca_states_t CsmaCa::previous_state
private

Previous state of the protocol

Referenced by updateState().

◆ rts_pkt_dropped

int CsmaCa::rts_pkt_dropped
private

RTS packet dropped

Referenced by command(), and dropPacket().

◆ state

csma_ca_states_t CsmaCa::state
private

Current state of the protocol

Referenced by ack_timer_fired(), getState(), recvFromUpperLayers(), stateRxACK(), and updateState().


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