DESERT 3.5.1
Loading...
Searching...
No Matches
uwpolling_AUV.cpp
Go to the documentation of this file.
1//
2// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova.
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions
7// are met:
8// 1. Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// 2. Redistributions in binary form must reproduce the above copyright
11// notice, this list of conditions and the following disclaimer in the
12// documentation and/or other materials provided with the distribution.
13// 3. Neither the name of the University of Padova (SIGNET lab) nor the
14// names of its contributors may be used to endorse or promote products
15// derived from this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
38#include <sstream>
39
40#include "mac.h"
41#include "uwcbr-module.h"
42#include "uwpolling_AUV.h"
43#include "uwpolling_cmn_hdr.h"
44
45#include <algorithm>
46#include <float.h>
47#include <fstream>
48#include <sstream>
49#include "uwphy-clmsg.h"
50
54static class UwpollingModule_AUV_Class : public TclClass
55{
56public:
61 : TclClass("Module/UW/POLLING/AUV")
62 {
63 }
64
69 TclObject *
70 create(int, const char *const *)
71 {
72 return (new Uwpolling_AUV());
73 }
75
79
81
82std::map<Uwpolling_AUV::UWPOLLING_AUV_STATUS, std::string>
84std::map<Uwpolling_AUV::UWPOLLING_AUV_REASON, std::string>
86std::map<Uwpolling_AUV::UWPOLLING_PKT_TYPE, std::string>
88
90 : data_timer(this)
91 , probe_timer(this)
92 , poll_timer(this)
93 , ack_timer(this)
94 , list_probbed_node()
95 , probbed_sink()
96 , polling_index(0)
97 , sink_inserted(true)
98 , curr_trigger_packet(0)
99 , curr_poll_packet(0)
100 , curr_data_packet(0)
101 , curr_probe_packet(0)
102 , curr_tx_data_packet(0)
103 , curr_ack_packet(0)
104 , T_ack_timer(20)
105 , sea_trial_(0)
106 , print_stats_(0)
107 , modem_data_bit_rate(900)
108 , DATA_POLL_guard_time_(0)
109 , n_run(0)
110 , curr_state(UWPOLLING_AUV_STATUS_IDLE)
111 , prev_state(UWPOLLING_AUV_STATUS_IDLE)
112 , RxDataEnabled(false)
113 , RxProbeEnabled(false)
114 , TxEnabled(false)
115 , N_expected_pkt(0)
116 , packet_index(0)
117 , curr_polled_node_address(0)
118// , curr_backoff_time(0)
119 , curr_RTT(0)
120 , curr_Tmeasured(0)
121 , probe_rtt(0)
122 , wrong_node_data_sent(0)
123 , initial_time(0)
124 , n_trigger_tx(0)
125 , n_probe_rx(0)
126 , n_ack_rx(0)
127 , n_poll_tx(0)
128 , begin(true)
129 , stop_time(0)
130 , pkt_time(0)
131 , total_time(0)
132 , TRIGGER_uid(0)
133 , POLL_uid(0)
134 , N_dropped_probe_pkts(0)
135 , n_dropped_ack_pkts(0)
136 , N_dropped_probe_wrong_state(0)
137 , tx_buffer()
138 , max_buffer_size(50)
139 , uid_tx_pkt(1)
140 , curr_is_sink(false)
141 , max_tx_pkts(20)
142 , n_pkts_to_tx(0)
143 , last_pkt_uid(0)
144 , enableAckRx(false)
145 , acked(true)
146 , rx_pkts_map()
147 , ack_enabled(1)//modified
148 , enable_adaptive_backoff(false)
149 , backoff_LUT_file("")
150 , lut_token_separator(',')
151 , backoff_LUT()
152 , probe_counters()
153 , full_knowledge(false)
154 , last_probe_lost(0)
155{
156 bind("max_payload_", (int *) &max_payload);
157 bind("T_probe_guard_", (double *) &T_probe_guard);
158 bind("T_min_", (double *) &T_min);
159 bind("T_max_", (double *) &T_max);
160 bind("T_guard_", (double *) &T_guard);
161 bind("T_ack_timer_", (double *) &T_ack_timer);
162 bind("max_polled_node_", (int *) &max_polled_node);
163 bind("sea_trial_", (int *) &sea_trial_);
164 bind("print_stats_", (int *) &print_stats_);
165 bind("modem_data_bit_rate_", (int *) &modem_data_bit_rate);
166 bind("n_run_", (int *) &n_run);
167 bind("Data_Poll_guard_time_", (int *) &DATA_POLL_guard_time_);
168 bind("max_buffer_size_", (uint *) &max_buffer_size);
169 bind("max_tx_pkts_", (uint *) &max_tx_pkts);
170 bind("ack_enabled_", (int *) &ack_enabled); //modified
171 bind("full_knowledge_", (uint *) &full_knowledge);
172
173 mac2phy_delay_ = 5e-3;
174 if (max_polled_node <= 0) {
175 max_polled_node = 1;
176 }
179 }
182}
183
184int
185Uwpolling_AUV::command(int argc, const char *const *argv)
186{
187 Tcl &tcl = Tcl::instance();
188 if (argc == 2) {
189 if (strcasecmp(argv[1], "initialize") == 0) {
190 if (initialized == false)
191 initInfo();
192 return TCL_OK;
193 } else if (strcasecmp(argv[1], "run") == 0) {
194 stateIdle();
195 return TCL_OK;
196 } else if (strcasecmp(argv[1], "stop_count_time") == 0) {
198 return TCL_OK;
199 } else if (strcasecmp(argv[1], "GetTotalReceivingTime") == 0) {
200 tcl.resultf("%f", GetTotalReceivingTime());
201 return TCL_OK;
202 } else if (strcasecmp(argv[1], "getTriggerSent") == 0) {
203 tcl.resultf("%d", getTriggerTx());
204 return TCL_OK;
205 } else if (strcasecmp(argv[1], "getWrongNodeDataSent") == 0) {
206 tcl.resultf("%d", getWrongNodeDataSent());
207 return TCL_OK;
208 } else if (strcasecmp(argv[1], "getProbeReceived") == 0) {
209 tcl.resultf("%d", getProbeRx());
210 return TCL_OK;
211 } else if (strcasecmp(argv[1], "getPollSent") == 0) {
212 tcl.resultf("%d", getPollSent());
213 return TCL_OK;
214 } else if (strcasecmp(argv[1], "getDroppedProbePkts") == 0) {
215 tcl.resultf("%d", getDroppedProbePkts());
216 return TCL_OK;
217 } else if (strcasecmp(argv[1], "getDroppedProbeWrongState") == 0) {
218 tcl.resultf("%d", getDroppedProbeWrongState());
219 return TCL_OK;
220 }
221 } else if (argc == 3) {
222 if (strcasecmp(argv[1], "setMacAddr") == 0) {
223 addr = atoi(argv[2]);
224 if (debug_)
225 std::cout << "UWPOLLING MAC address of the AUV is " << addr
226 << std::endl;
227 return TCL_OK;
228 } else if (strcasecmp(argv[1], "getRxFromNode") == 0) {
229 tcl.resultf("%d", getRxPkts(atoi(argv[2])));
230 return TCL_OK;
231 } else if (strcasecmp(argv[1], "set_adaptive_backoff_LUT") == 0) {
232 backoff_LUT_file = std::string(argv[2]);
233 if (initBackoffLUT()) {
234 return TCL_OK;
235 } else {
236 fprintf(stderr, "Uwpolling_AUV::LUT file not opened");
237 return TCL_ERROR;
238 }
239 } else if (strcasecmp(argv[1], "setLUTSeparator") == 0) {
240 lut_token_separator = *(argv[2]);
241 return TCL_OK;
242 }
243 }
244 return MMac::command(argc, argv);
245}
246bool
248{
249 ifstream input_file_;
250 string line_;
251 input_file_.open(backoff_LUT_file.c_str());
252 double n;
253 double b;
254 if (input_file_.is_open()) {
256 backoff_LUT.clear();
257 while (std::getline(input_file_, line_)) {
258 ::std::stringstream line_stream(line_);
259
260 line_stream >> n;
261 line_stream.ignore(ENTRY_MAX_SIZE, lut_token_separator);
262 line_stream >> b;
263 backoff_LUT[n] = b;
264 }
265 input_file_.close();
266 return true;
267 }
268 return false;
269}
270double
272{
275 return T_max;
276 }
277 uint n_n = 0;
278 if(full_knowledge) {
279 ClMsgUwPhyGetLostPkts m(true);
280 sendSyncClMsg(&m);
281 n_n = (m.getLostPkts() - last_probe_lost)
284 } else {
286 }
287 //if no probe received, either there are no nodes or backoff is too low. Use
288 //Max available backoff
289 if(n_n == 0) {
290 auto it = backoff_LUT.end();
291 it --;
292 T_max = it->second;
293 T_probe = it->second+T_probe_guard;
294 //return it->second;
295 } else {
296 auto it = backoff_LUT.lower_bound(n_n);
297 if (it == backoff_LUT.end()) {
298 it--;
299 T_max = it->second;
300 T_probe = it->second+T_probe_guard;
301 //return it->second;
302 } else {
303 if(it == backoff_LUT.begin()) {
304 T_max = it->second;
305 T_probe = it->second+T_probe_guard;
306 //return it->second;
307 } else {
308 if (it->first == n_n) {
309 T_max = it->second;
310 T_probe = it->second+T_probe_guard;
311 //return it->second;
312 } else {
313 it--;
314 double n_low = it->first;
315 double b_low = it->second;
316 double n_up = (++it)->first;
317 double b_up = it->second;
318 double optimal_backoff = linearInterpolator(
319 n_n, n_low, n_up, b_low, b_up);
320 T_max = optimal_backoff;
321 T_probe = optimal_backoff+T_probe_guard;
322 //return optimal_backoff;
323 }
324 }
325 }
326 }
327 if (debug_)
328 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
329 << ")::getMaxBackoffTime::N_probe_rx="
331 << "::N_probe_detected:" << probe_counters.n_probe_detected
332 << "::estimate_N_neighbor:" << n_n
333 << "::optimal_backoff:" << T_max
334 << std::endl;
335 return T_max;
336}
337
338double
340 double x, double x1, double x2, double y1, double y2)
341{
342 double m = (y1 - y2) / (x1 - x2);
343 double q = y1 - m * x1;
344 return m * x + q;
345}
346
347int
349{
350 switch (m->type()) {
351 default:
352 return MMac::crLayCommand(m);
353 }
354}
355
356void
358{
359 if (module->debug_)
360 std::cout << module->getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << module->addr
361 << ")::DATA_TIMER::EXPIRED::Packet_received:"
362 << module->packet_index
363 << "::TOT_PACKET_EXPECTED:" << module->N_expected_pkt
364 << std::endl;
366 module->DataTOExpired();
367}
368
369void
371{
372 timer_status = UWPOLLING_EXPIRED;
373 if (module->debug_)
374 std::cout << module->getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << module->addr
375 << ")::PROBE_TIMER::EXPIRED" << std::endl;
376 module->ProbeTOExpired();
377}
378void
380{
381 timer_status = UWPOLLING_EXPIRED;
382 if (module->debug_)
383 std::cout << module->getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << module->addr
384 << ")::ACK_TIMER::EXPIRED" << std::endl;
385 module->ackTOExpired();
386}
387
388void
390{
391 timer_status = UWPOLLING_EXPIRED;
392 if (module->debug_)
393 std::cout << module->getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << module->addr
394 << ")::POLL_TIMER::EXPIRED" << std::endl;
395 module->ChangeNodePolled();
396}
397
398void
405
406void
408{
409 RxProbeEnabled = false;
410 TxEnabled = true;
412 if (polling_index > 0) {
413 stateTx();
414 } else {
415 if (debug_)
416 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
417 << ")::PROBE_TIMER::NO_PROBE_RX" << std::endl;
418 stateIdle();
419 }
420
421}
422
423void
425{
426 enableAckRx = false;
427 acked = false;
429}
430
431void
433{
434 MMac::Mac2PhyStartTx(p);
435}
436
437void
439{
441 if (debug_)
442 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
443 << ")::TX_TRIGGER::T_max= " << T_max << " T_min = " << T_min
444 << "::uid = " << TRIGGER_uid << std::endl;
445 Packet *p = Packet::alloc();
446 hdr_cmn *cmh = hdr_cmn::access(p);
447 hdr_mac *mach = HDR_MAC(p);
448 hdr_TRIGGER *triggerh = HDR_TRIGGER(p);
449 cmh->ptype() = PT_TRIGGER;
450 mach->set(MF_CONTROL, addr, MAC_BROADCAST);
451 mach->macSA() = addr;
452 mach->macDA() = MAC_BROADCAST;
453 triggerh->t_fin() = (int) (getMaxBackoffTime() * 100);
454 triggerh->t_in() = (int) (T_min * 100);
455 TRIGGER_uid++;
456 triggerh->TRIGGER_uid_ = TRIGGER_uid;
457 cmh->size() = sizeof(hdr_TRIGGER);
459 out_file_stats << left << "[" << getEpoch() << "]::" << NOW
460 << "::Uwpolling_AUV(" << addr << ")::TX_TRIGGER_ID_"
461 << TRIGGER_uid << endl;
462 curr_trigger_packet = p->copy();
463 Packet::free(p);
465 TxTrigger();
467}
468
469void
471{
472 if (debug_)
473 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV (" << addr << ")::TX_TRIGGER"
474 << std::endl;
475 incrCtrlPktsTx();
478}
479
480void
482{
483 hdr_cmn *cmh = hdr_cmn::access(p);
484 if (cmh->ptype() == PT_TRIGGER) {
487 } else if (cmh->ptype() == PT_POLL) {
489 } else {
490 if (n_tx_pkts < n_pkts_to_tx) {
491 stateTxData();
492 } else {
493 n_tx_pkts = 0;
494 if (debug_)
495 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
496 << ")::LAST_DATA_PKTS_TX" << std::endl;
497
498 if (!ack_enabled) { //modified
500 } else {
501 stateWaitAck();
502 }
503
504 //ChangeNodePolled();
505 }
506 }
507}
508
509void
511{
513 if (debug_)
514 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
515 << ")::scheduling_PROBE_TIMER_T= " << T_probe << std::endl;
516 RxProbeEnabled = true;
517 if (T_probe < 0) {
518 cerr << "Scheduling PROBE timer ----> negative value " << T_probe
519 << endl;
520 exit(1);
521 }
523}
524
525void
527{
529 RxDataEnabled = true;
530 double data_timer_value = GetDataTimerValue();
531 if (debug_)
532 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
533 << ")STATE_WAIT_DATA::Data_Timer = " << data_timer_value
534 << std::endl;
535 data_timer.schedule(data_timer_value);
536 packet_index = 0;
537}
538
539double
541{
542 UpdateRTT();
543 double timer_value = 0;
544 if (!sea_trial_) {
546 timer_value = (N_expected_pkt * Tdata) + 2*curr_RTT + T_guard;
547 } else {
548 double Tdata = T_guard + (max_payload * 8.0) / modem_data_bit_rate;
549 timer_value = (N_expected_pkt * Tdata) + 2*curr_RTT + T_guard;
550 }
551 if (timer_value <= 0) {
552 timer_value = 20;
553 if (debug_)
554 cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
555 << ")::WARNING::Data Timer Value <= 0. Setting to 20 sec"
556 << std::endl;
557
558 }
559 return timer_value;
560}
561
562void
564{
565 hdr_cmn *cmh = hdr_cmn::access(p);
566 if (cmh->ptype() == PT_PROBE || cmh->ptype() == PT_PROBE_SINK) {
567 if (debug_)
568 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
569 << ")::PHY2MACSTARTRX::PROBE_PACKET" << std::endl;
570 } else if (cmh->ptype() == PT_ACK_SINK) {
571 if (debug_)
572 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
573 << ")::PHY2MACSTARTRX::ACK_PACKET" << std::endl;
574 } else {
575 if (debug_)
576 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
577 << ")::PHY2MACSTARTRX::DATA_PACKET" << std::endl;
578 }
579}
580
581void
583{
584 hdr_cmn *cmh = hdr_cmn::access(p);
585 hdr_mac *mach = HDR_MAC(p);
586 hdr_MPhy *ph = hdr_MPhy::access(p);
587 int dest_mac = mach->macDA();
588 double gen_time = ph->txtime;
589 double received_time = ph->rxtime;
590 double diff_time = received_time - gen_time;
591
592 if (cmh->error()) {
593 if (cmh->ptype_ == PT_POLL) {
594 if (debug_)
595 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
596 << ")::PHY2MACENDRX_DROP_POLL" << endl;
597 } else if (cmh->ptype_ == PT_PROBE || cmh->ptype() == PT_PROBE_SINK) {
598 if (debug_)
599 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
600 << ")::PHY2MACENDRX_DROP_PROBE_FROM_" << mach->macSA()
601 << endl;
603 out_file_stats << left << "[" << getEpoch() << "]::"
604 << NOW << "::Uwpolling_AUV(" << addr
605 << ")::PHY2MACENDRX::DROP_PROBE_FROM_NODE_"
606 << mach->macSA() << endl;
609 } else if ((cmh->ptype_ == PT_ACK_SINK) && ack_enabled) { //modified
610 if (debug_)
611 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
612 << ")::PHY2MACENDRX_DROP_ACK" << endl;
614 }else if (cmh->ptype_ == PT_TRIGGER) {
615 if (debug_)
616 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
617 << ")::PHY2MACENDRX_DROP_TRIGGER" << endl;
618 } else {
619 if (debug_)
620 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
621 << ")::PHY2MACENDRX::DROP_DATA_FROM_NODE_"
622 << mach->macSA() << endl;
624 out_file_stats << left << "[" << getEpoch() << "]::"
625 << NOW << "Uwpolling_AUV(" << addr
626 << ")::PHY2MACENDRX::DROP_DATA_FROM_NODE_"
627 << mach->macSA() << endl;
628 incrErrorPktsRx();
629 }
632 } else {
633 if ((dest_mac == addr) || (dest_mac == (int) MAC_BROADCAST)) {
634 if (cmh->ptype_ == PT_PROBE || cmh->ptype() == PT_PROBE_SINK) {
636 incrCtrlPktsRx();
638 curr_probe_packet = p->copy();
639 Packet::free(p);
640 probe_rtt = diff_time;
641 if (debug_)
642 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
643 << ")::PHY2MACENDRX::PROBE, probe rtt"<< 2*probe_rtt << std::endl;
644
645 if (begin) {
646 begin = false;
647 initial_time = NOW;
648 }
649 stateRxProbe();
650 } else if ((cmh->ptype() == PT_ACK_SINK) && ack_enabled) { //modified
651 incrAckRx();
652 curr_ack_packet = p->copy();
653 Packet::free(p);
654 stateAckRx();
655 //check ACK value and diacard acked packets
656
657 } else {
658 if ((cmh->ptype_ != PT_POLL) && (cmh->ptype_ != PT_PROBE) &&
659 (cmh->ptype_ != PT_TRIGGER)) {
661 curr_data_packet = p->copy();
662 Packet::free(p);
663 pkt_time = NOW;
664 stateRxData();
665 }
666 }
667 } else {
668 if (debug_)
669 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
670 << ")::PHY2MACENDRX::DROP_DATA_WRONG_DEST_"
671 << mach->macDA() << endl;
672 incrXCtrlPktsRx();
674 out_file_stats << left << "[" << getEpoch() << "]::" << NOW
675 << "::Uwpolling_AUV(" << addr
676 << ")::PHY2MACENDRX::DROP_DATA_WRONG_DEST_"
677 << mach->macDA() << endl;
680 }
681 }
682}
683
684void
686{
687 Packet *fuzzy_pkt;
688 fuzzy_pkt = Packet::alloc();
689 switch (pkt) {
690 case (UWPOLLING_POLL_PKT): {
691 hdr_cmn *cmh = HDR_CMN(fuzzy_pkt);
692 hdr_mac *mach = HDR_MAC(fuzzy_pkt);
693 mach->macSA() = addr;
694 cmh->size() = sizeof(id_poll) * polling_index;
695 Tpoll = Mac2PhyTxDuration(fuzzy_pkt);
696 } break;
697 case (UWPOLLING_PROBE_PKT): {
698 hdr_cmn *cmh = HDR_CMN(fuzzy_pkt);
699 hdr_mac *mach = HDR_MAC(fuzzy_pkt);
700 mach->macSA() = addr;
701 cmh->size() = sizeof(hdr_PROBE);
702 Tprobe = Mac2PhyTxDuration(fuzzy_pkt);
703 } break;
704 case (UWPOLLING_TRIGGER_PKT): {
705 hdr_cmn *cmh = HDR_CMN(fuzzy_pkt);
706 cmh->size() = sizeof(hdr_TRIGGER);
707 hdr_mac *mach = HDR_MAC(fuzzy_pkt);
708 mach->macSA() = addr;
709 // cmh->size() = 10;
710 Ttrigger = Mac2PhyTxDuration(fuzzy_pkt);
711 } break;
712 case (UWPOLLING_DATA_PKT): {
713 hdr_cmn *cmh = HDR_CMN(fuzzy_pkt);
714 hdr_mac *mach = HDR_MAC(fuzzy_pkt);
715 mach->macDA() = addr;
716 cmh->size() = max_payload;
717 Tdata = Mac2PhyTxDuration(fuzzy_pkt);
718 }
719 }
720 Packet::free(fuzzy_pkt);
721}
722
723void
725{
727 if (debug_)
728 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
729 << ")::UPDATE_RTT--->RTT = " << curr_RTT << std::endl;
730}
731
732void
734{
736 if (RxDataEnabled) {
737 hdr_mac *mach = HDR_MAC(curr_data_packet);
739 int mac_sa = mach->macSA();
741 out_file_stats << left << "[" << getEpoch() << "]::" << NOW
742 << "::Uwpolling_AUV(" << addr
743 << ")::STATE_RX_DATA::RX_DATA_ID_" << cbrh->sn_
744 << "_FROM_NODE_" << mach->macSA() << endl;
745 if (mach->macSA() == curr_polled_node_address) {
746 if (debug_)
747 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
748 << ")::STATE_RX_DATA::RX_DATA_ID_" << cbrh->sn_
749 << "_FROM_NODE_" << mach->macSA() << endl;
750 incrDataPktsRx();
751 packet_index++;
753 sendUp(curr_data_packet);
754
757 data_timer.force_cancel();
758 if (sea_trial_) {
760 } else {
762 }
763 if (debug_)
764 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
765 << ")::RECEIVED_" << packet_index << "_PKTS"
766 << "_FROM_NODE_" << mac_sa << endl;
767 }
768
769 } else {
771 if (debug_)
772 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
773 << ")::STATE_RX_DATA::DROP_DATA_WRONG_NODE_"
774 << mach->macSA_ << std::endl;
776 out_file_stats << left << "[" << getEpoch() << "]::" << NOW
777 << "::Uwpolling_AUV(" << addr
778 << ")::STATE_RX_DATA::DROP_DATA_FROM_NODE_"
779 << mach->macDA() << "_NOT_POLLED" << endl;
781 }
782 } else {
783 incrXDataPktsRx();
784 hdr_mac *mac = HDR_MAC(curr_data_packet);
785 if (debug_)
786 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
787 << ")::STATE_RX_DATA::DROP_DATA_WRONG_STATE="
788 << status_info[curr_state] << std::endl;
790 out_file_stats << left << "[" << getEpoch() << "]::" << NOW
791 << "::Uwpolling_AUV(" << addr
792 << ")::STATE_RX_DATA::DROP_DATA_FROM_NODE_"
793 << mac->macDA() << "_NOT_POLLED" << endl;
795 }
796}
797
798void
800{
801 RxDataEnabled = false;
802 if (debug_)
803 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
804 << ")::CHANGE_NODE_POLLED::" << std::endl;
805 if (polling_index > 1) {
808 TxEnabled = true;
809 stateTx();
810 } else {
811 list_probbed_node.clear();
813 stateIdle();
814 }
815}
816
817void
819{
820 if (RxProbeEnabled) {
821 hdr_cmn* ch = HDR_CMN(curr_probe_packet);
822 hdr_mac *mach = HDR_MAC(curr_probe_packet);
823
825 incrCtrlPktsRx();
826 incrProbeRx();
827
828 if (ch->ptype() == PT_PROBE) {
830 addNode2List();
831
832 if (debug_)
833 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
834 << ")::STATE_RX_PROBE"
835 << "::N_packet_expected=" << probeh->n_pkts_
836 << "::id_node=" << probeh->id_node_
837 //<< "::BackOff Time=" << probeh->backoff_time_
838 << std::endl;
839
841 out_file_stats << left << "[" << getEpoch() << "]::" << NOW
842 << "::Uwpolling_AUV(" << addr << ")::RX_PROBE_ID_"
843 << probeh->PROBE_uid_ << "_FROM_NODE_"
844 << mach->macSA() << endl;
845
846 } else if (ch->ptype() == PT_PROBE_SINK) {
848 //handle ack in the probe packet
849 if(!acked) {
850 acked = true;
852 }
853
854 addSink2List();
855
856 if (debug_)
857 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
858 << ")::STATE_RX_PROBE_SINK"
859 << "::id_sink=" << probeh->id_sink_
860 << "::ACK_ID=" << probeh->id_ack_
861 << std::endl;
862
864 out_file_stats << left << "[" << getEpoch() << "]::" << NOW
865 << "::Uwpolling_AUV(" << addr << ")::RX_PROBE_ID_"
866 << probeh->PROBE_uid_ << "_FROM_NODE_"
867 << mach->macSA() << endl;
868
869
870 } else {
871 std::cerr << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
872 << "wrong packet type" << std::endl;
873 }
874
875 Packet::free(curr_probe_packet);
876
879 RxProbeEnabled = false;
880 TxEnabled = true;
881 probe_timer.force_cancel();
882 stateTx();
883 }
884 } else {
886 if (debug_)
887 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
888 << "):: dropping Probe Wrong State "
889 << status_info[curr_state] << std::endl;
891 }
892}
893
894void
896{
897 if (TxEnabled) {
898 if (polling_index > 0) {
900 Packet *p = Packet::alloc();
901 hdr_cmn *cmh = hdr_cmn::access(p);
902 hdr_mac *mach = HDR_MAC(p);
903 cmh->ptype() = PT_POLL;
904 cmh->size() = 2;
905 mach->set(MF_CONTROL, addr, MAC_BROADCAST);
906 mach->macSA() = addr;
907 mach->macDA() = MAC_BROADCAST;
908 curr_poll_packet = p->copy();
909 Packet::free(p);
911 POLL_uid++;
912 pollh->POLL_uid_ = POLL_uid;
913 pollh->id_ = curr_node_id;
914 pollh->POLL_time() = getPollTime();
916 out_file_stats << left << "[" << getEpoch() << "]::" << NOW
917 << "::Uwpolling_AUV(" << addr << ")::TX_POLL_ID_"
918 << POLL_uid << "_NODE_POLLED_" << curr_node_id
919 << endl;
920 if (debug_)
921 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
922 << ")::STATE_TX_POLL::Node polled = " << pollh->id_
923 << "::NODE_TO_POLL= " << polling_index << std::endl;
924 TxPoll();
925 } else {
926 if (debug_)
927 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
928 << ")::STATE_TX_POLL--->IDLE--->No node to POLL"
929 << std::endl;
930 stateIdle();
931 }
932 } else {
933 if (debug_)
934 std::cerr << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
935 << ")---> going in stateTxPoll from WRONG STATE---> "
936 "current_state: "
937 << status_info[curr_state] << std::endl;
938 }
939}
940
941void
943{
944 if (debug_)
945 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr << ")::TX_POLL"
946 << std::endl;
947 incrCtrlPktsTx();
948 incrPollTx();
950}
951
952void
954{
955 if (debug_)
956 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr << ")::SORT_NODE_TO_POLL "
957 << std::endl;
959 uint n_pkts = tx_buffer.size() + temp_buffer.size();
960 if (!sink_inserted) {
961 std::vector<probbed_node>::iterator it = list_probbed_node.begin();
962 for(; it!= list_probbed_node.end(); it++) {
963 if (n_pkts > max_tx_pkts)
964 break;
965 n_pkts += (*it).n_pkts;
966 }
968 sink_inserted = true;
969 }
970 std::vector<probbed_node>::iterator it = list_probbed_node.begin();
971
972
973 if (!list_probbed_node.empty()){
976 curr_Tmeasured = list_probbed_node[0].Tmeasured;
977 curr_node_id = list_probbed_node[0].id_node;
978 curr_is_sink = list_probbed_node[0].is_sink_;
979 }
980}
981
982void
984{
986 if (debug_)
987 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr << ")::IDLE STATE "
988 << std::endl;
989 data_timer.force_cancel();
990 probe_timer.force_cancel();
991 polling_index = 0;
992 TxEnabled = false;
993 n_tx_pkts = 0;
995}
996
997void
999{
1000 initialized = true;
1001
1002 if (sea_trial_ && print_stats_) {
1003 std::stringstream stat_file;
1004 stat_file << "./Uwpolling_AUV_" << addr << "_" << n_run << ".out";
1005 out_file_stats.open(stat_file.str().c_str(), std::ios_base::app);
1006 out_file_stats << left << "[" << getEpoch() << "]::" << NOW
1007 << "::Uwpolling_AUV(" << addr << ")::NS_START" << endl;
1008 }
1009
1010 status_info[UWPOLLING_AUV_STATUS_IDLE] = "Idle state";
1011 status_info[UWPOLLING_AUV_STATUS_RX_DATA] = "Receiving Data Packet";
1012 status_info[UWPOLLING_AUV_STATUS_RX_PROBES] = "Receiving Probe Packet";
1013 status_info[UWPOLLING_AUV_STATUS_TX_POLL] = "Transmitting a POLL Packet";
1015 "Transmitting a TRIGGER Packet";
1016 status_info[UWPOLLING_AUV_STATUS_TX_DATA] = "Transmitting a DATA Packet";
1017 status_info[UWPOLLING_AUV_STATUS_WAIT_PROBE] = "Waiting for a PROBE Packet";
1018 status_info[UWPOLLING_AUV_STATUS_WAIT_DATA] = "Waiting for a DATA Packet";
1019 status_info[UWPOLLING_AUV_STATUS_WAIT_ACK] = "Waiting for an ACK Packet";
1020
1021 pkt_type_info[UWPOLLING_DATA_PKT] = "Data Packet";
1022 pkt_type_info[UWPOLLING_POLL_PKT] = "Poll packet";
1023 pkt_type_info[UWPOLLING_TRIGGER_PKT] = "Trigger packet";
1024 pkt_type_info[UWPOLLING_PROBE_PKT] = "Probe packet";
1025
1026 reason_info[UWPOLLING_AUV_REASON_DATA_RX] = "Received a Data Packet";
1028 "Received a PROBE packet";
1029 reason_info[UWPOLLING_AUV_REASON_TX_POLL] = "POLL Packet transmitted";
1030 reason_info[UWPOLLING_AUV_REASON_TX_TRIGGER] = "Trigger Packet transmitted";
1031 reason_info[UWPOLLING_AUV_REASON_RX_DATA_TO] = "Receiving Data Time-Out";
1033 "Last Packet Received from the Node";
1035 "Last Node from the list Polled";
1037 "Maximum Number of Probe Received";
1040 "Receiving PROBE Time-Out";
1041}
1042
1043void
1045{
1046 std::string response;
1047 std::cout << "Press Enter to continue";
1048 std::getline(std::cin, response);
1049}
1050
1051void
1057
1058
1059
1060void
1062{
1063 if ((uint)(tx_buffer.size() + temp_buffer.size()) < max_buffer_size) {
1064 //since packets in the temp_buffer can be reinserted in the tx_buffer
1065 //after an ACK, i need to count for the temp buffer size as well,
1066 //to avoid buffer overflow when packets are reinserted in the tx buffer
1067 hdr_uwcbr *cbrh = HDR_UWCBR(p);
1068 if (debug_)
1069 std::cout << getEpoch() << "::" << NOW << "::UWPOLLING_AUV(" << addr
1070 << ")::RECV_FROM_U_LAYERS_ID_" << cbrh->sn_
1071 << "::MAC_UID_"<< uid_tx_pkt << endl;
1072 if (sea_trial_ && print_stats_)
1073 out_file_stats << left << "[" << getEpoch() << "]::" << NOW
1074 << "::Uwpolling_AUV(" << addr
1075 << ")::RECV_FROM_U_LAYERS_ID_" << cbrh->sn_ << endl;
1076 hdr_AUV_MULE* auvh = HDR_AUV_MULE(p);
1077 auvh->pkt_uid() = uid_tx_pkt++;
1078 hdr_cmn* ch = HDR_CMN(p);
1079 ch->size() += sizeof(hdr_AUV_MULE);
1080 tx_buffer.push_back(p);
1081 } else {
1082 if (sea_trial_ && print_stats_)
1083 out_file_stats << left << "[" << getEpoch() << "]::" << NOW
1084 << "::Uwpolling_AUV(" << addr << ")::DROP_FULL_QUEUE"
1085 << endl;
1086 if (debug_)
1087 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
1088 << ")::DROP_FULL_QUEUE" << std::endl;
1089 incrDiscardedPktsTx();
1091 }
1092}
1093
1094void
1096{
1097 if (TxEnabled) {
1098 SortNode2Poll();
1099 if(curr_is_sink){
1100
1101 if (!ack_enabled) { //modified, removed all ack things
1102 if (tx_buffer.empty()) {
1103 if (debug_)
1104 std::cout << getEpoch() << "::" << NOW << "::UWPOLLING_AUV(" << addr
1105 << ")::NO_PKTS_TO_TX, TX BUFFER IS EMPTY" << std::endl;
1107 } else {
1108 n_pkts_to_tx = std::min((uint)tx_buffer.size(),max_tx_pkts);
1109 std::deque<Packet*>::iterator it = tx_buffer.begin();
1110 for(uint i = 1; i < n_pkts_to_tx; i++) {
1111 it++;
1112 }
1113 hdr_AUV_MULE* auvh = HDR_AUV_MULE(*it);
1114 last_pkt_uid = auvh->pkt_uid();
1115 if(debug_)
1116 std::cout << getEpoch() << "::" << NOW << "::UWPOLLING_AUV(" << addr
1117 << ")TX_DATA_PKTS, N PKTS TO TX=" << n_pkts_to_tx
1118 << ", UID LAST PKTS=" << last_pkt_uid <<std::endl;
1119
1121 //question: i don't undestand ack_timer.schedule(T_ack_timer);
1122 stateTxData();
1123 }
1124
1125 }else {
1126 if (tx_buffer.empty()) {
1127 if (debug_)
1128 std::cout << getEpoch() << "::" << NOW << "::UWPOLLING_AUV(" << addr
1129 << ")::NO_PKTS_TO_TX, TX BUFFER IS EMPTY" << std::endl;
1131 } else {
1132 if (!acked) {
1133 handleNoAck();
1134 }
1135 n_pkts_to_tx = std::min((uint)tx_buffer.size(),max_tx_pkts);
1136 std::deque<Packet*>::iterator it = tx_buffer.begin();
1137 for(uint i = 1; i < n_pkts_to_tx; i++) {
1138 it++;
1139 }
1140 hdr_AUV_MULE* auvh = HDR_AUV_MULE(*it);
1141 last_pkt_uid = auvh->pkt_uid();
1142 acked = false;
1143 if(debug_)
1144 std::cout << getEpoch() << "::" << NOW << "::UWPOLLING_AUV(" << addr
1145 << ")TX_DATA_PKTS, N PKTS TO TX=" << n_pkts_to_tx
1146 << ", UID LAST PKTS=" << last_pkt_uid <<std::endl;
1147
1148 if (!sea_trial_) {
1150 } else {
1152 }
1155 double est_rtt_ack = 2*curr_Tmeasured;
1156 T_ack_timer = T_ack_timer + est_rtt_ack + T_guard;
1157 if (debug_)
1158 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
1159 << ")::scheduling_ACK_TIMER_T= " << T_ack_timer
1160 << " Est_rtt= " << est_rtt_ack << std::endl;
1162 stateTxData();
1163 }
1164 }
1165
1166 } else {
1167 stateTxPoll();
1168 }
1169 }
1170}
1171
1172void
1174{
1175 if (TxEnabled) {
1177
1179 tx_buffer.pop_front();
1180 temp_buffer.push_back(curr_tx_data_packet->copy());
1181
1183 auvh->last_pkt_uid() = last_pkt_uid;
1184 n_tx_pkts++;
1185
1186 txData();
1187 }
1188}
1189
1190void
1192{
1193 if (debug_)
1194 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr << ")::TX_DATA"
1195 << std::endl;
1196 incrDataPktsTx();
1198}
1199
1200void
1202{
1204 TxEnabled = false;
1205 enableAckRx = true;
1206 if (debug_)
1207 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
1208 << ")::stateWaitAck"<< std::endl;
1209}
1210
1211void
1213{
1214 if(enableAckRx) {
1215 if (debug_)
1216 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
1217 << ")::stateAckRx()ACK received" << std::endl;
1219 enableAckRx = false;
1220 acked = true;
1221 handleAck();
1222
1223 ack_timer.force_cancel();
1224 Packet::free(curr_ack_packet);
1226 }
1227}
1228
1229void
1231{
1233 std::vector<uint16_t> & ack_list = ackh->id_ack();
1234
1235 Packet* front_p = temp_buffer.back();
1236 hdr_AUV_MULE* auvh_tmp = HDR_AUV_MULE(front_p);
1237 if (ack_list.front() == auvh_tmp->pkt_uid()+1) {
1238 if (debug_)
1239 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
1240 << ")::handleAck()::NO_ERROR" << std::endl;
1241 while (!temp_buffer.empty()) {
1242 Packet* p = temp_buffer.back();
1243 temp_buffer.pop_back();
1244 Packet::free(p);
1245 }
1246 } else {
1247 while (!temp_buffer.empty()) {
1248
1249 Packet* p = temp_buffer.back();
1250 temp_buffer.pop_back();
1251 hdr_AUV_MULE* auvh = HDR_AUV_MULE(p);
1252 if(std::find(ack_list.begin(),ack_list.end(),auvh->pkt_uid())
1253 != ack_list.end()) {
1254 if (debug_)
1255 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
1256 << ")::handleAck()::RX_ACK,PKT_ID"
1257 << auvh->pkt_uid()<< std::endl;
1258 tx_buffer.push_front(p);
1259 } else {
1260 Packet::free(p);
1261 }
1262 }
1263 }
1264}
1265
1266void
1268{
1269 if (debug_)
1270 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
1271 << ")::handleNoAck()::reinsert pkts in tx buffer" << std::endl;
1272 while (!temp_buffer.empty()) {
1273 Packet* p = temp_buffer.back();
1274 temp_buffer.pop_back();
1275 tx_buffer.push_front(p);
1276 }
1277}
1278
1279void
1281{
1283
1284
1285 Packet* front_p = temp_buffer.back();
1286 hdr_AUV_MULE* auvh_tmp = HDR_AUV_MULE(front_p);
1287 if(probeh->id_ack() == auvh_tmp->pkt_uid()+1) {
1288 if (debug_)
1289 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
1290 << ")::handleProbeAck()::rx ACK in probe pkt,no error"
1291 << std::endl;
1292 while (!temp_buffer.empty()) {
1293 Packet* p = temp_buffer.back();
1294 temp_buffer.pop_back();
1295 Packet::free(p);
1296 }
1297 } else {
1298 if (debug_)
1299 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_AUV(" << addr
1300 << ")::handleProbeAck()::rx ACK in probe pkt,ack_id = "
1301 << probeh->id_ack() << std::endl;
1302 while (!temp_buffer.empty()) {
1303 Packet* p = temp_buffer.back();
1304 temp_buffer.pop_back();
1305 hdr_AUV_MULE* auvh = HDR_AUV_MULE(p);
1306 if (auvh->pkt_uid() >= probeh->id_ack()) {
1307 tx_buffer.push_front(p);
1308 } else {
1309 Packet::free(p);
1310 }
1311 }
1312 }
1313
1314}
1315
1316void
1318{
1320 hdr_mac *mach = HDR_MAC(curr_probe_packet);
1321
1322 //create element of the list
1323 probbed_node new_node;
1324 new_node.is_sink_ = false;
1325 new_node.id_node = probeh->id_node();
1326 new_node.n_pkts = probeh->n_pkts();
1327 new_node.time_stamp = ((double)probeh->ts())/100;
1328 new_node.mac_address = mach->macSA();
1329 new_node.Tmeasured = probe_rtt; //FTT
1330 if (rx_pkts_map.find(new_node.mac_address) != rx_pkts_map.end()) {
1331 new_node.policy_weight =
1332 ((double)new_node.n_pkts)/rx_pkts_map[new_node.mac_address];
1333 } else { //never received a packet form this node
1334 new_node.policy_weight = DBL_MAX; //MAX PRIORITY
1335 }
1336 std::vector<probbed_node>::iterator it = list_probbed_node.begin();
1337 for (;it != list_probbed_node.end(); it++) {
1338 if ((*it).policy_weight < new_node.policy_weight) {
1339 break;
1340 }
1341 }
1342 list_probbed_node.insert(it,new_node);
1343 polling_index ++;
1344}
1345
1346void
1348{
1350 hdr_mac *mach = HDR_MAC(curr_probe_packet);
1351 probbed_sink.is_sink_ = true;
1352 probbed_sink.mac_address = mach->macSA();
1354 probbed_sink.id_ack = probeh->id_ack();
1355 probbed_sink.id_node = probeh->id_sink();
1356 probbed_sink.policy_weight = -1; //NOT_VALID
1357 polling_index++;
1358 sink_inserted = false;
1359}
1360
1361uint16_t
1363{
1364 double poll_time = 0;
1365 if (!sea_trial_) {
1367 } else {
1369 }
1370 for (uint i = 0; i < list_probbed_node.size(); i++) {
1371 if (list_probbed_node[i].is_sink_) {
1372 poll_time += (std::min((uint)tx_buffer.size()+
1373 (uint)temp_buffer.size(),max_tx_pkts) * Tdata) +
1374 2*list_probbed_node[i].Tmeasured + T_guard; //check if a specific values is needed when buffer is empty
1375 } else {
1376 poll_time += (list_probbed_node[i].n_pkts * Tdata) +
1377 2*list_probbed_node[i].Tmeasured + T_guard;
1378 }
1379 }
1380 return (uint16_t)(std::ceil(poll_time));
1381}
1382
1383uint
1385{
1386 std::map<int,uint>::iterator it = rx_pkts_map.find(mac_addr);
1387 if (it != rx_pkts_map.end()) {
1388 return it->second;
1389 } else {
1390 return -1;
1391 }
1392
1393}
ClMsgUwPhyGetLostPkts should be used by a layer to ask the phy how many packets it discarded from the...
uint getLostPkts()
method to return the number of packets lost by the phy.
Class that represents the binding with the tcl configuration script.
TclObject * create(int, const char *const *)
Creates the TCL object needed for the tcl language interpretation.
UwpollingModule_AUV_Class()
Constructor of the class.
virtual void expire(Event *e)
Method call when the timer expire.
virtual void expire(Event *e)
Method called when the timer expire.
virtual void expire(Event *e)
Method call when the timer expire.
virtual void expire(Event *e)
Method call when the timer expire.
Uwpolling_AUV *UWPOLLING_TIMER_STATUS timer_status
< Pointer to an object of type Uwpolling_AUV
virtual void schedule(double val)
Schedules a timer.
Class used to represent the UWPOLLING MAC layer of the AUV.
std::deque< Packet * > tx_buffer
Queue of DATA in number of packets.
virtual void initInfo()
Prints a file with every state change for debug purposes.
virtual void Phy2MacStartRx(const Packet *p)
Method called when the Phy Layer start to receive a Packet.
PollTimer poll_timer
POLL Timer.
virtual void refreshState(UWPOLLING_AUV_STATUS state)
Refresh the state of the protocol.
Packet * curr_data_packet
Pointer to the current DATA packet.
virtual void ChangeNodePolled()
The first element of the list of nodes is trimmed and the next node is polled.
Packet * curr_tx_data_packet
Pointer to the current DATA packet.
Packet * curr_probe_packet
Pointer to the current PROBE packet.
probbed_node probbed_sink
Element with sink probe data.
void incrPollTx()
Incrase the number of POLL transmitted.
virtual uint16_t getPollTime()
Estimate the time needed by the AUV to POLL all the remaining node in the probbed node list.
int full_knowledge
Set to a number != 0 means we have full_knowledge about the estimate of neighbors.
void incrTriggerTx()
Increases the number of TRIGGER packets sent.
std::vector< probbed_node > list_probbed_node
list of nodes that have sent correctly the PROBE
virtual void handleNoAck()
Handle case with no ack received.
double Ttrigger
Time needed to transmit a TRIGGER packet.
virtual void Mac2PhyStartTx(Packet *p)
Pass the packet to the PHY layer.
int modem_data_bit_rate
Bit rate of the modem used.
virtual void TxTrigger()
Transmission of the TRIGGER packet.
uint n_tx_pkts
Number of packets transmitted by the AUV during a TxData session.
virtual void stop_count_time()
Informs the protocol to stop counting the time in which the AUV receive DATA packets from the nodes I...
std::string backoff_LUT_file
File name of the backoff LUT.
virtual void stateIdle()
IDLE state.
virtual void waitForUser()
Used for debug purposes.
uint POLL_uid
POLL Unique ID.
uint TRIGGER_uid
TRIGGER Unique ID.
double Tdata
Time needed to transmit a DATA packet.
static std::map< UWPOLLING_AUV_REASON, std::string > reason_info
Map the UWPOLLING_AUV_STATUS to the description of each state.
@ UWPOLLING_AUV_REASON_PACKET_ERROR
@ UWPOLLING_AUV_REASON_RX_DATA_TO
@ UWPOLLING_AUV_REASON_PROBE_TO_EXPIRED
@ UWPOLLING_AUV_REASON_PROBE_RECEIVED
@ UWPOLLING_AUV_REASON_MAX_PROBE_RECEIVED
@ UWPOLLING_AUV_REASON_LAST_POLLED_NODE
@ UWPOLLING_AUV_REASON_LAST_PACKET_RECEIVED
@ UWPOLLING_AUV_REASON_TX_TRIGGER
virtual void SortNode2Poll()
Method in which the node that has sent correctly the PROBE packet is sorted in order to give the prio...
virtual void stateRxProbe()
State of the protocol in which there's a reception of a PROBE packet.
double curr_Tmeasured
Time elapsed between the transmission of the TRIGGER and the reception of the PROBE packet by the pol...
AckTimer ack_timer
ACK Timer.
int sea_trial_
Sea Trial flag: To activate if the protocol is going to be tested at the sea.
virtual void DataTOExpired()
DATA TIMER is Expired.
static bool initialized
Map the UWPOLLING_AUV_REASON to the description of each reason.
double T_probe
Duration of PROBE TIMER.
virtual double linearInterpolator(double x, double x1, double x2, double y1, double y2)
Calculate the linear interpolation between two 2-D points.
double total_time
Total time in which the AUV has received data packets.
Packet * curr_ack_packet
Pointer to the current ACK packet.
int getDroppedProbeWrongState()
Return the number of PROBE packets discarded because sent after the maximum time allowed.
void incrDroppedAckPkts()
Increases the number of wrong ACK packet received.
virtual void UpdateRTT()
Update the RTT between a node and the AUV based on the time elapsed between the transmisison of the T...
int getProbeRx()
Returns the number of PROBE received during the simulation.
int getWrongNodeDataSent()
Returns the number of Data Packet sent by Nodes not polled (used for debug purposes)
int DATA_POLL_guard_time_
Guard time between the reception of the last data and the transmission of the following POLL.
uint max_buffer_size
Temp buffer where packets are insert waiting for an ACK.
double T_guard
Guard time added to the calculation of the RTT.
int getPollSent()
Return the number of POLL packets sent during the simulation.
uint16_t uid_tx_pkt
Unique ID of the transmitted packets.
uint curr_node_id
ID of the node polled.
uint n_pkts_to_tx
Number of packets to transmit during a TxData session.
virtual void computeTxTime(UWPOLLING_PKT_TYPE pkt)
Compute the Transmission Time for various type of packet using a CrossLayer Message to ask the PHY to...
virtual void Phy2MacEndRx(Packet *p)
Method called when the Phy Layer finish to receive a Packet.
virtual void stateTxData()
Handle the data transmission after poll reception.
int max_polled_node
Maximum number of node that the AUV can poll each time.
int ack_enabled
True if ack is enabled, false if disabled, default true.
bool curr_is_sink
True if the current node of the list is a sink.
virtual void ackTOExpired()
ACK TIMER is Expired.
void incrDroppedProbePkts()
Increases the number of wrong PROBE packet received.
bool RxProbeEnabled
true if the AUV is enabled to receive PROBE packets, false otherwise
double probe_rtt
RTT calculation between AUV and NODE based on the time of PROBE transmission and reception.
double Tpoll
Time needed to transmit a POLL packet.
double T_max
Maximum value in which the node can choose his backoff time.
bool enableAckRx
True if the ack reception is enabled.
int getTriggerTx()
Returns the number of TRIGGER sent during the simulation.
static std::map< UWPOLLING_PKT_TYPE, std::string > pkt_type_info
Map the UWPOLLING_PKT_TYPE to the description of each type of packet.
double T_min
Minimum value in which the node can choose his backoff time.
ProbeTimer probe_timer
PROBE Timer.
virtual void refreshReason(UWPOLLING_AUV_REASON reason)
Refresh the reason for the changing of the state.
std::map< int, uint > rx_pkts_map
Map (mac_addr,rx_pkts) with the received packets for each node.
int print_stats_
Print protocol's statistics of the protocol.
void incrWrongNodeDataSent()
Increases the number of DATA packets received from node that are not POLLED anymore (i....
static std::map< UWPOLLING_AUV_STATUS, std::string > status_info
probe_cicle_counters probe_counters
Number of probe detected in a round (i.e., prehamble received)
virtual void handleAck()
Handle a received ack, reinserting in the buffer the packet not received by the sink.
virtual void addNode2List()
Add a node to the list of probbed nodes.
virtual void stateWaitData()
State of the protocol in which the DATA timer is set up.
virtual void stateTxPoll()
State of the protocol in which a POLL packet is initialized.
virtual void stateWaitAck()
State of the protcol in which the ACK timer is set up.
void incrAckRx()
Increases the number of Ack packets received.
void incrDroppedProbeWrongState()
Increase the number of PROBEs packets dropped because the AUV was not in the RX_PROBE state.
virtual void stateTxTrigger()
State of the protocol in which a TRIGGER packet is initialized.
virtual void handleProbeAck()
Handle the ack received in the probe packet tx by the sink.
int getDroppedProbePkts()
Return the number of PROBE packets discarded because of wrong CRC.
virtual uint getRxPkts(int mac_addr)
Get the packets received from the node with the given mac address.
double pkt_time
Time needed to transmit a data packet.
Packet * curr_trigger_packet
true if the sink has been inserted in the list
bool RxDataEnabled
true if the AUV is enabled to receive DATA packets, false otherwise
virtual void stateAckRx()
Handle the recption of an ACK from the sink.
void incrProbeRx()
Increases the number of PROBE packets received.
uint16_t last_pkt_uid
ID of the last packet transmitted in the round.
DataTimer data_timer
Data timer.
virtual void recvFromUpperLayers(Packet *p)
Handle a packet coming from upper layers.
double stop_time
Time stamp in which the AUV finish to receive data packets.
uint max_tx_pkts
Max number of packets can be transmitted by the AUV during a TxData session.
double T_probe_guard
Guard time for PROBE packet: T_probe=T_max+T_probe_guard.
std::ofstream out_file_stats
Variable that handle the file in which the protocol write the statistics.
virtual void addSink2List()
Add a sink node to the list of probbed nodes.
UWPOLLING_AUV_STATUS curr_state
int max_payload
Duration of ACK_TIMER.
std::deque< Packet * > temp_buffer
double Tprobe
Time needed to transmit a PROBE packet.
int N_expected_pkt
Number of packets that the node polled wish to transmit to the AUV.
double initial_time
Timestamp in which the AUV receive the first data packet.
virtual void TxPoll()
Transmisssion of the POLL packet.
virtual void stateWaitProbe()
State of the protocol in which the PROBE timer is set up.
std::map< double, double > backoff_LUT
Map with the backoff LUT.
int packet_index
Variable that indicate the number of the packet that has been just received by the AUV.
virtual ~Uwpolling_AUV()
Destructor of the Uwpolling_AUV class.
virtual void ProbeTOExpired()
PROBE TIMER is Expired.
double GetTotalReceivingTime()
Permits to retrieve the total time in which the AUV has received DATA packets.
virtual double GetDataTimerValue()
Calculation of DATA TIMER value based on the number of packet that a node need to transmit,...
virtual void Phy2MacEndTx(const Packet *p)
Method called when the PHY layer finish to transmit the packet.
bool initBackoffLUT()
Initialize the backoff LUT.
bool acked
True if an ack has been received.
virtual void txData()
Transmit data transmission after poll reception.
int curr_polled_node_address
MAC address of the node polled.
@ UWPOLLING_AUV_STATUS_WAIT_ACK
@ UWPOLLING_AUV_STATUS_TX_TRIGGER
@ UWPOLLING_AUV_STATUS_RX_PROBES
@ UWPOLLING_AUV_STATUS_WAIT_DATA
@ UWPOLLING_AUV_STATUS_WAIT_PROBE
Uwpolling_AUV()
Constructor of the Uwpolling_AUV class.
virtual int crLayCommand(ClMessage *m)
Cross-Layer messages interpreter.
unsigned long int getEpoch()
Calculate the epoch of the event.
int polling_index
Index of the node that the AUV is polling.
bool TxEnabled
true if the AUV is enabled to receive POLL packets, false otherwise
virtual void stateTx()
Handle the transmission after poll reception.
bool enable_adaptive_backoff
Set to true if backoff is chosen adaptively.
char lut_token_separator
LUT token separator.
bool begin
indicate the first PROBE received
virtual void stateRxData()
State of the protocol in which there's a reception of a DATA packet.
Packet * curr_poll_packet
Pointer to the current POLL packet.
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
double curr_RTT
Round Trip time of the node polled.
double getMaxBackoffTime()
Reference to the backoff_time variable.
Header of the ACK sent by the SINK.
std::vector< uint16_t > & id_ack()
Reference to the id_ack_ variable.
Header of the data sent from AUV MULE to SINK.
uint16_t & last_pkt_uid()
Reference to the last_pkt_uid_ variable.
uint16_t & pkt_uid()
Reference to the pkt_uid_ variable.
Header of the POLL message.
int id_
ID of the POLLED node.
uint16_t & POLL_time()
uint POLL_uid_
POLL packet unique ID.
Header of the PROBE message.
uint id_sink_
ID of the sink.
uint16_t & id_ack()
Reference to id_ack_ variable.
uint16_t id_ack_
ID used for ack purpose.
uint & id_sink()
Reference to id_sink variable.
uint PROBE_uid_
Unique ID of the PROBE packet.
Header of the PROBE message.
uint PROBE_uid_
Unique ID of the PROBE packet.
uint & id_node()
Reference to id_node variable.
uint16_t & ts()
Reference to timestamp variable.
int & n_pkts()
Reference to backoff_time variable.
uint id_node_
ID of the node.
int n_pkts_
Number of packets that the node wish to transmit to the AUV.
Header of the TRIGGER message.
uint TRIGGER_uid_
TRIGGER packet unique ID.
uint16_t & t_in()
Reference to the t_in variable.
uint16_t & t_fin()
Reference to the t_fin variable.
hdr_uwcbr describes UWCBR packets.
uint16_t sn_
Serial number of the packet.
Internal structure where the AUV store the informations about the node to POLL.
int n_pkts
Number of packets that the node transmit when he's polled.
double time_stamp
Timestamp of the most recent data packet generated by the node.
uint id_node
Id of the node.
double Tmeasured
Time elapsed between the transmisssion of the TRIGGER and the reception of the PROBE.
bool is_sink_
Ture if the probe comes from a sink.
uint16_t id_ack
Id used for ack purpose is the proebbed node is a sink.
double policy_weight
Weigth used to choose the order to poll the nodes.
int mac_address
Mac Address of the node.
uint n_probe_received
Number of probe received in a round (i.e., prehamble received)
uint n_probe_detected
Number of probe (prehamble) detected in a round by the MAC.
void incrementCounters()
Increment both counters.
void resetCounters()
Reset both counters.
uint getNumberOfNeighbors()
Get estimate number of neighbors.
Provides the UWCBR packets header description and the definition of the class UWCBR.
#define HDR_UWCBR(p)
const double q
Definition of ClMsgUwMmac class.
UwpollingModule_AUV_Class class_module_uwpolling_auv
Class that represents the AUV of UWPOLLING.
#define ENTRY_MAX_SIZE
#define UWPOLLING_AUV_DROP_REASON_WRONG_RECEIVER
Packet for another node.
#define UWPOLLING_AUV_DROP_REASON_BUFFER_FULL
#define UWPOLLING_AUV_DROP_REASON_WRONG_STATE
The AUV cannot receive this kind of packet in this state.
#define UWPOLLING_AUV_DROP_REASON_ERROR
Packet corrupted.
Common structures and variables in the protocol.
#define HDR_PROBE_SINK(p)
alias defined to access the ACK SINK HEADER
static const int MAX_POLLED_NODE
Maximum number of node to POLL.
#define HDR_ACK_SINK(p)
alias defined to access the ACK SINK HEADER
#define HDR_POLL(p)
alias defined to access the POLL HEADER
struct POLL_ID id_poll
Single location of the POLL vector.
#define HDR_AUV_MULE(p)
alias defined to access the AUV MULE HEADER
#define HDR_TRIGGER(p)
alias defined to access the TRIGGER HEADER \
#define HDR_PROBE(p)
alias defined to access the PROBE HEADER