DESERT 3.5.1
Loading...
Searching...
No Matches
uwaloha.cpp
Go to the documentation of this file.
1//
2// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova.
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions
7// are met:
8// 1. Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// 2. Redistributions in binary form must reproduce the above copyright
11// notice, this list of conditions and the following disclaimer in the
12// documentation and/or other materials provided with the distribution.
13// 3. Neither the name of the University of Padova (SIGNET lab) nor the
14// names of its contributors may be used to endorse or promote products
15// derived from this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
37#include "uwaloha.h"
38#include <mac.h>
39#include <cmath>
40#include <climits>
41#include <iomanip>
42#include <rng.h>
43
45
49static class UWALOHAModuleClass : public TclClass
50{
51public:
56 : TclClass("Module/UW/ALOHA")
57 {
58 }
59
60 TclObject *
61 create(int, const char *const *)
62 {
63 return (new UWAloha());
64 }
66
67void
69{
71 if (module->curr_state == UWALOHA_STATE_WAIT_ACK) {
72
73 if (module->uwaloha_debug)
74 cout << NOW << " UWAloha (" << module->addr
75 << ") timer expire() current state = "
76 << module->status_info[module->curr_state]
77 << "; ACK not received, next state = "
78 << module->status_info[UWALOHA_STATE_BACKOFF] << endl;
79
80 module->refreshReason(UWALOHA_REASON_ACK_TIMEOUT);
81 module->stateBackoff();
82 } else {
83 if (module->uwaloha_debug)
84 cout << NOW << " UWAloha (" << module->addr
85 << ")::AckTimer::expired() " << endl;
86 }
87}
88
89void
90UWAloha::BackOffTimer::expire(Event *e)
91{
92 timer_status = UWALOHA_EXPIRED;
93 if (module->curr_state == UWALOHA_STATE_BACKOFF) {
94
95 if (module->uwaloha_debug)
96 cout << NOW << " UWAloha (" << module->addr
97 << ") timer expire() current state = "
98 << module->status_info[module->curr_state]
99 << "; backoff expired, next state = "
100 << module->status_info[UWALOHA_STATE_IDLE] << endl;
101
103 module->exitBackoff();
104 module->stateIdle();
105 } else {
106 if (module->uwaloha_debug)
107 cout << NOW << " UWAloha (" << module->addr
108 << ")::BackOffTimer::expired() " << endl;
109 }
110}
111
112const double UWAloha::prop_speed = 1500.0;
113bool UWAloha::initialized = false;
114
115map<UWAloha::UWALOHA_STATUS, string> UWAloha::status_info;
116map<UWAloha::UWALOHA_REASON_STATUS, string> UWAloha::reason_info;
117map<UWAloha::UWALOHA_PKT_TYPE, string> UWAloha::pkt_type_info;
118
120 : ack_timer(this)
121 , backoff_timer(this)
122 , txsn(1)
124 , curr_data_pkt(0)
126 , curr_tx_rounds(0)
127 , print_transitions(false)
128 , has_buffer_queue(true)
134 , start_tx_time(0)
135 , recv_data_id(-1)
136 , srtt(0)
137 , sumrtt(0)
138 , sumrtt2(0)
139 , rttsamples(0)
140{
141 mac2phy_delay_ = 1e-19;
142
143 bind("HDR_size_", (int *) &HDR_size);
144 bind("ACK_size_", (int *) &ACK_size);
145 bind("max_tx_tries_", (int *) &max_tx_tries);
146 bind("wait_constant_", (double *) &wait_constant);
147 bind("uwaloha_debug_", (int *) &uwaloha_debug); // degug mode
148 bind("max_payload_", (int *) &max_payload);
149 bind("ACK_timeout_", (int *) &ACK_timeout);
150 bind("alpha_", (double *) &alpha_);
151 bind("buffer_pkts_", (int *) &buffer_pkts);
152 bind("backoff_tuner_", (double *) &backoff_tuner);
153 bind("max_backoff_counter_", (int *) &max_backoff_counter);
154 // bind("MAC_addr_", (int*)&addr);
155
156 if (max_tx_tries <= 0)
157 max_tx_tries = INT_MAX;
158 if (buffer_pkts > 0)
159 has_buffer_queue = true;
160}
161
165
166// TCL command interpreter
167
168int
169UWAloha::command(int argc, const char *const *argv)
170{
171 Tcl &tcl = Tcl::instance();
172 if (argc == 2) {
173 if (strcasecmp(argv[1], "setAckMode") == 0) {
175 return TCL_OK;
176 } else if (strcasecmp(argv[1], "setNoAckMode") == 0) {
178 return TCL_OK;
179 } else if (strcasecmp(argv[1], "initialize") == 0) {
180 if (initialized == false)
181 initInfo();
183 fout.open("/tmp/ALOHAstateTransitions.txt", ios_base::app);
184 return TCL_OK;
185 } else if (strcasecmp(argv[1], "printTransitions") == 0) {
186 print_transitions = true;
187 return TCL_OK;
188 } // stats functions
189 else if (strcasecmp(argv[1], "getQueueSize") == 0) {
190 tcl.resultf("%d", mapPacket.size());
191 return TCL_OK;
192 } else if (strcasecmp(argv[1], "getUpLayersDataRx") == 0) {
193 tcl.resultf("%d", getUpLayersDataPktsRx());
194 return TCL_OK;
195 }
196 } else if (argc == 3) {
197 if (strcasecmp(argv[1], "setMacAddr") == 0) {
198 addr = atoi(argv[2]);
199 if (debug_)
200 cout << "Aloha MAC address of current node is " << addr << endl;
201 return TCL_OK;
202 }
203 }
204 return MMac::command(argc, argv);
205}
206
207void
209{
210
211 initialized = true;
212
213 if ((print_transitions) && (system(NULL))) {
214 system("rm -f /tmp/ALOHAstateTransitions.txt");
215 system("touch /tmp/ALOHAstateTransitions.txt");
216 }
217
218 status_info[UWALOHA_STATE_IDLE] = "Idle state";
219 status_info[UWALOHA_STATE_TX_DATA] = "Transmit DATA state";
220 status_info[UWALOHA_STATE_TX_ACK] = "Transmit ACK state";
221 status_info[UWALOHA_STATE_WAIT_ACK] = "Wait for ACK state";
222 status_info[UWALOHA_STATE_DATA_RX] = "DATA received state";
223 status_info[UWALOHA_STATE_ACK_RX] = "ACK received state";
224 status_info[UWALOHA_STATE_RX_IDLE] = "Start rx Idle state";
225 status_info[UWALOHA_STATE_RX_WAIT_ACK] = "Start rx Wait ACK state";
226 status_info[UWALOHA_STATE_CHK_ACK_TIMEOUT] = "Check Wait ACK timeout state";
227 status_info[UWALOHA_STATE_WRONG_PKT_RX] = "Wrong Pkt Rx state";
228 status_info[UWALOHA_STATE_BACKOFF] = "Backoff state";
229 status_info[UWALOHA_STATE_RX_BACKOFF] = "Start rx Backoff state";
231 "Check Backoff timeout state";
232
233 reason_info[UWALOHA_REASON_DATA_PENDING] = "DATA pending from upper layers";
234 reason_info[UWALOHA_REASON_DATA_RX] = "DATA received";
235 reason_info[UWALOHA_REASON_DATA_TX] = "DATA transmitted";
236 reason_info[UWALOHA_REASON_ACK_TX] = "ACK tranmsitted";
237 reason_info[UWALOHA_REASON_ACK_RX] = "ACK received";
239 reason_info[UWALOHA_REASON_DATA_EMPTY] = "DATA queue empty";
241 "DATA dropped due to max tx rounds";
242 reason_info[UWALOHA_REASON_START_RX] = "Start rx pkt";
243 reason_info[UWALOHA_REASON_PKT_NOT_FOR_ME] = "Received an erroneous pkt";
244 reason_info[UWALOHA_REASON_WAIT_ACK_PENDING] = "Wait for ACK timer pending";
245 reason_info[UWALOHA_REASON_PKT_ERROR] = "Erroneous pkt";
246 reason_info[UWALOHA_REASON_BACKOFF_TIMEOUT] = "Backoff expired";
247 reason_info[UWALOHA_REASON_BACKOFF_PENDING] = "Backoff timer pending";
248
249 pkt_type_info[UWALOHA_ACK_PKT] = "ACK pkt";
250 pkt_type_info[UWALOHA_DATA_PKT] = "DATA pkt";
251 pkt_type_info[UWALOHA_DATAMAX_PKT] = "MAX payload DATA pkt";
252}
253
254void
255UWAloha::updateRTT(double curr_rtt)
256{
257 srtt = alpha_ * srtt + (1 - alpha_) * curr_rtt;
258 sumrtt += curr_rtt;
259 sumrtt2 += curr_rtt * curr_rtt;
260 rttsamples++;
262}
263
264void
266{
267 updateRTT(rtt);
268 // double curr_rtt = getRTT();
269
270 // if (curr_rtt > 0) ACK_timeout = min(ACK_timeout, getRTT() );
271
272 if (uwaloha_debug)
273 cout << NOW << " UWAloha (" << addr
274 << ")::updateAckTimeout() curr ACK_timeout = " << ACK_timeout
275 << endl;
276 // waitForUser();
277}
278
279void
284
285double
287{
288 incrTotalBackoffTimes();
289 double random = RNG::defaultrng()->uniform_double();
290
295
296 double backoff_duration =
297 backoff_tuner * random * 2.0 * ACK_timeout * pow(2.0, counter);
298
299 backoffSumDuration(backoff_duration);
300
301 if (uwaloha_debug) {
302 cout << NOW << " UWAloha (" << addr
303 << ")::getBackoffTime() backoff time = " << backoff_duration
304 << " s" << endl;
305 }
306 return backoff_duration;
307}
308
309double
311{
312 double duration;
313 Packet *temp_data_pkt;
314 map<pktSeqNum, Packet *>::iterator it_p;
315
316 if (type == UWALOHA_DATA_PKT) {
317 if (!mapPacket.empty()) {
318 it_p = mapPacket.begin();
319 temp_data_pkt = ((*it_p).second)->copy();
320 // temp_data_pkt = (Q.front())->copy();
321 hdr_cmn *ch = HDR_CMN(temp_data_pkt);
322 ch->size() = HDR_size + ch->size();
323 } else {
324 temp_data_pkt = Packet::alloc();
325 hdr_cmn *ch = HDR_CMN(temp_data_pkt);
326 ch->size() = HDR_size + max_payload;
327 }
328 } else if (type == UWALOHA_ACK_PKT) {
329 temp_data_pkt = Packet::alloc();
330 hdr_cmn *ch = HDR_CMN(temp_data_pkt);
331 ch->size() = ACK_size;
332 }
333 duration = Mac2PhyTxDuration(temp_data_pkt);
334 Packet::free(temp_data_pkt);
335 return (duration);
336}
337
338void
340{
341 if (((has_buffer_queue == true) && (mapPacket.size() < buffer_pkts)) ||
342 (has_buffer_queue == false)) {
344 // Q.push(p);
345 putPktInQueue(p);
347 waitStartTime();
348
351 stateTxData();
352
353 // /* if (uwaloha_debug) */
354 // cerr << showpoint << NOW << " " << __PRETTY_FUNCTION__
355 // << " mac busy => enqueueing packet" << endl;
356 } else {
357 // /* if (uwaloha_debug) */
358 // cerr << showpoint << NOW << " " << __PRETTY_FUNCTION__
359 // << " transmitting packet" << endl;
360 return; // I'm still waiting to go to IDLE status.
361 }
362 } else {
363 incrDiscardedPktsTx();
365 }
366}
367
368void
369UWAloha::initPkt(Packet *p, UWALOHA_PKT_TYPE type, int dest_addr)
370{
371 hdr_cmn *ch = hdr_cmn::access(p);
372 hdr_mac *mach = HDR_MAC(p);
373
374 int curr_size = ch->size();
375
376 switch (type) {
377
378 case (UWALOHA_DATA_PKT): {
379 ch->size() = curr_size + HDR_size;
380 } break;
381
382 case (UWALOHA_ACK_PKT): {
383 ch->ptype() = PT_MMAC_ACK;
384 ch->size() = ACK_size;
385 ch->uid() = recv_data_id;
386 mach->macSA() = addr;
387 mach->macDA() = dest_addr;
388 } break;
389 }
390}
391
392void
394{
395 if (uwaloha_debug)
396 cout << NOW << " UWAloha (" << addr
397 << ")::Mac2PhyStartTx() start tx packet" << endl;
398
399 MMac::Mac2PhyStartTx(p);
400}
401
402void
403UWAloha::Phy2MacEndTx(const Packet *p)
404{
405
406 if (uwaloha_debug)
407 cout << NOW << " UWAloha (" << addr
408 << ")::Phy2MacEndTx() end tx packet" << endl;
409
410 switch (curr_state) {
411
412 case (UWALOHA_STATE_TX_DATA): {
414 if (ack_mode == UWALOHA_ACK_MODE) {
415
416 if (uwaloha_debug)
417 cout << NOW << " UWAloha (" << addr
418 << ")::Phy2MacEndTx() DATA sent,from "
419 << status_info[curr_state] << " to "
421
422 stateWaitAck();
423 } else {
424
425 if (uwaloha_debug)
426 cout << NOW << " UWAloha (" << addr
427 << ")::Phy2MacEndTx() DATA sent, from "
428 << status_info[curr_state] << " to "
430
431 stateIdle();
432 }
433 } break;
434
435 case (UWALOHA_STATE_TX_ACK): {
437
438 if (uwaloha_debug)
439 cout << NOW << " UWAloha (" << addr
440 << ")::Phy2MacEndTx() ack sent, from "
441 << status_info[curr_state] << " to "
443 stateIdle();
444 } break;
445
446 default: {
447 cout << NOW << " UWAloha (" << addr
448 << ")::Phy2MacEndTx() logical error, current state = "
449 << status_info[curr_state] << endl;
450 stateIdle();
451 // exit(1);
452 } break;
453 }
454}
455
456void
458{
459 if (uwaloha_debug)
460 cout << NOW << " UWAloha (" << addr << ")::Phy2MacStartRx() rx Packet "
461 << endl;
462}
463
464void
466{
467 hdr_cmn *ch = HDR_CMN(p);
468 packet_t rx_pkt_type = ch->ptype();
469 hdr_mac *mach = HDR_MAC(p);
470 hdr_MPhy *ph = HDR_MPHY(p);
471
472 int source_mac = mach->macSA();
473 int dest_mac = mach->macDA();
474
475 double gen_time = ph->txtime;
476 double received_time = ph->rxtime;
477 double diff_time = received_time - gen_time;
478
479 double distance = diff_time * prop_speed;
480
481 if (uwaloha_debug)
482 cout << NOW << " UWAloha (" << addr << ")::Phy2MacEndRx() "
484 << ", received a pkt type = " << ch->ptype()
485 << ", src addr = " << mach->macSA()
486 << " dest addr = " << mach->macDA()
487 << ", estimated distance between nodes = " << distance << " m "
488 << endl;
489
490 if (ch->error()) {
491
492 if (uwaloha_debug)
493 cout << NOW << " UWAloha (" << addr
494 << ")::Phy2MacEndRx() dropping corrupted pkt " << endl;
495 incrErrorPktsRx();
496
498 drop(p, 1, UWALOHA_DROP_REASON_ERROR);
499 return;
500 } else {
501 if (dest_mac == addr || dest_mac == MAC_BROADCAST) {
502 if (rx_pkt_type == PT_MMAC_ACK) {
504 stateRxAck(p);
505 } else if (curr_state != UWALOHA_STATE_WAIT_ACK) {
507 stateRxData(p);
508 } else {
510 // Packet::free(p);
512 return;
513 }
514 } else {
516 // Packet::free(p);
518 return;
519 }
520 }
521}
522
523void
525{
526 Packet *data_pkt = curr_data_pkt->copy();
527
528 if ((ack_mode == UWALOHA_NO_ACK_MODE)) {
530 }
531
532 incrDataPktsTx();
534 Mac2PhyStartTx(data_pkt);
535}
536
537void
538UWAloha::txAck(int dest_addr)
539{
540 Packet *ack_pkt = Packet::alloc();
541 initPkt(ack_pkt, UWALOHA_ACK_PKT, dest_addr);
542
543 incrAckPktsTx();
544 Mac2PhyStartTx(ack_pkt);
545}
546
547void
549{
551
552 if (uwaloha_debug)
553 cout << NOW << " UWAloha (" << addr << ")::stateCheckAckExpired()"
554 << endl;
555
556 map<pktSeqNum, AckTimer>::iterator it_a;
557 it_a = mapAckTimer.begin();
558
561 if (((*it_a).second).isActive()) {
564 } else if (((*it_a).second).isExpired()) {
566 stateBackoff();
567 } else {
568 cerr << NOW << " UWAloha (" << addr
569 << ")::stateCheckAckExpired() ack_timer logical error, current "
570 "timer state = "
571 << status_info[curr_state] << endl;
572 stateIdle();
573 // exit(1);
574 }
575}
576
577void
579{
581
582 if (uwaloha_debug)
583 cout << NOW << " UWAloha (" << addr << ")::stateCheckBackoffExpired()"
584 << endl;
587 if (backoff_timer.isActive()) {
589 stateBackoff();
590 } else if (backoff_timer.isExpired()) {
592 exitBackoff();
593 stateIdle();
594 } else {
595 cerr << NOW << " UWAloha (" << addr
596 << ")::stateCheckBackoffExpired() backoff_timer logical error, "
597 "current timer state = "
598 << status_info[curr_state] << endl;
599 stateIdle();
600 // exit(1);
601 }
602}
603
604void
606{
607 mapAckTimer.clear();
609
610 if (uwaloha_debug)
611 cout << NOW << " UWAloha (" << addr
612 << ")::stateIdle() queue size = " << mapPacket.size() << endl;
613
615
618
619 if (!mapPacket.empty()) {
620 stateTxData();
621 }
622}
623
624void
632
633void
635{
636 backoff_timer.force_cancel();
638
641 else
643
644 if (uwaloha_debug)
645 cout << NOW << " UWAloha (" << addr << ")::stateBackoff() " << endl;
648}
649
650void
659
660void
662{
664
665 if (uwaloha_debug)
666 cout << NOW << " UWAloha (" << addr << ")::stateTxData() " << endl;
669
670 map<pktSeqNum, Packet *>::iterator it_p;
671 it_p = mapPacket.begin();
672 curr_data_pkt = (*it_p).second;
673 int seq_num;
674 seq_num = getPktSeqNum(curr_data_pkt);
675
676 map<pktSeqNum, AckTimer>::iterator it_a;
677
678 if (seq_num != last_sent_data_id) {
679 putAckTimerInMap(seq_num);
680 it_a = mapAckTimer.find(seq_num);
683 ((*it_a).second).resetCounter();
684 hdr_mac *mach = HDR_MAC(curr_data_pkt);
685 start_tx_time = NOW; // we set curr RTT
686 last_sent_data_id = seq_num;
687 txData();
688 } else {
689
690 if (mapAckTimer.size() == 0) {
691 putAckTimerInMap(seq_num);
692 it_a = mapAckTimer.find(seq_num);
693 ((*it_a).second).resetCounter();
697 hdr_mac *mach = HDR_MAC(curr_data_pkt);
698 start_tx_time = NOW; // we set curr RTT
699 last_sent_data_id = seq_num;
700 txData();
701 } else {
702 eraseItemFromPktQueue(seq_num);
703 incrDroppedPktsTx();
704
706
707 if (uwaloha_debug)
708 cout << NOW << " UWAloha (" << addr
709 << ")::statePreTxData() curr_tx_rounds "
711 << " > max_tx_tries = " << max_tx_tries << endl;
712
713 stateIdle();
714 }
715 } else {
717 }
718 }
719}
720
721void
723{
724
725 map<pktSeqNum, AckTimer>::iterator it_a;
726 it_a = mapAckTimer.begin();
727
728 ((*it_a).second).stop();
730
731 if (uwaloha_debug)
732 cout << NOW << " UWAloha (" << addr << ")::stateWaitAck() " << endl;
735
736 ((*it_a).second).incrCounter();
737 ((*it_a).second).schedule(ACK_timeout + 2 * wait_constant);
738}
739
740void
748
749void
751{
753
754 if (uwaloha_debug)
755 cout << NOW << " UWAloha (" << addr << ")::stateTxAck() dest addr "
756 << dest_addr << endl;
759
760 txAck(dest_addr);
761}
762
763void
764UWAloha::stateRxData(Packet *data_pkt)
765{
766 ack_timer.stop();
768
769 if (uwaloha_debug)
770 cout << NOW << " UWAloha (" << addr << ")::stateRxData() " << endl;
772
773 hdr_mac *mach = HDR_MAC(data_pkt);
774 int dst_addr = mach->macSA();
775
776 hdr_cmn *ch = hdr_cmn::access(data_pkt);
777 recv_data_id = ch->uid();
778 ch->size() = ch->size() - HDR_size;
779 incrDataPktsRx();
780 sendUp(data_pkt);
781
783 stateTxAck(dst_addr);
784 else
785 stateIdle();
786}
787
788void
790{
791
792 map<pktSeqNum, AckTimer>::iterator it_a;
793 it_a = mapAckTimer.begin();
794
795 ((*it_a).second).stop();
797 if (uwaloha_debug)
798 cout << NOW << " UWAloha (" << addr << ")::stateRxAck() " << endl;
799
800 int seq_num;
801 seq_num = getPktSeqNum(p);
802
803 Packet::free(p);
804
806
807 eraseItemFromPktQueue(seq_num);
810 incrAckPktsRx();
811 stateIdle();
812}
813
814void
816{
817 if (uwaloha_debug)
818 cout << NOW << " UWAloha (" << addr << ")::printStateInfo() "
819 << "from " << status_info[prev_state] << " to "
821 << ". Reason: " << reason_info[last_reason] << endl;
822
824 fout << left << setw(10) << NOW << " UWAloha (" << addr
825 << ")::printStateInfo() "
826 << "from " << status_info[prev_state] << " to "
828 << ". Reason: " << reason_info[last_reason]
829 << ". Backoff duration = " << delay << endl;
830 } else {
831 fout << left << setw(10) << NOW << " UWAloha (" << addr
832 << ")::printStateInfo() "
833 << "from " << status_info[prev_state] << " to "
835 << ". Reason: " << reason_info[last_reason] << endl;
836 }
837}
838
839void
841{
842 std::string response;
843 std::cout << "Press Enter to continue";
844 std::getline(std::cin, response);
845}
Class that describe the binding with tcl scripting language.
Definition uwaloha.cpp:50
UWALOHAModuleClass()
Constructor of the class.
Definition uwaloha.cpp:55
TclObject * create(int, const char *const *)
Definition uwaloha.cpp:61
virtual void expire(Event *e)
What a node is going to do when a timer expire.
Definition uwaloha.cpp:68
virtual void unFreeze()
It starts the timer from where it was stopped.
Definition uwaloha.h:215
double getDuration()
This methods provide the duration of a timer.
Definition uwaloha.h:332
virtual void stop()
Stop the timer any way.
Definition uwaloha.h:228
int getCounter()
It provides, how many times a timer ran.
Definition uwaloha.h:322
virtual void freeze()
It freezes or in another word, it stops the timer for some time.
Definition uwaloha.h:201
void resetCounter()
Reset the timer counter.
Definition uwaloha.h:302
UWAloha *UWALOHA_TIMER_STATUS timer_status
< Pointer of UWAloha module.
Definition uwaloha.h:346
virtual void schedule(double val)
Schedule the time, i.e., how long a timer is going to run.
Definition uwaloha.h:239
void incrCounter()
Increment the timer counter.
Definition uwaloha.h:312
bool isActive()
It tells whether the timer is active or not.
Definition uwaloha.h:292
bool isExpired()
Tells whether the timer is expired or not.
Definition uwaloha.h:272
bool isFrozen()
It tells whether the timer is in freeze mode or not.
Definition uwaloha.h:282
This is the base class of UWAloha protocol, which is a derived class of MMac.
Definition uwaloha.h:69
void putAckTimerInMap(int seq_num)
Put acknowledgement timer in the container.
Definition uwaloha.h:693
int rttsamples
Number of RTT samples.
Definition uwaloha.h:772
int txsn
Sequence number of the packet which is transmitted.
Definition uwaloha.h:781
static map< UWALOHA_STATUS, string > status_info
Container which stores all the status information.
Definition uwaloha.h:802
double start_tx_time
Time when a packet start transmitting.
Definition uwaloha.h:768
virtual void waitForUser()
Definition uwaloha.cpp:840
static map< UWALOHA_REASON_STATUS, string > reason_info
Container which stores all the reason information.
Definition uwaloha.h:806
UWALOHA_STATUS prev_prev_state
Enum variable.
Definition uwaloha.h:796
BackOffTimer backoff_timer
An object of the backoff timer class.
Definition uwaloha.h:786
void eraseItemFromPktQueue(int seq_num)
It erases the packet from the container.
Definition uwaloha.h:677
virtual ~UWAloha()
Destructor of UWAloha Class.
Definition uwaloha.cpp:162
UWAloha()
Constructor of UWAloha Class.
Definition uwaloha.cpp:119
static bool initialized
It checks whether UWAloha protocol is initialized or not.
Definition uwaloha.h:756
virtual void stateTxData()
If a node has packet to transmits.
Definition uwaloha.cpp:661
int max_payload
Maximum number of payload in a packet.
Definition uwaloha.h:744
@ UWALOHA_EXPIRED
Definition uwaloha.h:161
@ UWALOHA_NO_ACK_MODE
Definition uwaloha.h:151
@ UWALOHA_ACK_MODE
Definition uwaloha.h:151
int last_sent_data_id
sequence number of the last sent packet
Definition uwaloha.h:761
virtual void txData()
This method transmits Data packets from MAC layer to PHY layer.
Definition uwaloha.cpp:524
virtual void Phy2MacStartRx(const Packet *p)
PHY layer informs the MAC layer that it is receiving a packet.
Definition uwaloha.cpp:457
virtual void stateRxData(Packet *p)
It process the packet which is received.
Definition uwaloha.cpp:764
virtual void stateRxAck(Packet *p)
The node comes to this state if it receives an ACK packet.
Definition uwaloha.cpp:789
UWALOHA_PKT_TYPE
Enumeration class of UWAloha packet type.
Definition uwaloha.h:139
@ UWALOHA_ACK_PKT
Definition uwaloha.h:140
@ UWALOHA_DATAMAX_PKT
Definition uwaloha.h:142
@ UWALOHA_DATA_PKT
Definition uwaloha.h:141
bool print_transitions
Whether to print the state of the nodes.
Definition uwaloha.h:763
int buffer_pkts
Number of packets a node can store in the container.
Definition uwaloha.h:748
double srtt
Smoothed Round Trip Time, calculated as for TCP.
Definition uwaloha.h:769
virtual void stateWaitAck()
After transmitting a Data packet, a node waits for the ACK packet.
Definition uwaloha.cpp:722
UWALOHA_STATUS prev_state
Enum variable.
Definition uwaloha.h:794
virtual void stateCheckAckExpired()
It checks whether the ack timer is already expired while it was busy with other activities.
Definition uwaloha.cpp:548
double ACK_timeout
ACK timeout for the initial packet.
Definition uwaloha.h:747
double backoff_tuner
Tunes the backoff duration.
Definition uwaloha.h:743
virtual void stateIdle()
Node is in Idle state.
Definition uwaloha.cpp:605
int getUpLayersDataPktsRx()
Definition uwaloha.h:734
virtual void resetCurrTxRounds()
If a node is going to transmit a new packet, it resets the tx counter.
Definition uwaloha.h:609
virtual void updateRTT(double rtt)
Update the Round Trip Time (RTT) which is necessary to compute the acknowledgement duration as well a...
Definition uwaloha.cpp:255
@ UWALOHA_REASON_BACKOFF_PENDING
Definition uwaloha.h:132
@ UWALOHA_REASON_DATA_PENDING
Definition uwaloha.h:118
@ UWALOHA_REASON_DATA_EMPTY
Definition uwaloha.h:124
@ UWALOHA_REASON_WAIT_ACK_PENDING
Definition uwaloha.h:129
@ UWALOHA_REASON_DATA_TX
Definition uwaloha.h:120
@ UWALOHA_REASON_START_RX
Definition uwaloha.h:127
@ UWALOHA_REASON_BACKOFF_TIMEOUT
Definition uwaloha.h:131
@ UWALOHA_REASON_MAX_TX_TRIES
Definition uwaloha.h:126
@ UWALOHA_REASON_ACK_TX
Definition uwaloha.h:121
@ UWALOHA_REASON_NOT_SET
Definition uwaloha.h:125
@ UWALOHA_REASON_ACK_TIMEOUT
Definition uwaloha.h:123
@ UWALOHA_REASON_ACK_RX
Definition uwaloha.h:122
@ UWALOHA_REASON_PKT_ERROR
Definition uwaloha.h:130
@ UWALOHA_REASON_PKT_NOT_FOR_ME
Definition uwaloha.h:128
@ UWALOHA_REASON_DATA_RX
Definition uwaloha.h:119
virtual void initInfo()
This function is used to initialize the UWAloha protocol.
Definition uwaloha.cpp:208
virtual double computeTxTime(UWALOHA_PKT_TYPE type)
Compute the transmission time of a packet.
Definition uwaloha.cpp:310
int curr_tx_rounds
How many times a packet is transmitted.
Definition uwaloha.h:774
virtual void stateCheckBackoffExpired()
It checks whether the backoff timer is already expired while it was busy with other activities.
Definition uwaloha.cpp:578
virtual void stateRxIdle()
If a node start receiving a packet in Idle state.
Definition uwaloha.cpp:625
UWALOHA_STATUS curr_state
Enum variable.
Definition uwaloha.h:791
@ UWALOHA_STATE_TX_ACK
Definition uwaloha.h:100
@ UWALOHA_STATE_CHK_ACK_TIMEOUT
Definition uwaloha.h:105
@ UWALOHA_STATE_RX_BACKOFF
Definition uwaloha.h:109
@ UWALOHA_STATE_ACK_RX
Definition uwaloha.h:103
@ UWALOHA_STATE_RX_WAIT_ACK
Definition uwaloha.h:107
@ UWALOHA_STATE_TX_DATA
Definition uwaloha.h:99
@ UWALOHA_STATE_IDLE
Definition uwaloha.h:97
@ UWALOHA_STATE_BACKOFF
Definition uwaloha.h:98
@ UWALOHA_STATE_DATA_RX
Definition uwaloha.h:102
@ UWALOHA_STATE_WAIT_ACK
Definition uwaloha.h:101
@ UWALOHA_STATE_CHK_BACKOFF_TIMEOUT
Definition uwaloha.h:108
@ UWALOHA_STATE_WRONG_PKT_RX
Definition uwaloha.h:110
@ UWALOHA_STATE_RX_IDLE
Definition uwaloha.h:106
double sumrtt
Sum of RTT samples.
Definition uwaloha.h:770
virtual void Phy2MacEndTx(const Packet *p)
It infroms that a packet transmission end.
Definition uwaloha.cpp:403
int getPktSeqNum(Packet *p)
This method is used to get the sequence number from a packet.
Definition uwaloha.h:653
virtual void stateRxBackoff()
If a node start receiving a packet when it is in backoff state.
Definition uwaloha.cpp:651
virtual void exitBackoff()
It stops the backoff timer.
Definition uwaloha.cpp:280
int last_data_id_rx
The sequence number of last received packet.
Definition uwaloha.h:775
int max_backoff_counter
Maximum number of backoff it will consider while it increases the backoff exponentially.
Definition uwaloha.h:750
virtual void Phy2MacEndRx(Packet *p)
PHY layer informs the MAC layer that the reception of the packet is over.
Definition uwaloha.cpp:465
static const double prop_speed
Speed of the sound signal.
Definition uwaloha.h:783
bool has_buffer_queue
Whether the node has buffer to store data or not.
Definition uwaloha.h:765
virtual double getBackoffTime()
This function calculates the backoff duration and return the backoff time.It employs the exponential ...
Definition uwaloha.cpp:286
virtual void incrCurrTxRounds()
Increments the current transmission round of a packet.
Definition uwaloha.h:600
void putPktInQueue(Packet *p)
A node receives packet(s) from upper layer and store them in the container.
Definition uwaloha.h:667
AckTimer ack_timer
An object of the AckTimer class.
Definition uwaloha.h:785
virtual void Mac2PhyStartTx(Packet *p)
It informs that a packet transmission started.
Definition uwaloha.cpp:393
map< pktSeqNum, AckTimer > mapAckTimer
Container where acknowledgement timer(s) is stored.
Definition uwaloha.h:814
UWALOHA_ACK_MODES ack_mode
Enum variable.
Definition uwaloha.h:800
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
Definition uwaloha.cpp:169
int max_tx_tries
Maximum number of transmissions for one packet.
Definition uwaloha.h:740
static map< UWALOHA_PKT_TYPE, string > pkt_type_info
Container which stores all the packet type information of UWAloha.
Definition uwaloha.h:809
UWALOHA_REASON_STATUS last_reason
Enum variable which stores the last reason why a node changes its state.
Definition uwaloha.h:789
virtual void stateBackoff()
If ACK packet is not received within the acknowledgement expire time.
Definition uwaloha.cpp:634
virtual void initPkt(Packet *p, UWALOHA_PKT_TYPE pkt_type, int dest_addr=0)
This method, initialize the packet.
Definition uwaloha.cpp:369
void eraseItemFrommapAckTimer(int seq_num)
Erase an item from acknowledgement stored container.
Definition uwaloha.h:703
int ACK_size
Size of the ACK, if the node uses ARQ technique.
Definition uwaloha.h:746
double sumrtt2
Sum of (RTT^2)
Definition uwaloha.h:771
virtual void stateRxWaitAck()
If a node receives any packet while it was waiting for ACK packet, it moves to this state.
Definition uwaloha.cpp:741
int recv_data_id
The sequence number of the packet which is received.
Definition uwaloha.h:776
double wait_constant
This fixed time is used to componsate different time variations.
Definition uwaloha.h:741
map< pktSeqNum, Packet * > mapPacket
Container where Data packets are stored.
Definition uwaloha.h:813
virtual void incrUpperDataRx()
Increment the number of Data packet receive for the upper layer.
Definition uwaloha.h:728
virtual void refreshState(UWALOHA_STATUS state)
Refreshes the states of the node.
Definition uwaloha.h:578
int uwaloha_debug
Debuging Flag.
Definition uwaloha.h:753
virtual void recvFromUpperLayers(Packet *p)
This function receives the packet from upper layer and save it in the queue.
Definition uwaloha.cpp:339
ofstream fout
An object of ofstream class.
Definition uwaloha.h:817
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 ...
Definition uwaloha.cpp:750
virtual void updateAckTimeout(double rtt)
Like updateRTT() function.
Definition uwaloha.cpp:265
virtual void printStateInfo(double delay=0)
This methods print the state information of the nodes.
Definition uwaloha.cpp:815
virtual void refreshReason(UWALOHA_REASON_STATUS reason)
To know the reason why a node is in this current state.
Definition uwaloha.h:590
double alpha_
This variable is used to tune the RTT.
Definition uwaloha.h:749
Packet * curr_data_pkt
Pointer of the latest selected data packet.
Definition uwaloha.h:779
int HDR_size
Size of the HDR if any.
Definition uwaloha.h:745
virtual void txAck(int dest_addr)
This methods transmits ACK packet from MAC layer to PHY layer.
Definition uwaloha.cpp:538
@ NOT_SET
Definition uwaloha.cpp:44
@ SESSION_DISTANCE_NOT_SET
Definition uwaloha.cpp:44
UWALOHAModuleClass class_module_uwaloha
Your can find the brief description of this protocol in the paper, named "On ARQ Strategies over Rand...
#define UWALOHA_DROP_REASON_ERROR
Definition uwaloha.h:57
#define UWALOHA_DROP_REASON_BUFFER_FULL
Definition uwaloha.h:56
#define UWALOHA_DROP_REASON_WRONG_RECEIVER
Definition uwaloha.h:54
std::pair< int, int > counter
counter of collisions