DESERT 3.5.1
Loading...
Searching...
No Matches
uwpolling_SINK.cpp
Go to the documentation of this file.
1//
2// Copyright (c) 2019 Regents of the SIGNET lab, University of Padova.
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions
7// are met:
8// 1. Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// 2. Redistributions in binary form must reproduce the above copyright
11// notice, this list of conditions and the following disclaimer in the
12// documentation and/or other materials provided with the distribution.
13// 3. Neither the name of the University of Padova (SIGNET lab) nor the
14// names of its contributors may be used to endorse or promote products
15// derived from this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28//
29
39#include "uwpolling_SINK.h"
40#include "mmac.h"
41#include "mac.h"
42#include "uwcbr-module.h"
43#include "mphy_pktheader.h"
44#include "rng.h"
45
46#include <algorithm>
47#include <sstream>
48#include <sys/time.h>
49
51map<Uwpolling_SINK::UWPOLLING_SINK_STATUS, string> Uwpolling_SINK::status_info;
52map<Uwpolling_SINK::UWPOLLING_SINK_REASON, string> Uwpolling_SINK::reason_info;
53map<Uwpolling_SINK::UWPOLLING_PKT_TYPE, string> Uwpolling_SINK::pkt_type_info;
54
55
59static class UwpollingModule_SINK_Class : public TclClass
60{
61public:
66 : TclClass("Module/UW/POLLING/SINK")
67 {
68 }
69
74 TclObject *
75 create(int, const char *const *)
76 {
77 return (new Uwpolling_SINK());
78 }
80
82 : MMac()
83 , T_data(0)
84 , T_data_gurad(0)
85 , backoff_tuner(0)
86 , sink_id(0)
87 , RxDataEnabled(false)
88 , Triggered(false)
89 , triggerEnabled(true)
90 , T_in(0)
91 , T_fin(0)
92 , BOffTime(0)
93 , AUV_mac_addr(0)
94 , n_probe_sent(0)
95 , n_trigger_received(0)
96 , n_trigger_dropped(0)
97 , n_ack_sent(0)
98 , n_curr_rx_pkts(0)
99 , expected_id(1)
100 , last_rx(0)
101 , send_ACK(false)
102 , missing_id_list()
103 , expected_last_id(0)
104 , prev_expect_last_id(0)
105 , duplicate_pkts(0)
106 , first_rx_pkt(true)
107 , PROBE_uid(0)
108 , curr_data_pkt(0)
109 , curr_probe_pkt(0)
110 , curr_trigger_pkt(0)
111 , curr_ack_pkt(0)
112 , last_reason()
113 , curr_state(UWPOLLING_SINK_STATUS_IDLE)
114 , prev_state(UWPOLLING_SINK_STATUS_IDLE)
115 , backoff_timer(this)
116 , rx_data_timer(this)
117 , fout(0)
118 , out_file_stats(0)
119 , sea_trial(0)
120 , print_stats(0)
121 , n_run(0)
122 , useAdaptiveTdata(0)
123 , ack_enabled(1)
124 , max_n_ack(100)
125 , T_guard(1)
126 , max_payload(125)
127 , modem_data_bit_rate(900)
128{
129 bind("T_data_guard_", (double *) &T_data_gurad);
130 bind("backoff_tuner_", (double *) &backoff_tuner);
131 bind("sink_id_", (uint *) &sink_id);
132 bind("sea_trial_", (int *) &sea_trial);
133 bind("n_run_", (int *) &n_run);
134 bind("print_stats_", (int *) &print_stats);
135 bind("useAdaptiveTdata_", (int *) &useAdaptiveTdata);
136 bind("ack_enabled_", (int *) &ack_enabled);
137 bind("max_n_ack_", (int *) &max_n_ack);
138 bind("T_guard_", (double *) &T_guard);
139 bind("max_payload_", (int *) &max_payload);
140 bind("modem_data_bit_rate_", (int *) &modem_data_bit_rate);
141
142 if (T_data_gurad <= 0)
144}
145
149
150int
151Uwpolling_SINK::command(int argc, const char *const *argv)
152{
153 Tcl &tcl = Tcl::instance();
154 if (argc == 2) {
155 if (strcasecmp(argv[1], "initialize") == 0) {
156 if (!initialized)
157 initInfo();
158 return TCL_OK;
159 } else if (strcasecmp(argv[1], "getProbeSent") == 0) {
160 tcl.resultf("%d", getProbeSent());
161 return TCL_OK;
162 } else if (strcasecmp(argv[1], "getAckSent") == 0) {
163 tcl.resultf("%d", getAckSent());
164 return TCL_OK;
165 } else if (strcasecmp(argv[1], "getTriggerReceived") == 0) {
166 tcl.resultf("%d", getTriggerReceived());
167 return TCL_OK;
168 } else if (strcasecmp(argv[1], "getTriggerDropped") == 0) {
169 tcl.resultf("%d", getTriggerDropped());
170 return TCL_OK;
171 } else if (strcasecmp(argv[1], "getDuplicatedPkts") == 0) {
172 tcl.resultf("%d", getDuplicatedPkt());
173 return TCL_OK;
174 }
175 } else if (argc == 3) {
176 if (strcasecmp(argv[1], "setMacAddr") == 0) {
177 addr = atoi(argv[2]);
178 return TCL_OK;
179 }
180 }
181 return MMac::command(argc, argv);
182}
183
184int
186{
187 switch (m->type()) {
188 default:
189 return MMac::crLayCommand(m);
190 }
191}
192
193void
195{
196 if (module->debug_) {
197 std::cout << NOW << "Uwpolling_SINK(" << module->addr
198 << ")::BACKOFF_TIMER::EXPIRED" << std::endl;
199 }
201 module->BackOffTimerExpired();
202}
203
204void
206{
207 if (module->debug_) {
208 std::cout << NOW << "Uwpolling_SINK(" << module->addr
209 << ")::RX_DATA_TIMER::EXPIRED" << std::endl;
210 }
211 timer_status = UWPOLLING_EXPIRED;
212 module->RxDataTimerExpired();
213}
214
215void
217{
218 hdr_cmn *ch = HDR_CMN(p);
219 hdr_mac *mach = HDR_MAC(p);
220 int dest_mac = mach->macDA();
221 if (ch->error()) { //discard packet
222 //DISCARD PACKET AND INCREMENTS DEDICATED COUNTER
223 if (ch->ptype() == PT_TRIGGER) {
224 if (debug_)
225 std::cout << NOW << "Uwpolling_SINK(" << addr
226 << ")::PHY2MACENDRX::DROP_TRIGGER" << std::endl;
227 if (sea_trial && print_stats)
228 out_file_stats << left << "[" << getEpoch() << "]::" << NOW
229 << "::Uwpolling_SINK(" << addr
230 << ")::PKT_TRIGGER_DROP_ERROR" << endl;
232 }
235 } else {
236 if (dest_mac == addr || dest_mac == (int) MAC_BROADCAST) { //Check MAC address
237 if (ch->ptype() == PT_TRIGGER) {
238 curr_trigger_pkt = p->copy();
239 Packet::free(p);
242 } else if (ch->ptype() != PT_POLL && ch->ptype() != PT_PROBE &&
243 ch->ptype() != PT_ACK_SINK) { //data pkt
244
245 curr_data_pkt = p->copy();
246 Packet::free(p);
248 stateRxData();
249 } else {
250 if (ch->ptype() == PT_POLL && RxDataEnabled && useAdaptiveTdata) {
251 hdr_POLL *pollh = HDR_POLL(p);
253 if (debug_)
254 std::cout << NOW << "Uwpolling_SINK(" << addr
255 << ")::Resched rx data timer, timeout="
256 << pollh->POLL_time() << std::endl;
257 }
258 // PT_PROBE, PT_ACK_SINK and PT_POLL are not considerd by
259 // the SINK
261 }
262 } else {
263 //PACKET NOT FOR ME, DISCARD IT
265 }
266 }
267}
268
269void
271{
272 /* Reset timer and move to STATE_IDLE*/
273 if (debug_) {
274 std::cout << NOW << "Uwpolling_SINK(" << addr << ")::IDLE_STATE"
275 << std::endl;
276 }
278 Triggered = false;
279 RxDataEnabled = false;
280 send_ACK = false;
281 n_curr_rx_pkts = 0;
282 first_rx_pkt = true;
283 triggerEnabled = true;
284 backoff_timer.force_cancel();
285 rx_data_timer.force_cancel();
286}
287
288void
290{
291 if (triggerEnabled) {
292 if (RxDataEnabled && !send_ACK) { //probe was sent, but no packets has been received by AUV
293 RxDataEnabled = false;
294 rx_data_timer.force_cancel();
295 }
296 //triggerEnabled = false;
297 Triggered = true;
300 hdr_mac *mach = HDR_MAC(curr_trigger_pkt);
301 AUV_mac_addr = mach->macSA();
302 if (debug_)
303 std::cout << NOW << "Uwpolling_SINK(" << addr
304 << ")::STATE_RX_TRIGGER, rx from MAC="
305 << AUV_mac_addr<< std::endl;
306
308 T_fin = (double)trig_h->t_fin()/100;
309 T_in = (double)trig_h->t_in()/100;
312 if (BOffTime < 0) {
313 std::cerr << "Negative backoff value " << std::endl;
314 BOffTime = T_fin;
315 }
317 Packet::free(curr_trigger_pkt);
318 } else {
319 Packet::free(curr_trigger_pkt);
320 if (debug_)
321 std::cout << NOW << "Uwpolling_SINK(" << addr
322 << ")::RX_TRIGGER_NOT_ENABLED" << std::endl;
323 }
324}
325
326double
328{
329 double random = ((double)(RNG::defaultrng()->uniform(INT_MAX) % (int)((T_fin-T_in)*100)))/100 + T_in;
330 if (debug_)
331 std::cout << NOW << "Uwpolling_SINK(" << addr
332 << ")::BACKOFF_TIMER_VALUE = " << backoff_tuner * random
333 << std::endl;
334 return (backoff_tuner * random);
335}
336
337void
339{
340 if (Triggered) {
342 stateTxProbe();
343 } else {
344 if (debug_) {
345 std::cout << NOW << "Uwpolling_SINK(" << addr
346 << ") Backoff timer expired but node not triggered"
347 << std::endl;
348 }
349 }
350}
351
352void
354{
355 if (Triggered) {
359 if (sea_trial && print_stats) {
360 out_file_stats << left << "[" << getEpoch() << "]::" << NOW
361 << "::Uwpolling_SINK(" << addr
362 << ")::TX_PROBE_ID_" << probehdr->PROBE_uid() << std::endl;
363 }
364 if (debug_) {
365 std::cout << NOW << "Uwpolling_SINK(" << addr
366 << ")::STATE_TX_PROBE_ID_" << probehdr->PROBE_uid()
367 << std::endl;
368 }
369 TxProbe();
370 }
371}
372
373void
375{
376 if (pkt_type == UWPOLLING_PROBE_PKT) {
377 Packet *p = Packet::alloc();
378 hdr_PROBE_SINK *probehdr = HDR_PROBE_SINK(p);
379 hdr_cmn *ch = hdr_cmn::access(p);
380 hdr_mac *mach = HDR_MAC(p);
381 ch->ptype() = PT_PROBE_SINK;
382 ch->size() = sizeof(hdr_PROBE_SINK);
383 mach->ftype() = MF_CONTROL;
384 mach->macDA() = AUV_mac_addr;
385 mach->macSA() = addr;
386 probehdr->id_sink() = sink_id;
387 probehdr->PROBE_uid() = PROBE_uid++;
388 if(missing_id_list.empty()){
389 probehdr->id_ack() = last_rx+1;
390 } else {
391 probehdr->id_ack() = missing_id_list.front();
392 }
393 curr_probe_pkt = p->copy();
394 Packet::free(p);
395 } else if (pkt_type == UWPOLLING_ACK_PKT) {
396 Packet *p = Packet::alloc();
397 hdr_ACK_SINK *ackh = HDR_ACK_SINK(p);
398 hdr_cmn *ch = hdr_cmn::access(p);
399 hdr_mac *mach = HDR_MAC(p);
400 ch->ptype() = PT_ACK_SINK;
401
402 mach->ftype() = MF_CONTROL;
403 mach->macDA() = AUV_mac_addr;
404 mach->macSA() = addr;
405 std::vector<uint16_t> & ack = ackh->id_ack();
406 std::list<uint16_t>::iterator it = missing_id_list.begin();
407 if (it == missing_id_list.end()) {
408 if (ack.size() <= max_n_ack) {
409 ack.push_back(last_rx+1);
410 } else {
411 std::cout << "Uwpolling_SINK(" << addr << ")::max number of "
412 << "ack reached" << std::endl;
413 }
414 } else {
415 for (; it!= missing_id_list.end(); it++){
416 if (ack.size() <= max_n_ack) {
417 ack.push_back(*it);
418 } else {
419 std::cout << "Uwpolling_SINK(" << addr << ")::max number "
420 << "of ack reached" << std::endl;
421 break;
422 }
423 }
424 }
425 ch->size() = ack.size() * sizeof(uint16_t);
426 if (debug_)
427 std::cout << NOW << "Uwpolling_SINK(" << addr
428 << ")::ack list size=" << ack.size() << std::endl;
429 curr_ack_pkt = p->copy();
430 Packet::free(p);
431 }
432}
433
434void
436{
438 incrCtrlPktsTx();
440}
441
442
443void
445{
446 MMac::Mac2PhyStartTx(p); // Send down the packet to phy layer
447}
448
449void
451{
452 hdr_cmn* ch = HDR_CMN(p);
453 if (ch->ptype() == PT_PROBE_SINK) {
456 } else if (ch->ptype() == PT_ACK_SINK) {
458 stateIdle();
459 }
460}
461
462void
464{
466 RxDataEnabled = true;
467 //Compute T_data in some way
468 if (debug_)
469 std::cout << NOW << "Uwpolling_SINK(" << addr
470 << ")STATE_WAIT_DATA::Data_Timer = " << T_data << std::endl;
472 n_curr_rx_pkts = 0;
473}
474
475void
477{
478 if (RxDataEnabled) {
480 send_ACK = true; //At least one packet is received, so an ACK has to be sent
481 triggerEnabled = false;
482 hdr_mac *mach = HDR_MAC(curr_data_pkt);
485 hdr_cmn* ch = HDR_CMN(curr_data_pkt);
486 hdr_MPhy *ph = HDR_MPHY(curr_data_pkt);
487 uint16_t auv_uid = auvh->pkt_uid();
488
489 if (first_rx_pkt) {
490 first_rx_pkt = false;
493 double expected_pkts = 0;
494 if (!ack_enabled) {
495 expected_pkts = expected_last_id - auv_uid + 1;
496 } else {
497 expected_pkts = max(expected_last_id - prev_expect_last_id, 0) +
498 missing_id_list.size();
499 }
500
501 double duration = 0;
502 if (ph->duration > 0) {
503 duration = sea_trial ? (ph->duration + T_guard) : ph->duration;
504 } else {
505 duration = (max_payload*8.0)/modem_data_bit_rate;
506 duration = sea_trial ? (duration + T_guard) : duration;
507 }
508 double new_dataTO = (expected_pkts-1)*duration;//-1 because we don't have to consider the packet just received
509 new_dataTO = new_dataTO + 0.5*new_dataTO;
510 if(debug_)
511 std::cout << NOW << "Uwpolling_SINK(" << addr
512 << ")RX_DATA_TIMER::RESCHEDULED::Data_Timer = "
513 << new_dataTO << " n_packets " << expected_pkts << " pckt duration " << ph->duration <<std::endl;
514 rx_data_timer.schedule(new_dataTO);
515 }
516
517 if (sea_trial && print_stats) {
518 out_file_stats << left << "[" << getEpoch() << "]::" << NOW
519 << "::Uwpolling_SINK(" << addr
520 << ")::STATE_RX_DATA::RX_DATA_ID_" << cbrh->sn_
521 << "_FROM_NODE_" << mach->macSA() << endl;
522 }
523 if (debug_) {
524 std::cout << NOW << "Uwpolling_SINK(" << addr
525 << ")::STATE_RX_DATA::RX_DATA_ID_" << cbrh->sn_
526 << "::POLLING_UID_" << auv_uid
527 << "_FROM_NODE_" << mach->macSA() << endl;
528 }
529
530 if (auv_uid == last_rx+1) { //no missing packet
531 last_rx = auv_uid;
532 } else if(auv_uid > last_rx+1){ //lost some packets in between
533 uint16_t n_miss = (auv_uid-1) - last_rx;
534 addMissPkt2List(n_miss);
535 last_rx = auv_uid;
536 }
537
538 if(auv_uid <= prev_expect_last_id) { //retransmission
539
540 std::list<uint16_t>::iterator it =
541 std::find(missing_id_list.begin(),missing_id_list.end(),
542 auv_uid);
543 if (it != missing_id_list.end()) { //the packet was previously lost
544 //erase packet from list
545 missing_id_list.erase(it);
546 } else { // duplicate packet
547 if(debug_)
548 std::cout << NOW << "Uwpolling_SINK(" << addr
549 << ")received duplicate packet with id2 "
550 << auv_uid << std::endl;
551
552 incrDuplicatedPkt(); //the packet will be sendUp and discarded
553 //by the application
554 }
555 }
556
557 incrDataPktsRx();
559 ch->size() -= sizeof(hdr_AUV_MULE);
560 sendUp(curr_data_pkt);
561
562 if (expected_last_id == auv_uid) {
563 rx_data_timer.force_cancel();
564 n_curr_rx_pkts = 0;
565 RxDataEnabled = false;
566 first_rx_pkt = true;
568 if (!ack_enabled){
569 stateIdle();
570 } else {
571 stateTxAck();
572 }
573 }
574
575 }
576}
577
578void
580{
581 RxDataEnabled = false;
582 n_curr_rx_pkts = 0;
583 first_rx_pkt = true;
585 if (send_ACK) {
587 uint16_t n_miss = expected_last_id - last_rx;
588 addMissPkt2List(n_miss);
589 }
590 if (!ack_enabled){ //modified
591 stateIdle();
592 } else {
593 stateTxAck();
594 }
595 } else { //no packet has been received
596 stateIdle();
597 }
598
599}
600
601void
603{
604 for (uint16_t i = 1; i <= n_pkts; i++) {
605
606 std::list<uint16_t>::iterator it = std::find(missing_id_list.begin(),
607 missing_id_list.end(), last_rx+i);
608
609 if (it == missing_id_list.end()) {
610 missing_id_list.push_back(last_rx+i);
611 }
612 }
613}
614
615
616void
618{
619 if (send_ACK) {
620 if(debug_)
621 std::cout << NOW << "Uwpolling_SINK(" << addr
622 << ")stateTxAck()" << std::endl;
625 txAck();
626 }
627}
628
629void
631{
632 send_ACK = false;
633 incrAckSent();
634 incrCtrlPktsTx();
636}
637
638void
640{
641 initialized = true;
642
643 if (sea_trial && print_stats) {
644 std::stringstream stat_file;
645 stat_file << "./Uwpolling_SINK_" << addr << "_" << n_run << ".out";
646 std::cout << stat_file.str().c_str() << endl;
647 out_file_stats.open(stat_file.str().c_str(), std::ios_base::app);
648 out_file_stats << left << "[" << getEpoch() << "]::" << NOW
649 << "::Uwpolling_SINK(" << addr << ")::NS_START" << endl;
650 }
651
653 status_info[UWPOLLING_SINK_STATUS_RX_TRIGGER] ="Receiving Trigger from AUV";
654 status_info[UWPOLLING_SINK_STATUS_TX_PROBE] = "Transmitting Probe to AUV";
656 "Waiting for the reception of DATA packet";
657 status_info[UWPOLLING_SINK_STATUS_RX_DATA] = "Receiving Data from AUV";
658 status_info[UWPOLLING_SINK_STATUS_TX_ACK] = "Transmitting ACK from AUV";
659
660 pkt_type_info[UWPOLLING_DATA_PKT] = "Data Packet from Application Layer";
661 pkt_type_info[UWPOLLING_POLL_PKT] = "Poll packet";
662 pkt_type_info[UWPOLLING_TRIGGER_PKT] = "Trigger packet";
663 pkt_type_info[UWPOLLING_PROBE_PKT] = "Probe packet";
664 pkt_type_info[UWPOLLING_ACK_PKT] = "Ack packet";
665
667 "Received a Data Packet";
669 "Receiving a trigger from the AUV";
671 "Received a Corrupted Packet";
673 "Transmitting PROBE to the AUV";
675 "Transmitting ACK to the AUV";
677 "BackOff expired";
679 "Data timer expired Time-Out";
681 "Reason not set";
683 "Maximum Number of Data packets Received";
685 "Receiving a Packet of Wrong Type";
687 "Packet not for this receiver";
689 "Receiving a Packet in Wrong State (--> NOT enabled to receive "
690 "packets)";
691}
692
693void
695{
696 std::string response;
697 std::cout << "Press Enter to continue";
698 std::getline(std::cin, response);
699}
Class that represents the binding with the tcl configuration script.
UwpollingModule_SINK_Class()
Constructor of the class.
TclObject * create(int, const char *const *)
Creates the TCL object needed for the tcl language interpretation.
virtual void expire(Event *e)
Method call when the timer expire.
virtual void expire(Event *e)
Method call when the timer expire.
virtual void schedule(double val)
Schedules a timer.
Uwpolling_SINK *UWPOLLING_TIMER_STATUS timer_status
< Pointer to an object of type Uwpolling_SINK
Class used to represents the UWPOLLING MAC layer of a node.
int max_payload
Dimension of the DATA payload.
double BOffTime
Backoff time chosen.
static map< Uwpolling_SINK::UWPOLLING_PKT_TYPE, string > pkt_type_info
Textual info of the type of the packet.
Packet * curr_data_pkt
Pointer to the current DATA packet.
virtual void refreshReason(UWPOLLING_SINK_REASON reason)
Refresh the reason for the changing of the state.
uint n_curr_rx_pkts
Number of current received packets after the probe transmission.
virtual void stateWaitData()
State in which the protocol set up the timer to wait the reception of the DATA packet.
virtual void BackOffTimerExpired()
Method called by the Expire event of the timer.
virtual void stateRxData()
State in which the DATA packet is received.
unsigned long int getEpoch()
Calculate the epoch of the event.
virtual void refreshState(UWPOLLING_SINK_STATUS state)
Refresh the state of the protocol.
void incrTriggerReceived()
Increments the number of TRIGGER packets received.
void incrTriggerDropped()
Increments the number of TRIGGER packets dropped because of erroneous CRC.
virtual int crLayCommand(ClMessage *m)
Cross-Layer messages interpreter.
Packet * curr_trigger_pkt
Pointer to the current TRIGGER packet.
uint16_t expected_last_id
uint sink_id
Unique Node ID.
virtual void incrAckSent()
Increment the number of sent PROBE packets.
static bool initialized
true if the protocol is initialized, false otherwise
virtual double getBackOffTime()
The backoff timer is calculated choosing randomly using a Uniform random variable and multiplying it ...
bool first_rx_pkt
Number ot duplicated packets received.
int print_stats
Print protocol's statistics of the protocol.
int AUV_mac_addr
MAC address of the AUV from which it receives data.
int ack_enabled
True if ack is enabled, false if disabled, default true.
double T_guard
Guard time added to the calculation of the data TO.
virtual void initInfo()
Initializes the protocol at the beginning of the simulation.
double T_data_gurad
Guard time for RxDataTimer.
virtual void stateIdle()
IDLE state.
virtual void txAck()
The ACK Packet is sent down to the PHY layer.
virtual void incrProbeSent()
Increment the number of sent PROBE packets.
Packet * curr_ack_pkt
Pointer to the current ACK packet.
virtual void Phy2MacEndTx(const Packet *p)
Method called when the PHY layer finish to transmit the packet.
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
Rx_Data_Timer rx_data_timer
Receiving DATA Timer.
virtual void stateTxAck()
State in which the ACK is sent.
static map< Uwpolling_SINK::UWPOLLING_SINK_STATUS, string > status_info
Textual info of the state.
virtual void stateRxTrigger()
State of the protocol in which a TRIGGER packet is received.
std::list< uint16_t > missing_id_list
List with missing packet ID.
uint max_n_ack
Max number of ACK that can be sent in a single round.
double T_in
True if rx trigger is enabled.
@ UWPOLLING_SINK_REASON_BACKOFF_TIMER_EXPIRED
@ UWPOLLING_SINK_REASON_WRONG_STATE
@ UWPOLLING_SINK_REASON_WRONG_RECEIVER
@ UWPOLLING_SINK_REASON_RX_DATA_TIMER_EXPIRED
@ UWPOLLING_SINK_REASON_MAX_DATA_RECEIVED
int getProbeSent()
Returns the number of PROBE packets sent during the simulation.
Packet * curr_probe_pkt
Pointer to the current PROBE packet.
int getTriggerReceived()
Return the number of TRIGGER packets received by the NODE.
std::ofstream out_file_stats
virtual void waitForUser()
Used for debug purposes.
bool RxDataEnabled
true if the node is enabled to receive the DATA, false otherwise
uint PROBE_uid
True if the packet received is the first packet in the round.
int useAdaptiveTdata
True if an adaptive T_poll is used.
virtual void addMissPkt2List(uint16_t n_pkts)
Add packet uids in the missing packet list.
uint16_t prev_expect_last_id
Expected Unique ID of the last packet in the round.
virtual void RxDataTimerExpired()
Methods called by the Expire event of the timer.
double backoff_tuner
Multiplying value to the backoff value.
uint16_t last_rx
ID of the last received packet.
static map< Uwpolling_SINK::UWPOLLING_SINK_REASON, string > reason_info
Textual info of the reason.
virtual void TxProbe()
The PROBE Packet is sended down to the PHY layer.
int modem_data_bit_rate
Bit rate of the modem used.
virtual void stateTxProbe()
State of the protocol in which a PROBE packet is sent.
int getAckSent()
Returns the number of ACK packets sent during the simulation.
double T_data
Duration of RxDataTimer.
virtual ~Uwpolling_SINK()
Destructor of the Uwpolling_SINK class.
BackOffTimer backoff_timer
Backoff timer.
Uwpolling_SINK()
Constructor of the Uwpolling_SINK class.
int sea_trial
Sea Trial flag: To activate if the protocol is going to be tested at the sea.
virtual void initPkt(UWPOLLING_PKT_TYPE pkt_type)
Inits the packet with the MAC address of the receiver and the sender, the size of the packet and the ...
double T_fin
Upper bound of the range in which choose randomly the backoff time (sent by the AUV in the TRIGGER me...
virtual void Phy2MacEndRx(Packet *p)
Method called when the Phy Layer finish to receive a Packet.
virtual void Mac2PhyStartTx(Packet *p)
Pass the packet to the PHY layer.
int getTriggerDropped()
Return the number of TRIGGER dropped by the node because of erroneous CRC.
bool send_ACK
True if an ACK has to be sent, false otherwise.
bool Triggered
true if the node has correctly received a TRIGGER, false otherwise
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.
uint16_t & POLL_time()
Header of the PROBE message.
uint16_t & id_ack()
Reference to id_ack_ variable.
uint & PROBE_uid()
Reference to PROBE_uid_ variable.
uint & id_sink()
Reference to id_sink variable.
Header of the TRIGGER message.
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.
Provides the UWCBR packets header description and the definition of the class UWCBR.
#define HDR_UWCBR(p)
UwpollingModule_SINK_Class class_module_uwpolling_sink
Class that represents a node of UWPOLLING.
#define UWPOLLING_SINK_DROP_REASON_ERROR
Packet corrupted.
#define UWPOLLING_SINK_DROP_REASON_WRONG_RECEIVER
The packet is for another node.
#define UWPOLLING_SINK_DROP_REASON_UNKNOWN_TYPE
Packet type unknown.
#define HDR_PROBE_SINK(p)
alias defined to access the ACK SINK HEADER
#define HDR_ACK_SINK(p)
alias defined to access the ACK SINK HEADER
#define HDR_POLL(p)
alias defined to access the POLL HEADER
#define HDR_AUV_MULE(p)
alias defined to access the AUV MULE HEADER
#define HDR_TRIGGER(p)
alias defined to access the TRIGGER HEADER \
static const double MIN_T_DATA
Minimum duration of the DATA timer.