DESERT 3.5.1
Loading...
Searching...
No Matches
uwUFetch_NODE_SENSOR.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 "mac.h"
39#include "mmac.h"
40#include "uwUFetch_NODE.h"
41#include "uwUFetch_cmn_hdr.h"
42//#include "uwmphy_modem_cmn_hdr.h"
43#include "uwcbr-module.h"
44#include <sstream>
45#include <time.h>
46#include "rng.h"
47
49static class uwUFetchNODEModuleClass : public TclClass
50{
51public:
56 : TclClass("Module/UW/UFETCH/NODE")
57 {
58 }
59
60 TclObject *
61 create(int, const char *const *)
62 {
63 return (new uwUFetch_NODE());
64 }
66
68
69std::map<uwUFetch_NODE::UWUFETCH_NODE_STATUS, std::string>
71std::map<uwUFetch_NODE::UWUFETCH_NODE_STATUS_CHANGE, std::string>
73std::map<uwUFetch_NODE::UWUFETCH_NODE_PACKET_TYPE, std::string>
75std::map<uwUFetch_NODE::UWUFETCH_TIMER_STATUS, std::string>
77
82 : /***SENSOR NODE***/
83 // timers
84 BCK_timer_rts(this)
85 , CTS_timer(this)
86 , BCK_timer_data(this)
87 , BCK_timer_probe(this)
88 , POLL_timer(this)
89 , DATA_BEFORE_TX_timer(this)
90 , CBEACON_timer(this)
91 ,
92 // Global Variables that should be never reset
93 rx_BEACON_start_time(0)
94 , rx_BEACON_finish_time(0)
95 , tx_PROBE_start_time(0)
96 , tx_PROBE_finish_time(0)
97 , rx_POLL_start_time(0)
98 , rx_POLL_finish_time(0)
99 , tx_DATA_start_time(0)
100 , tx_DATA_finish_time(0)
101 , rx_CBEACON_start_time(0)
102 , rx_CBEACON_finish_time(0)
103 , n_tot_BEACON_pck_rx_by_NODE(0)
104 , n_tot_BEACON_pck_rx_corr_by_NODE(0)
105 , n_tot_PROBE_pck_tx_by_NODE(0)
106 , n_tot_POLL_pck_rx_by_NODE(0)
107 , n_tot_POLL_pck_rx_corr_by_NODE(0)
108 , n_tot_DATA_pck_tx_by_NODE(0)
109 , n_tot_CBEACON_pck_rx_by_NODE(0)
110 , n_tot_CBEACON_pck_rx_corr_by_NODE(0)
111 , T_min_bck_probe_node(0)
112 , T_max_bck_probe_node(0)
113 , num_cbeacon_node_rx(0)
114 , mac_addr_HN_in_beacon(0)
115 , bck_before_tx_probe(0)
116 , Tprobe(0)
117 , Tdata_NODE(0)
118 , RTT(0)
119 , mac_addr_HN_in_poll(0)
120 , num_pck_to_tx_by_NODE(0)
121 , num_cbeacon_at_now_HN_tx(0)
122 , mac_addr_HN_in_cbeacon(0)
123 ,
124 // Variables that should be reseted when a cycle is end
125 n_BEACON_pck_rx_by_NODE(0)
126 , n_PROBE_pck_tx_by_NODE(0)
127 , n_POLL_pck_rx_by_NODE(0)
128 , n_DATA_pck_tx_by_NODE(0)
129 , n_CBEACON_pck_rx_by_NODE(0)
130 , dataAlreadyTransmitted(false)
131 ,
132 // Variables that enable or not an operation
133 rxBEACONEnabled(false)
134 , txPROBEEnabled(false)
135 , rxPOLLEnabled(false)
136 , txDATAEnabled(false)
137 , rxCBEACONEnabled(false)
138 , curr_BEACON_NODE_pck_rx(NULL)
139 , curr_PROBE_NODE_pck_tx(NULL)
140 , curr_POLL_NODE_pck_rx(NULL)
141 , curr_DATA_NODE_pck_tx(NULL)
142 , curr_CBEACON_NODE_pck_rx(NULL)
143 ,
144 /***HEAD NODE***/
145 // Timers
146 BeaconBeforeTx_timer(this)
147 , PROBE_timer(this)
148 , DATA_timer(this)
149 ,
150 // Global Variables that should be never reset
151 tx_BEACON_start_HN_time(0)
152 , tx_BEACON_finish_HN_time(0)
153 , rx_PROBE_start_HN_time(0)
154 , rx_PROBE_finish_HN_time(0)
155 , tx_POLL_start_HN_time(0)
156 , tx_POLL_finish_HN_time(0)
157 , rx_DATA_start_HN_time(0)
158 , rx_DATA_finish_HN_time(0)
159 , tx_CBEACON_start_HN_time(0)
160 , tx_CBEACON_finish_HN_time(0)
161 , rx_TRIGGER_start_HN_time(0)
162 , rx_TRIGGER_finish_HN_time(0)
163 , tx_RTS_start_HN_time(0)
164 , tx_RTS_finish_HN_time(0)
165 , rx_CTS_start_HN_time(0)
166 , rx_CTS_finish_HN_time(0)
167 , tx_DATA_start_HN_time(0)
168 , tx_DATA_finish_HN_time(0)
169 , n_tot_BEACON_pck_tx_by_HN(0)
170 , n_tot_PROBE_pck_rx_by_HN(0)
171 , n_tot_PROBE_pck_corr_rx_by_HN(0)
172 , n_tot_POLL_pck_tx_by_HN(0)
173 , n_tot_DATA_pck_rx_by_HN(0)
174 , n_tot_DATA_pck_rx_corr_by_HN(0)
175 , n_tot_CBEACON_pck_tx_by_HN(0)
176 , n_tot_TRIGGER_pck_rx_by_HN(0)
177 , n_tot_TRIGGER_pck_rx_corr_by_HN(0)
178 , n_tot_DATA_pck_tx_by_HN(0)
179 , mac_addr_NODE_polled(0)
180 , number_data_pck_HN_rx_exact(0)
181 , pck_number_id(1)
182 , data_timeout(0)
183 , Tbeacon(0)
184 , Tpoll(0)
185 , Tdata_HN(0)
186 , mac_addr_NODE_in_data(0)
187 , T_min_bck_RTS(0)
188 , T_max_bck_RTS(0)
189 , T_min_bck_DATA(0)
190 , T_max_bck_DATA(0)
191 , bck_before_tx_data(0)
192 , mac_addr_AUV_in_trigger(0)
193 , mac_addr_AUV_in_CTS(0)
194 , bck_before_tx_RTS(0)
195 , max_data_HN_can_tx(0)
196 , max_pck_HN_can_tx(0)
197 , Tdata_HN_pck(0)
198 , CTSrx(false)
199 , txRTSbeforeCBEACON(false)
200 , sectionCBeacon(false)
201 ,
202 // Variables that should be reseted when a cycle is end
203 n_BEACON_pck_tx_by_HN(0)
204 , n_PROBE_pck_rx_by_HN(0)
205 , n_POLL_pck_tx_by_HN(0)
206 , n_DATA_pck_rx_by_HN(0)
207 , n_CBEACON_pck_tx_by_HN(0)
208 , n_TRIGGER_pck_rx_by_HN(0)
209 , n_RTS_pck_tx_by_HN(0)
210 , n_CTS_pck_rx_by_HN(0)
211 , n_DATA_pck_tx_by_HN(0)
212 ,
213 // Variables that enable or not an operation
214 txBEACONEnabled(false)
215 , rxPROBEEnabled(false)
216 , txPOLLEnabled(false)
217 , rxDATAEnabled(false)
218 , txCBEACONEnabled(false)
219 , rxTRIGGEREnabled(false)
220 , txRTSEnabled(false)
221 , rxCTSEnabled(false)
222 , txDATAEnabledHN(false)
223 ,
224 // PACKETS create
225 curr_BEACON_HN_pck_tx(NULL)
226 , curr_PROBE_HN_pck_rx(NULL)
227 , curr_POLL_HN_pck_tx(NULL)
228 , curr_DATA_HN_pck_rx(NULL)
229 , curr_CBEACON_HN_pck_tx(NULL)
230 , curr_TRIGGER_HN_pck_rx(NULL)
231 , curr_RTS_HN_pck_tx(NULL)
232 , curr_CTS_HN_pck_rx(NULL)
233 , curr_DATA_HN_pck_tx(NULL)
234 , curr_DATA_NODE_pck_tx_HN(NULL)
235{
236 // variable binding
237 mac2phy_delay_ = 1e-19;
238 bind("TIME_BEFORE_START_COMU_HN_NODE_",
239 (double *) &T_START_PROCEDURE_HN_NODE);
240 bind("MAXIMUM_VALUE_BACKOFF_PROBE_", (double *) &T_MAX_BACKOFF_PROBE);
241 bind("MINIMUM_VALUE_BACKOFF_PROBE_", (double *) &T_MIN_BACKOFF_PROBE);
242 bind("MAXIMUM_NODE_POLLED_", (int *) &MAX_POLLED_NODE);
243 bind("MAXIMUM_PAYLOAD_SIZE_", (int *) &MAX_PAYLOAD);
244 bind("TIME_TO_WAIT_PROBES_PCK_", (double *) &T_PROBE);
245 bind("TIME_TO_WAIT_POLL_PCK_", (double *) &T_POLL);
246 bind("TIME_BETWEEN_2_DATA_TX_HN_",
248 bind("TIME_BETWEEN_2_DATA_TX_NODE_",
250 bind("SEE_THE_TRANSITIONS_STATE_", (int *) &PRINT_TRANSITIONS_INT);
251 bind("GUARD_INTERVAL_", (double *) &T_GUARD);
252 bind("MAXIMUM_BUFFER_SIZE_", (int *) &MAXIMUM_BUFFER_DATA_PCK_NODE);
253 bind("MAXIMUM_CBEACON_TRANSMISSIONS_", (int *) &MAX_ALLOWED_CBEACON_TX);
254 bind("MAXIMUM_PCK_WANT_RX_HN_FROM_NODE_",
256 bind("MY_DEBUG_", (int *) &debugMio_);
257 bind("NUMBER_OF_RUN_", (int *) &N_RUN);
258 bind("TIME_TO_WAIT_CTS_", (double *) &T_CTS);
259 bind("MODE_COMM_", (int *) &MODE_COMM_HN_AUV);
260 bind("BURST_DATA_", (int *) &MODE_BURST_DATA);
261} // end uwUFetch_NODE()
262
263int
265{
266 switch (m->type()) {
267 default:
268 return MMac::crLayCommand(m);
269 }
270} // end crLCommand()
271
273{
274 // nothing to do
275} // end ~uwUFetch_NODE()
276
277int
278uwUFetch_NODE::command(int argc, const char *const *argv)
279{
280 Tcl &tcl = Tcl::instance();
281
282 if (argc == 2) {
283 if (strcasecmp(argv[1], "initialize") == 0) {
284 if (initialized == false)
285 initInfo();
286 if (debug_)
287 fout.open("/tmp/uwUFetch_AUV_stateTransitions.txt",
288 std::ios_base::app);
289 if (debugMio_) {
290 std::stringstream file_logging;
291 file_logging << "uwUFetch_NODE_" << addr << "_N_RUN_" << N_RUN
292 << ".out";
293 out_file_logging.open(
294 file_logging.str().c_str(), std::ios_base::app);
295 }
296 return TCL_OK;
297
298 } else if (strcasecmp(argv[1], "printTransitions") == 0) {
299 print_transitions = true;
300
301 return TCL_OK;
302 } else if (strcasecmp(argv[1], "getDataQueueSize") == 0) {
303
304 return TCL_OK;
305
306 } else if (strcasecmp(argv[1], "getBEACONrxByNODE") == 0) {
307 tcl.resultf("%d", getTotalBeaconPckRx_by_NODE());
308 return TCL_OK;
309
310 } else if (strcasecmp(argv[1], "getBEACONrxCorruptedByNODE") == 0) {
311 tcl.resultf("%d", getTotalBeaconPckRx_corrupted_by_NODE());
312 return TCL_OK;
313
314 } else if (strcasecmp(argv[1], "getPROBEtxByNODE") == 0) {
315 tcl.resultf("%d", getTotalProbePckTx_by_NODE());
316 return TCL_OK;
317
318 } else if (strcasecmp(argv[1], "getPOLLrxByNODE") == 0) {
319 tcl.resultf("%d", getTotalPollPckRx_by_NODE());
320 return TCL_OK;
321
322 } else if (strcasecmp(argv[1], "getPOLLrxCorruptedByNODE") == 0) {
323 tcl.resultf("%d", getTotalPollPckRx_corrupted_by_NODE());
324 return TCL_OK;
325
326 } else if (strcasecmp(argv[1], "getDATAtxByNODE") == 0) {
327 tcl.resultf("%d", getTotalDataPckTx_by_NODE());
328 return TCL_OK;
329
330 } else if (strcasecmp(argv[1], "getCBEACONrxByNODE") == 0) {
331 tcl.resultf("%d", getTotalCBeaconPckRx_by_NODE());
332 return TCL_OK;
333
334 } else if (strcasecmp(argv[1], "getCBEACONrxCorruptedByNODE") == 0) {
335 tcl.resultf("%d", getTotalCBeaconPckRx_corrupted_by_NODE());
336 return TCL_OK;
337
338 } else if (strcasecmp(argv[1], "SimpleNodeStart") == 0) {
340 return TCL_OK;
341
342 } else if (strcasecmp(argv[1], "getBEACONtxByHN") == 0) {
343 tcl.resultf("%d", getTotalBeaconTx_by_HN());
344 return TCL_OK;
345
346 } else if (strcasecmp(argv[1], "getPROBErxByHN") == 0) {
347 tcl.resultf("%d", getTotalProbePckRx_HN());
348 return TCL_OK;
349
350 } else if (strcasecmp(argv[1], "getPROBErxCorruptedByHN") == 0) {
351 tcl.resultf("%d", getTotalProbePckRx_corrupted_HN());
352 return TCL_OK;
353
354 } else if (strcasecmp(argv[1], "getPOLLtxByHN") == 0) {
355 tcl.resultf("%d", getTotalPollPckTx_by_HN());
356 return TCL_OK;
357
358 } else if (strcasecmp(argv[1], "getDATArxByHN") == 0) {
359 tcl.resultf("%d", getTotalDataPckRx_by_HN());
360 return TCL_OK;
361
362 } else if (strcasecmp(argv[1], "getDATArxCorruptedByHN") == 0) {
363 tcl.resultf("%d", getTotalDataPckRx_corrupted_by_HN());
364 return TCL_OK;
365
366 } else if (strcasecmp(argv[1], "getCBEACONtxbyHN") == 0) {
367 tcl.resultf("%d", getTotalCBeaconPckTx_by_HN());
368 return TCL_OK;
369
370 } else if (strcasecmp(argv[1], "getTRIGGERrxByHN") == 0) {
371 tcl.resultf("%d", getTotalTriggerPckRx_HN());
372 return TCL_OK;
373
374 } else if (strcasecmp(argv[1], "getTRIGGERrxCorrupteByHN") == 0) {
375 tcl.resultf("%d", getTotalTriggerPckRx_corrupted_HN());
376 return TCL_OK;
377
378 } else if (strcasecmp(argv[1], "getRTStxByHN") == 0) {
379 tcl.resultf("%d", getTotalRtsPckTx_by_HN());
380 return TCL_OK;
381
382 } else if (strcasecmp(argv[1], "getCTSrxByHN") == 0) {
383 tcl.resultf("%d", getTotalCtsPckRx_HN());
384 return TCL_OK;
385
386 } else if (strcasecmp(argv[1], "getCTSrxCorrupteByHN") == 0) {
387 tcl.resultf("%d", getTotalCtsPckRx_corrupted_HN());
388 return TCL_OK;
389
390 } else if (strcasecmp(argv[1], "getDATAtxByHN") == 0) {
391 tcl.resultf("%d", getTotalDataPckTx_by_HN());
392 return TCL_OK;
393
394 } else if (strcasecmp(argv[1], "HeadNodeStart") == 0) {
395 stateIdle_HN();
396 return TCL_OK;
397
398 } else if (strcasecmp(argv[1], "BeHeadNode") == 0) {
399 HEADNODE = 1;
400 return TCL_OK;
401 }
402 } else if (argc == 3) {
403 if (strcasecmp(argv[1], "setMacAddr") == 0) {
404 addr = atoi(argv[2]);
405 if (debug_)
406 std::cout << "UWFETCH_NODE MAC address is:" << addr
407 << std::endl;
408 return TCL_OK;
409 }
410 }
411 return MMac::command(argc, argv);
412} // end command
413
414void
416{
417 initialized = true;
418
419 if ((print_transitions) && (system(NULL))) {
420 system("rm -f /tmp/uwUFetch_NODE_stateTransitions.txt");
421 system("touch /tmp/uwUFetch_NODE_stateTransitions.txt");
422 }
423 // State in which the NODE may be
424 statusInfo[UWUFETCH_NODE_STATUS_IDLE] = "Node is in IDLE state";
426 "NODE has received a BEACON packet from HN";
428 "NODE is transmitting PROBE packet to HN";
430 "NODE is waiting for POLL packet from HN";
432 "NODE has received a POLL packet from HN";
434 "NODE is transmitting DATA packet to HN";
436 "HN has received a TRIGGER packet from the AUV";
438 "HN has transmitted a RTS packet to the AUV";
440 "HN is waiting to the CTS packet from the AUV";
442 " HN has received a CTS packet from the AUV";
444 "HN is transmitting the BEACON packet to the NODE";
446 "HN is waiting to receive a PROBE packet from the NODE";
448 "HN has received a PROBE packet from the NODE";
450 "HN is transmitting the POLL packet to the NODE";
452 "HN is waiting a DATA packet from the NODE";
454 "HN has received a DATA packet from the NODE";
456 "NODE is waiting to receive a CBEACON packet from the HN";
458 "NODE has received a CBEACON packet from the HN";
459 // Reason for which the NODE change his state
461 "NODE is in IDLE STATE";
463 "NODE has receive a packet that is corrupted";
465 "NODE has received a packet that is addressed for another node";
467 "NODE has received a packet that the type is unknown";
469 "NODE has received a BEACON packet";
471 "NODE has transmitted a PROBE packet";
473 "POLL timeout is expired";
475 "NODE has received a POLL packet";
477 "NODE has received a CBEACON packet but it has already transmit "
478 "its DATA packets";
480 "NODE has transmitted the maximum number of packets";
482 "NODE has transmitted a DATA packets";
484 "HN has received a TRIGGER packet";
486 "HN has transmitted a RTS packet to tha AUV";
488 "CTS timeout expired";
490 "HN has received a CTS packet from the AUV";
492 "HN has transmitted a BEACON packet to the NODE";
494 "HN has transmitted a CBEACON packet to the NODe";
496 "HN has received a BEACON packet from the NODE";
499 "HN has 0 NODE to poll and maximum number of CBEACON has "
500 "been transmitted";
502 "HN has 0 NODE to poll and another CBEACON can be transmitted";
505 "HN has received the maximum number of PROBE allowed and "
506 "the PROBE timeout is not still expired";
508 "PROBE timeout is expired and at least 1 node can be polled by the "
509 "HN";
511 "HN has transmitted a POLL packet to the NODE";
513 "DATA timeout is expire";
516 "DATA timeout is expire and there are 0 node to poll and "
517 "other CBEACONS can not be transmitted";
520 "DATA timeout is expire and there are 0 node to poll and "
521 "at least one CBEACON can be transmitted";
524 "DATA timeout is expire and at least 1 node can be polled";
526 "HN has received a DATA packet from the NODE";
528 "HN has received the last DATA packet from the NODE";
531 "HN has received all the packet from the NODE, there are 0 "
532 "node to polled and it's not possible to transmit other "
533 "CBEACON";
536 "HN has received all the packet from the NODE, there are 0 "
537 "node to polled and it's possible to transmit other "
538 "CBEACON";
541 "HN has received all the packet from the NODE, there are "
542 "at least one node that can be polled";
544 "HN has transmit the maximum number of CBEACON packets";
546 "BEACON timeout is expired";
548 "Trigger received by the HN, but HN has no DATA available to "
549 "transmit to the AUV";
551 "HN has transmitted all his DATA packet to the AUV";
553 "HN has received a TRIGGER from AUV that is corrupted by the "
554 "channel";
557 "HN has finished to transmit a DATA packets to the AUV, "
558 "and now continue"
559 " with the transmission of CBEACON packet";
560 // Type of packets
568 // Possible status in which NODE can be found
569 statusTimer[UWUFETCH_TIMER_STATUS_IDLE] = "NODE is in IDLE";
570 statusTimer[UWUFETCH_TIMER_STATUS_RUNNING] = "NODE is RUNNING";
571 statusTimer[UWUFETCH_TIMER_STATUS_FROZEN] = "NODE is FREEZING";
572 statusTimer[UWUFETCH_TIMER_STATUS_EXPIRED] = "NODE timeout is EXPIRED";
573} // end initInfo();
574
575/*******************************************************************************
576 * GENERAL METHODS *
577 *******************************************************************************/
578
579void
581{
582
583 if (isHeadNode()) {
584 /****************************
585 * I'm the HEAD NODE *
586 ******************************/
588
589 } else {
590 /****************************
591 * I'm the SENSOR NODE *
592 ****************************/
593
594 hdr_cmn *cmh = hdr_cmn::access(p);
595 hdr_mac *mach = HDR_MAC(p);
596 int src_mac_addr = mach->macSA();
597
598 if (cmh->ptype() == PT_BEACON_UFETCH) {
599 // BEACON section
600 if (debugMio_)
601 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
602 << ")::Phy2MacStartRx()_________________Start_"
603 "to_rx_BEACON_pck_"
604 << "from_HN(" << src_mac_addr << ")."
605 << std::endl;
606
607 if (rxBEACONEnabled) {
608 // Node is enabled to receive BEACON
609 if (debug_)
610 std::cout << NOW << " uwUFetch_NODE (" << addr
611 << ") ::Phy2MacStartRx() ---->NODE is starting "
612 "to receive a "
613 << " BEACON packet from the HN with MAC address: "
614 << src_mac_addr << std::endl;
615
617
618 } else {
619 // Node is not enabled to receive BEACON
620 if (debug_)
621 std::cout << NOW << " uwUFetch_NODE (" << addr
622 << ") ::Phy2MacStartRx() ---->NODE is not "
623 "enabled to receive a "
624 << "BEACON packet from the HN with MAC address: "
625 << src_mac_addr << ", so wait"
626 << " the end of the reception of the packet and "
627 "after DROP IT"
628 << std::endl;
629 }
630 } else if (cmh->ptype() == PT_POLL_UFETCH) {
631 // POLL section
632 if (debug_)
633 std::cout << NOW << " uwUFetch_NODE (" << addr
634 << ") ::Phy2MacStartRx() ---->NODE is starting to "
635 "receive a "
636 << " POLL packet from the HN with MAC address: "
637 << src_mac_addr << std::endl;
638 if (debugMio_)
639 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
640 << ")::Phy2MacStartRx()_________________Start_"
641 "to_rx_POLL_pck"
642 << "_from HN(" << src_mac_addr << ")."
643 << std::endl;
644
645 rx_POLL_start_time = NOW;
646
647 } else if (cmh->ptype() == PT_CBEACON_UFETCH) {
648 // CBEACON section
649 if (debug_)
650 std::cout << NOW << " uwUFetch_NODE (" << addr
651 << ") ::Phy2MacStartRx() ---->NODE is starting to "
652 "receive a "
653 << " CBEACON packet from the HN with MAC address: "
654 << src_mac_addr << std::endl;
655 if (debugMio_)
656 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
657 << ")::Phy2MacStartRx()_________________Start_"
658 "to_rx_CBEACON_pck"
659 << "_from HN(" << src_mac_addr << ")."
660 << std::endl;
661
663
664 } else if (cmh->ptype() == PT_PROBE_UFETCH) {
665 // PROBE section
666 if (debug_)
667 std::cout << NOW << " uwUFetch_NODE (" << addr
668 << ") ::Phy2MacStartRx() ---->NODE is starting to "
669 "receive a "
670 << " PROBE packet from the NODE with MAC address: "
671 << src_mac_addr << std::endl;
672
673 } else if (cmh->ptype() == PT_TRIGGER_UFETCH) {
674 // TRIGGER section
675 if (debug_)
676 std::cout << NOW << " uwUFetch_NODE (" << addr
677 << ") ::Phy2MacStartRx() ---->NODE is starting to "
678 "receive a "
679 << " TRIGGER packet from the AUV with MAC address: "
680 << src_mac_addr << std::endl;
681
682 } else {
683 // DATA section
684 if (debug_)
685 std::cout
686 << NOW << " uwUFetch_NODE (" << addr
687 << ") ::Phy2MacStartRx() ---->NODE is starting to "
688 "receive a "
689 << " DATA packet from the HN or NODE with MAC address: "
690 << src_mac_addr << std::endl;
691 }
692 }
693} // end Phy2MacStartRx();
694
695void
697{
698
699 if (isHeadNode()) {
700 /*********************
701 * I'm the HEAD NODE *
702 *********************/
704
705 } else {
706 /****************************
707 * I'm the SENSOR NODE *
708 *****************************/
709 hdr_cmn *cmh = hdr_cmn::access(p);
710 hdr_mac *mach = HDR_MAC(p);
711 int src_mac_addr = mach->macSA();
712 int dest_mac_addr = mach->macDA(); // Destination MAC address, the
713 // address to which the packet is
714 // addressed
715 hdr_MPhy *ph = HDR_MPHY(p);
716 double gen_time = ph->txtime;
717 double received_time = ph->rxtime;
718 double diff_time = received_time - gen_time;
719 double distance = diff_time * v_speed_sound;
720
721 // Control if the packet that the HN has received is really for him
722 if ((dest_mac_addr == addr) || (dest_mac_addr == MAC_BROADCAST)) {
723 // Packet is addressed to me NODE
724
725 if (cmh->ptype() == PT_BEACON_UFETCH) {
726 // BEACON section
727 if (debugMio_)
728 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
729 << ")::Phy2MacEndRx()___________________"
730 "Finished_to_rx_BEACON"
731 << "_pck_from_HN(" << src_mac_addr << ")"
732 << std::endl;
733
734 if (((cmh->error()) || (!rxBEACONEnabled))) {
735 if ((cmh->error()) && (rxBEACONEnabled)) {
736 // BEACON is corrupted by the channel
737 if (debug_)
738 std::cout << NOW << " uwUFetch_NODE (" << addr
739 << ") ::Phy2MacEndRx() ---->Node is "
740 "enabled to rx BEACON packet, but the "
741 "packet received"
742 << " is corrupted: DROP IT and return in "
743 "IDLE STATE."
744 << std::endl;
745
746 if (debugMio_)
748 << NOW << "uwUFetch_SENSOR_NODE(" << addr
749 << ")::Phy2MacEndRx()___________________"
750 "ENABLED_to_rx_BEACON_pck_from_HN("
751 << mach->macSA() << ")_"
752 << "but_pck_It_s_in_ERROR." << std::endl;
753
755
758
759 rxBEACONEnabled = true;
761
763 } else if ((cmh->error()) && (!rxBEACONEnabled)) {
764 // Node is not enabled to receive BEACON and packet it's
765 // in error
766
767 if (debug_)
768 std::cout << NOW << " uwUFetch_NODE (" << addr
769 << ") ::Phy2MacEndRx() ---->NODE has "
770 "finished to receive a "
771 << "BEACON packet from the HN with MAC "
772 "address: "
773 << src_mac_addr << " and it's not enabled"
774 << " to receive It, so DROP IT."
775 << std::endl;
776 if (debugMio_)
778 << NOW << "uwUFetch_SENSOR_NODE(" << addr
779 << ")::Phy2MacEndRx()___________________"
780 "NOT_ENABLED_to_rx_BEACON_pck_from_HN("
781 << mach->macSA() << ")"
782 << "_and_pck_It_s_in_ERROR." << std::endl;
783
791
792 if (mach->macSA() == mac_addr_HN_in_beacon) {
793 if (rxPOLLEnabled) {
794 if (debug_)
795 std::cout << NOW << " uwUFetch_NODE ("
796 << addr
797 << ") ::Phy2MacEndRx() ---->NODE "
798 "has finished to receive a "
799 << "BEACON packet from the HN "
800 "with MAC address: "
801 << src_mac_addr
802 << " and it's not enabled to rx "
803 "It, but SN it's waiting a "
804 "POLL packet"
805 << " from this HN, so return in "
806 "IDLE state and wait a BEACON "
807 "from another node."
808 << std::endl;
809 if (debugMio_)
811 << NOW << "uwUFetch_SENSOR_NODE("
812 << addr << ")::Phy2MacEndRx()______"
813 "_____________SN("
814 << addr
815 << ")_is_waiting_a_POLL_from_HN("
816 << mach->macSA() << ")"
817 << ":return_in_IDLE_STATE."
818 << std::endl;
819
820 if (debugMio_)
822 << NOW << "uwUFetch_SENSOR_NODE("
823 << addr
824 << ")::Phy2MacEndRx()______________"
825 "_____RESET_POLL_timeout."
826 << std::endl;
827
828 rxPOLLEnabled = false;
829 POLL_timer.force_cancel();
830
831 rxBEACONEnabled = true;
833
839
840 rxBEACONEnabled = true;
841 txPROBEEnabled = false;
842 rxPOLLEnabled = false;
843 txDATAEnabled = false;
844 rxCBEACONEnabled = false;
845
848 } else if (rxCBEACONEnabled) {
849 if (debug_)
850 std::cout << NOW << " uwUFetch_NODE ("
851 << addr
852 << ") ::Phy2MacEndRx() ---->NODE "
853 "has finished to receive a "
854 << "BEACON packet from the HN "
855 "with MAC address: "
856 << src_mac_addr
857 << " and it's not enabled to rx "
858 "It, but SN it's waiting a "
859 "CBEACON packet"
860 << " from this HN, so return in "
861 "IDLE state and wait a BEACON "
862 "from another node."
863 << std::endl;
864
865 if (debugMio_)
867 << NOW << "uwUFetch_SENSOR_NODE("
868 << addr << ")::Phy2MacEndRx()______"
869 "_____________SN("
870 << addr << ")_is_waiting_a_CBEACON_"
871 "pck_from_HN("
872 << mach->macSA() << ")_"
873 << ":return_in_IDLE_STATE."
874 << std::endl;
875
876 if (debugMio_)
878 << NOW << "uwUFetch_SENSOR_NODE("
879 << addr
880 << ")::Phy2MacEndRx()______________"
881 "_____RESET_CBEACON_timeout."
882 << std::endl;
883
884 rxPOLLEnabled = false;
885 rxCBEACONEnabled = false;
886 POLL_timer.force_cancel();
887 CBEACON_timer.force_cancel();
888
889 rxBEACONEnabled = true;
891
897
898 rxBEACONEnabled = true;
899 txPROBEEnabled = false;
900 rxPOLLEnabled = false;
901 txDATAEnabled = false;
902 rxCBEACONEnabled = false;
903
906 }
907 }
909 } else if (!(cmh->error()) && (!rxBEACONEnabled)) {
910 // Node is not enabled to receive BEACON and Beacon it's
911 // not in error
912 if (debug_)
913 std::cout << NOW << " uwUFetch_NODE (" << addr
914 << ") ::Phy2MacEndRx() ---->NODE has "
915 "finished to receive a "
916 << "BEACON packet from the HN with MAC "
917 "address: "
918 << src_mac_addr << " and it's not enabled"
919 << " to receive It, so DROP IT."
920 << std::endl;
921 if (debugMio_)
923 << NOW << "uwUFetch_SENSOR_NODE(" << addr
924 << ")::Phy2MacEndRx()___________________"
925 "NOT_ENABLED_to_rx_BEACON_pck_from_HN("
926 << mach->macSA() << ")_"
927 << "_and_BEACON_It_s_CORRECT:IGNORE_IT."
928 << std::endl;
929
931
932 if (mach->macSA() == mac_addr_HN_in_beacon) {
933 if (rxPOLLEnabled) {
934 if (debug_)
935 std::cout << NOW << " uwUFetch_NODE ("
936 << addr
937 << ") ::Phy2MacEndRx() ---->NODE "
938 "has finished to receive a "
939 << "BEACON packet from the HN "
940 "with MAC address: "
941 << src_mac_addr
942 << " and it's not enabled to rx "
943 "It, but SN it's waiting a "
944 "POLL packet"
945 << " from this HN, so return in "
946 "IDLE state and wait a BEACON "
947 "from another node."
948 << std::endl;
949
950 if (debugMio_)
952 << NOW << "uwUFetch_SENSOR_NODE("
953 << addr << ")::Phy2MacEndRx()______"
954 "_____________SN("
955 << addr << ")_is_waiting_a_POLL_"
956 "pck_from_HN("
957 << mach->macSA() << ")_"
958 << ":return_in_IDLE_STATE."
959 << std::endl;
960 if (debugMio_)
962 << NOW << "uwUFetch_SENSOR_NODE("
963 << addr
964 << ")::Phy2MacEndRx()______________"
965 "_____RESET_POLL_timeout."
966 << std::endl;
967
968 rxPOLLEnabled = false;
969 POLL_timer.force_cancel();
970
971 rxBEACONEnabled = true;
973
979
980 rxBEACONEnabled = true;
981 txPROBEEnabled = false;
982 rxPOLLEnabled = false;
983 txDATAEnabled = false;
984 rxCBEACONEnabled = false;
985
988 } else if (rxCBEACONEnabled) {
989
990 if (debug_)
991 std::cout << NOW << " uwUFetch_NODE ("
992 << addr
993 << ") ::Phy2MacEndRx() ---->NODE "
994 "has finished to receive a "
995 << "BEACON packet from the HN "
996 "with MAC address: "
997 << src_mac_addr
998 << " and it's not enabled to rx "
999 "It, but SN it's waiting a "
1000 "CBEACON packet"
1001 << " from this HN, so return in "
1002 "IDLE state and wait a BEACON "
1003 "from another node."
1004 << std::endl;
1005 if (debugMio_)
1007 << NOW << "uwUFetch_SENSOR_NODE("
1008 << addr << ")::Phy2MacEndRx()______"
1009 "_____________SN("
1010 << addr << ")_is_waiting_a_CBEACON_"
1011 "pck_from_HN("
1012 << mach->macSA() << ")"
1013 << ":return in IDLE STATE."
1014 << std::endl;
1015 if (debugMio_)
1017 << NOW << "uwUFetch_SENSOR_NODE("
1018 << addr
1019 << ")::Phy2MacEndRx()______________"
1020 "_____RESET_CBEACON_timeout."
1021 << std::endl;
1022
1023 rxPOLLEnabled = false;
1024 POLL_timer.force_cancel();
1025
1026 rxCBEACONEnabled = false;
1027 CBEACON_timer.force_cancel();
1028
1029 rxBEACONEnabled = true;
1031
1037
1038 rxBEACONEnabled = true;
1039 txPROBEEnabled = false;
1040 rxPOLLEnabled = false;
1041 txDATAEnabled = false;
1042 rxCBEACONEnabled = false;
1043
1044 dataAlreadyTransmitted = false;
1046 }
1047 }
1049 }
1050 } else {
1051 // Node is enabled to receive BEACON
1052 if (debug_)
1053 std::cout << NOW << " uwUFetch_NODE (" << addr
1054 << ") ::Phy2MacEndRx() ---->NODE has "
1055 "finished to receive a "
1056 << "BEACON packet from the HN with MAC "
1057 "address: "
1058 << src_mac_addr << " and it's enabled"
1059 << " to receive It." << std::endl;
1060 rxBEACONEnabled = false;
1061
1062 if (debug_)
1063 std::cout << NOW << " uwUFetch_NODE( " << addr
1064 << ") ::Phy2MacEndRx() ---->BEACON packet "
1065 "received by the NODE"
1066 << " is CORRECT, so COMPUTE IT" << std::endl;
1067
1069
1070 if (debugMio_)
1071 out_file_logging << NOW << "uwUFetch_SENSOR_NODE("
1072 << addr
1073 << ")::Phy2MacEndRx()_________________"
1074 "__BEACON_rx_from_HN("
1075 << mach->macSA() << ")_:It_s_CORRECT."
1076 << std::endl;
1077
1080
1081 curr_BEACON_NODE_pck_rx = p->copy();
1082
1083 Packet::free(p);
1085
1086 BEACON_rx();
1087 }
1088 } else if (cmh->ptype() == PT_POLL_UFETCH) {
1089 // POLL section
1090 if (debug_)
1091 std::cout << NOW << " uwUFetch_NODE (" << addr
1092 << ") ::Phy2MacEndRx() ---->NODE has finished to "
1093 "receive a"
1094 << " POLL packet from the HN with MAC address: "
1095 << src_mac_addr << std::endl;
1096
1097 if (debugMio_)
1098 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
1099 << ")::Phy2MacEndRx()___________________"
1100 "Finished_to_rx_POLL_pck"
1101 << "_from_HN(" << src_mac_addr << ")."
1102 << std::endl;
1103
1104 if ((src_mac_addr == mac_addr_HN_in_beacon)) {
1105 if (cmh->error()) {
1106 // POLL is corrupted
1107 if (debug_)
1108 std::cout << NOW << " uwUFetch_NODE( " << addr
1109 << ") ::Phy2MacEndRx() ---->POLL packet "
1110 "received by the NODE"
1111 << " is corrupted: DROP IT." << std::endl;
1112 if (debugMio_)
1114 << NOW << "uwUFetch_SENSOR_NODE(" << addr
1115 << ")::Phy2MacEndRx()___________________"
1116 "POLL_pck_rx_from_HN("
1117 << src_mac_addr << ")_It_s_in_ERROR."
1118 << std::endl;
1119
1120 rx_POLL_finish_time = NOW;
1121
1123 incrTotalPollPckRx_corrupted_by_NODE(); // increment the
1124 // number of
1125 // packets in
1126 // error
1127
1128 drop(p, 1, UWFETCH_NODE_DROP_REASON_ERROR); // drop the
1129 // packet
1131
1135
1136 rxPOLLEnabled = false;
1137 dataAlreadyTransmitted = false;
1138
1139 } else {
1140 // POLL is not corrupted
1141 if (debug_)
1142 std::cout << NOW << " uwUFetch_NODE (" << addr
1143 << ") ::Phy2MacEndRx() ---->POLL packet "
1144 "received by the NODE"
1145 << " is CORRECT." << std::endl;
1146
1147 if (debugMio_)
1149 << NOW << "uwUFetch_SENSOR_NODE(" << addr
1150 << ")::Phy2MacEndRx()___________________"
1151 "POLL_pck_rx_from_HN("
1152 << src_mac_addr << ")_It_s_CORRECT."
1153 << std::endl;
1154
1155 rx_POLL_finish_time = NOW;
1156
1157 if (debug_)
1158 std::cout << NOW << " uwUFetch_NODE (" << addr
1159 << ") ::Phy2MacEndRx() ---->POLL timer "
1160 "is resetted."
1161 << std::endl;
1162 POLL_timer.force_cancel();
1163
1166
1167 curr_POLL_NODE_pck_rx = p->copy();
1168
1169 Packet::free(p);
1171
1172 POLL_rx();
1173 }
1174 } else {
1175 if (debug_)
1176 std::cout << NOW << " uwUFetch_NODE (" << addr
1177 << ") ::Phy2MacEndRx() ---->NODE has "
1178 "received a POLL packet"
1179 << " from the HN from which it's not waiting "
1180 "a POLL, so DROP IT."
1181 << std::endl;
1182 if (debugMio_)
1184 << NOW << "uwUFetch_SENSOR_NODE(" << addr
1185 << ")::Phy2MacEndRx()___________________POLL_"
1186 "pck_rx_from_HN("
1187 << src_mac_addr
1188 << ")_It_s_not_addressed_to_me:_DROP_IT."
1189 << std::endl;
1190
1191 drop(p,
1192 1,
1193 UWFETCH_NODE_DROP_REASON_ERROR); // drop the packet
1195 }
1196 } else if (cmh->ptype() == PT_CBEACON_UFETCH) {
1197 // CBEACON section
1198 if (debug_)
1199 std::cout
1200 << NOW << " uwUFetch_NODE (" << addr
1201 << ") ::Phy2MacEndRx() ---->NODE has finished to "
1202 "receive a"
1203 << " CBEACON packet from the HN with MAC address: "
1204 << src_mac_addr << std::endl;
1205
1206 if (debugMio_)
1207 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
1208 << ")::Phy2MacEndRx()___________________"
1209 "NODE_has_finished_to_rx_CBEACON_packet"
1210 << "_from HN(" << src_mac_addr << ")."
1211 << std::endl;
1212
1213 mac_addr_HN_in_cbeacon = mach->macSA();
1214
1216 // CBEACON is received from the HN from which I have
1217 // received the BEACON
1218 if (debug_)
1219 std::cout << NOW << " uwUFetch_NODE (" << addr
1220 << ") ::Phy2MacEndRx() ---->CBEACON rx from "
1221 "the correct HN"
1222 << std::endl;
1223 if (debugMio_)
1224 out_file_logging << NOW << "uwUFetch_SENSOR_NODE("
1225 << addr
1226 << ")::Phy2MacEndRx()_________________"
1227 "__CBEACON_rx_from_the_correct_HN("
1228 << src_mac_addr << ")." << std::endl;
1229
1230 incrTotalCBeaconPckRx_by_NODE(); // increment the total
1231 // number of CBEACON
1232 // packets received.
1233 CBEACON_timer.force_cancel();
1234 if (cmh->error()) {
1235 // The CBEACON is corrupted
1236 if (debug_)
1237 std::cout << NOW << " uwUFetch_NODE (" << addr
1238 << ") ::Phy2MacEndRx() ---->CBEACON "
1239 "received by the NODE"
1240 << " is corrupted: DROP IT." << std::endl;
1241 if (debugMio_)
1243 << NOW << "uwUFetch_SENSOR_NODE(" << addr
1244 << ")::Phy2MacEndRx()___________________"
1245 "CBEACON_rx_from_HN("
1246 << mach->macSA() << ")_It_s_in_ERROR."
1247 << std::endl;
1248
1251
1252 if (debug_)
1253 std::cout << NOW << " uwUFetch_NODE (" << addr
1254 << ") ::Phy2MacEndRx() ---->CBEACON "
1255 "reset the timer"
1256 << std::endl;
1257 CBEACON_timer.force_cancel();
1258
1260 // Node has received the maximum number of CBEACON
1261 if (debug_)
1262 std::cout << NOW << " uwUFetch_NODE (" << addr
1263 << ") ::Phy2MacEndRx() ---->NODE has "
1264 "received the maximum"
1265 << " number of CBEACON packet from "
1266 "the HN with MAC address: "
1267 << mac_addr_HN_in_beacon << ", so"
1268 << " return in IDLE STATE."
1269 << std::endl;
1270 if (debugMio_)
1272 << NOW << "uwUFetch_SENSOR_NODE("
1273 << addr
1274 << ")::Phy2MacEndRx()__________________"
1275 "_MAX_number_of_CBEACON_received."
1276 << std::endl;
1277
1283
1284 rxBEACONEnabled = true;
1285 txPROBEEnabled = false;
1286 rxPOLLEnabled = false;
1287 txDATAEnabled = false;
1288 rxCBEACONEnabled = false;
1289 POLL_timer.force_cancel();
1290
1291 dataAlreadyTransmitted = false;
1293 } else {
1294 // Node can receive another CBEACON packet
1295 if (debug_)
1296 std::cout << NOW << " uwUFetch_NODE (" << addr
1297 << ") ::Phy2MacEndRx() ---->NODE has "
1298 "not received the maximum"
1299 << " number of CBEACON packet from "
1300 "the HN with MAC address: "
1301 << mac_addr_HN_in_beacon << ", so"
1302 << " wait other CBEACON packets."
1303 << std::endl;
1304 if (debugMio_)
1306 << NOW << "uwUFetch_SENSOR_NODE("
1307 << addr
1308 << ")::Phy2MacEndRx()__________________"
1309 "_Other_CBEACON_can_be_rx."
1310 << std::endl;
1311
1314 rxPOLLEnabled = false;
1315 POLL_timer.force_cancel();
1316 CBEACON_timer.force_cancel();
1317
1319 }
1320 } else {
1321 // The CBEACON is not corrupted
1322 if (debug_)
1323 std::cout << NOW << " uwUFetch_NODE (" << addr
1324 << ") ::Phy2MacEndRx() ---->CBEACON "
1325 "packet received by the NODE"
1326 << " is CORRECT." << std::endl;
1327 if (debug_)
1328 std::cout << NOW << " uwUFetch_NODE (" << addr
1329 << ") ::Phy2MacEndRx() ---->CBEACON "
1330 "received is the number: "
1332 << std::endl;
1333 if (debugMio_)
1335 << NOW << "uwUFetch_SENSOR_NODE(" << addr
1336 << ")::Phy2MacEndRx()___________________"
1337 "CBECON_rx_from_HN("
1338 << mach->macSA() << ")_It_s_CORRECT."
1339 << std::endl;
1340
1341 curr_CBEACON_NODE_pck_rx = p->copy();
1342
1343 Packet::free(p);
1345
1346 CBEACON_rx();
1347 }
1348 } else {
1349 // CBEACON is received from the HN from which I don't never
1350 // received the BEACON
1351 if (debug_)
1352 std::cout << NOW << " uwUFetch_NODE (" << addr
1353 << ") ::Phy2MacEndRx() ---->CBEACON packet "
1354 "received by the NODE"
1355 << " is received from the HN from which I "
1356 "never received the BEACON: IGNORE IT"
1357 << std::endl;
1358 if (debugMio_)
1360 << NOW << "uwUFetch_SENSOR_NODE(" << addr
1361 << ")::Phy2MacEndRx()___________________"
1362 "CBEACON_rx_It_s_not_for_me_SENSOR_NODE."
1363 << std::endl;
1364
1365 incrTotalCBeaconPckRx_by_NODE(); // increment the number of
1366 // packets in error
1367 }
1368 } else if (cmh->ptype() == PT_PROBE_UFETCH) {
1369 // PROBE section
1370 if (debug_)
1371 std::cout
1372 << NOW << " uwUFetch_NODE (" << addr
1373 << ") ::Phy2MacEndRx() ---->NODE has finished to "
1374 "receive a"
1375 << " PROBE packet from the NODE with MAC address: "
1376 << src_mac_addr << ". DROP IT" << std::endl;
1377
1379
1380 } else if (cmh->ptype() == PT_TRIGGER_UFETCH) {
1381 // TRIGGER section
1382 if (debug_)
1383 std::cout
1384 << NOW << " uwUFetch_NODE (" << addr
1385 << ") ::Phy2MacEndRx() ---->NODE has finished to "
1386 "receive a"
1387 << " TRIGGER packet from the AUV with MAC address: "
1388 << src_mac_addr << std::endl;
1389
1391 } else {
1392 // DATA section
1393 if (debug_)
1394 std::cout << NOW << " uwUFetch_NODE (" << addr
1395 << ") ::Phy2MacEndRx() ---->NODE has finished to "
1396 "receive a"
1397 << " DATA packet from the HN or NODE with MAC "
1398 "address: "
1399 << src_mac_addr << " .DROP IT" << std::endl;
1400
1401 if (mach->macSA() == mac_addr_HN_in_beacon) {
1402 if (rxPOLLEnabled) {
1403 if (debug_)
1404 std::cout
1405 << NOW << " uwUFetch_NODE (" << addr
1406 << ") ::Phy2MacEndRx() ---->NODE has "
1407 "finished to receive a "
1408 << "DATA packet from the HN with MAC "
1409 "address: "
1410 << src_mac_addr
1411 << " and it's not enabled to rx It, but SN "
1412 "it's waiting a POLL packet"
1413 << " from this HN, so return in IDLE state "
1414 "and wait a BEACON from another node."
1415 << std::endl;
1416
1417 if (debugMio_)
1419 << NOW << "uwUFetch_SENSOR_NODE(" << addr
1420 << ")::Phy2MacEndRx()___________________"
1421 "Received_DATA_from_HN_from_which_"
1422 << "SN(" << addr << ")_is_waiting_a_POLL."
1423 << std::endl;
1424 if (debugMio_)
1425 out_file_logging << NOW << "uwUFetch_SENSOR_NODE("
1426 << addr
1427 << ")::Phy2MacEndRx()_____________"
1428 "______RESET_POLL_timeout_and_"
1429 "return_in_IDLE_STATE."
1430 << std::endl;
1431
1432 rxPOLLEnabled = false;
1433 POLL_timer.force_cancel();
1434
1435 rxBEACONEnabled = true;
1437
1443
1444 rxBEACONEnabled = true;
1445 txPROBEEnabled = false;
1446 rxPOLLEnabled = false;
1447 txDATAEnabled = false;
1448 rxCBEACONEnabled = false;
1449
1450 dataAlreadyTransmitted = false;
1452
1453 } else if (rxCBEACONEnabled) {
1454
1455 if (debug_)
1456 std::cout
1457 << NOW << " uwUFetch_NODE (" << addr
1458 << ") ::Phy2MacEndRx() ---->NODE has "
1459 "finished to receive a "
1460 << "DATA packet from the HN with MAC "
1461 "address: "
1462 << src_mac_addr
1463 << " and it's not enabled to rx It, but SN "
1464 "it's waiting a CBEACON packet"
1465 << " from this HN, so return in IDLE state "
1466 "and wait a BEACON from another node."
1467 << std::endl;
1468 if (debugMio_)
1470 << NOW << "uwUFetch_SENSOR_NODE(" << addr
1471 << ")::Phy2MacEndRx()___________________"
1472 "Received_DATA_from_HN_from_which_"
1473 << "SN(" << addr
1474 << ")_is_waiting_a_CBEACON." << std::endl;
1475 if (debugMio_)
1476 out_file_logging << NOW << "uwUFetch_SENSOR_NODE("
1477 << addr
1478 << ")::Phy2MacEndRx()_____________"
1479 "______RESET_CBEACON_timeout_"
1480 "and_return_in_IDLE_STATE."
1481 << std::endl;
1482
1483 rxPOLLEnabled = false;
1484 POLL_timer.force_cancel();
1485
1486 rxCBEACONEnabled = false;
1487 CBEACON_timer.force_cancel();
1488
1489 rxBEACONEnabled = true;
1491
1497
1498 rxBEACONEnabled = true;
1499 txPROBEEnabled = false;
1500 rxPOLLEnabled = false;
1501 txDATAEnabled = false;
1502 rxCBEACONEnabled = false;
1503
1504 dataAlreadyTransmitted = false;
1506 }
1507 }
1509 }
1510 } else {
1511 // Packet not addressed to the exactly sensor node
1512 if (cmh->ptype() == PT_TRIGGER_UFETCH) {
1513
1515
1516 } else if (cmh->ptype() == PT_PROBE_UFETCH) {
1517
1519
1520 } else if (cmh->ptype() == PT_POLL_UFETCH) {
1521 if (debugMio_)
1522 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
1523 << ")::Phy2MacEndRx()___________________"
1524 "Finished_to_rx_POLL"
1525 << "_pck_from_HN(" << src_mac_addr << ")"
1526 << std::endl;
1527 if ((cmh->ptype() == PT_POLL_UFETCH) &&
1528 (src_mac_addr == mac_addr_HN_in_beacon) &&
1529 (getProbePckTx_by_NODE() >= 1)) {
1530 if (debug_)
1531 std::cout << NOW << " uwUFetch_NODE (" << addr
1532 << ") ::Phy2MacEndRx() ---->NODE has "
1533 "received a POLL packet"
1534 << " from the HN from which it waiting a "
1535 "POLL, but it's not my turn, so reset the "
1536 "POLL timer and"
1537 << " restart to waiting a POLL." << std::endl;
1538 if (debugMio_)
1540 << NOW << "uwUFetch_SENSOR_NODE(" << addr
1541 << ")::Phy2MacEndRx()___________________SN("
1542 << addr << ")_is_waiting_a_POLL_from"
1543 << "_HN(" << src_mac_addr
1544 << ")_but_It_s_NOT_ITS_TURN." << std::endl;
1545 if (debugMio_)
1546 out_file_logging << NOW << "uwUFetch_SENSOR_NODE("
1547 << addr
1548 << ")::Phy2MacEndRx()_________________"
1549 "__RESET_and_RESTART_POLL_timeout."
1550 << std::endl;
1551
1552 // POLL_timer.force_cancel();
1553 hdr_mac *mach = HDR_MAC(p);
1554 hdr_POLL_UFETCH *pollh = HDR_POLL_UFETCH(p);
1555
1560 pollh->num_DATA_pcks_MAX_rx(); // Number of DATA
1561 // packets that the
1562 // node will transmit
1563 // to the HN
1564 double poll_waiting_time =
1566 if (debug_)
1567 std::cout << NOW << " uwUFetch_NODE (" << addr
1568 << ") ::Phy2MacEndRx() ---->The new waiting "
1569 "time is:"
1570 << poll_waiting_time << std::endl;
1571 if (debugMio_)
1573 << NOW << "uwUFetch_SENSOR_NODE(" << addr
1574 << ")::Phy2MacEndRx()___________________POLL_"
1575 "waiting_time_is:_"
1576 << poll_waiting_time << "_[s]." << std::endl;
1577
1579
1580 POLL_timer.schedule(poll_waiting_time);
1581
1582 } else {
1583 // Packet is not addressed to me NODE
1584 if (debug_)
1585 std::cout << NOW << " uwUFetch_NODE (" << addr
1586 << ") ::Phy2MacEndRx() ---->The packet "
1587 "received is not for me NODE:"
1588 << " DROP IT." << std::endl;
1589
1593 }
1594 } else {
1595
1597 }
1598 }
1599 }
1600} // end Phy2MacEndRx();
1601
1602void
1604{
1605
1606 if (isHeadNode()) {
1607 /*********************
1608 * I'm the HEAD NODE *
1609 *********************/
1611 } else {
1612 /****************************
1613 * I'm the SENSOR NODE *
1614 ****************************/
1615 hdr_cmn *cmh = hdr_cmn::access(p);
1616 hdr_mac *mach = HDR_MAC(p);
1617
1618 if (cmh->ptype() == PT_PROBE_UFETCH) {
1619 // PROBE section
1620 if (debug_)
1621 std::cout << NOW << " uwUFetch_NODE (" << addr
1622 << ") ::Mac2PhyStartTx() ---->MAC layer of the NODE "
1623 "passes the PROBE"
1624 << " packet to its physical layer." << std::endl;
1625 if (debugMio_)
1626 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
1627 << ")::Mac2PhyStartTx()_________________Start_"
1628 "tx_PROBE_pck"
1629 << "_to_the_HN(" << mac_addr_HN_in_beacon
1630 << ")." << std::endl;
1631
1632 tx_PROBE_start_time = NOW;
1633
1634 MMac::Mac2PhyStartTx(p);
1635 } else {
1636 // DATA section
1637
1638 if (debug_)
1639 std::cout << NOW << " uwUFetch_NODE (" << addr
1640 << ") ::Mac2PhyStartTx() ---->MAC layer of the NODE "
1641 "passes the DATA"
1642 << " packet to its physical layer." << std::endl;
1643
1644 if (debugMio_)
1645 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
1646 << ")::Mac2PhyStartTx()_________________Start_"
1647 "tx_DATA_pck_"
1648 << "to_the_HN(" << mach->macDA() << ")."
1649 << std::endl;
1650
1651 tx_DATA_start_time = NOW;
1652
1653 Tdata_NODE_pck = Mac2PhyTxDuration(p);
1655
1656 MMac::Mac2PhyStartTx(p);
1657 }
1658 }
1659} // end Mac2PhyStartTx();
1660
1661void
1663{
1664 if (isHeadNode()) {
1665 /*********************
1666 * I'm the HEAD NODE *
1667 *********************/
1669
1670 } else {
1671 /****************************
1672 * I'm the SENSOR NODE *
1673 ****************************/
1674 hdr_cmn *cmh = hdr_cmn::access(p);
1675
1676 if (cmh->ptype() == PT_PROBE_UFETCH) {
1677 // PROBE section
1678 if (debug_)
1679 std::cout << NOW << " uwUFetch_NODE (" << addr
1680 << ") ::Phy2MacEndTx() ---->Physical layer of the "
1681 "NODE has finished"
1682 << " to transmit a PROBE packet to the HN with MAC "
1683 "address: "
1684 << mac_addr_HN_in_beacon << std::endl;
1685 if (debugMio_)
1686 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
1687 << ")::Phy2MacEndTx()___________________"
1688 "Finished_to_tx_PROBE_pck"
1689 << "_to_the_HN(" << mac_addr_HN_in_beacon
1690 << ")." << std::endl;
1691
1693
1696
1697 txPROBEEnabled = false;
1698
1700
1701 } else {
1702 // DATA section
1703 if (debug_)
1704 std::cout << NOW << " uwUFetch_NODE (" << addr
1705 << ") ::Phy2MacEndTx() ---->Physical layer of the "
1706 "NODE has finished"
1707 << " to transmit a DATA packet to the HN with MAC "
1708 "address: "
1709 << mac_addr_HN_in_poll << std::endl;
1710
1711 tx_DATA_finish_time = NOW;
1712
1715
1716 if (debugMio_)
1717 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
1718 << ")::Phy2MacEndTx()___________________"
1719 "Finished_to_tx_DATA_pck"
1720 << "_to_the_HN(" << mac_addr_HN_in_beacon
1721 << ")." << std::endl;
1722
1724 rxBEACONEnabled = false;
1727 } else {
1729 }
1730 }
1731 }
1732} // end Phy2MacEndTx();
1733
1734/******************************************************************************
1735 * SENSOR NODE *
1736 ******************************************************************************/
1737void
1739{
1740 if (debug_)
1741 std::cout << NOW << " uwUFetch_NODE (" << addr
1742 << ") ::stateIdle_NODE() ---->NODE is in IDLE STATE"
1743 << std::endl;
1744
1745 if (debugMio_)
1747 << NOW << "uwUFetch_SENSOR_NODE(" << addr
1748 << ")::stateIdle_NODE()_________________NODE_is_IDLE_STATE."
1749 << std::endl;
1750
1754
1755 rxBEACONEnabled = true;
1756
1757 if (debug_)
1758 std::cout << NOW << " uwUFetch_NODE (" << addr
1759 << ") ::stateIdle_NODE() ---->NODE is waiting a BEACON packet"
1760 << " from an HN." << std::endl;
1761 if (debugMio_)
1763 << NOW << "uwUFetch_SENSOR_NODE(" << addr
1764 << ")::stateIdle_NODE()_________________....Waiting_BEACON_pck."
1765 << std::endl;
1766 if (debugMio_)
1768 << NOW << "uwUFetch_SENSOR_NODE(" << addr
1769 << ")::stateIdle_NODE()_________________....Waiting_BEACON_pck."
1770 << std::endl;
1771 if (debugMio_)
1773 << NOW << "uwUFetch_SENSOR_NODE(" << addr
1774 << ")::stateIdle_NODE()_________________....Waiting_BEACON_pck."
1775 << std::endl;
1776
1777} // end stateIdle_NODE();
1778
1779void
1781{
1782
1786
1787 hdr_mac *mach = HDR_MAC(curr_BEACON_NODE_pck_rx);
1789
1790 /*
1791 * Save the header data of the beacon
1792 */
1793 T_min_bck_probe_node = (double) beaconh->t_min_bc() / 1000;
1794 T_max_bck_probe_node = (double) beaconh->t_max_bc() / 1000;
1796 beaconh->num_Max_CBEACON_tx_by_HN(); // Number of CBEACON that the
1797 // SENSOR NODE will be received
1798 // from the HN from which it
1799 // has
1800 // received the BEACON
1801 if (debug_)
1802 std::cout << NOW << " uwUFetch_NODE (" << addr
1803 << ") ::BEACON_rx() ---->NUMERO DI CBEACON: "
1804 << num_cbeacon_node_rx << std::endl;
1805
1806 mac_addr_HN_in_beacon = mach->macSA(); // Mac address from which the node
1807 // has received a BEACON
1808
1809 if (debugMio_)
1810 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
1811 << ")::BEACON_rx()______________________PARAMETERS_of_"
1812 "BEACON_PACKET:"
1813 << std::endl;
1814 if (debugMio_)
1816 << NOW << "uwUFetch_SENSOR_NODE(" << addr
1817 << ")::BEACON_rx()______________________Source_address:_"
1818 << mach->macSA() << "." << std::endl;
1819 if (mach->macDA() == -1) {
1820 if (debugMio_)
1821 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
1822 << ")::BEACON_rx()______________________"
1823 "Destination_address:_BROADCAST."
1824 << std::endl;
1825 } else {
1826 if (debugMio_)
1827 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
1828 << ")::BEACON_rx()______________________"
1829 "Destination_address:_"
1830 << mach->macDA() << "." << std::endl;
1831 }
1832 if (debugMio_)
1833 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
1834 << ")::BEACON_rx()______________________MIN_backoff_"
1835 "time_PROBE_pck:_"
1836 << T_min_bck_probe_node << "[s]." << std::endl;
1837 if (debugMio_)
1838 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
1839 << ")::BEACON_rx()______________________MAX_backoff_"
1840 "time_PROBE_pck:_"
1841 << T_max_bck_probe_node << "[s]." << std::endl;
1842 if (debugMio_)
1843 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
1844 << ")::BEACON_rx()______________________MAX_number_of_"
1845 "CBEACON_that_HN_will_tx:_"
1846 << num_cbeacon_node_rx << "." << std::endl;
1847
1848 rxBEACONEnabled = false;
1849
1851 if (debugMio_)
1852 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
1853 << ")::BEACON_rx()______________________Backoff_"
1854 "choice_before_tx_PROBE:_"
1855 << bck_before_tx_probe << "[s]." << std::endl;
1856
1858
1859} // end BEACON_rx();
1860
1861void
1863{
1864 if (isHeadNode()) {
1865 /*********************
1866 * I'm the HEAD NODE *
1867 *********************/
1869
1870 } else {
1871
1872 if (debug_)
1873 std::cout << NOW << " uwUFetch_NODE (" << addr
1874 << ") ::BCKTOExpired() ---->Back-off timeout is expired:"
1875 << " so the PROBE packet now can be transmitted by the "
1876 "NODE to the HN."
1877 << std::endl;
1878 if (debugMio_)
1879 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
1880 << ")::BCKTOExpired()___________________PROBE_"
1881 "Backoff_expired."
1882 << std::endl;
1884 }
1885} // end BCKTOExpired();
1886
1887void
1889{
1890
1891 if (!Q_data.empty()) {
1892 // QUEUE is not empty so transmit the PROBE packet
1893 if (debug_)
1894 std::cout << NOW << " uwUFetch_NODE (" << addr
1895 << ") ::state_PROBE_tx() ---->NODE create a PROBE packet"
1896 << " that will then transmit at the HN with MAC address: "
1897 << mac_addr_HN_in_beacon << std::endl;
1898
1902
1903 Packet *p = Packet::alloc();
1904 hdr_cmn *cmh = hdr_cmn::access(p);
1905 hdr_mac *mach = HDR_MAC(p);
1907
1908 cmh->ptype() = PT_PROBE_UFETCH;
1909 cmh->size() = sizeof(hdr_PROBE_UFETCH);
1910
1911 mach->set(MF_CONTROL, addr, mac_addr_HN_in_beacon);
1912 mach->macSA() = addr;
1913 mach->macDA() = mac_addr_HN_in_beacon;
1914
1915 // Filling the HEADER of the PROBE packet
1916 probeh->backoff_time_PROBE() =
1917 (int) (bck_before_tx_probe * 1000); // Back off value choose by
1918 // the NODE before to
1919 // transmit the PROBE packet
1920 probeh->n_DATA_pcks_Node_tx() =
1921 Q_data.size(); // Maximum quantity of DATA packets that the NODE
1922 // would like to transmit at the HN
1923
1924 if (debugMio_)
1925 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
1926 << ")::state_PROBE_tx()_________________PARAMETER_"
1927 "of_PROBE_pck:"
1928 << std::endl;
1929 if (debugMio_)
1931 << NOW << "uwUFetch_SENSOR_NODE(" << addr
1932 << ")::state_PROBE_tx()_________________Source_address:_"
1933 << mach->macSA() << "." << std::endl;
1934 if (debugMio_)
1935 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
1936 << ")::state_PROBE_tx()_________________"
1937 "Destination_address:_"
1938 << mach->macDA() << "." << std::endl;
1939 if (debugMio_)
1940 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
1941 << ")::state_PROBE_tx()_________________DATA_pck_"
1942 "would_be_tx:_"
1943 << probeh->n_DATA_pcks_Node_tx() << "[pck]."
1944 << std::endl;
1945 if (debugMio_)
1946 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
1947 << ")::state_PROBE_tx()_________________Backoff_"
1948 "time_choice:_"
1949 << bck_before_tx_probe << "[s]." << std::endl;
1950 if (debugMio_)
1952 << NOW << "uwUFetch_SENSOR_NODE(" << addr
1953 << ")::state_PROBE_tx()_________________Size_of_PROBE_pck:_"
1954 << cmh->size() << "[byte]." << std::endl;
1955
1956 curr_PROBE_NODE_pck_tx = p->copy();
1957
1958 /*hdr_uwmphy_modem* modemh = HDR_UWMPHY_MODEM(curr_PROBE_NODE_pck_tx);
1959 modemh->use_burst_data() = 0;*/
1960
1961 Packet::free(p);
1962
1963 txPROBEEnabled = true;
1964
1965 PROBE_tx();
1966
1967 } else {
1968 // QUEUE is empty, so the NODE doesn't transmit a PROBE packet to the
1969 // HN.
1970 if (debug_)
1971 std::cout << NOW << " uwUFetch_NODE (" << addr
1972 << ") ::state_PROBE_tx() ----> NODE has no DATA packet "
1973 "to be transmitted"
1974 << " to the HN, then ignore the BEACON received from the "
1975 "HN with MAC address: "
1976 << mac_addr_HN_in_beacon << std::endl;
1977 if (debugMio_)
1978 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
1979 << ")::state_PROBE_tx()_________________0_DATA_to_"
1980 "tx_so_NO_tx_PROBE_pck."
1981 << std::endl;
1982
1984 // Node has received the maximum number of CBEACON
1985 if (debug_)
1986 std::cout << NOW << " uwUFetch_NODE (" << addr
1987 << ") ::state_PROBE_tx() ---->NODE has received the "
1988 "maximum"
1989 << " number of CBEACON packet from the HN with MAC "
1990 "address: "
1991 << mac_addr_HN_in_beacon << ", so"
1992 << " return in IDLE STATE." << std::endl;
1993
1999
2000 rxBEACONEnabled = true;
2001 txPROBEEnabled = false;
2002
2003 dataAlreadyTransmitted = false;
2004
2006
2007 } else {
2008 // Node can received another CBEACON
2009 txPROBEEnabled = false;
2010 rxCBEACONEnabled = true;
2011
2015
2017 }
2018 }
2019} // end state_PROBE_tx();
2020
2021void
2023{
2024 // NODE is enabled to transmit PROBE packet
2025 if (debug_)
2026 std::cout << NOW << " uwUFetch_NODE(" << addr
2027 << ") ::PROBE_tx() ---->NODE is transmitting a PROBE packet "
2028 "to the HN"
2029 << " with MAC address: " << mac_addr_HN_in_beacon
2030 << std::endl;
2031
2033
2035
2037
2038} // end PROBE_tx();
2039
2040void
2042{
2043
2045
2046 if (debug_)
2047 std::cout << NOW << " uwUFetch_NODE (" << addr
2048 << ") ::state_wait_POLL() ---->NODE is waiting for a POLL "
2049 "packet from HN"
2050 << " with MAC address: " << mac_addr_HN_in_beacon
2051 << ". The maximum waiting time is: " << T_POLL << std::endl;
2052
2053 if (debugMio_)
2055 << NOW << "uwUFetch_SENSOR_NODE(" << addr
2056 << ")::state_wait_POLL()________________Waiting_POLL_pck"
2057 << "_from HN(" << mac_addr_HN_in_beacon << ")." << std::endl;
2058
2059 if (debugMio_)
2060 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2061 << ")::state_wait_POLL()________________Waiting_time:_"
2062 << T_POLL << "[s]." << std::endl;
2063 if (debugMio_)
2065 << NOW << "uwUFetch_SENSOR_NODE(" << addr
2066 << ")::state_wait_POLL()________________....Waiting_POLL."
2067 << std::endl;
2068 if (debugMio_)
2070 << NOW << "uwUFetch_SENSOR_NODE(" << addr
2071 << ")::state_wait_POLL()________________....Waiting_POLL."
2072 << std::endl;
2073 if (debugMio_)
2075 << NOW << "uwUFetch_SENSOR_NODE(" << addr
2076 << ")::state_wait_POLL()________________....Waiting_POLL."
2077 << std::endl;
2078
2082
2083 rxPOLLEnabled = true;
2084
2086
2087} // end state_wait_POLL();
2088
2089void
2091{
2092
2094
2096 num_cbeacon_node_rx) { //|| (getCBeaconPckRx_by_NODE() == 0)) {
2097 // Node has received the maximum number of CBEACON
2098 if (debug_)
2099 std::cout << NOW << " uwUFetch_NODE (" << addr
2100 << ") ::PollTOExpired() ---->NODE has received the "
2101 "maximum number of"
2102 << " CBEACON packet from the HN with MAC address: "
2103 << mac_addr_HN_in_beacon << ", so"
2104 << " return in IDLE STATE." << std::endl;
2105
2106 if (debugMio_)
2107 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2108 << ")::PollTOExpired()_______________POLL_timeout_"
2109 "EXPIRED:_Max_CBEACON_pck_rx."
2110 << std::endl;
2111
2117
2118 rxBEACONEnabled = true;
2119 rxPOLLEnabled = false;
2120 txDATAEnabled = false;
2121 rxCBEACONEnabled = false;
2122 mac_addr_HN_in_beacon = addr;
2123
2124 dataAlreadyTransmitted = false;
2125
2127
2128 } else {
2129 // Node wait the successive CBEACON
2130 if (debugMio_)
2131 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2132 << ")::PollTOExpired()_______________POLL_timeout_"
2133 "EXPIRED:_another_CBEACON_can_be_rx."
2134 << std::endl;
2135
2136 rxPOLLEnabled = false;
2137
2141
2143 }
2144} // end PollTOExpired();
2145
2146void
2148{
2149
2150 if (rxPOLLEnabled) {
2151
2155
2156 hdr_mac *mach = HDR_MAC(curr_POLL_NODE_pck_rx);
2158
2163 pollh->num_DATA_pcks_MAX_rx(); // Number of DATA packets that
2164 // the node will transmit to the
2165 // HN
2166
2167 mac_addr_HN_in_poll = mach->macSA(); // MAC address of the HN from which
2168 // the node has received the POLL
2169 // packet
2170
2171 if (debugMio_)
2172 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2173 << ")::POLL_rx()________________________"
2174 "PARAMETERS_of_POLL_PACKET:"
2175 << std::endl;
2176 if (debugMio_)
2178 << NOW << "uwUFetch_SENSOR_NODE(" << addr
2179 << ")::POLL_rx()________________________Source_address:_"
2180 << mach->macSA() << std::endl;
2181 if (debugMio_)
2182 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2183 << ")::POLL_rx()________________________"
2184 "Destination_address:_"
2185 << mach->macDA() << std::endl;
2186 if (debugMio_)
2187 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2188 << ")::POLL_rx()________________________DATA_pck_"
2189 "want_rx_from_SN:_"
2190 << num_pck_to_tx_by_NODE << std::endl;
2191 if (debugMio_)
2192 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2193 << ")::POLL_rx()________________________MAC_"
2194 "address_of_POLL_rx_("
2195 << mac_addr_HN_in_poll << ")." << std::endl;
2196
2197 rxPOLLEnabled = false;
2198
2200 } else {
2201 // POLL reception is not enabled
2202 hdr_mac *mach = HDR_MAC(curr_POLL_NODE_pck_rx);
2203
2204 if (debug_)
2205 std::cout << NOW << " uwUFetch_NODE (" << addr
2206 << ") ::POLL_rx() ---->NODE is not enabled to receive the"
2207 << " POLL packet: DROP IT." << std::endl;
2208
2209 if (debugMio_)
2210 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2211 << ")::POLL_rx()________________________Not_"
2212 "ENABLED_to_rx_POLL_pck_from_HN("
2213 << mach->macSA() << ")." << std::endl;
2215 }
2216} // end POLL_rx();
2217
2218void
2220{
2221
2222 if (debug_)
2223 std::cout << NOW << " uwUFetch_NODE (" << addr
2224 << ") ::state_DATA_NODE_first_tx() ---->NODE is starting "
2225 "transmission of the"
2226 << " FIRST DATA packet to the HN with MAC address: "
2227 << mac_addr_HN_in_poll << std::endl;
2228
2229 // Pick up the first element of the queue
2230 curr_DATA_NODE_pck_tx = (Q_data.front())->copy();
2231 // Remove the element from the queue that we have pick up the packet
2232 Q_data.pop();
2233
2234 hdr_mac *mach = HDR_MAC(curr_DATA_NODE_pck_tx);
2235 hdr_cmn *cmh = hdr_cmn::access(curr_DATA_NODE_pck_tx);
2236
2237 mach->set(MF_CONTROL, addr, mac_addr_HN_in_poll);
2238 mach->macSA() = addr;
2239 mach->macDA() = mac_addr_HN_in_poll;
2240 cmh->size() = sizeof(curr_DATA_NODE_pck_tx);
2241
2243
2244 if (debugMio_)
2246 << NOW << "uwUFetch_SENSOR_NODE(" << addr
2247 << ")::state_DATA_NODE_first_tx()_______DATA_pck_tx:_source("
2248 << mach->macSA() << ")_"
2249 << "destination(" << mach->macDA() << ")_id_pck:" << cbrh->sn()
2250 << "_size:" << cmh->size() << "[byte]" << std::endl;
2251
2252 txDATAEnabled = true;
2253
2254 DATA_NODE_tx();
2255} // end state_DATA_NODE_first_tx();
2256
2257void
2259{
2260
2261 if (debug_)
2262 std::cout << NOW << " uwUFetch_NODE (" << addr
2263 << ") ::DATA_NODE_tx() ---->NODE is transmitting a DATA "
2264 "packet to the HN"
2265 << " with MAC address: " << mac_addr_HN_in_poll << std::endl;
2266
2268
2270
2271} // end DATA_NODE_tx();
2272
2273void
2275{
2276 if (isHeadNode()) {
2277 /*********************
2278 * I'm the HEAD NODE *
2279 *********************/
2281 } else {
2282
2283 if (debug_)
2284 std::cout << NOW << " uwUFetch_NODE (" << addr
2285 << ") ::DataBeforeTxTOExpired() ---->NODE can transmit "
2286 "the next"
2287 << " DATA packet." << std::endl;
2288
2290 }
2291} // end DataBeforeTxTOExpired();
2292
2293void
2295{
2296
2297 if (debug_)
2298 std::cout << NOW << " uwUFetch_NODE (" << addr
2299 << ") ::state_DATA_NODE_tx() ---->NODE is starting "
2300 "transmission of the DATA"
2301 << " packet number: " << (getDataPckTx_by_NODE() + 1)
2302 << " to the HN with MAC"
2303 << " address: " << mac_addr_HN_in_poll << std::endl;
2304
2305 // Pick up the first element of the queue
2306 curr_DATA_NODE_pck_tx = (Q_data.front())->copy();
2307 // Remove the element from the queue that we have pick up the packet
2308 Q_data.pop();
2309
2310 hdr_mac *mach = HDR_MAC(curr_DATA_NODE_pck_tx);
2311 hdr_cmn *cmh = hdr_cmn::access(curr_DATA_NODE_pck_tx);
2312
2313 mach->set(MF_CONTROL, addr, mac_addr_HN_in_poll);
2314 mach->macSA() = addr;
2315 mach->macDA() = mac_addr_HN_in_poll;
2316 cmh->size() = sizeof(curr_DATA_NODE_pck_tx);
2317
2319
2320 if (debugMio_)
2322 << NOW << "uwUFetch_SENSOR_NODE(" << addr
2323 << ")::state_DATA_NODE_tx()_____________DATA_pck_tx:_source("
2324 << mach->macSA() << ")_"
2325 << "destination(" << mach->macDA() << ")_id_pck:" << cbrh->sn()
2326 << "_size:" << cmh->size() << "[byte]" << std::endl;
2327
2328 txDATAEnabled = true;
2329
2330 DATA_NODE_tx();
2331} // end state_DATA_tx();
2332
2333void
2335{
2336
2337 if (debug_)
2338 std::cout << NOW << " uwUFetch_NODE (" << addr
2339 << ") ::state_DATA_NODE_finish_tx() ---->NODE has "
2340 "transmitted all his DATA"
2341 << " packets to the HN with MAC address: "
2342 << mac_addr_HN_in_poll << std::endl;
2343 if (debugMio_)
2344 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2345 << ")::state_DATA_NODE_finish_tx()______NODE_has_"
2346 "finished_to_tx_all_DATA_packets_to_the_HN("
2347 << mac_addr_HN_in_poll << ")." << std::endl;
2348
2350
2352 // Node has received the maximum number of CBEACON
2353 if (debug_)
2354 std::cout << NOW << " uwUFetch_NODE (" << addr
2355 << ") ::state_DATA_NODE_finish_tx() ---->NODE has "
2356 "received the maximum"
2357 << " number of CBEACON packet from the HN with MAC "
2358 "address: "
2359 << mac_addr_HN_in_poll << ", so"
2360 << " return in IDLE STATE." << std::endl;
2361
2367
2368 rxBEACONEnabled = true;
2369 txDATAEnabled = false;
2370 rxCBEACONEnabled = false;
2371
2372 dataAlreadyTransmitted = false;
2373
2375
2376 } else {
2377 // Node wait the successive CBEACON
2378 if (debug_)
2379 std::cout << NOW << " uwUFetch_NODE (" << addr
2380 << ") ::state_DATA_NODE_finish_tx() ---->NODE has not "
2381 "received the maximum"
2382 << " number of CBEACON packet from the HN with MAC "
2383 "address: "
2384 << mac_addr_HN_in_poll << ", so"
2385 << " wait a CBEACON." << std::endl;
2386
2390
2391 txDATAEnabled = false;
2392 rxCBEACONEnabled = true;
2393
2395 }
2396} // end state_DATA_NODE_finish_tx();
2397
2398void
2400{
2401
2402 double T_CBEACON = 500;
2403
2404 if (debug_)
2405 std::cout << NOW << " uwUFetch_NODE (" << addr
2406 << ") ::state_wait_CBEACON() ---->NODE is scheduling CBEACON "
2407 "TIMER T= "
2408 << T_CBEACON << "[s]" << std::endl;
2409
2413
2414 rxBEACONEnabled = false;
2415 rxCBEACONEnabled = true;
2416 if (debugMio_)
2418 << NOW << "uwUFetch_SENSOR_NODE(" << addr
2419 << ")::state_wait_CBEACON()_____________Waiting_CBEACON_pck"
2420 << "_from_HN(" << mac_addr_HN_in_beacon << ")" << std::endl;
2421 if (debugMio_)
2423 << NOW << "uwUFetch_SENSOR_NODE(" << addr
2424 << ")::state_wait_CBEACON()_____________....Waiting_CBEACON_pck"
2425 << std::endl;
2426 if (debugMio_)
2428 << NOW << "uwUFetch_SENSOR_NODE(" << addr
2429 << ")::state_wait_CBEACON()_____________....Waiting_CBEACON_pck"
2430 << std::endl;
2431 if (debugMio_)
2433 << NOW << "uwUFetch_SENSOR_NODE(" << addr
2434 << ")::state_wait_CBEACON()_____________....Waiting_CBEACON_pck"
2435 << std::endl;
2436
2437 CBEACON_timer.schedule(T_CBEACON);
2438} // end state_wait_CBEACON();
2439
2440void
2442{
2443
2444 if (debug_)
2445 std::cout << NOW << " uwUFetch_NODE (" << addr
2446 << ") ::CBeaconTOExpired() ---->NODE can not receive other "
2447 "CBEACON"
2448 << " packet from the HN with MAC address: "
2449 << mac_addr_HN_in_beacon << ", so"
2450 << " return in IDLE STATE." << std::endl;
2451 if (debugMio_)
2453 << NOW << "uwUFetch_SENSOR_NODE(" << addr
2454 << ")::CBeaconTOExpired()_______NODE_CBEACON_timeout_expired."
2455 << std::endl;
2456
2462
2463 rxBEACONEnabled = true;
2464 txPROBEEnabled = false;
2465 rxPOLLEnabled = false;
2466 txDATAEnabled = false;
2467 rxCBEACONEnabled = false;
2468
2469 dataAlreadyTransmitted = false;
2471} // end CBeaconTOExpired();
2472
2473void
2475{
2476
2477 if (rxCBEACONEnabled) {
2478 // Node is enabled to receive a CBEACON
2482
2484
2485 CBEACON_timer.force_cancel();
2486
2487 hdr_mac *mach = HDR_MAC(curr_CBEACON_NODE_pck_rx);
2488 hdr_CBEACON_UFETCH *cbeaconh =
2490
2491 /*
2492 * Save the header data of the cbeacon
2493 */
2494 T_min_bck_probe_node = (double) cbeaconh->t_min_bc() / 1000;
2495 T_max_bck_probe_node = (double) cbeaconh->t_max_bc() / 1000;
2497 cbeaconh->num_Max_CBEACON_tx_by_HN(); // Number of CBEACON that
2498 // the HN has transmitted
2499 // at this time
2500
2501 mac_addr_HN_in_cbeacon = mach->macSA(); // Mac address from which the
2502 // node has received a BEACON
2503
2504 if (debugMio_)
2505 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2506 << ")::CBEACON_rx()_____________________"
2507 "PARAMETERS_of_CBEACON_pck:"
2508 << std::endl;
2509 if (debugMio_)
2511 << NOW << "uwUFetch_SENSOR_NODE(" << addr
2512 << ")::CBEACON_rx()_____________________Source_address:_"
2513 << mach->macSA() << ". " << std::endl;
2514 if (mach->macDA() == -1) {
2515 if (debugMio_)
2516 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2517 << ")::CBEACON_rx()_____________________"
2518 "Destination_address:_BROADCAST."
2519 << std::endl;
2520 } else {
2521 if (debugMio_)
2522 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2523 << ")::CBEACON_rx()_____________________"
2524 "Destination address:_"
2525 << mach->macDA() << ". " << std::endl;
2526 }
2527 if (debugMio_)
2528 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2529 << ")::CBEACON_rx()_____________________MIN_"
2530 "backoff_time_PROBE_pck:_"
2531 << T_min_bck_probe_node << "[s]. " << std::endl;
2532 if (debugMio_)
2533 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2534 << ")::CBEACON_rx()_____________________MAX_"
2535 "backoff_time_PROBE_pck:_"
2536 << T_max_bck_probe_node << "[s]." << std::endl;
2537
2538 if ((dataAlreadyTransmitted == false)) {
2539 // NODE in the past cycle has not transmitted his data packet, so
2540 // transmit a probe
2541 if (debugMio_)
2542 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2543 << ")::CBEACON_rx()_____________________NODE_"
2544 "has_not_yet_tx_DATA_in_this_cycle"
2545 "_so_start_the_tx_of_PROBE."
2546 << std::endl;
2547
2548 rxCBEACONEnabled = false; // Indicates if or not the NODE is enabled
2549 // to receive a CBEACON packet to the HN
2550
2551 CBEACON_timer.force_cancel();
2552
2555
2556 } else {
2557 // Node has already transmitted his data packet or the CBEACON
2558 // received is receive from an HN from which the NODE has never
2559 // receive a BEACON packet
2560 if (debug_)
2561 std::cout << NOW << " uwUFetch_NODE (" << addr
2562 << ") ::CBEACON_rx() ---->NODE has received a "
2563 "CBEACON and it"
2564 << " has already transmit his DATA packets in the "
2565 "previous cycle: DROP IT."
2566 << std::endl;
2567
2569 1,
2571
2573 // Node has received the maximum number of CBEACON
2574 if (debug_)
2575 std::cout << NOW << " uwUFetch_NODE (" << addr
2576 << ") ::CBEACON_rx() ---->NODE has received the "
2577 "maximum"
2578 << " number of CBEACON packet from the HN with "
2579 "MAC address: "
2580 << mac_addr_HN_in_beacon << ", so"
2581 << " return in IDLE STATE." << std::endl;
2582 if (debugMio_)
2584 << NOW << "uwUFetch_SENSOR_NODE(" << addr
2585 << ")::CBEACON_rx()_____________________NODE_has_"
2586 "already_tx_DATA_in_this_cycle_"
2587 << "_and_maximum_number_of_CBEACON_rx."
2588 << std::endl;
2589
2595
2596 rxBEACONEnabled = true;
2597 txPROBEEnabled = false;
2598 rxPOLLEnabled = false;
2599 txDATAEnabled = false;
2600 rxCBEACONEnabled = false;
2601
2602 dataAlreadyTransmitted = false;
2604
2605 } else {
2606 if (debug_)
2607 std::cout << NOW << " uwUFetch_NODE (" << addr
2608 << ") ::CBEACON_rx() ---->NODE has not received "
2609 "the maximum"
2610 << " number of CBEACON packet from the HN with "
2611 "MAC address: "
2612 << mac_addr_HN_in_beacon << ", so"
2613 << " wait other CBEACON packets." << std::endl;
2614 if (debugMio_)
2616 << NOW << "uwUFetch_SENSOR_NODE(" << addr
2617 << ")::CBEACON_rx()_____________________NODE_has_"
2618 "already_tx_DATA_in_this_cycle_"
2619 << "_wait_another_CBEACON." << std::endl;
2620
2623
2625 }
2626 }
2627 } else {
2628 // Node is not enable to receive a CBEACON packet
2629 if (debug_)
2630 std::cout << NOW << " uwUFetch_NODE (" << addr
2631 << ") ::CBEACON_r() ---->NODE is not enabled to receive"
2632 << " the CBEACON packet: DROP IT." << std::endl;
2634
2635 CBEACON_timer.force_cancel();
2636 rxPOLLEnabled = false;
2637 POLL_timer.force_cancel();
2638
2639 hdr_mac *mach = HDR_MAC(curr_CBEACON_NODE_pck_rx);
2640 hdr_CBEACON_UFETCH *cbeaconh =
2642
2643 if (debugMio_)
2644 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2645 << ")::CBEACON_rx()_____________________SN_is_"
2646 "waiting_a_POLL_from_HN("
2647 << mach->macSA() << ")"
2648 << "_but_it_has_rx_CBEACON_from_this_HN."
2649 << std::endl;
2650 if (debugMio_)
2651 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2652 << ")::CBEACON_rx()_____________________RESET_"
2653 "POLL_timeout_and_analyzed_CBEACON_pck."
2654 << std::endl;
2655
2656 /*
2657 * Save the header data of the cbeacon
2658 */
2659 T_min_bck_probe_node = (double) cbeaconh->t_min_bc() / 1000;
2660 T_max_bck_probe_node = (double) cbeaconh->t_max_bc() / 1000;
2662 cbeaconh->num_Max_CBEACON_tx_by_HN(); // Number of CBEACON that
2663 // the HN has transmitted
2664 // at this time
2665
2666 mac_addr_HN_in_cbeacon = mach->macSA(); // Mac address from which the
2667 // node has received a BEACON
2668
2669 if (debugMio_)
2670 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2671 << ")::CBEACON_rx()_____________________"
2672 "PARAMETERS_of_CBEACON_pck:"
2673 << std::endl;
2674 if (debugMio_)
2676 << NOW << "uwUFetch_SENSOR_NODE(" << addr
2677 << ")::CBEACON_rx()_____________________Source_address:_"
2678 << mach->macSA() << ". " << std::endl;
2679 if (mach->macDA() == -1) {
2680 if (debugMio_)
2681 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2682 << ")::CBEACON_rx()_____________________"
2683 "Destination_address:_BROADCAST."
2684 << std::endl;
2685 } else {
2686 if (debugMio_)
2687 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2688 << ")::CBEACON_rx()_____________________"
2689 "Destination_address:_"
2690 << mach->macDA() << ". " << std::endl;
2691 }
2692 if (debugMio_)
2693 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2694 << ")::CBEACON_rx()_____________________MIN_"
2695 "backoff_time_PROBE_pck:_"
2696 << T_min_bck_probe_node << "[s]. " << std::endl;
2697 if (debugMio_)
2698 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2699 << ")::CBEACON_rx()_____________________MAX_"
2700 "backoff_time_PROBE_pck:_"
2701 << T_max_bck_probe_node << "[s]." << std::endl;
2702
2703 if ((dataAlreadyTransmitted == false)) {
2704 // NODE in the past cycle has not transmitted his data packet, so
2705 // transmit a probe
2706 if (debugMio_)
2707 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2708 << ")::CBEACON_rx()_____________________Not_"
2709 "yet_tx_DATA_in_this_cycle"
2710 "_start_tx_of_another_PROBE_pck."
2711 << std::endl;
2712
2713 rxCBEACONEnabled = false; // Indicates if or not the NODE is enabled
2714 // to receive a CBEACON packet to the HN
2715
2716 CBEACON_timer.force_cancel();
2717
2720
2721 } else {
2722 // Node has already transmitted his data packet or the CBEACON
2723 // received is receive from an HN from which the NODE has never
2724 // receive a BEACON packet
2725 if (debug_)
2726 std::cout << NOW << " uwUFetch_NODE (" << addr
2727 << ") ::CBEACON_rx() ---->NODE has received a "
2728 "CBEACON and it"
2729 << " has already transmit his DATA packets in the "
2730 "previous cycle: DROP IT."
2731 << std::endl;
2732
2734 1,
2736
2738 // Node has received the maximum number of CBEACON
2739 if (debug_)
2740 std::cout << NOW << " uwUFetch_NODE (" << addr
2741 << ") ::CBEACON_rx() ---->NODE has received the "
2742 "maximum"
2743 << " number of CBEACON packet from the HN with "
2744 "MAC address: "
2745 << mac_addr_HN_in_beacon << ", so"
2746 << " return in IDLE STATE." << std::endl;
2747 if (debugMio_)
2748 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2749 << ")::CBEACON_rx()_____________________"
2750 "DATA_pck_already_tx_in_this_cycle_"
2751 << "and_maximum_number_of_CBEACON_pck_rx."
2752 << std::endl;
2753
2759
2760 rxBEACONEnabled = true;
2761 txPROBEEnabled = false;
2762 rxPOLLEnabled = false;
2763 txDATAEnabled = false;
2764 rxCBEACONEnabled = false;
2765
2766 dataAlreadyTransmitted = false;
2768
2769 } else {
2770 if (debug_)
2771 std::cout << NOW << " uwUFetch_NODE (" << addr
2772 << ") ::CBEACON_rx() ---->NODE has not received "
2773 "the maximum"
2774 << " number of CBEACON packet from the HN with "
2775 "MAC address: "
2776 << mac_addr_HN_in_beacon << ", so"
2777 << " wait other CBEACON packets." << std::endl;
2778 if (debugMio_)
2779 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2780 << ")::CBEACON_rx()_____________________"
2781 "DATA_pck_already_tx_in_this_cycle_"
2782 << "and_wait_another_CBEACON_pck."
2783 << std::endl;
2784 if (debugMio_)
2785 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2786 << ")::CBEACON_rx()_____________________.."
2787 "..Waiting_CBEACON_pck."
2788 << std::endl;
2789 if (debugMio_)
2790 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2791 << ")::CBEACON_rx()_____________________.."
2792 "..Waiting_CBEACON_pck."
2793 << std::endl;
2794 if (debugMio_)
2795 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2796 << ")::CBEACON_rx()_____________________.."
2797 "..Waiting_CBEACON_pck."
2798 << std::endl;
2799
2802
2804 }
2805 }
2806 }
2807} // end CBEACON_rx();
2808
2809/*******************************************************************************
2810 * METODI AUSILIARI *
2811 ******************************************************************************/
2812bool
2814{
2815 if (HEADNODE == 1) {
2816 return true;
2817 } else {
2818 return false;
2819 }
2820} // end isHeadNode();
2821
2822double
2824{
2825 int random = (int) RNG::defaultrng()->uniform(T_min_bck_probe_node, T_max_bck_probe_node);
2826
2827 if (debug_)
2828 std::cout << NOW << "uwUFetch_NODE(" << addr
2829 << ") getting Backoff time...Value = " << 0.883 * random
2830 << std::endl;
2831 return (0.833 * random);
2832} // end choiceBackoffTimer();
2833
2834void
2836{
2837 Packet *simple_pck = Packet::alloc();
2838
2840 hdr_cmn *cmh = HDR_CMN(simple_pck);
2841 hdr_mac *mach = HDR_MAC(simple_pck);
2842 cmh->size() = sizeof(hdr_PROBE_UFETCH);
2843
2844 mach->macSA() = addr;
2845 mach->macDA() = mac_addr_HN_in_beacon;
2846 Tprobe = Mac2PhyTxDuration(simple_pck);
2847 } else {
2848 hdr_mac *mach = HDR_MAC(simple_pck);
2849 hdr_cmn *cmh = HDR_CMN(simple_pck);
2850 cmh->size() = MAX_PAYLOAD;
2851
2852 mach->macSA() = addr;
2853 Tdata_NODE = Mac2PhyTxDuration(simple_pck);
2854 }
2855 Packet::free(simple_pck);
2856} // end computeTxTime();
2857
2858void
2860{
2861 if (isHeadNode()) {
2862 /**************************
2863 * I'm THE HEAD NODE *
2864 **************************/
2866 } else {
2867 /**************************
2868 * I'm THE SENSOR NODE *
2869 **************************/
2870 hdr_uwcbr *cbrh = HDR_UWCBR(p);
2871
2872 if ((int) Q_data.size() < MAXIMUM_BUFFER_DATA_PCK_NODE) {
2873 if (debug_)
2874 std::cout << NOW << " uwUFetch_NODE (" << addr
2875 << ") ::recvFromUpperLayers() ---->NODE is queuing a "
2876 "DATA packet"
2877 << " generated by the APPLICATION layer" << std::endl;
2878
2879 if (debugMio_)
2880 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2881 << ")::recvFromUpperLayers()____________DATA_"
2882 "rx_from_upper_layer:id_pck_"
2883 << cbrh->sn() << "_STORE_IT." << std::endl;
2884
2885 Q_data.push(p);
2886 } else {
2887 if (debug_)
2888 std::cout << NOW << " uwUFetch_NODE(" << addr
2889 << ") ::recvFromUpperLayers()--->NODE dropped DATA "
2890 "packet because"
2891 << " its buffer is full" << std::endl;
2892
2893 if (debugMio_)
2894 out_file_logging << NOW << "uwUFetch_SENSOR_NODE(" << addr
2895 << ")::recvFromUpperLayers()____________DATA_"
2896 "rx_from_upper_layer:id_pck_"
2897 << cbrh->sn() << "_MEMORY_IS_FULL:_DROP_IT."
2898 << std::endl;
2899
2901 }
2902 }
2903} // end recvFromUpperLayers();
2904
2905/*******************************************************************************
2906 * EXPIRE METHODS *
2907 ******************************************************************************/
2908void
2910{
2911 if ((module->debug_))
2912 std::cout << NOW << "uwUFetch_NODE (" << module->addr
2913 << ") ::uwUFetch_BackOffTimer::expire() ---->BACK-OFF "
2914 "timeout expired."
2915 << std::endl;
2917
2918 module->BCKTOExpired();
2919} // end uwUFetch_BackOffTimer::expire();
2920
2921void
2923{
2924 if ((module->debug_))
2925 std::cout
2926 << NOW << " uwUFetch_NODE (" << module->addr
2927 << ")::uwUFetch_POLL_timer::expire() ---->POLL timeout expired"
2928 << std::endl;
2929 timer_status = UWUFETCH_TIMER_STATUS_EXPIRED;
2930
2931 module->PollTOExpired();
2932} // end uwUFetch_POLL_timer::expire();
2933
2934void
2936{
2937 if ((module->debug_))
2938 std::cout << NOW << " uwUFetch_NODE (" << module->addr
2939 << ") ::uwUFetch_DATA_BEFORE_TX_timer::expire() ---->SINGLE "
2940 "DATA timeout expired"
2941 << std::endl;
2942 timer_status = UWUFETCH_TIMER_STATUS_EXPIRED;
2943
2944 module->DataBeforeTxTOExpired();
2945} // end uwUFetch_DATA_BEFORE_TX_timer::expire();
2946
2947void
2949{
2950 if ((module->debug_))
2951 std::cout << NOW << " uwUFetch_NODE (" << module->addr
2952 << ") ::uwUFetch_CBeacon_timer::expire() ---->CBEACON "
2953 "timeout expired"
2954 << std::endl;
2955 timer_status = UWUFETCH_TIMER_STATUS_EXPIRED;
2956
2957 module->CBeaconTOExpired();
2958} // end uwUFetch_CBeacon_timer::expire();
2959
2960void
2962{
2963 std::string response;
2964 std::cout << "Press Enter to continue";
2965 std::getline(std::cin, response);
2966} // end waitForUser();
2967
2968void
2970{
2971 fout << NOW << " uwUFetch_NODE (" << addr << ") ::printStateInfo() "
2972 << "from " << statusInfo[prev_state] << " to "
2973 << statusInfo[curr_state] << ". Reason: " << statusChange[last_reason]
2974 << std::endl;
2975} // end printStateInfo()
< class uwUFetchNODEModuleClass
TclObject * create(int, const char *const *)
uwUFetchNODEModuleClass()
Constructor of uwUFetchNODEModuleClass class.
virtual void expire(Event *e)
Method called when the timer expire.
virtual void expire(Event *e)
Method called when the timer expire.
virtual void expire(Event *e)
Method called when the timer expire.
uwUFetch_NODE *UWUFETCH_TIMER_STATUS timer_status
< Pointer to an object of type uwUFetch_NODE
virtual void schedule(double val)
schedule a timer
virtual void expire(Event *e)
Method called when the timer expire.
Packet * curr_PROBE_NODE_pck_tx
Pointer to the PROBE packet that is being transmitted by SN.
int N_RUN
Indicate the number of the run in execution.
void incrTotalCBeaconPckRx_corrupted_by_NODE()
Increase the total number of corrupted CBEACON packets received by SN during an entire duration of si...
double rx_POLL_finish_time
Indicates when SN finished the reception of POLL packet from HN.
double rx_BEACON_finish_time
Indicates when SN finished the reception of BEACON packet from HN.
int getCBeaconPckRx_by_NODE()
Number of CBEACON packets received by the SN during a single cycle BEACON-PROBE-POLL-DATA-CBEACON of ...
uwUFetch_NODE()
Constructor of uwUFetch_NODE class.
bool rxCBEACONEnabled
true if SN is enabled to receive a CBEACON packet from the HN
uwUFetch_CBeacon_timer CBEACON_timer
int getTotalBeaconPckRx_by_NODE()
Total number of BEACON packets received correctly or not by SN during an entire duration of simulatio...
int n_POLL_pck_rx_by_NODE
Number of POLL received by the SN during a single cycle BEACON-PROBE-POLL-DATA-CBEACON of the simulat...
void incrBeaconPckRx_by_NODE()
Increase the number of BEACON packets received by the SN during a single cycle BEACON-PROBE-POLL-DATA...
UWUFETCH_NODE_STATUS_CHANGE last_reason
Last reason because the SN or HN change its state.
int getTotalPollPckTx_by_HN()
Total number of POLL packets transmitted by the HN during an entire simulation.
int getTotalCtsPckRx_corrupted_HN()
Total number of corrupted CTS packets received by the HN during an entire simulation.
virtual void state_DATA_NODE_finish_tx()
SN has finished to transmit the last DATA packet promises with a PROBE packet to a specif HN.
void incrTotalBeaconPckRx_corrupted_by_NODE()
Increase the total number of corrupted BEACON packets received by SN during an entire duration of sim...
double T_MIN_BACKOFF_PROBE
Lower bound timer interval of back-off value used by the SN to choice its back-off time before to tra...
virtual void DataBeforeTxTOExpired_HN()
Backoff timeout is expired.
virtual void BEACON_rx()
SN received a BEACON packet.
void incrCBeaconPckRx_by_NODE()
Increase the number of CBEACON packets received by the SN during a single cycle BEACON-PROBE-POLL-DAT...
UWUFETCH_NODE_STATUS prev_state
Previous state in which the SN or HN it was located.
double T_GUARD
Guard interval used for successive transmission of DATA packets.
int getTotalTriggerPckRx_corrupted_HN()
Total number of corrupted TRIGGER packets received by the HN during an entire simulation.
void incrDataPckTx_by_NODE()
Increase the number of DATA packets transmitted by the SN during a single cycle BEACON-PROBE-POLL-DAT...
virtual void Phy2MacEndTx_HN(const Packet *p)
Handle the end-of-PHY-transmission event for HEAD NODE.
int n_DATA_pck_tx_by_NODE
Number of DATA transmitted by the SN during a single cycle BEACON-PROBE-POLL-DATA-CBEACON of the simu...
int MAX_POLLED_NODE
Maximum number of PROBE packets that the HN can receive from the SN after the transmission of a BEACO...
virtual void Phy2MacStartRx_HN(const Packet *p)
Handle the detected-start-of-PHY-reception event for HEAD NODE.
int getTotalProbePckRx_corrupted_HN()
Total number of corrupted PROBE packets received by the HN during an entire simulation.
double T_POLL
Interval time in which the SN wait a POLL packet from the HN.
virtual void stateIdle_HN()
Idle state for HN.
double T_PROBE
Interval time in which HN is enabled to received PROBE packets from SNs after the transmission of TRI...
@ UWUFETCH_TIMER_STATUS_RUNNING
@ UWUFETCH_TIMER_STATUS_EXPIRED
static std::map< UWUFETCH_TIMER_STATUS, std::string > statusTimer
Map the UWUFETCH_TIMER_STATUS to the description of the timers.
bool txDATAEnabled
true if SN is enabled to transmit a DATA packet to the HN
int num_pck_to_tx_by_NODE
Number of DATA packets that the SN at the instant time of BEACON reception has available to transmit ...
virtual int crLayCommand(ClMessage *m)
Cross-Layer messages interpreter.
virtual void BCKTOExpired_HN()
Backoff timeout is expired.
virtual void BCKTOExpired()
Handle the.
virtual void printStateInfo(double delay=0)
Prints a file with every state change for debug purposes.
std::ofstream out_file_logging
Variable that handle the file in which the protocol write the statistics.
virtual void Phy2MacEndRx_HN(Packet *p)
Handle the end-of-PHY-reception event for HEAD NODE.
double T_max_bck_probe_node
Upper bound timer interval used by the SN to choice the interval time before to transmit a PROBE pack...
double TIME_BETWEEN_2_TX_DATA_NODE_HN
Interval time used by the SN before to transmit the next DATA packet to the HN.
double TIME_BETWEEN_2_TX_DATA_HN_AUV
Interval time used by HN before to transmit the next DATA packet to the AUV.
int mac_addr_HN_in_beacon
HN MAC address from which the SN has received PROBE packet.
static bool initialized
Indicate if the protocol has been initialized or not.
int getTotalDataPckRx_by_HN()
Total number of DATA packets correctly or not received by the HN during an entire simulation.
int getTotalPollPckRx_by_NODE()
Total number of POLL packets received correctly or not by SN during an entire duration of simulation.
int debugMio_
Used if we want to create the logging file.
virtual void Mac2PhyStartTx_HN(Packet *p)
This method must be called by the HN-MAC to instruct the PHY to start the transmission of a packet.
int getTotalCBeaconPckTx_by_HN()
Total number of CBEACON packets transmitted by the HN during an entire simulation.
int getTotalDataPckTx_by_NODE()
Total number of DATA packets transmitted by SN during an entire duration of simulation.
int getTotalTriggerPckRx_HN()
Total number of TRIGGER packets correctly or not received by the HN during an entire simulation.
virtual void refreshReason(UWUFETCH_NODE_STATUS_CHANGE reason)
Refresh the reason for the changing of the state.
int getTotalDataPckRx_corrupted_by_HN()
Total number of corrupted DATA packets received by the HN during an entire simulation.
int mac_addr_HN_in_cbeacon
HN MAC address from which the SN has received the CBEACON packet.
Packet * curr_POLL_NODE_pck_rx
Pointer to the POLL packet that is being received by SN.
int HEADNODE
Indicate if the node work as HEAD NODE or SENSOR NODE.
int MODE_COMM_HN_AUV
Indicate the type of communication between HN and AUV, 0 = communication with RTS-CTS,...
int getTotalProbePckRx_HN()
Total number of PROBE packets correctly or not received by the HN during an entire simulation.
int getTotalBeaconPckRx_corrupted_by_NODE()
Total number of corrupted BEACON packets received by SN during an entire duration of simulation.
virtual void Phy2MacEndRx(Packet *p)
Handle the end-of-PHY-reception event.
bool txPROBEEnabled
true if SN is enabled to transmit a PROBE packet to the HN
void incrTotalPollPckRx_corrupted_by_NODE()
Increase the total number of corrupted POLL packets received by SN during an entire duration of simul...
int getDataPckTx_by_NODE()
Number of DATA packets transmitted by the SN during a single cycle BEACON-PROBE-POLL-DATA-CBEACON of ...
int getTotalBeaconTx_by_HN()
Total number of BEACON packets transmitted by the HN during an entire simulation.
double tx_DATA_start_time
Indicates when SN start a transmission of DATA packet to the HN.
int MAXIMUM_BUFFER_DATA_PCK_NODE
Maximum number of DATA packets that the SN can store in Its queue.
virtual void DATA_NODE_tx()
SN transmit a DATA packet to a specific HN.
std::ofstream fout
Variable that handle the file in which the protocol write the state transition for debug purposes.
double T_MAX_BACKOFF_PROBE
Upper bound timer interval of back-off value used by the SN to choice its back-off time before to tra...
int n_BEACON_pck_rx_by_NODE
Number of BEACON receive by the SN during a single cycle BEACON-PROBE-POLL-DATA-CBEACON of the simula...
virtual void initInfo()
Initialize the protocol at the beginning of the simulation.
double rx_CBEACON_start_time
Indicates when SN started the reception of CBEACON packet from HN.
virtual void Mac2PhyStartTx(Packet *p)
This method must be called by the SN-MAC to instruct the PHY to start the transmission of a packet.
virtual void CBeaconTOExpired()
CBEACON timeout is expired.
int num_cbeacon_at_now_HN_tx
NUmber of CBEACON packets transmitted by the HN during the single cycle BEACON-PROBE-POLL-DATA-CBEACO...
int getTotalCBeaconPckRx_by_NODE()
Total number of CBEACON packets received correctly or not by SN during an entire duration of simulati...
void incrTotalBeaconPckRx_by_NODE()
Increase the total number of BEACON packets received correctly or not by SN during an entire duration...
double bck_before_tx_probe
Backoff time choiced by SN before to transmit a PROBE packet to the HN.
int n_CBEACON_pck_rx_by_NODE
Number of CBEACON received by the SN during a single cycle BEACON-PROBE-POLL-DATA-CBEACON of the simu...
double T_min_bck_probe_node
Lower bound timer interval used by the SN to choice the interval time before to transmit a PROBE pack...
UWUFETCH_NODE_STATUS curr_state
Current state in which the SN or HN is located.
static std::map< UWUFETCH_NODE_PACKET_TYPE, std::string > packetType
Map the UWUFETCH_NODE_PACKET_TYPE to the description of packet type.
void incrTotalPollPckRx_by_NODE()
Increase the total number of POLL packets received correctly or not by SN during an entire duration o...
int mac_addr_HN_in_poll
HN MAC address from which the SN has received the POLL packet.
int getTotalPollPckRx_corrupted_by_NODE()
Total number of corrupted POLL packets received by SN during an entire duration of simulation.
virtual void computeTxTime(UWUFETCH_NODE_PACKET_TYPE tp)
Compute the transmission time for the packets transmitted by the SNs.
void incrProbePckTx_by_NODE()
Increase the number of PROBE packets transmitted by the SN during a single cycle BEACON-PROBE-POLL-DA...
int getTotalCBeaconPckRx_corrupted_by_NODE()
Total number of corrupted CBEACON packets received by SN during an entire duration of simulation.
Packet * curr_BEACON_NODE_pck_rx
Pointer to the BEACON packet that is being received by SN.
int getTotalCtsPckRx_HN()
Total number of CTS packets correctly or not received by the HN during an entire simulation.
uwUFetch_BackOffTimer BCK_timer_probe
Interval time in which HN is enabled to receive PROBE packets from SNs.
double tx_DATA_finish_time
Indicates when SN finished a transmission of DATA packet to the HN.
int getTotalDataPckTx_by_HN()
Total number of DATA packets transmitted by the HN during an entire simulation.
uwUFetch_DATA_BEFORE_TX_timer DATA_BEFORE_TX_timer
virtual void CBEACON_rx()
SN has received a CBEACON packet from HN.
double rx_POLL_start_time
Indicates when SN started the reception of POLL packet from HN.
virtual void state_PROBE_tx()
SN initialize the PROBE packet that will be forwarded to a specific HN.
bool rxPOLLEnabled
true if SN is enabled to receive a POLL packet from the HN
double rx_BEACON_start_time
Indicates when SN started the reception of BEACON packet from HN.
virtual void recvFromUpperLayers_HN(Packet *p)
Handle a packet coming from upper layers of HN.
int MAX_PAYLOAD
Maximum size of payload DATA packet.
virtual void PollTOExpired()
POLL timeout is expired.
virtual void recvFromUpperLayers(Packet *p)
Handle a packet coming from upper layers of SN.
double tx_PROBE_start_time
Indicates when SN start a transmission of PROBE packet.
double Tdata_NODE_pck
Time duration need for SN for transmit a DATA packet to the HN.
double Tdata_NODE
Time duration needed for SN to transmit a DATA packet to the HN.
void incrTotalCBeaconPckRx_by_NODE()
Increase the total number of CBEACON packets received correctly or not by SN during an entire duratio...
virtual void state_wait_CBEACON()
SN wait a CBEACON packet for a pre-established interval time.
virtual bool isHeadNode()
Indicate if the node created work as head node or sensor node.
double tx_PROBE_finish_time
Indicates when SN finished a transmission of PROBE packet.
@ UWUFETCH_NODE_PACKET_TYPE_CTS
@ UWUFETCH_NODE_PACKET_TYPE_PROBE
@ UWUFETCH_NODE_PACKET_TYPE_BEACON
@ UWUFETCH_NODE_PACKET_TYPE_RTS
@ UWUFETCH_NODE_PACKET_TYPE_DATA
@ UWUFETCH_NODE_PACKET_TYPE_POLL
@ UWUFETCH_NODE_PACKET_TYPE_TRIGGER
virtual double choiceBackOffTimer()
Choose the backoff timeout used by SN before to transmit a PROBE packet.
int MODE_BURST_DATA
Indicate if it's used or not the burst data.
void incrTotalDataPckTx_by_NODE()
Increase the total number of DATA packets transmitted by SN during an entire duration of simulation.
virtual void stateIdle_NODE()
Idle state for SN.
virtual void Phy2MacStartRx(const Packet *p)
Handle the detected-start-of-PHY-reception event for SENSOR NODE.
virtual ~uwUFetch_NODE()
Destructor of uwUFetch_NODE class.
@ UWUFETCH_NODE_STATUS_CHANGE_DATA_MAX_ALLOWED_PCK_RX_0_NODE_TO_POLL_NO_OTHER_CBEACON
@ UWUFETCH_NODE_STATUS_CHANGE_DATA_PCK_TX
@ UWUFETCH_NODE_STATUS_CHANGE_MAX_DATA_PCK_TX
@ UWUFETCH_NODE_STATUS_CHANGE_DATA_MAX_ALLOWED_PCK_RX_0_NODE_TO_POLL_YES_OTHER_CBEACON
@ UWUFETCH_NODE_STATUS_CHANGE_TRIGGER_RX
@ UWUFETCH_NODE_STATUS_CHANGE_DATA_RX
@ UWUFETCH_NODE_STATUS_CHANGE_PROBE_TX
@ UWFETCH_NODE_STATUS_CHANGE_CBEACON_RX_DATA_ALREADY_TX
@ UWUFETCH_NODE_STATUS_CHANGE_DATA_TO_EXPIRED_ANOTHER_NODE_TO_POLL
@ UWUFETCH_NODE_STATUS_CHANGE_TO_WAIT_POLL_EXPIRED
@ UWUFETCH_NODE_STATUS_CHANGE_CBEACON_ALLOWED_TX_0_PROBE_RX
@ UWUFETCH_NODE_STATUS_CHANGE_DATA_TO_EXPIRED_0_NODE_TO_POLL_YES_OTHER_CBEACON
@ UWUFETCH_NODE_STATUS_CHANGE_CBEACON_TX
@ UWUFETCH_NODE_STATUS_CHANGE_CBEACON_MAX_ALLOWED_TX
@ UWUFETCH_NODE_STATUS_CHANGE_HN_RX_TRIGGER_FROM_AUV_CORRUPTED
@ UWUFETCH_NODE_STATUS_CHANGE_RTS_TX
@ UWFETCH_NODE_STATUS_CHANGE_PACKET_UNKNOWN_TYPE
@ UWUFETCH_NODE_STATUS_CHANGE_PROBE_RX
@ UWUFETCH_NODE_STATUS_CHANGE_LAST_DATA_PCK_RX
@ UWUFETCH_NODE_STATUS_CHANGE_DATA_TO_EXPIRED
@ UWFETCH_NODE_STATUS_CHANGE_STATE_IDLE
@ UWUFETCH_NODE_STATUS_CHANGE_DATA_TO_EXPIRED_0_NODE_TO_POLL_NO_OTHER_CBEACON
@ UWUFETCH_NODE_STATUS_CHANGE_CBEACON_MAX_ALLOWED_TX_0_PROBE_RX
@ UWUFETCH_NODE_STATUS_CHANGE_POLL_TX
@ UWUFETCH_NODE_STATUS_CHANGE_POLL_RX
@ UWUFETCH_NODE_STATUS_CHANGE_DATA_MAX_ALLOWED_PCK_RX_YES_NODE_TO_POLL
@ UWUFETCH_NODE_STATUS_CHANGE_CTS_RX
@ UWUFETCH_NODE_STATUS_CHANGE_BEACON_RX
@ UWUFETCH_NODE_STATUS_CHANGE_BEACON_TO_EXPIRED
@ UWUFETCH_NODE_STATUS_CHANGE_TO_WAIT_CTS_EXPIRED
@ UWUFETCH_NODE_STATUS_CHANGE_TO_EXPIRED_AT_LEAST_1_PROBE_RX
@ UWUFETCH_NODE_STATUS_CHANGE_TRIGGER_RX_BUT_HN_NO_DATA_TO_TX
@ UWFETCH_NODE_STATUS_CHANGE_PACKET_FOR_ANOTHER_NODE
@ UWFETCH_NODE_STATUS_CHANGE_PACKET_ERROR
@ UWUFETCH_NODE_STATUS_CHANGE_BEACON_TX
@ UWUFETCH_NODE_STATUS_CHANGE_HN_FINISH_TX_DATA_PCK_TO_AUV_RETURN_CBEACON_TX
@ UWUFETCH_NODE_STATUS_CHANGE_HN_TX_ALL_DATA_TO_AUV
@ UWUFETCH_NODE_STATUS_CHANGE_MAX_PROBE_RX_PROBE_TO_NOT_EXPIRED
Packet * curr_CBEACON_NODE_pck_rx
Pointer to the CBEACON packet that is being received by SN
bool rxBEACONEnabled
true if SN is enabled to receive a BEACON packet from the HN
bool dataAlreadyTransmitted
Indicate whether the SN has transmit at least one DATA packets during the cycle BEACON-PROBE-POLL-DAT...
int getTotalRtsPckTx_by_HN()
Total number of RTS packets transmitted by the HN during an entire simulation.
double Tprobe
Time duration needed for SN to transmit a PROBE packet to the HN.
int MAX_PCK_HN_WANT_RX_FROM_NODE
int getTotalProbePckTx_by_NODE()
Total number of PROBE packets transmitted by SN during an entire duration of simulation.
static std::map< UWUFETCH_NODE_STATUS_CHANGE, std::string > statusChange
Map the UWUFETCH_NODE_STATUS_CHANGE to the description the reason of changing state.
static std::map< UWUFETCH_NODE_STATUS, std::string > statusInfo
Map the UWUFETCH_NODE_STATUS to the description of each state.
int PRINT_TRANSITIONS_INT
0 reason because the SN or HN is passed from a state to another state is not logged in a file
virtual void state_DATA_NODE_first_tx()
SN initialize the FIRST DATA packet that will be forwarded to a specific HN.
void incrTotalProbePckTx_by_NODE()
Increase the total number of PROBE packets transmitted by SN during an entire duration of simulation.
double T_START_PROCEDURE_HN_NODE
Time within HN is enabled to received a TRIGGER packet from AUV.
virtual void state_wait_POLL()
SN wait a POLL packet from a specific HN.
std::queue< Packet * > Q_data
Queue of DATA packets stored by the SN.
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
uwUFetch_POLL_timer POLL_timer
Interval time in which SN is enabled to receive POLL packet from the specific HN.
int n_PROBE_pck_tx_by_NODE
Number of PROBE transmitted by the SN during a single cycle BEACON-PROBE-POLL-DATA-CBEACON of the sim...
virtual void PROBE_tx()
Transmission of PROBE packet by SN to the specific HN.
void incrPollPckRx_by_NODE()
Increase the number of POLL packets received by the SN during a single cycle BEACON-PROBE-POLL-DATA-C...
virtual void waitForUser()
Method used for debug.
Packet * curr_DATA_NODE_pck_tx
Pointer to the DATA packet that is being transmitted by SN.
virtual void state_DATA_NODE_tx()
SN initialize the second or successive DATA packet that will be forwarded to a specific HN.
virtual void POLL_rx()
SN has received a POLL packet from a specific HN.
bool print_transitions
true if the writing of state transitions in the file is enabled.
int getProbePckTx_by_NODE()
Number of PROBE packets transmitted by the SN during a single cycle BEACON-PROBE-POLL-DATA-CBEACON of...
virtual void refreshState(UWUFETCH_NODE_STATUS state)
virtual void Phy2MacEndTx(const Packet *p)
Handle the end-of-PHY-transmission event.
virtual void DataBeforeTxTOExpired()
Data timeout.
@ UWUFETCH_NODE_STATUS_PROBE_RX
@ UWUFETCH_NODE_STATUS_WAIT_CBEACON_PACKET
@ UWUFETCH_NODE_STATUS_WAIT_CTS_PACKET
@ UWUFETCH_NODE_STATUS_CBEACON_RECEIVE
@ UWUFETCH_NODE_STATUS_TRIGGER_RECEIVE
@ UWUFETCH_NODE_STATUS_POLL_RECEIVE
@ UWUFETCH_NODE_STATUS_BEACON_RECEIVE
@ UWUFETCH_NODE_STATUS_CTS_RECEIVE
@ UWUFETCH_NODE_STATUS_WAIT_DATA_NODE
@ UWUFETCH_NODE_STATUS_WAIT_POLL_PACKET
@ UWUFETCH_NODE_STATUS_TRANSMIT_PROBE
@ UWUFETCH_NODE_STATUS_WAIT_PROBE_PACKET
@ UWUFETCH_NODE_STATUS_TRANSMIT_DATA
@ UWUFETCH_NODE_STATUS_TRANSMIT_BEACON
@ UWUFETCH_NODE_STATUS_RTS_TRANSMIT
int num_cbeacon_node_rx
Number of CBEACON that the node have received from the specific HN before to receive an another BEACO...
Content header of BEACON packet.
int & t_max_bc()
Reference to t_max_bc_ variable.
int & num_Max_CBEACON_tx_by_HN()
Reference to num_Max_CBEACON_tx_by_HN_ variable.
int & t_min_bc()
Reference to t_min_bc_ variable.
Content header of CBEACON packet.
int & t_max_bc()
Reference to t_max_bc_ variable.
int & t_min_bc()
Reference to t_min_bc_ variable.
int & num_Max_CBEACON_tx_by_HN()
Reference to num_Max_CBEACON_tx_by_HN_ variable.
Content header of POLL packet.
int & num_DATA_pcks_MAX_rx()
Reference to num_DATA_pcks_MAX_rx variable.
Content header of PROBE packet.
int & n_DATA_pcks_Node_tx()
Reference to n_DATA_pcks_Node_tx_ variable.
int & backoff_time_PROBE()
Reference to backoff_time_PROBE_ variable.
hdr_uwcbr describes UWCBR packets.
uint16_t & sn()
Reference to the sn_ variable.
Declaration of uwUFetch_NODE class.
packet_t PT_POLL_UFETCH
POLL packet type for UFetch protocol.
#define UWFETCH_NODE_DROP_REASON_ERROR
Packet dropped: packet is corrupted.
#define UWUFETCH_NODE_DROP_REASON_BUFFER_FULL
Packet dropped: buffer of the node is completely full.
packet_t PT_CBEACON_UFETCH
CBEACON packet type for UFetch protocol.
packet_t PT_TRIGGER_UFETCH
TRIGGER packet type for UFetch protocol.
packet_t PT_BEACON_UFETCH
BEACON packet type for UFetch protocol.
#define UWUFETCH_NODE_DROP_CAN_NOT_RX_THIS_PCK
Packet dropped: node can not receive this type of node.
#define UWFETCH_NODE_DROP_REASON_WRONG_RECEIVER
Packet dropped: Packet is addressed to another node.
packet_t PT_PROBE_UFETCH
PROBE packet type for UFetch protocol.
#define UWUFETCH_NODE_DROP_REASON_NOT_ENABLE
Packet dropped: node is not enabled to receive this type of \ packet.
uwUFetchNODEModuleClass class_module_uwufetchnode
Common structures and variables in the protocol.
#define HDR_BEACON_UFETCH(p)
alias defined to access the BEACON HEADER
#define HDR_POLL_UFETCH(p)
alias defined to access the POLL \ HEADER
#define HDR_CBEACON_UFETCH(p)
alias defined to access the CBEACON HEADER
static const int v_speed_sound
Underwater sound propagation speed.
#define HDR_PROBE_UFETCH(p)
alias defined to access the PROBE HEADER
Provides the UWCBR packets header description and the definition of the class UWCBR.
#define HDR_UWCBR(p)