DESERT 3.5.1
Loading...
Searching...
No Matches
uwUFetch_NODE_HEADNODE_mod_2.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
40#include "mac.h"
41#include "mmac.h"
42#include "uwUFetch_NODE.h"
43#include "uwUFetch_cmn_hdr.h"
44//#include "uwmphy_modem_cmn_hdr.h"
45#include "uwcbr-module.h"
46
47void
49{
50
51 hdr_cmn *cmh = hdr_cmn::access(p);
52 hdr_mac *mach = HDR_MAC(p);
53 int src_mac_addr = mach->macSA();
54 int dest_mac_addr = mach->macDA(); // Destination MAC address, the address
55 // to which the packet is addressed
56
57 if (debug_)
58 std::cout << NOW << "uwUFetch_NODE(" << addr
59 << ")::Phy2MacEndRx()______________________dest_mac_addr "
60 << dest_mac_addr << std::endl;
61 // Control if the packet that the HN has received is really for him
62
63 if ((dest_mac_addr == addr) || (dest_mac_addr == MAC_BROADCAST)) {
64 // Packet is addressed to me HN
65
66 if (cmh->ptype() == PT_TRIGGER_UFETCH) {
67 // TRIGGER section
68 if (debug_)
69 std::cout << NOW << " uwUFetch_NODE (" << addr
70 << ") ::Phy2MacEndRx() ---->HN has finished to "
71 "receive a"
72 << " TRIGGER packet from the AUV with MAC address: "
73 << src_mac_addr << std::endl;
74
75 if (debugMio_)
76 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
77 << ")::Phy2MacEndRx()______________________"
78 "Finished_to_rx_TRIGGER_pck"
79 << "_from_AUV(" << src_mac_addr << ")."
80 << std::endl;
81
83 mach->macSA(); // Save the Mac address of the
84
85 if (rxTRIGGEREnabled) {
86 int index_q = 0;
93 while ((!Q_data.empty()) &&
94 (index_q <= MAX_PCK_HN_WANT_RX_FROM_NODE)) {
95 // Pick up the first element of the queue
96 curr_DATA_NODE_pck_tx_HN = (Q_data.front())->copy();
97 // Remove the element from the queue that we have pick up
98 // the packet
99 Q_data.pop();
100 // Add the packet to the queue of data packets that HN will
101 // transmit to AUV when
102 // will be required
107
108 if (debugMio_)
109 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
110 << ")::Phy2MacEndRx()_________________"
111 "_______DATA_pck_tx:_source("
112 << mach->macSA() << ")_"
113 << "destination(" << mach->macDA()
114 << ")_id_pck:" << cbrh->sn() << ""
115 << std::endl;
116 index_q++;
117 }
118 }
119
120 if ((cmh->error()) || (Q_data_HN.empty())) {
121 if (cmh->error()) {
122 // Packet it's in error
123 if (debug_)
124 std::cout << NOW << " uwUFetch_NODE (" << addr
125 << ") ::Phy2MacEndRx() ---->TRIGGER packet "
126 "received by the HN"
127 << " is corrupted: DROP IT" << std::endl;
128
129 if (debugMio_)
130 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
131 << ")::Phy2MacEndRx()_________________"
132 "_______TRIGGER_rx_from_AUV("
133 << mach->macSA()
134 << ")_It_s_in_ERROR:IGNORE_It."
135 << std::endl;
136
138
141
142 drop(p,
143 1,
144 UWFETCH_NODE_DROP_REASON_ERROR); // drop the packet
146
147 if (rxTRIGGEREnabled) {
148 if (debug_)
149 std::cout << NOW << " uwUFetch_NODE (" << addr
150 << ") ::Phy2MacEndRx() ---->HN reset the "
151 "TRIGGER timer"
152 << std::endl;
153
154 BeaconBeforeTx_timer.force_cancel();
155
158 rxTRIGGEREnabled = true;
159
160 stateIdle_HN();
161 } else {
162 // HN is not enable to receive a TRIGGER packet
163 if (debug_)
164 std::cout << NOW << " uwUFetch_NODE (" << addr
165 << ") ::Phy2MacEndRx() ---->HN is not "
166 "enabled to receive"
167 << " the TRIGGER packet: DROP IT."
168 << std::endl;
169 }
170 } else {
171 if (debug_)
172 std::cout << NOW << " uwUFetch_NODE (" << addr
173 << ") ::Phy2MacEndRx() ---->TRIGGER packet "
174 "received by the HN"
175 << " is not corrupted, but the HN has 0 DATA "
176 "packet enabled to tx to the AUV: DROP IT"
177 << std::endl;
178
179 if (debugMio_)
180 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
181 << ")::Phy2MacEndRx()_________________"
182 "_______TRIGGER_rx_It_s_CORRECT_"
183 "but_0_DATA_to_tx:IGNORE_It."
184 << std::endl;
185
187
189
190 drop(p,
191 1,
192 UWFETCH_NODE_DROP_REASON_ERROR); // drop the packet
194
195 if (rxTRIGGEREnabled) {
196 if (debug_)
197 std::cout << NOW << " uwUFetch_NODE (" << addr
198 << ") ::Phy2MacEndRx() ---->HN reset the "
199 "TRIGGER timer"
200 << std::endl;
201 BeaconBeforeTx_timer.force_cancel();
202
205 rxTRIGGEREnabled = true;
206
207 stateIdle_HN();
208 } else {
209 // HN is not enable to receive a TRIGGER packet
210 if (debug_)
211 std::cout << NOW << " uwUFetch_NODE (" << addr
212 << ") ::Phy2MacEndRx() ---->HN is not "
213 "enabled to receive"
214 << " the TRIGGER packet: DROP IT."
215 << std::endl;
216 }
217 }
218 } else {
219 // Packet it's not in error
220 if (debug_)
221 std::cout << NOW << " uwUFetch_NODE (" << addr
222 << ") ::Phy2MacEndRx() ---->Physical layer of HN "
223 "with MAC"
224 << " address: " << dest_mac_addr
225 << " has finished to receive a TRIGGER packet"
226 << " from the AUV with MAC address: "
227 << src_mac_addr << std::endl;
228
229 if (debugMio_)
231 << NOW << "uwUFetch_HEAD_NODE(" << addr
232 << ")::Phy2MacEndRx()________________________"
233 "TRIGGER_rx_It_s_CORRECT_>=1_DATA_to_tx."
234 << std::endl;
235
237
240
241 curr_TRIGGER_HN_pck_rx = p->copy();
242
244
245 Packet::free(p);
246
247 TRIGGER_rx();
248 }
249 } else {
250 // DATA section
251 if (debug_)
252 std::cout << NOW << " uwUFetch_NODE (" << addr
253 << ") ::Phy2MacEndRx() ---->HN has finished to "
254 "receive a"
255 << " DATA packet from the NODE with MAC address: "
256 << src_mac_addr << std::endl;
257
259
260 if (debugMio_)
261 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
262 << ")::Phy2MacEndRx()________________________"
263 "End_to_rx_DATA_pck_"
264 << "from_SN(" << src_mac_addr << ")."
265 << std::endl;
266
267 if (cmh->error()) {
268 // Packet it's in error
269 if (debug_)
270 std::cout << NOW << " uwUFetch_NODE( " << addr
271 << ") ::Phy2MacEndRx() ---->DATA packet received "
272 "by the HN"
273 << " is corrupted: DROP IT" << std::endl;
274
275 curr_DATA_HN_pck_rx = p->copy();
276
278
282
284
285 if (debugMio_)
286 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
287 << ")::Phy2MacEndRx()_____________________"
288 "___DATA_pck_rx_by_HN("
289 << addr << ")_from_SN(" << src_mac_addr
290 << ")_id_pck:" << cbrh->sn() << ""
291 << "_It_s_in_ERROR." << std::endl;
292
293 drop(p, 1, UWFETCH_NODE_DROP_REASON_ERROR); // drop the packet
295
296 } else {
297 // Packet it's not in error
298
299 if (debug_)
300 std::cout << NOW << " uwUFetch_NODE (" << addr
301 << ") ::Phy2MacEndRx() ---->Physical layer of HN "
302 "with MAC"
303 << " address: " << dest_mac_addr
304 << " has finished to receive a DATA packet"
305 << " number: " << (getDataPckRx_by_HN() + 1)
306 << " from the NODE with MAC address: "
307 << src_mac_addr << std::endl;
308
310
313
314 curr_DATA_HN_pck_rx = p->copy();
315
317
318 Packet::free(p);
319
320 DATA_rx();
321 }
322 }
323 } else {
324 // Packet is not addressed to me HN
325 if (debug_)
326 std::cout << NOW << " uwUFetch_NODE (" << addr
327 << ") ::Phy2MacEndRx() ---->The packet received is not "
328 "for me HN:"
329 << " DROP IT." << std::endl;
330
331 if (cmh->ptype() == PT_POLL_UFETCH) {
332 // POLL section
333 if (debug_)
334 std::cout << NOW << " uwUFetch_NODE (" << addr
335 << ") ::Phy2MacEndRx() ---->HN has finished to "
336 "receive a"
337 << " POLL packet from the HN with MAC address: "
338 << src_mac_addr << " .DROP IT" << std::endl;
339
341
342 } else if (cmh->ptype() == PT_PROBE_UFETCH) {
343 // BEACON section
344 if (debug_)
345 std::cout << NOW << " uwUFetch_NODE (" << addr
346 << ") ::Phy2MacEndRx() ---->HN has finished to "
347 "receive a"
348 << " PROBE packet from the SENSOR NODE with MAC "
349 "address: "
350 << src_mac_addr << " .DROP IT" << std::endl;
351
352 if (debugMio_)
353 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
354 << ")::Phy2MacEndRx()________________________"
355 "Finished_to_rx_PROBE"
356 << "_pck_from_SN(" << src_mac_addr
357 << ").Not_addressed_to_me:_IGNORE_IT."
358 << std::endl;
359
361
362 } else if (cmh->ptype() == PT_TRIGGER_UFETCH) {
363 // TRIGGER section
364 if (debug_)
365 std::cout << NOW << " uwUFetch_NODE (" << addr
366 << ") ::Phy2MacEndRx() ---->HN has finished to "
367 "receive a"
368 << " TRIGGER packet from the AUV with MAC address ("
369 << src_mac_addr << ").DROP IT" << std::endl;
370
371 if (debugMio_)
372 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
373 << ")::Phy2MacEndRx()________________________"
374 "Finished_to_rx_TRIGGER"
375 << "_pck_from_AUV(" << src_mac_addr
376 << ")._Not_addressed_to_me:_IGNORE_IT."
377 << std::endl;
378
380
381 } else {
382 // DATA section
383 if (debug_)
384 std::cout << NOW << " uwUFetch_NODE (" << addr
385 << ") ::Phy2MacEndRx() ---->HN has finished to "
386 "receive a"
387 << " DATA packet from the SENSOR NODE with MAC "
388 "address: "
389 << src_mac_addr << " .DROP IT" << std::endl;
390
391 if (debugMio_)
392 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
393 << ")::Phy2MacEndRx()________________________"
394 "End_to_rx_DATA_pck_"
395 << "from_SN(" << src_mac_addr
396 << ")._Not_addressed_to_me:_IGNORE_IT."
397 << std::endl;
398
400 }
401 }
402} // end Phy2MacEndRx_HN();
403
404/******************************************************************************
405 * HEAD NODE METHODS *
406 ******************************************************************************/
407
408void
410{
411
412 if (rxTRIGGEREnabled) {
413 // HN is enabled to receive a TRIGGER
414 if (debug_)
415 std::cout << NOW << " uwUFetch_NODE (" << addr
416 << ") ::TRIGGER_rx() ---->HN reset the TRIGGER timer"
417 << std::endl;
418
419 if (debugMio_)
421 << NOW << "uwUFetch_HEAD_NODE(" << addr
422 << ")::TRIGGER_rx()_________________________TRIGGER_rx_It_"
423 "s_CORRECT_and_>= 1_DATA_to_tx_and_enabled_to_rx_It."
424 << std::endl;
425
426 BeaconBeforeTx_timer.force_cancel(); // reset the timer in which the HN
427 // wait a TRIGGER packet
428
432
433 hdr_mac *mach = HDR_MAC(curr_TRIGGER_HN_pck_rx);
434 hdr_TRIGGER_UFETCH *triggerh =
436
437 /*
438 * Save the header data of the trigger
439 */
440
441 T_min_bck_DATA = (double) triggerh->t_min() / 1000; // Minimum value
442 // time before that
443 // HN transmit a
444 // DATA packet
445 T_max_bck_DATA = (double) triggerh->t_max() / 1000; // Maximum value
446 // time before that
447 // HN transmit a
448 // DATA packet
450 triggerh->max_pck_want_rx(); // Maximum number of DATA packet
451 // that HN can transmit to the AUV
452
454 mach->macSA(); // Save the MAC address of the AUV node from
455 // which the HN has received a trigger packet
456
457 if (debugMio_)
458 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
459 << ")::TRIGGER_rx()__________________________"
460 "PARAMETERS_of_TRIGGER_PACKET: "
461 << std::endl;
462 if (debugMio_)
463 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
464 << ")::TRIGGER_rx()__________________________"
465 "Source_address:_"
466 << mach->macSA() << "." << std::endl;
467 if (mach->macDA() == -1) {
468 if (debugMio_)
469 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
470 << ")::TRIGGER_rx()__________________________"
471 "Destination_Address:_BROADCAST."
472 << std::endl;
473 } else {
474 if (debugMio_)
475 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
476 << ")::TRIGGER_rx()__________________________"
477 "Destination_Address:_"
478 << mach->macDA() << std::endl;
479 }
480 if (debugMio_)
481 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
482 << ")::TRIGGER_rx()__________________________MIN_"
483 "backoff_time_DATA_pck:_"
484 << T_min_bck_DATA << "[s]." << std::endl;
485 if (debugMio_)
486 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
487 << ")::TRIGGER_rx()__________________________MAX_"
488 "backoff_time_DATA_pck:_"
489 << T_max_bck_DATA << "[s]." << std::endl;
490 if (debugMio_)
491 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
492 << ")::TRIGGER_rx()__________________________MAX_"
493 "DATA_pck_want_rx_from_HN:_"
494 << max_pck_HN_can_tx << "[pck]." << std::endl;
495 if (debugMio_)
496 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
497 << ")::TRIGGER_rx()__________________________DATA_"
498 "pck_would_like_to_tx_to_the_AUV:_"
499 << Q_data_HN.size() << "[pck]." << std::endl;
500
501 rxTRIGGEREnabled = false;
502 txBEACONEnabled = false;
503
505 if (debugMio_)
506 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
507 << ")::TRIGGER_rx()__________________________"
508 "Backoff_timeout_choice:_"
509 << bck_before_tx_data << "[s]." << std::endl;
510
512
513 } else {
514 // HN is not enable to receive a TRIGGER packet
515 if (debug_)
516 std::cout << NOW << " uwUFetch_NODE (" << addr
517 << ") ::TRIGGER_rx() ---->HN is not enabled to receive"
518 << " the TRIGGER packet: DROP IT." << std::endl;
519
520 if (debugMio_)
522 << NOW << "uwUFetch_HEAD_NODE(" << addr
523 << ")::TRIGGER_rx()_________________________TRIGGER_rx_It_"
524 "s_CORRECT_and_>= "
525 "1_DATA_to_tx_and_not_enabled_to_rx_It:IGNORE_It."
526 << std::endl;
527
528 if (debugMio_)
530 << NOW << "uwUFetch_HEAD_NODE(" << addr
531 << ")::TRIGGER_rx()__________________________Not_ENABLED"
532 << "_to_rx_TRIGGER_pck." << std::endl;
533
535 }
536} // end TRIGGER_rx();
537
538void
540{
541 if (debug_)
542 std::cout << NOW << " uwUFetch_NODE (" << addr
543 << ") ::BCKTOExpired() ---->Back-off timeout is expired:"
544 << " so the first DATA packet can be transmitted by the HN "
545 "to the AUV."
546 << std::endl;
547
548 if (debugMio_)
549 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
550 << ")::BCKTOExpired()________________________Backoff_"
551 "timeout_expired."
552 << std::endl;
553
555}
556
557void
559{
560 // Compute the maximum number of DATA packet that the HN can be transmitted
561 // to the AUV
562 if (Q_data_HN.size() >= max_pck_HN_can_tx) {
564
565 } else {
567 }
568
569 if (debug_)
570 std::cout << NOW << " uwUFetch_NODE (" << addr
571 << ") ::state_DATA_HN_first_tx() ---->HN will be transmit "
573 << " DATA packets to the AUV with MAC address: "
574 << mac_addr_AUV_in_trigger << std::endl;
575
576 if (debugMio_)
578 << NOW << "uwUFetch_HEAD_NODE(" << addr
579 << ")::state_DATA_HN_first_tx()______________DATA_pck_to_tx_"
580 << max_data_HN_can_tx << "_to_the_AUV("
581 << mac_addr_AUV_in_trigger << ")." << std::endl;
582
583 if (debug_)
584 std::cout << NOW << " uwUFetch_NODE (" << addr
585 << ") ::state_DATA_HN_first_tx() ---->HN is starting "
586 "transmission of the"
587 << " FIRST DATA packet to the AUV with MAC address: "
588 << mac_addr_AUV_in_trigger << std::endl;
589
590 // Pick up the first element of the queue
591 curr_DATA_HN_pck_tx = (Q_data_HN.front())->copy();
592 // Remove the element from the queue that we have pick up
593 Q_data_HN.pop();
594
595 hdr_mac *mach = HDR_MAC(curr_DATA_HN_pck_tx);
596 hdr_cmn *cmh = hdr_cmn::access(curr_DATA_HN_pck_tx);
598
599 mach->set(MF_CONTROL, addr, mac_addr_AUV_in_trigger);
600 mach->macSA() = addr;
601 mach->macDA() = mac_addr_AUV_in_trigger;
602 cmh->size() = sizeof(curr_DATA_HN_pck_tx);
603
604 if (burstDATA()) {
605 // hdr_uwmphy_modem* modemh =
606 // HDR_UWMPHY_MODEM(curr_DATA_HN_pck_tx);
607 // modemh->use_burst_data() = 1;
608 // if (getDataPckTx_by_HN() == (max_data_HN_can_tx)) {
609 // modemh->last_packet() = 1;
610 // modemh->use_burst_data() = 1;
611 // } else {
612 // modemh->last_packet() = 0;
613 // modemh->use_burst_data() = 1;
614 // }
615 txDATAEnabledHN = true;
616
617 int old_sn = cbrh->sn();
618 cbrh->sn() = pck_number_id;
620
621 if (debugMio_)
622 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
623 << ")::state_DATA_HN_first_tx()______________DATA_"
624 "pck_tx:_source_SN("
625 << Q_data_source_SN.front() << ")_source_HN("
626 << mach->macSA() << ")_"
627 << "destination(" << mach->macDA()
628 << ")_id_pck_original:" << old_sn
629 << "_new_id_pck:" << cbrh->sn()
630 << "_size:" << cmh->size() << "[byte]"
631 << std::endl;
632 Q_data_source_SN.pop();
633
634 DATA_HN_tx();
635 } else {
636 txDATAEnabledHN = true;
637
638 int old_sn = cbrh->sn();
639 cbrh->sn() = pck_number_id;
641
642 if (debugMio_)
643 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
644 << ")::state_DATA_HN_first_tx()______________DATA_"
645 "pck_tx:_source_SN("
646 << Q_data_source_SN.front() << ")_source_HN("
647 << mach->macSA() << ")_"
648 << "destination(" << mach->macDA()
649 << ")_id_pck_original:" << old_sn
650 << "_new_id_pck:" << cbrh->sn()
651 << "_size:" << cmh->size() << "[byte]"
652 << std::endl;
653
654 Q_data_source_SN.pop();
655 DATA_HN_tx();
656 }
657} // end state_DATA_HN_first_tx_without();
658
659void
661{
662 // HN is enabled to transmit DATA packet
663 if (debug_)
664 std::cout << NOW << " uwUFetch_NODE (" << addr
665 << ") ::DATA_HN_tx() ---->HN is transmitting a DATA packet "
666 "to the AUV"
667 << " with MAC address: " << mac_addr_AUV_in_trigger
668 << std::endl;
669
671
673
674} // end DATA_HN_tx();
675
676void
678{
679
680 if (debug_)
681 std::cout << NOW << " uwUFetch_NODE (" << addr
682 << ") ::state_DATA_HN_tx() ---->HN is starting transmission "
683 "of the"
684 << " DATA packet number: " << (getDataPckTx_by_HN() + 1)
685 << " to the AUV with"
686 << " MAC address: " << mac_addr_AUV_in_trigger << std::endl;
687
688 // Pick up the first element of the queue
689 curr_DATA_HN_pck_tx = (Q_data_HN.front())->copy();
690 // Remove the element from the queue that we have pick up
691 Q_data_HN.pop();
692
693 hdr_mac *mach = HDR_MAC(curr_DATA_HN_pck_tx);
694 hdr_cmn *cmh = hdr_cmn::access(curr_DATA_HN_pck_tx);
696
697 mach->set(MF_CONTROL, addr, mac_addr_AUV_in_trigger);
698 mach->macSA() = addr;
699 mach->macDA() = mac_addr_AUV_in_trigger;
700 cmh->size() = sizeof(curr_DATA_HN_pck_tx);
701
702 if (burstDATA()) {
703 // hdr_uwmphy_modem* modemh =
704 // HDR_UWMPHY_MODEM(curr_DATA_HN_pck_tx);
705 // // modemh->use_burst_data() = 1;
706 // if (getDataPckTx_by_HN() == (max_data_HN_can_tx)) {
707 // modemh->last_packet() = 1;
708 // modemh->use_burst_data() = 1;
709 // } else {
710 // modemh->last_packet() = 0;
711 // modemh->use_burst_data() = 1;
712 // }
713 txDATAEnabledHN = true;
714
715 int old_sn = cbrh->sn();
716 cbrh->sn() = pck_number_id;
718
719 if (debugMio_)
720 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
721 << ")::state_DATA_HN_tx()____________________DATA_"
722 "pck_tx:_source_SN("
723 << Q_data_source_SN.front() << ")_source_HN("
724 << mach->macSA() << ")_"
725 << "destination(" << mach->macDA()
726 << ")_id_pck_original:" << old_sn
727 << "_new_id_pck:" << cbrh->sn()
728 << "_size:" << cmh->size() << "[byte]"
729 << std::endl;
730 Q_data_source_SN.pop();
731
732 DATA_HN_tx();
733 } else {
734 txDATAEnabledHN = true;
735
736 int old_sn = cbrh->sn();
737 cbrh->sn() = pck_number_id;
739
740 if (debugMio_)
741 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
742 << ")::state_DATA_HN_tx()_____________________"
743 "DATA_pck_tx:_source_SN("
744 << Q_data_source_SN.front() << ")_source_HN("
745 << mach->macSA() << ")_"
746 << "destination(" << mach->macDA()
747 << ")_id_pck_original:" << old_sn
748 << "_new_id_pck:" << cbrh->sn()
749 << "_size:" << cmh->size() << "[byte]"
750 << std::endl;
751 Q_data_source_SN.pop();
752
753 DATA_HN_tx();
754 }
755
756} // end state_DATA_HN_tx_without();
757
758void
760{
761 if (debugMio_)
762 out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
763 << ")::state_DATA_HN_finish_tx()_____________End_tx_"
764 "DATA_pcks_to_the_AUV."
765 << std::endl;
766 if (sectionCBeacon) {
767 // HN has start the communication with AUV before to start the
768 // transmission of CBEACON packet, so after the end of the communication
769 // with AUV, HN return in state_CBEACON_tx().
770 if (debug_)
771 std::cout << NOW << " uwUFetch_NODE (" << addr
772 << ") ::state_DATA_HN_finish_tx() ---->HN has "
773 "transmitted all his DATA"
774 << " packets to the AUV with MAC address: "
776 << ", so return in STATE_CBEACON_TX()." << std::endl;
777
780 sectionCBeacon = false;
783
784 txDATAEnabledHN = false;
785
787
788 } else {
789 // HN has start the communication with AUV when it was in IDLE STATE, so
790 // after the end of the communication
791 // with AUV, HN return in stateIdle_HN().
792 if (debug_)
793 std::cout << NOW << " uwUFetch_NODE (" << addr
794 << ") ::state_DATA_HN_finish_tx() ---->HN has "
795 "transmitted all his DATA"
796 << " packets to the AUV with MAC address: "
797 << mac_addr_AUV_in_trigger << ", so return in IDLE STATE."
798 << std::endl;
802
803 txBEACONEnabled = true;
804 rxTRIGGEREnabled = true;
805 txDATAEnabledHN = false;
806
807 stateIdle_HN();
808 }
809} // end state_DATA_HN_finish_tx_without();
virtual void schedule(double val)
schedule a timer
void incrTotalDataPckRx_by_HN()
Increase total number of DATA packets correctly or not received by the HN during an entire simulation...
double T_max_bck_DATA
Upper bound time interval from which the HN choice its backoff timer before to transmit a DATA packet...
virtual void state_DATA_HN_first_tx_without()
HN initialize the FIRST DATA packet that will be forwarded to the AUV node.
virtual bool burstDATA()
Indicate whether the transmission of DATA packets to the AUV take place with or without burst data.
virtual void state_DATA_HN_finish_tx_without()
HN has finished to transmit the sequence of DATA packets to the AUV.
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 ...
double bck_before_tx_data
Time value chosen by the HN and used by It for transmit a DATA packet to the AUV.
virtual void stateIdle_HN()
Idle state for HN.
uwUFetch_BackOffTimer BCK_timer_data
Interval time before that the HN transmit his DATA packet to the AUV.
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 printStateInfo(double delay=0)
Prints a file with every state change for debug purposes.
std::ofstream out_file_logging
Variable that handle the file in which the protocol write the statistics.
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-...
virtual void BCKTOExpired_HN_without()
Backoff timeout is expired.
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.
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.
bool sectionCBeacon
true HN has started the transmission of RTS packet when It was in the CBEACON section.
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.
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.
std::queue< Packet * > Q_data_HN
Queue of DATA packets stored by the HNs and received from SN.
Packet * curr_DATA_NODE_pck_tx_HN
Pointer to the DATA packet that is being transmitted by HN.
void incrDataPckRx_by_HN()
Increase the number of DATA packets transmitted by the HN during a single cycle BEACON-PROBE-POLL-DAT...
int pck_number_id
Unique identifier of the DATA packet received.
virtual void Mac2PhyStartTx(Packet *p)
This method must be called by the SN-MAC to instruct the PHY to start the transmission of a packet.
bool rxTRIGGEREnabled
true if HN is enabled to receive a TRIGGER packet from the AUV
virtual void state_DATA_HN_tx_without()
HN initialize the second and successive DATA packets that will be forwarded to the AUV node.
void incrTotalTriggerPckRx_corrupted_HN()
Increase the total number of corrupted TRIGGER packets received by the HN during an entire simulation...
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...
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.
virtual void state_CBEACON_tx()
HN initialize the CBEACON packet that will be forwarded in broadcast at all SNs of the network.
void incrTriggerPckRx_HN()
Increase the number of TRIGGER packets received by the HN during a single cycle TRIGGER-RTS-CTS-DATA ...
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...
virtual void TRIGGER_rx_without()
HN has received a TRIGGER packet from AUV.
uwUFetch_BEACON_timer BeaconBeforeTx_timer
Schedule the BEACON timeout timer.
void incrTotalDataPckTx_by_NODE()
Increase the total number of DATA packets transmitted by SN during an entire duration of simulation.
virtual void TRIGGER_rx()
HN has received a TRIGGER packet from AUV.
@ UWUFETCH_NODE_STATUS_CHANGE_DATA_PCK_TX
@ UWUFETCH_NODE_STATUS_CHANGE_TRIGGER_RX
@ UWUFETCH_NODE_STATUS_CHANGE_DATA_RX
@ UWUFETCH_NODE_STATUS_CHANGE_HN_RX_TRIGGER_FROM_AUV_CORRUPTED
@ UWFETCH_NODE_STATUS_CHANGE_PACKET_ERROR
@ UWUFETCH_NODE_STATUS_CHANGE_HN_FINISH_TX_DATA_PCK_TO_AUV_RETURN_CBEACON_TX
@ UWUFETCH_NODE_STATUS_CHANGE_HN_TX_ALL_DATA_TO_AUV
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
Packet * curr_DATA_HN_pck_tx
Pointer to the DATA packet that is being transmitted by HN to the AUV.
std::queue< int > Q_data_source_SN
Queue that contain the MAC address from which the HN has received the DATA packet.
std::queue< Packet * > Q_data
Queue of DATA packets stored by the SN.
int max_data_HN_can_tx
Maximum number of DATA packets that the HN must transmit to the AUV.
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...
Packet * curr_DATA_HN_pck_rx
Pointer to the DATA packet that is being received by HN from 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_TRIGGER_RECEIVE
Content header of TRIGGER packet.
int & t_min()
Reference to the t_min variable.
int & t_max()
Reference to the t_max variable.
int & max_pck_want_rx()
Reference to the max_pck_want_rx variable.
hdr_uwcbr describes UWCBR packets.
uint16_t & sn()
Reference to the sn_ variable.
Declaration of uwUFetch_NODE class.
packet_t PT_POLL_UFETCH
POLL packet type for UFetch protocol.
#define UWFETCH_NODE_DROP_REASON_ERROR
Packet dropped: packet is corrupted.
packet_t PT_TRIGGER_UFETCH
TRIGGER 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.
#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_TRIGGER_UFETCH(p)
alias defined to access the TRIGGER HEADER
Provides the UWCBR packets header description and the definition of the class UWCBR.
#define HDR_UWCBR(p)