61 : TclClass(
"Module/UW/CSMA_ALOHA")
80 module->printOnLog(Logger::LogLevel::DEBUG,
82 "AckTimer::expire(Event *)::current state = " +
83 module->status_info[module->curr_state] +
84 "; ACK not received, next state =
" +
85 module->status_info[CSMA_STATE_BACKOFF]);
87 module->refreshReason(CSMA_REASON_ACK_TIMEOUT);
88 module->stateBackoff();
90 module->printOnLog(Logger::LogLevel::DEBUG,
97CsmaAloha::BackOffTimer::expire(Event *e)
99 timer_status = CSMA_EXPIRED;
100 if (module->curr_state == CSMA_STATE_BACKOFF) {
101 module->printOnLog(Logger::LogLevel::DEBUG,
104 module->status_info[module->curr_state] +
105 "; ACK not received, next state =
" +
106 module->status_info[CSMA_STATE_BACKOFF]);
108 module->refreshReason(CSMA_REASON_BACKOFF_TIMEOUT);
109 module->exitBackoff();
112 module->printOnLog(Logger::LogLevel::DEBUG,
119CsmaAloha::ListenTimer::expire(Event *e)
121 timer_status = CSMA_EXPIRED;
123 if (module->curr_state == CSMA_STATE_LISTEN) {
125 module->printOnLog(Logger::LogLevel::DEBUG,
128 module->status_info[module->curr_state] +
129 "; ACK not received, next state =
" +
130 module->status_info[CSMA_STATE_BACKOFF]);
132 module->refreshReason(CSMA_REASON_LISTEN_TIMEOUT);
133 module->stateTxData();
135 module->printOnLog(Logger::LogLevel::DEBUG,
141const double CsmaAloha::prop_speed = 1500.0;
142int CsmaAloha::u_pkt_id;
143bool CsmaAloha::initialized = false;
145map<CsmaAloha::CSMA_STATUS, string> CsmaAloha::status_info;
146map<CsmaAloha::CSMA_REASON_STATUS, string> CsmaAloha::reason_info;
147map<CsmaAloha::CSMA_PKT_TYPE, string> CsmaAloha::pkt_type_info;
149CsmaAloha::CsmaAloha()
151 , last_sent_data_id(-1)
154 , session_active(false)
155 , print_transitions(false)
156 , has_buffer_queue(false)
163 , last_data_id_rx(NOT_SET)
165 , session_distance(SESSION_DISTANCE_NOT_SET)
167 , backoff_timer(this)
169 , last_reason(CSMA_REASON_NOT_SET)
170 , curr_state(CSMA_STATE_IDLE)
171 , prev_state(CSMA_STATE_IDLE)
172 , prev_prev_state(CSMA_STATE_IDLE)
173 , ack_mode(CSMA_ACK_MODE)
176 mac2phy_delay_ = 1e-19;
178 bind("HDR_size_
", (int *) &HDR_size);
179 bind("ACK_size_
", (int *) &ACK_size);
180 bind("max_tx_tries_
", (int *) &max_tx_tries);
181 bind("wait_costant_
", (double *) &wait_costant);
182 bind("debug_
", (double *) &debug_);
183 bind("max_payload_
", (int *) &max_payload);
184 bind("ACK_timeout_
", (double *) &ACK_timeout);
185 bind("alpha_", (double *) &alpha_);
186 bind("backoff_tuner_
", (double *) &backoff_tuner);
187 bind("buffer_pkts_
", (int *) &buffer_pkts);
188 bind("max_backoff_counter_
", (int *) &max_backoff_counter);
189 bind("listen_time_
", &listen_time);
191 if (max_tx_tries <= 0)
192 max_tx_tries = INT_MAX;
194 has_buffer_queue = true;
195 if (listen_time <= 0.0)
200CsmaAloha::command(int argc, const char *const *argv)
202 Tcl &tcl = Tcl::instance();
204 if (strcasecmp(argv[1], "setAckMode
") == 0) {
205 ack_mode = CSMA_ACK_MODE;
207 } else if (strcasecmp(argv[1], "setNoAckMode
") == 0) {
208 ack_mode = CSMA_NO_ACK_MODE;
210 } else if (strcasecmp(argv[1], "initialize
") == 0) {
211 if (initialized == false)
213 if (print_transitions)
214 fout.open("/tmp/CSMAstateTransitions.txt
", ios_base::app);
216 } else if (strcasecmp(argv[1], "printTransitions
") == 0) {
217 print_transitions = true;
219 } else if (strcasecmp(argv[1], "getQueueSize
") == 0) {
220 tcl.resultf("%d
", Q.size());
222 } else if (strcasecmp(argv[1], "getUpLayersDataRx
") == 0) {
223 tcl.resultf("%d
", getUpLayersDataPktsRx());
226 } else if (argc == 3) {
227 if (strcasecmp(argv[1], "setMacAddr
") == 0) {
228 std::stringstream addr_ss(argv[2]);
229 if (addr_ss >> addr) {
230 printOnLog(Logger::LogLevel::INFO,
232 "command(
int,
const char *
const)::current node MAC
"
241 return MMac::command(argc, argv);
250 if ((print_transitions) && (system(NULL))) {
251 system("rm -f /tmp/CSMAstateTransitions.txt
");
252 system("touch /tmp/CSMAstateTransitions.txt
");
255 status_info[CSMA_STATE_IDLE] = "Idle state
";
256 status_info[CSMA_STATE_BACKOFF] = "Backoff state
";
257 status_info[CSMA_STATE_TX_DATA] = "Transmit
DATA state
";
258 status_info[CSMA_STATE_TX_ACK] = "Transmit ACK state
";
259 status_info[CSMA_STATE_WAIT_ACK] = "Wait for ACK state
";
260 status_info[CSMA_STATE_DATA_RX] = "DATA received state
";
261 status_info[CSMA_STATE_ACK_RX] = "ACK received state
";
262 status_info[CSMA_STATE_LISTEN] = "Listening channel state
";
263 status_info[CSMA_STATE_RX_IDLE] = "Start rx Idle state
";
264 status_info[CSMA_STATE_RX_BACKOFF] = "Start rx Backoff state
";
265 status_info[CSMA_STATE_RX_LISTEN] = "Start rx Listen state
";
266 status_info[CSMA_STATE_RX_WAIT_ACK] = "Start rx Wait ACK state
";
267 status_info[CSMA_STATE_CHK_LISTEN_TIMEOUT] = "Check Listen timeout state
";
268 status_info[CSMA_STATE_CHK_BACKOFF_TIMEOUT] = "Check Backoff timeout state
";
269 status_info[CSMA_STATE_CHK_ACK_TIMEOUT] = "Check Wait ACK timeout state
";
270 status_info[CSMA_STATE_WRONG_PKT_RX] = "Wrong Pkt Rx state
";
272 reason_info[CSMA_REASON_DATA_PENDING] = "DATA pending from upper layers
";
273 reason_info[CSMA_REASON_DATA_RX] = "DATA received
";
274 reason_info[CSMA_REASON_DATA_TX] = "DATA transmitted
";
275 reason_info[CSMA_REASON_ACK_TX] = "ACK tranmsitted
";
276 reason_info[CSMA_REASON_ACK_RX] = "ACK received
";
277 reason_info[CSMA_REASON_BACKOFF_TIMEOUT] = "Backoff expired
";
278 reason_info[CSMA_REASON_ACK_TIMEOUT] = "ACK timeout
";
279 reason_info[CSMA_REASON_DATA_EMPTY] = "DATA queue empty
";
280 reason_info[CSMA_REASON_MAX_TX_TRIES] = "DATA dropped due to max tx rounds
";
281 reason_info[CSMA_REASON_LISTEN] = "DATA pending, listening to channel
";
282 reason_info[CSMA_REASON_LISTEN_TIMEOUT] =
283 "DATA pending, end of listening period
";
284 reason_info[CSMA_REASON_START_RX] = "Start rx pkt
";
285 reason_info[CSMA_REASON_PKT_NOT_FOR_ME] = "Received an erroneous pkt
";
286 reason_info[CSMA_REASON_BACKOFF_PENDING] = "Backoff timer pending
";
287 reason_info[CSMA_REASON_WAIT_ACK_PENDING] = "Wait for ACK timer pending
";
288 reason_info[CSMA_REASON_LISTEN_PENDING] = "Listen to channel pending
";
289 reason_info[CSMA_REASON_PKT_ERROR] = "Erroneous pkt
";
291 pkt_type_info[CSMA_ACK_PKT] = "ACK pkt
";
292 pkt_type_info[CSMA_DATA_PKT] = "DATA pkt
";
293 pkt_type_info[CSMA_DATAMAX_PKT] = "MAX payload
DATA pkt
";
297CsmaAloha::resetSession()
299 session_distance = SESSION_DISTANCE_NOT_SET;
303CsmaAloha::updateRTT(double curr_rtt)
305 srtt = alpha_ * srtt + (1 - alpha_) * curr_rtt;
307 sumrtt2 += curr_rtt * curr_rtt;
313CsmaAloha::updateAckTimeout(double rtt)
317 printOnLog(Logger::LogLevel::INFO,
320 to_string(ACK_timeout));
324CsmaAloha::keepDataPkt(int serial_number)
326 if (serial_number > last_data_id_rx) {
327 last_data_id_rx = serial_number;
335CsmaAloha::computeTxTime(CSMA_PKT_TYPE type)
338 Packet *temp_data_pkt;
340 if (type == CSMA_DATA_PKT) {
342 temp_data_pkt = (Q.front())->copy();
343 hdr_cmn *ch = HDR_CMN(temp_data_pkt);
344 ch->size() = HDR_size + ch->size();
346 temp_data_pkt = Packet::alloc();
347 hdr_cmn *ch = HDR_CMN(temp_data_pkt);
348 ch->size() = HDR_size + max_payload;
350 } else if (type == CSMA_ACK_PKT) {
351 temp_data_pkt = Packet::alloc();
352 hdr_cmn *ch = HDR_CMN(temp_data_pkt);
353 ch->size() = ACK_size;
355 printOnLog(Logger::LogLevel::ERROR,
362 duration = Mac2PhyTxDuration(temp_data_pkt);
363 Packet::free(temp_data_pkt);
368CsmaAloha::exitBackoff()
370 backoff_timer.stop();
374CsmaAloha::getBackoffTime()
376 incrTotalBackoffTimes();
377 double random = RNG::defaultrng()->uniform_double();
379 backoff_timer.incrCounter();
380 int counter = backoff_timer.getCounter();
381 if (counter > max_backoff_counter)
382 counter = max_backoff_counter;
384 double backoff_duration =
385 backoff_tuner * random * 2.0 * ACK_timeout * pow(2.0, counter);
386 backoffSumDuration(backoff_duration);
388 printOnLog(Logger::LogLevel::DEBUG,
391 to_string(backoff_duration) + " s
");
393 return backoff_duration;
397CsmaAloha::recvFromUpperLayers(Packet *p)
399 if ( (has_buffer_queue && (Q.size() < buffer_pkts)) || !has_buffer_queue) {
400 initPkt(p, CSMA_DATA_PKT);
405 if (curr_state == CSMA_STATE_IDLE) {
406 refreshReason(CSMA_REASON_DATA_PENDING);
410 incrDiscardedPktsTx();
411 drop(p, 1, CSMA_DROP_REASON_BUFFER_FULL);
416CsmaAloha::initPkt(Packet *p, CSMA_PKT_TYPE type, int dest_addr)
418 hdr_cmn *ch = hdr_cmn::access(p);
419 hdr_mac *mach = HDR_MAC(p);
421 int curr_size = ch->size();
425 case (CSMA_DATA_PKT): {
426 ch->size() = curr_size + HDR_size;
427 data_sn_queue.push(u_data_id);
431 case (CSMA_ACK_PKT): {
432 ch->ptype() = PT_MMAC_ACK;
433 ch->size() = ACK_size;
434 ch->uid() = u_pkt_id++;
435 mach->set(MF_CONTROL, addr, dest_addr);
436 mach->macSA() = addr;
437 mach->macDA() = dest_addr;
440 printOnLog(Logger::LogLevel::ERROR,
443 "type =
" + to_string(type));
448CsmaAloha::Mac2PhyStartTx(Packet *p)
450 printOnLog(Logger::LogLevel::DEBUG,
454 MMac::Mac2PhyStartTx(p);
458CsmaAloha::Phy2MacEndTx(const Packet *p)
461 printOnLog(Logger::LogLevel::DEBUG,
465 switch (curr_state) {
467 case (CSMA_STATE_TX_DATA): {
468 refreshReason(CSMA_REASON_DATA_TX);
469 if (ack_mode == CSMA_ACK_MODE) {
470 printOnLog(Logger::LogLevel::DEBUG,
473 status_info[curr_state] + " to
" +
474 status_info[CSMA_STATE_WAIT_ACK]);
478 printOnLog(Logger::LogLevel::DEBUG,
481 status_info[curr_state] + " to
" +
482 status_info[CSMA_STATE_IDLE]);
488 case (CSMA_STATE_TX_ACK): {
489 refreshReason(CSMA_REASON_ACK_TX);
491 if (prev_prev_state == CSMA_STATE_RX_BACKOFF) {
492 printOnLog(Logger::LogLevel::DEBUG,
495 status_info[curr_state] + " to
" +
496 status_info[CSMA_STATE_CHK_BACKOFF_TIMEOUT]);
498 stateCheckBackoffExpired();
499 } else if (prev_prev_state == CSMA_STATE_RX_LISTEN) {
500 printOnLog(Logger::LogLevel::DEBUG,
503 status_info[curr_state] + " to
" +
504 status_info[CSMA_STATE_CHK_LISTEN_TIMEOUT]);
506 stateCheckListenExpired();
507 } else if (prev_prev_state == CSMA_STATE_RX_IDLE) {
509 printOnLog(Logger::LogLevel::DEBUG,
512 status_info[curr_state] + " to
" +
513 status_info[CSMA_STATE_IDLE]);
516 } else if (prev_prev_state == CSMA_STATE_RX_WAIT_ACK) {
517 printOnLog(Logger::LogLevel::DEBUG,
520 status_info[curr_state] + " to
" +
521 status_info[CSMA_STATE_IDLE]);
523 stateCheckAckExpired();
526 printOnLog(Logger::LogLevel::DEBUG,
529 "current state =
" + status_info[curr_state]);
535 printOnLog(Logger::LogLevel::DEBUG,
538 "current state =
" + status_info[curr_state]);
546CsmaAloha::Phy2MacStartRx(const Packet *p)
548 printOnLog(Logger::LogLevel::DEBUG,
552 refreshReason(CSMA_REASON_START_RX);
554 switch (curr_state) {
556 case (CSMA_STATE_IDLE):
560 case (CSMA_STATE_LISTEN):
564 case (CSMA_STATE_BACKOFF):
568 case (CSMA_STATE_WAIT_ACK):
573 printOnLog(Logger::LogLevel::ERROR,
576 status_info[curr_state]);
583CsmaAloha::Phy2MacEndRx(Packet *p)
586 hdr_cmn *ch = HDR_CMN(p);
587 packet_t rx_pkt_type = ch->ptype();
588 hdr_mac *mach = HDR_MAC(p);
589 hdr_MPhy *ph = HDR_MPHY(p);
591 int dest_mac = mach->macDA();
593 double gen_time = ph->txtime;
594 double received_time = ph->rxtime;
595 double diff_time = received_time - gen_time;
597 double distance = diff_time * prop_speed;
599 std::stringstream log_stream;
600 log_stream << "Phy2MacEndRx(Packet *)::current state =
"
601 << status_info[curr_state]
602 << ", received a pkt type =
" << ch->ptype()
603 << ", src addr =
" << mach->macSA()
604 << " dest addr =
" << mach->macDA()
605 << ", estimated distance between nodes =
" << distance << " m
";
606 printOnLog(Logger::LogLevel::DEBUG, "CSMA_ALOHA
", log_stream.str());
610 printOnLog(Logger::LogLevel::ERROR,
615 refreshReason(CSMA_REASON_PKT_ERROR);
616 drop(p, 1, CSMA_DROP_REASON_ERROR);
617 // Next line is needed just to update the current state
618 stateRxPacketNotForMe(NULL);
620 if (dest_mac == addr || dest_mac == MAC_BROADCAST) {
621 if (rx_pkt_type == PT_MMAC_ACK) {
622 refreshReason(CSMA_REASON_ACK_RX);
624 } else if (curr_state != CSMA_STATE_RX_WAIT_ACK) {
625 refreshReason(CSMA_REASON_DATA_RX);
628 refreshReason(CSMA_REASON_PKT_NOT_FOR_ME);
629 stateRxPacketNotForMe(p);
632 refreshReason(CSMA_REASON_PKT_NOT_FOR_ME);
633 stateRxPacketNotForMe(p);
641 Packet *data_pkt = curr_data_pkt->copy();
643 if (ack_mode == CSMA_NO_ACK_MODE)
648 Mac2PhyStartTx(data_pkt);
652CsmaAloha::txAck(int dest_addr)
654 Packet *ack_pkt = Packet::alloc();
655 initPkt(ack_pkt, CSMA_ACK_PKT, dest_addr);
658 Mac2PhyStartTx(ack_pkt);
662CsmaAloha::stateRxPacketNotForMe(Packet *p)
664 // Check if packet already dropped because it was corrupted
666 printOnLog(Logger::LogLevel::ERROR,
674 refreshState(CSMA_STATE_WRONG_PKT_RX);
676 switch (prev_state) {
678 case CSMA_STATE_RX_IDLE:
682 case CSMA_STATE_RX_LISTEN:
683 stateCheckListenExpired();
686 case CSMA_STATE_RX_BACKOFF:
687 stateCheckBackoffExpired();
690 case CSMA_STATE_RX_WAIT_ACK:
691 stateCheckAckExpired();
695 printOnLog(Logger::LogLevel::ERROR,
698 "state =
" + status_info[prev_state]);
705CsmaAloha::stateCheckListenExpired()
707 refreshState(CSMA_STATE_CHK_LISTEN_TIMEOUT);
712 if (print_transitions)
714 if (listen_timer.isActive()) {
715 refreshReason(CSMA_REASON_LISTEN_PENDING);
716 refreshState(CSMA_STATE_LISTEN);
717 } else if (listen_timer.isExpired()) {
718 refreshReason(CSMA_REASON_LISTEN_TIMEOUT);
719 if (!(prev_state == CSMA_STATE_TX_ACK ||
720 prev_state == CSMA_STATE_WRONG_PKT_RX ||
721 prev_state == CSMA_STATE_ACK_RX ||
722 prev_state == CSMA_STATE_DATA_RX))
727 printOnLog(Logger::LogLevel::ERROR,
730 "state =
" + status_info[curr_state]);
737CsmaAloha::stateCheckAckExpired()
739 refreshState(CSMA_STATE_CHK_ACK_TIMEOUT);
743 if (print_transitions)
745 if (ack_timer.isActive()) {
746 refreshReason(CSMA_REASON_WAIT_ACK_PENDING);
747 refreshState(CSMA_STATE_WAIT_ACK);
748 } else if (ack_timer.isExpired()) {
749 refreshReason(CSMA_REASON_ACK_TIMEOUT);
752 printOnLog(Logger::LogLevel::ERROR,
755 "state =
" + status_info[curr_state]);
762CsmaAloha::stateCheckBackoffExpired()
764 refreshState(CSMA_STATE_CHK_BACKOFF_TIMEOUT);
766 printOnLog(Logger::LogLevel::DEBUG,
770 if (print_transitions)
772 if (backoff_timer.isActive()) {
773 refreshReason(CSMA_REASON_BACKOFF_PENDING);
775 } else if (backoff_timer.isExpired()) {
776 refreshReason(CSMA_REASON_BACKOFF_TIMEOUT);
780 printOnLog(Logger::LogLevel::ERROR,
783 "state =
" + status_info[curr_state]);
790CsmaAloha::stateIdle()
793 backoff_timer.stop();
797 refreshState(CSMA_STATE_IDLE);
799 if (print_transitions)
802 printOnLog(Logger::LogLevel::DEBUG,
804 "stateIdle()::queue size =
" + to_string(Q.size()));
807 refreshReason(CSMA_REASON_LISTEN);
813CsmaAloha::stateRxIdle()
815 refreshState(CSMA_STATE_RX_IDLE);
817 if (print_transitions)
822CsmaAloha::stateListen()
825 refreshState(CSMA_STATE_LISTEN);
827 listen_timer.incrCounter();
830 listen_time * RNG::defaultrng()->uniform_double() + wait_costant;
832 printOnLog(Logger::LogLevel::DEBUG,
834 "stateListen()::listen time =
" + to_string(time));
836 if (print_transitions)
839 listen_timer.schedule(time);
843CsmaAloha::stateRxListen()
845 refreshState(CSMA_STATE_RX_LISTEN);
847 if (print_transitions)
852CsmaAloha::stateBackoff()
854 refreshState(CSMA_STATE_BACKOFF);
856 if (backoff_timer.isFrozen())
857 backoff_timer.unFreeze();
859 backoff_timer.schedule(getBackoffTime());
861 printOnLog(Logger::LogLevel::DEBUG, "CSMA_ALOHA
", "stateBackoff()
");
863 if (print_transitions)
864 printStateInfo(backoff_timer.getDuration());
868CsmaAloha::stateRxBackoff()
870 backoff_timer.freeze();
871 refreshState(CSMA_STATE_RX_BACKOFF);
873 if (print_transitions)
878CsmaAloha::stateTxData()
880 refreshState(CSMA_STATE_TX_DATA);
882 printOnLog(Logger::LogLevel::DEBUG, "CSMA_ALOHA
", "stateTxData()
");
884 if (print_transitions)
887 curr_data_pkt = Q.front();
889 if (data_sn_queue.front() != last_sent_data_id) {
891 ack_timer.resetCounter();
892 listen_timer.resetCounter();
893 backoff_timer.resetCounter();
895 if (curr_tx_rounds < max_tx_tries) {
896 hdr_mac *mach = HDR_MAC(curr_data_pkt);
898 mach->macSA() = addr;
900 last_sent_data_id = data_sn_queue.front();
906 refreshReason(CSMA_REASON_MAX_TX_TRIES);
908 printOnLog(Logger::LogLevel::DEBUG,
918CsmaAloha::stateWaitAck()
921 refreshState(CSMA_STATE_WAIT_ACK);
923 printOnLog(Logger::LogLevel::DEBUG, "CSMA_ALOHA
", "stateWaitAck()
");
925 if (print_transitions)
928 ack_timer.incrCounter();
929 ack_timer.schedule(ACK_timeout + 2 * wait_costant);
933CsmaAloha::stateRxWaitAck()
935 refreshState(CSMA_STATE_RX_WAIT_ACK);
937 if (print_transitions)
942CsmaAloha::stateTxAck(int dest_addr)
944 refreshState(CSMA_STATE_TX_ACK);
946 printOnLog(Logger::LogLevel::DEBUG,
948 "stateTxAck(int)::dest_addr =
" + to_string(dest_addr));
950 if (print_transitions)
957CsmaAloha::stateRxData(Packet *data_pkt)
959 refreshState(CSMA_STATE_DATA_RX);
961 printOnLog(Logger::LogLevel::DEBUG,
964 status_info[curr_state]);
966 refreshReason(CSMA_REASON_DATA_RX);
968 hdr_mac *mach = HDR_MAC(data_pkt);
969 int dst_addr = mach->macSA();
971 switch (prev_state) {
973 case CSMA_STATE_RX_IDLE: {
974 hdr_cmn *ch = hdr_cmn::access(data_pkt);
975 ch->size() = ch->size() - HDR_size;
979 if (ack_mode == CSMA_ACK_MODE)
980 stateTxAck(dst_addr);
985 case CSMA_STATE_RX_LISTEN: {
986 hdr_cmn *ch = hdr_cmn::access(data_pkt);
987 ch->size() = ch->size() - HDR_size;
991 if (ack_mode == CSMA_ACK_MODE)
992 stateTxAck(dst_addr);
994 stateCheckListenExpired();
997 case CSMA_STATE_RX_BACKOFF: {
998 hdr_cmn *ch = hdr_cmn::access(data_pkt);
999 ch->size() = ch->size() - HDR_size;
1002 if (ack_mode == CSMA_ACK_MODE)
1003 stateTxAck(dst_addr);
1005 stateCheckBackoffExpired();
1008 case CSMA_STATE_RX_WAIT_ACK: {
1009 hdr_cmn *ch = hdr_cmn::access(data_pkt);
1010 ch->size() = ch->size() - HDR_size;
1013 if (ack_mode == CSMA_ACK_MODE)
1014 stateTxAck(dst_addr);
1016 stateCheckAckExpired();
1020 printOnLog(Logger::LogLevel::ERROR,
1023 "state =
" + status_info[prev_state]);
1028CsmaAloha::stateRxAck(Packet *p)
1031 refreshState(CSMA_STATE_ACK_RX);
1033 printOnLog(Logger::LogLevel::DEBUG, "CSMA_ALOHA
", "stateRxAck()
");
1037 refreshReason(CSMA_REASON_ACK_RX);
1039 switch (prev_state) {
1041 case CSMA_STATE_RX_IDLE:
1045 case CSMA_STATE_RX_LISTEN:
1046 stateCheckListenExpired();
1049 case CSMA_STATE_RX_BACKOFF:
1050 stateCheckBackoffExpired();
1053 case CSMA_STATE_RX_WAIT_ACK:
1055 updateAckTimeout(NOW - start_tx_time);
1061 printOnLog(Logger::LogLevel::ERROR,
1063 "stateRxAck(Packet *)::cannot RX in previous
"
1064 "state =
" + status_info[prev_state]);
1069CsmaAloha::printStateInfo(double delay)
1071 printOnLog(Logger::LogLevel::DEBUG,
1074 status_info[prev_state] + " to
" + status_info[curr_state] +
1075 ". Reason:
" + reason_info[last_reason]);
1077 if (curr_state == CSMA_STATE_BACKOFF) {
1078 fout << left << setw(10) << NOW << " CsmaAloha(
" << addr
1080 << "from
" << status_info[prev_state] << " to
"
1081 << status_info[curr_state]
1082 << ". Reason:
" << reason_info[last_reason]
1083 << ". Backoff duration =
" << delay << endl;
1085 fout << left << setw(10) << NOW << " CsmaAloha(
" << addr
1087 << "from
" << status_info[prev_state] << " to
"
1088 << status_info[curr_state]
1089 << ". Reason:
" << reason_info[last_reason] << endl;
Class that represents the binding with the tcl configuration script.
CSMAModuleClass()
Constructor of the class.
TclObject * create(int, const char *const *)
Creates the TCL object needed for the tcl language interpretation.
Class used to handle the timer for waiting the ACK.
virtual void expire(Event *e)
Method called when the timer expire.
CsmaAloha *CSMA_TIMER_STATUS timer_status
< Pointer to an object of type CsmaAloha
virtual void expire(Event *e)
Method called when the timer expire.
virtual void expire(Event *e)
Method called when the timer expire.
Class that describes a CsmaAloha module.
double ACK_timeout
Duration of the ACK waiting time.
virtual void stateIdle()
IDLE state.
virtual void stateTxData()
State in which the protocol allows the node to transmit a data packet.
virtual void stateCheckAckExpired()
Checks if the ACK reception timer is expired.
virtual void updateAckTimeout(double rtt)
Updates the AckTimeout calling getRTT, where the ACK timeout is computed as srtt/rttsamples using the...
virtual void stateRxAck(Packet *p)
state in which an ACK packet is received
virtual void Phy2MacStartRx(const Packet *p) override
Method called when the Phy Layer start to receive a Packet.
virtual int command(int argc, const char *const *argv) override
TCL command interpreter.
double alpha_
smooth factor in the calculation of the RTT
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...
virtual void stateWaitAck()
State in which a DATA packet is sent.
virtual void stateRxData(Packet *p)
State in which a DATA packet is received.
virtual void stateCheckListenExpired()
Checks if the Listen period is expired.
virtual void stateRxPacketNotForMe(Packet *p)
state in which a wrong Packet is received
virtual void Phy2MacEndTx(const Packet *p) override
Method called when the PHY layer finish to transmit the packet.
virtual void Phy2MacEndRx(Packet *p) override
Method called when the Phy Layer finish to receive a Packet.
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.
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 ...
virtual void stateBackoff()
BackOff STATE.
virtual void stateListen()
State in which the node is listening the channel.
int curr_tx_rounds
Number of current transmission of the same packet.
virtual void Mac2PhyStartTx(Packet *p)
Pass the packet to the PHY layer.
int max_tx_tries
Maximum number of transmissions for one packet.
virtual void stateCheckBackoffExpired()
Checks if the Backoff period is expired.
virtual void stateTxAck(int dest_addr)
State in which the protocol set-up the ACK packet to transmit.
@ SESSION_DISTANCE_NOT_SET
CSMAModuleClass class_module_csma
Provides the description of CsmaAloha Class.