DESERT 3.5.1
Loading...
Searching...
No Matches
uwUFetch_NODE_HEADNODE.cpp
Go to the documentation of this file.
1//
2// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova.
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions
7// are met:
8// 1. Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// 2. Redistributions in binary form must reproduce the above copyright
11// notice, this list of conditions and the following disclaimer in the
12// documentation and/or other materials provided with the distribution.
13// 3. Neither the name of the University of Padova (SIGNET lab) nor the
14// names of its contributors may be used to endorse or promote products
15// derived from this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28//
29
39// include files
40#include "mac.h"
41#include "mmac.h"
42#include "uwUFetch_NODE.h"
43#include "uwUFetch_cmn_hdr.h"
44#include "rng.h"
45
46/*******************************************************************************
47 * GENERAL METHODS *
48 *******************************************************************************/
49
55void
57{
58
59 hdr_cmn *cmh = hdr_cmn::access(p);
60 hdr_mac *mach = HDR_MAC(p);
61 int src_mac_addr = mach->macSA();
62
63 if (cmh->ptype() == PT_BEACON_UFETCH) {
64 // BEACON section
65 if (debug_)
66 std::cout
67 << NOW << " uwUFetch_NODE (" << addr
68 << ") ::Phy2MacStartRx() ---->HN is starting to receive a "
69 << " BEACON packet from the HN with MAC address: "
70 << src_mac_addr << std::endl;
71
72 if (debugMio_)
73 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
74 << ")::Phy2MacStartRx()____________________Start "
75 "to rx BEACON pck"
76 << " from HN(" << src_mac_addr << ")."
77 << std::endl;
78
79 } else if (cmh->ptype() == PT_POLL_UFETCH) {
80 // POLL section
81 if (debug_)
82 std::cout
83 << NOW << " uwUFetch_NODE (" << addr
84 << ") ::Phy2MacStartRx() ---->HN is starting to receive a "
85 << " POLL packet from the HN with MAC address: "
86 << src_mac_addr << std::endl;
87
88 if (debugMio_)
89 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
90 << ")::Phy2MacStartRx()______________________"
91 "Start to rx POLL pck"
92 << " from HN(" << src_mac_addr << ")."
93 << std::endl;
94
95 } else if (cmh->ptype() == PT_CBEACON_UFETCH) {
96 // CBEACON section
97 if (debug_)
98 std::cout
99 << NOW << " uwUFetch_NODE (" << addr
100 << ") ::Phy2MacStartRx() ---->HN is starting to receive a "
101 << " CBEACON packet from the HN with MAC address: "
102 << src_mac_addr << std::endl;
103
104 if (debugMio_)
105 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
106 << ")::Phy2MacStartRx()______________________"
107 "Start to rx CBEACON pck"
108 << " from HN(" << src_mac_addr << ")."
109 << std::endl;
110
111 } else if (cmh->ptype() == PT_PROBE_UFETCH) {
112 // PROBE section
113 if (debug_)
114 std::cout
115 << NOW << " uwUFetch_NODE (" << addr
116 << ") ::Phy2MacStartRx() ---->HN is starting to receive a "
117 << " PROBE packet from the NODE with MAC address: "
118 << src_mac_addr << std::endl;
119
120 if (debugMio_)
121 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
122 << ")::Phy2MacStartRx()______________________"
123 "Start to rx PROBE pck"
124 << " from SENSOR NODE(" << src_mac_addr << ")."
125 << std::endl;
126
128
129 } else if (cmh->ptype() == PT_TRIGGER_UFETCH) {
130 // TRIGGER section
131 if (debug_)
132 std::cout << NOW << " uwUFetch_NODE (" << addr
133 << ") ::Phy2MacStartRx() ---->HN is starting to receive a"
134 << " TRIGGER packet from the AUV with MAC address: "
135 << src_mac_addr << std::endl;
136
137 if (debugMio_)
138 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
139 << ")::Phy2MacStartRx()______________________"
140 "Start to rx TRIGGER pck"
141 << " from AUV(" << src_mac_addr << ")."
142 << std::endl;
143
145
146 } else if (cmh->ptype() == PT_CTS_UFETCH) {
147 // CTS section
148 if (debug_)
149 std::cout
150 << NOW << " uwUFetch_NODE (" << addr
151 << ") ::Phy2MacStartRx() ---->HN is starting to receive a "
152 << " CTS packet from the AUV with MAC address: "
153 << src_mac_addr << std::endl;
154
155 if (debugMio_)
156 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
157 << ")::Phy2MacStartRx()______________________"
158 "Start to rx CTS pck"
159 << " from AUV(" << src_mac_addr << ")."
160 << std::endl;
161
163
164 } else {
165 // DATA section
166 if (debug_)
167 std::cout
168 << NOW << " uwUFetch_NODE (" << addr
169 << ") ::Phy2MacStartRx() ---->HN is starting to receive a "
170 << " DATA packet from the NODE with MAC address: "
171 << src_mac_addr << std::endl;
172
173 if (debugMio_)
174 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
175 << ")::Phy2MacStartRx()______________________"
176 "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
177 "DDDDDDDDDDDDDDDDDDDDDD"
178 << std::endl;
179
180 if (debugMio_)
181 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
182 << ")::Phy2MacStartRx()______________________"
183 "Start to rx DATA pck"
184 << " from SN(" << src_mac_addr << ")."
185 << std::endl;
186
188 }
189
190} // end Phy2MacStartRx_HN();
191
197void
199{
200 hdr_cmn *cmh = hdr_cmn::access(p);
201 hdr_mac *mach = HDR_MAC(p);
202 int src_mac_addr = mach->macSA();
203 int dest_mac_addr = mach->macDA(); // Destination MAC address, the address
204 // to which the packet is addressed
205
206 if (debug_)
207 std::cout << NOW << "uwUFetch_NODE(" << addr
208 << ")::Phy2MacEndRx()______________________dest_mac_addr "
209 << dest_mac_addr << std::endl;
210 // Control if the packet that the HN has received is really for him
211
212 if ((dest_mac_addr == addr) || (dest_mac_addr == MAC_BROADCAST)) {
213 // Packet is addressed to me HN
214
215 if (cmh->ptype() == PT_BEACON_UFETCH) {
216 // BEACON section
217 if (debug_)
218 std::cout << NOW << " uwUFetch_NODE (" << addr
219 << ") ::Phy2MacEndRx() ---->HN has finished to "
220 "receive a"
221 << " BEACON packet from the HN with MAC address: "
222 << src_mac_addr << " .DROP IT" << std::endl;
223
224 if (debugMio_)
225 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
226 << ")::Phy2MacEndRx()________________________"
227 "Finished to rx BEACON"
228 << " pck from HN(" << src_mac_addr << ")."
229 << std::endl;
230
231 if (debugMio_)
232 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
233 << ")::Phy2MacEndRx()________________________"
234 "BEACON not addressed to me: DROP IT."
235 << std::endl;
236
238
239 } else if (cmh->ptype() == PT_CBEACON_UFETCH) {
240 // CBEACON section
241 if (debug_)
242 std::cout << NOW << " uwUFetch_NODE (" << addr
243 << ") ::Phy2MacEndRx() ---->HN has finished to "
244 "receive a"
245 << " CBEACON packet from the HN with MAC address: "
246 << src_mac_addr << " .DROP IT." << std::endl;
247
248 if (debugMio_)
249 out_file_logging << NOW << "uwUFetch_HEAD_NODE (" << addr
250 << ")::Phy2MacEndRx()________________________"
251 "Finished to rx CBEACON"
252 << " pck from HN(" << src_mac_addr
253 << "): IGNORE IT." << std::endl;
254
256
257 } else if (cmh->ptype() == PT_PROBE_UFETCH) {
258 // PROBE section
259 if (debug_)
260 std::cout << NOW << " uwUFetch_NODE (" << addr
261 << ") ::Phy2MacEndRx() ---->HN has finished to "
262 "receive a"
263 << " PROBE packet from the NODE with MAC address: "
264 << src_mac_addr << std::endl;
265
266 if (debugMio_)
267 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
268 << ")::Phy2MacEndRx()________________________"
269 "Finished to rx PROBE"
270 << " pck from SENSOR NODE(" << src_mac_addr
271 << ")." << std::endl;
272
273 if (cmh->error()) {
274 // Packet it's in error
275 if (debug_)
276 std::cout << NOW << " uwUFetch_NODE (" << addr
277 << ") ::Phy2MacEndRx() ---->PROBE packet "
278 "received by the HN"
279 << " is corrupted: DROP IT." << std::endl;
280
281 if (debugMio_)
282 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
283 << ")::Phy2MacEndRx()_____________________"
284 "___PROBE pck rx from SN("
285 << src_mac_addr << ") It's in ERROR."
286 << std::endl;
287
289
292
293 if (debugMio_)
294 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
295 << ")::Phy2MacEndRx()_____________________"
296 "___Total number of PROBE"
297 << " rx " << getTotalProbePckRx_HN() << "."
298 << std::endl;
299 if (debugMio_)
300 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
301 << ")::Phy2MacEndRx()_____________________"
302 "___Total number of CORRUPTED PROBE"
303 << " rx "
305 << std::endl;
306 if (debugMio_)
307 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
308 << ")::Phy2MacEndRx()_____________________"
309 "___Total number of CORRECT PROBE"
310 << " rx "
313 << "." << std::endl;
314
315 drop(p, 1, UWFETCH_NODE_DROP_REASON_ERROR); // drop the packet
317
318 } else {
319 if (rxPROBEEnabled) {
320 // Packet is not in error
321 if (debug_)
322 std::cout << NOW << " uwUFetch_NODE (" << addr
323 << ") ::Phy2MacEndRx() ---->Physical layer "
324 "of HN with MAC"
325 << " address: " << dest_mac_addr
326 << " has finished to receive a PROBE packet"
327 << " number: " << (getProbePckRx_HN() + 1)
328 << " from the NODE with MAC address: "
329 << src_mac_addr << std::endl;
330
331 if (debugMio_)
332 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
333 << ")::Phy2MacEndRx()_________________"
334 "_______PROBE pck rx from SN("
335 << src_mac_addr << ") It's CORRECT."
336 << std::endl;
337
339
342
343 if (debugMio_)
344 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
345 << ")::Phy2MacEndRx()_________________"
346 "_______Total number of PROBE"
347 << " rx " << getTotalProbePckRx_HN()
348 << "." << std::endl;
349 if (debugMio_)
351 << NOW << "uwUFetch_HEAD_NODE(" << addr
352 << ")::Phy2MacEndRx()________________________"
353 "Total number of CORRUPTED PROBE"
355 << "." << std::endl;
356 if (debugMio_)
358 << NOW << "uwUFetch_HEAD_NODE(" << addr
359 << ")::Phy2MacEndRx()________________________"
360 "Total number of CORRECT PROBE"
361 << " rx "
364 << "." << std::endl;
365
366 curr_PROBE_HN_pck_rx = p->copy();
367
369
370 Packet::free(p);
371
372 PROBE_rx();
373
374 } else {
375 // HN is not enabled to receive a PROBE packet
376 if (debug_)
377 std::cout << NOW << " uwUFetch_NODE (" << addr
378 << ") ::Phy2MacEndRx() ---->HN is not "
379 "enabled to receive the PROBE"
380 << " packet: DROP IT." << std::endl;
381 if (debugMio_)
383 << NOW << "uwUFetch_HEAD_NODE(" << addr
384 << ")::Phy2MacEndRx()________________________"
385 "Now not ENABLED to rx PROBE pck from SN("
386 << src_mac_addr << ")." << std::endl;
387
389
391 }
392 }
393
394 } else if (cmh->ptype() == PT_TRIGGER_UFETCH) {
395 if (typeCommunication()) {
396 // Communication between HN & AUV without RTS and CTS packets
397
399 } else {
400 // Communication between HN & AUV with RTS and CTS packets
401 // TRIGGER section
402 if (debug_)
403 std::cout
404 << NOW << " uwUFetch_NODE (" << addr
405 << ") ::Phy2MacEndRx() ---->HN has finished to "
406 "receive a"
407 << " TRIGGER packet from the AUV with MAC address: "
408 << src_mac_addr << std::endl;
409
410 if (debugMio_)
411 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
412 << ")::Phy2MacEndRx()_____________________"
413 "___Finished to rx TRIGGER pck"
414 << " from AUV(" << src_mac_addr << ")."
415 << std::endl;
416
418 mach->macSA(); // Save the Mac address of the
419
426 if (rxTRIGGEREnabled) {
427 int index_q = 0;
428 while ((!Q_data.empty()) &&
429 (index_q <= MAX_PCK_HN_WANT_RX_FROM_NODE)) {
430 // Pick up the first element of the queue
431 curr_DATA_NODE_pck_tx_HN = (Q_data.front())->copy();
432 // Remove the element from the queue that we have pick
433 // up the packet
434 Q_data.pop();
435 // Add the packet to the queue of data packets that HN
436 // will transmit to AUV when
437 // will be required
441 index_q++;
442 }
443 }
444
445 if ((cmh->error()) || (Q_data_HN.empty())) {
446 if (cmh->error()) {
447 // Packet it's in error
448 if (debug_)
449 std::cout << NOW << " uwUFetch_NODE (" << addr
450 << ") ::Phy2MacEndRx() ---->TRIGGER "
451 "packet received by the HN"
452 << " is corrupted: DROP IT" << std::endl;
453
454 if (debugMio_)
456 << NOW << "uwUFetch_HEAD_NODE(" << addr
457 << ")::Phy2MacEndRx()______________________"
458 "__TRIGGER rx from AUV("
459 << mach->macSA() << ") It's in ERROR."
460 << std::endl;
461
463
466
467 drop(p, 1, UWFETCH_NODE_DROP_REASON_ERROR); // drop the
468 // packet
470
471 if (rxTRIGGEREnabled) {
472 if (debug_)
473 std::cout << NOW << " uwUFetch_NODE (" << addr
474 << ") ::Phy2MacEndRx() ---->HN reset "
475 "the TRIGGER timer"
476 << std::endl;
477 if (debugMio_)
479 << NOW << "uwUFetch_HEAD_NODE(" << addr
480 << ")::Phy2MacEndRx()__________________"
481 "______TRIGGER rx in ERROR && HN is "
482 "enabled to rx It: IGNORE It."
483 << std::endl;
484
485 BeaconBeforeTx_timer.force_cancel();
486 // Trigger_timer.force_cancel();
487
488 if (debugMio_)
490 << NOW << "uwUFetch_HEAD_NODE(" << addr
491 << ")::Phy2MacEndRx()__________________"
492 "______Reset the TRIGGER timeout"
493 << std::endl;
494
497 rxTRIGGEREnabled = true;
498
499 stateIdle_HN();
500 } else {
501 // HN is not enable to receive a TRIGGER packet
502 if (debug_)
503 std::cout << NOW << " uwUFetch_NODE (" << addr
504 << ") ::Phy2MacEndRx() ---->HN is "
505 "not enabled to receive"
506 << " the TRIGGER packet: DROP IT."
507 << std::endl;
508 if (debugMio_)
510 << NOW << "uwUFetch_HEAD_NODE(" << addr
511 << ")::Phy2MacEndRx()__________________"
512 "______TRIGGER in error && Not "
513 "ENABLED"
514 << " to rx It: IGNORE It." << std::endl;
515 }
516 } else {
517 if (debug_)
518 std::cout << NOW << " uwUFetch_NODE (" << addr
519 << ") ::Phy2MacEndRx() ---->TRIGGER "
520 "packet received by the HN"
521 << " is not corrupted, but the HN has 0 "
522 "DATA packet enabled to tx to the "
523 "AUV: DROP IT"
524 << std::endl;
525
526 if (debugMio_)
527 out_file_logging << NOW << "uwUFetch_HEAD_NODE("
528 << addr
529 << ")::Phy2MacEndRx()_____________"
530 "___________TRIGGER rx It's "
531 "CORRECT but 0 DATA to tx."
532 << std::endl;
533
535
537
538 drop(p, 1, UWFETCH_NODE_DROP_REASON_ERROR); // drop the
539 // packet
541
542 if (rxTRIGGEREnabled) {
543 if (debug_)
544 std::cout << NOW << " uwUFetch_NODE (" << addr
545 << ") ::Phy2MacEndRx() ---->HN reset "
546 "the TRIGGER timer"
547 << std::endl;
548 BeaconBeforeTx_timer.force_cancel();
549 // Trigger_timer.force_cancel();
550
551 if (debugMio_)
553 << NOW << "uwUFetch_HEAD_NODE(" << addr
554 << ")::Phy2MacEndRx()__________________"
555 "______TRIGGER rx CORRECT, 0 DATA "
556 "to tx && enabled to rx It: IGNORE "
557 "It."
558 << std::endl;
559
560 if (debugMio_)
562 << NOW << "uwUFetch_HEAD_NODE(" << addr
563 << ")::Phy2MacEndRx()__________________"
564 "______Reset the TRIGGER timeout"
565 << std::endl;
566
569 rxTRIGGEREnabled = true;
570
571 stateIdle_HN();
572 } else {
573 // HN is not enable to receive a TRIGGER packet
574 if (debug_)
575 std::cout << NOW << " uwUFetch_NODE (" << addr
576 << ") ::Phy2MacEndRx() ---->HN is "
577 "not enabled to receive"
578 << " the TRIGGER packet: DROP IT."
579 << std::endl;
580
581 if (debugMio_)
583 << NOW << "uwUFetch_HEAD_NODE(" << addr
584 << ")::Phy2MacEndRx()__________________"
585 "______TRIGGER rx CORRECT, 0 DATA "
586 "to tx && not enabled to rx It: "
587 "IGNORE It."
588 << std::endl;
589 }
590 }
591 } else {
592 // Packet it's not in error
593 if (debug_)
594 std::cout << NOW << " uwUFetch_NODE (" << addr
595 << ") ::Phy2MacEndRx() ---->Physical layer "
596 "of HN with MAC"
597 << " address: " << dest_mac_addr
598 << " has finished to receive a TRIGGER packet"
599 << " from the AUV with MAC address: "
600 << src_mac_addr << std::endl;
601
602 if (debugMio_)
604 << NOW << "uwUFetch_HEAD_NODE(" << addr
605 << ")::Phy2MacEndRx()________________________"
606 "TRIGGER rx It's CORRECT >= 1 DATA to tx."
607 << std::endl;
608
610
613
614 curr_TRIGGER_HN_pck_rx = p->copy();
615
617
618 Packet::free(p);
619
620 TRIGGER_rx();
621 }
622 }
623
624 } else if (cmh->ptype() == PT_CTS_UFETCH) {
625 // CTS section
626 if (debug_)
627 std::cout << NOW << " uwUFetch_NODE (" << addr
628 << ") ::Phy2MacEndRx() ---->HN has finished to "
629 "receive a"
630 << " CTS packet from the AUV with MAC address: "
631 << src_mac_addr << std::endl;
632
633 if (debugMio_)
634 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
635 << ")::Phy2MacEndRx()________________________"
636 "Finished to rx CTS pck"
637 << " from AUV(" << src_mac_addr << ")."
638 << std::endl;
639
640 if (rxCTSEnabled) {
641 if (cmh->error()) {
642 // Packet it's in error
643 if (debug_)
644 std::cout << NOW << " uwUFetch_NODE (" << addr
645 << ") ::Phy2MacEndRx() ---->CTS packet "
646 "received by the HN"
647 << " is corrupted: DROP IT" << std::endl;
648 if (debugMio_)
649 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
650 << ")::Phy2MacEndRx()_________________"
651 "_______CTS pck rx from AUV("
652 << src_mac_addr << ") It's in ERROR."
653 << std::endl;
654
656
659
660 drop(p,
661 1,
662 UWFETCH_NODE_DROP_REASON_ERROR); // drop the packet
664
665 // return in Idle state
666 if (debug_)
667 std::cout << NOW << " uwUFetch_NODE (" << addr
668 << ") ::Phy2MacEndRx() ---->HN reset the "
669 "timer to wait CTS,"
670 << " and return in IDLE STATE." << std::endl;
671 if (debugMio_)
672 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
673 << ")::Phy2MacEndRx()_________________"
674 "_______RESET CTS timeout."
675 << std::endl;
676
677 CTS_timer.force_cancel();
678 // Trigger_timer.force_cancel();
679
684
685 rxCTSEnabled = false;
686 rxTRIGGEREnabled = true;
687 CTSrx = true;
688 stateIdle_HN();
689
690 } else {
691 // Packet it's not in error
692 if (debug_)
693 std::cout << NOW << " uwUFetch_NODE (" << addr
694 << ") ::Phy2MacEndRx() ---->Physical layer "
695 "of HN with MAC"
696 << " address: " << dest_mac_addr
697 << " has finished to receive a CTS packet"
698 << " from the AUV with MAC address: "
699 << src_mac_addr << std::endl;
700
702 if (debugMio_)
703 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
704 << ")::Phy2MacEndRx()_________________"
705 "_______CTS pck rx from AUV("
706 << src_mac_addr << ") It's CORRECT."
707 << std::endl;
708
709 if (debug_)
710 std::cout << NOW << " uwUFetch_NODE (" << addr
711 << ") ::Phy2MacEndRx() ---->HN reset the "
712 "timer to wait CTS,"
713 << " and COMPUTE IT." << std::endl;
714 if (debugMio_)
715 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
716 << ")::Phy2MacEndRx()_________________"
717 "_______RESET CTS timeout."
718 << std::endl;
719
720 CTS_timer.force_cancel(); // reset the timer in which the HN
721 // wait a TRIGGER packet
722 // Trigger_timer.force_cancel();
723
726
727 curr_CTS_HN_pck_rx = p->copy();
728
729 Packet::free(p);
731
732 CTS_rx();
733 }
734 } else {
735 // HN is not enable to receive a CTS packet
736 CTSrx = true;
737
738 if (debug_)
739 std::cout << NOW << " uwUFetch_NODE (" << addr
740 << ") ::Phy2MacEndRx() ---->HN is not enabled to "
741 "receive"
742 << " the CTS packet: DROP IT." << std::endl;
743 if (debugMio_)
744 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
745 << ")::Phy2MacEndRx()_____________________"
746 "___CTS pck rx from AUV("
747 << src_mac_addr
748 << "). It's not enabled to rx It."
749 << std::endl;
750
752 1,
754 }
755 } else {
756 // DATA section
757 if (debug_)
758 std::cout << NOW << " uwUFetch_NODE (" << addr
759 << ") ::Phy2MacEndRx() ---->HN has finished to "
760 "receive a"
761 << " DATA packet from the NODE with MAC address: "
762 << src_mac_addr << std::endl;
763
765
766 if (debugMio_)
767 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
768 << ")::Phy2MacEndRx()________________________"
769 "End to rx DATA pck "
770 << "from SN(" << src_mac_addr << ")."
771 << std::endl;
772
773 if (debugMio_)
774 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
775 << ")::Phy2MacEndRx()________________________"
776 "DATA pck number "
777 << getDataPckRx_by_HN() + 1 << "."
778 << std::endl;
779
780 if (cmh->error()) {
781 // Packet it's in error
782 if (debug_)
783 std::cout << NOW << " uwUFetch_NODE( " << addr
784 << ") ::Phy2MacEndRx() ---->DATA packet received "
785 "by the HN"
786 << " is corrupted: DROP IT" << std::endl;
787
789
793
794 if (debugMio_)
795 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
796 << ")::Phy2MacEndRx()_____________________"
797 "___DATA pck rx from SN("
798 << src_mac_addr << ")"
799 << " It's in ERROR." << std::endl;
800 if (debugMio_)
801 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
802 << ")::Phy2MacEndRx()_____________________"
803 "___DATA pck number "
804 << getDataPckRx_by_HN() + 1
805 << " rx It's in ERROR." << std::endl;
806 if (debugMio_)
808 << NOW << "uwUFetch_HEAD_NODE(" << addr
809 << ")::Phy2MacEndRx()________________________"
810 "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
811 "DDDDDDDDDDDDDDDDDDDDD"
812 << std::endl;
813
814 drop(p, 1, UWFETCH_NODE_DROP_REASON_ERROR); // drop the packet
816
817 } else {
818 // Packet it's not in error
819
820 if (debug_)
821 std::cout << NOW << " uwUFetch_NODE (" << addr
822 << ") ::Phy2MacEndRx() ---->Physical layer of HN "
823 "with MAC"
824 << " address: " << dest_mac_addr
825 << " has finished to receive a DATA packet"
826 << " number: " << (getDataPckRx_by_HN() + 1)
827 << " from the NODE with MAC address: "
828 << src_mac_addr << std::endl;
829
830 if (debugMio_)
831 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
832 << ")::Phy2MacEndRx()_____________________"
833 "___DATA pck rx from SN("
834 << src_mac_addr << ")"
835 << " It's CORRECT." << std::endl;
836 if (debugMio_)
837 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
838 << ")::Phy2MacEndRx()_____________________"
839 "___DATA pck number "
840 << getDataPckRx_by_HN() + 1
841 << " It's CORRECT." << std::endl;
842
844
847
848 curr_DATA_HN_pck_rx = p->copy();
849
851
852 Packet::free(p);
853
854 DATA_rx();
855 }
856 }
857 } else {
858 // Packet is not addressed to me HN
859 if (debug_)
860 std::cout << NOW << " uwUFetch_NODE (" << addr
861 << ") ::Phy2MacEndRx() ---->The packet received is not "
862 "for me HN:"
863 << " DROP IT." << std::endl;
864
865 if (cmh->ptype() == PT_POLL_UFETCH) {
866 // POLL section
867 if (debug_)
868 std::cout << NOW << " uwUFetch_NODE (" << addr
869 << ") ::Phy2MacEndRx() ---->HN has finished to "
870 "receive a"
871 << " POLL packet from the HN with MAC address: "
872 << src_mac_addr << " .DROP IT" << std::endl;
873
874 if (debugMio_)
875 out_file_logging << NOW << "uwUFetch_HEAD_NODE (" << addr
876 << ")::Phy2MacEndRx()________________________"
877 "Finished to rx POLL"
878 << " pck from HN(" << src_mac_addr
879 << "). Not addressed to me: IGNORE IT."
880 << std::endl;
881
883
884 } else if (cmh->ptype() == PT_PROBE_UFETCH) {
885 // BEACON section
886 if (debug_)
887 std::cout << NOW << " uwUFetch_NODE (" << addr
888 << ") ::Phy2MacEndRx() ---->HN has finished to "
889 "receive a"
890 << " PROBE packet from the SENSOR NODE with MAC "
891 "address: "
892 << src_mac_addr << " .DROP IT" << std::endl;
893 if (debugMio_)
894 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
895 << ")::Phy2MacEndRx()________________________"
896 "Finished to rx PROBE"
897 << " pck from SENSOR NODE(" << src_mac_addr
898 << ")." << std::endl;
899
900 if (debugMio_)
901 out_file_logging << NOW << "uwUFetch_HEAD_NODE (" << addr
902 << ")::Phy2MacEndRx()________________________"
903 "Finished to rx PROBE"
904 << " pck from SENSOR NODE(" << src_mac_addr
905 << "). Not addressed to me: IGNORE IT."
906 << std::endl;
907
909
910 } else if (cmh->ptype() == PT_TRIGGER_UFETCH) {
911 // TRIGGER section
912 if (debug_)
913 std::cout << NOW << " uwUFetch_NODE (" << addr
914 << ") ::Phy2MacEndRx() ---->HN has finished to "
915 "receive a"
916 << " TRIGGER packet from the AUV with MAC address ("
917 << src_mac_addr << ").DROP IT" << std::endl;
918
919 if (debugMio_)
920 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
921 << ")::Phy2MacEndRx()________________________"
922 "Finished to rx TRIGGER"
923 << " pck from AUV(" << src_mac_addr
924 << "). Not addressed to me: IGNORE IT."
925 << std::endl;
926
928
929 } else if (cmh->ptype() == PT_CTS_UFETCH) {
930 // CTS section
931 if (debug_)
932 std::cout << NOW << " uwUFetch_NODE (" << addr
933 << ") ::Phy2MacEndRx() ---->HN has finished to "
934 "receive a"
935 << " POLL packet from the HN with MAC address: "
936 << src_mac_addr << " .DROP IT" << std::endl;
937
938 if (debugMio_)
939 out_file_logging << NOW << "uwUFetch_HEAD_NODE (" << addr
940 << ")::Phy2MacEndRx()________________________"
941 "Finished to rx CTS"
942 << " pck from AUV(" << src_mac_addr
943 << "). Not addressed to me: IGNORE IT."
944 << std::endl;
945
947
948 } else {
949 // DATA section
950 if (debug_)
951 std::cout << NOW << " uwUFetch_NODE (" << addr
952 << ") ::Phy2MacEndRx() ---->HN has finished to "
953 "receive a"
954 << " DATA packet from the SENSOR NODE with MAC "
955 "address: "
956 << src_mac_addr << " .DROP IT" << std::endl;
957
958 if (debugMio_)
959 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
960 << ")::Phy2MacEndRx()________________________"
961 "End to rx DATA pck "
962 << "from SN(" << src_mac_addr << ")."
963 << std::endl;
964
965 if (debugMio_)
967 << NOW << "uwUFetch_HEAD_NODE(" << addr
968 << ") ::Phy2MacEndRx()________________________DATA pck"
969 << " rx from SN(" << src_mac_addr
970 << ") is not addressed to me: IGNORE IT." << std::endl;
971 if (debugMio_)
972 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
973 << ")::Phy2MacEndRx()________________________"
974 "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
975 "DDDDDDDDDDDDDDDDDDDDDDDDDD"
976 << std::endl;
977
979 }
980 }
981} // end Phy2MacEndRx_HN();
982
983void
985{
986
987 hdr_cmn *cmh = hdr_cmn::access(p);
988 hdr_mac *mach = HDR_MAC(p);
989 if (cmh->ptype() == PT_BEACON_UFETCH) {
990 // BEACON section
991 if (debug_)
992 std::cout << NOW << " uwUFetch_NODE (" << addr
993 << ") ::Mac2PhyStartTx() ---->MAC layer of the HN passes "
994 "the BEACON"
995 << " packet to his physical layer." << std::endl;
996
997 if (mach->macDA() == -1) {
998 if (debugMio_)
999 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1000 << ")::Mac2PhyStartTx_HN()___________________"
1001 "Start tx of BEACON pck in BROADCAST."
1002 << std::endl;
1003 } else {
1004 if (debugMio_)
1005 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1006 << ")::Mac2PhyStartTx_HN()___________________"
1007 "Start tx of BEACON pck to SENSOR NODE("
1008 << mach->macDA() << ")." << std::endl;
1009 }
1011
1012 MMac::Mac2PhyStartTx(p);
1013
1014 } else if (cmh->ptype() == PT_POLL_UFETCH) {
1015 // POLL section
1016 if (debug_)
1017 std::cout << NOW << " uwUFetch_NODE (" << addr
1018 << ") ::Mac2PhyStartTx() ---->MAC layer of HN passes the "
1019 "POLL"
1020 << " packet to his physical layer." << std::endl;
1021
1022 if (debugMio_)
1023 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1024 << ")::Mac2PhyStartTx_HN()___________________"
1025 "Start tx of POLL pck to the SENSOR NODE("
1026 << mac_addr_NODE_polled << ")." << std::endl;
1027
1029
1030 MMac::Mac2PhyStartTx(p);
1031
1032 } else if (cmh->ptype() == PT_CBEACON_UFETCH) {
1033 // CBEACON section
1034 if (debug_)
1035 std::cout << NOW << " uwUFetch_NODE (" << addr
1036 << ") ::Mac2PhyStartTx() ---->MAC layer of the HN passes "
1037 "the CBEACON"
1038 << " packet to his physical layer." << std::endl;
1039
1040 if (debugMio_)
1041 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1042 << ")::Mac2PhyStartTx_HN()___________________"
1043 "Start tx of CBEACON pck in BROADCAST."
1044 << std::endl;
1045
1047
1048 MMac::Mac2PhyStartTx(p);
1049
1050 } else if (cmh->ptype() == PT_RTS_UFETCH) {
1051 // RTS section
1052 if (debug_)
1053 std::cout << NOW << " uwUFetch_NODE (" << addr
1054 << ") ::Mac2PhyStartTx() ---->MAC layer of the HN passes "
1055 "the RTS"
1056 << " packet to his physical layer." << std::endl;
1057
1058 if (debugMio_)
1059 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1060 << ")::Mac2PhyStartTx_HN()___________________"
1061 "Start tx of RTS pck to the AUV("
1062 << mac_addr_AUV_in_trigger << ")." << std::endl;
1063
1065
1066 MMac::Mac2PhyStartTx(p);
1067
1068 } else {
1069 // DATA section
1070 if (debug_)
1071 std::cout << NOW << " uwUFetch_NODE (" << addr
1072 << ") ::Mac2PhyStartTx() ---->MAC layer of the HN passes "
1073 "the DATA"
1074 << " packet to his physical layer." << std::endl;
1075 if (debugMio_)
1076 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1077 << ")::Mac2PhyStartTx_HN()___________________"
1078 "Start tx of DATA pck"
1079 << " to the AUV(" << mac_addr_AUV_in_CTS << ")."
1080 << std::endl;
1081
1082 if (debugMio_)
1084 << NOW << "uwUFetch_HEAD_NODE(" << addr
1085 << ")::Mac2PhyStartTx_HN()___________________DATA pck"
1086 << " number " << (getDataPckTx_by_HN() + 1) << "."
1087 << std::endl;
1088
1090
1091 Tdata_HN_pck = Mac2PhyTxDuration(p);
1092 // Tdata_HN_pck = Tdata_HN_pck + 0.2;
1094
1095 MMac::Mac2PhyStartTx(p);
1096 }
1097} // end Mac2PhyStartTx_HN();
1098
1106void
1108{
1109
1110 hdr_cmn *cmh = hdr_cmn::access(p);
1111
1112 if (cmh->ptype() == PT_BEACON_UFETCH) {
1113 // BEACON section
1114 if (debug_)
1115 std::cout
1116 << NOW << " uwUFetch_NODE (" << addr
1117 << ") ::Phy2MacEndTx() ---->Physical layer of HN has "
1118 "finished"
1119 << " to transmit a BEACON packet to the NODEs in broadcast."
1120 << std::endl;
1121
1122 if (debugMio_)
1123 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1124 << ")::Phy2MacEndTx()________________________End "
1125 "the tx of BEACON pck in BROADCAST."
1126 << std::endl;
1127 if (debugMio_)
1128 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1129 << ")::Phy2MacEndTx()________________________"
1130 "Total number of BEACON tx "
1131 << getTotalBeaconTx_by_HN() + 1 << "[pck]."
1132 << std::endl;
1133
1137
1138 txBEACONEnabled = false;
1139
1141
1142 } else if (cmh->ptype() == PT_POLL_UFETCH) {
1143 // POLL section
1144 if (debug_)
1145 std::cout << NOW << " uwUFetch_NODE (" << addr
1146 << ") ::Phy2MacEndTx() ---->Physical layer of the HN has "
1147 "finished"
1148 << " to transmit a POLL packet to the NODE with MAC "
1149 "address: "
1150 << mac_addr_NODE_polled << std::endl;
1151
1152 if (debugMio_)
1153 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1154 << ")::Phy2MacEndTx()________________________End "
1155 "the tx of POLL pck to the SENSOR NODE"
1156 << "(" << mac_addr_NODE_polled << ")."
1157 << std::endl;
1158
1160
1163
1164 txPOLLEnabled = false;
1165
1167
1168 } else if (cmh->ptype() == PT_CBEACON_UFETCH) {
1169 // CBEACON section
1170 if (debug_)
1171 std::cout << NOW << " uwUFetch_NODE (" << addr
1172 << ") ::Phy2MacEndTx() ---->Physical layer of the HN has "
1173 "finished"
1174 << " to transmit a CBEACON packet to the NODEs in "
1175 "broadcast."
1176 << std::endl;
1177 if (debugMio_)
1178 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1179 << ")::Phy2MacEndTx()________________________End "
1180 "the tx of CBEACON pck in BROADCAST."
1181 << std::endl;
1182 if (debugMio_)
1183 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1184 << ")::Phy2MacEndTx()________________________"
1185 "Total number of CBEACON tx "
1186 << getTotalCBeaconPckTx_by_HN() + 1 << "[pck]."
1187 << std::endl;
1188
1190
1193
1194 txCBEACONEnabled = false;
1195
1197
1198 } else if (cmh->ptype() == PT_RTS_UFETCH) {
1199 // RTS section
1200 if (debug_)
1201 std::cout
1202 << NOW << " uwUFetch_NODE (" << addr
1203 << ") ::Phy2MacEndTx() ---->Physical layer of the HN has "
1204 "finished"
1205 << " to transmit a RTS packet to the AUV with MAC address: "
1206 << mac_addr_AUV_in_trigger << std::endl;
1207 if (debugMio_)
1208 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1209 << ")::Phy2MacEndTx()________________________End "
1210 "the tx of RTS pck to the AUV("
1211 << mac_addr_AUV_in_trigger << ")." << std::endl;
1212
1214
1217
1218 txRTSEnabled = false;
1219
1221
1222 } else {
1223 // DATA section
1224 if (debug_)
1225 std::cout << NOW << " uwUFetch_NODE (" << addr
1226 << ") ::Phy2MacEndTx() ---->Physical layer of the HN has "
1227 "finished"
1228 << " to transmit a DATA to the AUV with MAC address: "
1229 << mac_addr_AUV_in_CTS << std::endl;
1230
1232
1235
1236 if (debugMio_)
1237 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1238 << ")::Phy2MacEndTx()________________________End "
1239 "the tx of DATA"
1240 << " pck to the AUV(" << mac_addr_AUV_in_CTS
1241 << ")." << std::endl;
1242
1243 if (debugMio_)
1245 << NOW << "uwUFetch_HEAD_NODE(" << addr
1246 << ")::Phy2MacEndTx()________________________DATA pck"
1247 << " number " << getDataPckTx_by_HN() << "." << std::endl;
1248
1249 if (debugMio_)
1250 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1251 << ")::Phy2MacEndTx()________________________"
1252 "Total DATA pck tx by HN("
1253 << addr
1254 << ") to the AUV is: " << getTotalDataPckTx_by_HN()
1255 << "." << std::endl;
1256 if (debugMio_)
1258 << NOW << "uwUFetch_HEAD_NODE(" << addr
1259 << ")::Phy2MacEndTx()________________________**************"
1260 "*****************************************"
1261 << std::endl;
1262
1263 if (debug_)
1264 std::cout << NOW << " uwUFetch_NODE (" << addr
1265 << ") ::Phy2MacEndTx() ---->GET DATA PCK TX BY HN "
1267 << " to transmit a DATA to the AUV with MAC address: "
1268 << mac_addr_AUV_in_trigger << std::endl;
1269
1272 } else {
1274 }
1275 }
1276
1277} // end Phy2MacEndTx_HN();
1278
1279/******************************************************************************
1280 * HEAD NODE *
1281 ******************************************************************************/
1282void
1284{
1290 if (debug_)
1291 std::cout << NOW << " uwUFetch_NODE (" << addr
1292 << ") ::stateIdle_HN() ---->HN before to start the "
1293 "communication with"
1294 << " sensor node or AUV, empty his data queue." << std::endl;
1295
1296 int index_q = 0;
1297 while ((!Q_data.empty()) && (index_q <= MAX_PCK_HN_WANT_RX_FROM_NODE)) {
1298 // Pick up the first element of the queue
1299 curr_DATA_NODE_pck_tx_HN = (Q_data.front())->copy();
1300 // Remove the element from the queue that we have pick up the packet
1301 Q_data.pop();
1302 // Add the packet to the queue of data packets that HN will transmit to
1303 // AUV when
1304 // will be required
1308 index_q++;
1309 }
1310
1311 if (debug_)
1312 std::cout << NOW << " uwUFetch_NODE (" << addr
1313 << ") ::stateIdle_HN() ---->HN is in IDLE STATE" << std::endl;
1314 if (debugMio_)
1315 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1316 << ")::stateIdle_HN()________________________HN is in "
1317 "IDLE STATE"
1318 << std::endl;
1319
1323
1324 rxTRIGGEREnabled = true;
1325
1326 if ((last_reason ==
1328 (last_reason ==
1330 (last_reason ==
1333 if (last_reason ==
1335 /* if (debug_) std::cout << NOW << " uwUFetch_NODE (" << addr << ")
1336 ::stateIdle_HN() ---->HN has analyzed the TRIGGER,"
1337 << " but it hasn't DATA to transmit, so"
1338 << " start immediately the communication with SENSOR
1339 NODES." << std::endl;*/
1340 } else if (last_reason ==
1342 /* if (debug_) std::cout << NOW << " uwUFetch_NODE (" << addr << ")
1343 ::stateIdle_HN() ---->HN has transmitted all his"
1344 << " DATA packets to the AUV, so start immediately the
1345 communication with SENSOR NODES." << std::endl;*/
1346 } else if (last_reason ==
1348 /* if (debug_) std::cout << NOW << " uwUFetch_NODE (" << addr << ")
1349 ::stateIdle_HN() ---->HN has analyzed the TRIGGER,"
1350 << " but it's corrupted, so start immediately the
1351 communication with SENSOR NODES." << std::endl;*/
1352 } else if (last_reason ==
1354 /* if (debug_) std::cout << NOW << " uwUFetch_NODE (" << addr << ")
1355 ::stateIdle_HN() ---->HN has analyzed the TRIGGER,"
1356 << " has transmitted a CTS packet but it has never
1357 received a CTS packet, so start immediately"
1358 << " the communication with SENSOR NODES." << std::endl;*/
1359 }
1360
1361 if (debug_)
1362 std::cout << NOW << " uwUFetch_NODE (" << addr
1363 << ") ::stateIdle_HN() ---->HN before to start the "
1364 "communication"
1365 << " with SENSOR NODES wait an interval time equal to: "
1366 << 15 << "[s]." << std::endl;
1367
1368 CTSrx = false;
1369
1370 txBEACONEnabled = true;
1371 rxTRIGGEREnabled = false;
1372
1374
1375 } else {
1376 if ((!Q_data_HN.empty()) && (Q_data_HN.size() >= 1)) {
1383 if (debug_)
1384 std::cout << NOW << " uwUFetch_NODE (" << addr
1385 << ") ::stateIdle_HN() ---->HN waits a TRIGGER "
1386 "packets from the AUV"
1387 << " for an interval time equal to: "
1389 << " [s] before to start the communication"
1390 << " with the SENSOR NODEs." << std::endl;
1391
1393
1394 } else {
1401 if (debug_)
1402 std::cout << NOW << " uwUFetch_NODE (" << addr
1403 << ") ::stateIdle_HN() ---->HN waits a TRIGGER "
1404 "packets from the AUV"
1405 << " for an interval time equal to: "
1407 << "[s] before to start the communication"
1408 << " with the SENSOR NODEs." << std::endl;
1409
1411 }
1412 }
1413} // end stateIdle_HN();
1414
1415void
1417{
1418
1419 if (debug_)
1420 std::cout << NOW << " uwUFetch_NODE (" << addr
1421 << ") ::BeaconTxTOExpire() ---->HN start the procedure for "
1422 "communicate"
1423 << " with the SENSOR NODEs, reception of TRIGGER packet is "
1424 "not enabled. "
1425 << std::endl;
1426
1427 if (debugMio_)
1428 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1429 << ")::BeaconTxTOExpire()____________________HN start "
1430 "communication with SENSOR_NODE"
1431 << std::endl;
1432
1434
1435 CTSrx = false;
1436
1437 txBEACONEnabled = true;
1438 rxTRIGGEREnabled = false;
1439
1440 int index_q = 0;
1441 while ((!Q_data.empty()) && (index_q <= MAX_PCK_HN_WANT_RX_FROM_NODE)) {
1442 // Pick up the first element of the queue
1443 curr_DATA_NODE_pck_tx_HN = (Q_data.front())->copy();
1444 // Remove the element from the queue that we have pick up the packet
1445 Q_data.pop();
1446 // Add the packet to the queue of data packets that HN will transmit to
1447 // AUV when
1448 // will be required
1452 index_q++;
1453 }
1454
1456
1457} // end BeaconTxTOExpire();
1458
1459void
1461{
1462
1463 if (typeCommunication()) {
1464 // Communication between HN & AUV without RTS and CTS packets
1465
1467 } else {
1468 // Communication between HN & AUV with RTS and CTS packets
1469 if (rxTRIGGEREnabled) {
1470 // HN is enabled to receive a TRIGGER
1471 if (debug_)
1472 std::cout << NOW << " uwUFetch_NODE (" << addr
1473 << ") ::TRIGGER_rx() ---->HN reset the TRIGGER timer"
1474 << std::endl;
1475
1476 if (debugMio_)
1477 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1478 << ")::TRIGGER_rx()_________________________"
1479 "TRIGGER rx It's CORRECT && >= 1 DATA to "
1480 "tx && enabled to rx It."
1481 << std::endl;
1482
1483 if (debugMio_)
1484 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1485 << ")::TRIGGER_rx()__________________________"
1486 "TRIGGER pck rx, extract the parameters."
1487 << std::endl;
1488
1489 BeaconBeforeTx_timer.force_cancel(); // reset the timer in which the
1490 // HN wait a TRIGGER packet
1491
1495
1496 hdr_mac *mach = HDR_MAC(curr_TRIGGER_HN_pck_rx);
1497 hdr_TRIGGER_UFETCH *triggerh =
1499
1500 /*
1501 * Save the header data of the trigger
1502 */
1503
1504 T_min_bck_RTS = (double) triggerh->t_min() /
1505 1000; // Minimum value time before that HN transmit a RTS
1506 // packet
1507 T_max_bck_RTS = (double) triggerh->t_max() /
1508 1000; // Maximum value time before that HN transmit a RTS
1509 // packet
1511 triggerh->max_pck_want_rx(); // Maximum number of DATA
1512 // packet that HN can transmit
1513 // to the AUV
1514
1516 mach->macSA(); // Save the MAC address of the AUV node from
1517 // which the HN has received a trigger packet
1518
1519 if (debugMio_)
1520 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1521 << ")::TRIGGER_rx()__________________________"
1522 "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
1523 "TTTTTTTTTTTTTTTTTTTTTTTTTT"
1524 << std::endl;
1525 if (debugMio_)
1526 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1527 << ")::TRIGGER_rx()__________________________"
1528 "PARAMETERS of TRIGGER PACKET. "
1529 << std::endl;
1530 if (debugMio_)
1531 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1532 << ")::TRIGGER_rx()__________________________"
1533 "Source address: "
1534 << mach->macSA() << "." << std::endl;
1535 if (mach->macDA() == -1) {
1536 if (debugMio_)
1537 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1538 << ")::TRIGGER_rx()_______________________"
1539 "___Destination Address: BROADCAST."
1540 << std::endl;
1541 } else {
1542 if (debugMio_)
1543 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1544 << ")::TRIGGER_rx()_______________________"
1545 "___Destination Address: "
1546 << mach->macDA() << std::endl;
1547 }
1548 if (debugMio_)
1549 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1550 << ")::TRIGGER_rx()__________________________"
1551 "MIN backoff time RTS pck: "
1552 << T_min_bck_RTS << "[s]." << std::endl;
1553 if (debugMio_)
1554 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1555 << ")::TRIGGER_rx()__________________________"
1556 "MAX backoff time RTS pck: "
1557 << T_max_bck_RTS << "[s]." << std::endl;
1558 if (debugMio_)
1559 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1560 << ")::TRIGGER_rx()__________________________"
1561 "MAX DATA pck want rx from HN: "
1562 << max_pck_HN_can_tx << "[pck]." << std::endl;
1563 if (debugMio_)
1564 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1565 << ")::TRIGGER_rx()__________________________"
1566 "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
1567 "TTTTTTTTTTTTTTTTTTTTTTTTTT"
1568 << std::endl;
1569
1570 rxTRIGGEREnabled = false;
1571 txBEACONEnabled = false;
1572
1574 if (debugMio_)
1575 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1576 << ")::TRIGGER_rx()__________________________"
1577 "Backoff timeout choice: "
1578 << bck_before_tx_RTS << "[s]." << std::endl;
1580
1581 } else {
1582 // HN is not enable to receive a TRIGGER packet
1583 if (debug_)
1584 std::cout
1585 << NOW << " uwUFetch_NODE (" << addr
1586 << ") ::TRIGGER_rx() ---->HN is not enabled to receive"
1587 << " the TRIGGER packet: DROP IT." << std::endl;
1588
1589 if (debugMio_)
1590 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1591 << ")::TRIGGER_rx()_________________________"
1592 "TRIGGER rx It's CORRECT && >= 1 DATA to "
1593 "tx && not enabled to rx It:IGNORE It."
1594 << std::endl;
1595
1596 if (debugMio_)
1597 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1598 << ")::TRIGGER_rx()__________________________"
1599 "Not ENABLED"
1600 << " to rx TRIGGER pck." << std::endl;
1602 1,
1604 }
1605 }
1606
1607} // end TRIGGER_rx();
1608
1609void
1611{
1612 if (typeCommunication()) {
1613 // Communication between HN & AUV without RTS and CTS packets
1615 } else {
1616 // Communication between HN & AUV with RTS and CTS packets
1617 if (debug_)
1618 std::cout << NOW << " uwUFetch_NODE (" << addr
1619 << ") ::BCKTOExpired() ---->Back-off timeout is expired:"
1620 << " so the first DATA packet can be transmitted by the "
1621 "HN to the AUV."
1622 << std::endl;
1623
1624 if (debugMio_)
1625 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1626 << ")::BCKTOExpired()________________________"
1627 "Backoff timeout is expired."
1628 << std::endl;
1629
1630 state_RTS_tx();
1631 }
1632} // end BCKTOExpired();
1633
1634void
1636{
1637 // Transmit a RTS packet to the AUV
1638 if (!Q_data_HN.empty()) {
1639 // Queue is not empty so HN has at least one DATA packet to transmit to
1640 // the AUV
1641 if (debug_)
1642 std::cout << NOW << " uwUFetch_NODE (" << addr
1643 << ") ::state_RTS_tx() ---->HN with MAC address " << addr
1644 << " create"
1645 << " a RTS packet that will then transmit to the AUV "
1646 "with MAC address: "
1647 << mac_addr_AUV_in_trigger << std::endl;
1648 if (debugMio_)
1649 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1650 << ")::state_RTS_tx()________________________"
1651 "Initializing RTS pck."
1652 << std::endl;
1653
1657
1658 Packet *p = Packet::alloc();
1659 hdr_cmn *cmh = hdr_cmn::access(p);
1660 hdr_mac *mach = HDR_MAC(p);
1661 hdr_RTS_UFETCH *rtsh = HDR_RTS_UFETCH(p);
1662
1663 cmh->ptype() = PT_RTS_UFETCH;
1664 cmh->size() = sizeof(hdr_RTS_UFETCH);
1665
1666 mach->set(MF_CONTROL, addr, mac_addr_AUV_in_trigger);
1667 mach->macSA() = addr;
1668 mach->macDA() = mac_addr_AUV_in_trigger;
1669
1670 // Filling the HEADER of the RTS packet
1671 rtsh->num_DATA_pcks() = Q_data_HN.size(); // Number of packets that HN
1672 // want to transmit at the AUV
1673 rtsh->backoff_time_RTS() = (int) (bck_before_tx_RTS *
1674 1000); // Back-off timer choice before to transmit a RTS packet
1675
1676 curr_RTS_HN_pck_tx = p->copy();
1677
1678 txRTSEnabled = true;
1679
1680 if (debugMio_)
1681 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1682 << ")::state_RTS_tx()________________________"
1683 "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR"
1684 "RRRRRRRRRRRRRRRRRRRRRR"
1685 << std::endl;
1686 if (debugMio_)
1687 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1688 << ")::state_RTS_tx()________________________"
1689 "PARAMETERS of RTS PACKET. "
1690 << std::endl;
1691 if (debugMio_)
1692 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1693 << ")::state_RTS_tx()________________________"
1694 "Source address: "
1695 << mach->macSA() << "." << std::endl;
1696 if (mach->macDA() == -1) {
1697 if (debugMio_)
1698 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1699 << ")::state_RTS_tx()________________________"
1700 "Destination Address: BROADCAST."
1701 << std::endl;
1702 } else {
1703 if (debugMio_)
1704 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1705 << ")::state_RTS_tx()________________________"
1706 "Destination Address: "
1707 << mac_addr_AUV_in_trigger << "." << std::endl;
1708 }
1709 if (debugMio_)
1710 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1711 << ")::state_RTS_tx()________________________RTS "
1712 "backoff time choice by HN: "
1713 << bck_before_tx_RTS << "[s]." << std::endl;
1714 if (debugMio_)
1715 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1716 << ")::state_RTS_tx()________________________"
1717 "Number of pck HN would like to tx: "
1718 << rtsh->num_DATA_pcks() << "[pck]." << std::endl;
1719 if (debugMio_)
1720 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1721 << ")::state_RTS_tx()________________________"
1722 "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR"
1723 "RRRRRRRRRRRRRRRRRRRRRR"
1724 << std::endl;
1725
1726 Packet::free(p);
1727
1728 RTS_tx();
1729
1730 } else {
1731 // QUEUE is empty, so the HN doesn't transmit a RTS packet to the HN.
1732 if (debug_)
1733 std::cout << NOW << " uwUFetch_NODE (" << addr
1734 << ") ::state_RTS_tx() ----> HN with MAC address" << addr
1735 << " has no DATA"
1736 << " packet to be transmitted to the HN, then ignore the "
1737 "TRIGGER received from the AUV with"
1738 << " MAC address: " << mac_addr_AUV_in_trigger
1739 << ", and return in IDLE STATE." << std::endl;
1740 if (debugMio_)
1741 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1742 << ")::state_RTS_tx()________________________0 "
1743 "DATA pck to tx: NO tx RTS pck."
1744 << std::endl;
1747
1752
1753 txBEACONEnabled = true;
1754 rxTRIGGEREnabled = true;
1755 txRTSEnabled = false;
1756
1757 stateIdle_HN();
1758 }
1759
1760} // end state_RTS_tx();
1761
1762void
1764{
1765 // HN is enabled to transmit RTS packet
1766 if (debug_)
1767 std::cout << NOW << " uwUFetch_NODE (" << addr
1768 << ") ::RTS_tx() ---->HN with MAC address: " << addr
1769 << " is transmitting"
1770 << " a RTS packet to the AUV with MAC address: "
1771 << mac_addr_AUV_in_trigger << std::endl;
1772
1774
1776} // end RTS_tx();
1777
1778void
1780{
1781
1782 if (debug_)
1783 std::cout << NOW << " uwUFetch_NODE (" << addr
1784 << ") ::state_wait_CTS() ---->HN with MAC address: " << addr
1785 << " is"
1786 << " waiting the CTS packet from AUV with MAC address: "
1787 << mac_addr_AUV_in_trigger << ". The maximum"
1788 << " waiting time is: " << T_CTS << std::endl;
1789
1793
1794 if (T_CTS < 0) {
1795 if (debug_)
1796 std::cout << NOW << " uwUFetch_NODE (" << addr
1797 << ") ::state_wait_CTS() ---->CTS timer insert by the "
1798 "user for waiting a CTS"
1799 << " packet is negative, so use the default value 20[s]"
1800 << std::endl;
1801 T_CTS = 20;
1802 }
1803
1804 if (debugMio_)
1805 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1806 << ")::state_wait_CTS()______________________Waiting "
1807 "a CTS pck from AUV("
1808 << mac_addr_AUV_in_trigger << ")." << std::endl;
1809 if (debugMio_)
1810 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1811 << ")::state_wait_CTS()______________________......."
1812 "Waiting CTS pck."
1813 << std::endl;
1814 if (debugMio_)
1815 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1816 << ")::state_wait_CTS()______________________......."
1817 "Waiting CTS pck."
1818 << std::endl;
1819 if (debugMio_)
1820 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1821 << ")::state_wait_CTS()______________________......."
1822 "Waiting CTS pck."
1823 << std::endl;
1824
1825 rxCTSEnabled = true; // enable HN to receive CTS packet
1826
1828
1829} // end state_wait_CTS();
1830
1831void
1833{
1834
1835 /*if (sectionCBeacon) {
1836 if (debug_) std::cout << NOW << " uwUFetch_NODE (" << addr << ")
1837 ::CtsTOExpired() ---->Timeout CTS expired. HN has not receive"
1838 << " CTS packet within the pre-established time interval that is
1839 equal to: " << T_CTS << " [s],"
1840 << " so return in STATE_CBEACON_TX." << std::endl;
1841 if (debugMio_) out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1842 << ")::CtsTOExpired()____________HN CTS timeout expired:0 CTS rx." <<
1843 std::endl;
1844
1845 refreshReason(UWUFETCH_NODE_STATUS_CHANGE_TO_WAIT_CTS_EXPIRED);
1846
1847 n_TRIGGER_pck_rx_by_HN = 0;
1848 n_RTS_pck_tx_by_HN = 0;
1849 n_CTS_pck_rx_by_HN = 0;
1850
1851 rxTRIGGEREnabled = false;
1852 txRTSEnabled = false;
1853 rxCTSEnabled = false;
1854 txDATAEnabledHN = false;
1855 txCBEACONEnabled = true;
1856 sectionCBeacon = true;
1857 txRTSbeforeCBEACON = true;
1858
1859 state_CBEACON_tx();
1860
1861 } else {*/
1862 if (debug_)
1863 std::cout << NOW << " uwUFetch_NODE (" << addr
1864 << ") ::CtsTOExpired() ---->Timeout CTS expired. HN has not "
1865 "receive"
1866 << " CTS packet within the pre-established time interval "
1867 "that is equal to: "
1868 << T_CTS << " [s]."
1869 << " so return in IDLE STATE." << std::endl;
1870 if (debugMio_)
1871 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1872 << ")::CtsTOExpired()________________________CTS "
1873 "timeout EXPIRED."
1874 << std::endl;
1876
1880
1881 txBEACONEnabled = true;
1882 rxPROBEEnabled = false;
1883 txPOLLEnabled = false;
1884 rxDATAEnabled = false;
1885 txCBEACONEnabled = false;
1886 rxTRIGGEREnabled = true;
1887 txRTSEnabled = false;
1888 rxCTSEnabled = false;
1889 txDATAEnabledHN = false;
1890
1891 CTSrx = true;
1892 stateIdle_HN();
1893 //}
1894} // end CtsTOExpired();
1895
1896void
1898{
1899
1900 // if (rxCTSEnabled) {
1901 // HN is enabled to receive a CTS
1902 /* if (sectionCBeacon) {
1903 txRTSbeforeCBEACON = true;
1904 } else { */
1905 CTSrx = true;
1906 //}
1910
1911 hdr_mac *mach = HDR_MAC(curr_CTS_HN_pck_rx);
1913
1914 /*
1915 * Save the header data of the CTS
1916 */
1918 ctsh->num_DATA_pcks_MAX_rx(); // Maximum number of DATA packets that
1919 // the HN can transmit to the AUV
1920
1921 mac_addr_AUV_in_CTS = mach->macSA(); // MAC address of the AUV node from
1922 // which the HN has received a CTS
1923 // packet
1924
1925 rxCTSEnabled = false;
1926 if (debugMio_)
1927 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1928 << ")::CTS_rx()______________________________"
1929 "SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS"
1930 "SSSSSSSSSSSSSSSSSS"
1931 << std::endl;
1932 if (debugMio_)
1933 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1934 << ")::CTS_rx()______________________________"
1935 "PARAMETERS of CTS PACKET. "
1936 << std::endl;
1937 if (debugMio_)
1939 << NOW << "uwUFetch_HEAD_NODE(" << addr
1940 << ")::CTS_rx()______________________________Source address: "
1941 << mach->macSA() << "." << std::endl;
1942 if (mach->macDA() == -1) {
1943 if (debugMio_)
1944 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1945 << ")::CTS_rx()______________________________"
1946 "Destination Address: BROADCAST."
1947 << std::endl;
1948 } else {
1949 if (debugMio_)
1950 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1951 << ")::CTS_rx()______________________________"
1952 "Destination Address: "
1953 << mach->macDA() << "." << std::endl;
1954 }
1955 if (debugMio_)
1956 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1957 << ")::CTS_rx()______________________________DATA pck "
1958 "want rx from HN: "
1959 << max_data_HN_can_tx << "[pck]." << std::endl;
1960 if (debugMio_)
1961 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
1962 << ")::CTS_rx()______________________________"
1963 "SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS"
1964 "SSSSSSSSSSSSSSSSSS"
1965 << std::endl;
1966
1968
1969 /* } else {
1970 //HN is not enable to receive a CTS packet
1971 /*if (sectionCBeacon) {
1972 txRTSbeforeCBEACON = true;
1973 } else {*/
1974 CTSrx = true;
1975 //}
1976 /* if (debug_) std::cout << NOW << " uwUFetch_NODE (" << addr << ")
1977 ::CTS_rx() ---->HN is not enabled to receive"
1978 << " the CTS packet: DROP IT." << std::endl;
1979 if (debugMio_) out_file_logging << NOW << "uwUFetch_HEAD_NODE(" <<
1980 addr << ")::CTS_rx()____________CTS pck rx from AUV("<< <<"). It's not
1981 enabled to rx It." << std::endl;
1982
1983 drop(curr_CTS_HN_pck_rx, 1, UWUFETCH_NODE_DROP_REASON_NOT_ENABLE);
1984 }*/
1985
1986} // end CTS_rx();
1987
1988void
1990{
1991
1992 if (typeCommunication()) {
1993 // Communication between HN & AUV without RTS and CTS packets
1995 } else {
1996 // Communication between HN & AUV with RTS and CTS packets
1997 if (debug_)
1998 std::cout
1999 << NOW << " uwUFetch_NODE (" << addr
2000 << ") ::state_DATA_HN_first_tx() ---->HN will be transmit "
2002 << " DATA packets to the AUV with MAC address: "
2003 << mac_addr_AUV_in_CTS << std::endl;
2004
2005 if (debugMio_)
2006 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2007 << ")::state_DATA_HN_first_tx()______________DATA "
2008 "pck to tx "
2009 << max_data_HN_can_tx << " to the AUV("
2010 << mac_addr_AUV_in_CTS << ")." << std::endl;
2011
2012 if (debug_)
2013 std::cout << NOW << " uwUFetch_NODE (" << addr
2014 << ") ::state_DATA_HN_first_tx() ---->HN is starting "
2015 "transmission of the"
2016 << " FIRST DATA packet to the AUV with MAC address: "
2017 << mac_addr_AUV_in_CTS << std::endl;
2018 if (debugMio_)
2020 << NOW << "uwUFetch_HEAD_NODE(" << addr
2021 << ")::state_DATA_HN_first_tx()______________**************"
2022 "*****************************************"
2023 << std::endl;
2024 if (debugMio_)
2026 << NOW << "uwUFetch_HEAD_NODE(" << addr
2027 << ")::state_DATA_HN_first_tx()______________Initializing"
2028 << " DATA pck number " << (getDataPckTx_by_HN() + 1) << "."
2029 << std::endl;
2030
2031 // Pick up the first element of the queue
2032 curr_DATA_HN_pck_tx = (Q_data_HN.front())->copy();
2033 // Remove the element from the queue that we have pick up
2034 Q_data_HN.pop();
2035
2036 hdr_mac *mach = HDR_MAC(curr_DATA_HN_pck_tx);
2037
2038 mach->set(MF_CONTROL, addr, mac_addr_AUV_in_CTS);
2039 mach->macSA() = addr;
2040 mach->macDA() = mac_addr_AUV_in_CTS;
2041
2052 txDATAEnabledHN = true;
2053
2054 DATA_HN_tx();
2055 }
2056
2057} // end state_DATA_HN_first_tx();
2058
2059void
2061{
2062 if (typeCommunication()) {
2063 // Communication between HN & AUV without RTS and CTS packets
2065 } else {
2066 // Communication between HN & AUV with RTS and CTS packets
2067 // HN is enabled to transmit DATA packet
2068 if (debug_)
2069 std::cout << NOW << " uwUFetch_NODE (" << addr
2070 << ") ::DATA_HN_tx() ---->HN is transmitting a DATA "
2071 "packet to the AUV"
2072 << " with MAC address: " << mac_addr_AUV_in_CTS
2073 << std::endl;
2074
2076
2078 }
2079} // end DATA_HN_tx();
2080
2081void
2083{
2084
2085 if (debug_)
2086 std::cout << NOW << " uwUFetch_NODE (" << addr
2087 << ") ::DataBeforeTxTOExpired() ---->HN can transmit the next"
2088 << " DATA packet." << std::endl;
2089
2091
2092} // end DataBeforeTxTOExpired();
2093
2094void
2096{
2097
2098 if (typeCommunication()) {
2099 // Communication between HN & AUV without RTS and CTS packets
2101 } else {
2102 // Communication between HN & AUV with RTS and CTS packets
2103 if (debug_)
2104 std::cout << NOW << " uwUFetch_NODE (" << addr
2105 << ") ::state_DATA_HN_tx() ---->HN is starting "
2106 "transmission of the"
2107 << " DATA packet number: " << (getDataPckTx_by_HN() + 1)
2108 << " to the AUV with"
2109 << " MAC address: " << mac_addr_AUV_in_CTS << std::endl;
2110 if (debugMio_)
2111 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2112 << ")::state_DATA_HN_tx()____________________*****"
2113 "*************************"
2114 << std::endl;
2115 if (debugMio_)
2116 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2117 << ")::state_DATA_HN_tx()____________________"
2118 "Initializing DATA"
2119 << " pck number " << (getDataPckTx_by_HN() + 1)
2120 << "." << std::endl;
2121
2122 // Pick up the first element of the queue
2123 curr_DATA_HN_pck_tx = (Q_data_HN.front())->copy();
2124 // Remove the element from the queue that we have pick up
2125 Q_data_HN.pop();
2126
2127 hdr_mac *mach = HDR_MAC(curr_DATA_HN_pck_tx);
2128
2129 mach->set(MF_CONTROL, addr, mac_addr_AUV_in_CTS);
2130 mach->macSA() = addr;
2131 mach->macDA() = mac_addr_AUV_in_CTS;
2132 /*hdr_uwmphy_modem* modemh = HDR_UWMPHY_MODEM(curr_DATA_HN_pck_tx);
2133
2134 if ( getDataPckTx_by_HN() == (max_data_HN_can_tx) ) {
2135 modemh->last_packet() = 1;
2136 modemh->use_burst_data() = 1;
2137 } else {
2138 modemh->last_packet() = 0;
2139 modemh->use_burst_data() = 1;
2140 }*/
2141
2142 txDATAEnabledHN = true;
2143
2144 DATA_HN_tx();
2145 }
2146} // end state_DATA_HN_tx();
2147
2148void
2150{
2151
2152 if (typeCommunication()) {
2153 // Communication between HN & AUV without RTS and CTS packets
2155 } else {
2156 // Communication between HN & AUV with RTS and CTS packets
2157 if (debugMio_)
2158 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2159 << ")::state_DATA_HN_finish_tx()_____________End "
2160 "tx DATA pcks to the AUV."
2161 << std::endl;
2162 if (sectionCBeacon) {
2163 // HN has start the communication with AUV before to start the
2164 // transmission of CBEACON packet, so after the end of the
2165 // communication
2166 // with AUV, HN return in state_CBEACON_tx().
2167 if (debug_)
2168 std::cout << NOW << " uwUFetch_NODE (" << addr
2169 << ") ::state_DATA_HN_finish_tx() ---->HN has "
2170 "transmitted all his DATA"
2171 << " packets to the AUV with MAC address: "
2173 << ", so return in STATE_CBEACON_TX()." << std::endl;
2174
2177 sectionCBeacon = false;
2180
2181 txDATAEnabledHN = false;
2182
2184
2185 } else {
2186 // HN has start the communication with AUV when it was in IDLE
2187 // STATE, so after the end of the communication
2188 // with AUV, HN return in stateIdle_HN().
2189 if (debug_)
2190 std::cout << NOW << " uwUFetch_NODE (" << addr
2191 << ") ::state_DATA_HN_finish_tx() ---->HN has "
2192 "transmitted all his DATA"
2193 << " packets to the AUV with MAC address: "
2194 << mac_addr_AUV_in_CTS << ", so return in IDLE STATE."
2195 << std::endl;
2199
2200 txBEACONEnabled = true;
2201 rxTRIGGEREnabled = true;
2202 txDATAEnabledHN = false;
2203
2204 stateIdle_HN();
2205 }
2206 }
2207} // end state_DATA_HN_finish_tx();
2208
2209void
2211{
2212
2213 while (!Q_probbed_mac_HN.empty()) {
2214 Q_probbed_mac_HN.pop();
2217 }
2218
2219 if (debug_)
2220 std::cout << NOW << " uwUFetch_NODE (" << addr
2221 << ") ::state_BEACON_tx() ---->HN is initializing the BEACON "
2222 "packet"
2223 << " which will then transmit to the NODEs in broadcast."
2224 << std::endl;
2225
2226 if (debugMio_)
2227 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2228 << ")::state_BEACON_tx()_____________________"
2229 "Initializing BEACON pck."
2230 << std::endl;
2231
2235
2236 Packet *p = Packet::alloc(); // allocate the memory
2237 hdr_cmn *cmh = hdr_cmn::access(p);
2238 hdr_mac *mach = HDR_MAC(p);
2240
2241 cmh->ptype() = PT_BEACON_UFETCH; // type of the packet
2242
2243 mach->set(MF_CONTROL, addr, MAC_BROADCAST); // set the information of the
2244 // packet (type,source
2245 // address,destination address)
2246 mach->macSA() = addr; // set the source address as AUV MAC address
2247 mach->macDA() =
2248 MAC_BROADCAST; // set the destination address as BROADCAST address
2249
2250 beaconh->t_min_bc() =
2251 (int) (T_MIN_BACKOFF_PROBE * 1000); // minimum value for to choose
2252 // the back-off time for tx
2253 // PROBE pck
2254 beaconh->t_max_bc() =
2255 (int) (T_MAX_BACKOFF_PROBE * 1000); // maximum value for to choose
2256 // the back-off time for tx
2257 // PROBE pck
2258 beaconh->num_Max_CBEACON_tx_by_HN() =
2259 MAX_ALLOWED_CBEACON_TX; // maximum number of CBEACON tx by this HN
2260 cmh->size() =
2261 sizeof(hdr_BEACON_UFETCH); // set the size of BEACON header packet
2262
2263 if (debugMio_)
2264 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2265 << ")::state_BEACON_tx()_____________________"
2266 "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
2267 "BBBBBBBBBBBBBBBBBB"
2268 << std::endl;
2269 if (debugMio_)
2270 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2271 << ")::state_BEACON_tx()_____________________"
2272 "PARAMETERS of BEACON pck."
2273 << std::endl;
2274 if (debugMio_)
2276 << NOW << "uwUFetch_HEAD_NODE(" << addr
2277 << ")::state_BEACON_tx()_____________________Source address: "
2278 << mach->macSA() << "." << std::endl;
2279 if (mach->macDA() == -1) {
2280 if (debugMio_)
2281 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2282 << ")::state_BEACON_tx()_____________________"
2283 "Destination address: BROADCAST."
2284 << std::endl;
2285 } else {
2286 if (debugMio_)
2287 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2288 << ")::state_BEACON_tx()_____________________"
2289 "Destination address: "
2290 << mach->macDA() << "." << std::endl;
2291 }
2292 if (debugMio_)
2293 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2294 << ")::state_BEACON_tx()_____________________MIN "
2295 "backoff time PROBE pck: "
2296 << T_MIN_BACKOFF_PROBE << " [s]." << std::endl;
2297 if (debugMio_)
2298 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2299 << ")::state_BEACON_tx()_____________________MAX "
2300 "backoff time PROBE pck: "
2301 << T_MAX_BACKOFF_PROBE << " [s]." << std::endl;
2302 if (debugMio_)
2303 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2304 << ")::state_BEACON_tx()_____________________MAX "
2305 "number of CBEACON that HN will tx: "
2306 << beaconh->num_Max_CBEACON_tx_by_HN() << std::endl;
2307 if (debugMio_)
2308 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2309 << ")::state_BEACON_tx()_____________________Size of "
2310 "BEACON pck: "
2311 << cmh->size() << "[byte]." << std::endl;
2312 if (debugMio_)
2313 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2314 << ")::state_BEACON_tx()_____________________"
2315 "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
2316 "BBBBBBBBBBBBBBBBBB"
2317 << std::endl;
2318
2319 curr_BEACON_HN_pck_tx = p->copy(); // create a copy of the BEACON packet
2320
2321 /*hdr_uwmphy_modem* modemh = HDR_UWMPHY_MODEM(curr_BEACON_HN_pck_tx);
2322 modemh->use_burst_data() = 0;
2323 */
2324 Packet::free(p); // de-allocate the memory
2325
2326 BEACON_tx(); // recall the function that simulate the transmission of the
2327 // BEACON
2328
2329} // end state_BEACON_tx();
2330
2331void
2333{
2334
2335 if (debug_)
2336 std::cout << NOW << " uwUFetch_NODE (" << addr
2337 << ") ::BEACON_tx() ---->HN is transmitting a BEACON packet"
2338 << " to the NODEs in broadcast." << std::endl;
2339
2341 // that the protocol
2342 // state change
2343
2345
2346} // end BEACON_tx();
2347
2348void
2350{
2351
2352 if (debug_)
2353 std::cout << NOW << " uwUFetch_NODE (" << addr
2354 << ") ::state_PROBE_wait() ---->HN is scheduling PROBE TIMER "
2355 "T= "
2356 << T_PROBE << "[s]" << std::endl;
2357
2361
2362 if (T_PROBE < 0) {
2363 if (debug_)
2364 std::cout << NOW << " uwUFetch_NODE (" << addr
2365 << ") ::state_wait_PROBE() ---->The waiting time for "
2366 "PROBE packets is negative"
2367 << " so set the default value: 15[s]." << std::endl;
2368 T_PROBE = 15;
2369 }
2370 if (debugMio_)
2371 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2372 << ")::state_wait_PROBE()____________________Waiting "
2373 "PROBE pck from"
2374 " SENSOR NODES."
2375 << std::endl;
2376 if (debugMio_)
2377 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2378 << ")::state_wait_PROBE()____________________Timeout "
2379 "within rx PROBE"
2380 << " pcks " << T_PROBE << "[s]." << std::endl;
2381 if (debugMio_)
2383 << NOW << "uwUFetch_HEAD_NODE(" << addr
2384 << ")::state_wait_PROBE()____________________....waiting PROBE"
2385 << std::endl;
2386 if (debugMio_)
2388 << NOW << "uwUFetch_HEAD_NODE(" << addr
2389 << ")::state_wait_PROBE()____________________....waiting PROBE"
2390 << std::endl;
2391 if (debugMio_)
2393 << NOW << "uwUFetch_HEAD_NODE(" << addr
2394 << ")::state_wait_PROBE()____________________....waiting PROBE"
2395 << std::endl;
2396
2397 rxPROBEEnabled = true;
2398
2400
2401} // end state_wait_PROBE();
2402
2403void
2405{
2406
2407 if (debug_)
2408 std::cout << NOW << " uwUFetch_NODE (" << addr
2409 << ") ::ProbeTOExpired() ---->PROBE timeout is expired: other"
2410 << " PROBE packets can not be received by the HN."
2411 << std::endl;
2412
2413 if (debugMio_)
2414 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2415 << ")::ProbeTOExpired()______________________PROBE "
2416 "timeout expired."
2417 << std::endl;
2418
2419 if ((Q_probbed_mac_HN.empty()) &&
2421
2422 if (debug_)
2423 std::cout << NOW << " uwUFetch_NODE (" << addr
2424 << ") ::ProbeTOExpired() ---->HN has received 0 PROBE "
2425 "packets and"
2426 << " it has reached the maximum number of attempts to "
2427 "transmit CBEACON packets."
2428 << std::endl;
2429
2430 if (debugMio_)
2431 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2432 << ")::ProbeTOExpired()______________________0 "
2433 "PROBE rx && MAX CBEACON tx."
2434 << std::endl;
2435
2438
2440 0; // reset the number of BEACON packet transmitted by the HN
2442 0; // reset the number of PROBE packet received by the HN
2444 0; // reset the number of POLL packet transmitted by the HN
2446 0; // reset the number of DATA packet received by the HN
2448 0; // reset the number of CBEACON packet transmitted by the HN
2449
2450 rxPROBEEnabled = false;
2451 txBEACONEnabled = true;
2452 rxTRIGGEREnabled = true;
2453
2454 stateIdle_HN();
2455
2456 } else if ((Q_probbed_mac_HN.empty()) &&
2458
2459 if (debug_)
2460 std::cout << NOW << " uwUFetch_NODE (" << addr
2461 << ") ::ProbeTOExpired() ---->HN has received 0 PROBE "
2462 "packet and it"
2463 << " has not reached the maximum number of attempts to "
2464 "transmit CBEACON packets"
2465 << " that is: " << MAX_ALLOWED_CBEACON_TX << std::endl;
2466
2467 if (debugMio_)
2468 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2469 << ")::ProbeTOExpired()______________________0 "
2470 "PROBE rx && another CBEACON can be tx."
2471 << std::endl;
2472
2474 0; // reset the number of PROBE packet received by the HN
2476 0; // reset the number of POLL packet transmitted by the HN
2478 0; // reset the number of DATA packet received by the HN
2479
2480 rxPROBEEnabled = false;
2481 txCBEACONEnabled = true;
2482
2485
2487
2488 } else {
2489
2490 if (debug_)
2491 std::cout << NOW << " uwUFetch_NODE (" << addr
2492 << ") ::ProbeTOExpired() ---->HN has received "
2493 << (Q_probbed_mac_HN.size())
2494 << " PROBE packets, so start a new transmission of POLL "
2495 "packet."
2496 << std::endl;
2497
2498 if (debugMio_)
2499 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2500 << ")::ProbeTOExpired()______________________The "
2501 "number of PROBE rx is "
2502 << getProbePckRx_HN() << "." << std::endl;
2503
2505 0; // reset the number of DATA packet received by the HN
2506
2507 rxPROBEEnabled = false;
2508
2511
2512 state_POLL_tx();
2513 }
2514} // end ProbeTOExpire();
2515
2516void
2518{
2519 // HN is enabled to receive a PROBE packet
2520
2521 hdr_mac *mach = HDR_MAC(curr_PROBE_HN_pck_rx);
2523
2527
2534 Q_probbed_mac_HN.push(
2535 mach->macSA()); // store the MAC address of the NODE that
2536 // has sent the PROBE packet to the HN
2538 probeh->n_DATA_pcks_Node_tx()); // store the number of packets that
2539 // the NODE want to tx at
2540 // the HN
2541 Q_probbed_backoff_time.push((double) probeh->backoff_time_PROBE() /
2542 1000); // store the back-off time choice by the NODE before
2543 // to transmit the PROBE packet
2544
2545 if (debugMio_)
2546 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2547 << ")::PROBE_rx()____________________________PROBE "
2548 "pck rx number: "
2549 << getProbePckRx_HN() << ". Extract parameters."
2550 << std::endl;
2551 if (debugMio_)
2552 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2553 << ")::PROBE_rx()____________________________"
2554 "PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP"
2555 "PPPPPPPPPPPPPPPPPP"
2556 << std::endl;
2557 if (debugMio_)
2558 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2559 << ")::PROBE_rx()____________________________"
2560 "PARAMETERS OF PROBE PCK."
2561 << std::endl;
2562 if (debugMio_)
2564 << NOW << "uwUFetch_HEAD_NODE(" << addr
2565 << ")::PROBE_rx()____________________________Source address: "
2566 << mach->macSA() << std::endl;
2567 if (debugMio_)
2568 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2569 << ")::PROBE_rx()____________________________"
2570 "Destination address: "
2571 << mach->macDA() << std::endl;
2572 if (debugMio_)
2573 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2574 << ")::PROBE_rx()____________________________DATA pck "
2575 "would be tx SN: "
2576 << probeh->n_DATA_pcks_Node_tx() << "[pck]."
2577 << std::endl;
2578 if (debugMio_)
2579 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2580 << ")::PROBE_rx()____________________________Backoff "
2581 "time choice before tx PROBE: "
2582 << (double) probeh->backoff_time_PROBE() / 1000
2583 << "[s]." << std::endl;
2584 if (debugMio_)
2585 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2586 << ")::PROBE_rx()____________________________"
2587 "PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP"
2588 "PPPPPPPPPPPPPPPPPP"
2589 << std::endl;
2590
2591 Packet::free(curr_PROBE_HN_pck_rx);
2592
2593 if (Q_probbed_mac_HN.size() == MAX_POLLED_NODE) {
2594 // MAXIMUM number of PROBE packet is received by the HN
2595
2596 if (debug_)
2597 std::cout << NOW << " uwUFetch_NODE (" << addr
2598 << ") ::PROBE_Rx() ---->HN has received the maximum "
2599 "number of PROBE"
2600 << " packets and the timeout is not expired. Consequence "
2601 "of that, the HN with MAC address: "
2602 << addr << " can"
2603 << " not receive other PROBEs packets." << std::endl;
2604
2605 if (debug_)
2606 std::cout << NOW << " uwUFetch_NODE (" << addr
2607 << ") ::PROBE_Rx() ---->HN reset the PROBE timer"
2608 << " and start the transmission of POLL packets."
2609 << std::endl;
2610
2611 if (debugMio_)
2612 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2613 << ")::PROBE_rx()____________________________MAX "
2614 "number of PROBE pck rx: reset PROBE timeout."
2615 << std::endl;
2616
2617 PROBE_timer.force_cancel();
2618
2619 rxPROBEEnabled = false;
2620
2623
2624 state_POLL_tx();
2625
2626 } else {
2627 // Timeout is not expire and thus wait other PROBE packets
2628 if (debug_)
2629 std::cout << NOW << " uwUFetch_NODE (" << addr
2630 << ") ::PROBE_Rx() ---->Timeout is not expired and "
2631 "another PROBE"
2632 << " packet can be received by the HN with MAC address: "
2633 << addr << " from other NODEs." << std::endl;
2634
2636 }
2637
2638} // end PROBE_rx();
2639
2640void
2642{
2643
2644 if (debug_)
2645 std::cout << NOW << " uwUFetch_NODE (" << addr
2646 << ") ::state_wait_other_PROBE() ---->HN is waiting the "
2647 "reception of"
2648 << " PROBE packet number: " << (Q_probbed_mac_HN.size() + 1)
2649 << std::endl;
2650
2651 if (debugMio_)
2652 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2653 << ")::state_wait_other_PROBE()______________Waiting "
2654 "another PROBE pck from"
2655 " SENSOR NODES."
2656 << std::endl;
2657 if (debugMio_)
2659 << NOW << "uwUFetch_HEAD_NODE(" << addr
2660 << ")::state_wait_other_PROBE()______________PROBE number "
2661 << getProbePckRx_HN() + 1 << "." << std::endl;
2662
2663 if (debugMio_)
2664 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2665 << ")::state_wait_other_PROBE()______________...."
2666 "waiting another PROBE."
2667 << std::endl;
2668 if (debugMio_)
2669 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2670 << ")::state_wait_other_PROBE()______________...."
2671 "waiting another PROBE."
2672 << std::endl;
2673 if (debugMio_)
2674 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2675 << ")::state_wait_other_PROBE()______________...."
2676 "waiting another PROBE."
2677 << std::endl;
2678
2682
2683} // end state_wait_other_PROBE();
2684
2685void
2687{
2688
2689 if (debug_)
2690 std::cout
2691 << NOW << " uwUFetch_NODE (" << addr
2692 << ") ::state_POLL_tx() ---->HN is creating a POLL packet that"
2693 << " will then transmit at the first node of the queue that "
2694 "contain the PROBEs received. "
2695 << std::endl;
2696
2697 if (debugMio_)
2698 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2699 << ")::state_POLL_tx()_______________________"
2700 "Initializing POLL pck."
2701 << std::endl;
2702
2706
2707 Packet *p = Packet::alloc();
2708 hdr_cmn *cmh = hdr_cmn::access(p);
2709 hdr_mac *mach = HDR_MAC(p);
2710 hdr_POLL_UFETCH *pollh = HDR_POLL_UFETCH(p);
2711
2712 cmh->ptype() = PT_POLL_UFETCH;
2713 cmh->size() = sizeof(hdr_POLL_UFETCH);
2714
2715 mach->set(MF_CONTROL, addr, Q_probbed_mac_HN.front());
2716 mach->macSA() = addr;
2717 mach->macDA() = Q_probbed_mac_HN.front();
2718
2719 // Filling the HEADER of the POLL packet
2722 pollh->num_DATA_pcks_MAX_rx() =
2723 Q_probbed_n_pcks_NODE_want_tx_HN.front(); // Maximum number of
2724 // DATA packets that
2725 // the HN want to
2726 // receive from the NODE that is being to poll
2727 } else {
2728 pollh->num_DATA_pcks_MAX_rx() =
2729 MAX_PCK_HN_WANT_RX_FROM_NODE; // Maximum numbero of DATA packets
2730 // that the HN want to
2731 // receive from the NODE that is being to poll
2732 }
2734 pollh->mac_addr_Node_polled() =
2735 Q_probbed_mac_HN.front(); // Mac address of the NODE that the HN is
2736 // being to poll
2737 mac_addr_NODE_polled = Q_probbed_mac_HN.front(); // Store the mac address of
2738 // the NODE that the HN is
2739 // being
2740 // to poll
2741
2742 if (debugMio_)
2743 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2744 << ")::state_POLL_tx()_______________________"
2745 "LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL"
2746 "LLLLLLLLLLLLLLLLLL"
2747 << std::endl;
2748 if (debugMio_)
2749 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2750 << ")::state_POLL_tx()_______________________"
2751 "PARAMETERS OF POLL PCK."
2752 << std::endl;
2753 if (debugMio_)
2755 << NOW << "uwUFetch_HEAD_NODE(" << addr
2756 << ")::state_POLL_tx()_______________________Source address: "
2757 << mach->macSA() << std::endl;
2758 if (debugMio_)
2759 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2760 << ")::state_POLL_tx()_______________________"
2761 "Destination address: "
2762 << mach->macDA() << std::endl;
2763 if (debugMio_)
2764 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2765 << ")::state_POLL_tx()_______________________DATA pck "
2766 "want rx from SN: "
2767 << number_data_pck_HN_rx_exact << "[pck]."
2768 << std::endl;
2769 if (debugMio_)
2771 << NOW << "uwUFetch_HEAD_NODE(" << addr
2772 << ")::state_POLL_tx()_______________________Size of POLL pck: "
2773 << cmh->size() << "[byte]." << std::endl;
2774 if (debugMio_)
2775 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2776 << ")::state_POLL_tx()_______________________"
2777 "LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL"
2778 "LLLLLLLLLLLLLLLLLL"
2779 << std::endl;
2780
2781 curr_POLL_HN_pck_tx = p->copy();
2782
2783 /*hdr_uwmphy_modem* modemh = HDR_UWMPHY_MODEM(curr_POLL_HN_pck_tx);
2784 modemh->use_burst_data() = 0;*/
2785
2786 Packet::free(p); // de-allocate the memory
2787
2788 txPOLLEnabled = true;
2789
2790 POLL_tx();
2791} // end state_POLL_tx();
2792
2793void
2795{
2796
2797 if (debug_)
2798 std::cout << NOW << " uwUFetch_NODE (" << addr
2799 << ") ::POLL_tx() ---->HN is transmitting a POLL packet to "
2800 "the NODE with MAC"
2801 << " address: " << mac_addr_NODE_polled << std::endl;
2802
2804 // that the protocol
2805 // state change
2806
2808
2810
2811} // end POLL_tx();
2812
2813void
2815{
2816
2817 if (debug_)
2818 std::cout << NOW << " uwUFetch_NODE (" << addr
2819 << ") ::state_wait_first_DATA() ---->HN is waiting to "
2820 "receive the FIRST DATA"
2821 << " packet from the NODE with MAC address: "
2822 << mac_addr_NODE_polled << std::endl;
2823
2827
2828 data_timeout = getDataTimerValue(); // Compute the timeout interval within
2829 // HN want to receive all DATA packets
2830 // from NODE
2831
2832 if (debug_)
2833 std::cout << NOW << " uwUFetch_NODE (" << addr
2834 << ") ::state_wait_first_DATA() ---->HN want to receive all "
2835 "the DATA packets"
2836 << " from the NODE with MAC address: " << mac_addr_NODE_polled
2837 << " within "
2838 << " an interval time: " << data_timeout << "[s]."
2839 << std::endl;
2840
2841 if (debugMio_)
2842 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2843 << ")::state_wait_first_DATA()_______________Waiting "
2844 "DATA pck number "
2845 << (getDataPckRx_by_HN() + 1) << "."
2846 << " from SN(" << mac_addr_NODE_polled << ")."
2847 << std::endl;
2848 if (debugMio_)
2849 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2850 << ")::state_wait_first_DATA()_______________Timeout "
2851 "within rx all DATA"
2852 << " pcks: " << data_timeout << "[s]." << std::endl;
2853
2854 if (debugMio_)
2855 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2856 << ")::state_wait_first_DATA()_______________......."
2857 "Waiting DATA"
2858 << std::endl;
2859 if (debugMio_)
2860 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2861 << ")::state_wait_first_DATA()_______________......."
2862 "Waiting DATA"
2863 << std::endl;
2864 if (debugMio_)
2865 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2866 << ")::state_wait_first_DATA()_______________......."
2867 "Waiting DATA"
2868 << std::endl;
2869
2870 rxDATAEnabled = true;
2871
2873
2874} // end state_wait_first_DATA();
2875
2876void
2878{
2879
2880 if (debug_)
2881 std::cout << NOW << " uwUFetch_NODE (" << addr
2882 << ") ::state_wait_other_DATA() ---->HN is waiting the DATA "
2883 "packet number: "
2884 << (getDataPckRx_by_HN() + 1)
2885 << " from the NODE with MAC address: " << mac_addr_NODE_polled
2886 << std::endl;
2887
2888 if (debugMio_)
2889 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2890 << ")::state_wait_other_DATA()_______________Waiting "
2891 "DATA packet number: "
2892 << (getDataPckRx_by_HN() + 1) << ""
2893 << " from SENSOR NODE (" << mac_addr_NODE_polled
2894 << ")." << std::endl;
2895
2899
2900 txBEACONEnabled = false;
2901 rxPROBEEnabled = false;
2902 txPOLLEnabled = false;
2903 rxDATAEnabled = true;
2904 txCBEACONEnabled = false;
2905 rxTRIGGEREnabled = false;
2906 txRTSEnabled = false;
2907 rxCTSEnabled = false;
2908 txDATAEnabledHN = false;
2909
2910} // end state_wait_other_DATA();
2911
2912void
2914{
2915
2916 if (debug_)
2917 std::cout << NOW << " uwUFetch_NODE (" << addr
2918 << ") ::DataTOExpired() ---->HN has received from the NODE "
2919 "with MAC"
2920 << " address: " << mac_addr_NODE_polled << " only "
2921 << getDataPckRx_by_HN() << " packets." << std::endl;
2922
2923 if (debugMio_)
2924 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2925 << ")::DataTOExpired()_______________________DATA "
2926 "timeout is expired other DATA packets"
2927 << " can not be rx from SENSOR NODE ("
2928 << mac_addr_NODE_polled << ")." << std::endl;
2929
2931 // reason for
2932 // the changing
2933 // of the state
2934
2935 rxDATAEnabled = false;
2936 updateListProbbedNode(); // Remove the NODE that has already transmit his
2937 // data packet
2938
2939 // Verify if another node can be polled, or the HN will start the
2940 // transmission of CBEACON
2941 if ((Q_probbed_mac_HN.empty()) &&
2943 // There aren't another node to poll, and the maximum number of CBEACONS
2944 // are transmitted
2945 if (debug_)
2946 std::cout << NOW << " uwUFetch_NODE (" << addr
2947 << ") ::DataTOExpired() ---->HN has not other nodes to "
2948 "POLL, and"
2949 << " a CBEACON packet can not be transmitted: return in "
2950 "IDLE STATE."
2951 << std::endl;
2952
2953 if (debugMio_)
2955 << NOW << "uwUFetch_HEAD_NODE(" << addr
2956 << ")::DataTOExpired()_______________________0 SENSOR NODE "
2957 "to polled && MAX CBEACON can be tx."
2958 << std::endl;
2959
2965
2966 txBEACONEnabled = true;
2967 rxPROBEEnabled = false;
2968 txPOLLEnabled = false;
2969 rxDATAEnabled = false;
2970 txCBEACONEnabled = false;
2971 rxTRIGGEREnabled = true;
2972 txRTSEnabled = false;
2973 rxCTSEnabled = false;
2974 txDATAEnabledHN = false;
2975
2978
2979 stateIdle_HN();
2980
2981 } else if ((Q_probbed_mac_HN.empty()) &&
2983 // There aren't another node to poll, and the maximum number of CBEACONS
2984 // are not transmitted
2985 if (debug_)
2986 std::cout << NOW << " uwUFetch_NODE (" << addr
2987 << ") ::DataTOExpired() ---->HN has not other nodes to "
2988 "POLL, but"
2989 << " a CBEACON packet can be transmitted: transmit a "
2990 "CBEACON"
2991 << std::endl;
2992
2993 if (debugMio_)
2994 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
2995 << ")::DataTOExpired()_______________________0 "
2996 "SENSOR NODE to polled && CBEACON can be tx."
2997 << std::endl;
2998
3002
3003 txBEACONEnabled = false;
3004 rxPROBEEnabled = false;
3005 txPOLLEnabled = false;
3006 rxDATAEnabled = false;
3007 txCBEACONEnabled = false;
3008 rxTRIGGEREnabled = false;
3009 txRTSEnabled = false;
3010 rxCTSEnabled = false;
3011 txDATAEnabledHN = false;
3012
3015
3017
3018 } else {
3019 // There are another nodes to poll
3020 if (debug_)
3021 std::cout
3022 << NOW << " uwUFetch_NODE (" << addr
3023 << ") ::DataTOExpired() ---->HN has other nodes to polled."
3024 << std::endl;
3025
3026 if (debugMio_)
3027 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3028 << ")::DataTOExpired()_______________________"
3029 "Another SENSOR NODE can be polled."
3030 << std::endl;
3031
3034
3035 txBEACONEnabled = false;
3036 rxPROBEEnabled = false;
3037 txPOLLEnabled = false;
3038 rxDATAEnabled = false;
3039 txCBEACONEnabled = false;
3040 rxTRIGGEREnabled = false;
3041 txRTSEnabled = false;
3042 rxCTSEnabled = false;
3043 txDATAEnabledHN = false;
3044
3047
3048 state_POLL_tx();
3049 }
3050} // end DataTOExpired();
3051
3052void
3054{
3055
3056 if (rxDATAEnabled) {
3057
3058 hdr_mac *mach = HDR_MAC(curr_DATA_HN_pck_rx);
3059
3063
3070 mac_addr_NODE_in_data = mach->macSA(); // Source MAC address of the NODE
3071 // that has transmitted the DATA
3072 // packet to the HN
3073
3074 if (debugMio_)
3075 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3076 << ")::DATA_rx()_____________________________DATA "
3077 "pck rx from SN("
3078 << mach->macSA() << ")"
3079 << " is passed to the APP layer." << std::endl;
3080 if (debugMio_)
3081 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3082 << ")::DATA_rx()_____________________________DATA "
3083 "pck rnumber "
3084 << getDataPckRx_by_HN() << "." << std::endl;
3085 if (debugMio_)
3086 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3087 << ")::DATA_rx()_____________________________"
3088 "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
3089 "DDDDDDDDDDDDDDDDDDDDDD"
3090 << std::endl;
3091
3092 if (debug_)
3093 std::cout << NOW << " uwUFetch_NODE (" << addr
3094 << ") ::DATA_Rx() ---->HN has received the DATA packet"
3095 << " number: " << getDataPckRx_by_HN()
3096 << " from the NODE with"
3097 << " MAC address: " << mac_addr_NODE_in_data << "."
3098 << std::endl;
3099
3100 // save the data packet in the QUEUE of the HN
3101 Q_data_HN.push(curr_DATA_HN_pck_rx->copy()); // Save the data packets in
3102 // the QUEUE of the HN
3103
3104 Packet::free(curr_DATA_HN_pck_rx);
3105
3107 // Another DATA packet can not be received by the HN
3108 if (debug_)
3109 std::cout << NOW << " uwUFetch_NODE (" << addr
3110 << ") ::DATA_rx() ---->HN has received the LAST DATA "
3111 "packet from NODE"
3112 << " with MAC address: " << mac_addr_NODE_in_data
3113 << std::endl;
3114
3115 if (debugMio_)
3116 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3117 << ")::DATA_rx()_____________________________"
3118 "All DATA pcks"
3119 << " were rx from SN(" << mac_addr_NODE_in_data
3120 << ")." << std::endl;
3121
3123
3124 if (debug_)
3125 std::cout << NOW << " uwUFetch_NODE (" << addr
3126 << ") ::DATA_rx() ---->HN reset DATA timer"
3127 << std::endl;
3128 if (debugMio_)
3129 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3130 << ")::DATA_rx()_____________________________"
3131 "Reset DATA Timeout."
3132 << std::endl;
3133 DATA_timer.force_cancel(); // reset the timer
3134
3135 updateListProbbedNode(); // Remove the NODE that has already
3136 // transmit his data packet
3137
3138 // Verify if another node can be polled, or the HN will start the
3139 // transmission of CBEACON
3140 if ((Q_probbed_mac_HN.empty()) &&
3142 // There aren't another node to poll, and the maximum number of
3143 // CBEACONS are transmitted
3144 if (debug_)
3145 std::cout << NOW << " uwUFetch_NODE (" << addr
3146 << ") ::DATA_rx() ---->HN has not other nodes to "
3147 "POLL, and"
3148 << " a CBEACON packet can not be transmitted: "
3149 "return in IDLE STATE."
3150 << std::endl;
3151
3152 if (debugMio_)
3154 << NOW << "uwUFetch_HEAD_NODE(" << addr
3155 << ")::DATA_rx()_____________________________0 SNs "
3156 "to polled && MAX CBEACON is tx."
3157 << std::endl;
3158
3164
3165 txBEACONEnabled = true;
3166 rxDATAEnabled = false;
3167 rxTRIGGEREnabled = true;
3168
3171
3172 stateIdle_HN();
3173
3174 } else if ((Q_probbed_mac_HN.empty()) &&
3176 // There aren't another node to poll, and the maximum number of
3177 // CBEACONS are not transmitted
3178 if (debug_)
3179 std::cout << NOW << " uwUFetch_NODE (" << addr
3180 << ") ::DATA_rx() ---->HN has not other nodes to "
3181 "POLL, but"
3182 << " a CBEACON packet can be transmitted: "
3183 "transmit a CBEACON"
3184 << std::endl;
3185
3186 if (debugMio_)
3188 << NOW << "uwUFetch_HEAD_NODE(" << addr
3189 << ")::DATA_rx()_____________________________0 SNs "
3190 "to polled && another CBEACON can be tx."
3191 << std::endl;
3192
3196
3197 rxDATAEnabled = false;
3198 txCBEACONEnabled = true;
3199
3202
3204
3205 } else {
3206 // There are another nodes to poll
3207 if (debug_)
3208 std::cout << NOW << " uwUFetch_NODE (" << addr
3209 << ") ::DATA_rx() ---->HN has other nodes to "
3210 "polled."
3211 << std::endl;
3212
3213 if (debugMio_)
3214 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3215 << ")::DATA_rx()__________________________"
3216 "___Another SNs can be polled."
3217 << std::endl;
3218
3220
3221 rxDATAEnabled = false;
3222 txPOLLEnabled = true;
3223
3226
3227 state_POLL_tx();
3228 }
3229
3230 } else {
3231 // Another DATA packet can be received by the HN
3232
3233 if (debug_)
3234 std::cout
3235 << NOW << " uwUFetch_NODE (" << addr
3236 << ") ::DATA_rx() ---->HN wait an another DATA packet,"
3237 << " the number: " << (getDataPckRx_by_HN() + 1)
3238 << ", from NODE with MAC "
3239 << " address: " << mac_addr_NODE_in_data << std::endl;
3240
3241 rxDATAEnabled = true;
3243 }
3244 } else {
3245 // HN is not enabled to receive a DATA packet
3246 if (debugMio_)
3247 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3248 << ")::DATA_rx()_____________________________Not "
3249 "enabled to rx DATA pcks."
3250 << std::endl;
3251
3252 if (debug_)
3253 std::cout << NOW << " uwUFetch_NODE (" << addr
3254 << ") DATA_rx() ---->HN(" << addr
3255 << ") is not enabled to receive the DATA"
3256 << " packet: DROP IT." << std::endl;
3257
3259 }
3260} // end DATA_rx();
3261
3262void
3264{
3265
3266 while (!Q_probbed_mac_HN.empty()) {
3267 Q_probbed_mac_HN.pop();
3270 }
3271 // HN transmit a CBEACON packet to the sensor nodes
3272
3273 if (debug_)
3274 std::cout << NOW << " uwUFetch_NODE (" << addr
3275 << ") ::state_CBEACON_tx() ---->HN is initializing the "
3276 "CBEACON packet"
3277 << " which will then transmit to the NODEs in broadcast. "
3278 << std::endl;
3279
3280 if (debugMio_)
3281 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3282 << ")::state_CBEACON_tx()____________________"
3283 "Initializing CBEACON pck number "
3284 << getCBeaconPckTx_by_HN() + 1 << std::endl;
3285
3286 txRTSbeforeCBEACON == false;
3290
3291 Packet *p = Packet::alloc(); // allocate the memory
3292 hdr_cmn *cmh = hdr_cmn::access(p);
3293 hdr_mac *mach = HDR_MAC(p);
3295
3296 cmh->ptype() = PT_CBEACON_UFETCH; // type of the packet
3297
3298 mach->set(MF_CONTROL, addr, MAC_BROADCAST); // set the information of the
3299 // packet (type,source
3300 // address,destination address)
3301 mach->macSA() = addr; // set the source address as AUV MAC address
3302 mach->macDA() =
3303 MAC_BROADCAST; // set the destination address as BROADCAST address
3304
3305 cbeaconh->t_min_bc() =
3306 (int) (T_MIN_BACKOFF_PROBE * 1000); // minimum value for to choose
3307 // the back-off time for tx
3308 // PROBE pck
3309 cbeaconh->t_max_bc() =
3310 (int) (T_MAX_BACKOFF_PROBE * 1000); // maximum value for to choose
3311 // the back-off time for tx
3312 // PROBE pck
3313
3314 cmh->size() =
3315 sizeof(hdr_CBEACON_UFETCH); // set the size of CBEACON header packet
3316 curr_CBEACON_HN_pck_tx = p->copy(); // create a copy of the CBEACON packet
3317
3318 if (debugMio_)
3319 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3320 << ")::state_CBEACON_tx()____________________"
3321 "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
3322 "CCCCCCCCCCCCCCCCCC"
3323 << std::endl;
3324 if (debugMio_)
3325 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3326 << ")::state_CBEACON_tx()____________________"
3327 "PARAMETERS of CBEACON pck."
3328 << std::endl;
3329 if (debugMio_)
3331 << NOW << "uwUFetch_HEAD_NODE(" << addr
3332 << ")::state_CBEACON_tx()____________________Source address: "
3333 << mach->macSA() << "." << std::endl;
3334 if (mach->macDA() == -1) {
3335 if (debugMio_)
3336 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3337 << ")::state_CBEACON_tx()____________________"
3338 "Destination address: BROADCAST."
3339 << std::endl;
3340 } else {
3341 if (debugMio_)
3342 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3343 << ")::state_CBEACON_tx()____________________"
3344 "Destination address: "
3345 << mach->macDA() << "." << std::endl;
3346 }
3347 if (debugMio_)
3348 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3349 << ")::state_CBEACON_tx()____________________MIN "
3350 "backoff time PROBE pck: "
3351 << T_MIN_BACKOFF_PROBE << "[s]." << std::endl;
3352 if (debugMio_)
3353 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3354 << ")::state_CBEACON_tx()____________________MAX "
3355 "backoff time PROBE pck: "
3356 << T_MAX_BACKOFF_PROBE << "[s]." << std::endl;
3357 if (debugMio_)
3358 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3359 << ")::state_CBEACON_tx()____________________Size of "
3360 "CBEACON pck: "
3361 << cmh->size() << "[byte]." << std::endl;
3362 if (debugMio_)
3363 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3364 << ")::state_CBEACON_tx()____________________"
3365 "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
3366 "CCCCCCCCCCCCCCCCCC"
3367 << std::endl;
3368
3369 /*hdr_uwmphy_modem* modemh = HDR_UWMPHY_MODEM(curr_CBEACON_HN_pck_tx);
3370 modemh->use_burst_data() = 0;*/
3371
3372 Packet::free(p); // de-allocate the memory
3373
3374 txCBEACONEnabled = true; // Indicates if or not the HN is enabled to
3375 // transmit a CBEACON packet to the NODE
3376
3377 CBEACON_tx(); // recall the function that simulate the transmission of the
3378 // CBEACON
3379
3380} // end state_CBEACON_tx();
3381
3382void
3384{
3385
3386 if (debug_)
3387 std::cout << NOW << " uwUFetch_NODE (" << addr
3388 << ") ::CBEACON_tx() ---->HN is transmitting a CBEACON packet"
3389 << " to the NODEs in broadcast." << std::endl;
3390
3392 // that the protocol
3393 // state change
3394
3396
3397} // end CBEACON_tx();
3398
3399/*******************************************************************************
3400 * METODI AUSILIARI *
3401 ******************************************************************************/
3402bool
3404{
3405 if (mode_comm_hn_auv == 1) {
3406 return true;
3407 } else {
3408 return false;
3409 }
3410} // end typeCommunication();
3411
3412double
3414{
3415 if (typeCommunication()) {
3416 // Communication between HN & AUV without RTS and CTS packets
3417 // RNG::defaultrng()->set_seed(addr*5);
3418 if (debug_)
3419 std::cout << NOW << " uwUFetch_NODE (" << addr
3420 << ") choiceBackOffTimer() ---->HN is choosing the "
3421 "back-off timer."
3422 << std::endl;
3423 int random = (int) RNG::defaultrng()->uniform(T_min_bck_DATA, T_max_bck_DATA);
3424
3425 if (debug_)
3426 std::cout << NOW << " uwUFetch_NODE(" << addr
3427 << ") ::choiceBackOffTimer() ---->Back-off time choice "
3428 "by the HN is = "
3429 << 0.833 * random << "[s]." << std::endl;
3430 return (0.833 * random);
3431 } else {
3432 // Communication between HN & AUV with RTS and CTS packets
3433 // RNG::defaultrng()->set_seed(addr*5);
3434 if (debug_)
3435 std::cout << NOW << " uwUFetch_NODE (" << addr
3436 << ") choiceBackOffTimer() ---->HN is choosing the "
3437 "back-off timer."
3438 << std::endl;
3439 int random = (int) RNG::defaultrng()->uniform(T_min_bck_RTS, T_max_bck_RTS);
3440
3441 if (debug_)
3442 std::cout << NOW << " uwUFetch_NODE(" << addr
3443 << ") ::choiceBackOffTimer() ---->Back-off time choice "
3444 "by the HN is = "
3445 << 0.833 * random << "[s]." << std::endl;
3446 return (0.833 * random);
3447 }
3448} // end choiceBackoffTimer_HN();
3449
3450double
3452{
3453
3454 if (debug_)
3455 std::cout
3456 << NOW << " uwUFetch_NODE (" << addr
3457 << ") ::getDataTimerValue() ---->HN is computing DATA timeout."
3458 << std::endl;
3459
3461 RTT = getRTT();
3462
3463 int pck_tx_number = 0;
3466 pck_tx_number = Q_probbed_n_pcks_NODE_want_tx_HN.front();
3467 } else {
3468 pck_tx_number = MAX_PCK_HN_WANT_RX_FROM_NODE;
3469 }
3470
3471 double data_timeout_val = 0;
3472 data_timeout_val = number_data_pck_HN_rx_exact * (Tdata_HN + T_GUARD + RTT);
3473
3474 return data_timeout_val;
3475
3476} // end getDataTimerValue();
3477
3478void
3480{
3481 if ((int) Q_data.size() < MAXIMUM_BUFFER_DATA_PCK_NODE) {
3482 if (debug_)
3483 std::cout << NOW << " uwUFetch_NODE (" << addr
3484 << ") ::recvFromUpperLayers() ---->HN is queuing a DATA "
3485 "packet"
3486 << " generated by the APPLICATION layer" << std::endl;
3487 Q_data.push(p);
3488 if (debugMio_)
3489 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3490 << ")::recvFromUpperLayer()__________________DATA "
3491 "pck from upper layer:STORE It."
3492 << std::endl;
3493 } else {
3494 if (debug_)
3495 std::cout << NOW << " uwUFetch_NODE (" << addr
3496 << ") ::recvFromUpperLayers()--->HN dropped DATA packet "
3497 "because"
3498 << " its buffer is full" << std::endl;
3499 if (debugMio_)
3500 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
3501 << ")::recvFromUpperLayer()__________________DATA "
3502 "pck from upper layer:BUFFER FULL, drop It."
3503 << std::endl;
3505 }
3506
3507} // end recvFromUpperLayers_HN();
3508
3509void
3511{
3512 Packet *simple_pck = Packet::alloc();
3513
3515 hdr_cmn *cmh = HDR_CMN(simple_pck);
3516 cmh->size() = sizeof(hdr_POLL_UFETCH);
3517 hdr_mac *mach = HDR_MAC(simple_pck);
3518
3519 mach->macSA() = addr;
3520 mach->macDA() = mac_addr_NODE_polled;
3521 Tpoll = Mac2PhyTxDuration(simple_pck);
3522
3523 } else {
3524 hdr_cmn *cmh = HDR_CMN(simple_pck);
3525 hdr_mac *mach = HDR_MAC(simple_pck);
3526 cmh->size() = MAX_PAYLOAD;
3527
3528 mach->macSA() = addr;
3529 mach->macDA() = mac_addr_AUV_in_trigger;
3530 Tdata_HN = Mac2PhyTxDuration(simple_pck);
3531 }
3532
3533 Packet::free(simple_pck);
3534} // end computeTxTime_HN();
3535
3536double
3538{
3539 RTT = 0;
3540
3543 tx_BEACON_start_HN_time; //- bck_value_probe_tx - Tprobe;
3544 } else {
3546 tx_CBEACON_start_HN_time; // - bck_value_probe_tx - Tprobe;
3547 }
3548 return RTT;
3549} // end getRTT();
3550
3551void
3553{
3554
3555 if (debug_)
3556 std::cout << NOW << " uwUFetch_NODE (" << addr
3557 << ") ::updateListProbbedNode() ---->HN has finished to "
3558 "receive DATA packet from the NODE with"
3559 << " MAC address: " << mac_addr_NODE_polled
3560 << ", so remove the NODE from the list." << std::endl;
3561
3562 Q_probbed_mac_HN.pop();
3565
3566} // end updateListProbbedNode();
3567
3568/*******************************************************************************
3569 * EXPIRE METHODS *
3570 ******************************************************************************/
3571void
3573{
3574 if ((module->debug_))
3575 std::cout << NOW << " uwUFetch_NODE (" << module->addr
3576 << ") ::uwUFetch_BEACON_timer::expire() ---->BEACON timeout "
3577 "expired"
3578 << std::endl;
3580
3581 module->BeaconTxTOExpire();
3582 ;
3583} // end uwUFetch_BEACON_timer::expire();
3584
3585void
3587{
3588 if ((module->debug_))
3589 std::cout << NOW << " uwUFetch_NODE (" << module->addr
3590 << ")::uwUFetch_PROBE_timer::expire() ---->PROBE timeout "
3591 "expired"
3592 << std::endl;
3593 timer_status = UWUFETCH_TIMER_STATUS_EXPIRED;
3594
3595 module->ProbeTOExpired();
3596} // end uwUFetch_PROBE_timer::expire();
3597
3598void
3600{
3601 if ((module->debug_))
3602 std::cout
3603 << NOW << " uwUFetch_NODE (" << module->addr
3604 << ") ::uwUFetch_DATA_timer::expire() ---->DATA timeout expired"
3605 << std::endl;
3606 timer_status = UWUFETCH_TIMER_STATUS_EXPIRED;
3607
3608 module->DataTOExpired();
3609} // end uwUFetch_DATA_timer::expire();
3610
3611void
3613{
3614 if ((module->debug_))
3615 std::cout << NOW << " uwUFetch_NODE (" << module->addr
3616 << ")::uwUFetch_CTS_timer::expire() ---->CTS timeout expired"
3617 << std::endl;
3618 timer_status = UWUFETCH_TIMER_STATUS_EXPIRED;
3619
3620 module->CtsTOExpired();
3621} // 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.
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 ...
int getTotalProbePckRx_corrupted_HN()
Total number of corrupted PROBE packets received by the HN during an entire simulation.
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...
int getTotalCBeaconPckTx_by_HN()
Total number of CBEACON packets transmitted by the HN during an entire simulation.
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 getTotalProbePckRx_HN()
Total number of PROBE packets correctly or not received by the HN during an entire simulation.
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 getTotalBeaconTx_by_HN()
Total number of BEACON packets transmitted by the HN during an entire simulation.
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.
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...
int getTotalDataPckTx_by_HN()
Total number of DATA packets transmitted by the HN during an entire simulation.
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
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< 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.
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