63 : TclClass(
"Module/UW/OFDM_ALOHA")
80 if (module->uwofdmaloha_debug)
81 cout << NOW <<
" UWOFDMAloha (" <<
module->addr
82 << ") timer expire() current state = "
83 << module->status_info[module->curr_state]
84 << "; ACK not received, next state =
"
85 << module->status_info[UWOFDMALOHA_STATE_BACKOFF] << endl;
87 module->refreshReason(UWOFDMALOHA_REASON_ACK_TIMEOUT);
88 module->stateBackoff();
92 if (module->uwofdmaloha_debug)
94 << ")::AckTimer::expired()
" << endl;
98void UWOFDMAloha::BackOffTimer::expire(Event *e)
100 timer_status = UWOFDMALOHA_EXPIRED;
101 if (module->curr_state == UWOFDMALOHA_STATE_BACKOFF)
104 if (module->uwofdmaloha_debug)
106 << ") timer
expire() current state = "
108 << "; backoff expired, next state = "
117 if (module->uwofdmaloha_debug)
118 cout << NOW <<
" UWOFDMAloha (" <<
module->addr
119 << ")::BackOffTimer::expired() " << endl;
154 mac2phy_delay_ = 1e-19;
156 bind(
"HDR_size_", (
int *)&
HDR_size);
157 bind(
"ACK_size_", (
int *)&
ACK_size);
163 bind(
"alpha_", (
double *)&
alpha_);
167 bind(
"MAC_addr_", (
int *)&addr);
183 Tcl &tcl = Tcl::instance();
186 if (strcasecmp(argv[1],
"setAckMode") == 0)
191 else if (strcasecmp(argv[1],
"setNoAckMode") == 0)
196 else if (strcasecmp(argv[1],
"setDisturbanceNode") == 0)
201 else if (strcasecmp(argv[1],
"initialize") == 0)
206 fout.open(
"/tmp/OFDMALOHAstateTransitions.txt", ios_base::app);
209 else if (strcasecmp(argv[1],
"printTransitions") == 0)
214 else if (strcasecmp(argv[1],
"getQueueSize") == 0)
219 else if (strcasecmp(argv[1],
"getUpLayersDataRx") == 0)
224 else if (strcasecmp(argv[1],
"getAckPktsTx") == 0)
226 tcl.resultf(
"%d", getAckPktsTx());
232 if (strcasecmp(argv[1],
"setMacAddr") == 0)
234 addr = atoi(argv[2]);
236 cout <<
"OFDM Aloha MAC address of current node is " << addr << endl;
239 if (strcasecmp(argv[1],
"addInvalidCarriers") == 0)
243 cout <<
"Carrier " << atoi(argv[2]) <<
" not usable " << endl;
249 if (strcasecmp(argv[1],
"init_macofdm_node") == 0)
255 return MMac::command(argc, argv);
265 system(
"rm -f /tmp/OFDMALOHAstateTransitions.txt");
266 system(
"touch /tmp/OFDMALOHAstateTransitions.txt");
282 "Check Backoff timeout state";
294 "DATA dropped due to max tx rounds";
330 sumrtt2 += curr_rtt * curr_rtt;
340 cout << NOW <<
" UWOFDMAloha (" << addr
341 <<
")::updateAckTimeout() curr ACK_timeout = " <<
ACK_timeout
353 incrTotalBackoffTimes();
354 double random = RNG::defaultrng()->uniform_double();
361 double backoff_duration =
364 backoffSumDuration(backoff_duration);
368 cout << NOW <<
" UWOFDMAloha (" << addr
369 <<
")::getBackoffTime() backoff time = " << backoff_duration
372 return backoff_duration;
379 Packet *temp_data_pkt;
380 map<pktSeqNum, Packet *>::iterator it_p;
387 temp_data_pkt = ((*it_p).second)->copy();
389 hdr_cmn *ch = HDR_CMN(temp_data_pkt);
394 temp_data_pkt = Packet::alloc();
395 hdr_cmn *ch = HDR_CMN(temp_data_pkt);
401 temp_data_pkt = Packet::alloc();
402 hdr_cmn *ch = HDR_CMN(temp_data_pkt);
405 duration = Mac2PhyTxDuration(temp_data_pkt);
406 Packet::free(temp_data_pkt);
413 std::cout << NOW <<
" UWOFDMAloha (" << addr
414 <<
")::recvFromUpperLayers()";
424 cout << NOW <<
" UWOFDMAloha (" << addr
425 <<
")::recvFromUpperLayers() current status "
429 cout << NOW <<
" UWOFDMAloha (" << addr
430 <<
")::recvFromUpperLayers() recv queue size: " <<
pkt_rcv_queue.size() << endl;
441 incrDiscardedPktsTx();
448 hdr_cmn *ch = hdr_cmn::access(p);
449 hdr_mac *mach = HDR_MAC(p);
450 hdr_MPhy *ph = HDR_MPHY(p);
460 std::cout << NOW <<
" UWOFDMAloha (" << addr
461 <<
")::initPkt(), pkt destination " << dest_addr << std::endl;
464 for (std::size_t i = 0; i <
mac_carVec.size(); ++i)
472 int curr_size = ch->size();
481 mach->ftype() = MF_BEACON;
483 mach->ftype() = MF_DATA;
492 mach->macSA() = addr;
493 mach->macDA() = dest_addr;
499 std::cout << NOW <<
" UWOFDMAloha (" << addr
500 <<
")::initPkt() Packet SEQ NUM " <<
getPktSeqNum(p) <<
" initialized like:" << std::endl;
508 cout << NOW <<
" UWOFDMAloha (" << addr
509 <<
")::Mac2PhyStartTx() start tx packet" << endl;
513 hdr_mac *mach = HDR_MAC(p);
514 MMac::Mac2PhyStartTx(p);
517 std::cout << NOW <<
" UWOFDMAloha (" << addr
518 <<
")::Mac2PhyStartTx() Sent down packet SEQ NUM "
524 hdr_mac *mach = HDR_MAC(p);
527 cout << NOW <<
" UWOFDMAloha (" << addr
528 <<
")::Phy2MacEndTx() end tx packet for node " << mach->macDA() << endl;
540 cout << NOW <<
" UWOFDMAloha (" << addr
541 <<
")::Phy2MacEndTx() DATA sent,from "
551 cout << NOW <<
" UWOFDMAloha (" << addr
552 <<
")::Phy2MacEndTx() DATA sent, from "
566 cout << NOW <<
" UWOFDMAloha (" << addr
567 <<
")::Phy2MacEndTx() ack sent, from "
576 cout << NOW <<
" UWOFDMAloha (" << addr
577 <<
")::Phy2MacEndTx() logical error, current state = "
589 hdr_mac *mach = HDR_MAC(p);
590 Packet *temp_packet = p->copy();
593 cout << NOW <<
" UWOFDMAloha (" << addr <<
")::Phy2MacStartRx() rx Packet SEQ NUM "
594 <<
getPktSeqNum(temp_packet) <<
" from " << mach->macSA() << endl;
599 hdr_cmn *ch = HDR_CMN(p);
600 packet_t rx_pkt_type = ch->ptype();
601 hdr_mac *mach = HDR_MAC(p);
602 MacFrameType frame_type = mach->ftype();
603 hdr_MPhy *ph = HDR_MPHY(p);
605 int source_mac = mach->macSA();
606 int dest_mac = mach->macDA();
608 double gen_time = ph->txtime;
609 double received_time = ph->rxtime;
610 double diff_time = received_time - gen_time;
617 cout << NOW <<
" UWOFDMAloha (" << addr <<
")::Phy2MacEndRx() "
619 <<
", received a pkt type = " << ch->ptype()
620 <<
", src addr = " << mach->macSA()
621 <<
" dest addr = " << mach->macDA()
622 <<
", estimated distance between nodes = " << distance <<
" m "
629 cout << NOW <<
" UWOFDMAloha (" << addr
630 <<
")::Phy2MacEndRx() dropping corrupted pkt " << endl;
639 if (dest_mac == addr || dest_mac == MAC_BROADCAST)
641 if (frame_type == MF_ACK)
648 cout << NOW <<
" UWOFDMAloha (" << addr
649 <<
")::Phy2MacEndRx() PKT NOT FOR ME 111 (wasn't waiting ACKS)" << endl;
655 cout << NOW <<
" UWOFDMAloha (" << addr
656 <<
")::Phy2MacEndRx() PKT NOT FOR ME 333 (wasn't waiting ACKS)" << endl;
664 cout << NOW <<
" UWOFDMAloha (" << addr
665 <<
")::Phy2MacEndRx() PKT NOT FOR ME 444 (Previous ACK)" << endl;
676 cout << NOW <<
" UWOFDMAloha (" << addr
677 <<
")::Phy2MacEndRx() going to stateRxData " << endl;
686 std::cout << NOW <<
" UWOFDMAloha (" << addr
687 <<
")::Phy2MacEndRx() NOT IN CONDITION TO RECEIVE FOR NOW " << endl;
695 if(frame_type != MF_RTS && frame_type != MF_CTS && frame_type != MF_ACK && frame_type != MF_DATA){
696 cerr << NOW <<
" UWSmartOFDM (" << addr <<
")::Phy2MacEndRx Unrecognized packet " << std::endl;
702 cout << NOW <<
" UWOFDMAloha (" << addr
703 <<
")::Phy2MacEndRx() PKT NOT FOR ME 222x " << endl;
722 cout << NOW <<
" UWOFDMAloha (" << addr
723 <<
")::txData sending SEQ NUM PACKET " <<
getPktSeqNum(data_pkt) << std::endl;
732 Packet *ack_pkt = Packet::alloc();
736 cout << NOW <<
" UWOFDMAloha (" << addr
737 <<
")::txAck sending ACK to " << dest_addr << std::endl;
748 cout << NOW <<
" UWOFDMAloha (" << addr <<
")::stateCheckAckExpired()"
751 map<pktSeqNum, AckTimer>::iterator it_a;
756 if (((*it_a).second).isActive())
761 else if (((*it_a).second).isExpired())
768 cerr << NOW <<
" UWOFDMAloha (" << addr
769 <<
")::stateCheckAckExpired() ack_timer logical error, current "
781 cout << NOW <<
" UWOFDMAloha (" << addr <<
")::stateCheckBackoffExpired()"
798 cerr << NOW <<
" UWOFDMAloha (" << addr
799 <<
")::stateCheckBackoffExpired() backoff_timer logical error, "
800 "current timer state = "
812 cout << NOW <<
" UWOFDMAloha (" << addr
813 <<
")::stateIdle() reception queue size = " <<
pkt_rcv_queue.size() << endl;
816 cout << NOW <<
" UWOFDMAloha (" << addr
817 <<
")::stateIdle() transmission queue size = " <<
mapPacket.size() << endl;
849 std::cout << NOW <<
" UWOFDMAloha (" << addr <<
")::stateBackoff() " << endl;
853 map<pktSeqNum, Packet *>::iterator it_p;
876 std::cout << NOW <<
" UWOFDMAloha (" << addr <<
")::stateTxData() " << endl;
880 map<pktSeqNum, Packet *>::iterator it_p;
890 std::cout <<
"carrier[" << i <<
"] = " << ofdmph->
carMod[i] << std::endl;
893 map<pktSeqNum, AckTimer>::iterator it_a;
901 ((*it_a).second).resetCounter();
914 ((*it_a).second).resetCounter();
932 cout << NOW <<
" UWOFDMAloha (" << addr
933 <<
")::statePreTxData() curr_tx_rounds "
948 map<pktSeqNum, AckTimer>::iterator it_a;
951 ((*it_a).second).stop();
955 cout << NOW <<
" UWOFDMAloha (" << addr <<
")::stateWaitAck() " << endl;
959 ((*it_a).second).incrCounter();
976 cout << NOW <<
" UWOFDMAloha (" << addr <<
")::stateTxAck() dest addr "
977 << dest_addr << endl;
991 hdr_mac *mach = HDR_MAC(data_pkt);
992 int dst_addr = mach->macSA();
994 hdr_cmn *ch = hdr_cmn::access(data_pkt);
1000 cout << NOW <<
" UWOFDMAloha (" << addr <<
")::stateRxData() SEQ NUM "
1001 <<
getPktSeqNum(data_pkt) <<
" from " << dst_addr << endl;
1011 map<pktSeqNum, AckTimer>::iterator it_a;
1014 ((*it_a).second).stop();
1017 cout << NOW <<
" UWOFDMAloha (" << addr <<
")::stateRxAck() " << endl;
1023 cout << NOW <<
" UWOFDMAloha (" << addr <<
")::stateRxAck() seq number " << seq_num << endl;
1028 cout << NOW <<
" UWOFDMAloha (" << addr <<
")::stateRxAck() refreshReason " << endl;
1032 cout << NOW <<
" UWOFDMAloha (" << addr <<
")::stateRxAck() erase from pkt queue" << endl;
1035 cout << NOW <<
" UWOFDMAloha (" << addr <<
")::stateRxAck() erase from ACK timer" << endl;
1039 cout << NOW <<
" UWOFDMAloha (" << addr <<
")::stateRxAck() Going back to Idle" << endl;
1046 cout << NOW <<
" UWOFDMAloha (" << addr <<
")::printStateInfo() "
1053 fout << left << setw(10) << NOW <<
" UWOFDMAloha (" << addr
1054 <<
")::printStateInfo() "
1058 <<
". Backoff duration = " << delay << endl;
1062 fout << left << setw(10) << NOW <<
" UWOFDMAloha (" << addr
1063 <<
")::printStateInfo() "
Class that describe the binding with tcl scripting language.
TclObject * create(int, const char *const *)
UWOFDMALOHAModuleClass()
Constructor of the class.
virtual void expire(Event *e)
What a node is going to do when a timer expire.
virtual void freeze()
It freezes or in another word, it stops the timer for some time.
void incrCounter()
Increment the timer counter.
bool isActive()
It tells whether the timer is active or not.
bool isExpired()
Tells whether the timer is expired or not.
bool isFrozen()
It tells whether the timer is in freeze mode or not.
virtual void schedule(double val)
Schedule the time, i.e., how long a timer is going to run.
double getDuration()
This methods provide the duration of a timer.
virtual void stop()
Stop the timer any way.
virtual void unFreeze()
It starts the timer from where it was stopped.
void resetCounter()
Reset the timer counter.
int getCounter()
It provides, how many times a timer ran.
UWOFDMAloha *UWOFDMALOHA_TIMER_STATUS timer_status
< Pointer of UWOFDMAloha module.
virtual ~UWOFDMAloha()
Destructor of UWOFDMAloha Class.
UWOFDMALOHA_REASON_STATUS last_reason
Enum variable which stores the last reason why a node changes its state.
static map< UWOFDMALOHA_PKT_TYPE, string > pkt_type_info
Container which stores all the packet type information of UWOFDMAloha.
void eraseItemFromPktQueue(int seq_num)
It erases the packet from the container.
virtual void resetCurrTxRounds()
If a node is going to transmit a new packet, it resets the tx counter.
Packet * curr_data_pkt
Pointer of the latest selected data packet.
int getPktSeqNum(Packet *p)
This method is used to get the sequence number from a packet.
@ UWOFDMALOHA_REASON_ACK_TX
@ UWOFDMALOHA_REASON_BACKOFF_TIMEOUT
@ UWOFDMALOHA_REASON_DATA_RX
@ UWOFDMALOHA_REASON_DATA_EMPTY
@ UWOFDMALOHA_REASON_ACK_TIMEOUT
@ UWOFDMALOHA_REASON_ACK_RX
@ UWOFDMALOHA_REASON_DATA_PENDING
@ UWOFDMALOHA_REASON_PKT_ERROR
@ UWOFDMALOHA_REASON_MAX_TX_TRIES
@ UWOFDMALOHA_REASON_WAIT_ACK_PENDING
@ UWOFDMALOHA_REASON_BACKOFF_PENDING
@ UWOFDMALOHA_REASON_DATA_TX
@ UWOFDMALOHA_REASON_NOT_SET
@ UWOFDMALOHA_REASON_PKT_NOT_FOR_ME
@ UWOFDMALOHA_REASON_START_RX
virtual void txAck(int dest_addr)
This methods transmits ACK packet from MAC layer to PHY layer.
UWOFDMALOHA_ACK_MODES ack_mode
Enum variable.
UWOFDMALOHA_STATUS prev_state
Enum variable.
virtual void incrCurrTxRounds()
Increments the current transmission round of a packet.
UWOFDMAloha()
Constructor of UWOFDMAloha Class.
virtual void stateRxIdle()
If a node start receiving a packet in Idle state.
void init_macofdm_node(int subCarNum, double subCarSize, int ctrl_subCar, string modulation)
Initialize subCarriers parameters inside a node, default all carriers are used.
virtual void stateRxData(Packet *p)
It process the packet which is received.
double wait_constant
This fixed time is used to componsate different time variations.
virtual void stateCheckBackoffExpired()
It checks whether the backoff timer is already expired while it was busy with other activities.
int ACK_size
Size of the ACK, if the node uses ARQ technique.
map< pktSeqNum, Packet * > mapPacket
Container where Data packets are stored.
virtual void Phy2MacEndRx(Packet *p)
PHY layer informs the MAC layer that the reception of the packet is over.
int uwofdmaloha_debug
Debuging Flag.
virtual void refreshReason(UWOFDMALOHA_REASON_STATUS reason)
To know the reason why a node is in this current state.
double max_backoff_counter
Maximum number of backoff it will consider while it increases the backoff exponentially.
int rttsamples
Number of RTT samples.
std::vector< int > nouse_carriers
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
virtual void stateTxAck(int dest_addr)
If the protocl uses ARQ technique, in that case, after receiving a Data packet the node sends an ACK ...
double srtt
Smoothed Round Trip Time, calculated as for TCP.
std::vector< Packet * > pkt_rcv_queue
@ UWOFDMALOHA_NO_ACK_MODE
virtual void exitBackoff()
It stops the backoff timer.
int last_sent_data_id
sequence number of the last sent packet
static const double prop_speed
Speed of the sound signal.
int last_data_id_rx
The sequence number of last received packet.
virtual double getBackoffTime()
This function calculates the backoff duration and return the backoff time.It employs the exponential ...
ofstream fout
An object of ofstream class.
int curr_tx_rounds
How many times a packet is transmitted.
virtual void refreshState(UWOFDMALOHA_STATUS state)
Refreshes the states of the node.
virtual void initPkt(Packet *p, UWOFDMALOHA_PKT_TYPE pkt_type, int dest_addr=0)
This method, initialize the packet.
virtual void stateBackoff()
If ACK packet is not received within the acknowledgement expire time.
void addInvalidCarriers(int c)
Adds carriers that should not be used.
virtual double computeTxTime(UWOFDMALOHA_PKT_TYPE type)
Compute the transmission time of a packet.
UWOFDMALOHA_STATUS curr_state
Enum variable.
double start_tx_time
Time when a packet start transmitting.
double alpha_
This variable is used to tune the RTT.
virtual void Phy2MacEndTx(const Packet *p)
It infroms that a packet transmission end.
virtual void recvFromUpperLayers(Packet *p)
This function receives the packet from upper layer and save it in the queue.
double ACK_timeout
ACK timeout for the initial packet.
static map< UWOFDMALOHA_REASON_STATUS, string > reason_info
Container which stores all the reason information.
virtual void Mac2PhyStartTx(Packet *p)
It informs that a packet transmission started.
virtual void stateRxAck(Packet *p)
The node comes to this state if it receives an ACK packet.
static map< UWOFDMALOHA_STATUS, string > status_info
Container which stores all the status information.
virtual void txData()
This method transmits Data packets from MAC layer to PHY layer.
int buffer_pkts
Number of packets a node can store in the container.
virtual void updateRTT(double rtt)
Update the Round Trip Time (RTT) which is necessary to compute the acknowledgement duration as well a...
map< pktSeqNum, AckTimer > mapAckTimer
Container where acknowledgement timer(s) is stored.
virtual void stateRxBackoff()
If a node start receiving a packet when it is in backoff state.
virtual void stateTxData()
If a node has packet to transmits.
std::vector< string > mac_carMod
--— OFDM PARAMS
UWOFDMALOHA_PKT_TYPE
Enumeration class of UWOFDMAloha packet type.
@ UWOFDMALOHA_DATAMAX_PKT
virtual void Phy2MacStartRx(const Packet *p)
PHY layer informs the MAC layer that it is receiving a packet.
void putPktInQueue(Packet *p)
A node receives packet(s) from upper layer and store them in the container.
int getUpLayersDataPktsRx()
bool print_transitions
Whether to print the state of the nodes.
AckTimer ack_timer
An object of the AckTimer class.
int recv_data_id
The sequence number of the packet which is received.
int max_tx_tries
Maximum number of retransmissions attempt.
@ UWOFDMALOHA_STATE_BACKOFF
@ UWOFDMALOHA_STATE_TX_ACK
@ UWOFDMALOHA_STATE_CHK_BACKOFF_TIMEOUT
@ UWOFDMALOHA_STATE_WRONG_PKT_RX
@ UWOFDMALOHA_STATE_WAIT_ACK
@ UWOFDMALOHA_STATE_DATA_RX
@ UWOFDMALOHA_STATE_RX_IDLE
@ UWOFDMALOHA_STATE_RX_IN_PROGRESS
@ UWOFDMALOHA_STATE_TX_DATA
@ UWOFDMALOHA_STATE_CHK_ACK_TIMEOUT
@ UWOFDMALOHA_STATE_MULTIPLE_RX_IN_PROGRESS
@ UWOFDMALOHA_STATE_RX_BACKOFF
@ UWOFDMALOHA_STATE_RX_WAIT_ACK
@ UWOFDMALOHA_STATE_ACK_RX
int txsn
Sequence number of the packet which is transmitted.
virtual void stateRxWaitAck()
If a node receives any packet while it was waiting for ACK packet, it moves to this state.
double sumrtt
Sum of RTT samples.
bool has_buffer_queue
Whether the node has buffer to store data or not.
BackOffTimer backoff_timer
An object of the backoff timer class.
virtual void printStateInfo(double delay=0)
This methods print the state information of the nodes.
double backoff_tuner
Tunes the backoff duration.
double sumrtt2
Sum of (RTT^2)
virtual void updateAckTimeout(double rtt)
Like updateRTT() function.
int max_payload
Maximum number of payload in a packet.
static bool initialized
It checks whether UWOFDMAloha protocol is initialized or not.
virtual void incrUpperDataRx()
Increment the number of Data packet receive for the upper layer.
int HDR_size
Size of the HDR if any.
virtual void stateCheckAckExpired()
It checks whether the ack timer is already expired while it was busy with other activities.
void displayCarriers(Packet *p)
Prints the carriers as a sequence of 0s and 1s.
virtual void stateWaitAck()
After transmitting a Data packet, a node waits for the ACK packet.
std::vector< int > mac_carVec
UWOFDMALOHA_STATUS prev_prev_state
Enum variable.
virtual void initInfo()
This function is used to initialize the UWOFDMAloha protocol.
virtual void stateIdle()
Node is in Idle state.
void putAckTimerInMap(int seq_num)
Put acknowledgement timer in the container.
void eraseItemFrommapAckTimer(int seq_num)
Erase an item from acknowledgement stored container.
Header of the OFDM message with fields to implement a multi carrier system.
int carriers[MAX_CARRIERS]
string carMod[MAX_CARRIERS]
UWOFDMALOHAModuleClass class_module_uwofdmaloha
@ SESSION_DISTANCE_NOT_SET
This is the base class of UWOFDMAloha Protocol, derived of MMac. Your can find the brief description ...
#define UWOFDMALOHA_DROP_REASON_ERROR
#define UWOFDMALOHA_DROP_REASON_WRONG_RECEIVER
#define UWOFDMALOHA_DROP_REASON_BUFFER_FULL
std::pair< int, int > counter
counter of collisions
#define HDR_OFDM(p)
alias defined to access the PROBE HEADER
Definition of ClMsgUwMmac class.