DESERT 4.0.0
CsmaAloha Class Reference

#include <uw-csma-aloha.h>

Inheritance diagram for CsmaAloha:
Inheritance graph
Collaboration diagram for CsmaAloha:
Collaboration graph

Classes

class  AckTimer
 
class  AlohaTimer
 
class  BackOffTimer
 
class  ListenTimer
 

Public Member Functions

 CsmaAloha ()
 
virtual ~CsmaAloha ()=default
 
virtual int command (int argc, const char *const *argv) override
 

Protected Types

enum  CSMA_STATUS {
  CSMA_STATE_IDLE = 1 , CSMA_STATE_BACKOFF , CSMA_STATE_TX_DATA , CSMA_STATE_TX_ACK ,
  CSMA_STATE_WAIT_ACK , CSMA_STATE_DATA_RX , CSMA_STATE_ACK_RX , CSMA_STATE_NOT_SET ,
  CSMA_STATE_LISTEN , CSMA_STATE_CHK_ACK_TIMEOUT , CSMA_STATE_CHK_LISTEN_TIMEOUT , CSMA_STATE_CHK_BACKOFF_TIMEOUT ,
  CSMA_STATE_RX_IDLE , CSMA_STATE_RX_LISTEN , CSMA_STATE_RX_BACKOFF , CSMA_STATE_RX_WAIT_ACK ,
  CSMA_STATE_WRONG_PKT_RX
}
 
enum  CSMA_REASON_STATUS {
  CSMA_REASON_DATA_PENDING , CSMA_REASON_DATA_RX , CSMA_REASON_DATA_TX , CSMA_REASON_ACK_TX ,
  CSMA_REASON_ACK_RX , CSMA_REASON_BACKOFF_TIMEOUT , CSMA_REASON_ACK_TIMEOUT , CSMA_REASON_DATA_EMPTY ,
  CSMA_REASON_NOT_SET , CSMA_REASON_MAX_TX_TRIES , CSMA_REASON_BACKOFF_PENDING , CSMA_REASON_LISTEN ,
  CSMA_REASON_LISTEN_TIMEOUT , CSMA_REASON_LISTEN_PENDING , CSMA_REASON_START_RX , CSMA_REASON_PKT_NOT_FOR_ME ,
  CSMA_REASON_WAIT_ACK_PENDING , CSMA_REASON_PKT_ERROR
}
 
enum  CSMA_PKT_TYPE { CSMA_ACK_PKT = 1 , CSMA_DATA_PKT , CSMA_DATAMAX_PKT }
 
enum  CSMA_ACK_MODES { CSMA_ACK_MODE = 1 , CSMA_NO_ACK_MODE }
 
enum  CSMA_TIMER_STATUS { CSMA_IDLE = 1 , CSMA_RUNNING , CSMA_FROZEN , CSMA_EXPIRED }
 

Protected Member Functions

virtual void recvFromUpperLayers (Packet *p) override
 
virtual void Mac2PhyStartTx (Packet *p)
 
virtual void Phy2MacEndTx (const Packet *p) override
 
virtual void Phy2MacStartRx (const Packet *p) override
 
virtual void Phy2MacEndRx (Packet *p) override
 
virtual double computeTxTime (CSMA_PKT_TYPE type)
 
virtual void initPkt (Packet *p, CSMA_PKT_TYPE pkt_type, int dest_addr=0)
 
virtual double getBackoffTime ()
 
virtual void txData ()
 
virtual void txAck (int dest_addr)
 
virtual void stateIdle ()
 
virtual void stateRxIdle ()
 
virtual void stateTxData ()
 
virtual void stateTxAck (int dest_addr)
 
virtual void stateBackoff ()
 
virtual void stateRxBackoff ()
 
virtual void stateWaitAck ()
 
virtual void stateRxWaitAck ()
 
virtual void stateListen ()
 
virtual void stateRxListen ()
 
virtual void stateCheckListenExpired ()
 
virtual void stateCheckAckExpired ()
 
virtual void stateCheckBackoffExpired ()
 
virtual void stateRxData (Packet *p)
 
virtual void stateRxAck (Packet *p)
 
virtual void stateRxPacketNotForMe (Packet *p)
 
virtual void printStateInfo (double delay=0)
 
virtual void initInfo ()
 
virtual void refreshState (CSMA_STATUS state)
 
virtual void refreshReason (CSMA_REASON_STATUS reason)
 
virtual void exitBackoff ()
 
virtual void setSessionDistance (double distance)
 
virtual bool keepDataPkt (int serial_number)
 
virtual void incrCurrTxRounds ()
 
virtual void resetCurrTxRounds ()
 
virtual void updateRTT (double rtt)
 
virtual double getRTT () const
 
virtual void updateAckTimeout (double rtt)
 
virtual void updateLastDataIdRx (int id)
 
virtual void queuePop (bool flag=true)
 
virtual void resetSession ()
 
virtual int getRemainingPkts () override
 
virtual void incrUpperDataRx () override
 
virtual int getUpLayersDataPktsRx ()
 

Protected Attributes

int max_tx_tries
 
double backoff_tuner
 
double wait_costant
 
int max_payload
 
int HDR_size
 
int ACK_size
 
double ACK_timeout
 
int buffer_pkts
 
double alpha_
 
int max_backoff_counter
 
double listen_time
 
std::queue< Packet * > Q
 
std::queue< int > data_sn_queue
 
int u_data_id
 
int last_sent_data_id
 
bool TxActive
 
bool RxActive
 
bool session_active
 
bool print_transitions
 
bool has_buffer_queue
 
double start_tx_time
 
double srtt
 
double sumrtt
 
double sumrtt2
 
int rttsamples
 
int curr_tx_rounds
 
int last_data_id_rx
 
Packet * curr_data_pkt
 
double session_distance
 
AckTimer ack_timer
 
BackOffTimer backoff_timer
 
ListenTimer listen_timer
 
CSMA_REASON_STATUS last_reason
 
CSMA_STATUS curr_state
 
CSMA_STATUS prev_state
 
CSMA_STATUS prev_prev_state
 
CSMA_ACK_MODES ack_mode
 
ofstream fout
 

Static Protected Attributes

static const double prop_speed = 1500.0
 
static bool initialized = false
 
static int u_pkt_id
 
static map< CSMA_STATUS, string > status_info
 
static map< CSMA_REASON_STATUS, string > reason_info
 
static map< CSMA_PKT_TYPE, string > pkt_type_info
 

Detailed Description

Class that describes a CsmaAloha module

Member Enumeration Documentation

◆ CSMA_ACK_MODES

enum CsmaAloha::CSMA_ACK_MODES
protected
Enumerator
CSMA_ACK_MODE 
CSMA_NO_ACK_MODE 

◆ CSMA_PKT_TYPE

enum CsmaAloha::CSMA_PKT_TYPE
protected
Enumerator
CSMA_ACK_PKT 
CSMA_DATA_PKT 
CSMA_DATAMAX_PKT 

◆ CSMA_REASON_STATUS

Enumerator
CSMA_REASON_DATA_PENDING 
CSMA_REASON_DATA_RX 
CSMA_REASON_DATA_TX 
CSMA_REASON_ACK_TX 
CSMA_REASON_ACK_RX 
CSMA_REASON_BACKOFF_TIMEOUT 
CSMA_REASON_ACK_TIMEOUT 
CSMA_REASON_DATA_EMPTY 
CSMA_REASON_NOT_SET 
CSMA_REASON_MAX_TX_TRIES 
CSMA_REASON_BACKOFF_PENDING 
CSMA_REASON_LISTEN 
CSMA_REASON_LISTEN_TIMEOUT 
CSMA_REASON_LISTEN_PENDING 
CSMA_REASON_START_RX 
CSMA_REASON_PKT_NOT_FOR_ME 
CSMA_REASON_WAIT_ACK_PENDING 
CSMA_REASON_PKT_ERROR 

◆ CSMA_STATUS

enum CsmaAloha::CSMA_STATUS
protected
Enumerator
CSMA_STATE_IDLE 
CSMA_STATE_BACKOFF 
CSMA_STATE_TX_DATA 
CSMA_STATE_TX_ACK 
CSMA_STATE_WAIT_ACK 
CSMA_STATE_DATA_RX 
CSMA_STATE_ACK_RX 
CSMA_STATE_NOT_SET 
CSMA_STATE_LISTEN 
CSMA_STATE_CHK_ACK_TIMEOUT 
CSMA_STATE_CHK_LISTEN_TIMEOUT 
CSMA_STATE_CHK_BACKOFF_TIMEOUT 
CSMA_STATE_RX_IDLE 
CSMA_STATE_RX_LISTEN 
CSMA_STATE_RX_BACKOFF 
CSMA_STATE_RX_WAIT_ACK 
CSMA_STATE_WRONG_PKT_RX 

◆ CSMA_TIMER_STATUS

Enumerator
CSMA_IDLE 
CSMA_RUNNING 
CSMA_FROZEN 
CSMA_EXPIRED 

Constructor & Destructor Documentation

◆ CsmaAloha()

CsmaAloha::CsmaAloha ( )

Constructor of the CsmaAloha class

◆ ~CsmaAloha()

virtual CsmaAloha::~CsmaAloha ( )
virtualdefault

Destructor of the CsmaAloha class

Member Function Documentation

◆ command()

int CsmaAloha::command ( int  argc,
const char *const *  argv 
)
overridevirtual

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.

◆ computeTxTime()

double CsmaAloha::computeTxTime ( CSMA_PKT_TYPE  type)
protectedvirtual

Compute the time needed to transmit the packet (using a CrLayerMessage to ask the PHY to perform the computation)

Parameters
CMSA_PKT_TYPEType of the packet

◆ exitBackoff()

void CsmaAloha::exitBackoff ( )
protectedvirtual

Method called when the Backoff timer is expired

◆ getBackoffTime()

double CsmaAloha::getBackoffTime ( )
protectedvirtual

compute the BackOff time as backoff = backoff_tuner*random*2*ACK_timeout*2^(counter) where counter is a value incremented each time this method is called and backoff_tuner is a multiplier factor chosen by the user

◆ getRemainingPkts()

virtual int CsmaAloha::getRemainingPkts ( )
inlineoverrideprotectedvirtual

Return the number of packets not transmitted (remained in the protocol queue) at the end of the simulation

Returns
the size of the queue at the end of the simulation

References Q.

◆ getRTT()

virtual double CsmaAloha::getRTT ( ) const
inlineprotectedvirtual

get the value of RTT as mean of all the rttsamples

Returns
RTT value

References rttsamples, and sumrtt.

◆ getUpLayersDataPktsRx()

virtual int CsmaAloha::getUpLayersDataPktsRx ( )
inlineprotectedvirtual

◆ incrCurrTxRounds()

virtual void CsmaAloha::incrCurrTxRounds ( )
inlineprotectedvirtual

Increases the number of times a packet is re-transmitted

References curr_tx_rounds.

◆ incrUpperDataRx()

virtual void CsmaAloha::incrUpperDataRx ( )
inlineoverrideprotectedvirtual

Increase the number of Data packet Received from the Upper layers

◆ initInfo()

void CsmaAloha::initInfo ( )
protectedvirtual

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

◆ initPkt()

void CsmaAloha::initPkt ( Packet *  p,
CSMA_PKT_TYPE  pkt_type,
int  dest_addr = 0 
)
protectedvirtual

Init the packet with the MAC address of the receiver and the sender, the size of the packet and the type

Parameters
Packet*Pointer to a Packet to initialize
CSMA_PKT_TYPEType of the packet
intdestination address

◆ keepDataPkt()

bool CsmaAloha::keepDataPkt ( int  serial_number)
protectedvirtual

Checks if the data packet received is a double packet (using the serial number of the packet)

Parameters
intserial number of the received packet
Returns
true if the serial number of the last data pacekt received is greater than the serial number of the last data packet received. false otherwise

◆ Mac2PhyStartTx()

void CsmaAloha::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

◆ Phy2MacEndRx()

void CsmaAloha::Phy2MacEndRx ( Packet *  p)
overrideprotectedvirtual

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

◆ Phy2MacEndTx()

void CsmaAloha::Phy2MacEndTx ( const Packet *  p)
overrideprotectedvirtual

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

◆ Phy2MacStartRx()

void CsmaAloha::Phy2MacStartRx ( const Packet *  p)
overrideprotectedvirtual

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

◆ printStateInfo()

void CsmaAloha::printStateInfo ( double  delay = 0)
protectedvirtual

Prints in a file the textual information of the current state and the transitions reasons

Parameters
doubletime lapse from the call of the method and the effective write process in the file (setted to zero by default)

◆ queuePop()

virtual void CsmaAloha::queuePop ( bool  flag = true)
inlineprotectedvirtual

Pop the first element of the data packet queue

References data_sn_queue, and Q.

◆ recvFromUpperLayers()

void CsmaAloha::recvFromUpperLayers ( Packet *  p)
overrideprotectedvirtual

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

Parameters
Packet*pointer to the packet received

◆ refreshReason()

virtual void CsmaAloha::refreshReason ( CSMA_REASON_STATUS  reason)
inlineprotectedvirtual

Refresh the reason for the change of state

References last_reason.

◆ refreshState()

virtual void CsmaAloha::refreshState ( CSMA_STATUS  state)
inlineprotectedvirtual

Refresh the State of the protocol

References curr_state, prev_prev_state, and prev_state.

◆ resetCurrTxRounds()

virtual void CsmaAloha::resetCurrTxRounds ( )
inlineprotectedvirtual

Reset the number of times a data pacekt is re-transmitted

References curr_tx_rounds.

◆ resetSession()

void CsmaAloha::resetSession ( )
protectedvirtual

Resets the current session (e.g. the session distance)

◆ setSessionDistance()

virtual void CsmaAloha::setSessionDistance ( double  distance)
inlineprotectedvirtual

Set the distance between the sender and the receiver

Parameters
doubleDistance between the sender and the receiver

References session_distance.

◆ stateBackoff()

void CsmaAloha::stateBackoff ( )
protectedvirtual

BackOff STATE. An ACK packet is lost. A backoff timer is set up. When the timer expire the protocol will re-send the data packet

◆ stateCheckAckExpired()

void CsmaAloha::stateCheckAckExpired ( )
protectedvirtual

Checks if the ACK reception timer is expired

◆ stateCheckBackoffExpired()

void CsmaAloha::stateCheckBackoffExpired ( )
protectedvirtual

Checks if the Backoff period is expired

◆ stateCheckListenExpired()

void CsmaAloha::stateCheckListenExpired ( )
protectedvirtual

Checks if the Listen period is expired

◆ stateIdle()

void CsmaAloha::stateIdle ( )
protectedvirtual

IDLE state. Each variable is resetted

◆ stateListen()

void CsmaAloha::stateListen ( )
protectedvirtual

State in which the node is listening the channel

◆ stateRxAck()

void CsmaAloha::stateRxAck ( Packet *  p)
protectedvirtual

state in which an ACK packet is received

◆ stateRxBackoff()

void CsmaAloha::stateRxBackoff ( )
protectedvirtual

State in which a reception is occurring while the protocol is in the backoff state

◆ stateRxData()

void CsmaAloha::stateRxData ( Packet *  p)
protectedvirtual

State in which a DATA packet is received

◆ stateRxIdle()

void CsmaAloha::stateRxIdle ( )
protectedvirtual

A reception is occuring while the protocol is in IDLE state

◆ stateRxListen()

void CsmaAloha::stateRxListen ( )
protectedvirtual

State in which a reception is occuring while the node is listening the channel

◆ stateRxPacketNotForMe()

void CsmaAloha::stateRxPacketNotForMe ( Packet *  p)
protectedvirtual

state in which a wrong Packet is received

◆ stateRxWaitAck()

void CsmaAloha::stateRxWaitAck ( )
protectedvirtual

State in which a reception is occuring while the node is waiting an ACK

◆ stateTxAck()

void CsmaAloha::stateTxAck ( int  dest_addr)
protectedvirtual

State in which the protocol set-up the ACK packet to transmit

Parameters
intMAC address of the destination of the ACK packet

◆ stateTxData()

void CsmaAloha::stateTxData ( )
protectedvirtual

State in which the protocol allows the node to transmit a data packet

◆ stateWaitAck()

void CsmaAloha::stateWaitAck ( )
protectedvirtual

State in which a DATA packet is sent. The time-out for receiving a ACK is set-up

◆ txAck()

void CsmaAloha::txAck ( int  dest_addr)
protectedvirtual

Transmits the ACK packet (calling Mac2PhyStartTx) and increment the counter of transmitted ACK packets

Parameters
inMAC address of the destination of ACK packet

◆ txData()

void CsmaAloha::txData ( )
protectedvirtual

Transmits the DATA packet (calling Mac2PhyStartTx) and increment the counter of transmitted data packets

◆ updateAckTimeout()

void CsmaAloha::updateAckTimeout ( double  rtt)
protectedvirtual

Updates the AckTimeout calling getRTT, where the ACK timeout is computed as srtt/rttsamples using the smooth RTT

See also
updateRTT
Parameters
doubleRTT value

◆ updateLastDataIdRx()

virtual void CsmaAloha::updateLastDataIdRx ( int  id)
inlineprotectedvirtual

Updates the ID of the last DATA packet received

References last_data_id_rx.

◆ updateRTT()

void CsmaAloha::updateRTT ( double  rtt)
protectedvirtual

Update the RTT increasing the number of RTT samples and calculating the smoothed RTT using the formula srtt = alpha*srtt + (1-alpha) * curr_rtt where alpha is a value chosen by the user

Parameters
doublecurrent value of RTT

Member Data Documentation

◆ ack_mode

CSMA_ACK_MODES CsmaAloha::ack_mode
protected

Variable that indicates if the protocol is in ACK or NO_ACK mode

◆ ACK_size

int CsmaAloha::ACK_size
protected

Size of the ACK message

◆ ACK_timeout

double CsmaAloha::ACK_timeout
protected

Duration of the ACK waiting time

◆ ack_timer

AckTimer CsmaAloha::ack_timer
protected

Object that represents the ack timer

◆ alpha_

double CsmaAloha::alpha_
protected

smooth factor in the calculation of the RTT

◆ backoff_timer

BackOffTimer CsmaAloha::backoff_timer
protected

Object that represents the backoff timer

◆ backoff_tuner

double CsmaAloha::backoff_tuner
protected

Multiplier factor in the calculation of the backoff

◆ buffer_pkts

int CsmaAloha::buffer_pkts
protected

Length of the data buffer in number of packets

◆ curr_data_pkt

Packet* CsmaAloha::curr_data_pkt
protected

Pointer to the current data packet

◆ curr_state

CSMA_STATUS CsmaAloha::curr_state
protected

Current state of the protocol

Referenced by refreshState().

◆ curr_tx_rounds

int CsmaAloha::curr_tx_rounds
protected

Number of current transmission of the same packet

Referenced by incrCurrTxRounds(), and resetCurrTxRounds().

◆ data_sn_queue

std::queue<int> CsmaAloha::data_sn_queue
protected

Queue of the sequence number of the packets

Referenced by queuePop().

◆ fout

ofstream CsmaAloha::fout
protected

Object that handles the output file where the protocol writes the state transistions

◆ has_buffer_queue

bool CsmaAloha::has_buffer_queue
protected

flag that indicates if a node has a buffer where store DATA packets

◆ HDR_size

int CsmaAloha::HDR_size
protected

Size (in bytes) of the header added by the protocol

◆ initialized

bool CsmaAloha::initialized = false
staticprotected

true if the protocol is initialized

◆ last_data_id_rx

int CsmaAloha::last_data_id_rx
protected

ID of the last DATA packet received

Referenced by updateLastDataIdRx().

◆ last_reason

CSMA_REASON_STATUS CsmaAloha::last_reason
protected

Reason for the state transitions

Referenced by refreshReason().

◆ last_sent_data_id

int CsmaAloha::last_sent_data_id
protected

ID of the last sent packet

◆ listen_time

double CsmaAloha::listen_time
protected

Time in which the node sense the channel

◆ listen_timer

ListenTimer CsmaAloha::listen_timer
protected

Object that represents the listen timer

◆ max_backoff_counter

int CsmaAloha::max_backoff_counter
protected

Number of times a backoff is calculated

◆ max_payload

int CsmaAloha::max_payload
protected

Maximum dimension of the data payload in bytes

◆ max_tx_tries

int CsmaAloha::max_tx_tries
protected

Maximum number of transmissions for one packet

◆ pkt_type_info

map< CsmaAloha::CSMA_PKT_TYPE, string > CsmaAloha::pkt_type_info
staticprotected

Textual description of the packet type

◆ prev_prev_state

CSMA_STATUS CsmaAloha::prev_prev_state
protected

Previous previous state of the protocol

Referenced by refreshState().

◆ prev_state

CSMA_STATUS CsmaAloha::prev_state
protected

Previous state of the protocol

Referenced by refreshState().

◆ print_transitions

bool CsmaAloha::print_transitions
protected

flag that indicates if the protocol is enabled to print its state transitions on a file

◆ prop_speed

const double CsmaAloha::prop_speed = 1500.0
staticprotected

Typical sound propagation speed in underwater enviroment Variable that represent the status of the protocol machine state

◆ Q

std::queue<Packet *> CsmaAloha::Q
protected

Packet queue

Referenced by getRemainingPkts(), and queuePop().

◆ reason_info

map< CsmaAloha::CSMA_REASON_STATUS, string > CsmaAloha::reason_info
staticprotected

Textual description of the protocol reason for the change of the state

◆ rttsamples

int CsmaAloha::rttsamples
protected

num of RTT samples

Referenced by getRTT().

◆ RxActive

bool CsmaAloha::RxActive
protected

flag that indicates if a reception is occuring

◆ session_active

bool CsmaAloha::session_active
protected

flag that indicates if a session (i.e. a transmission/reception activity is occuring) between two nodes

◆ session_distance

double CsmaAloha::session_distance
protected

Distance between sender and the receiver involved in the current session

Referenced by setSessionDistance().

◆ srtt

double CsmaAloha::srtt
protected

Smoothed Round Trip Time, calculated as for TCP

◆ start_tx_time

double CsmaAloha::start_tx_time
protected

timestamp in which the node stars to transmit a packet

◆ status_info

map< CsmaAloha::CSMA_STATUS, string > CsmaAloha::status_info
staticprotected

Textual description of the protocol states

◆ sumrtt

double CsmaAloha::sumrtt
protected

sum of RTT samples

Referenced by getRTT().

◆ sumrtt2

double CsmaAloha::sumrtt2
protected

sum of (RTT^2)

◆ TxActive

bool CsmaAloha::TxActive
protected

flag that indicates if a transmission is occuring

◆ u_data_id

int CsmaAloha::u_data_id
protected

DATA packete ID

◆ u_pkt_id

int CsmaAloha::u_pkt_id
staticprotected

simulation-unique packet ID

◆ wait_costant

double CsmaAloha::wait_costant
protected

Adding factor in the calculation of the listen time


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