DESERT 3.5.1
Loading...
Searching...
No Matches
uw-mac-DACAP-alter.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//
29
39#include "uw-mac-DACAP-alter.h"
40#include <mac.h>
41#include <cmath>
42#include <iostream>
43#include <iomanip>
44#include <rng.h>
45//#include <ip-clmsg.h>
46//#include <mll-clmsg.h>
47#include <stdio.h>
48#include <stdlib.h>
49
50static const double prop_speed = 1500.0;
51
55enum {
56 NOT_SET = -1,
116
117extern packet_t PT_DACAP;
118
122static class DACAPModuleClass : public TclClass
123{
124public:
129 : TclClass("Module/UW/DACAP")
130 {
131 }
132 TclObject *
133 create(int, const char *const *)
134 {
135 return (new MMacDACAP());
136 }
138
139void
141{
142 if (module->debug_)
143 cout << NOW << " MMacDACAP(" << module->addr
144 << ") backoff expired, current state = "
145 << module->info[module->curr_state] << endl;
146
147 module->last_reason = REASON_BACKOFF_END;
148 module->exitBackoff();
149
150 if (module->curr_state == STATE_BACKOFF) {
151
152 if (module->debug_)
153 cout << NOW << " MMacDACAP(" << module->addr
154 << ") next state = " << module->info[STATE_IDLE] << endl;
155
156 module->stateIdle();
157 }
158}
159
160void
162{
163 switch (module->curr_state) {
164
165 case (STATE_RECONTEND_WINDOW): {
166
167 if (module->debug_)
168 cout << NOW << " MMacDACAP(" << module->addr
169 << ") timer expire() current state = "
170 << module->info[module->curr_state]
171 << " Recontend Window expired, next state = "
172 << module->info[STATE_IDLE] << endl;
173
174 module->last_reason = REASON_WAIT_RECONTEND_END;
175 module->stateIdle();
176 } break;
177
178 case (STATE_WAIT_CTS): {
179
180 if (module->debug_)
181 cout << NOW << " MMacDACAP(" << module->addr
182 << ") timer expire() current state = "
183 << module->info[module->curr_state]
184 << " handshake not completed, next state = "
185 << module->info[STATE_BACKOFF] << endl;
186
187 module->last_reason = REASON_NOCTS;
188 module->stateBackoff();
189 } break;
190
191 case (STATE_WAIT_WRN): {
192
193 if (module->defer_data == false) {
194
195 if (module->debug_)
196 cout << NOW << " MMacDACAP(" << module->addr
197 << ") timer expire() current state = "
198 << module->info[module->curr_state]
199 << " warning not received, next state = "
200 << module->info[STATE_SEND_DATA] << endl;
201
202 module->last_reason = REASON_NOWRN;
203 module->stateSendData();
204 } else {
205
206 if (module->debug_)
207 cout << NOW << " MMacDACAP(" << module->addr
208 << ") timer expire() current state = "
209 << module->info[module->curr_state]
210 << " warning received, next state = "
211 << module->info[STATE_DEFER_DATA] << endl;
212
213 module->last_reason = REASON_WRN_RECEIVED;
214 module->stateDeferData();
215 }
216 } break;
217
218 case (STATE_DEFER_DATA): {
219
220 if (module->debug_)
221 cout << NOW << " MMacDACAP(" << module->addr
222 << ") timer expire() current state = "
223 << module->info[module->curr_state]
224 << " defer data complete, next state = "
225 << module->info[STATE_SEND_DATA] << endl;
226
227 module->last_reason = REASON_DEFER_END;
228 module->stateSendData();
229
230 } break;
231
232 case (STATE_WAIT_ACK): {
233
234 if (module->debug_)
235 cout << NOW << " MMacDACAP(" << module->addr
236 << ") timer expire() current state = "
237 << module->info[module->curr_state]
238 << " ack not received, next state = "
239 << module->info[STATE_BACKOFF] << endl;
240
241 module->last_reason = REASON_NOACK;
242 module->stateBackoff();
243 } break;
244
245 case (STATE_BACKOFF): {
246
247 if (module->debug_)
248 cout << NOW << " MMacDACAP(" << module->addr
249 << ") timer expire() current state = "
250 << module->info[module->curr_state]
251 << " backoff expired, next state = "
252 << module->info[STATE_IDLE] << endl;
253
254 module->last_reason = REASON_BACKOFF_END;
255 module->exitBackoff();
256 module->stateIdle();
257 } break;
258
259 case (STATE_WAIT_DATA): {
260
261 if (module->debug_)
262 cout << NOW << " MMacDACAP(" << module->addr
263 << ") timer expire() current state = "
264 << module->info[module->curr_state]
265 << " data not received, next state = "
266 << module->info[STATE_IDLE] << endl;
267
268 module->last_reason = REASON_NODATA;
269 module->stateIdle();
270 } break;
271
272 case (STATE_SEND_WRN): {
273
274 if (module->debug_)
275 cout << NOW << " MMacDACAP(" << module->addr
276 << ") timer expire() current state = "
277 << module->info[module->curr_state]
278 << " send WRN Window ended, next state = "
279 << module->info[STATE_WAIT_DATA] << endl;
280
281 module->last_reason = REASON_WRN_END;
282 module->stateWaitData();
283 } break;
284
285 case (STATE_WAIT_XCTS): {
286
287 if (module->debug_)
288 cout << NOW << " MMacDACAP(" << module->addr
289 << ") timer expire() current state = "
290 << module->info[module->curr_state]
291 << " , next state = " << module->info[STATE_WAIT_XWRN]
292 << endl;
293
294 module->last_reason = REASON_XCTS_END;
295 module->stateWaitXWarning();
296 } break;
297
298 case (STATE_WAIT_XWRN): {
299
300 if (module->debug_)
301 cout << NOW << " MMacDACAP(" << module->addr
302 << ") timer expire() current state = "
303 << module->info[module->curr_state]
304 << " , next state = " << module->info[STATE_WAIT_XDATA]
305 << endl;
306
307 module->last_reason = REASON_WAIT_XWRN_END;
308 module->stateWaitXData();
309 } break;
310
311 case (STATE_WAIT_XDATA): {
312 module->last_reason = REASON_XDATA_END;
313 if (module->op_mode == ACK_MODE) {
314 module->stateWaitXAck();
315
316 if (module->debug_)
317 cout << NOW << " MMacDACAP(" << module->addr
318 << ") timer expire() current state = "
319 << module->info[module->curr_state]
320 << " , next state = " << module->info[STATE_WAIT_XACK]
321 << endl;
322 } else {
323 module->stateIdle();
324
325 if (module->debug_)
326 cout << NOW << " MMacDACAP(" << module->addr
327 << ") timer expire() current state = "
328 << module->info[module->curr_state]
329 << " , next state = " << module->info[STATE_IDLE]
330 << endl;
331 }
332 } break;
333
334 case (STATE_WAIT_XACK): {
335
336 if (module->debug_)
337 cout << NOW << " MMacDACAP(" << module->addr
338 << ") timer expire() current state = "
339 << module->info[module->curr_state]
340 << " , next state = " << module->info[STATE_IDLE] << endl;
341
342 module->last_reason = REASON_XACK_END;
343 module->stateIdle();
344 } break;
345
346 default: {
347 cout << NOW << " MMacDACAP(" << module->addr
348 << ") timer expire() logical error, current state = "
349 << module->info[module->curr_state] << endl;
350 exit(1);
351 } break;
352 }
353}
354
356// int MMacDACAP::u_data_id;
357map<int, string> MMacDACAP::info;
358
360 : timer(this)
361 , backoff_timer(this)
362 , txsn(1)
363 , u_data_id(0)
364 , backoff_counter(0)
365 , RTS_sent_time(NOT_SET)
366 , session_distance(NOT_SET)
367 , curr_dest_addr(NOT_SET)
368 , sleep_node_1(NOT_SET)
369 , sleep_node_2(NOT_SET)
370 , backoff_duration(NOT_SET)
371 , backoff_start_time(NOT_SET)
372 , backoff_remaining(NOT_SET)
373 , last_reason(NOT_SET)
374 , backoff_first_start(NOT_SET)
375 , curr_data_pkt(0)
376 , TxActive(false)
377 , RxActive(false)
378 , defer_data(false)
379 , session_active(false)
380 , backoff_pending(false)
381 , warning_sent(false)
382 , backoff_freeze_mode(false)
383 , print_transitions(false)
384 , has_buffer_queue(false)
385 , multihop_mode(false)
386 , curr_state(STATE_IDLE)
387 , prev_state(STATE_IDLE)
388 , op_mode(ACK_MODE)
389 , wrn_pkts_tx(0)
390 , wrn_pkts_rx(0)
391 , rts_pkts_tx(0)
392 , rts_pkts_rx(0)
393 , cts_pkts_tx(0)
394 , cts_pkts_rx(0)
395 , sum_defer_time(0)
396 , defer_times_no(0)
397 , last_data_id_tx(NOT_SET)
398 , last_data_id_rx(NOT_SET)
399 , start_tx_time(0)
400 , srtt(0)
401 , sumrtt(0)
402 , sumrtt2(0)
403 , rttsamples(0)
404
405{
406 u_pkt_id = 0;
407
408 bind("t_min", (double *) &t_min);
409 bind("T_W_min", (double *) &T_W_min);
410 bind("delta_D", (double *) &delta_D);
411 bind("delta_data", (double *) &delta_data);
412 bind("max_prop_delay", (double *) &max_prop_delay);
413 bind("CTS_size", (int *) &CTS_size);
414 bind("RTS_size", (int *) &RTS_size);
415 bind("WRN_size", (int *) &WRN_size);
416 bind("HDR_size", (int *) &HDR_size);
417 bind("ACK_size", (int *) &ACK_size);
418 bind("backoff_tuner", (double *) &backoff_tuner);
419 bind("wait_costant", (double *) &wait_costant);
420 bind("debug_", (int *) &debug_); // degug mode
421 bind("max_payload", (int *) &max_payload);
422 bind("max_tx_tries", (double *) &max_tx_tries);
423 bind("buffer_pkts", (int *) &buffer_pkts);
424 bind("alpha_", (double *) &alpha_);
425 bind("max_backoff_counter", (double *) &max_backoff_counter);
426
427 if (buffer_pkts > 0)
428 has_buffer_queue = true;
429 if (max_tx_tries <= 0)
430 max_tx_tries = HUGE_VAL;
431 if (max_backoff_counter <= 0)
432 max_backoff_counter = HUGE_VAL;
433
434 if (info.empty())
435 initInfo();
436}
437
441
442// TCL command interpreter
443int
444MMacDACAP::command(int argc, const char *const *argv)
445{
446 Tcl &tcl = Tcl::instance();
447 if (argc == 2) {
448 if (strcasecmp(argv[1], "printTransitions") == 0) {
449 print_transitions = true;
451 fout.open("/tmp/DACAPstateTransitions.txt", ios_base::app);
452 return TCL_OK;
453 } else if (strcasecmp(argv[1], "setAckMode") == 0) {
455 return TCL_OK;
456 } else if (strcasecmp(argv[1], "setNoAckMode") == 0) {
458 return TCL_OK;
459 } else if (strcasecmp(argv[1], "setBackoffFreeze") == 0) {
460 backoff_freeze_mode = true;
461 return TCL_OK;
462 } else if (strcasecmp(argv[1], "setBackoffNoFreeze") == 0) {
463 backoff_freeze_mode = false;
464 return TCL_OK;
465 } else if (strcasecmp(argv[1], "setMultiHopMode") == 0) {
466 multihop_mode = true;
467 return TCL_OK;
468 } else if (strcasecmp(argv[1], "getQueueSize") == 0) {
469 tcl.resultf("%d", getQueueSize());
470 return TCL_OK;
471 } else if (strcasecmp(argv[1], "getMeanDeferTime") == 0) {
472 tcl.resultf("%f", getMeanDeferTime());
473 return TCL_OK;
474 } else if (strcasecmp(argv[1], "getTotalDeferTimes") == 0) {
475 tcl.resultf("%d", getTotalDeferTimes());
476 return TCL_OK;
477 } else if (strcasecmp(argv[1], "getWrnPktsTx") == 0) {
478 tcl.resultf("%d", getWrnPktsTx());
479 return TCL_OK;
480 } else if (strcasecmp(argv[1], "getWrnPktsRx") == 0) {
481 tcl.resultf("%d", getWrnPktsRx());
482 return TCL_OK;
483 } else if (strcasecmp(argv[1], "getRtsPktsTx") == 0) {
484 tcl.resultf("%d", getRtsPktsTx());
485 return TCL_OK;
486 } else if (strcasecmp(argv[1], "getRtsPktsRx") == 0) {
487 tcl.resultf("%d", getRtsPktsRx());
488 return TCL_OK;
489 } else if (strcasecmp(argv[1], "getCtsPktsTx") == 0) {
490 tcl.resultf("%d", getCtsPktsTx());
491 return TCL_OK;
492 } else if (strcasecmp(argv[1], "getCtsPktsRx") == 0) {
493 tcl.resultf("%d", getCtsPktsRx());
494 return TCL_OK;
495 } else if (strcasecmp(argv[1], "getUpLayersDataRx") == 0) {
496 tcl.resultf("%d", getUpLayersDataPktsRx());
497 return TCL_OK;
498 }
499 } else if (argc == 3) {
500 if (strcasecmp(argv[1], "setMacAddr") == 0) {
501 addr = atoi(argv[2]);
502 if (debug_)
503 cout << "DACAP MAC address of current node is " << addr << endl;
504 return TCL_OK;
505 }
506 }
507 return MMac::command(argc, argv);
508}
509
510int
512{
513 switch (m->type()) {
514
515 // case whatever:
516 // return 0;
517 // break;
518
519 default:
520 return Module::crLayCommand(m);
521 }
522}
523
524void
526{
527 if (system(NULL)) {
528 system("rm -f /tmp/DACAPstateTransitions.txt");
530 system("touch /tmp/DACAPstateTransitions.txt");
531 }
532
533 info[STATE_IDLE] = "Idle State";
534 info[STATE_WAIT_CTS] = "Wait CTS State";
535 info[STATE_DEFER_DATA] = "Defer Data State";
536 info[STATE_SEND_DATA] = "Send Data State";
537 info[STATE_WAIT_ACK] = "Wait ACK State";
538 info[STATE_BACKOFF] = "Backoff State";
539 info[STATE_CTS_RECEIVED] = "CTS Received State";
540 info[STATE_WAIT_DATA] = "Wait Data State";
541 info[STATE_DATA_RECEIVED] = "Data Received State";
542 info[STATE_SEND_ACK] = "Send ACK State";
543 info[STATE_SEND_RTS] = "Send RTS State";
544 info[STATE_SEND_CTS] = "Send CTS State";
545 info[STATE_WAIT_WRN] = "Wait WRN Window State";
546 info[STATE_SEND_WRN] = "Send WRN Window State";
547 info[STATE_WAIT_XCTS] = "Wait XCTS State";
548 info[STATE_WAIT_XDATA] = "Wait XDATA State";
549 info[STATE_WAIT_XACK] = "Wait XACK State";
550 info[STATE_WAIT_XWRN] = "Wait XWRN State";
551 info[STATE_RECONTEND_WINDOW] = "Wait Recontend Window State";
552
553 info[RTS_PKT] = "RTS pkt";
554 info[CTS_PKT] = "CTS pkt";
555 info[WRN_PKT] = "Warning pkt";
556 info[DATA_PKT] = "Data pkt";
557 info[ACK_PKT] = "ACK pkt";
558 info[REASON_DEFER] = "xCTS, or xRTS received";
559 info[REASON_NOACK] = "ACK timeout";
560 info[REASON_NODATA] = "Data timeout";
561 info[REASON_NOCTS] = "CTS timeout";
562 info[REASON_CTS_RECEIVED] = "CTS received";
563 info[REASON_ACK_RECEIVED] = "ACK received";
564 info[REASON_RTS_RECEIVED] = "RTS received";
565 info[REASON_DATA_RECEIVED] = "DATA received";
566 info[REASON_WRN_RECEIVED] = "WRN received";
567 info[REASON_BACKOFF_END] = "Backoff ended";
568 info[REASON_DEFER_END] = "Defer time elapsed";
569 info[REASON_DATA_SENT] = "Data sent";
570 info[REASON_BACKOFF_PENDING] = "Backoff pending";
571 info[REASON_ACK_SENT] = "ACK sent";
572 info[REASON_RTS_SENT] = "RTS sent";
573 info[REASON_CTS_SENT] = "CTS sent";
574 info[REASON_INTERFERENCE] = "xRTS or xCTS received";
575 info[REASON_TX_ENDED] = "Interfering trasmission ended";
576 info[REASON_DATA_PENDING] = "Data from upper layers pending in queue";
577 info[REASON_NOWRN] = "Wait WRN Window ended with no WRN";
578 info[REASON_WRN_END] = "Send WRN window ended";
580 "RTS received for the same current DATA pkt";
581 info[REASON_MAX_TX_TRIES] = "DATA dropped due to max tx rounds";
582 info[REASON_XCTS_END] = "xCTS wait window ended";
583 info[REASON_XDATA_END] = "xDATA wait window ended";
584 info[REASON_XACK_END] = "xACK wait window ended";
585 info[REASON_XACK_RX] = "xACK received";
586 info[REASON_XCTS_RX] = "xCTS received";
587 info[REASON_XDATA_RX] = "xDATA received";
588 info[REASON_XRTS_RX] = "xRTS received";
589 info[REASON_WAIT_XWRN_END] = "xWRN wait window ended";
590 info[REASON_WAIT_RECONTEND_END] = "Recontend window ended";
591}
592
593double
595{
596
597 double duration;
598 Packet *temp_data_pkt;
599
600 if (type == DATA_PKT) {
601 if (!Q.empty()) {
602 temp_data_pkt = (Q.front())->copy();
603 hdr_cmn *ch = HDR_CMN(temp_data_pkt);
604 ch->size() = HDR_size + ch->size();
605 } else {
606 temp_data_pkt = Packet::alloc();
607 hdr_cmn *ch = HDR_CMN(temp_data_pkt);
608 ch->size() = HDR_size + max_payload;
609 }
610 } else if (type == RTS_PKT) {
611 temp_data_pkt = Packet::alloc();
612 hdr_cmn *ch = HDR_CMN(temp_data_pkt);
613 ch->size() = RTS_size;
614 } else if (type == CTS_PKT) {
615 temp_data_pkt = Packet::alloc();
616 hdr_cmn *ch = HDR_CMN(temp_data_pkt);
617 ch->size() = CTS_size;
618 } else if (type == ACK_PKT) {
619 temp_data_pkt = Packet::alloc();
620 hdr_cmn *ch = HDR_CMN(temp_data_pkt);
621 ch->size() = ACK_size;
622 } else if (type == WRN_PKT) {
623 temp_data_pkt = Packet::alloc();
624 hdr_cmn *ch = HDR_CMN(temp_data_pkt);
625 ch->size() = WRN_size;
626 }
627 duration = Mac2PhyTxDuration(temp_data_pkt);
628 Packet::free(temp_data_pkt);
629 return (duration);
630}
631
632double
633MMacDACAP::computeWaitTime(int mode, double distance)
634{
635
636 double t_data = computeTxTime(DATA_PKT);
637
638 if (debug_) {
639 cout << NOW << " MMacDACAP(" << addr
640 << ")::computeWaitTime() tx duration = " << t_data << endl;
641 }
642
643 double T_w;
644
645 double t_1 = (t_min - min((delta_D / prop_speed),
646 min(t_data, 2.0 * max_prop_delay - t_min))) /
647 2.0;
648 double t_2 = (t_min - delta_data) / 2.0;
649 double t_3 =
650 min(t_1, (t_min + T_W_min - (2.0 * delta_D / prop_speed)) / 4.0);
651
652 if (mode == NO_ACK_MODE) {
653 if ((distance / prop_speed) < t_1) {
654 T_w = t_min - (2.0 * distance / prop_speed);
655 } else {
656 T_w = 2.0 * (distance + delta_D) / prop_speed - t_min;
657 }
658 if (T_w < (2.0 * delta_D / prop_speed))
659 T_w = 2.0 * delta_D / prop_speed;
660 } else {
661 if (((distance / prop_speed) < t_2) &&
662 ((distance / prop_speed) > t_1)) {
663 T_w = (2.0 * (distance + delta_D) / prop_speed) - t_min;
664 } else if ((distance / prop_speed) > max(t_2, t_3)) {
665 T_w = (2.0 * (distance + delta_D) / prop_speed) - T_W_min;
666 } else {
667 T_w = t_min - 2.0 * (distance / prop_speed);
668 }
669
670 if (T_w < (max((2.0 * delta_D / prop_speed), T_W_min)))
671 T_w = max((2 * delta_D / prop_speed), T_W_min);
672 }
673
674 return (T_w);
675}
676
677inline void
679{
680 if (backoff_freeze_mode == true)
681 timer.force_cancel();
682 backoff_timer.force_cancel();
683
685 backoff_pending = false;
691}
692
693void
699
700inline void
702{
703 timer.force_cancel();
704
705 double elapsed_time = NOW - backoff_start_time;
706 backoff_pending = true;
707
709 cout << NOW << " MMacDACAP(" << addr
710 << ")::freezeBackoff() error, backoff start time not set " << endl;
711 exit(1);
712 }
713
714 backoff_remaining = backoff_duration - elapsed_time;
715
716 if (backoff_remaining < (-0.3)) {
717 cout << NOW << " MMacDACAP(" << addr
718 << ")::freezeBackoff() error, backoff elapsed time = "
719 << elapsed_time << " > backoff duration = " << backoff_duration
720 << " !!" << endl;
721 exit(1);
722 } else {
723 backoff_remaining = abs(backoff_duration - elapsed_time);
724
725 if (debug_) {
726 cout << NOW << " MMacDACAP(" << addr
727 << ")::freezeBackoff() elapsed time = " << elapsed_time
728 << " < backoff duration = " << backoff_duration
729 << ", remaining backoff = " << backoff_remaining << endl;
730 }
731 }
732}
733
734double
736{
737
738 double random = RNG::defaultrng()->uniform_double();
739
740 while (random == 0) {
741 random = RNG::defaultrng()->uniform_double();
742 }
743
744 return (random * 2.0 * max_prop_delay + wait_costant);
745}
746
747double
749{
750 incrTotalBackoffTimes();
751
752 double random = RNG::defaultrng()->uniform_double();
753 double duration;
754
755 while (random == 0) {
756 random = RNG::defaultrng()->uniform_double();
757 }
758
761
762 random = backoff_tuner * random * 2.0 * max_prop_delay *
763 pow(2.0, (double) backoff_counter);
764
765 if (debug_) {
766 cout << NOW << " MMacDACAP(" << addr
767 << ")::getBackoffTime() backoff time = " << random << " s "
768 << endl;
769 }
770
771 duration = random;
772 return duration;
773}
774
775void
777{
778 if (((has_buffer_queue == true) && (Q.size() < buffer_pkts)) ||
779 (has_buffer_queue == false)) {
780
781 incrUpperDataRx();
782 waitStartTime();
783
784 initPkt(p, DATA_PKT);
785 Q.push(p);
786
787 if ((curr_state == STATE_IDLE) && (session_active == false) &&
788 (RxActive == false)) // se sono libero comincio handshake
789 {
791 stateSendRTS();
792
793 } else {
794 }
795 } else {
796 incrDiscardedPktsTx();
798 }
799}
800
801void
802MMacDACAP::initPkt(Packet *p, int type)
803{
804
805 hdr_cmn *ch = hdr_cmn::access(p);
806 hdr_dacap *dacaph = HDR_DACAP(p);
807 hdr_mac *mach = HDR_MAC(p);
808
809 dacaph->sn = txsn;
810 txsn++;
811 dacaph->ts = Scheduler::instance().clock();
812 dacaph->dacap_type = type;
813 dacaph->tx_tries = 0;
814
815 int curr_size = ch->size();
816
817 if (type != DATA_PKT) {
818 ch->timestamp() = dacaph->ts;
819 ch->ptype() = PT_DACAP;
820 if (curr_data_pkt != 0)
821 dacaph->data_sn = HDR_DACAP(curr_data_pkt)->data_sn;
822 else
823 dacaph->data_sn = u_data_id;
824 } else {
825 dacaph->orig_type = ch->ptype();
826 ch->ptype() = PT_DACAP;
827 }
828
829 switch (type) {
830
831 case (RTS_PKT): {
832 ch->size() = RTS_size;
833 ch->uid() = u_pkt_id++;
834 mach->set(MF_CONTROL, addr, curr_dest_addr);
835 } break;
836
837 case (CTS_PKT): {
838 ch->size() = CTS_size;
839 ch->uid() = u_pkt_id++;
840 mach->set(MF_CONTROL, addr, curr_dest_addr);
841 } break;
842
843 case (WRN_PKT): {
844 ch->size() = WRN_size;
845 ch->uid() = u_pkt_id++;
846 mach->set(MF_CONTROL, addr, curr_dest_addr);
847 } break;
848
849 case (DATA_PKT): {
850 ch->size() = curr_size + HDR_size;
851 dacaph->data_sn = u_data_id++;
852 mach->macSA() = addr;
853 } break;
854
855 case (ACK_PKT): {
856 ch->size() = CTS_size;
857 ch->uid() = u_pkt_id++;
858 mach->set(MF_CONTROL, addr, curr_dest_addr);
859 } break;
860 }
861}
862
863void
865{
866
867 TxActive = false;
868
869 switch (curr_state) {
870
871 case (STATE_SEND_DATA): {
872
873 if ((debug_ > 0) && (op_mode == ACK_MODE))
874 cout << NOW << " MMacDACAP(" << addr
875 << ")::Phy2MacEndTx() DATA sent, from " << info[curr_state]
876 << " to " << info[STATE_WAIT_ACK] << endl;
877
878 else if ((debug_ > 0) && (op_mode == NO_ACK_MODE))
879 cout << NOW << " MMacDACAP(" << addr
880 << ")::Phy2MacEndTx() DATA sent, from " << info[curr_state]
881 << " to " << info[STATE_IDLE] << endl;
882
884 if (op_mode == ACK_MODE)
885 stateWaitACK();
886 else if ((multihop_mode == true) && (Q.size() > 0))
888 else
889 stateIdle();
890 } break;
891
892 case (STATE_WAIT_DATA): {
893
894 } break;
895
896 case (STATE_SEND_ACK): {
897 if (backoff_pending == true) {
898
899 if (debug_)
900 cout << NOW << " MMacDACAP(" << addr
901 << ")::Phy2MacEndTx() ack sent and backoff pending, "
902 "from "
903 << info[curr_state] << " to " << info[STATE_BACKOFF]
904 << endl;
905
907 stateBackoff();
908 return;
909 } else {
910
911 if (debug_)
912 cout << NOW << " MMacDACAP(" << addr
913 << ")::Phy2MacEndTx() ack sent, from "
914 << info[curr_state] << " to " << info[STATE_IDLE]
915 << endl;
916
918 stateIdle();
919 }
920 } break;
921
922 case (STATE_SEND_RTS): {
923 if (debug_)
924 cout << NOW << " MMacDACAP(" << addr
925 << ")::Phy2MacEndTx() RTS sent, from " << info[curr_state]
926 << " to " << info[STATE_WAIT_CTS] << endl;
927
929 stateWaitCTS();
930 } break;
931
932 case (STATE_SEND_CTS): {
933 if (debug_)
934 cout << NOW << " MMacDACAP(" << addr
935 << ")::Phy2MacEndTx() CTS sent, from " << info[curr_state]
936 << " to " << info[STATE_SEND_WRN] << endl;
937
940 } break;
941
942 case (STATE_SEND_WRN): {
943
944 } break;
945
946 default: {
947 cout << NOW << " MMacDACAP(" << addr
948 << ")::Phy2MacEndTx() logical error, current state = "
949 << info[curr_state] << endl;
950 exit(1);
951 } break;
952 }
953}
954
955void
957{
958 RxActive = true;
959}
960
961void
963{
964
965 hdr_cmn *ch = HDR_CMN(p);
966 packet_t rx_pkt_type = ch->ptype();
967
968 if (rx_pkt_type != PT_DACAP) {
970 return;
971 }
972
973 hdr_dacap *dacaph = HDR_DACAP(p);
974 hdr_mac *mach = HDR_MAC(p);
975 hdr_MPhy *ph = HDR_MPHY(p);
976
977 int source_mac = mach->macSA();
978 double tx_time = ph->txtime;
979 double rx_time = ph->rxtime;
980 double diff_time = rx_time - tx_time;
981 double distance = diff_time * prop_speed;
982
983 if (ch->error()) {
984 drop(p, 1, "ERR");
985 incrErrorPktsRx();
986
987 return;
988 } else {
989
990 if (debug_)
991 cout << NOW << " MMacDACAP(" << addr << ")::Phy2MacEndRx() "
992 << info[curr_state]
993 << ", received a pkt type = " << info[dacaph->dacap_type]
994 << ", src addr = " << mach->macSA()
995 << " dest addr = " << mach->macDA()
996 << ", estimated distance between nodes = " << distance << " m "
997 << endl;
998
999 switch (curr_state) {
1000
1001 case (STATE_IDLE): {
1002 rxStateIdle(p);
1003 } break;
1004
1005 case (STATE_RECONTEND_WINDOW): {
1007 } break;
1008
1009 case (STATE_WAIT_CTS): {
1010 rxStateWaitCTS(p);
1011 } break;
1012
1013 case (STATE_WAIT_WRN): {
1015 } break;
1016
1017 case (STATE_WAIT_ACK): {
1018 rxStateWaitACK(p);
1019 } break;
1020
1021 case (STATE_BACKOFF): {
1022 rxStateBackoff(p);
1023 } break;
1024
1025 case (STATE_WAIT_DATA): {
1026 rxStateWaitData(p);
1027 } break;
1028
1029 case (STATE_SEND_WRN): {
1031 } break;
1032
1033 case (STATE_WAIT_XCTS): {
1034 rxStateWaitXCts(p);
1035 } break;
1036
1037 case (STATE_WAIT_XWRN): {
1039 } break;
1040
1041 case (STATE_WAIT_XDATA): {
1043 } break;
1044
1045 case (STATE_WAIT_XACK): {
1046 rxStateWaitXAck(p);
1047 } break;
1048
1049 default: {
1050
1051 if (debug_)
1052 cout << NOW << " MMacDACAP(" << addr
1053 << ")::Phy2MacEndRx() dropping pkt, wrong state"
1054 << endl;
1055
1056 Packet::free(p);
1057 return;
1058 } break;
1059 }
1060 }
1061}
1062
1063void
1064MMacDACAP::setBackoffNodes(double node_a, double node_b)
1065{
1066 if ((sleep_node_1 == NOT_SET) && (sleep_node_2 == NOT_SET)) {
1067 sleep_node_1 = node_a;
1068 sleep_node_2 = node_b;
1069 }
1070 if (debug_) {
1071 cout << NOW << " MMacDACAP(" << addr
1072 << ")::setBackoffNodes() mac addr involved = " << sleep_node_1
1073 << " , " << sleep_node_2
1074 << " . next state = " << info[STATE_BACKOFF] << endl;
1075 }
1076}
1077
1078void
1080{
1081 Packet *ack_pkt = Packet::alloc();
1082 initPkt(ack_pkt, ACK_PKT);
1083
1084 incrCtrlPktsTx();
1085 incrAckPktsTx();
1086 Mac2PhyStartTx(ack_pkt);
1087 TxActive = true;
1088}
1089
1090void
1092{
1093 Packet *data_pkt = (Q.front())->copy();
1094
1095 if ((op_mode == NO_ACK_MODE))
1096 queuePop(true);
1097
1098 incrDataPktsTx();
1099 Mac2PhyStartTx(data_pkt);
1100 TxActive = true;
1101}
1102
1103void
1105{
1106 Packet *rts_pkt = Packet::alloc();
1107
1108 // IpClMsgUpdRoute m(curr_data_pkt);
1109 // sendSyncClMsg(&m);
1110
1111 // MllClMsgUpdMac m2(curr_data_pkt);
1112 // sendSyncClMsg(&m2);
1113
1114 hdr_mac *mach = HDR_MAC(curr_data_pkt);
1115
1116 curr_dest_addr = mach->macDA();
1117
1118 initPkt(rts_pkt, RTS_PKT);
1119
1120 incrCtrlPktsTx();
1121 incrRtsPktsTx();
1122
1123 TxActive = true;
1124 start_tx_time = NOW; // we set curr RTT
1125 Mac2PhyStartTx(rts_pkt);
1126}
1127
1128void
1130{
1131 Packet *cts_pkt = Packet::alloc();
1132 initPkt(cts_pkt, CTS_PKT);
1133
1134 incrCtrlPktsTx();
1135 incrCtsPktsTx();
1136
1137 Mac2PhyStartTx(cts_pkt);
1138 TxActive = true;
1139}
1140
1141void
1143{
1144 warning_sent = true;
1145 Packet *wrn_ptk = Packet::alloc();
1146 initPkt(wrn_ptk, WRN_PKT);
1147 Mac2PhyStartTx(wrn_ptk);
1148 incrWrnPktsTx();
1149 TxActive = true;
1150}
1151
1152void
1154{
1155 RxActive = false;
1156
1157 hdr_dacap *dacaph = HDR_DACAP(p);
1158 hdr_mac *mach = HDR_MAC(p);
1159 hdr_MPhy *ph = HDR_MPHY(p);
1160
1161 int source_mac = mach->macSA();
1162 int dest_mac = mach->macDA();
1163 int pkt_type = dacaph->dacap_type;
1164 int pkt_data_sn = dacaph->data_sn;
1165 double tx_time = ph->txtime;
1166 double rx_time = ph->rxtime;
1167 double diff_time = rx_time - tx_time;
1168 double distance = diff_time * prop_speed;
1169
1170 Packet::free(p);
1171
1172 if (dest_mac == addr) { // RTS for me
1173 if (pkt_type == RTS_PKT) {
1174 incrCtrlPktsRx();
1175 incrRtsPktsRx();
1176
1177 curr_dest_addr = source_mac;
1178 session_active = true;
1179 session_distance = distance;
1180 if (last_data_id_rx != pkt_data_sn)
1181 last_data_id_rx = pkt_data_sn;
1183
1184 if (debug_)
1185 cout << NOW << " MMacDACAP(" << addr
1186 << ")::rxStateIdle() next state = " << info[STATE_SEND_CTS]
1187 << endl;
1188
1189 stateSendCTS();
1190 return;
1191 }
1192 } else { // not for me
1193 if (pkt_type == RTS_PKT) {
1194 incrXCtrlPktsRx();
1195 setBackoffNodes(source_mac, dest_mac);
1197 stateWaitXCts();
1198 return;
1199 } else if (pkt_type == CTS_PKT) {
1200 incrXCtrlPktsRx();
1201 setBackoffNodes(source_mac, dest_mac);
1204 return;
1205 } else if (pkt_type == DATA_PKT) {
1206 incrXDataPktsRx();
1207 setBackoffNodes(source_mac, dest_mac);
1209 stateWaitXAck();
1210 return;
1211 }
1212 }
1213}
1214
1215void
1217{
1218 RxActive = false;
1219
1220 hdr_dacap *dacaph = HDR_DACAP(p);
1221 hdr_mac *mach = HDR_MAC(p);
1222 hdr_MPhy *ph = HDR_MPHY(p);
1223
1224 int source_mac = mach->macSA();
1225 int dest_mac = mach->macDA();
1226 int pkt_type = dacaph->dacap_type;
1227 int pkt_data_sn = dacaph->data_sn;
1228 double tx_time = ph->txtime;
1229 double rx_time = ph->rxtime;
1230 double diff_time = rx_time - tx_time;
1231 double distance = diff_time * prop_speed;
1232
1233 Packet::free(p);
1234
1235 if (dest_mac == addr) { // for me
1236 if (pkt_type == RTS_PKT) { // RTS
1237 incrCtrlPktsRx();
1238 incrRtsPktsRx();
1239
1240 session_distance = distance;
1241 curr_dest_addr = source_mac;
1242 if (last_data_id_rx != pkt_data_sn)
1243 last_data_id_rx = pkt_data_sn;
1245 session_active = true;
1246
1247 if (backoff_freeze_mode == true)
1248 freezeBackoff();
1249 else
1250 exitBackoff();
1251
1252 if (debug_)
1253 cout << NOW << " MMacDACAP(" << addr
1254 << ")::rxStateBackoff() next state = "
1255 << info[STATE_SEND_CTS] << endl;
1256
1257 stateSendCTS();
1258 return;
1259 }
1260 } else {
1261 if (pkt_type == RTS_PKT) {
1262 incrXCtrlPktsRx();
1263 setBackoffNodes(source_mac, dest_mac);
1265
1266 if (debug_)
1267 cout << NOW << " MMacDACAP(" << addr
1268 << ")::rxStateBackoff() next state = "
1269 << info[STATE_WAIT_XCTS] << endl;
1270
1271 stateWaitXCts();
1272 return;
1273 } else if (pkt_type == CTS_PKT) {
1274 incrXCtrlPktsRx();
1275 setBackoffNodes(source_mac, dest_mac);
1277
1278 if (debug_)
1279 cout << NOW << " MMacDACAP(" << addr
1280 << ")::rxStateBackoff() next state = "
1281 << info[STATE_WAIT_XWRN] << endl;
1282
1284 return;
1285 } else if (pkt_type == DATA_PKT) {
1286 incrXDataPktsRx();
1287 setBackoffNodes(source_mac, dest_mac);
1289
1290 if (debug_)
1291 cout << NOW << " MMacDACAP(" << addr
1292 << ")::rxStateBackoff() next state = "
1293 << info[STATE_WAIT_XACK] << endl;
1294
1295 stateWaitXAck();
1296 return;
1297 }
1298 }
1299}
1300
1301void
1303{
1304 RxActive = false;
1305
1306 hdr_dacap *dacaph = HDR_DACAP(p);
1307 hdr_mac *mach = HDR_MAC(p);
1308 hdr_MPhy *ph = HDR_MPHY(p);
1309
1310 int source_mac = mach->macSA();
1311 int dest_mac = mach->macDA();
1312 int pkt_type = dacaph->dacap_type;
1313 int pkt_data_sn = dacaph->data_sn;
1314 double tx_time = ph->txtime;
1315 double rx_time = ph->rxtime;
1316 double diff_time = rx_time - tx_time;
1317 double distance = diff_time * prop_speed;
1318
1319 Packet::free(p);
1320
1321 if ((dest_mac != addr) && (pkt_type == CTS_PKT)) {
1322 incrXCtrlPktsRx();
1323 if ((op_mode == NO_ACK_MODE) && (diff_time < t_min)) {
1324
1325 if (debug_) {
1326 cout << NOW << " MMacDACAP(" << addr
1327 << ")::rxStateWaitCTS() diff time = " << diff_time
1328 << " < t_min = " << t_min << " ; Defering data " << endl;
1329 }
1330
1331 defer_data = true;
1332 return;
1333 } else if ((op_mode == ACK_MODE) && (diff_time < T_W_min)) { // ack
1334
1335 if (debug_) {
1336 cout << NOW << " MMacDACAP(" << addr
1337 << ")::rxStateWaitCTS() diff time = " << diff_time
1338 << " < T_W_min = " << T_W_min << " ; Defering data "
1339 << endl;
1340 // waitForUser();
1341 }
1342
1343 defer_data = true;
1344 return;
1345 }
1346 } else if ((dest_mac != addr) && (pkt_type == RTS_PKT)) { // xRTS
1347 incrXCtrlPktsRx();
1348 if ((op_mode == ACK_MODE) && (diff_time < max_prop_delay)) { // ack
1349
1350 if (debug_) {
1351 cout << NOW << " MMacDACAP(" << addr
1352 << ")::rxStateWaitCTS() diff time = " << diff_time
1353 << " < max_prop_delay = " << max_prop_delay
1354 << " ; Defering data " << endl;
1355 }
1356
1357 defer_data = true;
1358 return;
1359 }
1360 } else if ((dest_mac == addr) && (source_mac == curr_dest_addr) &&
1361 (pkt_type == CTS_PKT)) {
1362 // CTS for me
1363 incrCtrlPktsRx();
1364 incrCtsPktsRx();
1365
1366 session_distance = distance;
1368
1369 if (debug_)
1370 cout << NOW << " MMacDACAP(" << addr
1371 << ")::rxStateWaitCTS() next state = " << info[STATE_WAIT_WRN]
1372 << endl;
1373
1375 return;
1376 }
1377}
1378
1379void
1381{
1382 RxActive = false;
1383
1384 hdr_dacap *dacaph = HDR_DACAP(p);
1385 hdr_mac *mach = HDR_MAC(p);
1386 hdr_MPhy *ph = HDR_MPHY(p);
1387
1388 int source_mac = mach->macSA();
1389 int dest_mac = mach->macDA();
1390 int pkt_type = dacaph->dacap_type;
1391 int pkt_data_sn = dacaph->data_sn;
1392 double tx_time = ph->txtime;
1393 double rx_time = ph->rxtime;
1394 double diff_time = rx_time - tx_time;
1395 double distance = diff_time * prop_speed;
1396
1397 Packet::free(p);
1398
1399 if ((dest_mac == addr) && (source_mac == curr_dest_addr) &&
1400 (pkt_type == ACK_PKT)) {
1401 // ACK
1402 incrCtrlPktsRx();
1403 incrAckPktsRx();
1404
1405 queuePop(true);
1406
1407 if (backoff_pending == false) {
1408
1409 if (debug_)
1410 cout << NOW << " MMacDACAP(" << addr
1411 << ")::rxStateWaitACK() next state = " << info[STATE_IDLE]
1412 << endl;
1413
1415 if ((multihop_mode == true) && (Q.size() > 0))
1417 else
1418 stateIdle();
1419 } else {
1420
1421 if (debug_)
1422 cout << NOW << " MMacDACAP(" << addr
1423 << ")::rxStateWaitACK() next state = "
1424 << info[STATE_BACKOFF] << endl;
1425
1427 stateBackoff();
1428 }
1429 }
1430}
1431
1432void
1434{
1435 RxActive = false;
1436
1437 hdr_dacap *dacaph = HDR_DACAP(p);
1438 hdr_mac *mach = HDR_MAC(p);
1439 hdr_MPhy *ph = HDR_MPHY(p);
1440
1441 int source_mac = mach->macSA();
1442 int dest_mac = mach->macDA();
1443 int pkt_type = dacaph->dacap_type;
1444 int pkt_data_sn = dacaph->data_sn;
1445 double tx_time = ph->txtime;
1446 double rx_time = ph->rxtime;
1447 double diff_time = rx_time - tx_time;
1448 double distance = diff_time * prop_speed;
1449
1450 if ((dest_mac == addr) && (source_mac == curr_dest_addr) &&
1451 (pkt_type == DATA_PKT)) {
1452 // DATA for me
1453
1454 if (debug_)
1455 cout << NOW << " MMacDACAP(" << addr
1456 << ")::rxStateWaitData() next state = "
1457 << info[STATE_DATA_RECEIVED] << endl;
1458
1461 return;
1462 }
1463
1464 Packet::free(p);
1465
1466 if ((dest_mac == addr) && (source_mac == curr_dest_addr) &&
1467 (pkt_type == RTS_PKT) && (last_data_id_rx == pkt_data_sn)) {
1468 incrCtrlPktsRx();
1469 incrRtsPktsRx();
1470
1471 curr_dest_addr = source_mac;
1472 session_active = true;
1473 session_distance = distance;
1474
1476 stateSendCTS();
1477 return;
1478 }
1479}
1480
1481void
1483{
1484 RxActive = false;
1485
1486 hdr_dacap *dacaph = HDR_DACAP(p);
1487 hdr_mac *mach = HDR_MAC(p);
1488 hdr_MPhy *ph = HDR_MPHY(p);
1489
1490 int source_mac = mach->macSA();
1491 int dest_mac = mach->macDA();
1492 int pkt_type = dacaph->dacap_type;
1493 int pkt_data_sn = dacaph->data_sn;
1494 double tx_time = ph->txtime;
1495 double rx_time = ph->rxtime;
1496 double diff_time = rx_time - tx_time;
1497 double distance = diff_time * prop_speed;
1498
1499 Packet::free(p);
1500
1501 if ((dest_mac != addr) &&
1502 ((source_mac == sleep_node_1) || (source_mac == sleep_node_2))) {
1503
1504 if (((pkt_type == ACK_PKT) && (op_mode == ACK_MODE)) ||
1505 ((pkt_type == DATA_PKT) && (op_mode == NO_ACK_MODE))) {
1506
1507 if (pkt_type == ACK_PKT)
1508 incrXCtrlPktsRx();
1509 else
1510 incrXDataPktsRx();
1511
1512 if (debug_) {
1513 cout << NOW << " MMacDACAP(" << addr
1514 << ")::rxStateWaitXCts() DATA or ACK received "
1515 << "from nodes involved. quitting sleep. next state = "
1516 << info[STATE_IDLE] << endl;
1517 }
1518 exitSleep();
1519
1521 stateIdle();
1522 return;
1523 } else if (pkt_type == CTS_PKT) {
1524 incrXCtrlPktsRx();
1526
1527 if (debug_)
1528 cout << NOW << " MMacDACAP(" << addr
1529 << ")::rxStateWaitXCts() next state = "
1530 << info[STATE_WAIT_XWRN] << endl;
1531
1533 return;
1534 } else if (pkt_type == DATA_PKT) {
1535 incrXDataPktsRx();
1537
1538 if (debug_)
1539 cout << NOW << " MMacDACAP(" << addr
1540 << ")::rxStateWaitXCts() next state = "
1541 << info[STATE_WAIT_XACK] << endl;
1542
1543 stateWaitXAck();
1544 return;
1545 }
1546 }
1547}
1548
1549void
1551{
1552 RxActive = false;
1553
1554 hdr_dacap *dacaph = HDR_DACAP(p);
1555 hdr_mac *mach = HDR_MAC(p);
1556 hdr_MPhy *ph = HDR_MPHY(p);
1557
1558 int source_mac = mach->macSA();
1559 int dest_mac = mach->macDA();
1560 int pkt_type = dacaph->dacap_type;
1561 int pkt_data_sn = dacaph->data_sn;
1562 double tx_time = ph->txtime;
1563 double rx_time = ph->rxtime;
1564 double diff_time = rx_time - tx_time;
1565 double distance = diff_time * prop_speed;
1566
1567 Packet::free(p); // rilascio il pkt
1568
1569 if ((dest_mac != addr) &&
1570 ((source_mac == sleep_node_1) || (source_mac == sleep_node_2))) {
1571
1572 if (((pkt_type == ACK_PKT) && (op_mode == ACK_MODE)) ||
1573 ((pkt_type == DATA_PKT) && (op_mode == NO_ACK_MODE))) {
1574
1575 if (pkt_type == ACK_PKT)
1576 incrXCtrlPktsRx();
1577 else
1578 incrXDataPktsRx();
1579
1580 if (debug_) {
1581 cout << NOW << " MMacDACAP(" << addr
1582 << ")::rxStateWaitXData() DATA or ACK received "
1583 << "from nodes involved. quitting sleep. next state = "
1584 << info[STATE_IDLE] << endl;
1585 // waitForUser();
1586 }
1587
1588 exitSleep();
1590 stateIdle(); // esco da backoff
1591 return;
1592 } else if (dacaph->dacap_type == DATA_PKT) {
1593 incrXDataPktsRx();
1595
1596 if (debug_)
1597 cout << NOW << " MMacDACAP(" << addr
1598 << ")::rxStateWaitXData() next state = "
1599 << info[STATE_WAIT_XACK] << endl;
1600
1601 stateWaitXAck();
1602 return;
1603 }
1604 }
1605}
1606
1607void
1609{
1610 RxActive = false;
1611
1612 hdr_dacap *dacaph = HDR_DACAP(p);
1613 hdr_mac *mach = HDR_MAC(p);
1614 hdr_MPhy *ph = HDR_MPHY(p);
1615
1616 int source_mac = mach->macSA();
1617 int dest_mac = mach->macDA();
1618 int pkt_type = dacaph->dacap_type;
1619 int pkt_data_sn = dacaph->data_sn;
1620 double tx_time = ph->txtime;
1621 double rx_time = ph->rxtime;
1622 double diff_time = rx_time - tx_time;
1623 double distance = diff_time * prop_speed;
1624
1625 Packet::free(p);
1626
1627 if ((dest_mac != addr) &&
1628 ((source_mac == sleep_node_1) || (source_mac == sleep_node_2))) {
1629
1630 if (((pkt_type == ACK_PKT) && (op_mode == ACK_MODE)) ||
1631 ((pkt_type == DATA_PKT) && (op_mode == NO_ACK_MODE))) {
1632
1633 if (pkt_type == ACK_PKT)
1634 incrXCtrlPktsRx();
1635 else
1636 incrXDataPktsRx();
1637
1638 if (debug_) {
1639 cout << NOW << " MMacDACAP(" << addr
1640 << ")::rxStateWaitXAck() DATA or ACK received "
1641 << "from nodes involved. quitting sleep. next state = "
1642 << info[STATE_IDLE] << endl;
1643 // waitForUser();
1644 }
1645 exitSleep();
1647 stateIdle(); // esco da backoff
1648 }
1649 }
1650}
1651
1652void
1654{
1655 RxActive = false;
1656
1657 hdr_dacap *dacaph = HDR_DACAP(p);
1658 hdr_mac *mach = HDR_MAC(p);
1659 hdr_MPhy *ph = HDR_MPHY(p);
1660
1661 int source_mac = mach->macSA();
1662 int dest_mac = mach->macDA();
1663 int pkt_type = dacaph->dacap_type;
1664 int pkt_data_sn = dacaph->data_sn;
1665 double tx_time = ph->txtime;
1666 double rx_time = ph->rxtime;
1667 double diff_time = rx_time - tx_time;
1668 double distance = diff_time * prop_speed;
1669
1670 Packet::free(p);
1671
1672 if ((dest_mac != addr) &&
1673 ((source_mac == sleep_node_1) || (source_mac == sleep_node_2))) {
1674
1675 if (((pkt_type == ACK_PKT) && (op_mode == ACK_MODE)) ||
1676 ((pkt_type == DATA_PKT) && (op_mode == NO_ACK_MODE))) {
1677
1678 if (pkt_type == ACK_PKT)
1679 incrXCtrlPktsRx();
1680 else
1681 incrXDataPktsRx();
1682
1683 if (debug_) {
1684 cout << NOW << " MMacDACAP(" << addr
1685 << ")::rxStateWaitXWarning() DATA or ACK received "
1686 << "from nodes involved. quitting sleep. next state = "
1687 << info[STATE_IDLE] << endl;
1688 // waitForUser();
1689 }
1690 exitSleep();
1692 stateIdle(); // esco da backoff
1693 return;
1694 } else if (dacaph->dacap_type == DATA_PKT) {
1695 incrXDataPktsRx();
1697
1698 if (debug_)
1699 cout << NOW << " MMacDACAP(" << addr
1700 << ")::rxStateWaitXWarning() next state = "
1701 << info[STATE_WAIT_XACK] << endl;
1702
1703 stateWaitXAck();
1704 return;
1705 }
1706 }
1707}
1708
1709void
1711{
1712 RxActive = false;
1713
1714 hdr_dacap *dacaph = HDR_DACAP(p);
1715 hdr_mac *mach = HDR_MAC(p);
1716 hdr_MPhy *ph = HDR_MPHY(p);
1717
1718 int source_mac = mach->macSA();
1719 int dest_mac = mach->macDA();
1720 int pkt_type = dacaph->dacap_type;
1721 int pkt_data_sn = dacaph->data_sn;
1722 double tx_time = ph->txtime;
1723 double rx_time = ph->rxtime;
1724 double diff_time = rx_time - tx_time;
1725 double distance = diff_time * prop_speed;
1726
1727 Packet::free(p);
1728
1729 if ((dest_mac != addr) && (source_mac == CTS_PKT)) { // xCTS
1730 incrXCtrlPktsRx();
1731 if ((op_mode == NO_ACK_MODE) && (diff_time < t_min)) { // no ack
1732
1733 if (debug_) {
1734 cout << NOW << " MMacDACAP(" << addr
1735 << ")::rxStateWaitWarning() diff time = " << diff_time
1736 << " < t_min = " << t_min << " ; Defering data " << endl;
1737 }
1738
1739 defer_data = true;
1740 return;
1741 } else if ((op_mode == ACK_MODE) &&
1742 (diff_time < T_W_min)) { // condizione ack
1743
1744 if (debug_) {
1745 cout << NOW << " MMacDACAP(" << addr
1746 << ")::rxStateWaitWarning() diff time = " << diff_time
1747 << " < T_W_min = " << T_W_min << " ; Defering data "
1748 << endl;
1749 }
1750
1751 defer_data = true;
1752 return;
1753 }
1754 } else if ((dest_mac != addr) && (pkt_type == RTS_PKT)) { // xRTS
1755 incrXCtrlPktsRx();
1756 if ((op_mode == ACK_MODE) && (diff_time < max_prop_delay)) { // ack
1757
1758 if (debug_) {
1759 cout << NOW << " MMacDACAP(" << addr
1760 << ")::rxStateWaitWarning() diff time = " << diff_time
1761 << " < max_prop_delay = " << max_prop_delay
1762 << " ; Defering data " << endl;
1763 // waitForUser();
1764 }
1765
1766 defer_data = true;
1767 return;
1768 }
1769 } else if ((dest_mac == addr) && (source_mac == curr_dest_addr) &&
1770 (pkt_type == WRN_PKT)) {
1771 // WRN
1772 incrWrnPktsRx();
1773
1774 if (debug_) {
1775 cout << NOW << " MMacDACAP(" << addr
1776 << ")::rxStateWaitWarning() WRN received, defering data "
1777 << endl;
1778 }
1779
1780 defer_data = true;
1781 return;
1782 }
1783}
1784
1785void
1787{
1788 RxActive = false;
1789
1790 hdr_dacap *dacaph = HDR_DACAP(p);
1791 hdr_mac *mach = HDR_MAC(p);
1792 hdr_MPhy *ph = HDR_MPHY(p);
1793
1794 int source_mac = mach->macSA();
1795 int dest_mac = mach->macDA();
1796 int pkt_type = dacaph->dacap_type;
1797 int pkt_data_sn = dacaph->data_sn;
1798 double tx_time = ph->txtime;
1799 double rx_time = ph->rxtime;
1800 double diff_time = rx_time - tx_time;
1801 double distance = diff_time * prop_speed;
1802
1803 if ((dest_mac == addr) && (source_mac == curr_dest_addr) &&
1804 (pkt_type == DATA_PKT)) {
1805 // ricevo DATA x me
1806
1807 if (debug_) {
1808 cout << NOW << " MMacDACAP(" << addr
1809 << ")::rxStateSendWarning() DATA received in "
1810 << info[curr_state] << " logical error!!!! " << endl;
1811 waitForUser();
1812 }
1813
1816 return;
1817 }
1818
1819 Packet::free(p);
1820
1821 if ((dest_mac == addr) && (source_mac == curr_dest_addr) &&
1822 (pkt_type == RTS_PKT) && (last_data_id_rx == pkt_data_sn)) {
1823
1824 incrCtrlPktsRx();
1825 incrRtsPktsRx();
1826
1827 curr_dest_addr = source_mac;
1828 session_active = true;
1829 session_distance = distance;
1831 stateSendCTS();
1832 return;
1833 } else if ((dest_mac != addr) && (pkt_type == RTS_PKT)) {
1834 if (diff_time < (2 * max_prop_delay - t_min)) {
1835 incrXCtrlPktsRx();
1836
1837 if (debug_) {
1838 cout << NOW << " MMacDACAP(" << addr
1839 << ")::rxStateSendWarning() difference time = "
1840 << diff_time << " < " << (2 * max_prop_delay - t_min)
1841 << " sending a warning " << endl;
1842 }
1843
1844 txWrn();
1845 return;
1846 }
1847 } else if ((dest_mac != addr) && (pkt_type == CTS_PKT)) { // ricevo xCTS
1848 if ((diff_time < (2 * max_prop_delay - T_W_min)) &&
1849 (op_mode == ACK_MODE)) { // se è ack mode
1850 incrXCtrlPktsRx();
1851
1852 if (debug_) {
1853 cout << NOW << " MMacDACAP(" << addr
1854 << ")::rxStateSendWarning() difference time = "
1855 << diff_time << " < " << (2 * max_prop_delay - T_W_min)
1856 << " sending a warning " << endl;
1857 }
1858
1859 txWrn();
1860 return;
1861 }
1862 }
1863}
1864
1865void
1867{
1868 RxActive = false;
1869
1870 hdr_dacap *dacaph = HDR_DACAP(p);
1871 hdr_mac *mach = HDR_MAC(p);
1872 hdr_MPhy *ph = HDR_MPHY(p);
1873
1874 int source_mac = mach->macSA();
1875 int dest_mac = mach->macDA();
1876 int pkt_type = dacaph->dacap_type;
1877 int pkt_data_sn = dacaph->data_sn;
1878 double tx_time = ph->txtime;
1879 double rx_time = ph->rxtime;
1880 double diff_time = rx_time - tx_time;
1881 double distance = diff_time * prop_speed;
1882
1883 Packet::free(p);
1884
1885 if (dest_mac == addr) { // RTS for me
1886 if (pkt_type == RTS_PKT) {
1887 incrCtrlPktsRx();
1888 incrRtsPktsRx();
1889
1890 curr_dest_addr = source_mac;
1891 session_active = true;
1892 session_distance = distance;
1893 if (last_data_id_rx != pkt_data_sn)
1894 last_data_id_rx = pkt_data_sn;
1896
1897 if (debug_)
1898 cout << NOW << " MMacDACAP(" << addr
1899 << ")::rxStateRecontendWindow() next state = "
1900 << info[STATE_SEND_CTS] << endl;
1901
1902 stateSendCTS();
1903 return;
1904 }
1905 } else {
1906 if (dacaph->dacap_type == RTS_PKT) {
1907 incrXCtrlPktsRx();
1908 setBackoffNodes(source_mac, dest_mac);
1910
1911 if (debug_)
1912 cout << NOW << " MMacDACAP(" << addr
1913 << ")::rxStateRecontendWindow() next state = "
1914 << info[STATE_WAIT_XCTS] << endl;
1915
1916 stateWaitXCts();
1917 return;
1918 } else if (pkt_type == CTS_PKT) {
1919 incrXCtrlPktsRx();
1920 setBackoffNodes(source_mac, dest_mac);
1922
1923 if (debug_)
1924 cout << NOW << " MMacDACAP(" << addr
1925 << ")::rxStateRecontendWindow() next state = "
1926 << info[STATE_WAIT_XWRN] << endl;
1927
1929 return;
1930 } else if (pkt_type == DATA_PKT) {
1931 incrXDataPktsRx();
1932 setBackoffNodes(source_mac, dest_mac);
1934
1935 if (debug_)
1936 cout << NOW << " MMacDACAP(" << addr
1937 << ")::rxStateRecontendWindow() next state = "
1938 << info[STATE_WAIT_XACK] << endl;
1939
1940 stateWaitXAck();
1941 return;
1942 }
1943 }
1944}
1945
1946void
1948{
1949 timer.force_cancel();
1951
1953
1954 warning_sent = false;
1955 session_active = false;
1956 defer_data = false;
1957
1959 exitSleep();
1960
1961 if (!Q.empty()) {
1962 if (HDR_DACAP(Q.front())->data_sn != last_data_id_tx) {
1964 backoff_counter = 0;
1965 last_data_id_tx = HDR_DACAP(Q.front())->data_sn;
1966 }
1967 if (HDR_DACAP(Q.front())->tx_tries < max_tx_tries) {
1969 HDR_DACAP(Q.front())->tx_tries++;
1970 stateSendRTS();
1971 } else {
1972 queuePop(false);
1973 incrDroppedPktsTx();
1974
1976
1977 if (debug_)
1978 cout << NOW << " MMacDACAP(" << addr
1979 << ")::stateIdle() dropping pkt, max tx tries reached"
1980 << endl;
1981
1982 stateIdle();
1983 }
1984 }
1985}
1986
1987void
1989{
1990 session_active = true;
1991
1992 timer.force_cancel();
1994
1996
1997 curr_data_pkt = Q.front();
1998
1999 txRts();
2000}
2001
2002void
2004{
2005 timer.force_cancel();
2007
2008 warning_sent = false;
2009 defer_data = false;
2010
2011 if (backoff_pending == false) {
2012
2013 if (debug_)
2014 cout << NOW << " MMacDACAP(" << addr
2015 << ")::stateBackoff() starting a new backoff" << endl;
2016
2019 backoff_start_time = NOW;
2020
2023
2024 if (backoff_freeze_mode == true)
2025 timer.resched(backoff_duration);
2026 else
2028 } else if (backoff_freeze_mode == true) { // backoff freeze mode on, we need
2029 // to restore freezed backoff
2030
2031 if (backoff_remaining == NOT_SET) {
2032 cout << NOW << " MMacDACAP(" << addr
2033 << ")::stateBackoff() error!!! backoff remaining not set!!!"
2034 << endl;
2035 exit(1);
2036 }
2037
2038 if (debug_)
2039 cout << NOW << " MMacDACAP(" << addr
2040 << ")::stateBackoff() continuing previous backoff, "
2041 << " time remaining = " << backoff_remaining << " s" << endl;
2042
2043 backoff_start_time = NOW;
2045 timer.resched(backoff_remaining);
2046 }
2047 // no freeze,backoff pending and timer already counting, we wait for an
2048 // event
2049
2051}
2052
2053void
2055{
2056 timer.force_cancel();
2058
2060
2061 timer.resched(2.0 * max_prop_delay + computeTxTime(CTS_PKT));
2062}
2063
2064void
2066{
2067 timer.force_cancel();
2069
2071
2072 timer.resched(2.0 * max_prop_delay + computeTxTime(DATA_PKT) +
2073 computeWaitTime(op_mode, ((max_prop_delay * 2.0) * 1500.0)));
2074}
2075
2076void
2078{
2079 timer.force_cancel();
2081
2083
2084 timer.resched(2.0 * max_prop_delay + computeTxTime(ACK_PKT));
2085}
2086
2087void
2089{
2090 timer.force_cancel();
2092
2094
2095 if (op_mode == ACK_MODE)
2096 timer.resched(3.0 * max_prop_delay - T_W_min + computeTxTime(WRN_PKT) +
2098 else
2099 timer.resched(3.0 * max_prop_delay - t_min + computeTxTime(WRN_PKT) +
2101}
2102
2103void
2105{
2106 timer.force_cancel();
2108
2110
2111 if (op_mode == ACK_MODE)
2112 timer.resched(2.0 * max_prop_delay - T_W_min + computeTxTime(WRN_PKT) +
2113 wait_costant);
2114 else
2115 timer.resched(2.0 * max_prop_delay - t_min + computeTxTime(WRN_PKT) +
2116 wait_costant);
2117}
2118
2119void
2121{
2122 timer.force_cancel();
2124
2126
2127 // timer.resched(2 * max_prop_delay - min(T_W_min,t_min) +
2128 // computeTxTime(WRN_PKT) + wait_costant);
2129
2130 if (op_mode == ACK_MODE)
2131 timer.resched(2.0 * max_prop_delay - T_W_min + wait_costant);
2132 else
2133 timer.resched(2.0 * max_prop_delay - t_min + wait_costant);
2134}
2135
2136void
2138{
2139 timer.force_cancel();
2140
2142
2144
2145 timer.resched(2.0 * max_prop_delay + computeTxTime(CTS_PKT) +
2147}
2148
2149void
2151{
2152 timer.force_cancel();
2154 double delay;
2155
2157
2158 timer.resched(2.0 * max_prop_delay + computeTxTime(DATA_PKT) +
2159 computeWaitTime(op_mode, (max_prop_delay * 2.0) * 1500.0) +
2160 wait_costant);
2161}
2162
2163void
2165{
2166 timer.force_cancel();
2168
2170
2171 timer.resched(2.0 * max_prop_delay + computeTxTime(ACK_PKT) +
2173}
2174
2175void
2177{
2178 timer.force_cancel();
2181
2182 double defer_delay = computeWaitTime(op_mode, session_distance);
2183 deferEndTime(defer_delay);
2184
2185 if (debug_) {
2186 cout << NOW << " MMacDACAP(" << addr
2187 << ")::stateDeferData() defer delay = " << defer_delay << endl;
2188 }
2189
2190 if (debug_)
2191 printStateInfo(defer_delay);
2192
2193 timer.resched(defer_delay);
2194}
2195
2196void
2198{
2199 timer.force_cancel();
2201
2202 defer_data = false;
2203
2205
2206 txData();
2207}
2208
2209void
2211{
2212 timer.force_cancel();
2214
2216
2217 if (defer_data == true)
2219 else
2220 stateSendData();
2221}
2222
2223void
2225{
2226 timer.force_cancel();
2228
2230
2231 incrDataPktsRx();
2232
2233 hdr_cmn *ch = hdr_cmn::access(data_pkt);
2234 hdr_dacap *dacaph = HDR_DACAP(data_pkt);
2235 ch->ptype() = dacaph->orig_type;
2236 ch->size() = ch->size() - HDR_size;
2237
2238 sendUp(data_pkt);
2239
2240 if (op_mode == ACK_MODE)
2241 stateSendAck();
2242 else
2243 stateIdle();
2244}
2245
2246void
2248{
2249 timer.force_cancel();
2251
2253
2254 txAck();
2255}
2256
2257void
2259{
2260 timer.force_cancel();
2262
2264
2265 txCts();
2266}
2267
2268void
2270{
2271 timer.force_cancel();
2273
2274 double delay = getRecontendTime();
2275 printStateInfo(delay);
2276
2277 timer.resched(delay);
2278}
2279
2280void
2282{
2283 if (debug_)
2284 cout << NOW << " MMacDACAP(" << addr << ")::printStateInfo() "
2285 << "from " << info[prev_state] << " to " << info[curr_state]
2286 << " reason: " << info[last_reason] << endl;
2287
2288 if (print_transitions) {
2289 if (curr_state == STATE_BACKOFF) {
2290 fout << left << setw(10) << NOW << " MMacDACAP(" << addr
2291 << ")::printStateInfo() "
2292 << "from " << info[prev_state] << " to " << info[curr_state]
2293 << " reason: " << info[last_reason]
2294 << ". Backoff duration = " << delay
2295 << "; backoff cnt = " << backoff_counter << endl;
2296 } else if (curr_state == STATE_DEFER_DATA) {
2297 fout << left << setw(10) << NOW << " MMacDACAP(" << addr
2298 << ")::printStateInfo() "
2299 << "from " << info[prev_state] << " to " << info[curr_state]
2300 << " reason: " << info[last_reason]
2301 << ". Defering delay = " << delay << endl;
2302 } else if (curr_state == STATE_RECONTEND_WINDOW) {
2303 fout << left << setw(10) << NOW << " MMacDACAP(" << addr
2304 << ")::printStateInfo() "
2305 << "from " << info[prev_state] << " to " << info[curr_state]
2306 << " reason: " << info[last_reason]
2307 << ". Waiting delay = " << delay << endl;
2308 } else {
2309 fout << left << setw(10) << NOW << " MMacDACAP(" << addr
2310 << ")::printStateInfo() "
2311 << "from " << info[prev_state] << " to " << info[curr_state]
2312 << " reason: " << info[last_reason] << endl;
2313 }
2314 }
2315}
2316
2317inline void
2319{
2320 std::string response;
2321 std::cout << "Press Enter to continue";
2322 std::getline(std::cin, response);
2323}
virtual void expire(Event *e)
Method called when the timer expire.
Class that represent the binding of the protocol with tcl.
TclObject * create(int, const char *const *)
DACAPModuleClass()
Constructor of the class.
virtual void expire(Event *e)
Method call when the timer expire.
Class that represents a DACAP node.
double wait_costant
Additive factor in the calculation of ACK timer.
ofstream fout
Object that handle the file where the state transitions is written (if the print_transitions option i...
DACAPBTimer backoff_timer
backoff timer
int op_mode
Indicates if the ACK_mode or no_ACK_mode is activated.
virtual int getWrnPktsRx()
virtual void stateWaitXCts()
The protocol is in WaitXCts state.
virtual void waitForUser()
Used for debug purposes.
virtual double getMeanDeferTime()
bool warning_sent
true if a WRN packet has been just sent
MMacDACAP()
Costructor of the MMacDACAP class.
virtual int getTotalDeferTimes()
int ACK_size
Size (in bytes) of the ACK packet.
bool print_transitions
true if the state-transitions of the protocol is printed on a file
virtual int getRtsPktsTx()
virtual void txRts()
Pass a RTS packet to transmit to the PHY layer.
virtual void incrWrnPktsRx()
Increases the counter of WRN packets received.
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
Packet * curr_data_pkt
Pointer to the current data packet.
virtual void stateDeferData()
The protocol is in the DeferData state.
int last_reason
last reason for the change of state
bool backoff_freeze_mode
true if the backoff-timer is freezed
int u_data_id
simulation-unique DATA packet ID
bool has_buffer_queue
true if the node has a buffer queue to store data packets
int WRN_size
Size (in bytes) of the WRN packet.
double alpha_
smoothing factor used for statistics using first order IIR filter
double max_tx_tries
Maximum transmission tries for one packet before discarding the packet.
virtual int getCtsPktsRx()
double max_prop_delay
One way maximum propagation delay (in seconds) in the network.
double session_distance
Distance between sender and receiver in the current session.
int last_data_id_tx
Unique ID of the last data packet transmitted.
int CTS_size
Size (in bytes) of the CTS packet.
static int u_pkt_id
simulation-unique packet ID
int txsn
serial number of the DATA packet transmitted
virtual int getQueueSize()
double backoff_remaining
Backoff time remaining (if the timer is freezed)
virtual void stateSendWarning()
The protocol is in the SendWarning state.
virtual void stateWaitXAck()
The protocol is in WaitXAck state.
int curr_dest_addr
MAC address of the current node involved in this session.
virtual void rxStateIdle(Packet *p)
The case of reception while the protocol is in IDLE state is handled.
virtual void incrRtsPktsTx()
Increases the counter of RTS packets transmitted.
int buffer_pkts
Dimension (in packets) of the buffer queue.
virtual double computeTxTime(int type)
Computes the time that is needed to transmit a packet, implementing a CrLayMessage for asking the PHY...
virtual void backoffStartTime()
Sets the start time of the backoff timer to NOW.
int prev_state
Previous state of the protocol.
virtual void Phy2MacStartRx(const Packet *p)
Method called when the Phy Layer start to receive a Packet.
virtual void rxStateWaitXData(Packet *p)
The case of reception while the protocol is in WaitXData state is handled.
virtual void rxStateWaitXCts(Packet *p)
The case of reception while the protocol is in WaitXCts state is handled.
std::queue< Packet * > Q
MAC queue used for packet scheduling.
int max_payload
Dimension of the maximum allowed data paylaod in bytes.
virtual void rxStateWaitWarning(Packet *p)
The case of reception while the protocol is in WaitWarning state is handled.
int sleep_node_2
MAC address of sleep_node 2.
double start_tx_time
Timestamp at which a packet is transmitted.
double delta_D
Value (in m) that indicates how far we want the CTS propagates over the sender before initiate the da...
int RTS_size
Size (in bytes) of the RTS packet.
bool TxActive
true if a transmission process is occuring
virtual void rxStateWaitXAck(Packet *p)
The case of reception while the protocol is in WaitXAck state is handled.
bool backoff_pending
true if the backoff-timer is active (i.e.
bool multihop_mode
true if the multihop mode is active to simulate a multihop scenario with routing
double backoff_start_time
Backoff starting time.
virtual void txAck()
Pass an ACK packet to transmit to the PHY layer.
virtual void deferEndTime(double duration)
Sets the end time of the defer summing the duration to the actual duration of defer.
virtual void refreshState(int state)
Refresh the state of the protocol.
virtual void setBackoffNodes(double node, double node_b)
Saves the MAC address of another couple of nodes that is the handshake procedure in order to access t...
int HDR_size
Size (in bytes) of the header added by DACAP.
virtual void rxStateSendWarning(Packet *p)
The case of reception while the protocol is in SendWarning state is handled.
double max_backoff_counter
Number of times a backoff is calculated.
virtual void queuePop(bool flag=true)
Pop the first element of the queue.
virtual void stateDataReceived(Packet *data_pkt)
The protocol is in the DataReceived state.
virtual void rxStateWaitData(Packet *p)
The case of reception while the protocol is in WaitDATA state is handled.
virtual double getRecontendTime()
Used in multihop mode.
int last_data_id_rx
Unique ID of the last data packet received.
virtual void rxStateBackoff(Packet *p)
The case of reception while the protocol is in BACKOFF state is handled.
virtual void initPkt(Packet *p, int pkt_type)
Initializes the packet with the correct MAC source address and destination address,...
bool RxActive
true if a reception process is occuring
virtual double getBackoffTime()
Calculate the backoff time if the node didn't received the ACK.
virtual int getWrnPktsTx()
virtual void recvFromUpperLayers(Packet *p)
Receive the packet from the upper layer (e.g.
virtual void incrCtsPktsRx()
Increases the counter of CTS packets received.
virtual void stateSendAck()
The protocol is in SendAck state.
bool session_active
true if a session is active (i.e.
virtual void rxStateWaitXWarning(Packet *p)
The case of reception while the protocol is in WaitXWarning state is handled.
virtual void stateWaitWarning()
The protocol is in WaitWarning state.
virtual void stateWaitXWarning()
The protocol is in WaitXWarning state.
virtual void incrWrnPktsTx()
Increases the counter of WRN packets transmitted.
virtual void stateCTSReceived()
The protocol is in the CTSReceived state.
int sleep_node_1
MAC address of sleep_node 1.
virtual void stateWaitData()
The protocol is in the WaitData state.
virtual void stateSendData()
The protocol is in the SendData state.
virtual void rxStateRecontendWindow(Packet *p)
The case of reception while the protocol is in RecontendWindow state is handled.
virtual void incrTotalDeferTimes()
Increases the number of times a transmission is deferred.
virtual void initInfo()
Initializes the protocol at the beginning of the simulation.
virtual void stateBackoff()
The protocol is in Backoff state.
virtual void rxStateWaitACK(Packet *p)
The case of reception while the protocol is in WaitACK state is handled.
double t_min
Minimum time needed to do an hand-shaking.
int curr_state
Current state of the protocol.
virtual void incrCtsPktsTx()
Increases the counter of CTS packets transmitted.
virtual void stateWaitCTS()
The protocol is in the WaitCTS state.
double backoff_duration
Backoff duration.
virtual void txWrn()
Pass a WRN packet to transmit to the PHY layer.
virtual int getCtsPktsTx()
virtual void freezeBackoff()
Freezes the Backoff timer.
virtual void Phy2MacEndTx(const Packet *p)
Method called when the PHY layer finish to transmit the packet.
double T_W_min
Minimum Warning Time in sencods.
virtual void rxStateWaitCTS(Packet *p)
The case of reception while the protocol is in WaitCTS state is handled.
DACAPTimer timer
ACK timer.
int getUpLayersDataPktsRx()
double delta_data
Dimension difference (in bytes) among data packets ( 0 if the packets have always the same dimension...
virtual void stateRecontendWindow()
The protocol is in RecontendWindow state.
virtual void incrRtsPktsRx()
Increases the counter of RTS packets received.
virtual void exitSleep()
This method erase the MAC address of the two nodes that have intiated a handshake procedure if this h...
virtual void exitBackoff()
The backoff timer is stopped.
virtual void Phy2MacEndRx(Packet *p)
Method called when the Phy Layer finish to receive a Packet.
virtual void txCts()
Pass a CTS packet to transmit to the PHY layer.
int backoff_counter
Number of times a backoff timer is set up.
virtual int crLayCommand(ClMessage *m)
Cross-Layer messages interpreter.
virtual int getRtsPktsRx()
bool defer_data
true if a node has to defer the transmission of a data packet
virtual ~MMacDACAP()
Destructor of the MMacDACAP class.
virtual void printStateInfo(double delay=0)
Prints a file with every state change for debug purposes.
static map< int, string > info
Relationship between the state and its textual description.
virtual double computeWaitTime(int mode, double distance)
Computes the T_w parameter, that is the minimum time that the sender has to wait between the receptio...
virtual void backoffEndTime()
calculates the End Time of the backoff timer
virtual void stateIdle()
The protocol is in the IDLE state.
virtual void txData()
Pass a DATA packet to transmit to the PHYl layer.
double backoff_tuner
Multiplicative factor in the calculation of backoff.
double backoff_first_start
Timestamp at which the backoff timer is started for the first time (if the timer has been freezed man...
virtual void stateWaitACK()
The protocol is in the WaitACK state.
virtual void stateSendRTS()
The protocol is in SendRTS state.
virtual void stateWaitXData()
The protocol is in WaitXData state.
virtual void stateSendCTS()
The protocol is in SendCTS state.
Definition of the header of DACAP packets.
int sn
sequence number of this packet
int dacap_type
sequence number of this packet
int tx_tries
Number of transmission tries of the packet.
int data_sn
Sequence number of the packet.
double ts
packet timestamp, i.e., its generation time)
packet_t orig_type
Original type of the packet.
static const double prop_speed
DACAPModuleClass class_module_dacap
@ REASON_NOACK
@ REASON_XRTS_RX
@ REASON_CTS_SENT
@ REASON_ACK_SENT
@ REASON_CTS_RECEIVED
@ STATE_WAIT_XDATA
@ REASON_DATA_SENT
@ STATE_WAIT_CTS
@ REASON_XDATA_RX
@ REASON_RTS_RECEIVED
@ REASON_BACKOFF_PENDING
@ REASON_XDATA_END
@ STATE_CTS_RECEIVED
@ STATE_SEND_ACK
@ STATE_WAIT_DATA
@ REASON_ACK_RECEIVED
@ REASON_INTERFERENCE
@ STATE_WAIT_XACK
@ REASON_DATA_PENDING
@ REASON_XCTS_END
@ REASON_DATA_RECEIVED
@ REASON_DEFER
@ REASON_MAX_TX_TRIES
@ STATE_WAIT_XWRN
@ REASON_SAME_RTS_RECEIVED
@ REASON_NODATA
@ STATE_SEND_WRN
@ STATE_SEND_RTS
@ STATE_WAIT_XCTS
@ REASON_RTS_SENT
@ REASON_DEFER_END
@ STATE_DEFER_DATA
@ REASON_WAIT_RECONTEND_END
@ REASON_NOCTS
@ REASON_XCTS_RX
@ STATE_WAIT_WRN
@ REASON_XACK_RX
@ STATE_DATA_RECEIVED
@ STATE_RECONTEND_WINDOW
@ STATE_SEND_DATA
@ REASON_XACK_END
@ REASON_WRN_RECEIVED
@ REASON_WRN_END
@ STATE_BACKOFF
@ REASON_TX_ENDED
@ REASON_WAIT_XWRN_END
@ STATE_WAIT_ACK
@ STATE_SEND_CTS
@ REASON_BACKOFF_END
@ NO_ACK_MODE
Provides the DACAP Class header description.
#define DACAP_DROP_REASON_UNKNOWN_TYPE
The type of the packet is unknown.
#define HDR_DACAP(P)
#define DACAP_DROP_REASON_BUFFER_FULL
The buffer of the node is full.
@ NOT_SET
Definition uwaloha.cpp:44