DESERT 3.5.1
Loading...
Searching...
No Matches
uwUFetch_AUV_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
39#include "mac.h"
40#include "mmac.h"
41#include "uwUFetch_AUV.h"
42#include "uwUFetch_cmn_hdr.h"
43#include "uwcbr-module.h"
44#include <sstream>
45#include <time.h>
46
47/******************************************************************************
48 * TX/RX METHODS *
49 ******************************************************************************/
50void
52{
53
54 hdr_cmn *cmh = hdr_cmn::access(p);
55 hdr_mac *mach = HDR_MAC(p);
56
57 if (cmh->ptype() == PT_TRIGGER_UFETCH) {
58 // TRIGGER section
59 if (debug_)
60 std::cout << NOW << " uwUFetch_AUV (" << addr
61 << ") ::Mac2PhyStartTx() ---->MAC layer of the AUV "
62 "passes the TRIGGER"
63 << " packet to his physical layer." << std::endl;
64
65 if (mach->macDA() == -1) {
66 if (debugMio_)
67 out_file_logging << NOW << "uwUFetch_AUV(" << addr
68 << ")::Mac2PhyStartTx()______________________"
69 "Start_tx_of_TRIGGER_pck_in_BROADCAST."
70 << std::endl;
71 } else {
72 if (debugMio_)
73 out_file_logging << NOW << "uwUFetch_AUV(" << addr
74 << ")::Mac2PhyStartTx()______________________"
75 "Start_tx_of_TRIGGER_pck_to_HN("
76 << mach->macDA() << ")." << std::endl;
77 }
78
79 // Compute the time required for transmission of the TRIGGER pck.
81
83
84 MMac::Mac2PhyStartTx(p);
85 }
86} // end Mac2PhyStartTx()
87
88void
90{
91
92 hdr_cmn *cmh = hdr_cmn::access(p);
93 hdr_mac *mach = HDR_MAC(p);
94
95 if (cmh->ptype() == PT_TRIGGER_UFETCH) {
96 // TRIGGER section
97 if (debug_)
98 std::cout << NOW << " uwUFetch_AUV (" << addr
99 << ") ::Phy2MacEndTx() ---->Physical layer of AUV has "
100 "finished"
101 << " to transmit a TRIGGER packet to the HN ("
102 << mach->macDA() << "), now the AUV is waiting for"
103 << " the reception of DATA packets from that HN."
104 << std::endl;
105
106 if (mach->macDA() == -1) {
107 if (debugMio_)
108 out_file_logging << NOW << "uwUFetch_AUV(" << addr
109 << ")::Phy2MacEndTx()________________________"
110 "End_tx_of_TRIGGER_pck_in_BROADCAST."
111 << std::endl;
112 } else {
113 if (debugMio_)
114 out_file_logging << NOW << "uwUFetch_AUV(" << addr
115 << ")::Phy2MacEndTx()________________________"
116 "End_tx_of_TRIGGER_pck_to_the_HN("
117 << mach->macDA() << ")." << std::endl;
118 }
120
123
124 txTRIGGEREnabled = false;
125
128 }
129} // end Phy2MacEndTx()
130
131void
133{
134
135 hdr_cmn *cmh = hdr_cmn::access(p);
136 hdr_mac *mach = HDR_MAC(p);
137 int src_mac_addr = mach->macSA();
138
139 if (cmh->ptype() == PT_BEACON_UFETCH) {
140 // BEACON section
141 if (debug_)
142 std::cout
143 << NOW << " uwUFetch_AUV (" << addr
144 << ") ::Phy2MacStartRx() ---->AUV is starting to receive a"
145 << " BEACON packet from the HN with MAC address: "
146 << src_mac_addr << std::endl;
147
148 } else if (cmh->ptype() == PT_POLL_UFETCH) {
149 // POLL section
150 if (debug_)
151 std::cout
152 << NOW << " uwUFetch_AUV (" << addr
153 << ") ::Phy2MacStartRx() ---->AUV is starting to receive a"
154 << " POLL packet from the HN with MAC address: "
155 << src_mac_addr << std::endl;
156
157 } else if (cmh->ptype() == PT_CBEACON_UFETCH) {
158 // CBEACON section
159 if (debug_)
160 std::cout
161 << NOW << " uwUFetch_AUV (" << addr
162 << ") ::Phy2MacStartRx() ---->AUV is starting to receive a"
163 << " CBEACON packet from the HN with MAC address: "
164 << src_mac_addr << std::endl;
165
166 } else if (cmh->ptype() == PT_PROBE_UFETCH) {
167 // PROBE section
168 if (debug_)
169 std::cout
170 << NOW << " uwUFetch_AUV (" << addr
171 << ") ::Phy2MacStartRx() ---->AUV is starting to receive a"
172 << " PROBE packet from the NODE with MAC address: "
173 << src_mac_addr << std::endl;
174
175 } else if (cmh->ptype() == PT_TRIGGER_UFETCH) {
176 // TRIGGER section
177 if (debug_)
178 std::cout
179 << NOW << " uwUFetch_AUV (" << addr
180 << ") ::Phy2MacStartRx() ---->AUV is starting to receive a"
181 << " TRIGGER packet from the AUV with MAC address: "
182 << src_mac_addr << std::endl;
183
184 } else {
185 // DATA section
186 if (debug_)
187 std::cout
188 << NOW << " uwUFetch_AUV (" << addr
189 << ") ::Phy2MacStartRx() ---->AUV is starting to receive a"
190 << " DATA packet from the HN with MAC address: "
191 << src_mac_addr << std::endl;
192
193 if (debugMio_)
194 out_file_logging << NOW << "uwUFetch_AUV(" << addr
195 << ")::Phy2MacStartRx()______________________"
196 "Start_to_rx_DATA_pck"
197 << "_from_HN(" << src_mac_addr << ")."
198 << std::endl;
199 rx_DATA_start_time = NOW;
200 }
201} // Phy2MacStartRx_without();
202
203void
205{
206
207 hdr_cmn *cmh = hdr_cmn::access(p);
208 hdr_mac *mach = HDR_MAC(p);
209 int src_mac_addr = mach->macSA();
210 int dest_mac_addr = mach->macDA(); // Destination MAC address, the address
211 // to which the packet is addressed
212
213 // Control if the packet that the HN has received is really for him
214 if ((dest_mac_addr == addr) || (dest_mac_addr == MAC_BROADCAST)) {
215
216 if (cmh->ptype() == PT_BEACON_UFETCH) {
217 // BEACON section
218 if (debug_)
219 std::cout << NOW << " uwUFetch_AUV (" << addr
220 << ") ::Phy2MacEndRx() ---->AUV has finished to "
221 "receive a"
222 << " BEACON packet from the HN with MAC address: "
223 << src_mac_addr << " .IGNORE IT" << std::endl;
224
225 if (src_mac_addr == mac_addr_hn_triggered) {
226 if (debug_)
227 std::cout << NOW << " uwUFetch_AUV (" << addr
228 << ") ::Phy2MacEndRx() ---->AUV reset the DATA "
229 "timeout."
230 << std::endl;
231 if (debugMio_)
233 << NOW << "uwUFetch_AUV(" << addr
234 << ")::Phy2MacEndRx()_________________________"
235 "RESET_DATA_timeout:BEACON_rx_from_triggered_HN."
236 << std::endl;
237
238 DATA_timer_first_pck.force_cancel();
239 DATA_timer.force_cancel();
240
243
244 txTRIGGEREnabled = true;
245 rxDATAEnabled = false;
246
249 // the
250 // reason
251 // for
252 // the
253 // changing
254 // of
255 // the
256 // state
257 stateIdle_AUV(); // AUV return in IDLE state
258 }
259
260 } else if (cmh->ptype() == PT_POLL_UFETCH) {
261 // POLL section
262 if (debug_)
263 std::cout << NOW << " uwUFetch_AUV (" << addr
264 << ") ::Phy2MacEndRx() ---->AUV has finished to "
265 "receive a"
266 << " POLL packet from the HN with MAC address: "
267 << src_mac_addr << " .IGNORE IT" << std::endl;
268
269 if (src_mac_addr == mac_addr_hn_triggered) {
270 if (debug_)
271 std::cout << NOW << " uwUFetch_AUV (" << addr
272 << ") ::Phy2MacEndRx() ---->AUV reset the DATA "
273 "timeout."
274 << std::endl;
275 if (debugMio_)
277 << NOW << "uwUFetch_AUV(" << addr
278 << ")::Phy2MacEndRx()_________________________"
279 "RESET_DATA_timeout:POLL_rx_from_triggered_HN."
280 << std::endl;
281
282 DATA_timer_first_pck.force_cancel();
283 DATA_timer.force_cancel();
284
287
288 txTRIGGEREnabled = true;
289 rxDATAEnabled = false;
290
293 // the
294 // reason
295 // for
296 // the
297 // changing
298 // of
299 // the
300 // state
301 stateIdle_AUV(); // AUV return in IDLE state
302 }
303
304 } else if (cmh->ptype() == PT_CBEACON_UFETCH) {
305 // CBEACON section
306 if (debug_)
307 std::cout << NOW << " uwUFetch_AUV (" << addr
308 << ") ::Phy2MacEndRx() ---->AUV has finished to "
309 "receive a"
310 << " CBEACON packet from the HN with MAC address: "
311 << src_mac_addr << " .IGNORE IT." << std::endl;
312 if (debugMio_)
313 out_file_logging << NOW << "uwUFetch_AUV(" << addr
314 << ")::Phy2MacEndRx()_________________________"
315 "Finished to rx CBEACON pck"
316 << " from HN(" << src_mac_addr
317 << "): IGNORE IT." << std::endl;
318
319 if (src_mac_addr == mac_addr_hn_triggered) {
320 if (debug_)
321 std::cout << NOW << " uwUFetch_AUV (" << addr
322 << ") ::Phy2MacEndRx() ---->AUV reset the DATA "
323 "timeout."
324 << std::endl;
325 if (debugMio_)
326 out_file_logging << NOW << "uwUFetch_AUV(" << addr
327 << ")::Phy2MacEndRx()_____________________"
328 "____RESET_DATA_timeout:CBEACON_rx_"
329 "from_triggered_HN."
330 << std::endl;
331 DATA_timer_first_pck.force_cancel();
332 DATA_timer.force_cancel();
333
336
337 txTRIGGEREnabled = true;
338 rxDATAEnabled = false;
339
342 // the
343 // reason
344 // for
345 // the
346 // changing
347 // of
348 // the
349 // state
350 stateIdle_AUV(); // AUV return in IDLE state
351 }
352
353 } else if (cmh->ptype() == PT_PROBE_UFETCH) {
354 // PROBE section
355 if (debug_)
356 std::cout << NOW << " uwUFetch_AUV (" << addr
357 << ") ::Phy2MacEndRx() ---->AUV has finished to "
358 "receive a"
359 << " PROBE packet from the NODE with MAC address: "
360 << src_mac_addr << " .IGNORE IT." << std::endl;
361
362 } else if (cmh->ptype() == PT_TRIGGER_UFETCH) {
363 // TRIGGER section
364 if (debug_)
365 std::cout << NOW << " uwUFetch_AUV (" << addr
366 << ") ::Phy2MacEndRx() ---->AUV has finished to "
367 "receive a"
368 << " TRIGGER packet from the AUV with MAC address: "
369 << src_mac_addr << " .IGNORE IT." << std::endl;
370
371 } else {
372 // DATA section
373 if (debug_)
374 std::cout
375 << NOW << " uwUFetch_AUV (" << addr
376 << ") ::Phy2MacEndRx() ---->AUV has finished to "
377 "receive a"
378 << " DATA packet from the HEAD NODE with MAC address: "
379 << src_mac_addr << std::endl;
380
381 if (debugMio_)
382 out_file_logging << NOW << "uwUFetch_AUV(" << addr
383 << ")::Phy2MacEndRx()________________________"
384 "Finished_to_rx_DATA_pck"
385 << "_from_HN(" << src_mac_addr << ")."
386 << std::endl;
387
389
391
392 if ((cmh->error()) || (!rxDATAEnabled)) {
393 if (cmh->error()) {
394 // Packet it's in error
395 if (debug_)
396 std::cout << NOW << " uwUFetch_AUV (" << addr
397 << ") ::Phy2MacEndRx() ---->DATA packet "
398 "received by the AUV"
399 << " is corrupted: DROP IT and continue with "
400 "the actual processing."
401 << std::endl;
402
405
406 curr_DATA_pck_rx = p->copy();
407
409
410 if (debugMio_)
411 out_file_logging << NOW << "uwUFetch_AUV(" << addr
412 << ")::Phy2MacEndRx()_________________"
413 "_______DATA_pck_rx_by_AUV("
414 << addr << ")_from_HN("
415 << mach->macSA()
416 << ")_id_pck:" << cbrh->sn() << ""
417 << "_It_s_in_ERROR." << std::endl;
418
419 drop(p, 1, UWFETCH_AUV_DROP_REASON_ERROR); // drop the
420 // packet
421
422 // Reset the DATA timeout within it want to receive the
423 // first packet
424 if (debugMio_)
426 << NOW << "uwUFetch_AUV(" << addr
427 << ")::Phy2MacEndRx()_________________________"
428 "Reset_FIRST_DATA_PACKET_TIMEOUT."
429 << std::endl;
430 DATA_timer_first_pck.force_cancel();
431
433 } else {
434 // AUV is not enabled to receive a DATA packet
435 if (debug_)
436 std::cout << NOW << " uwUFetch_AUV (" << addr
437 << ") ::Phy2MacEndRx() ---->AUV is not "
438 "enabled to receive the DATA"
439 << " packet: DROP IT." << std::endl;
440
441 curr_DATA_pck_rx = p->copy();
442
444
445 if (debugMio_)
447 << NOW << "uwUFetch_AUV(" << addr
448 << ")::Phy2MacEndRx()________________________"
449 "DATA_pck_rx_by_AUV("
450 << addr << ")_from_HN(" << mach->macSA()
451 << ")_id_pck:" << cbrh->sn() << ""
452 << "_NOT_ENABLED_TO_RX_IT." << std::endl;
453
455 }
456 } else {
457 // Packet it's not in error
458 if (debug_)
459 std::cout << NOW << " uwUFetch_AUV (" << addr
460 << ") ::Phy2MacEndRx() ---->Physical layer of "
461 "AUV with MAC"
462 << " address: " << dest_mac_addr
463 << " has finished to receive a DATA packet"
464 << " number: " << (getData_Rx_by_AUV() + 1)
465 << " from the HEAD NODE with MAC address: "
466 << src_mac_addr << std::endl;
467
469
470 // Reset the DATA timeout within it want to receive the first
471 // packet
472 if (debugMio_)
473 out_file_logging << NOW << "uwUFetch_AUV(" << addr
474 << ")::Phy2MacEndRx()_____________________"
475 "____Reset FIRST DATA PACKET TIMEOUT."
476 << std::endl;
477 DATA_timer_first_pck.force_cancel();
478
479 curr_DATA_pck_rx = p->copy();
480
482
483 if (debugMio_)
484 out_file_logging << NOW << "uwUFetch_AUV(" << addr
485 << ")::Phy2MacEndRx()_____________________"
486 "___DATA_pck_rx_by_AUV("
487 << addr << ")_from_HN(" << mach->macSA()
488 << ")_id_pck:" << cbrh->sn() << ""
489 << "_IT_S_CORRECT." << std::endl;
490
491 Packet::free(p);
492
495 DATA_rx();
496 }
497 }
498 } else {
499 // Packet is not addressed to me AUV
500 if (debug_)
501 std::cout << NOW << " uwUFetch_AUV (" << addr
502 << ") ::Phy2MacEndRx() ---->The packet received is not "
503 "for me AUV:"
504 << " DROP IT" << std::endl;
505
506 if (cmh->ptype() == PT_BEACON_UFETCH) {
509
510 } else if (cmh->ptype() == PT_POLL_UFETCH) {
511 if (debugMio_)
512 out_file_logging << NOW << "uwUFetch_AUV(" << addr
513 << ")::Phy2MacEndRx()_________________________"
514 "POLL not addressed to me: IGNORE IT."
515 << std::endl;
516
519
520 if (src_mac_addr == mac_addr_hn_triggered) {
521 if (debug_)
522 std::cout << NOW << " uwUFetch_AUV (" << addr
523 << ") ::Phy2MacEndRx() ---->AUV reset the DATA "
524 "timeout."
525 << std::endl;
526 if (debugMio_)
528 << NOW << "uwUFetch_AUV(" << addr
529 << ")::Phy2MacEndRx()_________________________"
530 "RESET_DATA_timeout:POLL_rx_from_triggered_HN."
531 << std::endl;
532
533 DATA_timer_first_pck.force_cancel();
534 DATA_timer.force_cancel();
535
538
539 txTRIGGEREnabled = true;
540 rxDATAEnabled = false;
541
544 // the
545 // reason
546 // for
547 // the
548 // changing
549 // of
550 // the
551 // state
552 stateIdle_AUV(); // AUV return in IDLE state
553 }
554
555 } else if (cmh->ptype() == PT_CBEACON_UFETCH) {
556
559
560 if (src_mac_addr == mac_addr_hn_triggered) {
561 if (debug_)
562 std::cout << NOW << " uwUFetch_AUV (" << addr
563 << ") ::Phy2MacEndRx() ---->AUV reset the DATA "
564 "timeout."
565 << std::endl;
566 if (debugMio_)
567 out_file_logging << NOW << "uwUFetch_AUV(" << addr
568 << ")::Phy2MacEndRx()_____________________"
569 "____RESET_DATA_timeout:CBEACON_rx_"
570 "from_triggered_HN."
571 << std::endl;
572 DATA_timer_first_pck.force_cancel();
573 DATA_timer.force_cancel();
574
577
578 txTRIGGEREnabled = true;
579 rxDATAEnabled = false;
580
583 // the
584 // reason
585 // for
586 // the
587 // changing
588 // of
589 // the
590 // state
591 stateIdle_AUV(); // AUV return in IDLE state
592 }
593
594 } else if (cmh->ptype() == PT_PROBE_UFETCH) {
597
598 } else if (cmh->ptype() == PT_TRIGGER_UFETCH) {
601
602 } else {
605 }
606 }
607} // end Phy2MacEndRx_without()
608
609/******************************************************************************
610 * AUV METHODS *
611 ******************************************************************************/
612void
614{
615
619
620 Packet *p = Packet::alloc(); // allocate the memory for the packet
621 hdr_cmn *cmh = hdr_cmn::access(p);
622 hdr_mac *mach = HDR_MAC(p);
624
625 cmh->ptype() = PT_TRIGGER_UFETCH; // assign the type of the packet
626
627 if (index == 0) {
628 if (debug_)
629 std::cout << NOW << " uwUFetch_AUV (" << addr
630 << ") ::state_TRIGGER_tx() ---->Initialization TRIGGER "
631 "packet."
632 << std::endl;
633
634 if (debugMio_)
635 out_file_logging << NOW << "uwUFetch_AUV(" << addr
636 << ")::state_TRIGGER_tx()_____________________"
637 "Initialize_TRIGGER_pck_that"
638 << "_will_be_tx_to_the_HN(" << HEAD_NODE_1 << ")."
639 << std::endl;
640
642 mach->set(MF_CONTROL, addr, HEAD_NODE_1); // set the information of the
643 // packet (type,source
644 // address,destination
645 // address)
646 mach->macSA() = addr; // set the source address as AUV MAC address
647 mach->macDA() =
648 HEAD_NODE_1; // set the destination address as BROADCAST address
649 if (index == NUM_HN_NET)
650 index = index + NUM_HN_NET + 1;
651 else {
652 index = index + 1;
653 }
654 } else if (index == 1) {
655
656 if (debug_)
657 std::cout << NOW << " uwUFetch_AUV (" << addr
658 << ") ::state_TRIGGER_tx() ---->Initialization TRIGGER "
659 "packet."
660 << std::endl;
661
662 if (debugMio_)
663 out_file_logging << NOW << "uwUFetch_AUV(" << addr
664 << ")::state_TRIGGER_tx()_____________________"
665 "Initialize_TRIGGER_pck_that"
666 << "_will_be_tx_to_the_HN(" << HEAD_NODE_2 << ")."
667 << std::endl;
668
670 mach->set(MF_CONTROL, addr, HEAD_NODE_2); // set the information of the
671 // packet (type,source
672 // address,destination
673 // address)
674 mach->macSA() = addr; // set the source address as AUV MAC address
675 mach->macDA() =
676 HEAD_NODE_2; // set the destination address as BROADCAST address
677
678 if (index == NUM_HN_NET)
679 index = index + NUM_HN_NET + 1;
680 else {
681 index = index + 1;
682 }
683
684 } else if (index == 2) {
685
686 if (debug_)
687 std::cout << NOW << " uwUFetch_AUV (" << addr
688 << ") ::state_TRIGGER_tx() ---->Initialization TRIGGER "
689 "packet."
690 << std::endl;
691
692 if (debugMio_)
693 out_file_logging << NOW << "uwUFetch_AUV(" << addr
694 << ")::state_TRIGGER_tx()_____________________"
695 "Initialize_TRIGGER_pck_that"
696 << "_will_be_tx_to_the_HN(" << HEAD_NODE_3 << ")."
697 << std::endl;
698
699 mach->set(MF_CONTROL, addr, HEAD_NODE_3); // set the information of the
700 // packet (type,source
701 // address,destination
702 // address)
703 mach->macSA() = addr; // set the source address as AUV MAC address
704 mach->macDA() =
705 HEAD_NODE_3; // set the destination address as BROADCAST address
707 if (index == NUM_HN_NET)
708 index = index + NUM_HN_NET + 1;
709 else {
710 index = index + 1;
711 }
712
713 } else if (index == 3) {
714
715 if (debug_)
716 std::cout << NOW << " uwUFetch_AUV (" << addr
717 << ") ::state_TRIGGER_tx() ---->Initialization TRIGGER "
718 "packet."
719 << std::endl;
720
721 if (debugMio_)
722 out_file_logging << NOW << "uwUFetch_AUV(" << addr
723 << ")::state_TRIGGER_tx()_____________________"
724 "Initialize_TRIGGER_pck_that"
725 << "_will_be_tx_to_the_HN(" << HEAD_NODE_4 << ")."
726 << std::endl;
727
728 mach->set(MF_CONTROL, addr, HEAD_NODE_4); // set the information of the
729 // packet (type,source
730 // address,destination
731 // address)
732 mach->macSA() = addr; // set the source address as AUV MAC address
733 mach->macDA() =
734 HEAD_NODE_4; // set the destination address as BROADCAST address
736 if (index == NUM_HN_NET)
737 index = index + NUM_HN_NET + 1;
738 else {
739 index = index + 1;
740 }
741
742 } else {
743 if (debug_)
744 std::cout << NOW << " uwUFetch_AUV (" << addr
745 << ") ::state_TRIGGER_tx() ---->Initialization TRIGGER "
746 "packet."
747 << std::endl;
748
749 if (debugMio_)
750 out_file_logging << NOW << "uwUFetch_AUV(" << addr
751 << ")::state_TRIGGER_tx()_____________________"
752 "Initialize_TRIGGER_pck_that"
753 << "_will_be_tx_to_the_HN(" << HEAD_NODE_1 << ")."
754 << std::endl;
755
757 mach->set(MF_CONTROL, addr, HEAD_NODE_1); // set the information of the
758 // packet (type,source
759 // address,destination
760 // address)
761 mach->macSA() = addr; // set the source address as AUV MAC address
762 mach->macDA() =
763 HEAD_NODE_1; // set the destination address as BROADCAST address
764 index = 1;
765 }
766
767 // Filling the header of TRIGGER packet e determine the size of the TRIGGER
768 // packet
769 triggerh->t_min() = (int) (T_MIN_RTS * 1000); // minimum value for to choose
770 // the back-off time for tx
771 // RTS pck
772 triggerh->t_max() = (int) (T_MAX_RTS * 1000); // maximum value for to choose
773 // the back-off time for tx
774 // RTS pck
775 triggerh->max_pck_want_rx() =
776 NUM_MAX_DATA_AUV_WANT_RX; // maximum number of DATA packets that the
777 // AUV want to receive from the HN
778 cmh->size() =
779 sizeof(hdr_TRIGGER_UFETCH); // set the size of TRIGGER header packet
780
781 if (debugMio_)
782 out_file_logging << NOW << "uwUFetch_AUV(" << addr
783 << ")::state_TRIGGER_tx()_____________________"
784 "PARAMETERS_of_TRIGGER_PACKET."
785 << std::endl;
786 if (debugMio_)
788 << NOW << "uwUFetch_AUV(" << addr
789 << ")::state_TRIGGER_tx()_____________________Source_address:_"
790 << mach->macSA() << std::endl;
791 if (mach->macDA() == -1) {
792 if (debugMio_)
793 out_file_logging << NOW << "uwUFetch_AUV(" << addr
794 << ")::state_TRIGGER_tx()_____________________"
795 "Destination_Address:_BROADCAST."
796 << std::endl;
797 } else {
798 if (debugMio_)
799 out_file_logging << NOW << "uwUFetch_AUV(" << addr
800 << ")::state_TRIGGER_tx()_____________________"
801 "Destination_Address:_"
802 << mach->macDA() << std::endl;
803 }
804 if (debugMio_)
805 out_file_logging << NOW << "uwUFetch_AUV(" << addr
806 << ")::state_TRIGGER_tx()_____________________MIN_"
807 "backoff_time_DATA_pck:_"
808 << T_MIN_RTS << "[s]." << std::endl;
809 if (debugMio_)
810 out_file_logging << NOW << "uwUFetch_AUV(" << addr
811 << ")::state_TRIGGER_tx()_____________________MAX_"
812 "backoff_time_DATA_pck:_"
813 << T_MAX_RTS << "[s]." << std::endl;
814 if (debugMio_)
815 out_file_logging << NOW << "uwUFetch_AUV(" << addr
816 << ")::state_TRIGGER_tx()_____________________MAX_"
817 "DATA_pck_want_rx_from_HN:_"
818 << triggerh->max_pck_want_rx() << "[pck]."
819 << std::endl;
820 if (debugMio_)
821 out_file_logging << NOW << "uwUFetch_AUV(" << addr
822 << ")::state_TRIGGER_tx()_____________________Size_of_"
823 "TRIGGER_pck:_"
824 << cmh->size() << "[byte]." << std::endl;
825
826 // Create a copy f the TRIGGER packet
827 curr_TRIGGER_pck_tx = p->copy();
828
829 // DE-allocate the memory occupied by TRIGGER packet
830 Packet::free(p);
831
832 // Recall the function that simulate the transmission of the trigger
834 TRIGGER_tx();
835} // end state_TRIGGER_tx_without();
836
837void
839{
840
841 if (debugMio_)
843 << NOW << "uwUFetch_AUV(" << addr
844 << ")::state_wait_first_DATA()_________________Waiting_DATA"
845 << "_pck_number_" << (getData_Rx_by_AUV() + 1) << "_from_HN("
846 << mac_addr_hn_triggered << ")" << std::endl;
847
851
852 data_timeout = getDataTimerValue(); // Compute the timeout interval within
853 // AUV want to receive all DATA packets from HN
854 if (debug_)
855 std::cout << NOW << " uwUFetch_AUV (" << addr
856 << ") ::state_wait_first_DATA() ---->AUV want to receive all "
857 "the DATA packets"
858 << " from the HN (" << mac_addr_hn_triggered
859 << ") within an interval time: " << data_timeout << " [s]."
860 << std::endl;
861
862 if (debugMio_)
863 out_file_logging << NOW << "uwUFetch_AUV(" << addr
864 << ")::state_wait_first_DATA()_______________Timeout_"
865 "within_rx_all_DATA"
866 << "_pcks_" << data_timeout << "[s]." << std::endl;
867
868 if (debugMio_)
869 out_file_logging << NOW << "uwUFetch_AUV(" << addr
870 << ")::state_wait_first_DATA()_______________......."
871 "Waiting_DATA"
872 << std::endl;
873 if (debugMio_)
874 out_file_logging << NOW << "uwUFetch_AUV(" << addr
875 << ")::state_wait_first_DATA()_______________......."
876 "Waiting_DATA"
877 << std::endl;
878 if (debugMio_)
879 out_file_logging << NOW << "uwUFetch_AUV(" << addr
880 << ")::state_wait_first_DATA()_______________......."
881 "Waiting_DATA"
882 << std::endl;
883
884 rxDATAEnabled = true;
885
888
889} // end state_wait_first_DATA();
virtual void schedule(double val)
Schedule a timer.
@ UWUFETCH_AUV_PACKET_TYPE_TRIGGER
virtual double getDataTimerValue()
Compute the length of time interval within AUV want to receive all DATA packet from specifical HN.
int n_DATA_rx_by_AUV
Counter of the number of DATA packets transmitted by AUV during a single cycle of simulation.
uwUFetch_FIRST_DATA_timer DATA_timer_first_pck
Interval time in which the AUV want to receive the first DATA packet from the HN.
int HEAD_NODE_4
Id number of HN 4.
virtual void state_TRIGGER_tx_without()
Initialization of TRIGGER packet that will be forwarded in broadcast to the HNs.
double data_timeout
Interval time within AUV want to receive all DATA packets from the HN.
void incrData_Rx_by_AUV()
Increase of 1 the number of DATA packets received by AUV.
double tx_TRIGGER_finish_time
Indicates when AUV end the transmission of TRIGGER packet.
int HEAD_NODE_2
Id number of HN 2.
int NUM_MAX_DATA_AUV_WANT_RX
Maximum number of data packet that AUV want to receive from the HN in a single cycle of TRIGGER-RTS-C...
bool txTRIGGEREnabled
true if AUV is enabled to transmit a TRIGGER packet
int debugMio_
Used if we want to create the logging file.
std::ofstream out_file_logging
Variable that handle the file in which the protocol write the statistics.
int n_TRIGGER_tx_by_AUV
Counter of the number of TRIGGER packets transmitted by AUV during a single cycle of simulation.
void incrTotal_Data_Rx_by_AUV()
Increase of 1 the number of DATA packets received by AUV.
int NUM_HN_NET
Number of Head Nodes in the network.
virtual void refreshReason(UWUFETCH_AUV_STATUS_CHANGE reason)
Refresh the reason for the changing of the state.
int HEAD_NODE_1
Id number of HN 1.
@ UWUFETCH_AUV_STATUS_CHANGE_PACKET_FOR_ANOTHER_NODE
@ UWUFETCH_AUV_STATUS_CHANGE_TRIGGER_INITIALIZE_TX_TRIGGER
@ UWUFETCH_AUV_STATUS_CHANGE_TRIGGER_TX_WAIT_RTS
@ UWUFETCH_AUV_STATUS_CHANGE_DATA_PCK_FINISHED_TO_RX
@ UWUFETCH_AUV_STATUS_CHANGE_TO_WAIT_DATA_EXPIRED
virtual void Phy2MacStartRx_without(const Packet *p)
Handle the detected-start-of-PHY-reception event in the case protocol doesn't use RTS and CTS packets...
virtual void computeTxTime(UWUFETCH_AUV_PACKET_TYPE tp)
Compute the transmission time for a specifical type of packet.
int HEAD_NODE_3
Id number of HN 3.
double T_MAX_RTS
Upper bound of the interval in which HN choice the back-off time to tx RTS pck.
double T_MIN_RTS
Lower bound of the interval in which HN choice the back-off time to tx RTS pck.
double tx_TRIGGER_start_time
Indicates when AUV start a transmission of TRIGGER packet.
virtual void another_DATA_received()
Verify whether AUV must to receive another DATA packet from the HN to whome It has transmitted the TR...
void incrTotalTrigger_Tx_by_AUV()
Increase of 1 the number of TRIGGER packets transmitted by AUV.
int mac_addr_hn_triggered
MAC address of the HN triggered by the AUV.
virtual void Mac2PhyStartTx_without(Packet *p)
This method must be called by the MAC to instruct the PHY to start the transmission of a packet in th...
virtual void state_wait_first_DATA_without()
AUV is waiting the FIRST DATA packet from the HN to whom It has sent only RTS packet.
void incrTrigger_Tx_by_AUV()
Increment by 1 the number of TRIGGER packets transmitted by AUV during a single cycle TRIGGER-RTS-CTS...
Packet * curr_DATA_pck_rx
Pointer to the DATA packet that is being received by AUV.
@ UWUFETCH_AUV_STATUS_WAIT_DATA_HN
@ UWUFETCH_AUV_STATUS_TRANSMIT_TRIGGER
int getData_Rx_by_AUV()
Number of DATA packets received by AUV after the transmission of TRIGGER-RTS-CTS packets from a speci...
uwUFetch_DATA_timer DATA_timer
Interval time in which the AUV want to receive all DATA packets from the HN.
virtual void Phy2MacEndRx_without(Packet *p)
Handle the end-of-PHY-reception event in the case protocol doesn't use RTS and CTS packets.
virtual void Phy2MacEndTx_without(const Packet *p)
Handle the end-of-PHY-transmission event in the case protocol doesn't use RTS and CTS packets.
bool rxDATAEnabled
true if AUV is enabled to receive a DATA packet
double rx_DATA_finish_time
Indicates when AUV end the reception of DATA packet.
virtual void DATA_rx()
AUV has received a DATA packet from HN.
virtual void refreshState(UWUFETCH_AUV_STATUS state)
Refresh the state of the protocol.
double rx_DATA_start_time
Indicates when AUV start the reception of DATA packet.
virtual void state_wait_first_DATA()
AUV is waiting the FIRST DATA packet from the HN to whom It has sent a RTS and CTS packet.
virtual void printStateInfo(double delay=0)
Prints a file with every state change for debug purposes.
virtual void stateIdle_AUV()
Idle state.
void incrTotal_Data_Rx_corrupted_by_AUV()
Increase of 1 the number of corrupted DATA packets received by AUV.
Packet * curr_TRIGGER_pck_tx
Pointer to the TRIGGER packet that is being transmitted by AUV.
virtual void TRIGGER_tx()
Trasmission of TRIGGER packet.
bool print_transitions
true if the writing of state transitions in the file is enabled.
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 class that implement AUV for UFetch protocol.
packet_t PT_POLL_UFETCH
POLL packet type for UFetch protocol.
packet_t PT_CBEACON_UFETCH
CBEACON packet type for UFetch protocol.
#define UWFETCH_AUV_DROP_REASON_ERROR
Packet dropped: Packet corrupted.
#define UWFETCH_AUV_DROP_REASON_WRONG_RECEIVER
Packet dropped: Packet is addressed to another node of the.
packet_t PT_TRIGGER_UFETCH
Trigger packet type for UFetch protocol.
packet_t PT_BEACON_UFETCH
BEACON packet type for UFetch protocol.
packet_t PT_PROBE_UFETCH
PROBE packet type for UFetch protocol.
#define UUFETCH_AUV_DROP_REASON_NOT_ENABLE
Packet dropped: AUV is not enabled to transmit or 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)