52#define CSMA_DROP_REASON_WRONG_STATE \
55#define CSMA_DROP_REASON_WRONG_RECEIVER \
57#define CSMA_DROP_REASON_UNKNOWN_TYPE \
59#define CSMA_DROP_REASON_BUFFER_FULL \
61#define CSMA_DROP_REASON_ERROR "ERR"
89 virtual int command(
int argc,
const char *
const *argv);
371 virtual void expire(Event *e);
401 virtual void expire(Event *e);
433 virtual void expire(Event *e);
496 virtual void txAck(
int dest_addr);
685 Packet::free(
Q.front());
711 return (up_data_pkts_rx -
Q.size());
726 return up_data_pkts_rx;
745 std::queue<Packet *>
Q;
797 static map<CSMA_STATUS, string>
799 static map<CSMA_REASON_STATUS, string>
802 static map<CSMA_PKT_TYPE, string>
Class used to handle the timer for waiting the ACK.
AckTimer(CsmaAloha *m)
Conscructor of AckTimer class.
virtual ~AckTimer()
Destructor of AckTimer class.
virtual void expire(Event *e)
Method called when the timer expire.
Class that describes the timers in the node.
virtual void unFreeze()
unFreezes is used to resume the timer starting from the point where it was freezed
virtual void schedule(double val)
schedule a timer
void incrCounter()
Increments the counter of the timer.
virtual void stop()
stops the timer
CsmaAloha *CSMA_TIMER_STATUS timer_status
< Pointer to an object of type CsmaAloha
double left_duration
Left duration of the timer.
bool isFrozen()
Checks if the timer is FROZEN.
double getDuration()
Returns the left duration of the timer.
double start_time
Start Time of the timer.
bool isActive()
Checks if the timer is ACTIVE.
int getCounter()
Returns the counter of the timer.
int counter
counter of the timer
void resetCounter()
Resets the counter of the timer.
virtual void freeze()
Freezes the timer.
AlohaTimer(CsmaAloha *m)
Constructor of the AlohaTimer class.
bool isRunning()
checks if the timer is RUNNING
bool isIdle()
checks if the timer is IDLE
virtual ~AlohaTimer()
Destructor of the AlohaTimer class.
bool isExpired()
Checks if the timer is EXPIRED.
Class used to handle the timer of the backoff period.
virtual void expire(Event *e)
Method called when the timer expire.
virtual ~BackOffTimer()
Destructor of DataTimer class.
BackOffTimer(CsmaAloha *m)
Conscructor of BackOffTimer class.
Class used to handle the Listen Timer.
ListenTimer(CsmaAloha *m)
Conscructor of ListenTimer class.
virtual ~ListenTimer()
Destructor of AckTimer class.
virtual void expire(Event *e)
Method called when the timer expire.
Class that describes a CsmaAloha module.
int rttsamples
num of RTT samples
double ACK_timeout
Duration of the ACK waiting time.
int ACK_size
Size of the ACK message.
virtual void stateRxWaitAck()
State in which a reception is occuring while the node is waiting an ACK.
virtual void stateIdle()
IDLE state.
std::queue< int > data_sn_queue
Queue of the sequence number of the packets.
virtual void txAck(int dest_addr)
Transmits the ACK packet (calling Mac2PhyStartTx) and increment the counter of transmitted ACK packet...
virtual void stateTxData()
State in which the protocol allows the node to transmit a data packet.
virtual void setSessionDistance(double distance)
Set the distance between the sender and the receiver.
virtual void stateCheckAckExpired()
Checks if the ACK reception timer is expired.
virtual void refreshState(CSMA_STATUS state)
Refresh the State of the protocol.
int buffer_pkts
Length of the data buffer in number of packets.
virtual void queuePop(bool flag=true)
Pop the first element of the data packet queue.
virtual void waitForUser()
Used for debug purposes.
virtual void initInfo()
Initializes the protocol at the beginning of the simulation.
virtual void updateRTT(double rtt)
Update the RTT increasing the number of RTT samples and calculating the smoothed RTT using the formul...
virtual void updateAckTimeout(double rtt)
Updates the AckTimeout calling getRTT, where the ACK timeout is computed as srtt/rttsamples using the...
std::queue< Packet * > Q
Packet queue.
int last_sent_data_id
ID of the last sent packet.
CSMA_STATUS prev_prev_state
Previous previous state of the protocol.
virtual void stateRxAck(Packet *p)
state in which an ACK packet is received
virtual void resetSession()
Resets the current session (e.g.
virtual int getUpLayersDataPktsRx()
Packet * curr_data_pkt
Pointer to the current data packet.
@ CSMA_STATE_CHK_ACK_TIMEOUT
@ CSMA_STATE_CHK_LISTEN_TIMEOUT
@ CSMA_STATE_WRONG_PKT_RX
@ CSMA_STATE_CHK_BACKOFF_TIMEOUT
double alpha_
smooth factor in the calculation of the RTT
bool RxActive
flag that indicates if a reception is occuring
@ CSMA_REASON_WAIT_ACK_PENDING
@ CSMA_REASON_DATA_PENDING
@ CSMA_REASON_BACKOFF_TIMEOUT
@ CSMA_REASON_LISTEN_TIMEOUT
@ CSMA_REASON_PKT_NOT_FOR_ME
@ CSMA_REASON_BACKOFF_PENDING
@ CSMA_REASON_MAX_TX_TRIES
@ CSMA_REASON_ACK_TIMEOUT
@ CSMA_REASON_LISTEN_PENDING
virtual void initPkt(Packet *p, CSMA_PKT_TYPE pkt_type, int dest_addr=0)
Init the packet with the MAC address of the receiver and the sender, the size of the packet and the t...
static map< CSMA_PKT_TYPE, string > pkt_type_info
Textual description of the packet type.
virtual ~CsmaAloha()
Destructor of the CsmaAloha class.
virtual void stateWaitAck()
State in which a DATA packet is sent.
virtual int getRemainingPkts()
Return the number of packets not transmitted (remained in the protocol queue) at the end of the simul...
static const double prop_speed
Typical sound propagation speed in underwater enviroment.
virtual void stateRxData(Packet *p)
State in which a DATA packet is received.
bool has_buffer_queue
flag that indicates if a node has a buffer where store DATA packets
virtual void stateCheckListenExpired()
Checks if the Listen period is expired.
int last_data_id_rx
ID of the last DATA packet received.
virtual double getRTT()
get the value of RTT as mean of all the rttsamples
static int u_pkt_id
simulation-unique packet ID
virtual void stateRxListen()
State in which a reception is occuring while the node is listening the channel.
virtual void refreshReason(CSMA_REASON_STATUS reason)
Refresh the reason for the change of state.
CSMA_ACK_MODES ack_mode
Variable that indicates if the protocol is in ACK or NO_ACK mode.
double wait_costant
Adding factor in the calculation of the listen time.
virtual void incrCurrTxRounds()
Increases the number of times a packet is re-transmitted.
virtual void stateRxPacketNotForMe(Packet *p)
state in which a wrong Packet is received
virtual void Phy2MacEndRx(Packet *p)
Method called when the Phy Layer finish to receive a Packet.
double session_distance
Distance between sender and the receiver involved in the current session.
CsmaAloha()
Constructor of the CsmaAloha class.
virtual void txData()
Transmits the DATA packet (calling Mac2PhyStartTx) and increment the counter of transmitted data pack...
static map< CSMA_REASON_STATUS, string > reason_info
Textual description of the protocol reason for the change of the state.
int max_payload
Maximum dimension of the data payload in bytes.
BackOffTimer backoff_timer
Object that represents the backoff timer.
virtual double getBackoffTime()
compute the BackOff time as backoff = backoff_tuner*random*2*ACK_timeout*2^(counter) where counter is...
virtual void printStateInfo(double delay=0)
Prints in a file the textual information of the current state and the transitions reasons.
int HDR_size
Size (in bytes) of the header added by the protocol.
double sumrtt
sum of RTT samples
bool print_transitions
flag that indicates if the protocol is enabled to print its state transitions on a file
virtual double computeTxTime(CSMA_PKT_TYPE type)
Compute the time needed to transmit the packet (using a CrLayerMessage to ask the PHY to perform the ...
static bool initialized
true if the protocol is initialized
virtual int crLayCommand(ClMessage *m)
Cross-Layer messages interpreter.
virtual void incrUpperDataRx()
Increase the number of Data packet Received from the Upper layers.
virtual void Phy2MacEndTx(const Packet *p)
Method called when the PHY layer finish to transmit the packet.
AckTimer ack_timer
Object that represents the ack timer.
int max_backoff_counter
Number of times a backoff is calculated.
virtual void recvFromUpperLayers(Packet *p)
Receives the packet from the upper layer (e.g.
int u_data_id
DATA packete ID.
virtual void updateLastDataIdRx(int id)
Updates the ID of the last DATA packet received.
virtual void stateBackoff()
BackOff STATE.
bool TxActive
flag that indicates if a transmission is occuring
virtual void exitBackoff()
Method called when the Backoff timer is expired.
virtual void Phy2MacStartRx(const Packet *p)
Method called when the Phy Layer start to receive a Packet.
virtual void stateRxBackoff()
State in which a reception is occurring while the protocol is in the backoff state.
bool session_active
flag that indicates if a session (i.e.
ListenTimer listen_timer
Object that represents the listen timer.
CSMA_STATUS prev_state
Previous state of the protocol.
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
virtual void stateListen()
State in which the node is listening the channel.
static map< CSMA_STATUS, string > status_info
Textual description of the protocol states.
double srtt
Smoothed Round Trip Time, calculated as for TCP.
int curr_tx_rounds
Number of current transmission of the same packet.
CSMA_REASON_STATUS last_reason
Reason for the state transitions.
double start_tx_time
timestamp in which the node stars to transmit a packet
virtual void resetCurrTxRounds()
Reset the number of times a data pacekt is re-transmitted.
double sumrtt2
sum of (RTT^2)
virtual void Mac2PhyStartTx(Packet *p)
Pass the packet to the PHY layer.
virtual bool keepDataPkt(int serial_number)
Checks if the data packet received is a double packet (using the serial number of the packet)
double backoff_tuner
Multiplier factor in the calculation of the backoff.
CSMA_STATUS curr_state
Current state of the protocol.
int max_tx_tries
Maximum number of transmissions for one packet.
virtual void stateCheckBackoffExpired()
Checks if the Backoff period is expired.
ofstream fout
Object that handles the output file where the protocol writes the state transistions.
virtual void stateRxIdle()
A reception is occuring while the protocol is in IDLE state.
double listen_time
Time in which the node sense the channel.
virtual void stateTxAck(int dest_addr)
State in which the protocol set-up the ACK packet to transmit.
std::pair< int, int > counter
counter of collisions