39#ifndef MMAC_UW_TLOHI_H
40#define MMAC_UW_TLOHI_H
54#define HDR_TLOHI(P) (hdr_tlohi::access(P))
56#define TLOHI_DROP_REASON_WRONG_STATE "WST"
57#define TLOHI_DROP_REASON_WRONG_RECEIVER "WRCV"
58#define TLOHI_DROP_REASON_UNKNOWN_TYPE "UPT"
59#define TLOHI_DROP_REASON_BUFFER_FULL "DBF"
205 virtual void expire(Event *e);
231 virtual void expire(Event *e);
269 virtual int command(
int argc,
const char *
const *argv);
354 virtual void txAck();
359 virtual void rxTone(Packet *p);
364 virtual void rxAck(Packet *p);
369 virtual void rxElse(Packet *p);
513 Packet::free(
Q.front());
557 return MMac::resetStats();
567 return (up_data_pkts_rx -
Q.size());
591 return up_data_pkts_rx;
680 static map<TLOHI_STATUS, string>
683 static map<TLOHI_REASON_STATUS, string>
Class that represents the timer that describe the time needed for the DATA Phy layer to receive packe...
virtual void expire(Event *e)
Event method called when the timer expire.
DataTimer(MMacTLOHI *m)
Constructor of the class.
Class that represents the T-LOHI MAC protocol for a node.
virtual double getCRduration()
Returns the duration of the Contention Round, where the nodes contend the channel.
virtual void initMphyIds()
Initializes the ID of the PHY layer for tone and Data.
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
double tone_data_delay
Not used anymore.
virtual void stateWaitXAck()
The node has just received a DATA packet intended for another node.
int curr_dest_addr
Current destination MAC address.
ofstream fout
Object that handle the output file for the state transition of the protocol.
virtual void exitBackoff()
Reset the timer for Backoff (i.e.
static map< TLOHI_STATUS, string > status_info
Map between the state and the textual description of the state.
int buffer_pkts
Buffer capacity in number of packets.
virtual int getTonePktsRx()
returns the number of tones received in the simulation
virtual void stateDataReceived(Packet *data_pkt)
A data packet is received.
virtual void resetStats()
Resets the variables related to the Statiscal computation.
queue< Packet * > Q
MAC queue used for packet scheduling.
int u_data_id
simulation-unique data packet ID
virtual void stateSleep()
Simulate the sleep modality of the PHY layer of the node, while the node is waiting for the DATA.
virtual void Phy2MacEndRx(Packet *p)
Method called when the Phy Layer finish to receive a Packet.
int last_data_id_rx
Last data packet transmitted ID.
virtual void stateWaitEndContention()
The nodes waits the end of Contention listening the channel for possible contenders.
virtual void setSessionDistance(double distance)
Set the distance between transmitter and receiver for this session.
double backoff_start_time
Timestamp of the backoff start time.
virtual void recvFromUpperLayers(Packet *p)
Receives the packet from the upper layer (e.g.
bool mphy_ids_initialized
Flag that indicates if the IDs of the PHY layers is stored.
virtual int getRemainingPkts()
returns the number of Packet remained in the queue at the end of the simulation
double wait_costant
Additive factor in the calculation of ACK timer.
Timer timer
timer for Contention Round
virtual void incrTonePktsTx()
Increments the number of the TONE sended.
virtual void incrCurrTxRounds()
Increments the number of times a packet has been transmitted.
virtual void stateTxAck()
The node transmit the ACK packet for a received DATA packet (in ACK_MODE modality)
virtual void rxAck(Packet *p)
Method that receive an ACK packet.
virtual int getUpLayersDataPktsRx()
TLOHI_MODE op_mode
Operational mode of the protocol.
virtual void refreshReason(TLOHI_REASON_STATUS reason)
Refresh the reason for the change of state of the protocol.
virtual void incrTonePktsRx()
Increments the number of the TONE received.
virtual void waitForUser()
Used for debug purposes (permits a step-by-step behaviour of the protocol.
static map< TLOHI_PKT_TYPE, string > pkt_type_info
Map between the pkt-type and the description of the packet.
static map< TLOHI_REASON_STATUS, string > reason_info
Map between the reason for state transitions and the description of this reason.
virtual int countContenders(double time)
Returns the number of Contenders in this Contention Round based on the number of tones received.
virtual void rxTone(Packet *p)
Method that receives a Tone.
virtual int getTonePktsTx()
returns the number of tones transmitted in the simulation
bool TxActive
Flag that indicates if a transmission is occuring.
int tone_pkts_rx
Number of tone received.
virtual void txTone()
Send the Tone to the tone PHY layer.
virtual void stateIdle()
IDLE state of the protocol.
virtual void initData()
Initializes the information of the protocol related to the data PHY layers (i.e.
double backoff_tuner
Multiplier factor in the calculation of the backoff.
int ACK_size
Size of the ACK packet in bytes.
int txsn
Transmitted data serial number.
bool print_transitions
Flat that indicates if the modality in which the protocol write in a file the state transitions is ac...
static bool initialized
Flag that indicates if the protocol is initialized.
bool has_buffer_queue
Flag that indicates whether the node has a buffer queue.
virtual void queuePop(bool flag)
Pop the first element of the data packets queue.
int curr_contenders
Number of contenders in current Contention Round.
virtual void Phy2MacEndTx(const Packet *p)
Method called when the PHY layer finish to transmit the packet.
int tone_pkts_tx
Number of tone transmitted.
TLOHI_ACK_MODE ack_mode
ACK mode of the protocol.
double DATA_listen_timeout
Time needed for the reception of a DATA packet.
virtual double computeTxTime(TLOHI_PKT_TYPE type)
Computes the Transmission Time of a Packet using a CrLayer Message to ask the PHY to perform this cal...
virtual void stateStartContention()
The node starts the Contention sending a Tone.
virtual void printStateInfo(double delay=0)
Initializes the protocol at the beginning of the simulation.
double session_distance
Distance between transmitter and receiver in this session.
static int u_pkt_id
simulation-unique packet ID
double CR_duration
Contention Round Duration.
virtual void initPkt(Packet *p, TLOHI_PKT_TYPE pkt_type)
Init the packet with the MAC address of the receiver and the sender, the size of the packet and the t...
virtual void checkPhyInit()
Checks if the PHY layers (for DATA and TONE) are initialized.
virtual int crLayCommand(ClMessage *m)
Cross-Layer messages interpreter.
virtual void txData()
Send a DATA packet to the data PHY layer.
virtual void stateTxData()
The node has won the CR.
virtual void checkDataPhy()
Checks if the PHY layer for Data is active.
TLOHI_REASON_STATUS last_reason
Last reason for state transition of the protocol.
double max_prop_delay
Maximum propagation delay in the network.
virtual void stateWaitCR()
Set the duration of the timer of the duration of the Contention Round.
int max_tx_rounds
Maximum transmission round for one packet.
bool backoff_pending
Flag that indicates if a backoff timer is pending.
TLOHI_STATUS prev_state
Previous state of the protocol.
virtual void stateBackoff()
The node is in Backoff state.
virtual void incrCurrTxTries()
Increments the number of tries for the transmission of a packet.
virtual void stateWaitAck()
The node has just sent a DATA packet.
TLOHI_STATUS curr_state
Current state of the protocol.
int data_phy_id
ID of the DATA PHY layer.
virtual void refreshState(TLOHI_STATUS state)
Refresh the state of the protocol.
int curr_tx_rounds
Number of current transmission round.
string tcl_modulation
Type of modulation adopted for data PHY layer.
Packet * curr_data_pkt
Pointer to the current data packet.
int max_payload
Maximum Data payload dimension in number of bytes.
int tone_phy_id
ID of the tone PHY layer.
MMacTLOHI()
Constructor of the class.
virtual void initInfo()
Initializes the map between the protocol states and the textual description of these states.
double sleep_timeout
Duration of the sleep phase for the PHY layer.
double recontend_time
Time needed for the recontention.
int HDR_size
Dimension of the header added by T-LOHI in bytes.
virtual void rxElse(Packet *p)
Receives other types of packets.
virtual void txAck()
Send a ACK packet of the data PHY layer.
DataTimer data_phy_timer
Timer that describe the time needed to receive the packet (i.e.
virtual void stateRecontendWindow()
Calculate the duration of the RecontendWindow.
double backoff_duration
Duration of the backoff timer.
int curr_tx_tries
Number of current transmission tries.
virtual void stateCountContenders()
The node counts the contenders in the CR.
bool tone_transmitted
Flag that indicates if a tone has been transmitted.
virtual void resetSession()
Resets the variable related to the Session (i.e.
double ACK_timeout
Time needed for the reception of a ACK packet.
virtual void setDestAddr(int mac_addr)
Store the MAC address of the destination for this session.
double max_tx_tries
Maximum transmission tries for one packet.
int last_data_id_tx
Last data packet received ID.
bool session_active
Flag that indicates if a Session is active.
virtual void Phy2MacStartRx(const Packet *p)
Method called when the Phy Layer start to receive a Packet.
virtual void getBackoffTime()
Performs the calculation of the Backoff timer.
double backoff_remaining
Remaining time of the backoff (if the timer has been freezed)
virtual ~MMacTLOHI()
Destructor of the class.
Class that handles the timers in T-LOHI nodes.
virtual void expire(Event *e)
Event method called when the timer expire.
Timer(MMacTLOHI *m)
Constructor of the class.
Struct that defines the header of T-LOHI in the packets.
int data_sn
DATA packet sequence number.
double ts
packet timestamp, i.e., its generation time)
static int & offset()
Reference to the offset_ variable.
static struct hdr_tlohi * access(const Packet *p)
Method that permits to access to the header.
TLOHI_PKT_TYPE pkt_type
T-LOHI packet type.
static int offset_
Required by PacketManager Header.
packet_t orig_type
Original type of the packet (i.e.
int sn
sequence number of this packet
static const int prop_speed
typical sound speed in underwater scenario
TIMER_STATUS
Enumeration that indicates the possible state of the timers, namely: RUNNING, STOPPED or FREEZED.
TLOHI_ACK_MODE
Enumeration that indicates the possible type of ACK MODE, namely: ACK_MODE or NO_ACK_MODE.
TLOHI_PKT_TYPE
Enumeration that indicates the possibile type of packets in T-LOHI MAC protocol.
TLOHI_STATUS
Enumeration that indicates the possible state of T-LOHI MAC.
@ STATE_WAIT_END_CONTENTION
TLOHI_MODE
Enumeration that indicates the possible modality of T-LOHI protocol, namely: CONSERVATIVE_UNSYNC_MODE...
@ CONSERVATIVE_UNSYNC_MODE
TLOHI_REASON_STATUS
Enumeration that indicates the possibile reason for the change of state in T-LOHI MAC protocol.