DESERT 3.5.1
Loading...
Searching...
No Matches
uwUFetch_NODE_HEADNODE_mod_1.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
39#include "mac.h"
40#include "mmac.h"
41#include "uwUFetch_NODE.h"
42#include "uwUFetch_cmn_hdr.h"
43//#include "uwmphy_modem_cmn_hdr.h"
44#include "uwcbr-module.h"
45#include "rng.h"
46
47/*******************************************************************************
48 * GENERAL METHODS *
49 *******************************************************************************/
50void
52{
53
54 hdr_cmn *cmh = hdr_cmn::access(p);
55 hdr_mac *mach = HDR_MAC(p);
56 int src_mac_addr = mach->macSA();
57
58 if (cmh->ptype() == PT_BEACON_UFETCH) {
59 // BEACON section
60 if (debug_)
61 std::cout
62 << NOW << " uwUFetch_NODE (" << addr
63 << ") ::Phy2MacStartRx() ---->HN is starting to receive a "
64 << " BEACON packet from the HN with MAC address: "
65 << src_mac_addr << std::endl;
66
67 } else if (cmh->ptype() == PT_POLL_UFETCH) {
68 // POLL section
69 if (debug_)
70 std::cout
71 << NOW << " uwUFetch_NODE (" << addr
72 << ") ::Phy2MacStartRx() ---->HN is starting to receive a "
73 << " POLL packet from the HN with MAC address: "
74 << src_mac_addr << std::endl;
75
76 } else if (cmh->ptype() == PT_CBEACON_UFETCH) {
77 // CBEACON section
78 if (debug_)
79 std::cout
80 << NOW << " uwUFetch_NODE (" << addr
81 << ") ::Phy2MacStartRx() ---->HN is starting to receive a "
82 << " CBEACON packet from the HN with MAC address: "
83 << src_mac_addr << std::endl;
84
85 } else if (cmh->ptype() == PT_PROBE_UFETCH) {
86 // PROBE section
87 if (debug_)
88 std::cout
89 << NOW << " uwUFetch_NODE (" << addr
90 << ") ::Phy2MacStartRx() ---->HN is starting to receive a "
91 << " PROBE packet from the NODE with MAC address: "
92 << src_mac_addr << std::endl;
93
94 if (debugMio_)
95 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
96 << ")::Phy2MacStartRx()______________________"
97 "Start_to_rx_PROBE_pck"
98 << "_from_SENSOR_NODE(" << src_mac_addr << ")."
99 << std::endl;
100
102
103 } else if (cmh->ptype() == PT_TRIGGER_UFETCH) {
104 // TRIGGER section
105 if (debug_)
106 std::cout << NOW << " uwUFetch_NODE (" << addr
107 << ") ::Phy2MacStartRx() ---->HN is starting to receive a"
108 << " TRIGGER packet from the AUV with MAC address: "
109 << src_mac_addr << std::endl;
110
111 if (debugMio_)
112 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
113 << ")::Phy2MacStartRx()______________________"
114 "Start_to_rx_TRIGGER_pck"
115 << "_from_AUV(" << src_mac_addr << ")."
116 << std::endl;
117
119
120 } else if (cmh->ptype() == PT_RTS_UFETCH) {
121 // RTS section
122 if (debug_)
123 std::cout
124 << NOW << " uwUFetch_NODE (" << addr
125 << ") ::Phy2MacStartRx() ---->HN is starting to receive a "
126 << " RTS packet from the HN with MAC address: "
127 << src_mac_addr << std::endl;
128
129 } else if (cmh->ptype() == PT_CTS_UFETCH) {
130 // CTS section
131 if (debug_)
132 std::cout
133 << NOW << " uwUFetch_NODE (" << addr
134 << ") ::Phy2MacStartRx() ---->HN is starting to receive a "
135 << " CTS packet from the AUV with MAC address: "
136 << src_mac_addr << std::endl;
137
138 if (debugMio_)
139 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
140 << ")::Phy2MacStartRx()______________________"
141 "Start_to_rx_CTS_pck"
142 << "_from_AUV(" << src_mac_addr << ")."
143 << std::endl;
144
146
147 } else {
148 // DATA section
149 if (debug_)
150 std::cout
151 << NOW << " uwUFetch_NODE (" << addr
152 << ") ::Phy2MacStartRx() ---->HN is starting to receive a "
153 << " DATA packet from the NODE with MAC address: "
154 << src_mac_addr << std::endl;
155
156 if (debugMio_)
157 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
158 << ")::Phy2MacStartRx()______________________"
159 "Start_to_rx_DATA_pck"
160 << "_from_SN(" << src_mac_addr << ")."
161 << std::endl;
162
164 }
165
166} // end Phy2MacStartRx_HN();
167
168void
170{
171 hdr_cmn *cmh = hdr_cmn::access(p);
172 hdr_mac *mach = HDR_MAC(p);
173 int src_mac_addr = mach->macSA();
174 int dest_mac_addr = mach->macDA(); // Destination MAC address, the address
175 // to which the packet is addressed
176
177 if (debug_)
178 std::cout << NOW << "uwUFetch_NODE(" << addr
179 << ")::Phy2MacEndRx()______________________dest_mac_addr "
180 << dest_mac_addr << std::endl;
181 // Control if the packet that the HN has received is really for him
182
183 if ((dest_mac_addr == addr) || (dest_mac_addr == MAC_BROADCAST)) {
184 // Packet is addressed to me HN
185
186 if (cmh->ptype() == PT_BEACON_UFETCH) {
187 // BEACON section
188 if (debug_)
189 std::cout << NOW << " uwUFetch_NODE (" << addr
190 << ") ::Phy2MacEndRx() ---->HN has finished to "
191 "receive a"
192 << " BEACON packet from the HN with MAC address: "
193 << src_mac_addr << " .DROP IT" << std::endl;
194
196
197 } else if (cmh->ptype() == PT_CBEACON_UFETCH) {
198 // CBEACON section
199 if (debug_)
200 std::cout << NOW << " uwUFetch_NODE (" << addr
201 << ") ::Phy2MacEndRx() ---->HN has finished to "
202 "receive a"
203 << " CBEACON packet from the HN with MAC address: "
204 << src_mac_addr << " .DROP IT." << std::endl;
205
207
208 } else if (cmh->ptype() == PT_PROBE_UFETCH) {
209 // PROBE section
210 if (debug_)
211 std::cout << NOW << " uwUFetch_NODE (" << addr
212 << ") ::Phy2MacEndRx() ---->HN has finished to "
213 "receive a"
214 << " PROBE packet from the NODE with MAC address: "
215 << src_mac_addr << std::endl;
216
217 if (debugMio_)
218 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
219 << ")::Phy2MacEndRx()________________________"
220 "Finished_to_rx_PROBE"
221 << "_pck_from_SENSOR_NODE(" << src_mac_addr
222 << ")." << std::endl;
223
224 if (cmh->error()) {
225 // Packet it's in error
226 if (debug_)
227 std::cout << NOW << " uwUFetch_NODE (" << addr
228 << ") ::Phy2MacEndRx() ---->PROBE packet "
229 "received by the HN"
230 << " is corrupted: DROP IT." << std::endl;
231
232 if (debugMio_)
233 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
234 << ")::Phy2MacEndRx()_____________________"
235 "___PROBE_pck_rx_from_SN("
236 << src_mac_addr << ")_It_s_in_ERROR."
237 << std::endl;
238
240
243
244 drop(p, 1, UWFETCH_NODE_DROP_REASON_ERROR); // drop the packet
246
247 } else {
248 if (rxPROBEEnabled) {
249 // Packet is not in error
250 if (debug_)
251 std::cout << NOW << " uwUFetch_NODE (" << addr
252 << ") ::Phy2MacEndRx() ---->Physical layer "
253 "of HN with MAC"
254 << " address: " << dest_mac_addr
255 << " has finished to receive a PROBE packet"
256 << " number: " << (getProbePckRx_HN() + 1)
257 << " from the NODE with MAC address: "
258 << src_mac_addr << std::endl;
259
260 if (debugMio_)
261 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
262 << ")::Phy2MacEndRx()_________________"
263 "_______PROBE_pck_rx_from_SN("
264 << src_mac_addr << ")_It_s_CORRECT."
265 << std::endl;
266
268
271
272 curr_PROBE_HN_pck_rx = p->copy();
273
275
276 Packet::free(p);
277
278 PROBE_rx();
279
280 } else {
281 // HN is not enabled to receive a PROBE packet
282 if (debug_)
283 std::cout << NOW << " uwUFetch_NODE (" << addr
284 << ") ::Phy2MacEndRx() ---->HN is not "
285 "enabled to receive the PROBE"
286 << " packet: DROP IT." << std::endl;
287 if (debugMio_)
289 << NOW << "uwUFetch_HEAD_NODE(" << addr
290 << ")::Phy2MacEndRx()________________________"
291 "HN_is_not_ENABLED_to_rx_PROBE_pck_from_SN("
292 << src_mac_addr << ")." << std::endl;
293
295
297 }
298 }
299
300 } else if (cmh->ptype() == PT_TRIGGER_UFETCH) {
301 if (typeCommunication()) {
302 // Communication between HN & AUV without RTS and CTS packets
303
305 } else {
306 // Communication between HN & AUV with RTS and CTS packets
307 // TRIGGER section
308 if (debug_)
309 std::cout
310 << NOW << " uwUFetch_NODE (" << addr
311 << ") ::Phy2MacEndRx() ---->HN has finished to "
312 "receive a"
313 << " TRIGGER packet from the AUV with MAC address: "
314 << src_mac_addr << std::endl;
315
316 if (debugMio_)
317 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
318 << ")::Phy2MacEndRx()_____________________"
319 "___Finished_to_rx_TRIGGER_pck"
320 << "_from_AUV(" << src_mac_addr << ")."
321 << std::endl;
322
324 mach->macSA(); // Save the Mac address of the
325
332 if (rxTRIGGEREnabled) {
333 int index_q = 0;
340 while ((!Q_data.empty()) &&
341 (index_q <= MAX_PCK_HN_WANT_RX_FROM_NODE)) {
342 // Pick up the first element of the queue
343 curr_DATA_NODE_pck_tx_HN = (Q_data.front())->copy();
344 // Remove the element from the queue that we have pick
345 // up the packet
346 Q_data.pop();
347 // Add the packet to the queue of data packets that HN
348 // will transmit to AUV when
349 // will be required
351 Q_data_source_SN.push(addr); // Save the MAC address
352 // from which the data
353 // packet it's arrived.
356
358
359 if (debugMio_)
361 << NOW << "uwUFetch_HEAD_NODE(" << addr
362 << ")::Phy2MacEndRx()______________________"
363 "__DATA_pck_rx:_source("
364 << addr << ")_"
365 << "destination(" << addr
366 << ")_id_pck:" << cbrh->sn() << ""
367 << std::endl;
368 index_q++;
369 }
370 }
371
372 if ((cmh->error()) || (Q_data_HN.empty())) {
373 if (cmh->error()) {
374 // Packet it's in error
375 if (debug_)
376 std::cout << NOW << " uwUFetch_NODE (" << addr
377 << ") ::Phy2MacEndRx() ---->TRIGGER "
378 "packet received by the HN"
379 << " is corrupted: DROP IT" << std::endl;
380
381 if (debugMio_)
383 << NOW << "uwUFetch_HEAD_NODE(" << addr
384 << ")::Phy2MacEndRx()______________________"
385 "__TRIGGER_rx_from_AUV("
386 << mach->macSA()
387 << ")_It_s_in_ERROR:IGNORE_It."
388 << std::endl;
389
391
394
395 drop(p, 1, UWFETCH_NODE_DROP_REASON_ERROR); // drop the
396 // packet
398
399 if (rxTRIGGEREnabled) {
400 if (debug_)
401 std::cout << NOW << " uwUFetch_NODE (" << addr
402 << ") ::Phy2MacEndRx() ---->HN reset "
403 "the TRIGGER timer"
404 << std::endl;
405 // if (debugMio_) out_file_logging << NOW <<
406 // "uwUFetch_HEAD_NODE(" << addr <<
407 // ")::Phy2MacEndRx()________________________TRIGGER
408 // rx in ERROR && HN is enabled to rx It: IGNORE
409 // It." << std::endl;
410
411 BeaconBeforeTx_timer.force_cancel();
412
415 rxTRIGGEREnabled = true;
416
417 stateIdle_HN();
418 } else {
419 // HN is not enable to receive a TRIGGER packet
420 if (debug_)
421 std::cout << NOW << " uwUFetch_NODE (" << addr
422 << ") ::Phy2MacEndRx() ---->HN is "
423 "not enabled to receive"
424 << " the TRIGGER packet: DROP IT."
425 << std::endl;
426 }
427 } else {
428 if (debug_)
429 std::cout << NOW << " uwUFetch_NODE (" << addr
430 << ") ::Phy2MacEndRx() ---->TRIGGER "
431 "packet received by the HN"
432 << " is not corrupted, but the HN has 0 "
433 "DATA packet enabled to tx to the "
434 "AUV: DROP IT"
435 << std::endl;
436
437 if (debugMio_)
439 << NOW << "uwUFetch_HEAD_NODE(" << addr
440 << ")::Phy2MacEndRx()______________________"
441 "__TRIGGER_rx_It_s_CORRECT_but_0_DATA_"
442 "to_tx:IGNORE_It."
443 << std::endl;
444
446
448
449 drop(p, 1, UWFETCH_NODE_DROP_REASON_ERROR); // drop the
450 // packet
452
453 if (rxTRIGGEREnabled) {
454 if (debug_)
455 std::cout << NOW << " uwUFetch_NODE (" << addr
456 << ") ::Phy2MacEndRx() ---->HN reset "
457 "the TRIGGER timer"
458 << std::endl;
459 BeaconBeforeTx_timer.force_cancel();
460
463 rxTRIGGEREnabled = true;
464
465 stateIdle_HN();
466 } else {
467 // HN is not enable to receive a TRIGGER packet
468 if (debug_)
469 std::cout << NOW << " uwUFetch_NODE (" << addr
470 << ") ::Phy2MacEndRx() ---->HN is "
471 "not enabled to receive"
472 << " the TRIGGER packet: DROP IT."
473 << std::endl;
474 }
475 }
476 } else {
477 // Packet it's not in error
478 if (debug_)
479 std::cout << NOW << " uwUFetch_NODE (" << addr
480 << ") ::Phy2MacEndRx() ---->Physical layer "
481 "of HN with MAC"
482 << " address: " << dest_mac_addr
483 << " has finished to receive a TRIGGER packet"
484 << " from the AUV with MAC address: "
485 << src_mac_addr << std::endl;
486
487 if (debugMio_)
489 << NOW << "uwUFetch_HEAD_NODE(" << addr
490 << ")::Phy2MacEndRx()________________________"
491 "TRIGGER_rx_It_s_CORRECT_>=1_DATA_to_tx."
492 << std::endl;
493
495
498
499 curr_TRIGGER_HN_pck_rx = p->copy();
500
502
503 Packet::free(p);
504
505 TRIGGER_rx();
506 }
507 }
508
509 } else if (cmh->ptype() == PT_CTS_UFETCH) {
510 // CTS section
511 if (debug_)
512 std::cout << NOW << " uwUFetch_NODE (" << addr
513 << ") ::Phy2MacEndRx() ---->HN has finished to "
514 "receive a"
515 << " CTS packet from the AUV with MAC address: "
516 << src_mac_addr << std::endl;
517
518 if (debugMio_)
519 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
520 << ")::Phy2MacEndRx()________________________"
521 "Finished_to_rx_CTS_pck"
522 << "_from_AUV(" << src_mac_addr << ")."
523 << std::endl;
524
525 if (rxCTSEnabled) {
526 if (cmh->error()) {
527 // Packet it's in error
528 if (debug_)
529 std::cout << NOW << " uwUFetch_NODE (" << addr
530 << ") ::Phy2MacEndRx() ---->CTS packet "
531 "received by the HN"
532 << " is corrupted: DROP IT" << std::endl;
533 if (debugMio_)
534 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
535 << ")::Phy2MacEndRx()_________________"
536 "_______CTS_pck_rx_from_AUV("
537 << src_mac_addr << ")_It_s_in_ERROR."
538 << std::endl;
539
541
544
545 drop(p,
546 1,
547 UWFETCH_NODE_DROP_REASON_ERROR); // drop the packet
549
550 // return in Idle state
551 if (debug_)
552 std::cout << NOW << " uwUFetch_NODE (" << addr
553 << ") ::Phy2MacEndRx() ---->HN reset the "
554 "timer to wait CTS,"
555 << " and return in IDLE STATE." << std::endl;
556 if (debugMio_)
557 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
558 << ")::Phy2MacEndRx()_________________"
559 "_______RESET_CTS_timeout."
560 << std::endl;
561 CTS_timer.force_cancel();
562 // Trigger_timer.force_cancel();
563
568
569 rxCTSEnabled = false;
570 rxTRIGGEREnabled = true;
571 CTSrx = true;
572 stateIdle_HN();
573
574 } else {
575 // Packet it's not in error
576 if (debug_)
577 std::cout << NOW << " uwUFetch_NODE (" << addr
578 << ") ::Phy2MacEndRx() ---->Physical layer "
579 "of HN with MAC"
580 << " address: " << dest_mac_addr
581 << " has finished to receive a CTS packet"
582 << " from the AUV with MAC address: "
583 << src_mac_addr << std::endl;
584
586 if (debugMio_)
587 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
588 << ")::Phy2MacEndRx()_________________"
589 "_______CTS_pck_rx_from_AUV("
590 << src_mac_addr << ")_It_s_CORRECT."
591 << std::endl;
592
593 if (debug_)
594 std::cout << NOW << " uwUFetch_NODE (" << addr
595 << ") ::Phy2MacEndRx() ---->HN reset the "
596 "timer to wait CTS,"
597 << " and COMPUTE IT." << std::endl;
598 if (debugMio_)
599 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
600 << ")::Phy2MacEndRx()_________________"
601 "_______RESET_CTS_timeout."
602 << std::endl;
603 CTS_timer.force_cancel(); // reset the timer in which the HN
604 // wait a TRIGGER packet
605 // Trigger_timer.force_cancel();
606
609
610 curr_CTS_HN_pck_rx = p->copy();
611
612 Packet::free(p);
614
615 CTS_rx();
616 }
617 } else {
618 // HN is not enable to receive a CTS packet
619 CTSrx = true;
620
621 if (debug_)
622 std::cout << NOW << " uwUFetch_NODE (" << addr
623 << ") ::Phy2MacEndRx() ---->HN is not enabled to "
624 "receive"
625 << " the CTS packet: DROP IT." << std::endl;
626 if (debugMio_)
627 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
628 << ")::Phy2MacEndRx()_____________________"
629 "___CTS_pck_rx_from_AUV("
630 << src_mac_addr
631 << ")_It_s_not_enabled_to_rx_It."
632 << std::endl;
633
635 1,
637 }
638 } else {
639 // DATA section
640 if (debug_)
641 std::cout << NOW << " uwUFetch_NODE (" << addr
642 << ") ::Phy2MacEndRx() ---->HN has finished to "
643 "receive a"
644 << " DATA packet from the NODE with MAC address: "
645 << src_mac_addr << std::endl;
646
648
649 if (debugMio_)
650 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
651 << ")::Phy2MacEndRx()________________________"
652 "End_to_rx_DATA_pck_"
653 << "from_SN(" << src_mac_addr << ")."
654 << std::endl;
655
656 if (cmh->error()) {
657 // Packet it's in error
658 if (debug_)
659 std::cout << NOW << " uwUFetch_NODE( " << addr
660 << ") ::Phy2MacEndRx() ---->DATA packet received "
661 "by the HN"
662 << " is corrupted: DROP IT" << std::endl;
663
665
666 curr_DATA_HN_pck_rx = p->copy();
667
671
673
674 if (debugMio_)
675 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
676 << ")::Phy2MacEndRx()_____________________"
677 "___DATA_pck_rx_by_HN("
678 << addr << ")_from_SN(" << src_mac_addr
679 << ")_id_pck:" << cbrh->sn() << ""
680 << "_It_s_in_ERROR." << std::endl;
681
682 drop(p, 1, UWFETCH_NODE_DROP_REASON_ERROR); // drop the packet
684
685 } else {
686 // Packet it's not in error
687
688 if (debug_)
689 std::cout << NOW << " uwUFetch_NODE (" << addr
690 << ") ::Phy2MacEndRx() ---->Physical layer of HN "
691 "with MAC"
692 << " address: " << dest_mac_addr
693 << " has finished to receive a DATA packet"
694 << " number: " << (getDataPckRx_by_HN() + 1)
695 << " from the NODE with MAC address: "
696 << src_mac_addr << std::endl;
697
699
702
703 curr_DATA_HN_pck_rx = p->copy();
704
706
708
709 Packet::free(p);
710
711 DATA_rx();
712 }
713 }
714 } else {
715 // Packet is not addressed to me HN
716 if (debug_)
717 std::cout << NOW << " uwUFetch_NODE (" << addr
718 << ") ::Phy2MacEndRx() ---->The packet received is not "
719 "for me HN:"
720 << " DROP IT." << std::endl;
721
722 if (cmh->ptype() == PT_POLL_UFETCH) {
723 // POLL section
724 if (debug_)
725 std::cout << NOW << " uwUFetch_NODE (" << addr
726 << ") ::Phy2MacEndRx() ---->HN has finished to "
727 "receive a"
728 << " POLL packet from the HN with MAC address: "
729 << src_mac_addr << " .DROP IT" << std::endl;
730
732
733 } else if (cmh->ptype() == PT_PROBE_UFETCH) {
734 // BEACON section
735 if (debug_)
736 std::cout << NOW << " uwUFetch_NODE (" << addr
737 << ") ::Phy2MacEndRx() ---->HN has finished to "
738 "receive a"
739 << " PROBE packet from the SENSOR NODE with MAC "
740 "address: "
741 << src_mac_addr << " .DROP IT" << std::endl;
742 if (debugMio_)
743 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
744 << ")::Phy2MacEndRx()________________________"
745 "Finished_to_rx_PROBE"
746 << "_pck_from_SN(" << src_mac_addr
747 << ").Not_addressed_to_me:_IGNORE_IT."
748 << std::endl;
749
751
752 } else if (cmh->ptype() == PT_TRIGGER_UFETCH) {
753 // TRIGGER section
754 if (debug_)
755 std::cout << NOW << " uwUFetch_NODE (" << addr
756 << ") ::Phy2MacEndRx() ---->HN has finished to "
757 "receive a"
758 << " TRIGGER packet from the AUV with MAC address ("
759 << src_mac_addr << ").DROP IT" << std::endl;
760
761 if (debugMio_)
762 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
763 << ")::Phy2MacEndRx()________________________"
764 "Finished_to_rx_TRIGGER"
765 << "_pck_from_AUV(" << src_mac_addr
766 << ")._Not_addressed_to_me:_IGNORE_IT."
767 << std::endl;
768
770
771 } else if (cmh->ptype() == PT_CTS_UFETCH) {
772 // CTS section
773 if (debug_)
774 std::cout << NOW << " uwUFetch_NODE (" << addr
775 << ") ::Phy2MacEndRx() ---->HN has finished to "
776 "receive a"
777 << " POLL packet from the HN with MAC address: "
778 << src_mac_addr << " .DROP IT" << std::endl;
779
780 if (debugMio_)
781 out_file_logging << NOW << "uwUFetch_HEAD_NODE (" << addr
782 << ")::Phy2MacEndRx()________________________"
783 "Finished_to_rx_CTS"
784 << "_pck_from_AUV(" << src_mac_addr
785 << ")._Not_addressed_to_me:_IGNORE_IT."
786 << std::endl;
787
789
790 } else {
791 // DATA section
792 if (debug_)
793 std::cout << NOW << " uwUFetch_NODE (" << addr
794 << ") ::Phy2MacEndRx() ---->HN has finished to "
795 "receive a"
796 << " DATA packet from the SENSOR NODE with MAC "
797 "address: "
798 << src_mac_addr << " .DROP IT" << std::endl;
799
800 if (debugMio_)
801 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
802 << ")::Phy2MacEndRx()________________________"
803 "End_to_rx_DATA_pck_"
804 << "from_SN(" << src_mac_addr
805 << ")._Not_addressed_to_me:_IGNORE_IT."
806 << std::endl;
807
809 }
810 }
811} // end Phy2MacEndRx_HN();
812
813void
815{
816
817 hdr_cmn *cmh = hdr_cmn::access(p);
818 hdr_mac *mach = HDR_MAC(p);
819 if (cmh->ptype() == PT_BEACON_UFETCH) {
820 // BEACON section
821 if (debug_)
822 std::cout << NOW << " uwUFetch_NODE (" << addr
823 << ") ::Mac2PhyStartTx() ---->MAC layer of the HN passes "
824 "the BEACON"
825 << " packet to his physical layer." << std::endl;
826
827 if (mach->macDA() == -1) {
828 if (debugMio_)
829 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
830 << ")::Mac2PhyStartTx()______________________"
831 "Start_tx_of_BEACON_pck_in_BROADCAST."
832 << std::endl;
833 } else {
834 if (debugMio_)
835 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
836 << ")::Mac2PhyStartTx()______________________"
837 "Start_tx_of_BEACON_pck_to_SENSOR_NODE("
838 << mach->macDA() << ")." << std::endl;
839 }
841
842 MMac::Mac2PhyStartTx(p);
843
844 } else if (cmh->ptype() == PT_POLL_UFETCH) {
845 // POLL section
846 if (debug_)
847 std::cout << NOW << " uwUFetch_NODE (" << addr
848 << ") ::Mac2PhyStartTx() ---->MAC layer of HN passes the "
849 "POLL"
850 << " packet to his physical layer." << std::endl;
851
852 if (debugMio_)
853 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
854 << ")::Mac2PhyStartTx()______________________"
855 "Start_tx_of_POLL_pck_to_the_SENSOR_NODE("
856 << mac_addr_NODE_polled << ")." << std::endl;
857
859
860 MMac::Mac2PhyStartTx(p);
861
862 } else if (cmh->ptype() == PT_CBEACON_UFETCH) {
863 // CBEACON section
864 if (debug_)
865 std::cout << NOW << " uwUFetch_NODE (" << addr
866 << ") ::Mac2PhyStartTx() ---->MAC layer of the HN passes "
867 "the CBEACON"
868 << " packet to his physical layer." << std::endl;
869
870 if (debugMio_)
871 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
872 << ")::Mac2PhyStartTx()______________________"
873 "Start_tx_of_CBEACON_pck_in_BROADCAST."
874 << std::endl;
875
877
878 MMac::Mac2PhyStartTx(p);
879
880 } else if (cmh->ptype() == PT_RTS_UFETCH) {
881 // RTS section
882 if (debug_)
883 std::cout << NOW << " uwUFetch_NODE (" << addr
884 << ") ::Mac2PhyStartTx() ---->MAC layer of the HN passes "
885 "the RTS"
886 << " packet to his physical layer." << std::endl;
887
888 if (debugMio_)
889 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
890 << ")::Mac2PhyStartTx()______________________"
891 "Start_tx_of_RTS_pck_to_the_AUV("
892 << mac_addr_AUV_in_trigger << ")." << std::endl;
893
895
896 MMac::Mac2PhyStartTx(p);
897
898 } else {
899 // DATA section
900 if (debug_)
901 std::cout << NOW << " uwUFetch_NODE (" << addr
902 << ") ::Mac2PhyStartTx() ---->MAC layer of the HN passes "
903 "the DATA"
904 << " packet to his physical layer." << std::endl;
905 if (debugMio_)
906 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
907 << ")::Mac2PhyStartTx()______________________"
908 "Start_tx_of_DATA_pck"
909 << "_to_the_AUV(" << mac_addr_AUV_in_CTS << ")."
910 << std::endl;
911
913
914 Tdata_HN_pck = Mac2PhyTxDuration(p);
915 // Tdata_HN_pck = Tdata_HN_pck + 0.2;
917
918 MMac::Mac2PhyStartTx(p);
919 }
920} // end Mac2PhyStartTx_HN();
921
922void
923uwUFetch_NODE::Phy2MacEndTx_HN(const Packet *p)
924{
925
926 hdr_cmn *cmh = hdr_cmn::access(p);
927
928 if (cmh->ptype() == PT_BEACON_UFETCH) {
929 // BEACON section
930 if (debug_)
931 std::cout
932 << NOW << " uwUFetch_NODE (" << addr
933 << ") ::Phy2MacEndTx() ---->Physical layer of HN has "
934 "finished"
935 << " to transmit a BEACON packet to the NODEs in broadcast."
936 << std::endl;
937
938 if (debugMio_)
939 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
940 << ")::Phy2MacEndTx()________________________End_"
941 "the_tx_of_BEACON_pck_in_BROADCAST."
942 << std::endl;
943
947
948 txBEACONEnabled = false;
949
951
952 } else if (cmh->ptype() == PT_POLL_UFETCH) {
953 // POLL section
954 if (debug_)
955 std::cout << NOW << " uwUFetch_NODE (" << addr
956 << ") ::Phy2MacEndTx() ---->Physical layer of the HN has "
957 "finished"
958 << " to transmit a POLL packet to the NODE with MAC "
959 "address: "
960 << mac_addr_NODE_polled << std::endl;
961
962 if (debugMio_)
963 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
964 << ")::Phy2MacEndTx()________________________End_"
965 "the_tx_of_POLL_pck_to_the_SENSOR NODE"
966 << "(" << mac_addr_NODE_polled << ")."
967 << std::endl;
968
970
973
974 txPOLLEnabled = false;
975
977
978 } else if (cmh->ptype() == PT_CBEACON_UFETCH) {
979 // CBEACON section
980 if (debug_)
981 std::cout << NOW << " uwUFetch_NODE (" << addr
982 << ") ::Phy2MacEndTx() ---->Physical layer of the HN has "
983 "finished"
984 << " to transmit a CBEACON packet to the NODEs in "
985 "broadcast."
986 << std::endl;
987 if (debugMio_)
988 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
989 << ")::Phy2MacEndTx()________________________End_"
990 "the_tx_of_CBEACON_pck_in_BROADCAST."
991 << std::endl;
992
994
997
998 txCBEACONEnabled = false;
999
1001
1002 } else if (cmh->ptype() == PT_RTS_UFETCH) {
1003 // RTS section
1004 if (debug_)
1005 std::cout
1006 << NOW << " uwUFetch_NODE (" << addr
1007 << ") ::Phy2MacEndTx() ---->Physical layer of the HN has "
1008 "finished"
1009 << " to transmit a RTS packet to the AUV with MAC address: "
1010 << mac_addr_AUV_in_trigger << std::endl;
1011 if (debugMio_)
1012 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1013 << ")::Phy2MacEndTx()________________________End_"
1014 "the_tx_of_RTS_pck_to_the_AUV("
1015 << mac_addr_AUV_in_trigger << ")." << std::endl;
1016
1018
1021
1022 txRTSEnabled = false;
1023
1025
1026 } else {
1027 // DATA section
1028 if (debug_)
1029 std::cout << NOW << " uwUFetch_NODE (" << addr
1030 << ") ::Phy2MacEndTx() ---->Physical layer of the HN has "
1031 "finished"
1032 << " to transmit a DATA to the AUV with MAC address: "
1033 << mac_addr_AUV_in_CTS << std::endl;
1034
1036
1039
1040 if (debugMio_)
1041 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1042 << ")::Phy2MacEndTx()________________________End_"
1043 "the_tx_of_DATA"
1044 << "_pck_to_the_AUV(" << mac_addr_AUV_in_CTS
1045 << ")." << std::endl;
1046
1047 if (debugMio_)
1049 << NOW << "uwUFetch_HEAD_NODE(" << addr
1050 << ")::Phy2MacEndTx()________________________DATA pck"
1051 << " number " << getDataPckTx_by_HN() << "." << std::endl;
1052
1053 if (debug_)
1054 std::cout << NOW << " uwUFetch_NODE (" << addr
1055 << ") ::Phy2MacEndTx() ---->GET DATA PCK TX BY HN "
1057 << " to transmit a DATA to the AUV with MAC address: "
1058 << mac_addr_AUV_in_trigger << std::endl;
1059
1062 } else {
1064 }
1065 }
1066
1067} // end Phy2MacEndTx_HN();
1068
1069/******************************************************************************
1070 * HEAD NODE *
1071 ******************************************************************************/
1072void
1074{
1075
1076 if (debug_)
1077 std::cout << NOW << " uwUFetch_NODE (" << addr
1078 << ") ::stateIdle_HN() ---->HN is in IDLE STATE" << std::endl;
1079 if (debugMio_)
1080 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1081 << ")::stateIdle_HN()________________________HN_is_in_"
1082 "IDLE_STATE"
1083 << std::endl;
1089 if (debug_)
1090 std::cout << NOW << " uwUFetch_NODE (" << addr
1091 << ") ::stateIdle_HN() ---->HN before to start the "
1092 "communication with"
1093 << " sensor node or AUV, empty his data queue." << std::endl;
1094
1101 int index_q = 0;
1102 while ((!Q_data.empty()) && (index_q <= MAX_PCK_HN_WANT_RX_FROM_NODE)) {
1103 // Pick up the first element of the queue
1104 curr_DATA_NODE_pck_tx_HN = (Q_data.front())->copy();
1105 // Remove the element from the queue that we have pick up the packet
1106 Q_data.pop();
1107 // Add the packet to the queue of data packets that HN will transmit to
1108 // AUV when
1109 // will be required
1111 Q_data_source_SN.push(addr); // Save the MAC address from which the data
1112 // packet it's arrived.
1115
1117 if (debugMio_)
1118 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1119 << ")::stateIdle_HN()________________________DATA_"
1120 "pck_rx:_source("
1121 << addr << ")_"
1122 << "destination(" << addr
1123 << ")_id_pck:" << cbrh->sn() << "" << std::endl;
1124 index_q++;
1125 }
1126
1130
1131 rxTRIGGEREnabled = true;
1132
1133 if ((last_reason ==
1135 (last_reason ==
1137 (last_reason ==
1140 if (last_reason ==
1142 /* if (debug_) std::cout << NOW << " uwUFetch_NODE (" << addr << ")
1143 ::stateIdle_HN() ---->HN has analyzed the TRIGGER,"
1144 << " but it hasn't DATA to transmit, so"
1145 << " start immediately the communication with SENSOR
1146 NODES." << std::endl;*/
1147 } else if (last_reason ==
1149 /* if (debug_) std::cout << NOW << " uwUFetch_NODE (" << addr << ")
1150 ::stateIdle_HN() ---->HN has transmitted all his"
1151 << " DATA packets to the AUV, so start immediately the
1152 communication with SENSOR NODES." << std::endl;*/
1153 } else if (last_reason ==
1155 /* if (debug_) std::cout << NOW << " uwUFetch_NODE (" << addr << ")
1156 ::stateIdle_HN() ---->HN has analyzed the TRIGGER,"
1157 << " but it's corrupted, so start immediately the
1158 communication with SENSOR NODES." << std::endl;*/
1159 } else if (last_reason ==
1161 /* if (debug_) std::cout << NOW << " uwUFetch_NODE (" << addr << ")
1162 ::stateIdle_HN() ---->HN has analyzed the TRIGGER,"
1163 << " has transmitted a CTS packet but it has never
1164 received a CTS packet, so start immediately"
1165 << " the communication with SENSOR NODES." << std::endl;*/
1166 }
1167
1168 if (debug_)
1169 std::cout << NOW << " uwUFetch_NODE (" << addr
1170 << ") ::stateIdle_HN() ---->HN before to start the "
1171 "communication"
1172 << " with SENSOR NODES wait an interval time equal to: "
1173 << 15 << "[s]." << std::endl;
1174
1175 CTSrx = false;
1176
1177 txBEACONEnabled = true;
1178 rxTRIGGEREnabled = false;
1179
1181
1182 } else {
1183 if ((!Q_data_HN.empty()) && (Q_data_HN.size() >= 1)) {
1190 if (debug_)
1191 std::cout << NOW << " uwUFetch_NODE (" << addr
1192 << ") ::stateIdle_HN() ---->HN waits a TRIGGER "
1193 "packets from the AUV"
1194 << " for an interval time equal to: "
1196 << " [s] before to start the communication"
1197 << " with the SENSOR NODEs." << std::endl;
1198
1200
1201 } else {
1208 if (debug_)
1209 std::cout << NOW << " uwUFetch_NODE (" << addr
1210 << ") ::stateIdle_HN() ---->HN waits a TRIGGER "
1211 "packets from the AUV"
1212 << " for an interval time equal to: "
1214 << "[s] before to start the communication"
1215 << " with the SENSOR NODEs." << std::endl;
1216
1218 }
1219 }
1220} // end stateIdle_HN();
1221
1222void
1224{
1225
1226 if (debug_)
1227 std::cout << NOW << " uwUFetch_NODE (" << addr
1228 << ") ::BeaconTxTOExpire() ---->HN start the procedure for "
1229 "communicate"
1230 << " with the SENSOR NODEs, reception of TRIGGER packet is "
1231 "not enabled. "
1232 << std::endl;
1233
1234 if (debugMio_)
1235 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1236 << ")::BeaconTxTOExpire()____________________HN_start_"
1237 "communication_with_SNs."
1238 << std::endl;
1239
1241
1242 CTSrx = false;
1243
1244 txBEACONEnabled = true;
1245 rxTRIGGEREnabled = false;
1246
1253 int index_q = 0;
1254 while ((!Q_data.empty()) && (index_q <= MAX_PCK_HN_WANT_RX_FROM_NODE)) {
1255 // Pick up the first element of the queue
1256 curr_DATA_NODE_pck_tx_HN = (Q_data.front())->copy();
1257 // Remove the element from the queue that we have pick up the packet
1258 Q_data.pop();
1259 // Add the packet to the queue of data packets that HN will transmit to
1260 // AUV when
1261 // will be required
1263 Q_data_source_SN.push(addr); // Save the MAC address from which the data
1264 // packet it's arrived.
1267
1269 if (debugMio_)
1270 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1271 << ")::BeaconTxTOExpire()____________________DATA_"
1272 "pck_rx:_source("
1273 << addr << ")_"
1274 << "destination(" << addr
1275 << ")_id_pck:" << cbrh->sn() << "" << std::endl;
1276
1277 index_q++;
1278 }
1279
1281} // end BeaconTxTOExpire();
1282
1283void
1285{
1286
1287 if (typeCommunication()) {
1288 // Communication between HN & AUV without RTS and CTS packets
1289
1291 } else {
1292 // Communication between HN & AUV with RTS and CTS packets
1293 if (rxTRIGGEREnabled) {
1294 // HN is enabled to receive a TRIGGER
1295 if (debug_)
1296 std::cout << NOW << " uwUFetch_NODE (" << addr
1297 << ") ::TRIGGER_rx() ---->HN reset the TRIGGER timer"
1298 << std::endl;
1299
1300 if (debugMio_)
1301 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1302 << ")::TRIGGER_rx()_________________________"
1303 "TRIGGER_rx_It_s_CORRECT_and_>= "
1304 "1_DATA_to_tx_and_enabled_to_rx_It."
1305 << std::endl;
1306
1307 BeaconBeforeTx_timer.force_cancel(); // reset the timer in which the
1308 // HN wait a TRIGGER packet
1309
1313
1314 hdr_mac *mach = HDR_MAC(curr_TRIGGER_HN_pck_rx);
1315 hdr_TRIGGER_UFETCH *triggerh =
1317
1318 /*
1319 * Save the header data of the trigger
1320 */
1321 T_min_bck_RTS = (double) triggerh->t_min() /
1322 1000; // Minimum value time before that HN transmit a RTS
1323 // packet
1324 T_max_bck_RTS = (double) triggerh->t_max() /
1325 1000; // Maximum value time before that HN transmit a RTS
1326 // packet
1328 triggerh->max_pck_want_rx(); // Maximum number of DATA
1329 // packet that HN can transmit
1330 // to the AUV
1331
1333 mach->macSA(); // Save the MAC address of the AUV node from
1334 // which the HN has received a trigger packet
1335
1336 if (debugMio_)
1337 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1338 << ")::TRIGGER_rx()__________________________"
1339 "PARAMETERS_of_TRIGGER_PACKET: "
1340 << std::endl;
1341 if (debugMio_)
1342 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1343 << ")::TRIGGER_rx()__________________________"
1344 "Source_address:_"
1345 << mach->macSA() << "." << std::endl;
1346 if (mach->macDA() == -1) {
1347 if (debugMio_)
1348 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1349 << ")::TRIGGER_rx()_______________________"
1350 "___Destination_Address:_BROADCAST."
1351 << std::endl;
1352 } else {
1353 if (debugMio_)
1354 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1355 << ")::TRIGGER_rx()_______________________"
1356 "___Destination_Address:_"
1357 << mach->macDA() << std::endl;
1358 }
1359 if (debugMio_)
1360 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1361 << ")::TRIGGER_rx()__________________________"
1362 "MIN_backoff_time_RTS_pck:_"
1363 << T_min_bck_RTS << "[s]." << std::endl;
1364 if (debugMio_)
1365 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1366 << ")::TRIGGER_rx()__________________________"
1367 "MAX_backoff_time_RTS_pck:_"
1368 << T_max_bck_RTS << "[s]." << std::endl;
1369 if (debugMio_)
1370 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1371 << ")::TRIGGER_rx()__________________________"
1372 "MAX_DATA_pck_want_rx_from_HN:_"
1373 << max_pck_HN_can_tx << "[pck]." << std::endl;
1374
1375 rxTRIGGEREnabled = false;
1376 txBEACONEnabled = false;
1377
1379 if (debugMio_)
1380 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1381 << ")::TRIGGER_rx()__________________________"
1382 "Backoff_timeout_choice:_"
1383 << bck_before_tx_RTS << "[s]." << std::endl;
1385
1386 } else {
1387 // HN is not enable to receive a TRIGGER packet
1388 if (debug_)
1389 std::cout
1390 << NOW << " uwUFetch_NODE (" << addr
1391 << ") ::TRIGGER_rx() ---->HN is not enabled to receive"
1392 << " the TRIGGER packet: DROP IT." << std::endl;
1393
1394 if (debugMio_)
1396 << NOW << "uwUFetch_HEAD_NODE(" << addr
1397 << ")::TRIGGER_rx()_________________________TRIGGER_rx_"
1398 "It_s_CORRECT_and_>= "
1399 "1_DATA_to_tx_and_not_enabled_to_rx_It:IGNORE_It."
1400 << std::endl;
1401
1402 if (debugMio_)
1403 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1404 << ")::TRIGGER_rx()__________________________"
1405 "Not_ENABLED"
1406 << "_to_rx_TRIGGER_pck." << std::endl;
1408 1,
1410 }
1411 }
1412} // end TRIGGER_rx();
1413
1414void
1416{
1417 if (typeCommunication()) {
1418 // Communication between HN & AUV without RTS and CTS packets
1420 } else {
1421 // Communication between HN & AUV with RTS and CTS packets
1422 if (debug_)
1423 std::cout << NOW << " uwUFetch_NODE (" << addr
1424 << ") ::BCKTOExpired() ---->Back-off timeout is expired:"
1425 << " so the first DATA packet can be transmitted by the "
1426 "HN to the AUV."
1427 << std::endl;
1428
1429 if (debugMio_)
1430 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1431 << ")::BCKTOExpired()________________________"
1432 "Backoff_timeout_expired."
1433 << std::endl;
1434
1435 state_RTS_tx();
1436 }
1437} // end BCKTOExpired();
1438
1439void
1441{
1442 // Transmit a RTS packet to the AUV
1443 if (!Q_data_HN.empty()) {
1444 // Queue is not empty so HN has at least one DATA packet to transmit to
1445 // the AUV
1446 if (debug_)
1447 std::cout << NOW << " uwUFetch_NODE (" << addr
1448 << ") ::state_RTS_tx() ---->HN with MAC address " << addr
1449 << " create"
1450 << " a RTS packet that will then transmit to the AUV "
1451 "with MAC address: "
1452 << mac_addr_AUV_in_trigger << std::endl;
1453
1457
1458 Packet *p = Packet::alloc();
1459 hdr_cmn *cmh = hdr_cmn::access(p);
1460 hdr_mac *mach = HDR_MAC(p);
1461 hdr_RTS_UFETCH *rtsh = HDR_RTS_UFETCH(p);
1462
1463 cmh->ptype() = PT_RTS_UFETCH;
1464 cmh->size() = sizeof(hdr_RTS_UFETCH);
1465
1466 mach->set(MF_CONTROL, addr, mac_addr_AUV_in_trigger);
1467 mach->macSA() = addr;
1468 mach->macDA() = mac_addr_AUV_in_trigger;
1469
1470 // Filling the HEADER of the RTS packet
1471 rtsh->num_DATA_pcks() = Q_data_HN.size(); // Number of packets that HN
1472 // want to transmit at the AUV
1473 rtsh->backoff_time_RTS() = (int) (bck_before_tx_RTS *
1474 1000); // Back-off timer choice before to transmit a RTS packet
1475
1476 curr_RTS_HN_pck_tx = p->copy();
1477
1478 txRTSEnabled = true;
1479
1480 if (debugMio_)
1481 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1482 << ")::state_RTS_tx()________________________"
1483 "PARAMETERS_of_RTS_PACKET. "
1484 << std::endl;
1485 if (debugMio_)
1486 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1487 << ")::state_RTS_tx()________________________"
1488 "Source_address:_"
1489 << mach->macSA() << "." << std::endl;
1490 if (mach->macDA() == -1) {
1491 if (debugMio_)
1492 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1493 << ")::state_RTS_tx()________________________"
1494 "Destination_Address:_BROADCAST."
1495 << std::endl;
1496 } else {
1497 if (debugMio_)
1498 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1499 << ")::state_RTS_tx()________________________"
1500 "Destination_Address:_"
1501 << mac_addr_AUV_in_trigger << "." << std::endl;
1502 }
1503 if (debugMio_)
1504 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1505 << ")::state_RTS_tx()________________________RTS_"
1506 "backoff_time_choice_by_HN: "
1507 << bck_before_tx_RTS << "[s]." << std::endl;
1508 if (debugMio_)
1509 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1510 << ")::state_RTS_tx()________________________"
1511 "Number_of_pck_HN_would_like_to_tx:_"
1512 << rtsh->num_DATA_pcks() << "[pck]." << std::endl;
1513 if (debugMio_)
1514 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1515 << ")::state_RTS_tx()________________________Size_"
1516 "of_RTS_pck:_"
1517 << cmh->size() << "[byte]." << std::endl;
1518
1519 Packet::free(p);
1520
1521 RTS_tx();
1522
1523 } else {
1524 // QUEUE is empty, so the HN doesn't transmit a RTS packet to the HN.
1525 if (debug_)
1526 std::cout << NOW << " uwUFetch_NODE (" << addr
1527 << ") ::state_RTS_tx() ----> HN with MAC address" << addr
1528 << " has no DATA"
1529 << " packet to be transmitted to the HN, then ignore the "
1530 "TRIGGER received from the AUV with"
1531 << " MAC address: " << mac_addr_AUV_in_trigger
1532 << ", and return in IDLE STATE." << std::endl;
1533 if (debugMio_)
1534 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1535 << ")::state_RTS_tx()________________________0_"
1536 "DATA_pck_to_tx:_NO_tx_RTS_pck."
1537 << std::endl;
1540
1545
1546 txBEACONEnabled = true;
1547 rxTRIGGEREnabled = true;
1548 txRTSEnabled = false;
1549
1550 stateIdle_HN();
1551 }
1552} // end state_RTS_tx();
1553
1554void
1556{
1557 // HN is enabled to transmit RTS packet
1558 if (debug_)
1559 std::cout << NOW << " uwUFetch_NODE (" << addr
1560 << ") ::RTS_tx() ---->HN with MAC address: " << addr
1561 << " is transmitting"
1562 << " a RTS packet to the AUV with MAC address: "
1563 << mac_addr_AUV_in_trigger << std::endl;
1564
1566
1568} // end RTS_tx();
1569
1570void
1572{
1573
1574 if (debug_)
1575 std::cout << NOW << " uwUFetch_NODE (" << addr
1576 << ") ::state_wait_CTS() ---->HN with MAC address: " << addr
1577 << " is"
1578 << " waiting the CTS packet from AUV with MAC address: "
1579 << mac_addr_AUV_in_trigger << ". The maximum"
1580 << " waiting time is: " << T_CTS << std::endl;
1581
1585
1586 if (T_CTS < 0) {
1587 if (debug_)
1588 std::cout << NOW << " uwUFetch_NODE (" << addr
1589 << ") ::state_wait_CTS() ---->CTS timer insert by the "
1590 "user for waiting a CTS"
1591 << " packet is negative, so use the default value 20[s]"
1592 << std::endl;
1593 T_CTS = 20;
1594 }
1595
1596 if (debugMio_)
1597 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1598 << ")::state_wait_CTS()______________________Waiting_"
1599 "a_CTS_pck_from_AUV("
1600 << mac_addr_AUV_in_trigger << ")." << std::endl;
1601 if (debugMio_)
1602 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1603 << ")::state_wait_CTS()______________________......."
1604 "Waiting_CTS_pck."
1605 << std::endl;
1606 if (debugMio_)
1607 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1608 << ")::state_wait_CTS()______________________......."
1609 "Waiting_CTS_pck."
1610 << std::endl;
1611 if (debugMio_)
1612 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1613 << ")::state_wait_CTS()______________________......."
1614 "Waiting_CTS_pck."
1615 << std::endl;
1616
1617 rxCTSEnabled = true; // enable HN to receive CTS packet
1618
1620} // end state_wait_CTS();
1621
1622void
1624{
1625
1626 if (debug_)
1627 std::cout << NOW << " uwUFetch_NODE (" << addr
1628 << ") ::CtsTOExpired() ---->Timeout CTS expired. HN has not "
1629 "receive"
1630 << " CTS packet within the pre-established time interval "
1631 "that is equal to: "
1632 << T_CTS << " [s]."
1633 << " so return in IDLE STATE." << std::endl;
1634 if (debugMio_)
1635 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1636 << ")::CtsTOExpired()________________________CTS_"
1637 "timeout_expired."
1638 << std::endl;
1640
1644
1645 txBEACONEnabled = true;
1646 rxPROBEEnabled = false;
1647 txPOLLEnabled = false;
1648 rxDATAEnabled = false;
1649 txCBEACONEnabled = false;
1650 rxTRIGGEREnabled = true;
1651 txRTSEnabled = false;
1652 rxCTSEnabled = false;
1653 txDATAEnabledHN = false;
1654
1655 CTSrx = true;
1656 stateIdle_HN();
1657} // end CtsTOExpired();
1658
1659void
1661{
1662
1663 CTSrx = true;
1667
1668 hdr_mac *mach = HDR_MAC(curr_CTS_HN_pck_rx);
1670
1671 /*
1672 * Save the header data of the CTS
1673 */
1675 ctsh->num_DATA_pcks_MAX_rx(); // Maximum number of DATA packets that
1676 // the HN can transmit to the AUV
1677
1678 mac_addr_AUV_in_CTS = mach->macSA(); // MAC address of the AUV node from
1679 // which the HN has received a CTS
1680 // packet
1681
1682 rxCTSEnabled = false;
1683 if (debugMio_)
1684 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1685 << ")::CTS_rx()______________________________"
1686 "PARAMETERS_of_CTS_PACKET."
1687 << std::endl;
1688 if (debugMio_)
1690 << NOW << "uwUFetch_HEAD_NODE(" << addr
1691 << ")::CTS_rx()______________________________Source_address:_"
1692 << mach->macSA() << "." << std::endl;
1693 if (mach->macDA() == -1) {
1694 if (debugMio_)
1695 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1696 << ")::CTS_rx()______________________________"
1697 "Destination_Address:_BROADCAST."
1698 << std::endl;
1699 } else {
1700 if (debugMio_)
1701 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1702 << ")::CTS_rx()______________________________"
1703 "Destination_Address:_"
1704 << mach->macDA() << "." << std::endl;
1705 }
1706 if (debugMio_)
1707 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1708 << ")::CTS_rx()______________________________DATA_pck_"
1709 "want_rx_from_HN: "
1710 << max_data_HN_can_tx << "[pck]." << std::endl;
1711
1713
1714 CTSrx = true;
1715} // end CTS_rx();
1716
1717void
1719{
1720
1721 if (typeCommunication()) {
1722 // Communication between HN & AUV without RTS and CTS packets
1724 } else {
1725 // Communication between HN & AUV with RTS and CTS packets
1726 if (debug_)
1727 std::cout
1728 << NOW << " uwUFetch_NODE (" << addr
1729 << ") ::state_DATA_HN_first_tx() ---->HN will be transmit "
1731 << " DATA packets to the AUV with MAC address: "
1732 << mac_addr_AUV_in_CTS << std::endl;
1733
1734 if (debugMio_)
1735 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1736 << ")::state_DATA_HN_first_tx()______________DATA_"
1737 "pck_to_tx_"
1738 << max_data_HN_can_tx << "_to_the_AUV("
1739 << mac_addr_AUV_in_CTS << ")." << std::endl;
1740
1741 if (debug_)
1742 std::cout << NOW << " uwUFetch_NODE (" << addr
1743 << ") ::state_DATA_HN_first_tx() ---->HN is starting "
1744 "transmission of the"
1745 << " FIRST DATA packet to the AUV with MAC address: "
1746 << mac_addr_AUV_in_CTS << std::endl;
1747
1748 // Pick up the first element of the queue
1749 curr_DATA_HN_pck_tx = (Q_data_HN.front())->copy();
1750 // Remove the element from the queue that we have pick up
1751 Q_data_HN.pop();
1752
1753 hdr_mac *mach = HDR_MAC(curr_DATA_HN_pck_tx);
1754 hdr_cmn *cmh = hdr_cmn::access(curr_DATA_HN_pck_tx);
1756
1757 mach->set(MF_CONTROL, addr, mac_addr_AUV_in_CTS);
1758 mach->macSA() = addr;
1759 mach->macDA() = mac_addr_AUV_in_CTS;
1760 cmh->size() = sizeof(curr_DATA_HN_pck_tx);
1761
1762 if (burstDATA()) {
1763 // hdr_uwmphy_modem* modemh = HDR_UWMPHY_MODEM(curr_DATA_HN_pck_tx);
1764 // modemh->use_burst_data() = 1;
1765 // if (getDataPckTx_by_HN() == (max_data_HN_can_tx)) {
1766 // modemh->last_packet() = 1;
1767 // modemh->use_burst_data() = 1;
1768 // } else {
1769 // modemh->last_packet() = 0;
1770 // modemh->use_burst_data() = 1;
1771 // }
1772
1773 txDATAEnabledHN = true;
1774
1775 int old_sn = cbrh->sn();
1776 cbrh->sn() = pck_number_id;
1777 pck_number_id++;
1778
1779 if (debugMio_)
1780 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1781 << ")::state_DATA_HN_first_tx()______________"
1782 "DATA_pck_tx:_source_SN("
1783 << Q_data_source_SN.front() << ")_source_HN("
1784 << mach->macSA() << ")_"
1785 << "destination(" << mach->macDA()
1786 << ")_id_pck_original:" << old_sn
1787 << "_new_id_pck:" << cbrh->sn()
1788 << "_size:" << cmh->size() << "[byte]"
1789 << std::endl;
1790 Q_data_source_SN.pop();
1791
1792 DATA_HN_tx();
1793 } else {
1794 txDATAEnabledHN = true;
1795
1796 int old_sn = cbrh->sn();
1797 cbrh->sn() = pck_number_id;
1798 pck_number_id++;
1799
1800 if (debugMio_)
1801 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1802 << ")::state_DATA_HN_first_tx()______________"
1803 "DATA_pck_tx:_source_SN("
1804 << Q_data_source_SN.front() << ")_source_HN("
1805 << mach->macSA() << ")_"
1806 << "destination(" << mach->macDA()
1807 << ")_id_pck_original:" << old_sn
1808 << "_new_id_pck:" << cbrh->sn()
1809 << "_size:" << cmh->size() << "[byte]"
1810 << std::endl;
1811
1812 Q_data_source_SN.pop();
1813 DATA_HN_tx();
1814 }
1815 }
1816} // end state_DATA_HN_first_tx();
1817
1818void
1820{
1821 if (typeCommunication()) {
1822 // Communication between HN & AUV without RTS and CTS packets
1824 } else {
1825 // Communication between HN & AUV with RTS and CTS packets
1826 // HN is enabled to transmit DATA packet
1827 if (debug_)
1828 std::cout << NOW << " uwUFetch_NODE (" << addr
1829 << ") ::DATA_HN_tx() ---->HN is transmitting a DATA "
1830 "packet to the AUV"
1831 << " with MAC address: " << mac_addr_AUV_in_CTS
1832 << std::endl;
1833
1835
1837 }
1838} // end DATA_HN_tx();
1839
1840void
1842{
1843
1844 if (debug_)
1845 std::cout << NOW << " uwUFetch_NODE (" << addr
1846 << ") ::DataBeforeTxTOExpired() ---->HN can transmit the next"
1847 << " DATA packet." << std::endl;
1848
1850
1851} // end DataBeforeTxTOExpired();
1852
1853void
1855{
1856
1857 if (typeCommunication()) {
1858 // Communication between HN & AUV without RTS and CTS packets
1860 } else {
1861 // Communication between HN & AUV with RTS and CTS packets
1862 if (debug_)
1863 std::cout << NOW << " uwUFetch_NODE (" << addr
1864 << ") ::state_DATA_HN_tx() ---->HN is starting "
1865 "transmission of the"
1866 << " DATA packet number: " << (getDataPckTx_by_HN() + 1)
1867 << " to the AUV with"
1868 << " MAC address: " << mac_addr_AUV_in_CTS << std::endl;
1869
1870 // Pick up the first element of the queue
1871 curr_DATA_HN_pck_tx = (Q_data_HN.front())->copy();
1872 // Remove the element from the queue that we have pick up
1873 Q_data_HN.pop();
1874
1875 hdr_mac *mach = HDR_MAC(curr_DATA_HN_pck_tx);
1876 hdr_cmn *cmh = hdr_cmn::access(curr_DATA_HN_pck_tx);
1878
1879 mach->set(MF_CONTROL, addr, mac_addr_AUV_in_CTS);
1880 mach->macSA() = addr;
1881 mach->macDA() = mac_addr_AUV_in_CTS;
1882 cmh->size() = sizeof(curr_DATA_HN_pck_tx);
1883
1884 if (burstDATA()) {
1885 // hdr_uwmphy_modem* modemh =
1886 // HDR_UWMPHY_MODEM(curr_DATA_HN_pck_tx);
1887 //
1888 // if (getDataPckTx_by_HN() == (max_data_HN_can_tx)) {
1889 // modemh->last_packet() = 1;
1890 // modemh->use_burst_data() = 1;
1891 // } else {
1892 // modemh->last_packet() = 0;
1893 // modemh->use_burst_data() = 1;
1894 // }
1895
1896 txDATAEnabledHN = true;
1897
1898 int old_sn = cbrh->sn();
1899 cbrh->sn() = pck_number_id;
1900 pck_number_id++;
1901
1902 if (debugMio_)
1903 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1904 << ")::state_DATA_HN_tx()____________________"
1905 "DATA_pck_tx:_source_SN("
1906 << Q_data_source_SN.front() << ")_source_HN("
1907 << mach->macSA() << ")_"
1908 << "destination(" << mach->macDA()
1909 << ")_id_pck_original:" << old_sn
1910 << "_new_id_pck:" << cbrh->sn()
1911 << "_size:" << cmh->size() << "[byte]"
1912 << std::endl;
1913
1914 Q_data_source_SN.pop();
1915 DATA_HN_tx();
1916
1917 } else {
1918 txDATAEnabledHN = true;
1919
1920 int old_sn = cbrh->sn();
1921 cbrh->sn() = pck_number_id;
1922 pck_number_id++;
1923
1924 if (debugMio_)
1925 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1926 << ")::state_DATA_HN_tx()____________________"
1927 "DATA_pck_tx:_source_SN("
1928 << Q_data_source_SN.front() << ")_source_HN("
1929 << mach->macSA() << ")_"
1930 << "destination(" << mach->macDA()
1931 << ")_id_pck_original:" << old_sn
1932 << "_new_id_pck:" << cbrh->sn()
1933 << "_size:" << cmh->size() << "[byte]"
1934 << std::endl;
1935
1936 Q_data_source_SN.pop();
1937 DATA_HN_tx();
1938 }
1939 }
1940} // end state_DATA_HN_tx();
1941
1942void
1944{
1945
1946 if (typeCommunication()) {
1947 // Communication between HN & AUV without RTS and CTS packets
1949 } else {
1950 // Communication between HN & AUV with RTS and CTS packets
1951 if (debugMio_)
1952 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1953 << ")::state_DATA_HN_finish_tx()_____________End_"
1954 "tx_DATA_pcks_to_the_AUV."
1955 << std::endl;
1956 if (sectionCBeacon) {
1957 // HN has start the communication with AUV before to start the
1958 // transmission of CBEACON packet, so after the end of the
1959 // communication
1960 // with AUV, HN return in state_CBEACON_tx().
1961 if (debug_)
1962 std::cout << NOW << " uwUFetch_NODE (" << addr
1963 << ") ::state_DATA_HN_finish_tx() ---->HN has "
1964 "transmitted all his DATA"
1965 << " packets to the AUV with MAC address: "
1967 << ", so return in STATE_CBEACON_TX()." << std::endl;
1968
1971 sectionCBeacon = false;
1974
1975 txDATAEnabledHN = false;
1976
1978
1979 } else {
1980 // HN has start the communication with AUV when it was in IDLE
1981 // STATE, so after the end of the communication
1982 // with AUV, HN return in stateIdle_HN().
1983 if (debug_)
1984 std::cout << NOW << " uwUFetch_NODE (" << addr
1985 << ") ::state_DATA_HN_finish_tx() ---->HN has "
1986 "transmitted all his DATA"
1987 << " packets to the AUV with MAC address: "
1988 << mac_addr_AUV_in_CTS << ", so return in IDLE STATE."
1989 << std::endl;
1993
1994 txBEACONEnabled = true;
1995 rxTRIGGEREnabled = true;
1996 txDATAEnabledHN = false;
1997
1998 stateIdle_HN();
1999 }
2000 }
2001} // end state_DATA_HN_finish_tx();
2002
2003void
2005{
2006
2007 while (!Q_probbed_mac_HN.empty()) {
2008 Q_probbed_mac_HN.pop();
2011 }
2012
2013 if (debug_)
2014 std::cout << NOW << " uwUFetch_NODE (" << addr
2015 << ") ::state_BEACON_tx() ---->HN is initializing the BEACON "
2016 "packet"
2017 << " which will then transmit to the NODEs in broadcast."
2018 << std::endl;
2019
2020 if (debugMio_)
2021 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2022 << ")::state_BEACON_tx()_____________________"
2023 "Initializing_BEACON_pck."
2024 << std::endl;
2025
2029
2030 Packet *p = Packet::alloc(); // allocate the memory
2031 hdr_cmn *cmh = hdr_cmn::access(p);
2032 hdr_mac *mach = HDR_MAC(p);
2034
2035 cmh->ptype() = PT_BEACON_UFETCH; // type of the packet
2036
2037 mach->set(MF_CONTROL, addr, MAC_BROADCAST); // set the information of the
2038 // packet (type,source
2039 // address,destination address)
2040 mach->macSA() = addr; // set the source address as AUV MAC address
2041 mach->macDA() =
2042 MAC_BROADCAST; // set the destination address as BROADCAST address
2043
2044 beaconh->t_min_bc() =
2045 (int) (T_MIN_BACKOFF_PROBE * 1000); // minimum value for to choose
2046 // the back-off time for tx
2047 // PROBE pck
2048 beaconh->t_max_bc() =
2049 (int) (T_MAX_BACKOFF_PROBE * 1000); // maximum value for to choose
2050 // the back-off time for tx
2051 // PROBE pck
2052 beaconh->num_Max_CBEACON_tx_by_HN() =
2053 MAX_ALLOWED_CBEACON_TX; // maximum number of CBEACON tx by this HN
2054 cmh->size() =
2055 sizeof(hdr_BEACON_UFETCH); // set the size of BEACON header packet
2056
2057 if (debugMio_)
2058 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2059 << ")::state_BEACON_tx()_____________________"
2060 "PARAMETERS_of_BEACON_pck."
2061 << std::endl;
2062 if (debugMio_)
2064 << NOW << "uwUFetch_HEAD_NODE(" << addr
2065 << ")::state_BEACON_tx()_____________________Source_address:_"
2066 << mach->macSA() << "." << std::endl;
2067 if (mach->macDA() == -1) {
2068 if (debugMio_)
2069 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2070 << ")::state_BEACON_tx()_____________________"
2071 "Destination_address:_BROADCAST."
2072 << std::endl;
2073 } else {
2074 if (debugMio_)
2075 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2076 << ")::state_BEACON_tx()_____________________"
2077 "Destination_address:_"
2078 << mach->macDA() << "." << std::endl;
2079 }
2080 if (debugMio_)
2081 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2082 << ")::state_BEACON_tx()_____________________MIN_"
2083 "backoff_time_PROBE_pck:_"
2084 << T_MIN_BACKOFF_PROBE << "[s]." << std::endl;
2085 if (debugMio_)
2086 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2087 << ")::state_BEACON_tx()_____________________MAX_"
2088 "backoff_time_PROBE_pck: "
2089 << T_MAX_BACKOFF_PROBE << "[s]." << std::endl;
2090 if (debugMio_)
2091 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2092 << ")::state_BEACON_tx()_____________________MAX_"
2093 "number_of_CBEACON_that_HN_will_tx:_"
2094 << beaconh->num_Max_CBEACON_tx_by_HN() << std::endl;
2095 if (debugMio_)
2096 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2097 << ")::state_BEACON_tx()_____________________Size_of_"
2098 "BEACON_pck:_"
2099 << cmh->size() << "[byte]." << std::endl;
2100
2101 curr_BEACON_HN_pck_tx = p->copy(); // create a copy of the BEACON packet
2102
2103 Packet::free(p); // de-allocate the memory
2104
2105 BEACON_tx(); // recall the function that simulate the transmission of the
2106 // BEACON
2107
2108} // end state_BEACON_tx();
2109
2110void
2112{
2113
2114 if (debug_)
2115 std::cout << NOW << " uwUFetch_NODE (" << addr
2116 << ") ::BEACON_tx() ---->HN is transmitting a BEACON packet"
2117 << " to the NODEs in broadcast." << std::endl;
2118
2120 // that the protocol
2121 // state change
2122
2124
2125} // end BEACON_tx();
2126
2127void
2129{
2130
2131 if (debug_)
2132 std::cout << NOW << " uwUFetch_NODE (" << addr
2133 << ") ::state_PROBE_wait() ---->HN is scheduling PROBE TIMER "
2134 "T= "
2135 << T_PROBE << "[s]" << std::endl;
2136
2140
2141 if (T_PROBE < 0) {
2142 if (debug_)
2143 std::cout << NOW << " uwUFetch_NODE (" << addr
2144 << ") ::state_wait_PROBE() ---->The waiting time for "
2145 "PROBE packets is negative"
2146 << " so set the default value: 15[s]." << std::endl;
2147 T_PROBE = 15;
2148 }
2149 if (debugMio_)
2150 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2151 << ")::state_wait_PROBE()____________________Waiting_"
2152 "PROBE_pck from"
2153 "_SNs."
2154 << std::endl;
2155 if (debugMio_)
2156 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2157 << ")::state_wait_PROBE()____________________Timeout_"
2158 "within_rx_PROBE"
2159 << "_pcks_" << T_PROBE << "[s]." << std::endl;
2160 if (debugMio_)
2162 << NOW << "uwUFetch_HEAD_NODE(" << addr
2163 << ")::state_wait_PROBE()____________________....Waiting_PROBE"
2164 << std::endl;
2165 if (debugMio_)
2167 << NOW << "uwUFetch_HEAD_NODE(" << addr
2168 << ")::state_wait_PROBE()____________________....Waiting_PROBE"
2169 << std::endl;
2170 if (debugMio_)
2172 << NOW << "uwUFetch_HEAD_NODE(" << addr
2173 << ")::state_wait_PROBE()____________________....Waiting_PROBE"
2174 << std::endl;
2175
2176 rxPROBEEnabled = true;
2177
2179
2180} // end state_wait_PROBE();
2181
2182void
2184{
2185
2186 if (debug_)
2187 std::cout << NOW << " uwUFetch_NODE (" << addr
2188 << ") ::ProbeTOExpired() ---->PROBE timeout is expired: other"
2189 << " PROBE packets can not be received by the HN."
2190 << std::endl;
2191
2192 if (debugMio_)
2193 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2194 << ")::ProbeTOExpired()______________________PROBE_"
2195 "timeout_expired."
2196 << std::endl;
2197
2198 if ((Q_probbed_mac_HN.empty()) &&
2200
2201 if (debug_)
2202 std::cout << NOW << " uwUFetch_NODE (" << addr
2203 << ") ::ProbeTOExpired() ---->HN has received 0 PROBE "
2204 "packets and"
2205 << " it has reached the maximum number of attempts to "
2206 "transmit CBEACON packets."
2207 << std::endl;
2208
2209 if (debugMio_)
2210 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2211 << ")::ProbeTOExpired()______________________0_"
2212 "PROBE_rx_and_MAX_CBEACON_tx."
2213 << std::endl;
2214
2217
2219 0; // reset the number of BEACON packet transmitted by the HN
2221 0; // reset the number of PROBE packet received by the HN
2223 0; // reset the number of POLL packet transmitted by the HN
2225 0; // reset the number of DATA packet received by the HN
2227 0; // reset the number of CBEACON packet transmitted by the HN
2228
2229 rxPROBEEnabled = false;
2230 txBEACONEnabled = true;
2231 rxTRIGGEREnabled = true;
2232
2233 stateIdle_HN();
2234
2235 } else if ((Q_probbed_mac_HN.empty()) &&
2237
2238 if (debug_)
2239 std::cout << NOW << " uwUFetch_NODE (" << addr
2240 << ") ::ProbeTOExpired() ---->HN has received 0 PROBE "
2241 "packet and it"
2242 << " has not reached the maximum number of attempts to "
2243 "transmit CBEACON packets"
2244 << " that is: " << MAX_ALLOWED_CBEACON_TX << std::endl;
2245
2246 if (debugMio_)
2247 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2248 << ")::ProbeTOExpired()______________________0_"
2249 "PROBE_rx_and_another_CBEACON_can_be_tx."
2250 << std::endl;
2251
2253 0; // reset the number of PROBE packet received by the HN
2255 0; // reset the number of POLL packet transmitted by the HN
2257 0; // reset the number of DATA packet received by the HN
2258
2259 rxPROBEEnabled = false;
2260 txCBEACONEnabled = true;
2261
2264
2266
2267 } else {
2268
2269 if (debug_)
2270 std::cout << NOW << " uwUFetch_NODE (" << addr
2271 << ") ::ProbeTOExpired() ---->HN has received "
2272 << (Q_probbed_mac_HN.size())
2273 << " PROBE packets, so start a new transmission of POLL "
2274 "packet."
2275 << std::endl;
2276
2278 0; // reset the number of DATA packet received by the HN
2279
2280 rxPROBEEnabled = false;
2281
2284
2285 state_POLL_tx();
2286 }
2287} // end ProbeTOExpire();
2288
2289void
2291{
2292 // HN is enabled to receive a PROBE packet
2293
2294 hdr_mac *mach = HDR_MAC(curr_PROBE_HN_pck_rx);
2296
2300
2307 Q_probbed_mac_HN.push(
2308 mach->macSA()); // store the MAC address of the NODE that
2309 // has sent the PROBE packet to the HN
2311 probeh->n_DATA_pcks_Node_tx()); // store the number of packets that
2312 // the NODE want to tx at
2313 // the HN
2314 Q_probbed_backoff_time.push((double) probeh->backoff_time_PROBE() /
2315 1000); // store the back-off time choice by the NODE before
2316 // to transmit the PROBE packet
2317
2318 if (debugMio_)
2319 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2320 << ")::PROBE_rx()____________________________PROBE_"
2321 "pck_rx_number:_"
2322 << getProbePckRx_HN() << "." << std::endl;
2323 if (debugMio_)
2324 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2325 << ")::PROBE_rx()____________________________"
2326 "PARAMETERS_OF_PROBE_PCK."
2327 << std::endl;
2328 if (debugMio_)
2330 << NOW << "uwUFetch_HEAD_NODE(" << addr
2331 << ")::PROBE_rx()____________________________Source_address:_"
2332 << mach->macSA() << std::endl;
2333 if (debugMio_)
2334 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2335 << ")::PROBE_rx()____________________________"
2336 "Destination_address:_"
2337 << mach->macDA() << std::endl;
2338 if (debugMio_)
2339 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2340 << ")::PROBE_rx()____________________________DATA_pck_"
2341 "would_be_tx_SN:_"
2342 << probeh->n_DATA_pcks_Node_tx() << "[pck]."
2343 << std::endl;
2344 if (debugMio_)
2345 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2346 << ")::PROBE_rx()____________________________Backoff_"
2347 "time_choice_before_tx_PROBE:_"
2348 << (double) probeh->backoff_time_PROBE() / 1000
2349 << "[s]." << std::endl;
2350
2351 Packet::free(curr_PROBE_HN_pck_rx);
2352
2353 if (Q_probbed_mac_HN.size() == MAX_POLLED_NODE) {
2354 // MAXIMUM number of PROBE packet is received by the HN
2355
2356 if (debug_)
2357 std::cout << NOW << " uwUFetch_NODE (" << addr
2358 << ") ::PROBE_Rx() ---->HN has received the maximum "
2359 "number of PROBE"
2360 << " packets and the timeout is not expired. Consequence "
2361 "of that, the HN with MAC address: "
2362 << addr << " can"
2363 << " not receive other PROBEs packets." << std::endl;
2364
2365 if (debug_)
2366 std::cout << NOW << " uwUFetch_NODE (" << addr
2367 << ") ::PROBE_Rx() ---->HN reset the PROBE timer"
2368 << " and start the transmission of POLL packets."
2369 << std::endl;
2370
2371 if (debugMio_)
2372 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2373 << ")::PROBE_rx()____________________________MAX_"
2374 "number_of_PROBE_pck_rx:_reset_PROBE_timeout."
2375 << std::endl;
2376
2377 PROBE_timer.force_cancel();
2378
2379 rxPROBEEnabled = false;
2380
2383
2384 state_POLL_tx();
2385
2386 } else {
2387 // Timeout is not expire and thus wait other PROBE packets
2388 if (debug_)
2389 std::cout << NOW << " uwUFetch_NODE (" << addr
2390 << ") ::PROBE_Rx() ---->Timeout is not expired and "
2391 "another PROBE"
2392 << " packet can be received by the HN with MAC address: "
2393 << addr << " from other NODEs." << std::endl;
2395 }
2396} // end PROBE_rx();
2397
2398void
2400{
2401
2402 if (debug_)
2403 std::cout << NOW << " uwUFetch_NODE (" << addr
2404 << ") ::state_wait_other_PROBE() ---->HN is waiting the "
2405 "reception of"
2406 << " PROBE packet number: " << (Q_probbed_mac_HN.size() + 1)
2407 << std::endl;
2408
2409 if (debugMio_)
2411 << NOW << "uwUFetch_HEAD_NODE(" << addr
2412 << ")::state_wait_other_PROBE()______________....Waiting_PROBE."
2413 << std::endl;
2414 if (debugMio_)
2416 << NOW << "uwUFetch_HEAD_NODE(" << addr
2417 << ")::state_wait_other_PROBE()______________....Waiting_PROBE."
2418 << std::endl;
2419 if (debugMio_)
2421 << NOW << "uwUFetch_HEAD_NODE(" << addr
2422 << ")::state_wait_other_PROBE()______________....Waiting_PROBE."
2423 << std::endl;
2424
2428
2429} // end state_wait_other_PROBE();
2430
2431void
2433{
2434
2435 if (debug_)
2436 std::cout
2437 << NOW << " uwUFetch_NODE (" << addr
2438 << ") ::state_POLL_tx() ---->HN is creating a POLL packet that"
2439 << " will then transmit at the first node of the queue that "
2440 "contain the PROBEs received. "
2441 << std::endl;
2442
2446
2447 Packet *p = Packet::alloc();
2448 hdr_cmn *cmh = hdr_cmn::access(p);
2449 hdr_mac *mach = HDR_MAC(p);
2450 hdr_POLL_UFETCH *pollh = HDR_POLL_UFETCH(p);
2451
2452 cmh->ptype() = PT_POLL_UFETCH;
2453 cmh->size() = sizeof(hdr_POLL_UFETCH);
2454
2455 mach->set(MF_CONTROL, addr, Q_probbed_mac_HN.front());
2456 mach->macSA() = addr;
2457 mach->macDA() = Q_probbed_mac_HN.front();
2458
2459 // Filling the HEADER of the POLL packet
2462 pollh->num_DATA_pcks_MAX_rx() =
2463 Q_probbed_n_pcks_NODE_want_tx_HN.front(); // Maximum number of
2464 // DATA packets that
2465 // the HN want to
2466 // receive from the NODE that is being to poll
2467 } else {
2468 pollh->num_DATA_pcks_MAX_rx() =
2469 MAX_PCK_HN_WANT_RX_FROM_NODE; // Maximum numbero of DATA packets
2470 // that the HN want to
2471 // receive from the NODE that is being to poll
2472 }
2474 pollh->mac_addr_Node_polled() =
2475 Q_probbed_mac_HN.front(); // Mac address of the NODE that the HN is
2476 // being to poll
2477 mac_addr_NODE_polled = Q_probbed_mac_HN.front(); // Store the mac address of
2478 // the NODE that the HN is
2479 // being
2480 // to poll
2481
2482 if (debugMio_)
2483 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2484 << ")::state_POLL_tx()_______________________"
2485 "PARAMETERS_OF_POLL_PCK:"
2486 << std::endl;
2487 if (debugMio_)
2489 << NOW << "uwUFetch_HEAD_NODE(" << addr
2490 << ")::state_POLL_tx()_______________________Source_address:_"
2491 << mach->macSA() << std::endl;
2492 if (debugMio_)
2493 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2494 << ")::state_POLL_tx()_______________________"
2495 "Destination_address:_"
2496 << mach->macDA() << std::endl;
2497 if (debugMio_)
2498 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2499 << ")::state_POLL_tx()_______________________DATA_pck_"
2500 "want_rx_from_SN:_"
2501 << number_data_pck_HN_rx_exact << "[pck]."
2502 << std::endl;
2503 if (debugMio_)
2505 << NOW << "uwUFetch_HEAD_NODE(" << addr
2506 << ")::state_POLL_tx()_______________________Size_of_POLL_pck:_"
2507 << cmh->size() << "[byte]." << std::endl;
2508
2509 curr_POLL_HN_pck_tx = p->copy();
2510
2511 Packet::free(p); // de-allocate the memory
2512
2513 txPOLLEnabled = true;
2514
2515 POLL_tx();
2516} // end state_POLL_tx();
2517
2518void
2520{
2521
2522 if (debug_)
2523 std::cout << NOW << " uwUFetch_NODE (" << addr
2524 << ") ::POLL_tx() ---->HN is transmitting a POLL packet to "
2525 "the NODE with MAC"
2526 << " address: " << mac_addr_NODE_polled << std::endl;
2527
2529 // that the protocol
2530 // state change
2531
2533
2535
2536} // end POLL_tx();
2537
2538void
2540{
2541
2542 if (debug_)
2543 std::cout << NOW << " uwUFetch_NODE (" << addr
2544 << ") ::state_wait_first_DATA() ---->HN is waiting to "
2545 "receive the FIRST DATA"
2546 << " packet from the NODE with MAC address: "
2547 << mac_addr_NODE_polled << std::endl;
2548
2552
2553 data_timeout = getDataTimerValue(); // Compute the timeout interval within
2554 // HN want to receive all DATA packets
2555 // from NODE
2556
2557 if (debug_)
2558 std::cout << NOW << " uwUFetch_NODE (" << addr
2559 << ") ::state_wait_first_DATA() ---->HN want to receive all "
2560 "the DATA packets"
2561 << " from the NODE with MAC address: " << mac_addr_NODE_polled
2562 << " within "
2563 << " an interval time: " << data_timeout << "[s]."
2564 << std::endl;
2565
2566 if (debugMio_)
2567 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2568 << ")::state_wait_first_DATA()_______________Timeout_"
2569 "within_rx_all_DATA"
2570 << "_pcks: " << data_timeout << "[s]." << std::endl;
2571
2572 if (debugMio_)
2573 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2574 << ")::state_wait_first_DATA()_______________......."
2575 "Waiting_DATA"
2576 << std::endl;
2577 if (debugMio_)
2578 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2579 << ")::state_wait_first_DATA()_______________......."
2580 "Waiting_DATA"
2581 << std::endl;
2582 if (debugMio_)
2583 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2584 << ")::state_wait_first_DATA()_______________......."
2585 "Waiting_DATA"
2586 << std::endl;
2587
2588 rxDATAEnabled = true;
2589
2591} // end state_wait_first_DATA();
2592
2593void
2595{
2596
2597 if (debug_)
2598 std::cout << NOW << " uwUFetch_NODE (" << addr
2599 << ") ::state_wait_other_DATA() ---->HN is waiting the DATA "
2600 "packet number: "
2601 << (getDataPckRx_by_HN() + 1)
2602 << " from the NODE with MAC address: " << mac_addr_NODE_polled
2603 << std::endl;
2604
2605 if (debugMio_)
2606 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2607 << ")::state_wait_other_DATA()_______________......."
2608 "Waiting_DATA"
2609 << std::endl;
2610 if (debugMio_)
2611 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2612 << ")::state_wait_other_DATA()_______________......."
2613 "Waiting_DATA"
2614 << std::endl;
2615 if (debugMio_)
2616 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2617 << ")::state_wait_other_DATA()_______________......."
2618 "Waiting_DATA"
2619 << std::endl;
2620
2624
2625 txBEACONEnabled = false;
2626 rxPROBEEnabled = false;
2627 txPOLLEnabled = false;
2628 rxDATAEnabled = true;
2629 txCBEACONEnabled = false;
2630 rxTRIGGEREnabled = false;
2631 txRTSEnabled = false;
2632 rxCTSEnabled = false;
2633 txDATAEnabledHN = false;
2634
2635} // end state_wait_other_DATA();
2636
2637void
2639{
2640
2641 if (debug_)
2642 std::cout << NOW << " uwUFetch_NODE (" << addr
2643 << ") ::DataTOExpired() ---->HN has received from the NODE "
2644 "with MAC"
2645 << " address: " << mac_addr_NODE_polled << " only "
2646 << getDataPckRx_by_HN() << " packets." << std::endl;
2647
2648 if (debugMio_)
2649 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2650 << ")::DataTOExpired()_______________________DATA_"
2651 "timeout_expired."
2652 << std::endl;
2653
2655 // reason for
2656 // the changing
2657 // of the state
2658
2659 rxDATAEnabled = false;
2660 updateListProbbedNode(); // Remove the NODE that has already transmit his
2661 // data packet
2662
2663 // Verify if another node can be polled, or the HN will start the
2664 // transmission of CBEACON
2665 if ((Q_probbed_mac_HN.empty()) &&
2667 // There aren't another node to poll, and the maximum number of CBEACONS
2668 // are transmitted
2669 if (debug_)
2670 std::cout << NOW << " uwUFetch_NODE (" << addr
2671 << ") ::DataTOExpired() ---->HN has not other nodes to "
2672 "POLL, and"
2673 << " a CBEACON packet can not be transmitted: return in "
2674 "IDLE STATE."
2675 << std::endl;
2676
2677 if (debugMio_)
2678 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2679 << ")::DataTOExpired()_______________________0_SN_"
2680 "to_polled_and_MAX_number_CBEACON_tx."
2681 << std::endl;
2682
2688
2689 txBEACONEnabled = true;
2690 rxPROBEEnabled = false;
2691 txPOLLEnabled = false;
2692 rxDATAEnabled = false;
2693 txCBEACONEnabled = false;
2694 rxTRIGGEREnabled = true;
2695 txRTSEnabled = false;
2696 rxCTSEnabled = false;
2697 txDATAEnabledHN = false;
2698
2701
2702 stateIdle_HN();
2703
2704 } else if ((Q_probbed_mac_HN.empty()) &&
2706 // There aren't another node to poll, and the maximum number of CBEACONS
2707 // are not transmitted
2708 if (debug_)
2709 std::cout << NOW << " uwUFetch_NODE (" << addr
2710 << ") ::DataTOExpired() ---->HN has not other nodes to "
2711 "POLL, but"
2712 << " a CBEACON packet can be transmitted: transmit a "
2713 "CBEACON"
2714 << std::endl;
2715
2716 if (debugMio_)
2717 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2718 << ")::DataTOExpired()_______________________0_SN_"
2719 "to_polled_and_another_CBEACON_can_be_tx."
2720 << std::endl;
2721
2725
2726 txBEACONEnabled = false;
2727 rxPROBEEnabled = false;
2728 txPOLLEnabled = false;
2729 rxDATAEnabled = false;
2730 txCBEACONEnabled = false;
2731 rxTRIGGEREnabled = false;
2732 txRTSEnabled = false;
2733 rxCTSEnabled = false;
2734 txDATAEnabledHN = false;
2735
2738
2740
2741 } else {
2742 // There are another nodes to poll
2743 if (debug_)
2744 std::cout
2745 << NOW << " uwUFetch_NODE (" << addr
2746 << ") ::DataTOExpired() ---->HN has other nodes to polled."
2747 << std::endl;
2748
2749 if (debugMio_)
2750 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2751 << ")::DataTOExpired()_______________________"
2752 "Another_SN_can_be_polled."
2753 << std::endl;
2754
2757
2758 txBEACONEnabled = false;
2759 rxPROBEEnabled = false;
2760 txPOLLEnabled = false;
2761 rxDATAEnabled = false;
2762 txCBEACONEnabled = false;
2763 rxTRIGGEREnabled = false;
2764 txRTSEnabled = false;
2765 rxCTSEnabled = false;
2766 txDATAEnabledHN = false;
2767
2770
2771 state_POLL_tx();
2772 }
2773} // end DataTOExpired();
2774
2775void
2777{
2778
2779 if (rxDATAEnabled) {
2780
2781 hdr_mac *mach = HDR_MAC(curr_DATA_HN_pck_rx);
2782
2786
2793 mac_addr_NODE_in_data = mach->macSA(); // Source MAC address of the NODE
2794 // that has transmitted the DATA
2795 // packet to the HN
2796
2798
2799 if (debugMio_)
2800 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2801 << ")::DATA_rx()_____________________________DATA_"
2802 "pck_rx_by_HN("
2803 << addr << ")_from_SN(" << mac_addr_NODE_in_data
2804 << ")_id_pck:" << cbrh->sn() << ""
2805 << "_It_s_CORRECT." << std::endl;
2806
2807 if (debug_)
2808 std::cout << NOW << " uwUFetch_NODE (" << addr
2809 << ") ::DATA_Rx() ---->HN has received the DATA packet"
2810 << " number: " << getDataPckRx_by_HN()
2811 << " from the NODE with"
2812 << " MAC address: " << mac_addr_NODE_in_data << "."
2813 << std::endl;
2814
2815 // save the data packet in the QUEUE of the HN
2816 Q_data_HN.push(curr_DATA_HN_pck_rx->copy()); // Save the data packets in
2817 // the QUEUE of the HN
2818 Q_data_source_SN.push(mac_addr_NODE_in_data); // Save the MAC address
2819 // from which the data
2820 // packet it's arrived.
2821
2822 Packet::free(curr_DATA_HN_pck_rx);
2823
2825 // Another DATA packet can not be received by the HN
2826 if (debug_)
2827 std::cout << NOW << " uwUFetch_NODE (" << addr
2828 << ") ::DATA_rx() ---->HN has received the LAST DATA "
2829 "packet from NODE"
2830 << " with MAC address: " << mac_addr_NODE_in_data
2831 << std::endl;
2832
2833 if (debugMio_)
2834 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2835 << ")::DATA_rx()_____________________________"
2836 "All_DATA_pcks"
2837 << "_were_rx_from_SN(" << mac_addr_NODE_in_data
2838 << ")." << std::endl;
2839
2841
2842 if (debug_)
2843 std::cout << NOW << " uwUFetch_NODE (" << addr
2844 << ") ::DATA_rx() ---->HN reset DATA timer"
2845 << std::endl;
2846 if (debugMio_)
2847 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2848 << ")::DATA_rx()_____________________________"
2849 "Reset_DATA_Timeout."
2850 << std::endl;
2851 DATA_timer.force_cancel(); // reset the timer
2852
2853 updateListProbbedNode(); // Remove the NODE that has already
2854 // transmit his data packet
2855
2856 // Verify if another node can be polled, or the HN will start the
2857 // transmission of CBEACON
2858 if ((Q_probbed_mac_HN.empty()) &&
2860 // There aren't another node to poll, and the maximum number of
2861 // CBEACONS are transmitted
2862 if (debug_)
2863 std::cout << NOW << " uwUFetch_NODE (" << addr
2864 << ") ::DATA_rx() ---->HN has not other nodes to "
2865 "POLL, and"
2866 << " a CBEACON packet can not be transmitted: "
2867 "return in IDLE STATE."
2868 << std::endl;
2869
2870 if (debugMio_)
2872 << NOW << "uwUFetch_HEAD_NODE(" << addr
2873 << ")::DATA_rx()_____________________________0_SNs_"
2874 "to_polled_and_MAX_CBEACON_is_tx."
2875 << std::endl;
2876
2882
2883 txBEACONEnabled = true;
2884 rxDATAEnabled = false;
2885 rxTRIGGEREnabled = true;
2886
2889
2890 stateIdle_HN();
2891
2892 } else if ((Q_probbed_mac_HN.empty()) &&
2894 // There aren't another node to poll, and the maximum number of
2895 // CBEACONS are not transmitted
2896 if (debug_)
2897 std::cout << NOW << " uwUFetch_NODE (" << addr
2898 << ") ::DATA_rx() ---->HN has not other nodes to "
2899 "POLL, but"
2900 << " a CBEACON packet can be transmitted: "
2901 "transmit a CBEACON"
2902 << std::endl;
2903
2904 if (debugMio_)
2906 << NOW << "uwUFetch_HEAD_NODE(" << addr
2907 << ")::DATA_rx()_____________________________0_SNs_"
2908 "to_polled_and_another_CBEACON_can_be_tx."
2909 << std::endl;
2910
2914
2915 rxDATAEnabled = false;
2916 txCBEACONEnabled = true;
2917
2920
2922
2923 } else {
2924 // There are another nodes to poll
2925 if (debug_)
2926 std::cout << NOW << " uwUFetch_NODE (" << addr
2927 << ") ::DATA_rx() ---->HN has other nodes to "
2928 "polled."
2929 << std::endl;
2930
2931 if (debugMio_)
2932 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2933 << ")::DATA_rx()__________________________"
2934 "___Another_SNs_can_be_polled."
2935 << std::endl;
2936
2938
2939 rxDATAEnabled = false;
2940 txPOLLEnabled = true;
2941
2944
2945 state_POLL_tx();
2946 }
2947
2948 } else {
2949 // Another DATA packet can be received by the HN
2950
2951 if (debug_)
2952 std::cout
2953 << NOW << " uwUFetch_NODE (" << addr
2954 << ") ::DATA_rx() ---->HN wait an another DATA packet,"
2955 << " the number: " << (getDataPckRx_by_HN() + 1)
2956 << ", from NODE with MAC "
2957 << " address: " << mac_addr_NODE_in_data << std::endl;
2958
2959 rxDATAEnabled = true;
2961 }
2962 } else {
2963 // HN is not enabled to receive a DATA packet
2964 if (debugMio_)
2965 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2966 << ")::DATA_rx()_____________________________Not_"
2967 "enabled_to_rx_DATA_pcks."
2968 << std::endl;
2969
2970 if (debug_)
2971 std::cout << NOW << " uwUFetch_NODE (" << addr
2972 << ") DATA_rx() ---->HN(" << addr
2973 << ") is not enabled to receive the DATA"
2974 << " packet: DROP IT." << std::endl;
2975
2977 }
2978} // end DATA_rx();
2979
2980void
2982{
2983
2984 while (!Q_probbed_mac_HN.empty()) {
2985 Q_probbed_mac_HN.pop();
2988 }
2989 // HN transmit a CBEACON packet to the sensor nodes
2990 if (debug_)
2991 std::cout << NOW << " uwUFetch_NODE (" << addr
2992 << ") ::state_CBEACON_tx() ---->HN is initializing the "
2993 "CBEACON packet"
2994 << " which will then transmit to the NODEs in broadcast. "
2995 << std::endl;
2996
2997 if (debugMio_)
2998 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2999 << ")::state_CBEACON_tx()____________________"
3000 "Initializing_CBEACON_pck_number_"
3001 << getCBeaconPckTx_by_HN() + 1 << std::endl;
3002
3003 txRTSbeforeCBEACON == false;
3007
3008 Packet *p = Packet::alloc(); // allocate the memory
3009 hdr_cmn *cmh = hdr_cmn::access(p);
3010 hdr_mac *mach = HDR_MAC(p);
3012
3013 cmh->ptype() = PT_CBEACON_UFETCH; // type of the packet
3014
3015 mach->set(MF_CONTROL, addr, MAC_BROADCAST); // set the information of the
3016 // packet (type,source
3017 // address,destination address)
3018 mach->macSA() = addr; // set the source address as AUV MAC address
3019 mach->macDA() =
3020 MAC_BROADCAST; // set the destination address as BROADCAST address
3021
3022 cbeaconh->t_min_bc() =
3023 (int) (T_MIN_BACKOFF_PROBE * 1000); // minimum value for to choose
3024 // the back-off time for tx
3025 // PROBE pck
3026 cbeaconh->t_max_bc() =
3027 (int) (T_MAX_BACKOFF_PROBE * 1000); // maximum value for to choose
3028 // the back-off time for tx
3029 // PROBE pck
3030
3031 cmh->size() =
3032 sizeof(hdr_CBEACON_UFETCH); // set the size of CBEACON header packet
3033 curr_CBEACON_HN_pck_tx = p->copy(); // create a copy of the CBEACON packet
3034
3035 if (debugMio_)
3036 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3037 << ")::state_CBEACON_tx()____________________"
3038 "PARAMETERS_of_CBEACON_pck."
3039 << std::endl;
3040 if (debugMio_)
3042 << NOW << "uwUFetch_HEAD_NODE(" << addr
3043 << ")::state_CBEACON_tx()____________________Source_address:_"
3044 << mach->macSA() << "." << std::endl;
3045 if (mach->macDA() == -1) {
3046 if (debugMio_)
3047 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3048 << ")::state_CBEACON_tx()____________________"
3049 "Destination_address:_BROADCAST."
3050 << std::endl;
3051 } else {
3052 if (debugMio_)
3053 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3054 << ")::state_CBEACON_tx()____________________"
3055 "Destination_address:_"
3056 << mach->macDA() << "." << std::endl;
3057 }
3058 if (debugMio_)
3059 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3060 << ")::state_CBEACON_tx()____________________MIN_"
3061 "backoff_time_PROBE_pck:_"
3062 << T_MIN_BACKOFF_PROBE << "[s]." << std::endl;
3063 if (debugMio_)
3064 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3065 << ")::state_CBEACON_tx()____________________MAX_"
3066 "backoff_time_PROBE_pck:_"
3067 << T_MAX_BACKOFF_PROBE << "[s]." << std::endl;
3068 if (debugMio_)
3069 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3070 << ")::state_CBEACON_tx()____________________Size_of_"
3071 "CBEACON_pck:_"
3072 << cmh->size() << "[byte]." << std::endl;
3073
3074 Packet::free(p); // de-allocate the memory
3075
3076 txCBEACONEnabled = true; // Indicates if or not the HN is enabled to
3077 // transmit a CBEACON packet to the NODE
3078
3079 CBEACON_tx(); // recall the function that simulate the transmission of the
3080 // CBEACON
3081
3082} // end state_CBEACON_tx();
3083
3084void
3086{
3087
3088 if (debug_)
3089 std::cout << NOW << " uwUFetch_NODE (" << addr
3090 << ") ::CBEACON_tx() ---->HN is transmitting a CBEACON packet"
3091 << " to the NODEs in broadcast." << std::endl;
3092
3094 // that the protocol
3095 // state change
3096
3098
3099} // end CBEACON_tx();
3100
3101/*******************************************************************************
3102 * METODI AUSILIARI *
3103 ******************************************************************************/
3104bool
3106{
3107 if (MODE_COMM_HN_AUV == 1) {
3108 return true;
3109 } else {
3110 return false;
3111 }
3112} // end typeCommunication();
3113
3114bool
3116{
3117 if (MODE_BURST_DATA == 1) {
3118 return true;
3119 } else {
3120 return false;
3121 }
3122} // end burstDATA()
3123
3124double
3126{
3127 if (typeCommunication()) {
3128 // Communication between HN & AUV without RTS and CTS packets
3129 // RNG::defaultrng()->set_seed(addr*5);
3130 if (debug_)
3131 std::cout << NOW << " uwUFetch_NODE (" << addr
3132 << ") choiceBackOffTimer() ---->HN is choosing the "
3133 "back-off timer."
3134 << std::endl;
3135 int random = (int) RNG::defaultrng()->uniform(T_min_bck_DATA, T_max_bck_DATA);
3136
3137 if (debug_)
3138 std::cout << NOW << " uwUFetch_NODE(" << addr
3139 << ") ::choiceBackOffTimer() ---->Back-off time choice "
3140 "by the HN is = "
3141 << 0.833 * random << "[s]." << std::endl;
3142 return (0.833 * random);
3143 } else {
3144 // Communication between HN & AUV with RTS and CTS packets
3145 // RNG::defaultrng()->set_seed(addr*5);
3146 if (debug_)
3147 std::cout << NOW << " uwUFetch_NODE (" << addr
3148 << ") choiceBackOffTimer() ---->HN is choosing the "
3149 "back-off timer."
3150 << std::endl;
3151 int random = (int) RNG::defaultrng()->uniform(T_min_bck_RTS, T_max_bck_RTS);
3152
3153 if (debug_)
3154 std::cout << NOW << " uwUFetch_NODE(" << addr
3155 << ") ::choiceBackOffTimer() ---->Back-off time choice "
3156 "by the HN is = "
3157 << 0.833 * random << "[s]." << std::endl;
3158 return (0.833 * random);
3159 }
3160} // end choiceBackoffTimer_HN();
3161
3162double
3164{
3165
3166 if (debug_)
3167 std::cout
3168 << NOW << " uwUFetch_NODE (" << addr
3169 << ") ::getDataTimerValue() ---->HN is computing DATA timeout."
3170 << std::endl;
3171
3173 RTT = getRTT();
3174
3175 int pck_tx_number = 0;
3178 pck_tx_number = Q_probbed_n_pcks_NODE_want_tx_HN.front();
3179 } else {
3180 pck_tx_number = MAX_PCK_HN_WANT_RX_FROM_NODE;
3181 }
3182
3183 double data_timeout_val = 0;
3184 data_timeout_val = number_data_pck_HN_rx_exact * (Tdata_HN + T_GUARD + RTT);
3185
3186 return data_timeout_val;
3187
3188} // end getDataTimerValue();
3189
3190void
3192{
3193 hdr_uwcbr *cbrh = HDR_UWCBR(p);
3194
3195 if ((int) Q_data.size() < MAXIMUM_BUFFER_DATA_PCK_NODE) {
3196 if (debug_)
3197 std::cout << NOW << " uwUFetch_NODE (" << addr
3198 << ") ::recvFromUpperLayers() ---->HN is queuing a DATA "
3199 "packet"
3200 << " generated by the APPLICATION layer" << std::endl;
3201 Q_data.push(p);
3202 if (debugMio_)
3203 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3204 << ")::recvFromUpperLayer()__________________DATA_"
3205 "pck_from_upper_layer:id_pck_"
3206 << cbrh->sn() << "_STORE_It." << std::endl;
3207 } else {
3208 if (debug_)
3209 std::cout << NOW << " uwUFetch_NODE (" << addr
3210 << ") ::recvFromUpperLayers()--->HN dropped DATA packet "
3211 "because"
3212 << " its buffer is full" << std::endl;
3213 if (debugMio_)
3214 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3215 << ")::recvFromUpperLayer()__________________DATA_"
3216 "pck_from_upper_layer:id_pck_"
3217 << cbrh->sn() << "_BUFFER_FULL:_drop_It."
3218 << std::endl;
3220 }
3221} // end recvFromUpperLayers_HN();
3222
3223void
3224uwUFetch_NODE::computeTxTime_HN(UWUFETCH_NODE_PACKET_TYPE tp)
3225{
3226 Packet *simple_pck = Packet::alloc();
3227
3229 hdr_cmn *cmh = HDR_CMN(simple_pck);
3230 cmh->size() = sizeof(hdr_POLL_UFETCH);
3231 hdr_mac *mach = HDR_MAC(simple_pck);
3232
3233 mach->macSA() = addr;
3234 mach->macDA() = mac_addr_NODE_polled;
3235 Tpoll = Mac2PhyTxDuration(simple_pck);
3236
3237 } else {
3238 hdr_cmn *cmh = HDR_CMN(simple_pck);
3239 hdr_mac *mach = HDR_MAC(simple_pck);
3240 cmh->size() = MAX_PAYLOAD;
3241
3242 mach->macSA() = addr;
3243 mach->macDA() = mac_addr_AUV_in_trigger;
3244 Tdata_HN = Mac2PhyTxDuration(simple_pck);
3245 }
3246
3247 Packet::free(simple_pck);
3248} // end computeTxTime_HN();
3249
3250double
3252{
3253 RTT = 0;
3254
3257 tx_BEACON_start_HN_time; //- bck_value_probe_tx - Tprobe;
3258 } else {
3260 tx_CBEACON_start_HN_time; // - bck_value_probe_tx - Tprobe;
3261 }
3262 return RTT;
3263} // end getRTT();
3264
3265void
3267{
3268
3269 if (debug_)
3270 std::cout << NOW << " uwUFetch_NODE (" << addr
3271 << ") ::updateListProbbedNode() ---->HN has finished to "
3272 "receive DATA packet from the NODE with"
3273 << " MAC address: " << mac_addr_NODE_polled
3274 << ", so remove the NODE from the list." << std::endl;
3275
3276 Q_probbed_mac_HN.pop();
3279
3280} // end updateListProbbedNode();
3281
3282/*******************************************************************************
3283 * EXPIRE METHODS *
3284 ******************************************************************************/
3285void
3287{
3288 if ((module->debug_))
3289 std::cout << NOW << " uwUFetch_NODE (" << module->addr
3290 << ") ::uwUFetch_BEACON_timer::expire() ---->BEACON timeout "
3291 "expired"
3292 << std::endl;
3294
3295 module->BeaconTxTOExpire();
3296} // end uwUFetch_BEACON_timer::expire();
3297
3298void
3300{
3301 if ((module->debug_))
3302 std::cout << NOW << " uwUFetch_NODE (" << module->addr
3303 << ")::uwUFetch_PROBE_timer::expire() ---->PROBE timeout "
3304 "expired"
3305 << std::endl;
3306 timer_status = UWUFETCH_TIMER_STATUS_EXPIRED;
3307
3308 module->ProbeTOExpired();
3309} // end uwUFetch_PROBE_timer::expire();
3310
3311void
3313{
3314 if ((module->debug_))
3315 std::cout
3316 << NOW << " uwUFetch_NODE (" << module->addr
3317 << ") ::uwUFetch_DATA_timer::expire() ---->DATA timeout expired"
3318 << std::endl;
3319 timer_status = UWUFETCH_TIMER_STATUS_EXPIRED;
3320
3321 module->DataTOExpired();
3322} // end uwUFetch_DATA_timer::expire();
3323
3324void
3326{
3327 if ((module->debug_))
3328 std::cout << NOW << " uwUFetch_NODE (" << module->addr
3329 << ")::uwUFetch_CTS_timer::expire() ---->CTS timeout expired"
3330 << std::endl;
3331 timer_status = UWUFETCH_TIMER_STATUS_EXPIRED;
3332
3333 module->CtsTOExpired();
3334} // end uwUFetch_CTS_timer::expire();
virtual void expire(Event *e)
Method called when the timer expire.
virtual void expire(Event *e)
Method called when the timer expire.
virtual void expire(Event *e)
Method called when the timer expire.
uwUFetch_NODE *UWUFETCH_TIMER_STATUS timer_status
< Pointer to an object of type uwUFetch_NODE
virtual void schedule(double val)
schedule a timer
virtual void expire(Event *e)
Method called when the timer expire.
std::queue< double > Q_probbed_backoff_time
Queue that stored the backoff time choice by the single nodes before to transmit the PROBE packet to ...
double data_timeout
Interval time in which the HN want to receive all DATA packets from the node that have polled.
double tx_POLL_finish_HN_time
Indicates when HN finished the transmission of POLL packet to a specific SN.
void incrTotalDataPckRx_by_HN()
Increase total number of DATA packets correctly or not received by the HN during an entire simulation...
virtual void state_BEACON_tx()
HN initialize the BEACON packet that will be forwarded in broadcast at all SNs of the network.
UWUFETCH_NODE_STATUS_CHANGE last_reason
Last reason because the SN or HN change its state.
virtual void state_DATA_HN_finish_tx()
HN has finished to transmit the sequence of DATA packets promises to the AUV with the exchange of pre...
double T_max_bck_DATA
Upper bound time interval from which the HN choice its backoff timer before to transmit a DATA packet...
double T_MIN_BACKOFF_PROBE
Lower bound timer interval of back-off value used by the SN to choice its back-off time before to tra...
int n_BEACON_pck_tx_by_HN
Number of BEACON packet transmitted by the HN during a single cycle BEACON-PROBE-POLL-DATA-CBEACON of...
double bck_before_tx_RTS
Time value choice by the HN and used for transmit a RTS packet to the AUV.
virtual void state_DATA_HN_first_tx_without()
HN initialize the FIRST DATA packet that will be forwarded to the AUV node.
virtual void DataBeforeTxTOExpired_HN()
Backoff timeout is expired.
bool CTSrx
true HN has received a CTS packet after the transmission of RTS
virtual void CBEACON_tx()
HN transmit the BEACON packet.
virtual bool burstDATA()
Indicate whether the transmission of DATA packets to the AUV take place with or without burst data.
double T_GUARD
Guard interval used for successive transmission of DATA packets.
virtual void state_DATA_HN_finish_tx_without()
HN has finished to transmit the sequence of DATA packets to the AUV.
virtual void Phy2MacEndTx_HN(const Packet *p)
Handle the end-of-PHY-transmission event for HEAD NODE.
Packet * curr_RTS_HN_pck_tx
Pointer to the RTS packet that is being transmitted by HN.
int MAX_POLLED_NODE
Maximum number of PROBE packets that the HN can receive from the SN after the transmission of a BEACO...
virtual void Phy2MacStartRx_HN(const Packet *p)
Handle the detected-start-of-PHY-reception event for HEAD NODE.
bool txDATAEnabledHN
true if HN is enabled to transmit a DATA packet to the AUV
virtual double choiceBackOffTimer_HN()
Choose the backoff timeout used by HN before to transmit a RTS packet.
int getDataPckRx_by_HN()
Number of DATA packets transmitted by the HN during a single cycle BEACON-PROBE-POLL-DATA-CBEACON of ...
void incrProbePckRx_HN()
Increase number of PROBE packets received by the HN during a single cycle BEACON-PROBE-POLL-DATA-CBEA...
virtual void stateIdle_HN()
Idle state for HN.
double tx_DATA_finish_HN_time
Indicates when HN finished the transmission of DATA packet to the AUV.
double T_PROBE
Interval time in which HN is enabled to received PROBE packets from SNs after the transmission of TRI...
@ UWUFETCH_TIMER_STATUS_EXPIRED
virtual void BeaconTxTOExpire()
BEACON timeout is expired.
virtual void state_wait_CTS()
HN start to wait a CTS packet for a pre-established time interval.
double tx_CBEACON_start_HN_time
Indicates when HN started the transmission of CBEACON packet to the SNs.
double tx_POLL_start_HN_time
Indicates when HN started the transmission of POLL packet to a specific SN.
bool rxCTSEnabled
true if HN is enabled to receive a CTS packet from the AUV
Packet * curr_CBEACON_HN_pck_tx
Pointer to the CBEACON packet that is being transmitted by HN.
virtual void state_DATA_HN_first_tx()
HN initialize the FIRST DATA packet that will be forwarded to the AUV node.
virtual void DATA_rx()
HN has received a BEACON packet from SN.
virtual void BCKTOExpired_HN()
Backoff timeout is expired.
virtual void computeTxTime_HN(UWUFETCH_NODE_PACKET_TYPE tp)
Compute the transmission time for the packets transmitted by the HNs.
virtual void printStateInfo(double delay=0)
Prints a file with every state change for debug purposes.
virtual void ProbeTOExpired()
Probe timeout is expired.
std::ofstream out_file_logging
Variable that handle the file in which the protocol write the statistics.
virtual void Phy2MacEndRx_HN(Packet *p)
Handle the end-of-PHY-reception event for HEAD NODE.
double tx_RTS_finish_HN_time
Indicates when HN finished the transmission of RTS packet to the AUV.
virtual void Phy2MacEndRx_HN_without(Packet *p)
Handle the end-of-PHY-reception event for HEAD NODE in the case that the communication don't use RTS-...
double rx_TRIGGER_start_HN_time
Indicates when HN started the reception of TRIGGER packet from the AUV.
int n_CBEACON_pck_tx_by_HN
Number of CBEACON packet transmitted by the HN during a single cycle BEACON-PROBE-POLL-DATA-CBEACON o...
virtual void state_wait_other_PROBE()
HN start to wait the second or successive PROBE packet from some SNs.
virtual void BCKTOExpired_HN_without()
Backoff timeout is expired.
double TIME_BETWEEN_2_TX_DATA_HN_AUV
Interval time used by HN before to transmit the next DATA packet to the AUV.
virtual void updateListProbbedNode()
Update the list of the SN from which HN has received the PROBE packets.
virtual void DATA_HN_tx_without()
HN transmit a DATA packet to the AUV.
double rx_DATA_finish_HN_time
Indicates when HN finished the reception of DATA packet from the SNs.
double T_max_bck_RTS
Upper bound interval time from which the HN choice his backoff timer before to transmit a RTS packet ...
void incrPollPckTx_by_HN()
Increase the number of POLL packets transmitted by the HN during a single cycle BEACON-PROBE-POLL-DAT...
double T_min_bck_RTS
Lower bound interval time from which the HN choice its backoff timer before to transmit a RTS packet ...
void incrTotalTriggerPckRx_HN()
Increase the total number of TRIGGER packets correctly or not received by the HN during an entire sim...
int debugMio_
Used if we want to create the logging file.
void incrTotalDataPckRx_corrupted_by_HN()
Increase total number of corrupted DATA packets received by the HN during an entire simulation.
virtual void Mac2PhyStartTx_HN(Packet *p)
This method must be called by the HN-MAC to instruct the PHY to start the transmission of a packet.
bool txRTSEnabled
true if HN is enabled to transmit a RTS packet to the AUV
virtual double getDataTimerValue()
Compute the interval time within HN want to receive all DATA packets from a specific SN.
void incrBeaconPckTx_by_HN()
Increase the number of BEACON packet transmitted by the HN during a single cycle BEACON-PROBE-POLL-DA...
bool sectionCBeacon
true HN has started the transmission of RTS packet when It was in the CBEACON section.
int number_data_pck_HN_rx_exact
Exact number of DATA packets that the HN want to receive from the SN that have polled.
virtual void refreshReason(UWUFETCH_NODE_STATUS_CHANGE reason)
Refresh the reason for the changing of the state.
Packet * curr_TRIGGER_HN_pck_rx
Pointer to the TRIGGER packet that is being received by HN.
int MODE_COMM_HN_AUV
Indicate the type of communication between HN and AUV, 0 = communication with RTS-CTS,...
double rx_PROBE_start_HN_time
Indicates when HN started the reception of PROBE packet from the SNs.
bool txBEACONEnabled
true if HN is enabled to transmit a BEACON packet to the SN
int mac_addr_AUV_in_trigger
AUV-MAC address contained in the TRIGGER packet received by the HN.
Packet * curr_BEACON_HN_pck_tx
Pointer to the BEACON packet that is being transmitted by HN.
void incrDataPckTx_by_HN()
Increase the number of DATA packets transmitted by the HN during a single cycle TRIGGER-RTS-CTS-DATA ...
bool rxPROBEEnabled
true if HN is enabled to receive a PROBE packet from the SN
std::queue< Packet * > Q_data_HN
Queue of DATA packets stored by the HNs and received from SN.
virtual void state_DATA_HN_tx()
HN initialize the second and successive DATA packets that will be forwarded to the AUV node.
virtual void BEACON_tx()
HN transmit the BEACON packet.
Packet * curr_DATA_NODE_pck_tx_HN
Pointer to the DATA packet that is being transmitted by HN.
int MAXIMUM_BUFFER_DATA_PCK_NODE
Maximum number of DATA packets that the SN can store in Its queue.
double T_MAX_BACKOFF_PROBE
Upper bound timer interval of back-off value used by the SN to choice its back-off time before to tra...
void incrTotalPollPckTx_by_HN()
Increase the total number of POLL packets transmitted by the HN during an entire simulation.
double tx_BEACON_start_HN_time
Indicates when HN started the transmission of BEACON packet to the SNs.
double rx_CTS_start_HN_time
Indicates when HN started the reception of CTS packet from the AUV.
void incrDataPckRx_by_HN()
Increase the number of DATA packets transmitted by the HN during a single cycle BEACON-PROBE-POLL-DAT...
bool txPOLLEnabled
true if HN is enabled to transmit a POLL packet to the SN
virtual void state_wait_PROBE()
HN start to wait the FIRST PROBE packet from some SNs.
int pck_number_id
Unique identifier of the DATA packet received.
virtual void Mac2PhyStartTx(Packet *p)
This method must be called by the SN-MAC to instruct the PHY to start the transmission of a packet.
std::queue< int > Q_probbed_mac_HN
Queue that store the MAC address of the SN from which the HN has received correctly the PROBE packets...
bool rxTRIGGEREnabled
true if HN is enabled to receive a TRIGGER packet from the AUV
void incrTotalBeaconPckTx_by_HN()
Increase the total number of BEACON packets transmitted by the HN during an entire simulation.
double rx_DATA_start_HN_time
Indicates when HN started the reception of DATA packet from the SNs.
virtual void state_DATA_HN_tx_without()
HN initialize the second and successive DATA packets that will be forwarded to the AUV node.
double tx_RTS_start_HN_time
Indicates when HN started the transmission of RTS packet to the AUV.
virtual double getRTT()
Compute the round trip time.
virtual void state_wait_first_DATA()
HN start to wait the FIRST DATA packet from SN.
void incrTotalTriggerPckRx_corrupted_HN()
Increase the total number of corrupted TRIGGER packets received by the HN during an entire simulation...
void incrRtsPckTx_by_HN()
Increase the number of RTS packets transmitted by the HN during a single cycle TRIGGER-RTS-CTS-DATA o...
int n_POLL_pck_tx_by_HN
Number of POLL packet transmitted by the HN during a single cycle BEACON-PROBE-POLL-DATA-CBEACON of t...
void incrTotalDataPckTx_by_HN()
Increase the total number of DATA packets transmitted by the HN during an entire simulation.
virtual void CTS_rx()
HN has received a CTS packet from AUV.
int getDataPckTx_by_HN()
Number of DATA packets transmitted by the HN during a single cycle TRIGGER-RTS-CTS-DATA of the simula...
double T_min_bck_DATA
Lower bound time interval from which the HN choice its backoff timer before to transmit a DATA packet...
uwUFetch_DATA_timer DATA_timer
Schedule the DATA timeout timer.
virtual void DataTOExpired()
DATA timeout is expired.
void incrTotalCtsPckRx_HN()
Increase the total number of CTS packets correctly or not received by the HN during an entire simulat...
virtual void DATA_HN_tx()
HN transmit a DATA packet to the AUV.
int max_pck_HN_can_tx
Maximum number of DATA packets that AUV want to receive from HN.
double Tdata_HN
Time needed to transmit a DATA packet.
virtual void state_CBEACON_tx()
HN initialize the CBEACON packet that will be forwarded in broadcast at all SNs of the network.
int n_PROBE_pck_rx_by_HN
Number of PROBE packet received by the HN during a single cycle BEACON-PROBE-POLL-DATA-CBEACON of the...
void incrTriggerPckRx_HN()
Increase the number of TRIGGER packets received by the HN during a single cycle TRIGGER-RTS-CTS-DATA ...
virtual void PROBE_rx()
HN has received a PROBE packet from SN.
uwUFetch_BackOffTimer BCK_timer_rts
Schedule the backoff timeout timer.
uwUFetch_DATA_BEFORE_TX_timer DATA_BEFORE_TX_timer
void incrCBeaconPckTx_by_HN()
Increase the number of CBEACON packets transmitted by the HN during a single cycle BEACON-PROBE-POLL-...
int n_CTS_pck_rx_by_HN
Number of CTS packet received by the HN during a single cycle TRIGGER-RTS-CTS-DATA of the simulation.
virtual void state_wait_other_DATA()
HN start to wait the second or successive DATA packet from SN.
virtual bool typeCommunication()
Indicate if the communiation between HN and AUV take place with or without RTS and CTS packets.
virtual void recvFromUpperLayers_HN(Packet *p)
Handle a packet coming from upper layers of HN.
int n_TRIGGER_pck_rx_by_HN
Number of TRIGGER packet received by the HN during a single cycle TRIGGER-RTS-CTS-DATA of the simulat...
void incrTotalProbePckRx_HN()
Increase total number of PROBE packets correctly or not received by the HN during an entire simulatio...
virtual void TRIGGER_rx_without()
HN has received a TRIGGER packet from AUV.
int MAX_PAYLOAD
Maximum size of payload DATA packet.
double tx_BEACON_finish_HN_time
Indicates when HN finished the transmission of BEACON packet to the SNs.
int mac_addr_NODE_polled
SN-MAC address of the node that the HN is going to be poll and from which It want to receive DATA pac...
uwUFetch_BEACON_timer BeaconBeforeTx_timer
Schedule the BEACON timeout timer.
@ UWUFETCH_NODE_PACKET_TYPE_DATA
@ UWUFETCH_NODE_PACKET_TYPE_POLL
int MODE_BURST_DATA
Indicate if it's used or not the burst data.
virtual void POLL_tx()
HN transmit POLL packet to a specific SN of th network.
void incrTotalDataPckTx_by_NODE()
Increase the total number of DATA packets transmitted by SN during an entire duration of simulation.
int n_DATA_pck_rx_by_HN
Number of DATA packet received by the HN during a single cycle BEACON-PROBE-POLL-DATA-CBEACON of the ...
virtual void TRIGGER_rx()
HN has received a TRIGGER packet from AUV.
bool txRTSbeforeCBEACON
true HN block the transmission of CBEACON because It try to communicate with the AUV.
double tx_DATA_start_HN_time
Indicates when HN started the transmission of DATA packet to the AUV.
Packet * curr_PROBE_HN_pck_rx
Pointer to the PROBE packet that is being received by HN.
uwUFetch_PROBE_timer PROBE_timer
Schedule the PROBE timeout timer.
@ UWUFETCH_NODE_STATUS_CHANGE_DATA_MAX_ALLOWED_PCK_RX_0_NODE_TO_POLL_NO_OTHER_CBEACON
@ UWUFETCH_NODE_STATUS_CHANGE_DATA_PCK_TX
@ UWUFETCH_NODE_STATUS_CHANGE_DATA_MAX_ALLOWED_PCK_RX_0_NODE_TO_POLL_YES_OTHER_CBEACON
@ UWUFETCH_NODE_STATUS_CHANGE_TRIGGER_RX
@ UWUFETCH_NODE_STATUS_CHANGE_DATA_RX
@ UWUFETCH_NODE_STATUS_CHANGE_CBEACON_ALLOWED_TX_0_PROBE_RX
@ UWUFETCH_NODE_STATUS_CHANGE_CBEACON_TX
@ UWUFETCH_NODE_STATUS_CHANGE_HN_RX_TRIGGER_FROM_AUV_CORRUPTED
@ UWUFETCH_NODE_STATUS_CHANGE_RTS_TX
@ UWUFETCH_NODE_STATUS_CHANGE_PROBE_RX
@ UWUFETCH_NODE_STATUS_CHANGE_LAST_DATA_PCK_RX
@ UWUFETCH_NODE_STATUS_CHANGE_DATA_TO_EXPIRED
@ UWUFETCH_NODE_STATUS_CHANGE_CBEACON_MAX_ALLOWED_TX_0_PROBE_RX
@ UWUFETCH_NODE_STATUS_CHANGE_POLL_TX
@ UWUFETCH_NODE_STATUS_CHANGE_DATA_MAX_ALLOWED_PCK_RX_YES_NODE_TO_POLL
@ UWUFETCH_NODE_STATUS_CHANGE_CTS_RX
@ UWUFETCH_NODE_STATUS_CHANGE_BEACON_TO_EXPIRED
@ UWUFETCH_NODE_STATUS_CHANGE_TO_WAIT_CTS_EXPIRED
@ UWUFETCH_NODE_STATUS_CHANGE_TO_EXPIRED_AT_LEAST_1_PROBE_RX
@ UWUFETCH_NODE_STATUS_CHANGE_TRIGGER_RX_BUT_HN_NO_DATA_TO_TX
@ UWFETCH_NODE_STATUS_CHANGE_PACKET_ERROR
@ UWUFETCH_NODE_STATUS_CHANGE_BEACON_TX
@ UWUFETCH_NODE_STATUS_CHANGE_HN_FINISH_TX_DATA_PCK_TO_AUV_RETURN_CBEACON_TX
@ UWUFETCH_NODE_STATUS_CHANGE_HN_TX_ALL_DATA_TO_AUV
@ UWUFETCH_NODE_STATUS_CHANGE_MAX_PROBE_RX_PROBE_TO_NOT_EXPIRED
double Tpoll
Time needed to transmit a POLL packet.
int getProbePckRx_HN()
Number of PROBE packets received by the HN during a single cycle BEACON-PROBE-POLL-DATA-CBEACON of th...
double rx_TRIGGER_finish_HN_time
Indicates when HN finished the reception of TRIGGER packet from the AUV.
int MAX_PCK_HN_WANT_RX_FROM_NODE
bool txCBEACONEnabled
true if HN is enabled to transmit a CBEACON packet to the SN
double RTT
Round trip time value.
Packet * curr_POLL_HN_pck_tx
Pointer to the POLL packet that is being transmitted by HN.
int mac_addr_AUV_in_CTS
AUV-MAC address contained int the CTS packet received by HN.
void incrTotalProbePckRx_corrupted_HN()
Increase the total number of corrupted PROBE packets received by the HN during an entire simulation.
virtual void state_POLL_tx()
HN initialize the POLL packet that will be forwarded to a specific SN of the network.
Packet * curr_DATA_HN_pck_tx
Pointer to the DATA packet that is being transmitted by HN to the AUV.
double T_START_PROCEDURE_HN_NODE
Time within HN is enabled to received a TRIGGER packet from AUV.
std::queue< int > Q_data_source_SN
Queue that contain the MAC address from which the HN has received the DATA packet.
std::queue< Packet * > Q_data
Queue of DATA packets stored by the SN.
virtual void CtsTOExpired()
CTS timeout is expired.
virtual void state_RTS_tx()
HN initialize the RTS packet that will be forwarded to the AUV.
int max_data_HN_can_tx
Maximum number of DATA packets that the HN must transmit to the AUV.
int mac_addr_NODE_in_data
Mac address of the node from which the HN has received a DATA packet.
double Tdata_HN_pck
Time to transmit a DATA packet by the HN.
int n_DATA_pck_tx_by_HN
Number of DATA packet transmitted by the HN during a single cycle TRIGGER-RTS-CTS-DATA of the simulat...
void incrTotalRtsPckTx_by_HN()
Increase the total number of RTS packets transmitted by the HN during an entire simulation.
uwUFetch_CTS_timer CTS_timer
Schedule the CTS timeout timer.
double rx_CTS_finish_HN_time
Indicates when HN finished the reception of CTS packet from the SNs.
std::queue< int > Q_probbed_n_pcks_NODE_want_tx_HN
Queue that store the number of DATA packets that the single SN want to tx to the HN.
virtual void RTS_tx()
HN transmit a RTS packet to the AUV.
double rx_PROBE_finish_HN_time
Indicates when HN finished the reception of PROBE packet from the SNs.
Packet * curr_DATA_HN_pck_rx
Pointer to the DATA packet that is being received by HN from SN.
double tx_CBEACON_finish_HN_time
Indicates when HN finished the transmission of CBEACON packet to the SNs.
int n_RTS_pck_tx_by_HN
Number of RTS packet transmitted by the HN during a single cycle TRIGGER-RTS-CTS-DATA of the simulati...
void incrTotalCtsPckRx_corrupted_HN()
Increase the total number of corrupted CTS packets received by the HN during an entire simulation.
Packet * curr_CTS_HN_pck_rx
Pointer to the CTS packet that is being received by HN.
void incrTotalCBeaconPckTx_by_HN()
Increase the total number of CBEACON packets transmitted by the HN during an entire simulation.
int getCBeaconPckTx_by_HN()
Number of CBEACON packets transmitted by the HN during a single cycle BEACON-PROBE-POLL-DATA-CBEACON ...
bool rxDATAEnabled
true if HN is enabled to receive a DATA packet from teh SN
bool print_transitions
true if the writing of state transitions in the file is enabled.
virtual void refreshState(UWUFETCH_NODE_STATUS state)
@ UWUFETCH_NODE_STATUS_PROBE_RX
@ UWUFETCH_NODE_STATUS_WAIT_CTS_PACKET
@ UWUFETCH_NODE_STATUS_TRIGGER_RECEIVE
@ UWUFETCH_NODE_STATUS_CTS_RECEIVE
@ UWUFETCH_NODE_STATUS_WAIT_DATA_NODE
@ UWUFETCH_NODE_STATUS_WAIT_PROBE_PACKET
@ UWUFETCH_NODE_STATUS_TRANSMIT_BEACON
@ UWUFETCH_NODE_STATUS_RTS_TRANSMIT
void incrCtsPckRx_HN()
Increase the number of CTS packets received by the HN during a single cycle TRIGGER-RTS-CTS-DATA of t...
Content header of BEACON packet.
int & t_max_bc()
Reference to t_max_bc_ variable.
int & num_Max_CBEACON_tx_by_HN()
Reference to num_Max_CBEACON_tx_by_HN_ variable.
int & t_min_bc()
Reference to t_min_bc_ variable.
Content header of CBEACON packet.
int & t_max_bc()
Reference to t_max_bc_ variable.
int & t_min_bc()
Reference to t_min_bc_ variable.
Content header of CTS packet.
int & num_DATA_pcks_MAX_rx()
Reference to the num_DATA_pcks_MAX_rx_ variable.
Content header of POLL packet.
int & mac_addr_Node_polled()
Reference to mac_addr_Node_polled_ variable.
int & num_DATA_pcks_MAX_rx()
Reference to num_DATA_pcks_MAX_rx variable.
Content header of PROBE packet.
int & n_DATA_pcks_Node_tx()
Reference to n_DATA_pcks_Node_tx_ variable.
int & backoff_time_PROBE()
Reference to backoff_time_PROBE_ variable.
Content header of RTS packet.
int & backoff_time_RTS()
Reference to the backoff_Time_RTS_ variable.
int & num_DATA_pcks()
Reference to the num_Data_pcks_ variable.
Content header of TRIGGER packet.
int & t_min()
Reference to the t_min variable.
int & t_max()
Reference to the t_max variable.
int & max_pck_want_rx()
Reference to the max_pck_want_rx variable.
hdr_uwcbr describes UWCBR packets.
uint16_t & sn()
Reference to the sn_ variable.
Declaration of uwUFetch_NODE class.
packet_t PT_POLL_UFETCH
POLL packet type for UFetch protocol.
#define UWFETCH_NODE_DROP_REASON_ERROR
Packet dropped: packet is corrupted.
#define UWUFETCH_NODE_DROP_REASON_BUFFER_FULL
Packet dropped: buffer of the node is completely full.
packet_t PT_CBEACON_UFETCH
CBEACON packet type for UFetch protocol.
packet_t PT_CTS_UFETCH
CTS packet type for UFetch protocol.
packet_t PT_TRIGGER_UFETCH
TRIGGER packet type for UFetch protocol.
packet_t PT_BEACON_UFETCH
BEACON packet type for UFetch protocol.
#define UWUFETCH_NODE_DROP_CAN_NOT_RX_THIS_PCK
Packet dropped: node can not receive this type of node.
packet_t PT_PROBE_UFETCH
PROBE packet type for UFetch protocol.
packet_t PT_RTS_UFETCH
RTS packet type for UFetch protocol.
#define UWUFETCH_NODE_DROP_REASON_NOT_ENABLE
Packet dropped: node is not enabled to receive this type of \ packet.
Common structures and variables in the protocol.
#define HDR_BEACON_UFETCH(p)
alias defined to access the BEACON HEADER
#define HDR_POLL_UFETCH(p)
alias defined to access the POLL \ HEADER
#define HDR_CTS_UFETCH(p)
alias defined to access the CTS HEADER
#define HDR_CBEACON_UFETCH(p)
alias defined to access the CBEACON HEADER
#define HDR_TRIGGER_UFETCH(p)
alias defined to access the TRIGGER HEADER
#define HDR_PROBE_UFETCH(p)
alias defined to access the PROBE HEADER
#define HDR_RTS_UFETCH(p)
alias defined to access the RTS HEADER
Provides the UWCBR packets header description and the definition of the class UWCBR.
#define HDR_UWCBR(p)