59 : TclClass(
"Module/UW/CSMA_ALOHA")
80 cout << NOW <<
" CsmaAloha(" <<
module->addr
81 << ") timer expire() current state = "
82 << module->status_info[module->curr_state]
83 << "; ACK not received, next state =
"
84 << module->status_info[CSMA_STATE_BACKOFF] << endl;
86 module->refreshReason(CSMA_REASON_ACK_TIMEOUT);
87 module->stateBackoff();
90 cout << NOW << " CsmaAloha(
" << module->addr
91 << ")::AckTimer::expired()
" << endl;
96CsmaAloha::BackOffTimer::expire(Event *e)
98 timer_status = CSMA_EXPIRED;
99 if (module->curr_state == CSMA_STATE_BACKOFF) {
102 cout << NOW << " CsmaAloha(
" << module->addr
103 << ") timer
expire() current state = "
105 << "; backoff expired, next state = "
113 cout << NOW <<
" CsmaAloha(" <<
module->addr
114 << ")::BackoffTimer::expired() " << endl;
126 cout << NOW <<
" CsmaAloha(" <<
module->addr
127 << ") timer expire() current state = "
128 << module->status_info[module->curr_state]
129 << "; listening period expired, next state =
"
130 << module->status_info[CSMA_STATE_TX_DATA] << endl;
132 module->refreshReason(CSMA_REASON_LISTEN_TIMEOUT);
133 module->stateTxData();
136 cout << NOW << " CsmaAloha(
" << module->addr
137 << ")::ListenTimer::expired()
" << endl;
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()
152 , backoff_timer(this)
154 , last_sent_data_id(-1)
155 , session_distance(SESSION_DISTANCE_NOT_SET)
157 , last_data_id_rx(NOT_SET)
161 , session_active(false)
162 , print_transitions(false)
163 , has_buffer_queue(false)
164 , curr_state(CSMA_STATE_IDLE)
165 , prev_state(CSMA_STATE_IDLE)
166 , prev_prev_state(CSMA_STATE_IDLE)
167 , ack_mode(CSMA_ACK_MODE)
168 , last_reason(CSMA_REASON_NOT_SET)
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)
199CsmaAloha::~CsmaAloha()
203// TCL command interpreter
205CsmaAloha::command(int argc, const char *const *argv)
207 Tcl &tcl = Tcl::instance();
209 if (strcasecmp(argv[1], "setAckMode
") == 0) {
210 ack_mode = CSMA_ACK_MODE;
212 } else if (strcasecmp(argv[1], "setNoAckMode
") == 0) {
213 ack_mode = CSMA_NO_ACK_MODE;
215 } else if (strcasecmp(argv[1], "initialize
") == 0) {
216 if (initialized == false)
218 if (print_transitions)
219 fout.open("/tmp/CSMAstateTransitions.txt
", ios_base::app);
221 } else if (strcasecmp(argv[1], "printTransitions
") == 0) {
222 print_transitions = true;
224 } else if (strcasecmp(argv[1], "getQueueSize
") == 0) {
225 tcl.resultf("%d
", Q.size());
227 } else if (strcasecmp(argv[1], "getUpLayersDataRx
") == 0) {
228 tcl.resultf("%d
", getUpLayersDataPktsRx());
231 } else if (argc == 3) {
232 if (strcasecmp(argv[1], "setMacAddr
") == 0) {
233 addr = atoi(argv[2]);
235 cout << "Csma_Aloha MAC address of current node is
" << addr
240 return MMac::command(argc, argv);
244CsmaAloha::crLayCommand(ClMessage *m)
249 return Module::crLayCommand(m);
259 if ((print_transitions) && (system(NULL))) {
260 system("rm -f /tmp/CSMAstateTransitions.txt
");
261 system("touch /tmp/CSMAstateTransitions.txt
");
264 status_info[CSMA_STATE_IDLE] = "Idle state
";
265 status_info[CSMA_STATE_BACKOFF] = "Backoff state
";
266 status_info[CSMA_STATE_TX_DATA] = "Transmit
DATA state
";
267 status_info[CSMA_STATE_TX_ACK] = "Transmit ACK state
";
268 status_info[CSMA_STATE_WAIT_ACK] = "Wait
for ACK state
";
269 status_info[CSMA_STATE_DATA_RX] = "DATA received state
";
270 status_info[CSMA_STATE_ACK_RX] = "ACK received state
";
271 status_info[CSMA_STATE_LISTEN] = "Listening channel state
";
272 status_info[CSMA_STATE_RX_IDLE] = "Start rx Idle state
";
273 status_info[CSMA_STATE_RX_BACKOFF] = "Start rx Backoff state
";
274 status_info[CSMA_STATE_RX_LISTEN] = "Start rx Listen state
";
275 status_info[CSMA_STATE_RX_WAIT_ACK] = "Start rx Wait ACK state
";
276 status_info[CSMA_STATE_CHK_LISTEN_TIMEOUT] = "Check Listen timeout state
";
277 status_info[CSMA_STATE_CHK_BACKOFF_TIMEOUT] = "Check Backoff timeout state
";
278 status_info[CSMA_STATE_CHK_ACK_TIMEOUT] = "Check Wait ACK timeout state
";
279 status_info[CSMA_STATE_WRONG_PKT_RX] = "Wrong Pkt Rx state
";
281 reason_info[CSMA_REASON_DATA_PENDING] = "DATA pending from upper layers
";
282 reason_info[CSMA_REASON_DATA_RX] = "DATA received
";
283 reason_info[CSMA_REASON_DATA_TX] = "DATA transmitted
";
284 reason_info[CSMA_REASON_ACK_TX] = "ACK tranmsitted
";
285 reason_info[CSMA_REASON_ACK_RX] = "ACK received
";
286 reason_info[CSMA_REASON_BACKOFF_TIMEOUT] = "Backoff expired
";
287 reason_info[CSMA_REASON_ACK_TIMEOUT] = "ACK timeout
";
288 reason_info[CSMA_REASON_DATA_EMPTY] = "DATA queue empty
";
289 reason_info[CSMA_REASON_MAX_TX_TRIES] = "DATA dropped due to max tx rounds
";
290 reason_info[CSMA_REASON_LISTEN] = "DATA pending, listening to channel
";
291 reason_info[CSMA_REASON_LISTEN_TIMEOUT] =
292 "DATA pending, end of listening period
";
293 reason_info[CSMA_REASON_START_RX] = "Start rx pkt
";
294 reason_info[CSMA_REASON_PKT_NOT_FOR_ME] = "Received an erroneous pkt
";
295 reason_info[CSMA_REASON_BACKOFF_PENDING] = "Backoff timer pending
";
296 reason_info[CSMA_REASON_WAIT_ACK_PENDING] = "Wait
for ACK timer pending
";
297 reason_info[CSMA_REASON_LISTEN_PENDING] = "Listen to channel pending
";
298 reason_info[CSMA_REASON_PKT_ERROR] = "Erroneous pkt
";
300 pkt_type_info[CSMA_ACK_PKT] = "ACK pkt
";
301 pkt_type_info[CSMA_DATA_PKT] = "DATA pkt
";
302 pkt_type_info[CSMA_DATAMAX_PKT] = "MAX payload
DATA pkt
";
306CsmaAloha::resetSession()
308 session_distance = SESSION_DISTANCE_NOT_SET;
312CsmaAloha::updateRTT(double curr_rtt)
314 srtt = alpha_ * srtt + (1 - alpha_) * curr_rtt;
316 sumrtt2 += curr_rtt * curr_rtt;
322CsmaAloha::updateAckTimeout(double rtt)
333CsmaAloha::keepDataPkt(int serial_number)
336 if (serial_number > last_data_id_rx) {
338 last_data_id_rx = serial_number;
345CsmaAloha::computeTxTime(CSMA_PKT_TYPE type)
348 Packet *temp_data_pkt;
350 if (type == CSMA_DATA_PKT) {
352 temp_data_pkt = (Q.front())->copy();
353 hdr_cmn *ch = HDR_CMN(temp_data_pkt);
354 ch->size() = HDR_size + ch->size();
356 temp_data_pkt = Packet::alloc();
357 hdr_cmn *ch = HDR_CMN(temp_data_pkt);
358 ch->size() = HDR_size + max_payload;
360 } else if (type == CSMA_ACK_PKT) {
361 temp_data_pkt = Packet::alloc();
362 hdr_cmn *ch = HDR_CMN(temp_data_pkt);
363 ch->size() = ACK_size;
365 duration = Mac2PhyTxDuration(temp_data_pkt);
366 Packet::free(temp_data_pkt);
371CsmaAloha::exitBackoff()
373 backoff_timer.stop();
377CsmaAloha::getBackoffTime()
379 incrTotalBackoffTimes();
380 double random = RNG::defaultrng()->uniform_double();
382 backoff_timer.incrCounter();
383 int counter = backoff_timer.getCounter();
384 if (counter > max_backoff_counter)
385 counter = max_backoff_counter;
387 double backoff_duration =
388 backoff_tuner * random * 2.0 * ACK_timeout * pow(2.0, counter);
389 backoffSumDuration(backoff_duration);
396 return backoff_duration;
400CsmaAloha::recvFromUpperLayers(Packet *p)
402 if (((has_buffer_queue == true) && (Q.size() < buffer_pkts)) ||
403 (has_buffer_queue == false)) {
404 initPkt(p, CSMA_DATA_PKT);
409 if (curr_state == CSMA_STATE_IDLE) {
410 refreshReason(CSMA_REASON_DATA_PENDING);
414 incrDiscardedPktsTx();
415 drop(p, 1, CSMA_DROP_REASON_BUFFER_FULL);
420CsmaAloha::initPkt(Packet *p, CSMA_PKT_TYPE type, int dest_addr)
422 hdr_cmn *ch = hdr_cmn::access(p);
423 hdr_mac *mach = HDR_MAC(p);
425 int curr_size = ch->size();
429 case (CSMA_DATA_PKT): {
430 ch->size() = curr_size + HDR_size;
431 data_sn_queue.push(u_data_id);
435 case (CSMA_ACK_PKT): {
436 ch->ptype() = PT_MMAC_ACK;
437 ch->size() = ACK_size;
438 ch->uid() = u_pkt_id++;
439 mach->set(MF_CONTROL, addr, dest_addr);
440 mach->macSA() = addr;
441 mach->macDA() = dest_addr;
447CsmaAloha::Mac2PhyStartTx(Packet *p)
453 MMac::Mac2PhyStartTx(p);
457CsmaAloha::Phy2MacEndTx(const Packet *p)
464 switch (curr_state) {
466 case (CSMA_STATE_TX_DATA): {
467 refreshReason(CSMA_REASON_DATA_TX);
468 if (ack_mode == CSMA_ACK_MODE) {
473 << status_info[curr_state] << " to
"
474 << status_info[CSMA_STATE_WAIT_ACK] << endl;
482 << status_info[curr_state] << " to
"
483 << status_info[CSMA_STATE_IDLE] << endl;
489 case (CSMA_STATE_TX_ACK): {
490 refreshReason(CSMA_REASON_ACK_TX);
492 if (prev_prev_state == CSMA_STATE_RX_BACKOFF) {
496 << status_info[curr_state] << " to
"
497 << status_info[CSMA_STATE_CHK_BACKOFF_TIMEOUT] << endl;
499 stateCheckBackoffExpired();
500 } else if (prev_prev_state == CSMA_STATE_RX_LISTEN) {
504 << status_info[curr_state] << " to
"
505 << status_info[CSMA_STATE_CHK_LISTEN_TIMEOUT] << endl;
507 stateCheckListenExpired();
508 } else if (prev_prev_state == CSMA_STATE_RX_IDLE) {
513 << status_info[curr_state] << " to
"
514 << status_info[CSMA_STATE_IDLE] << endl;
517 } else if (prev_prev_state == CSMA_STATE_RX_WAIT_ACK) {
521 << status_info[curr_state] << " to
"
522 << status_info[CSMA_STATE_IDLE] << endl;
523 stateCheckAckExpired();
527 << ")::
Phy2MacEndTx() logical error in timers, current
"
529 << status_info[curr_state] << endl;
537 << status_info[curr_state] << endl;
544CsmaAloha::Phy2MacStartRx(const Packet *p)
550 refreshReason(CSMA_REASON_START_RX);
552 switch (curr_state) {
554 case (CSMA_STATE_IDLE):
558 case (CSMA_STATE_LISTEN):
562 case (CSMA_STATE_BACKOFF):
566 case (CSMA_STATE_WAIT_ACK):
573 << status_info[curr_state] << endl;
580CsmaAloha::Phy2MacEndRx(Packet *p)
583 hdr_cmn *ch = HDR_CMN(p);
584 packet_t rx_pkt_type = ch->ptype();
585 hdr_mac *mach = HDR_MAC(p);
586 hdr_MPhy *ph = HDR_MPHY(p);
588 int source_mac = mach->macSA();
589 int dest_mac = mach->macDA();
591 double gen_time = ph->txtime;
592 double received_time = ph->rxtime;
593 double diff_time = received_time - gen_time;
595 double distance = diff_time * prop_speed;
599 << status_info[curr_state]
600 << ", received a pkt type =
" << ch->ptype()
601 << ", src addr =
" << mach->macSA()
602 << " dest addr =
" << mach->macDA()
603 << ", estimated distance between nodes =
" << distance << " m
"
613 refreshReason(CSMA_REASON_PKT_ERROR);
614 drop(p, 1, CSMA_DROP_REASON_ERROR);
615 stateRxPacketNotForMe(NULL);
617 if (dest_mac == addr || dest_mac == MAC_BROADCAST) {
618 if (rx_pkt_type == PT_MMAC_ACK) {
619 refreshReason(CSMA_REASON_ACK_RX);
621 } else if (curr_state != CSMA_STATE_RX_WAIT_ACK) {
622 refreshReason(CSMA_REASON_DATA_RX);
625 refreshReason(CSMA_REASON_PKT_NOT_FOR_ME);
626 stateRxPacketNotForMe(p);
629 refreshReason(CSMA_REASON_PKT_NOT_FOR_ME);
630 stateRxPacketNotForMe(p);
638 Packet *data_pkt = curr_data_pkt->copy();
640 if ((ack_mode == CSMA_NO_ACK_MODE)) {
646 Mac2PhyStartTx(data_pkt);
650CsmaAloha::txAck(int dest_addr)
652 Packet *ack_pkt = Packet::alloc();
653 initPkt(ack_pkt, CSMA_ACK_PKT, dest_addr);
656 Mac2PhyStartTx(ack_pkt);
660CsmaAloha::stateRxPacketNotForMe(Packet *p)
670 refreshState(CSMA_STATE_WRONG_PKT_RX);
672 switch (prev_state) {
674 case CSMA_STATE_RX_IDLE:
678 case CSMA_STATE_RX_LISTEN:
679 stateCheckListenExpired();
682 case CSMA_STATE_RX_BACKOFF:
683 stateCheckBackoffExpired();
686 case CSMA_STATE_RX_WAIT_ACK:
687 stateCheckAckExpired();
693 << status_info[curr_state] << endl;
699CsmaAloha::stateCheckListenExpired()
701 refreshState(CSMA_STATE_CHK_LISTEN_TIMEOUT);
706 if (print_transitions)
708 if (listen_timer.isActive()) {
709 refreshReason(CSMA_REASON_LISTEN_PENDING);
710 refreshState(CSMA_STATE_LISTEN);
711 } else if (listen_timer.isExpired()) {
712 refreshReason(CSMA_REASON_LISTEN_TIMEOUT);
713 if (!(prev_state == CSMA_STATE_TX_ACK ||
714 prev_state == CSMA_STATE_WRONG_PKT_RX ||
715 prev_state == CSMA_STATE_ACK_RX ||
716 prev_state == CSMA_STATE_DATA_RX))
723 "current timer state =
"
724 << status_info[curr_state] << endl;
730CsmaAloha::stateCheckAckExpired()
732 refreshState(CSMA_STATE_CHK_ACK_TIMEOUT);
737 if (print_transitions)
739 if (ack_timer.isActive()) {
740 refreshReason(CSMA_REASON_WAIT_ACK_PENDING);
741 refreshState(CSMA_STATE_WAIT_ACK);
742 } else if (ack_timer.isExpired()) {
743 refreshReason(CSMA_REASON_ACK_TIMEOUT);
749 << status_info[curr_state] << endl;
755CsmaAloha::stateCheckBackoffExpired()
757 refreshState(CSMA_STATE_CHK_BACKOFF_TIMEOUT);
762 if (print_transitions)
764 if (backoff_timer.isActive()) {
765 refreshReason(CSMA_REASON_BACKOFF_PENDING);
767 } else if (backoff_timer.isExpired()) {
768 refreshReason(CSMA_REASON_BACKOFF_TIMEOUT);
774 "current timer state =
"
775 << status_info[curr_state] << endl;
781CsmaAloha::stateIdle()
784 backoff_timer.stop();
788 refreshState(CSMA_STATE_IDLE);
790 if (print_transitions)
795 << ")::
stateIdle() queue size =
" << Q.size() << endl;
798 refreshReason(CSMA_REASON_LISTEN);
804CsmaAloha::stateRxIdle()
806 refreshState(CSMA_STATE_RX_IDLE);
808 if (print_transitions)
813CsmaAloha::stateListen()
816 refreshState(CSMA_STATE_LISTEN);
818 listen_timer.incrCounter();
821 listen_time * RNG::defaultrng()->uniform_double() + wait_costant;
825 << ")::
stateListen() listen time =
" << time << endl;
827 if (print_transitions)
830 listen_timer.schedule(time);
834CsmaAloha::stateRxListen()
836 refreshState(CSMA_STATE_RX_LISTEN);
838 if (print_transitions)
843CsmaAloha::stateBackoff()
845 refreshState(CSMA_STATE_BACKOFF);
847 if (backoff_timer.isFrozen())
848 backoff_timer.unFreeze();
850 backoff_timer.schedule(getBackoffTime());
854 if (print_transitions)
855 printStateInfo(backoff_timer.getDuration());
859CsmaAloha::stateRxBackoff()
861 backoff_timer.freeze();
862 refreshState(CSMA_STATE_RX_BACKOFF);
864 if (print_transitions)
869CsmaAloha::stateTxData()
871 refreshState(CSMA_STATE_TX_DATA);
875 if (print_transitions)
878 curr_data_pkt = Q.front();
880 if (data_sn_queue.front() != last_sent_data_id) {
882 ack_timer.resetCounter();
883 listen_timer.resetCounter();
884 backoff_timer.resetCounter();
886 if (curr_tx_rounds < max_tx_tries) {
887 hdr_mac *mach = HDR_MAC(curr_data_pkt);
889 mach->macSA() = addr;
891 last_sent_data_id = data_sn_queue.front();
897 refreshReason(CSMA_REASON_MAX_TX_TRIES);
909CsmaAloha::stateWaitAck()
912 refreshState(CSMA_STATE_WAIT_ACK);
916 if (print_transitions)
919 ack_timer.incrCounter();
920 ack_timer.schedule(ACK_timeout + 2 * wait_costant);
924CsmaAloha::stateRxWaitAck()
926 refreshState(CSMA_STATE_RX_WAIT_ACK);
928 if (print_transitions)
933CsmaAloha::stateTxAck(int dest_addr)
935 refreshState(CSMA_STATE_TX_ACK);
939 << dest_addr << endl;
940 if (print_transitions)
947CsmaAloha::stateRxData(Packet *data_pkt)
949 refreshState(CSMA_STATE_DATA_RX);
953 << status_info[curr_state] << endl;
954 refreshReason(CSMA_REASON_DATA_RX);
956 hdr_mac *mach = HDR_MAC(data_pkt);
957 int dst_addr = mach->macSA();
959 switch (prev_state) {
961 case CSMA_STATE_RX_IDLE: {
962 hdr_cmn *ch = hdr_cmn::access(data_pkt);
963 ch->size() = ch->size() - HDR_size;
967 if (ack_mode == CSMA_ACK_MODE)
968 stateTxAck(dst_addr);
973 case CSMA_STATE_RX_LISTEN: {
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);
982 stateCheckListenExpired();
985 case CSMA_STATE_RX_BACKOFF: {
986 hdr_cmn *ch = hdr_cmn::access(data_pkt);
987 ch->size() = ch->size() - HDR_size;
990 if (ack_mode == CSMA_ACK_MODE)
991 stateTxAck(dst_addr);
993 stateCheckBackoffExpired();
996 case CSMA_STATE_RX_WAIT_ACK: {
997 hdr_cmn *ch = hdr_cmn::access(data_pkt);
998 ch->size() = ch->size() - HDR_size;
1001 if (ack_mode == CSMA_ACK_MODE)
1002 stateTxAck(dst_addr);
1004 stateCheckAckExpired();
1010 << ")::
stateRxData() logical error, prev state =
"
1011 << status_info[prev_state] << endl;
1016CsmaAloha::stateRxAck(Packet *p)
1019 refreshState(CSMA_STATE_ACK_RX);
1025 refreshReason(CSMA_REASON_ACK_RX);
1027 switch (prev_state) {
1029 case CSMA_STATE_RX_IDLE:
1033 case CSMA_STATE_RX_LISTEN:
1034 stateCheckListenExpired();
1037 case CSMA_STATE_RX_BACKOFF:
1038 stateCheckBackoffExpired();
1041 case CSMA_STATE_RX_WAIT_ACK:
1043 updateAckTimeout(NOW - start_tx_time);
1051 << ")::
stateRxAck() logical error, prev state =
"
1052 << status_info[prev_state] << endl;
1057CsmaAloha::printStateInfo(double delay)
1061 << "from
" << status_info[prev_state] << " to
"
1062 << status_info[curr_state]
1063 << ". Reason:
" << reason_info[last_reason] << endl;
1065 if (curr_state == CSMA_STATE_BACKOFF) {
1066 fout << left << setw(10) << NOW << " CsmaAloha(
" << addr
1068 << "from
" << status_info[prev_state] << " to
"
1069 << status_info[curr_state]
1070 << ". Reason:
" << reason_info[last_reason]
1071 << ". Backoff duration =
" << delay << endl;
1073 fout << left << setw(10) << NOW << " CsmaAloha(
" << addr
1075 << "from
" << status_info[prev_state] << " to
"
1076 << status_info[curr_state]
1077 << ". Reason:
" << reason_info[last_reason] << endl;
1082CsmaAloha::waitForUser()
1084 std::string response;
1085 std::cout << "Press Enter to continue
";
1086 std::getline(std::cin, response);
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.
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.
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
double alpha_
smooth factor in the calculation of the RTT
@ CSMA_REASON_BACKOFF_TIMEOUT
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 refreshReason(CSMA_REASON_STATUS reason)
Refresh the reason for the change of state.
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.
CsmaAloha()
Constructor of the CsmaAloha class.
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.
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.
virtual void stateBackoff()
BackOff STATE.
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.
ListenTimer listen_timer
Object that represents the listen timer.
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.
int curr_tx_rounds
Number of current transmission of the same packet.
virtual void Mac2PhyStartTx(Packet *p)
Pass the packet to the PHY layer.
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.
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.