DESERT 3.5.1
Loading...
Searching...
No Matches
uwUFetch_AUV.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
38// include files
39#include "mac.h"
40#include "mmac.h"
41#include "uwUFetch_AUV.h"
42#include "uwUFetch_cmn_hdr.h"
43
44#include <sstream>
45#include <time.h>
46
50static class uwUFetchAUVModuleClass : public TclClass
51{
52public:
57 : TclClass("Module/UW/UFETCH/AUV")
58 {
59 }
60
65 TclObject *
66 create(int, const char *const *)
67 {
68 return (new uwUFetch_AUV());
69 }
70} class_module_uwufetchauv; // uwUFetchAUVModuleClass
71
78
79bool uwUFetch_AUV::initialized = false;
80
81std::map<uwUFetch_AUV::UWUFETCH_AUV_STATUS, std::string>
83std::map<uwUFetch_AUV::UWUFETCH_AUV_STATUS_CHANGE, std::string>
85std::map<uwUFetch_AUV::UWUFETCH_AUV_PACKET_TYPE, std::string>
87std::map<uwUFetch_AUV::UWUFETCH_TIMER_STATUS, std::string>
89
94 : // TIMERS
95 Trigger_timer(this)
96 , // Interval time before that the AUV start the transmission of the TRIGGER
97 // packet
98 RTS_timer(this)
99 , // Interval time in which the AUV wait a RTS packets from the HNs
100 DATA_timer(this)
101 , // Interval time in which the AUV want to receive all the DATA packets
102 // from the HN
103 // GLOBAL VARIABLES THAT SHOULD BE NEVER RESET
104 MAX_PAYLOAD(0)
105 , // Maximum size of DATA PAYLOAD packet
106 NUM_MAX_DATA_AUV_WANT_RX(0)
107 , // Maximum number of data packet that AUV want to receive from the HN
108 T_START_PROC_TRIGGER(0)
109 , // Time before that the AUV start the procedure to transmit a TRIGGER
110 // packet
111 N_RUN(0)
112 , // Indicate the number of the run in execution
113 HEAD_NODE_1(0)
114 , // Id number of HN 1
115 HEAD_NODE_2(0)
116 , // Id number of HN 2
117 HEAD_NODE_3(0)
118 , // Id number of HN 3
119 HEAD_NODE_4(0)
120 , // Id number of HN 4
121 tx_TRIGGER_start_time(0)
122 , // Indicates when a transmission of TRIGGER packet by AUV is started
123 tx_TRIGGER_finish_time(0)
124 , // Indicates when a transmission of TRIGGER packet by AUV is finished
125 rx_RTS_start_time(0)
126 , // Indicates when a reception of RTS packet by AUV is started
127 rx_RTS_finish_time(0)
128 , // Indicates when a reception of RTS packet by AUV is completed
129 tx_CTS_start_time(0)
130 , // Indicates when a transmission of CTS packet by AUV is started
131 tx_CTS_finish_time(0)
132 , // Indicates when a transmission of CTS packet by AUV is completed
133 rx_DATA_start_time(0)
134 , // Indicates when a reception of DATA packet by AUV is started
135 rx_DATA_finish_time(0)
136 , // Indicates when a reception of DATA packet by AUV is completed
137 n_tot_TRIGGER_tx_by_AUV(0)
138 , // Total number of the TRIGGER packets transmitted by the AUV during an
139 // entire cycle of simulation
140 n_tot_RTS_rx_by_AUV(0)
141 , // Total number of RTS packets rx by the AUV during an entire cycle of
142 // simulation
143 n_tot_RTS_rx_corr_by_AUV(0)
144 , // Total number of RTS packets corrupted rx by the AUV during an entire
145 // cycle of simulation
146 n_tot_CTS_tx_by_AUV(0)
147 , // Total number of the CTS packets transmitted by the AUV during an entire
148 // cycle of simulation
149 n_tot_DATA_rx_by_AUV(0)
150 , // Total number of DATA packets rx by the AUV during an entire cycle of
151 // simulation
152 n_tot_DATA_rx_corr_by_AUV(0)
153 , // Total number of DATA packets corrupted rx by the AUV during an entire
154 // cycle of simulation
155 number_data_pck_AUV_rx_exact(0)
156 , // Exact number of data packet that the AUV want to receive from the HN
157 mac_addr_HN_ctsed(0)
158 , // Mac address of the HN from which the AUV want to receive the data
159 // packets
160 data_timeout(0)
161 , // Interval time within the AUV want to receive all the DATA packets from
162 // the HN
163 T_tx_TRIGGER(0)
164 , // Time required to transimt the TRIGGER packet
165 Tdata(0)
166 , RTT(0)
167 , mac_addr_HN_in_data(0)
168 , // MAC address of the HN from which the AUV has received the DATA packet
169 hn_trigg(0)
170 , // Indicate the index of the node that will be triggered with the next
171 // cycle of trigger
172 index(0)
173 , mac_addr_hn_triggered(0)
174 , // MAC address of the HN triggered by the AUV.
175 num_pck_hn_1(0)
176 , // Number of correct packets received by the HN 1
177 num_pck_hn_2(0)
178 , // Number of correct packets received by the HN 2
179 num_pck_hn_3(0)
180 , // Number of correct packets received by the HN 3
181 num_pck_hn_4(0)
182 , // Number of correct packets received by the HN 4
183 // VARIABLES THAT ENABLES OR NOT AN OPERATION
184 txTRIGGEREnabled(false)
185 , // Enable or not AUV to transmit a TRIGGER packet
186 rxRTSEnabled(false)
187 , // Enable or not AUV to receive a RTS packet
188 txCTSEnabled(false)
189 , // Enable or not AUV to transmit a CTS packet
190 rxDATAEnabled(false)
191 , // Enable or not AUV to receive a DATA packet
192 // VARIABLES THAT SHOULD BE RESETED WHEN A CYCLE IS ENDED
193 n_TRIGGER_tx_by_AUV(0)
194 , // Total number of the TRIGGER packets transmitted by the AUV during a
195 // single cycle of simulation
196 n_RTS_rx_by_AUV(0)
197 , // Total number of RTS packets rx by the AUV during a single cycle of
198 // simulation
199 n_CTS_tx_by_AUV(0)
200 , // Total number of CTS packet tx by the AUV during a single cycle of
201 // simulation
202 n_DATA_rx_by_AUV(0)
203 , // Total number of DATA packet rx by the AUV during a single cycle of
204 // simulation
205 // PACKETS CREATED
206 curr_TRIGGER_pck_tx(NULL)
207 , // Contains the information TRIGGER packet
208 curr_RTS_pck_rx(NULL)
209 , // Contains the information RTS packet
210 curr_CTS_pck_tx(NULL)
211 , // Contains the information CTS packet
212 curr_DATA_pck_rx(NULL) // Contains the information DATA packet
213{
214 mac2phy_delay_ = 1e-19;
215 bind("T_min_RTS_", (double *) &T_MIN_RTS);
216 bind("T_max_RTS_", (double *) &T_MAX_RTS);
217 bind("T_guard_", (double *) &T_GUARD);
218 bind("t_RTS_", (double *) &T_RTS);
219 bind("MAX_PAYLOAD", (double *) &MAX_PAYLOAD);
220 bind("num_max_DATA_AUV_want_receive_", (int *) &NUM_MAX_DATA_AUV_WANT_RX);
221 bind("TIME_BEFORE_TX_TRIGGER_PCK_", (double *) &T_START_PROC_TRIGGER);
222 bind("MY_DEBUG_", (int *) &debugMio_);
223 bind("NUMBER_OF_RUN_", (int *) &N_RUN);
224 bind("HEAD_NODE_1_", (int *) &HEAD_NODE_1);
225 bind("HEAD_NODE_2_", (int *) &HEAD_NODE_2);
226 bind("HEAD_NODE_3_", (int *) &HEAD_NODE_3);
227 bind("HEAD_NODE_4_", (int *) &HEAD_NODE_4);
228 bind("MODE_COMM_", (int *) &mode_comm_hn_auv);
229 bind("NUM_HN_NETWORK_", (int *) &NUM_HN_NET);
230
231} // end uwUFetch_AUV()
232
233int
234uwUFetch_AUV::command(int argc, const char *const *argv)
235{
236 Tcl &tcl = Tcl::instance();
237
238 if (argc == 2) {
239 if (strcasecmp(argv[1], "initialize") == 0) {
240 if (initialized == false)
241 initInfo();
242 if (debug_)
243 fout.open("/tmp/uwUFetch_AUV_stateTransitions.txt",
244 std::ios_base::app);
245
246 if (debugMio_) {
247 std::stringstream file_logging;
248 file_logging << "uwUFetch_AUV_" << addr << "_N_RUN_" << N_RUN
249 << ".out";
250 out_file_logging.open(
251 file_logging.str().c_str(), std::ios_base::app);
252 }
253
254 return TCL_OK;
255 } else if (strcasecmp(argv[1], "printTransitions") == 0) {
256 print_transitions = true;
257
258 return TCL_OK;
259 } else if (strcasecmp(argv[1], "getTRIGGERtxByAUV") == 0) {
260 tcl.resultf("%d", getTotalTrigger_Tx_by_AUV());
261
262 return TCL_OK;
263 } else if (strcasecmp(argv[1], "getRTSrxByAUV") == 0) {
264 tcl.resultf("%d", getTotalRts_Rx_by_AUV());
265
266 return TCL_OK;
267 } else if (strcasecmp(argv[1], "getRTSCorruptedRxByAUV") == 0) {
268 tcl.resultf("%d", getTotalRts_Rx_corrupted_by_AUV());
269
270 return TCL_OK;
271 } else if (strcasecmp(argv[1], "getCTStxByAUV") == 0) {
272 tcl.resultf("%d", getTotalCts_Tx_by_AUV());
273
274 return TCL_OK;
275 } else if (strcasecmp(argv[1], "getDataRxByAUV") == 0) {
276 tcl.resultf("%d", getTotal_Data_Rx_by_AUV());
277
278 return TCL_OK;
279 } else if (strcasecmp(argv[1], "getDataCorruptedRxByAUV") == 0) {
280 tcl.resultf("%d", getTotal_Data_Rx_corrupted_by_AUV());
281
282 return TCL_OK;
283 } else if (strcasecmp(argv[1], "AUVNodeStart") == 0) {
285 return TCL_OK;
286 }
287 } else if (argc == 3) {
288 if (strcasecmp(argv[1], "setMacAddr") == 0) {
289 addr = atoi(argv[2]);
290 if (debug_)
291 std::cout << "UWFETCH_AUV MAC address is:" << addr << std::endl;
292
293 return TCL_OK;
294 }
295 }
296
297 return MMac::command(argc, argv);
298} // end command
299
300int
302{
303 switch (m->type()) {
304 default:
305 return MMac::crLayCommand(m);
306 }
307} // end crLCommand()
308
309/******************************************************************************
310 * TX/RX METHODS *
311 ******************************************************************************/
312
319void
321{
322
323 hdr_cmn *cmh = hdr_cmn::access(p);
324 hdr_mac *mach = HDR_MAC(p);
325
326 if (cmh->ptype() == PT_TRIGGER_UFETCH) {
327 // TRIGGER section
328 if (debug_)
329 std::cout << NOW << " uwUFetch_AUV (" << addr
330 << ") ::Mac2PhyStartTx() ---->MAC layer of the AUV "
331 "passes the TRIGGER"
332 << " packet to his physical layer." << std::endl;
333
334 if (mach->macDA() == -1) {
335 if (debugMio_)
336 out_file_logging << NOW << "uwUFetch_AUV(" << addr
337 << ")::Mac2PhyStartTx()______________________"
338 "Start tx of TRIGGER pck in BROADCAST."
339 << std::endl;
340 } else {
341 if (debugMio_)
342 out_file_logging << NOW << "uwUFetch_AUV(" << addr
343 << ")::Mac2PhyStartTx()______________________"
344 "Start tx of TRIGGER pck to HN("
345 << mach->macDA() << ")." << std::endl;
346 }
347 // Compute the time required for transmission of the TRIGGER pck.
349
350 if (debugMio_)
351 out_file_logging << NOW << "uwUFetch_AUV(" << addr
352 << ")::Mac2PhyStartTx()______________________Time "
353 "required for the tx: "
354 << T_tx_TRIGGER << "[s]" << std::endl;
355
357
358 MMac::Mac2PhyStartTx(p);
359 } else if (cmh->ptype() == PT_CTS_UFETCH) {
360 // CTS section
361 if (debug_)
362 std::cout << NOW << " uwUFetch_AUV (" << addr
363 << ") ::Mac2PhyStartTx() ---->MAC layer of the AUV "
364 "passes the CTS"
365 << " packet to his physical layer." << std::endl;
366
367 if (debugMio_)
368 out_file_logging << NOW << "uwUFetch_AUV(" << addr
369 << ")::Mac2PhyStartTx()______________________"
370 "Start tx of CTS pck to HN("
371 << mach->macDA() << ")." << std::endl;
372
373 tx_CTS_start_time = NOW;
374
375 MMac::Mac2PhyStartTx(p);
376 }
377} // end Mac2PhyStartTx()
378
386void
388{
389
390 hdr_cmn *cmh = hdr_cmn::access(p);
391 hdr_mac *mach = HDR_MAC(p);
392
393 if (cmh->ptype() == PT_TRIGGER_UFETCH) {
394
395 if (typeCommunication()) {
396 // Communication between HN & AUV without RTS and CTS packets
398
399 } else {
400 // Communication between HN & AUV with RTS and CTS packets
401
402 if (debug_)
403 std::cout << NOW << " uwUFetch_AUV (" << addr
404 << ") ::Phy2MacEndTx() ---->Physical layer of AUV "
405 "has finished"
406 << " to transmit a TRIGGER packet to the AUVs in "
407 "broadcast, now the AUV is waiting for"
408 << " the reception of RTS packets from the HNs."
409 << std::endl;
410
411 if (mach->macDA() == -1) {
412 if (debugMio_)
414 << NOW << "uwUFetch_AUV(" << addr
415 << ")::Phy2MacEndTx()________________________End "
416 "the tx of TRIGGER pck in BROADCAST"
417 << std::endl;
418 } else {
419 if (debugMio_)
421 << NOW << "uwUFetch_AUV(" << addr
422 << ")::Phy2MacEndTx()________________________End "
423 "the tx of TRIGGER pck to the HN("
424 << mach->macDA() << ")." << std::endl;
425 }
427
430
431 txTRIGGEREnabled = false;
432
435 }
436
437 } else if (cmh->ptype() == PT_CTS_UFETCH) {
438 // CTS section
439
440 if (debug_)
441 std::cout
442 << NOW << " uwUFetch_AUV (" << addr
443 << ") ::Phy2MacEndTx() ---->Physical layer of the AUV has "
444 "finished"
445 << " to transmit a CTS packet to the AUV with MAC address: "
446 << mac_addr_HN_ctsed << "so wait"
447 << " the DATA packets from the HN and disable the "
448 "reception of other CTS"
449 << std::endl;
450
451 if (debugMio_)
452 out_file_logging << NOW << "uwUFetch_AUV(" << addr
453 << ")::Phy2MacEndTx()________________________End "
454 "the tx of CTS pck to the HN("
455 << mach->macDA() << ")." << std::endl;
456
457 tx_CTS_finish_time = NOW;
458
461
462 txCTSEnabled = false;
463
466 }
467} // end Phy2MacEndTx()
468
474void
476{
477
478 if (typeCommunication()) {
479 // Communication between HN & AUV without RTS and CTS packets
481
482 } else {
483 // Communication between HN & AUV with RTS and CTS packets
484 hdr_cmn *cmh = hdr_cmn::access(p);
485 hdr_mac *mach = HDR_MAC(p);
486 int src_mac_addr = mach->macSA();
487
488 if (cmh->ptype() == PT_BEACON_UFETCH) {
489 // BEACON section
490 if (debug_)
491 std::cout << NOW << " uwUFetch_AUV (" << addr
492 << ") ::Phy2MacStartRx() ---->AUV is starting to "
493 "receive a"
494 << " BEACON packet from the HN with MAC address: "
495 << src_mac_addr << std::endl;
496 if (debugMio_)
497 out_file_logging << NOW << "uwUFetch_AUV(" << addr
498 << ")::Phy2MacStartRx()______________________"
499 "Start to rx BEACON pck"
500 << " from HN(" << src_mac_addr << ")."
501 << std::endl;
502
503 } else if (cmh->ptype() == PT_POLL_UFETCH) {
504 // POLL section
505 if (debug_)
506 std::cout << NOW << " uwUFetch_AUV (" << addr
507 << ") ::Phy2MacStartRx() ---->AUV is starting to "
508 "receive a"
509 << " POLL packet from the HN with MAC address: "
510 << src_mac_addr << std::endl;
511 if (debugMio_)
512 out_file_logging << NOW << "uwUFetch_AUV(" << addr
513 << ")::Phy2MacStartRx()______________________"
514 "Start to rx POLL pck"
515 << " from HN(" << src_mac_addr << ")."
516 << std::endl;
517
518 } else if (cmh->ptype() == PT_CBEACON_UFETCH) {
519 // CBEACON section
520 if (debug_)
521 std::cout << NOW << " uwUFetch_AUV (" << addr
522 << ") ::Phy2MacStartRx() ---->AUV is starting to "
523 "receive a"
524 << " CBEACON packet from the HN with MAC address: "
525 << src_mac_addr << std::endl;
526 if (debugMio_)
527 out_file_logging << NOW << "uwUFetch_AUV(" << addr
528 << ")::Phy2MacStartRx()______________________"
529 "Start to rx CBEACON pck"
530 << " from HN(" << src_mac_addr << ")."
531 << std::endl;
532
533 } else if (cmh->ptype() == PT_PROBE_UFETCH) {
534 // PROBE section
535 if (debug_)
536 std::cout << NOW << " uwUFetch_AUV (" << addr
537 << ") ::Phy2MacStartRx() ---->AUV is starting to "
538 "receive a"
539 << " PROBE packet from the NODE with MAC address: "
540 << src_mac_addr << std::endl;
541 if (debugMio_)
542 out_file_logging << NOW << "uwUFetch_AUV(" << addr
543 << ")::Phy2MacStartRx()______________________"
544 "Start to rx PROBE pck"
545 << " from NODE(" << src_mac_addr << ")."
546 << std::endl;
547
548 } else if (cmh->ptype() == PT_TRIGGER_UFETCH) {
549 // TRIGGER section
550 if (debug_)
551 std::cout << NOW << " uwUFetch_AUV (" << addr
552 << ") ::Phy2MacStartRx() ---->AUV is starting to "
553 "receive a"
554 << " TRIGGER packet from the AUV with MAC address: "
555 << src_mac_addr << std::endl;
556 if (debugMio_)
557 out_file_logging << NOW << "uwUFetch_AUV(" << addr
558 << ")::Phy2MacStartRx()______________________"
559 "Start to rx TRIGGER pck"
560 << " from AUV(" << src_mac_addr << ")."
561 << std::endl;
562
563 } else if (cmh->ptype() == PT_RTS_UFETCH) {
564 // RTS section
565 if (debug_)
566 std::cout << NOW << " uwUFetch_AUV (" << addr
567 << ") ::Phy2MacStartRx() ---->AUV is starting to "
568 "receive a"
569 << " RTS packet from the HN with MAC address: "
570 << src_mac_addr << std::endl;
571 if (debugMio_)
572 out_file_logging << NOW << "uwUFetch_AUV(" << addr
573 << ")::Phy2MacStartRx()______________________"
574 "Start to rx a RTS pck"
575 << " from HN(" << src_mac_addr << ")."
576 << std::endl;
577
578 rx_RTS_start_time = NOW;
579
580 } else {
581 // DATA section
582 if (debug_)
583 std::cout << NOW << " uwUFetch_AUV (" << addr
584 << ") ::Phy2MacStartRx() ---->AUV is starting to "
585 "receive a"
586 << " DATA packet from the HN with MAC address: "
587 << src_mac_addr << std::endl;
588 if (debugMio_)
589 out_file_logging << NOW << "uwUFetch_AUV(" << addr
590 << ")::Phy2MacStartRx()______________________"
591 "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
592 "DDDDDDDDDDDDDDDDDDDDDDDDDD"
593 << std::endl;
594
595 if (debugMio_)
596 out_file_logging << NOW << "uwUFetch_AUV(" << addr
597 << ")::Phy2MacStartRx()______________________"
598 "Start to rx DATA pck"
599 << " from HN(" << src_mac_addr << ")."
600 << std::endl;
601
602 rx_DATA_start_time = NOW;
603 }
604 }
605} // Phy2MacStartRx();
606
612void
614{
615
616 if (typeCommunication()) {
617 // Communication between HN & AUV without RTS and CTS packets
619
620 } else {
621 // Communication between HN & AUV with RTS and CTS packets
622 hdr_cmn *cmh = hdr_cmn::access(p);
623 hdr_mac *mach = HDR_MAC(p);
624 int src_mac_addr = mach->macSA();
625 int dest_mac_addr = mach->macDA(); // Destination MAC address, the
626 // address to which the packet is
627 // addressed
628
629 // Control if the packet that the HN has received is really for him
630 if ((dest_mac_addr == addr) || (dest_mac_addr == MAC_BROADCAST)) {
631
632 if (cmh->ptype() == PT_BEACON_UFETCH) {
633 // BEACON section
634 if (debug_)
635 std::cout << NOW << " uwUFetch_AUV (" << addr
636 << ") ::Phy2MacEndRx() ---->AUV has finished to "
637 "receive a"
638 << " BEACON packet from the HN with MAC address: "
639 << src_mac_addr << " .IGNORE IT" << std::endl;
640 if (debugMio_)
641 out_file_logging << NOW << "uwUFetch_AUV(" << addr
642 << ")::Phy2MacEndRx()_____________________"
643 "___Finished to rx BEACON pck"
644 << " from HN(" << src_mac_addr
645 << "): IGNORE IT." << std::endl;
646 } else if (cmh->ptype() == PT_POLL_UFETCH) {
647 // POLL section
648 if (debug_)
649 std::cout << NOW << " uwUFetch_AUV (" << addr
650 << ") ::Phy2MacEndRx() ---->AUV has finished to "
651 "receive a"
652 << " POLL packet from the HN with MAC address: "
653 << src_mac_addr << " .IGNORE IT" << std::endl;
654 if (debugMio_)
655 out_file_logging << NOW << "uwUFetch_AUV(" << addr
656 << ")::Phy2MacEndRx()_____________________"
657 "___Finished to rx POLL pck"
658 << " from HN(" << src_mac_addr
659 << "): IGNORE IT." << std::endl;
660
661 } else if (cmh->ptype() == PT_CBEACON_UFETCH) {
662 // CBEACON section
663 if (debug_)
664 std::cout
665 << NOW << " uwUFetch_AUV (" << addr
666 << ") ::Phy2MacEndRx() ---->AUV has finished to "
667 "receive a"
668 << " CBEACON packet from the HN with MAC address: "
669 << src_mac_addr << " .IGNORE IT." << std::endl;
670 if (debugMio_)
671 out_file_logging << NOW << "uwUFetch_AUV(" << addr
672 << ")::Phy2MacEndRx()_____________________"
673 "___Finished to rx CBEACON pck"
674 << " from HN(" << src_mac_addr
675 << "): IGNORE IT." << std::endl;
676
677 } else if (cmh->ptype() == PT_PROBE_UFETCH) {
678 // PROBE section
679 if (debug_)
680 std::cout
681 << NOW << " uwUFetch_AUV (" << addr
682 << ") ::Phy2MacEndRx() ---->AUV has finished to "
683 "receive a"
684 << " PROBE packet from the NODE with MAC address: "
685 << src_mac_addr << " .IGNORE IT." << std::endl;
686 if (debugMio_)
687 out_file_logging << NOW << "uwUFetch_AUV(" << addr
688 << ")::Phy2MacEndRx()_____________________"
689 "___Finished to rx PROBE pck"
690 << " from NODE(" << src_mac_addr
691 << "): IGNORE IT." << std::endl;
692
693 } else if (cmh->ptype() == PT_TRIGGER_UFETCH) {
694 // TRIGGER section
695 if (debug_)
696 std::cout
697 << NOW << " uwUFetch_AUV (" << addr
698 << ") ::Phy2MacEndRx() ---->AUV has finished to "
699 "receive a"
700 << " TRIGGER packet from the AUV with MAC address: "
701 << src_mac_addr << " .IGNORE IT." << std::endl;
702 if (debugMio_)
703 out_file_logging << NOW << "uwUFetch_AUV(" << addr
704 << ")::Phy2MacEndRx()_____________________"
705 "___Finished to rx TRIGGER pck"
706 << " from AUV(" << src_mac_addr
707 << "): IGNORE IT." << std::endl;
708
709 } else if (cmh->ptype() == PT_RTS_UFETCH) {
710 // RTS section
711 rx_RTS_finish_time = NOW;
712
713 if (debugMio_)
714 out_file_logging << NOW << "uwUFetch_AUV(" << addr
715 << ")::Phy2MacEndRx()_____________________"
716 "___Finished to rx RTS pck"
717 << " from HN(" << src_mac_addr << ")."
718 << std::endl;
720
721 if ((cmh->error()) || (!rxRTSEnabled)) {
722 if (cmh->error()) {
723 // Packet it's in error
724 if (debug_)
725 std::cout << NOW << " uwUFetch_AUV (" << addr
726 << ") ::Phy2MacEndRx() ---->RTS packet "
727 "received by the AUV"
728 << " is corrupted: DROP IT, and continue "
729 "with the processing."
730 << std::endl;
731 if (debugMio_)
732 out_file_logging << NOW << "uwUFetch_AUV(" << addr
733 << ")::Phy2MacEndRx()_____________"
734 "___________RTS pck rx"
735 << " from HN(" << src_mac_addr
736 << ") It's in ERROR." << std::endl;
737
739
740 drop(p, 1, UWFETCH_AUV_DROP_REASON_ERROR); // drop the
741 // packet
742
743 } else {
744 // AUV is not enabled to receive RTS
745 if (debug_)
746 std::cout << NOW << " uwUFetch_AUV (" << addr
747 << ") ::Phy2MacEndRx() ---->AUV has "
748 "finished to receive a"
749 << " RTS packet from the HN with MAC "
750 "address: "
751 << src_mac_addr << ", but it's not "
752 << " enabled to receive It, so DROP the "
753 "packet and continue the processing."
754 << std::endl;
755 if (debugMio_)
756 out_file_logging << NOW << "uwUFetch_AUV(" << addr
757 << ")::Phy2MacEndRx()_____________"
758 "___________RTS pck rx"
759 << " from HN(" << src_mac_addr
760 << ") NOT ENABLED to rx It."
761 << std::endl;
762
764 }
765 } else {
766 // AUV is enabled to receive RTS
767 if (debug_)
768 std::cout
769 << NOW << " uwUFetch_AUV (" << addr
770 << ") ::Phy2MacEndRx() ---->AUV has finished "
771 "to receive a"
772 << " RTS packet from the HN with MAC address: "
773 << src_mac_addr << "." << std::endl;
774
775 if (debugMio_)
776 out_file_logging << NOW << "uwUFetch_AUV(" << addr
777 << ")::Phy2MacEndRx()_________________"
778 "_______RTS pck rx"
779 << " from HN(" << src_mac_addr
780 << ") It's CORRECT." << std::endl;
781
782 if (getTrigger_Tx_by_AUV() == 1) {
783 // The RTS is received after a transmission of TRIGGER
784 // packet
786
787 curr_RTS_pck_rx = p->copy();
788
789 Packet::free(p);
790
793 RTS_rx();
794
795 } else {
796 // The RTS is received without sending previous TRIGGER
797 // packets
799
800 curr_RTS_pck_rx = p->copy();
801
802 Packet::free(p);
803
806 RTS_rx();
807 }
808 }
809 } else {
810 // DATA section
811 if (debug_)
812 std::cout << NOW << " uwUFetch_AUV (" << addr
813 << ") ::Phy2MacEndRx() ---->AUV has finished to "
814 "receive a"
815 << " DATA packet from the HEAD NODE with MAC "
816 "address: "
817 << src_mac_addr << std::endl;
818
819 if (debugMio_)
820 out_file_logging << NOW << "uwUFetch_AUV(" << addr
821 << ")::Phy2MacEndRx()_____________________"
822 "___Finished to rx DATA packet"
823 << " from HN(" << src_mac_addr << ")."
824 << std::endl;
825
827
829
830 if ((cmh->error()) || (!rxDATAEnabled)) {
831 if (cmh->error()) {
832 // Packet it's in error
833 if (debug_)
834 std::cout << NOW << " uwUFetch_AUV (" << addr
835 << ") ::Phy2MacEndRx() ---->DATA packet "
836 "received by the AUV"
837 << " is corrupted: DROP IT and continue "
838 "with the actual processing."
839 << std::endl;
840
843
844 if (debugMio_)
845 out_file_logging << NOW << "uwUFetch_AUV(" << addr
846 << ")::Phy2MacEndRx()_____________"
847 "___________DATA pck"
848 << " rx from HN(" << mach->macSA()
849 << ") It's in ERROR." << std::endl;
850 if (debugMio_)
851 out_file_logging << NOW << "uwUFetch_AUV(" << addr
852 << ")::Phy2MacEndRx()_____________"
853 "___________DATA number "
854 << getData_Rx_by_AUV() << "."
855 << std::endl;
856
857 if (debugMio_)
859 << NOW << "uwUFetch_AUV(" << addr
860 << ")::Phy2MacEndRx()______________________"
861 "__"
862 "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
863 "DDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
864 << std::endl;
865 drop(p, 1, UWFETCH_AUV_DROP_REASON_ERROR); // drop the
866 // packet
867
869 } else {
870 // AUV is not enabled to receive a DATA packet
871 if (debug_)
872 std::cout << NOW << " uwUFetch_AUV (" << addr
873 << ") ::Phy2MacEndRx() ---->AUV is not "
874 "enabled to receive the DATA"
875 << " packet from HN(" << mach->macSA()
876 << "): DROP IT." << std::endl;
877 if (debugMio_)
878 out_file_logging << NOW << "uwUFetch_AUV(" << addr
879 << ")::Phy2MacEndRx()_____________"
880 "___________AUV It's not "
881 "enabled to rx DATA from HN("
882 << mach->macSA() << ")."
883 << std::endl;
884 if (debugMio_)
886 << NOW << "uwUFetch_AUV(" << addr
887 << ")::Phy2MacEndRx()______________________"
888 "__"
889 "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
890 "DDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
891 << std::endl;
892
894 }
895 } else {
896 // Packet it's not in error
897 if (debug_)
898 std::cout << NOW << " uwUFetch_AUV (" << addr
899 << ") ::Phy2MacEndRx() ---->Physical layer "
900 "of AUV with MAC"
901 << " address: " << dest_mac_addr
902 << " has finished to receive a DATA packet"
903 << " number: " << (getData_Rx_by_AUV() + 1)
904 << " from the HEAD NODE with MAC address: "
905 << src_mac_addr << std::endl;
906
908
909 curr_DATA_pck_rx = p->copy();
910
911 if (debugMio_)
912 out_file_logging << NOW << "uwUFetch_AUV(" << addr
913 << ")::Phy2MacEndRx()_________________"
914 "_______DATA pck rx from HN("
915 << mach->macSA() << ") It's CORRECT."
916 << std::endl;
917
918 if (debugMio_)
919 out_file_logging << NOW << "uwUFetch_AUV(" << addr
920 << ")::Phy2MacEndRx()_________________"
921 "_______DATA pck number "
922 << getData_Rx_by_AUV() << "."
923 << std::endl;
924
925 Packet::free(p);
926
929 DATA_rx();
930 }
931 }
932 } else {
933 // Packet is not addressed to me AUV
934 if (debug_)
935 std::cout << NOW << " uwUFetch_AUV (" << addr
936 << ") ::Phy2MacEndRx() ---->The packet received is "
937 "not for me AUV:"
938 << " DROP IT" << std::endl;
939
940 if (cmh->ptype() == PT_BEACON_UFETCH) {
941 if (debugMio_)
943 << NOW << "uwUFetch_AUV(" << addr
944 << ")::Phy2MacEndRx()________________________"
945 "BEACON not addressed to me: IGNORE IT."
946 << std::endl;
947
948 } else if (cmh->ptype() == PT_POLL_UFETCH) {
949 if (debugMio_)
951 << NOW << "uwUFetch_AUV(" << addr
952 << ")::Phy2MacEndRx()________________________POLL "
953 "not addressed to me: IGNORE IT."
954 << std::endl;
955
959
960 } else if (cmh->ptype() == PT_CBEACON_UFETCH) {
961 if (debugMio_)
963 << NOW << "uwUFetch_AUV(" << addr
964 << ")::Phy2MacEndRx()________________________"
965 "CBEACON not addressed to me: IGNORE IT."
966 << std::endl;
967
971
972 } else if (cmh->ptype() == PT_PROBE_UFETCH) {
973 if (debugMio_)
975 << NOW << "uwUFetch_AUV(" << addr
976 << ")::Phy2MacEndRx()________________________PROBE "
977 "not addressed to me: IGNORE IT."
978 << std::endl;
979
983
984 } else if (cmh->ptype() == PT_TRIGGER_UFETCH) {
985 if (debugMio_)
987 << NOW << "uwUFetch_AUV(" << addr
988 << ")::Phy2MacEndRx()________________________"
989 "TRIGGER not addressed to me: IGNORE IT."
990 << std::endl;
991
995
996 } else if (cmh->ptype() == PT_RTS_UFETCH) {
997 if (debugMio_)
998 out_file_logging << NOW << "uwUFetch_AUV(" << addr
999 << ")::Phy2MacEndRx()_____________________"
1000 "___RTS rx from HN("
1001 << mach->macSA()
1002 << ")not addressed to me: IGNORE IT."
1003 << std::endl;
1004
1008
1009 } else if (cmh->ptype() == PT_CTS_UFETCH) {
1010 if (debugMio_)
1011 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1012 << ")::Phy2MacEndRx()_____________________"
1013 "___CTS not addressed to me: IGNORE IT."
1014 << std::endl;
1015
1019
1020 } else {
1021 if (debugMio_)
1022 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1023 << ")::Phy2MacEndRx()_____________________"
1024 "___DATA pck rx from HN("
1025 << mach->macSA()
1026 << ") is not addressed to me: IGNORE IT."
1027 << std::endl;
1028 if (debugMio_)
1030 << NOW << "uwUFetch_AUV(" << addr
1031 << ")::Phy2MacEndRx()________________________"
1032 "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
1033 "DDDDDDDDDDDDDDDDDDDDD"
1034 << std::endl;
1035
1039 }
1040 }
1041 }
1042} // end Phy2MacEndRx()
1043
1044/******************************************************************************
1045 * AUV METHODS *
1046 ******************************************************************************/
1047void
1049{
1050
1051 if (debug_)
1052 std::cout << NOW << " uwUFetch_AUV (" << addr
1053 << ") ::stateIdle_AUV() ---->AUV is in IDLE state."
1054 << std::endl;
1055
1056 if (debugMio_)
1057 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1058 << ")::stateIdle_AUV()_______________________AUV is "
1059 "in IDLE STATE."
1060 << std::endl;
1061
1062 txTRIGGEREnabled = false;
1063
1067
1069 if (debug_)
1070 std::cout << NOW << " uwUFetch_AUV (" << addr
1071 << ") ::stateIdle_AUV() ---->AUV start immediately the "
1072 "transmission of TRIGGER packet"
1073 << " to a specific HN." << std::endl;
1074
1075 if (debugMio_)
1076 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1077 << ")::stateIdle_AUV()_______________________"
1078 "Start immediately the tx of TRIGGER pck"
1079 << std::endl;
1080
1081 txTRIGGEREnabled = true;
1083
1084 } else {
1085 if (debug_)
1086 std::cout << NOW << " uwUFetch_AUV (" << addr
1087 << ") ::stateIdle_AUV() ---->AUV before to transmit a "
1088 "TRIGGER packet"
1089 << " to a specific HNs waits an interval time equal to: "
1090 << T_START_PROC_TRIGGER << "[s]." << std::endl;
1091
1092 if (debugMio_)
1093 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1094 << ")::stateIdle_AUV()_______________________Wait "
1095 "an interval time equal to: "
1097 << " before to tx a TRIGGER pck." << std::endl;
1098 if (debugMio_)
1100 << NOW << "uwUFetch_AUV(" << addr
1101 << ")::stateIdle_AUV()_______________________.......Waiting"
1102 << std::endl;
1103 if (debugMio_)
1105 << NOW << "uwUFetch_AUV(" << addr
1106 << ")::stateIdle_AUV()_______________________.......Waiting"
1107 << std::endl;
1108 if (debugMio_)
1110 << NOW << "uwUFetch_AUV(" << addr
1111 << ")::stateIdle_AUV()_______________________.......Waiting"
1112 << std::endl;
1113
1115 }
1116} // end stateIdle_AUV()
1117
1118void
1120{
1121 // The timeout is expired, so now the AUV node can transmit a TRIGGER
1122 // packet. Before to transmit a TRIGGER packet, AUV
1123 // must be created It.
1124 if (debug_)
1125 std::cout << NOW << " uwUFetch_AUV (" << addr
1126 << ") ::TriggerTOExpired() --->AUV now can start the "
1127 "transmission of the"
1128 << " TRIGGER packet in broadcast to the HNs." << std::endl;
1129
1130 if (debugMio_)
1131 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1132 << ")::TriggerTOExpired()____________________Start "
1133 "the communication with HNs."
1134 << std::endl;
1135
1136 txTRIGGEREnabled = true;
1137 rxRTSEnabled = false;
1138
1141
1142} // end TRIGGERTOExpired()
1143
1144void
1146{
1147
1148 if (typeCommunication()) {
1149 // Communication between HN & AUV without RTS and CTS packets
1151
1152 } else {
1153 // Communication between HN & AUV with RTS and CTS packets
1157
1158 if (debug_)
1159 std::cout << NOW << " uwUFetch_AUV (" << addr
1160 << ") ::state_TRIGGER_tx() ---->AUV is initializing the "
1161 "TRIGGER packet that"
1162 << " will then transmitted to the HNs in broadcast. Only "
1163 "after the end of transmission of TRIGGER"
1164 << " the AUV will enabled to receive a RTS packet."
1165 << std::endl;
1166
1167 Packet *p = Packet::alloc(); // allocate the memory for the packet
1168 hdr_cmn *cmh = hdr_cmn::access(p);
1169 hdr_mac *mach = HDR_MAC(p);
1171
1172 cmh->ptype() = PT_TRIGGER_UFETCH; // assign the type of the packet
1173
1174 mach->set(MF_CONTROL, addr, MAC_BROADCAST); // set the information of
1175 // the packet (type,source
1176 // address,destination
1177 // address)
1178 mach->macSA() = addr; // set the source address as AUV MAC address
1179 mach->macDA() = MAC_BROADCAST; // set the destination address as
1180 // BROADCAST address
1181
1182 // Filling the header of TRIGGER packet e determine the size of the
1183 // TRIGGER packet
1184 triggerh->t_min() = (int) (T_MIN_RTS * 1000); // minimum value for to
1185 // choose the back-off
1186 // time for tx RTS pck
1187 triggerh->t_max() = (int) (T_MAX_RTS * 1000); // maximum value for to
1188 // choose the back-off
1189 // time for tx RTS pck
1190 triggerh->max_pck_want_rx() =
1191 NUM_MAX_DATA_AUV_WANT_RX; // maximum number of DATA packets that
1192 // the AUV want to receive from the HN
1193 cmh->size() = sizeof(
1194 hdr_TRIGGER_UFETCH); // set the size of TRIGGER header packet
1195
1196 if (debugMio_)
1197 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1198 << ")::state_TRIGGER_tx()____________________"
1199 "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
1200 "TTTTTTTTTTTTTTTTTTTTTT"
1201 << std::endl;
1202 if (debugMio_)
1203 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1204 << ")::state_TRIGGER_tx()____________________"
1205 "PARAMETERS of TRIGGER PACKET. "
1206 << std::endl;
1207 if (debugMio_)
1208 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1209 << ")::state_TRIGGER_tx()____________________"
1210 "Source address: "
1211 << mach->macSA() << std::endl;
1212 if (mach->macDA() == -1) {
1213 if (debugMio_)
1214 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1215 << ")::state_TRIGGER_tx()____________________"
1216 "Destination Address: BROADCAST."
1217 << std::endl;
1218 } else {
1219 if (debugMio_)
1220 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1221 << ")::state_TRIGGER_tx()____________________"
1222 "Destination Address: "
1223 << mach->macDA() << std::endl;
1224 }
1225 if (debugMio_)
1226 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1227 << ")::state_TRIGGER_tx()____________________MIN "
1228 "backoff time DATA pck: "
1229 << T_MIN_RTS << "[s]." << std::endl;
1230 if (debugMio_)
1231 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1232 << ")::state_TRIGGER_tx()____________________MAX "
1233 "backoff time DATA pck: "
1234 << T_MAX_RTS << "[s]." << std::endl;
1235 if (debugMio_)
1236 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1237 << ")::state_TRIGGER_tx()____________________MAX "
1238 "DATA pck want rx from HN: "
1239 << triggerh->max_pck_want_rx() << "[pck]."
1240 << std::endl;
1241 if (debugMio_)
1242 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1243 << ")::state_TRIGGER_tx()____________________Size "
1244 "of TRIGGER pck: "
1245 << cmh->size() << "[byte]." << std::endl;
1246 if (debugMio_)
1247 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1248 << ")::state_TRIGGER_tx()____________________"
1249 "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
1250 "TTTTTTTTTTTTTTTTTTTTTT"
1251 << std::endl;
1252
1253 // Create a copy f the TRIGGER packet
1254 curr_TRIGGER_pck_tx = p->copy();
1255
1256 // DE-allocate the memory occupied by TRIGGER packet
1257 Packet::free(p);
1258
1259 // Recall the function that simulate the transmission of the trigger
1261 TRIGGER_tx();
1262 }
1263
1264} // end state_TRIGGER_tx()
1265
1266void
1268{
1269 if (typeCommunication()) {
1270 // Communication between HN & AUV without RTS and CTS packets
1272
1273 } else {
1274 // Communication between HN & AUV with RTS and CTS packets
1276 }
1277} // end TRIGGER_tx()
1278
1279void
1281{
1282
1283 if (T_RTS < 0) {
1284 if (debug_)
1285 std::cout << NOW << " uwUFetch_AUV (" << addr
1286 << ") ::state_wait_RTS() ---->The waiting time for RTS "
1287 "packets is negative"
1288 << " so set the default value: 10[s]." << std::endl;
1289 T_RTS = 10;
1290 }
1291
1292 if (debug_)
1293 std::cout << NOW << " uwUFetch_AUV (" << addr
1294 << ") ::state_wait_RTS() ---->AUV is scheduling RTS TIMER T= "
1295 << T_RTS
1296 << "[s]. In this interval AUV waiting the RTS packets."
1297 << std::endl;
1298
1302
1303 if (debugMio_)
1305 << NOW << "uwUFetch_AUV(" << addr
1306 << ")::state_wait_RTS()______________________Waiting a RTS pck."
1307 << std::endl;
1308 if (debugMio_)
1309 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1310 << ")::state_wait_RTS()______________________Timeout "
1311 "within rx RTS pck: "
1312 << T_RTS << "[s]." << std::endl;
1313 if (debugMio_)
1314 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1315 << ")::state_wait_RTS()______________________........"
1316 "Waiting RTS."
1317 << std::endl;
1318 if (debugMio_)
1319 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1320 << ")::state_wait_RTS()______________________........"
1321 "Waiting RTS."
1322 << std::endl;
1323 if (debugMio_)
1324 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1325 << ")::state_wait_RTS()______________________........"
1326 "Waiting RTS."
1327 << std::endl;
1328
1329 rxRTSEnabled = true;
1330
1332
1333} // end state_wait_RTS();
1334
1335void
1337{
1338
1339 hdr_mac *mach = HDR_MAC(curr_RTS_pck_rx);
1341
1350 double bck_time_choice_rts_by_HN = (double) rtsh->backoff_time_RTS() / 1000;
1351
1352 Q_rts_mac_HN.push(mach->macSA()); // store the MAC address of the HN that
1353 // has sent the RTS packet to the AUV
1354 Q_rts_n_pcks_HN_want_tx_AUV.push(rtsh->num_DATA_pcks()); // store the number
1355 // of DATA packets
1356 // that the HN want
1357 // to tx to
1358 // the AUV
1359 Q_rts_backoff_time.push(bck_time_choice_rts_by_HN); // store the back-off
1360 // time choice by the HN
1361 // before to transmit
1362 // a RTS packet
1363
1364 if (debugMio_)
1365 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1366 << ")::RTS_rx()______________________________"
1367 "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR"
1368 "RRRRRRRRRRRRRRRRRR"
1369 << std::endl;
1370 if (debugMio_)
1371 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1372 << ")::RTS_rx()______________________________"
1373 "PARAMETERS of RTS PACKET. "
1374 << std::endl;
1375 if (debugMio_)
1377 << NOW << "uwUFetch_AUV(" << addr
1378 << ")::RTS_rx()______________________________Source address: "
1379 << mach->macSA() << "." << std::endl;
1380 if (debugMio_)
1381 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1382 << ")::RTS_rx()______________________________"
1383 "Destination address: "
1384 << mach->macDA() << "." << std::endl;
1385 if (debugMio_)
1386 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1387 << ")::RTS_rx()______________________________RTS "
1388 "backoff time choice by HN: "
1389 << bck_time_choice_rts_by_HN << "[s]." << std::endl;
1390 if (debugMio_)
1391 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1392 << ")::RTS_rx()______________________________Number "
1393 "of pck HN would like to tx: "
1394 << rtsh->num_DATA_pcks() << "[pck]." << std::endl;
1395 if (debugMio_)
1396 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1397 << ")::RTS_rx()______________________________"
1398 "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR"
1399 "RRRRRRRRRRRRRRRRRR"
1400 << std::endl;
1401
1402 Packet::free(curr_RTS_pck_rx);
1403
1404 if (getTrigger_Tx_by_AUV() == 1) {
1405 // This mean that the AUV has received the RTS after the sending of
1406 // trigger,
1407 // so AUV before proceeding with the transmission of CTS it must reset
1408 // the RTS timer.
1409 if (debugMio_)
1410 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1411 << ")::RTS_rx()______________________________"
1412 "RESET RTS timeout."
1413 << std::endl;
1414 RTS_timer.force_cancel();
1415 rxRTSEnabled = false;
1416 txCTSEnabled = true;
1417
1419 state_CTS_tx();
1420 } else {
1421 // This mean that the AUV has received the RTS without the sending of
1422 // trigger,
1423 // so AUV before proceeding with the transmission of CTS it must reset
1424 // the RTS timer and Trigger timer.
1425 Trigger_timer.force_cancel();
1426 if (debugMio_)
1427 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1428 << ")::RTS_rx()______________________________"
1429 "RESET RTS timeout."
1430 << std::endl;
1431 RTS_timer.force_cancel();
1432 rxRTSEnabled = false;
1433 txCTSEnabled = true;
1434
1436 state_CTS_tx();
1437 }
1438} // end RTS_rx();
1439
1440void
1442{
1443
1444 if (debug_)
1445 std::cout << NOW << " uwUFetch_AUV (" << addr
1446 << ") ::RtsTOExpired() ---->RTS timeout is expired: other"
1447 << " RTS packets can not be received by the AUV."
1448 << std::endl;
1449
1450 if (debugMio_)
1451 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1452 << ")::RtsTOExpired()________________________RTS "
1453 "timeout is expired."
1454 << std::endl;
1455
1456 if (!Q_rts_mac_HN.empty()) {
1457 // Queue is not empty.
1458 if (debug_)
1459 std::cout
1460 << NOW << " uwUFetch_AUV (" << addr
1461 << ") ::RtsTOExpired() ---->AUV has received "
1462 << Q_rts_mac_HN.size() << " RTS"
1463 << " packets within the interval time pre-established, so "
1464 << " transmit a CTS packet." << std::endl;
1465 if (debugMio_)
1466 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1467 << ")::RtsTOExpired()________________________At "
1468 "least one RTS pck it was rx."
1469 << std::endl;
1470
1471 rxRTSEnabled = false;
1472 txCTSEnabled = true;
1473
1476 state_CTS_tx();
1477
1478 } else {
1479 // Queue is empty.
1480 if (debug_)
1481 std::cout << NOW << " uwUFetch_AUV (" << addr
1482 << ") ::RtsTOExpired() ---->AUV has received 0 RTS "
1483 "packets within the interval"
1484 << " time pre-established, so return in IDLE STATE."
1485 << std::endl;
1486 if (debugMio_)
1487 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1488 << ")::RtsTOExpired()________________________0 "
1489 "RTS pck it was rx."
1490 << std::endl;
1491
1493 n_RTS_rx_by_AUV = 0;
1494 n_CTS_tx_by_AUV = 0;
1495 n_DATA_rx_by_AUV = 0;
1496
1497 txTRIGGEREnabled = true;
1498 rxRTSEnabled = false;
1499
1501 stateIdle_AUV(); // AUV return in IDLE state
1502 }
1503} // end RtsTOExpired
1504
1505void
1507{
1508
1509 if (debug_)
1510 std::cout << NOW << " uwUFetch_AUV (" << addr
1511 << ") ::state_CTS_tx() ---->AUV is creating a CTS packet that"
1512 << " will then transmit at the first node of the queue that "
1513 "contain the RTS'received."
1514 << std::endl;
1515 if (debugMio_)
1516 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1517 << ")::state_CTS_tx()________________________"
1518 "Initializing CTS pck."
1519 << std::endl;
1520
1524
1525 Packet *p = Packet::alloc();
1526 hdr_cmn *cmh = hdr_cmn::access(p);
1527 hdr_mac *mach = HDR_MAC(p);
1528 hdr_CTS_UFETCH *ctsh = HDR_CTS_UFETCH(p);
1529
1530 cmh->ptype() = PT_CTS_UFETCH;
1531 cmh->size() = sizeof(hdr_CTS_UFETCH);
1532
1533 mach->set(MF_CONTROL, addr, Q_rts_mac_HN.front());
1534 mach->macSA() = addr;
1535 mach->macDA() = Q_rts_mac_HN.front();
1536
1537 // Filling the HEADER of the CTS packet
1539 ctsh->num_DATA_pcks_MAX_rx() =
1540 Q_rts_n_pcks_HN_want_tx_AUV.front(); // Maximum number of DATA
1541 // packets that the AUV
1542 // want to
1543 // receive from the HN that is being to cts
1544 } else {
1545 ctsh->num_DATA_pcks_MAX_rx() =
1546 NUM_MAX_DATA_AUV_WANT_RX; // Maximum number of DATA packets that
1547 // the AUV want to
1548 // receive from the HN that is being to cts
1549 }
1550
1552 ctsh->mac_addr_HN_ctsed() = Q_rts_mac_HN.front(); // Mac address of the HN
1553 // that the AUV is being
1554 // to cts
1555 mac_addr_HN_ctsed = Q_rts_mac_HN.front(); // Store the mac address of the HN
1556 // that the AUV is being
1557 // to cts
1558
1559 curr_CTS_pck_tx = p->copy();
1560
1561 if (debugMio_)
1562 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1563 << ")::state_CTS_tx()________________________"
1564 "SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS"
1565 "SSSSSSSSSSSSSSSSSS"
1566 << std::endl;
1567 if (debugMio_)
1568 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1569 << ")::state_CTS_tx()________________________"
1570 "PARAMETERS OF CTS PCK."
1571 << std::endl;
1572 if (debugMio_)
1574 << NOW << "uwUFetch_AUV(" << addr
1575 << ")::state_CTS_tx()________________________Source address: "
1576 << mach->macSA() << std::endl;
1577 if (debugMio_)
1578 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1579 << ")::state_CTS_tx()________________________"
1580 "Destination address: "
1581 << mach->macDA() << std::endl;
1582 if (debugMio_)
1583 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1584 << ")::state_CTS_tx()________________________DATA pck "
1585 "want rx from HN: "
1586 << number_data_pck_AUV_rx_exact << "[pck]."
1587 << std::endl;
1588 if (debugMio_)
1590 << NOW << "uwUFetch_AUV(" << addr
1591 << ")::state_CTS_tx()________________________Size of CTS pck: "
1592 << cmh->size() << "[byte]." << std::endl;
1593 if (debugMio_)
1594 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1595 << ")::state_CTS_tx()________________________"
1596 "SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS"
1597 "SSSSSSSSSSSSSSSSSS"
1598 << std::endl;
1599
1600 Packet::free(p); // de-allocate the memory
1601
1602 txCTSEnabled = true;
1603
1605 CTS_tx();
1606} // end state_CTS_tx();
1607
1608void
1610{
1611
1613
1614} // end state_CTS_tx();
1615
1616void
1618{
1619
1620 if (typeCommunication()) {
1621 // Communication between HN & AUV without RTS and CTS packets
1623
1624 } else {
1625 // Communication between HN & AUV with RTS and CTS packets
1626 if (debugMio_)
1628 << NOW << "uwUFetch_AUV(" << addr
1629 << ")::state_wait_first_DATA()_______________Waiting DATA"
1630 << " pck number " << (getData_Rx_by_AUV() + 1)
1631 << " from HN(" << mac_addr_HN_ctsed << ")" << std::endl;
1632
1636
1637 data_timeout =
1638 getDataTimerValue(); // Compute the timeout interval within
1639 // AUV want to receive all DATA packets from HN
1640 if (debug_)
1641 std::cout << NOW << " uwUFetch_AUV (" << addr
1642 << ") ::state_wait_first_DATA() ---->AUV want to receive "
1643 "all the DATA packets"
1644 << " from the HN (" << mac_addr_hn_triggered
1645 << ") within an interval time: " << data_timeout
1646 << " [s]." << std::endl;
1647
1648 if (debugMio_)
1649 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1650 << ")::state_wait_first_DATA()_______________"
1651 "Timeout within rx all DATA"
1652 << " pcks " << data_timeout << " [s]."
1653 << std::endl;
1654
1655 if (debugMio_)
1656 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1657 << ")::state_wait_first_DATA()_______________....."
1658 "..Waiting DATA"
1659 << std::endl;
1660 if (debugMio_)
1661 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1662 << ")::state_wait_first_DATA()_______________....."
1663 "..Waiting DATA"
1664 << std::endl;
1665 if (debugMio_)
1666 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1667 << ")::state_wait_first_DATA()_______________....."
1668 "..Waiting DATA"
1669 << std::endl;
1670
1671 rxDATAEnabled = true;
1672
1674 }
1675
1676} // end state_wait_first_DATA();
1677
1678void
1680{
1681
1685
1686 hdr_mac *mach = HDR_MAC(curr_DATA_pck_rx);
1687
1692 mac_addr_HN_in_data = mach->macSA(); // Source MAC address of the HN that
1693 // has transmitted the DATA packet to
1694 // the AUV
1695
1696 if (debug_)
1697 std::cout << NOW << " uwUFetch_AUV (" << addr
1698 << ") ::DATA_Rx() ---->AUV has received the DATA packet"
1699 << " number: " << getData_Rx_by_AUV() << " from the HN with"
1700 << " MAC address: " << mac_addr_HN_in_data << "."
1701 << std::endl;
1702
1707 Q_data_AUV.push(
1709 ->copy()); // Save the data packets in the QUEUE of the AUV
1710 sendUp(curr_DATA_pck_rx->copy()); // Pass the DATA packets received from the
1711 // AUV at the CBR level
1712 Q_data_AUV.pop();
1713
1714 Packet::free(curr_DATA_pck_rx);
1715
1716 if (debug_)
1717 std::cout << NOW << " uwUFetch_AUV (" << addr
1718 << ") ::DATA_Rx() ----> The DATA packet is passed to the "
1719 "APPLICATION"
1720 << " layer of the AUV." << std::endl;
1721 if (debugMio_)
1723 << NOW << "uwUFetch_AUV(" << addr
1724 << ")::DATA_Rx()_____________________________DATA pck number "
1725 << getData_Rx_by_AUV() << " is passed to the APP layer."
1726 << std::endl;
1727
1729 num_pck_hn_1++;
1730 if (debugMio_)
1731 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1732 << ")::DATA_Rx()_____________________________"
1733 "Total DATA pck rx by HN("
1734 << HEAD_NODE_1 << "): " << num_pck_hn_1 << "."
1735 << std::endl;
1736 } else if (mac_addr_HN_in_data == HEAD_NODE_2) {
1737 num_pck_hn_2++;
1738 if (debugMio_)
1739 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1740 << ")::DATA_Rx()_____________________________"
1741 "Total DATA pck rx by HN("
1742 << HEAD_NODE_2 << "): " << num_pck_hn_2 << "."
1743 << std::endl;
1744 } else if (mac_addr_HN_in_data == HEAD_NODE_3) {
1745 num_pck_hn_3++;
1746 if (debugMio_)
1747 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1748 << ")::DATA_Rx()_____________________________"
1749 "Total DATA pck rx by HN("
1750 << HEAD_NODE_3 << "): " << num_pck_hn_3 << "."
1751 << std::endl;
1752 } else if (mac_addr_HN_in_data == HEAD_NODE_4) {
1753 num_pck_hn_4++;
1754 if (debugMio_)
1755 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1756 << ")::DATA_Rx()_____________________________"
1757 "Total DATA pck rx by HN("
1758 << HEAD_NODE_4 << "): " << num_pck_hn_4 << "."
1759 << std::endl;
1760 }
1761 if (debugMio_)
1762 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1763 << ")::DATA_Rx()_____________________________"
1764 "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
1765 "DDDDDDDDDDDDDDDDDD"
1766 << std::endl;
1767
1769} // end DATA_rx();
1770
1771void
1773{
1774
1778
1779 if (debug_)
1780 std::cout << NOW << " uwUFetch_AUV (" << addr
1781 << ") ::state_Wait_DATA() ---->AUV is waiting to receive the "
1782 "DATA packet"
1783 << " number: " << (getData_Rx_by_AUV() + 1)
1784 << " from HN with MAC address: " << mac_addr_HN_ctsed
1785 << std::endl;
1786
1787 if (debugMio_)
1789 << NOW << "uwUFetch_AUV(" << addr
1790 << ")::state_wait_DATA()_____________________Waiting DATA"
1791 << " packet number " << (getData_Rx_by_AUV() + 1) << "."
1792 << std::endl;
1793
1794 if (debugMio_)
1795 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1796 << ")::state_wait_DATA()_____________________......."
1797 "Waiting DATA"
1798 << std::endl;
1799 if (debugMio_)
1800 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1801 << ")::state_wait_DATA()_____________________......."
1802 "Waiting DATA"
1803 << std::endl;
1804 if (debugMio_)
1805 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1806 << ")::state_wait_DATA()_____________________......."
1807 "Waiting DATA"
1808 << std::endl;
1809
1810} // end state_wait_DATA();
1811
1812void
1814{
1815
1816 if (debug_)
1817 std::cout << NOW << " uwUFetch_AUV (" << addr
1818 << ") ::DataTOExpired() ---->AUV has not received all the "
1819 "DATA packets"
1820 << " within the time interval pre-established, so return in "
1821 "IDLE STATE."
1822 << std::endl;
1823
1824 if (debugMio_)
1825 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1826 << ")::DataTOExpired()_______________________DATA "
1827 "timeout expired."
1828 << std::endl;
1829 if (debugMio_)
1830 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1831 << ")::DataTOExpired()_______________________Total "
1832 "DATA pck rx from HN("
1833 << mac_addr_HN_in_data << ") is/are "
1834 << getData_Rx_by_AUV() << std::endl;
1835
1837
1839 n_RTS_rx_by_AUV = 0;
1840 n_CTS_tx_by_AUV = 0;
1841 n_DATA_rx_by_AUV = 0;
1842
1843 txTRIGGEREnabled = true;
1844 rxDATAEnabled = false;
1845
1848 // reason for the
1849 // changing of the
1850 // state
1851 stateIdle_AUV(); // AUV return in IDLE state
1852
1853} // end DataTOExpired();
1854
1855/******************************************************************************
1856 * METODI AUSILIARI *
1857 ******************************************************************************/
1858bool
1860{
1861 if (mode_comm_hn_auv == 1) {
1862 return true;
1863 } else {
1864 return false;
1865 }
1866} // end isHeadNode();
1867
1868double
1870{
1871
1872 if (debug_)
1873 std::cout << NOW << " uwUFetch_AUV (" << addr
1874 << ") ::getDataTimerValue() ----> AUV is computing the time "
1875 "interval"
1876 << " within it want to receive all DATA packets from the HN."
1877 << std::endl;
1878
1879 RTT = 0;
1881 RTT = getRTT();
1882
1890 double data_timeout_cnt =
1892
1893 return data_timeout_cnt;
1894
1895} // end getDataTimerValue()
1896
1897void
1899{
1900
1901 int size_pck = 0;
1903 size_pck = sizeof(hdr_TRIGGER_UFETCH);
1904 T_tx_TRIGGER = size_pck / BIT_RATE_SERVICE;
1905 } else {
1906 size_pck = MAX_PAYLOAD;
1907 Tdata = size_pck / BIT_RATE_INSTANT;
1908 }
1909 // Packet* simple_pck = Packet::alloc();
1910 // hdr_cmn* cmh = HDR_CMN(simple_pck);
1911 // cmh->size() = MAX_PAYLOAD;
1912 // Tdata = Mac2PhyTxDuration(simple_pck);
1913 // Packet::free(simple_pck);
1914} // end computeTxTime()
1915
1916double
1918{
1919 RTT = 4000 / v_speed_sound; // 4000 because is the maximum distance between
1920 // AUV and HN.
1921 // The exactly distance is 3500 but I have floor this distance at 4000[m]
1922 return RTT;
1923} // end getRTT();
1924
1925void
1927{
1928 if (debug_)
1929 std::cout << NOW << " uwUFetch_AUV (" << addr
1930 << ") ::updateQueueRTS() ---->AUV remove the HN from the "
1931 "list of queue"
1932 << " node from which it has received the RTS packets."
1933 << std::endl;
1934 if (debugMio_)
1935 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1936 << ")::updateQueueRTS()______________________Update "
1937 "the queue of RTS received."
1938 << std::endl;
1939 while (!Q_rts_mac_HN.empty()) {
1940 Q_rts_mac_HN.pop();
1942 Q_rts_backoff_time.pop();
1943 }
1944}
1945
1946void
1948{
1953 // Other data packet can not be received by the AUV
1954 if (debug_)
1955 std::cout << NOW << " uwUFetch_AUV (" << addr
1956 << ") ::another_DATA_received() ---->AUV has received "
1957 "all the DATA packets from HN"
1958 << " with MAC address: " << mac_addr_HN_in_data
1959 << ", so return in IDLE STATE." << std::endl;
1960
1961 if (debugMio_)
1962 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1963 << ")::another_DATA_received()_______________ALL "
1964 "DATA pck rx"
1965 << " from HN(" << mac_addr_HN_in_data << ")."
1966 << std::endl;
1967
1969
1970 if (debug_)
1971 std::cout << NOW << " uwUFetch_AUV (" << addr
1972 << ") ::another_DATA_received() ---->AUV reset DATA "
1973 "timeout."
1974 << std::endl;
1975 if (debugMio_)
1976 out_file_logging << NOW << "uwUFetch_AUV(" << addr
1977 << ")::another_DATA_received()_______________"
1978 "Reset DATA timeout."
1979 << std::endl;
1980
1981 DATA_timer.force_cancel(); // reset the DATA timer
1982
1984 n_RTS_rx_by_AUV = 0;
1985 n_CTS_tx_by_AUV = 0;
1986 n_DATA_rx_by_AUV = 0;
1987
1988 txTRIGGEREnabled = true;
1989 rxDATAEnabled = false;
1990
1992 stateIdle_AUV();
1993
1994 } else {
1995 // Another data packet can be received
1996 if (debug_)
1997 std::cout << NOW << " uwUFetch_AUV (" << addr
1998 << ") ::another_DATA_received() ---->AUV can receive "
1999 "another DATA packet from the "
2000 << " HN with MAC address: " << mac_addr_HN_in_data << ". "
2001 << " The DATA packet number: "
2002 << (getData_Rx_by_AUV() + 1) << std::endl;
2003
2004 if (debugMio_)
2005 out_file_logging << NOW << "uwUFetch_AUV(" << addr
2006 << ")::another_DATA_received()_______________"
2007 "Another DATA pck can rx. Number "
2008 << (getData_Rx_by_AUV() + 1) << "." << std::endl;
2009 rxDATAEnabled = true;
2010
2013 }
2014} // end another_DATA_received();
2015
2016/******************************************************************************
2017 * METODI EXTRA *
2018 ******************************************************************************/
2019
2020void
2022{
2023 if (module->debug_)
2024 std::cout << NOW << " uwUFetch_AUV (" << module->addr
2025 << ")::UWUFetch_TRIGGER_timer::expire() ---->TRIGGER timeout "
2026 "expired."
2027 << std::endl;
2029
2030 module->TriggerTOExpired();
2031} // end UWUFetch_TRIGGER_timer::expire()
2032
2033void
2035{
2036 if (module->debug_)
2037 std::cout
2038 << NOW << " uwUFetch_AUV (" << module->addr
2039 << ") ::UWUFetch_RTS_timer::expire() ---->RTS timeout expired."
2040 << std::endl;
2041 timer_status = UWUFETCH_TIMER_STATUS_EXPIRED;
2042
2043 module->RtsTOExpired();
2044} // end uwUFetch_RTS_timer::expire()
2045
2046void
2048{
2049 if (module->debug_)
2050 std::cout
2051 << NOW << " uwUFetch_AUV (" << module->addr
2052 << ")::UWUFetch_DATA_timer::expire() ---->DATA timeout expired"
2053 << std::endl;
2054 timer_status = UWUFETCH_TIMER_STATUS_EXPIRED;
2055
2056 module->DataTOExpired();
2057} // end UWUFetch_DATA_timer::expire()
2058
2059void
2061{
2062 fout << NOW << "uwUFetch(" << addr << ")::printStateInfo() "
2063 << "from " << statusInfo[prev_state] << " to "
2064 << statusInfo[curr_state] << ". Reason: " << statusChange[last_reason]
2065 << std::endl;
2066} // end printStateInfo()
2067
2068void
2070{
2071 initialized = true;
2072
2073 if ((print_transitions) && (system(NULL))) {
2074 system("rm -f /tmp/uwUFetch_AUV_stateTransitions.txt");
2075 system("touch /tmp/uwUFetch_AUV_stateTransitions.txt");
2076 }
2077
2078 statusInfo[UWUFETCH_AUV_STATUS_IDLE] = "AUV is in IDLE state ";
2080 "AUV is transmitting a TRIGGER packet ";
2082 "AUV is waiting a RTS packet from HN ";
2084 "AUV has received a RTS packet ";
2086 "AUV is transmitting a CTS packet ";
2088 "AUV is waiting DATA packet from HN ";
2090 "AUV has receive a DATA packet from HN ";
2091
2093 "Trigger TO is expired, so the AUV start the transmission of "
2094 "TRIGGER packet";
2096 "AUV has finished to initialize the TRIGGER packet, so pass "
2097 "the packet to the physical layer";
2099 "AUV has finished to transmit a TRIGGER packet, so enter in the "
2100 "state in"
2101 " which it wait a RTS packet";
2103 "AUV has finishe to receive a RTS packet, so go to the state in "
2104 "which"
2105 " the RTS is analyzed.";
2107 "AUV has finished to store the information of the RTS packet, so "
2108 "go to"
2109 " the state in which initiale the CTS packet";
2112 "RTS timeout is expired and another RTS can not be "
2113 "received, "
2114 "but at least one RTS has been received, so go to the state"
2115 " in which initialize the CTS packet";
2117 "RTS timeout is expired and another RTS can not be received, "
2118 "but zero RTS has been received, so go to the state idle";
2120 "AUV has finished to initialize the CTS packet, so go to the state"
2121 " in which AUV recall the physical layer";
2123 "AUV has finished to transmit a CTS packet, so go to the state in "
2124 "which the"
2125 " the AUV wait a DATA packets from the HN";
2127 "AUV has finished to receive the DATA packet, so go to the DATA "
2128 "receive method and analyzed it";
2130 "AUV has received the LAST DATA packet from HN, so go to the IDLE "
2131 "state";
2133 "AUV has received a DATA packet, and another DATA packet can be "
2134 "received by It, so go to the waiting state in which it wait "
2135 "another"
2136 " DATA packet.";
2138 "DATA timeout expired, all the packets are not received by the HN, "
2139 "so"
2140 "go to the IDLE stae";
2142 "AUV has received a packet that is not addressed to It";
2143
2145 packetType[UWUFETCH_AUV_PACKET_TYPE_TRIGGER] = "TRIGGER packet";
2148
2149 statusTimer[UWUFETCH_TIMER_STATUS_IDLE] = "AUV is in Idle";
2150 statusTimer[UWUFETCH_TIMER_STATUS_RUNNING] = "AUV is running";
2151 statusTimer[UWUFETCH_TIMER_STATUS_FROZEN] = "AUV is Freezing";
2152 statusTimer[UWUFETCH_TIMER_STATUS_EXPIRED] = "AUV timeout expired";
2153
2154} // end initInfo()
2155
2156void
2158{
2159 std::string response;
2160 std::cout << "Press Enter to continue";
2161 std::getline(std::cin, response);
2162}
Class that represents the binding with the TCL configuration script.
uwUFetchAUVModuleClass()
Constructor of the class uwUFetchAUV.
TclObject * create(int, const char *const *)
Creates the TCL object needed for the TCL language interpretation.
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.
virtual void schedule(double val)
Schedule a timer.
uwUFetch_AUV *UWUFETCH_TIMER_STATUS timer_status
< Pointer to an object of type uwUFetch_AUV
Class that represent the UFetch mac layer for AUV node.
@ UWUFETCH_AUV_PACKET_TYPE_CTS
@ UWUFETCH_AUV_PACKET_TYPE_TRIGGER
@ UWUFETCH_AUV_PACKET_TYPE_DATA
@ UWUFETCH_AUV_PACKET_TYPE_RTS
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
int num_pck_hn_1
Counter of the correct DATA packets received by HN 1 from SNs.
double tx_CTS_start_time
Indicates when AUV start a transmission of CTS packet.
virtual double getDataTimerValue()
Compute the length of time interval within AUV want to receive all DATA packet from specifical HN.
int getTrigger_Tx_by_AUV()
Number of TRIGGER packets transmitted during the simulation during the single cycle.
int n_DATA_rx_by_AUV
Counter of the number of DATA packets transmitted by AUV during a single cycle of simulation.
int n_RTS_rx_by_AUV
Counter of the number of RTS packets received by AUV during a single cycle of simulation.
int getTotal_Data_Rx_by_AUV()
Total number of DATA packets received by AUV from all HNs of the netwrok during the simulation.
uwUFetch_RTS_timer RTS_timer
Interval time in which the AUV wait a RTS packets from the HNs.
int HEAD_NODE_4
Id number of HN 4.
virtual void Phy2MacEndTx(const Packet *p)
Handle the end-of-PHY-transmission event.
double MAX_PAYLOAD
Maximum size of DATA PAYLOAD packet.
int num_pck_hn_3
Counter of the correct DATA packets received by HN 3 from SNs.
int number_data_pck_AUV_rx_exact
Number of DATA packets that AUV want exactly received from the HN.
double rx_RTS_start_time
Indicates when AUV start the reception of RTS packet.
UWUFETCH_AUV_STATUS prev_state
Previous state in which the node it was located.
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...
uwUFetch_AUV()
Constructor of the class UWUFetch.
bool txTRIGGEREnabled
true if AUV is enabled to transmit a TRIGGER packet
UWUFETCH_AUV_STATUS_CHANGE last_reason
Last reason because the NODE change his state.
std::queue< int > Q_rts_n_pcks_HN_want_tx_AUV
Queue that store the number of DATA packets that the single HN want to tx to the AUV.
int debugMio_
Used if we want to create the logging file.
virtual double getRTT()
Compute the Round Trip Time.
UWUFETCH_AUV_STATUS curr_state
Current state in which the node is located.
std::ofstream out_file_logging
Variable that handle the file in which the protocol write the statistics.
int mac_addr_HN_ctsed
Mac address of the HN from which the AUV want to receive the DATA packets.
int n_TRIGGER_tx_by_AUV
Counter of the number of TRIGGER packets transmitted by AUV during a single cycle of simulation.
double Tdata
Time needed to transmit a DATA packet.
void incrTotal_Data_Rx_by_AUV()
Increase of 1 the number of DATA packets received by AUV.
virtual void state_CTS_tx()
Initialization of CTS packet that will be forwarded to the specifical HN.
int NUM_HN_NET
Number of Head Nodes in the network.
double RTT
Round Trip Time.
double rx_RTS_finish_time
Indicates when AUV end the reception of RTS packet.
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.
std::ofstream fout
Variable that handle the file in which the protocol write the state transition for debug purposes.
virtual void updateQueueRTS()
Remove the information relative to the HN from which AUV wanted and it has finished to receive DATA p...
void incrTotalRts_Rx_corrupted_by_AUV()
Increase of 1 the number of corrupted RTS packets received by AUV.
@ UWUFETCH_AUV_STATUS_CHANGE_PACKET_FOR_ANOTHER_NODE
@ UWUFETCH_AUV_STATUS_CHANGE_RTS_TO_EXPIRED_0_RTS_RX
@ UWUFETCH_AUV_STATUS_CHANGE_TRIGGER_TO_EXPIRED
@ UWUFETCH_AUV_STATUS_CHANGE_TRIGGER_INITIALIZE_TX_TRIGGER
@ UWUFETCH_AUV_STATUS_CHANGE_RTS_TO_EXPIRED_AT_LEAST_ONE_RTS_RX
@ UWUFETCH_AUV_STATUS_CHANGE_CTS_INITIALIZED_TX_CTS
@ UWUFETCH_AUV_STATUS_CHANGE_RTS_FINISHED_TO_RX
@ UWUFETCH_AUV_STATUS_CHANGE_TRIGGER_TX_WAIT_RTS
@ UWUFETCH_AUV_STATUS_CHANGE_DATA_PCK_FINISHED_TO_RX
@ UWUFETCH_AUV_STATUS_CHANGE_RTS_FINSHED_TO_STORE
@ UWUFETCH_AUV_STATUS_CHANGE_TO_WAIT_DATA_EXPIRED
@ UWUFETCH_AUV_STATUS_CHANGE_ANOTHER_DATA_PCK_RX
@ UWUFETCH_AUV_STATUS_CHANGE_CTS_TX_WAIT_DATA
@ UWUFETCH_AUV_STATUS_CHANGE_LAST_DATA_PCK_RX
int mode_comm_hn_auv
Indicate how the communication takes place with or without RTS-CTS packets.
int getTotalCts_Tx_by_AUV()
Total number of CTS packets transmitted by AUV during the simulation.
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 Mac2PhyStartTx(Packet *p)
This method must be called by the MAC to instruct the PHY to start the transmission of a packet.
virtual void DataTOExpired()
Timeout within received DATA packets is expired.
int num_pck_hn_2
Counter of the correct DATA packets received by HN 2 from SNs.
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.
int N_RUN
Number of run in execution
void incrTotalRts_Rx_by_AUV()
Increase of 1 the number of RTS packets received by AUV.
std::queue< double > Q_rts_backoff_time
Queue that stored the backoff time choice by the single HN before to transmit RTS packet.
double T_MAX_RTS
Upper bound of the interval in which HN choice the back-off time to tx RTS pck.
void incrTotalCts_Tx_by_AUV()
Increase of 1 the number of CTS packets transmitted by AUV.
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 state_TRIGGER_tx()
Initialization of TRIGGER packet that will be forwarded in broadcast to the HNs.
virtual void state_wait_DATA()
AUV is waiting the SECOND and successive DATA packets from HN.
static std::map< UWUFETCH_AUV_PACKET_TYPE, std::string > packetType
Map the UWUFETCH_AUV_PACKET_TYPE to the description of packet type.
bool rxRTSEnabled
true if AUV is enabled to receive a RTS packet
Packet * curr_CTS_pck_tx
Pointer to the CTS packet that is being transmitted by AUV.
uwUFetch_TRIGGER_timer Trigger_timer
Interval time.
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 incrCts_Tx_by_AUV()
Increase of 1 the number of CTS packets transmitted by AUV.
void incrTotalTrigger_Tx_by_AUV()
Increase of 1 the number of TRIGGER packets transmitted by AUV.
double T_START_PROC_TRIGGER
Time before that the AUV start the procedure to transmit a TRIGGER packet.
int getTotal_Data_Rx_corrupted_by_AUV()
Total number of corrupted DATA packets received by the AUV from all HNs of the network.
std::queue< int > Q_rts_mac_HN
Queue of HN MAC address from which AUV has received correctly the RTS packet.
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...
int getTotalRts_Rx_by_AUV()
Total number of RTS received by AUV during the simulation from all HNs of the network.
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.
int n_CTS_tx_by_AUV
Counter of the number of CTS packets transmitted by AUV during a single cycle of simulation.
static std::map< UWUFETCH_TIMER_STATUS, std::string > statusTimer
Map the UWUFETCH_TIMER_STATUS to the description of the timers.
void incrTrigger_Tx_by_AUV()
Increment by 1 the number of TRIGGER packets transmitted by AUV during a single cycle TRIGGER-RTS-CTS...
static bool initialized
Indicate if the protocol has been initialized or not.
double T_GUARD
Guard time interval used between two consecutive transmissions of data packets.
Packet * curr_DATA_pck_rx
Pointer to the DATA packet that is being received by AUV.
@ UWUFETCH_AUV_STATUS_RECEIVE_RTS_PACKET
@ UWUFETCH_AUV_STATUS_TRANSMIT_CTS_PACKET
@ UWUFETCH_AUV_STATUS_WAIT_RTS_PACKET
@ UWUFETCH_AUV_STATUS_RECEIVE_DATA_PACKET
@ UWUFETCH_AUV_STATUS_WAIT_DATA_HN
@ UWUFETCH_AUV_STATUS_TRANSMIT_TRIGGER
virtual void waitForUser()
Method used for debug.
int getData_Rx_by_AUV()
Number of DATA packets received by AUV after the transmission of TRIGGER-RTS-CTS packets from a speci...
virtual ~uwUFetch_AUV()
Destructor of the class UWUFetch.
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.
double T_RTS
Interval time in which the AUV want to receive an RTS packet in answer to the trigger.
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.
virtual void RTS_rx()
AUV has received RTS packet.
bool rxDATAEnabled
true if AUV is enabled to receive a DATA packet
std::queue< Packet * > Q_data_AUV
Queue of DATA packets stored by the AUV and received from HNs.
double rx_DATA_finish_time
Indicates when AUV end the reception of DATA packet.
int num_pck_hn_4
Counter of the correct DATA packets received by HN 4 from SNs.
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.
virtual void initInfo()
Initialize the protocol at the beginning of the simulation.
double rx_DATA_start_time
Indicates when AUV start the reception of DATA packet.
static std::map< UWUFETCH_AUV_STATUS_CHANGE, std::string > statusChange
Map the UWUFETCH_AUV_STATUS_CHANGE to the description the reason of changing state.
Packet * curr_RTS_pck_rx
Pointer to the RTS packet that is being received by AUV.
int getTotalRts_Rx_corrupted_by_AUV()
Total number of corrupted RTS packets received by AUV from all HNs of the network.
int mac_addr_HN_in_data
MAC address of the HN from which the AUV has received the 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.
double T_tx_TRIGGER
Time required to transimt a single TRIGGER 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.
virtual void TriggerTOExpired()
Timeout trigger is expired.
virtual void Phy2MacEndRx(Packet *p)
Handle the end-of-PHY-reception event.
Packet * curr_TRIGGER_pck_tx
Pointer to the TRIGGER packet that is being transmitted by AUV.
virtual void Phy2MacStartRx(const Packet *p)
Handle the detected-start-of-PHY-reception event.
bool txCTSEnabled
true if AUV is enabled to transmit a CTS packet
virtual void state_wait_RTS()
AUV is wait a RTS packet from HNs.
virtual void RtsTOExpired()
Timeout within AUV is enabled to receive RTS packet is expired.
virtual void CTS_tx()
Transmission of CTS packet.
void incrRts_Rx_by_AUV()
Increase of 1 the number of RTS packets received by AUV.
virtual void TRIGGER_tx()
Trasmission of TRIGGER packet.
@ UWUFETCH_TIMER_STATUS_IDLE
@ UWUFETCH_TIMER_STATUS_EXPIRED
@ UWUFETCH_TIMER_STATUS_FROZEN
@ UWUFETCH_TIMER_STATUS_RUNNING
virtual bool typeCommunication()
Establish whether the communication between SN and AUV take place with RTS and CTS or only using TRIG...
virtual int crLayCommand(ClMessage *m)
Cross-Layer messages interpreter.
bool print_transitions
true if the writing of state transitions in the file is enabled.
int getTotalTrigger_Tx_by_AUV()
Total number of TRIGGER packets transmitted by the AUV during the simulation.
static std::map< UWUFETCH_AUV_STATUS, std::string > statusInfo
Map the UWUFETCH_AUV_STATUS to the description of each state.
double tx_CTS_finish_time
Indicates when AUV end the transmission of CTS packet.
Content header of CTS packet.
int & mac_addr_HN_ctsed()
Reference to the mac_addr_HN_ctsed_ variable.
int & num_DATA_pcks_MAX_rx()
Reference to the num_DATA_pcks_MAX_rx_ 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.
uwUFetchAUVModuleClass class_module_uwufetchauv
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_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.
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.
packet_t PT_RTS_UFETCH
RTS packet type for UFetch protocol.
Common structures and variables in the protocol.
#define HDR_CTS_UFETCH(p)
alias defined to access the CTS HEADER
static const int BIT_RATE_INSTANT
#define HDR_TRIGGER_UFETCH(p)
alias defined to access the TRIGGER HEADER
static const int v_speed_sound
Underwater sound propagation speed.
static const int BIT_RATE_SERVICE
#define HDR_RTS_UFETCH(p)
alias defined to access the RTS HEADER