DESERT 3.5.1
Loading...
Searching...
No Matches
uwpolling_NODE.cpp
Go to the documentation of this file.
1//
2// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova.
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions
7// are met:
8// 1. Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// 2. Redistributions in binary form must reproduce the above copyright
11// notice, this list of conditions and the following disclaimer in the
12// documentation and/or other materials provided with the distribution.
13// 3. Neither the name of the University of Padova (SIGNET lab) nor the
14// names of its contributors may be used to endorse or promote products
15// derived from this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28//
29
39#include "uwpolling_NODE.h"
40#include "uwpolling_cmn_hdr.h"
41#include "mac.h"
42#include "mmac.h"
43
44#include "uwcbr-module.h"
45#include "rng.h"
46
47#include <sstream>
48#include <sys/time.h>
49
53static class UwpollingModule_NODE_Class : public TclClass
54{
55public:
60 : TclClass("Module/UW/POLLING/NODE")
61 {
62 }
63
68 TclObject *
69 create(int, const char *const *)
70 {
71 return (new Uwpolling_NODE());
72 }
74
75void
77{
78 if (module->debug_)
79 std::cout << module->getEpoch() << "::" << NOW << "::Uwpolling_NODE(" << module->addr
80 << ")::BACKOFF_TIMER::EXPIRED" << std::endl;
82 if (module->Triggered) {
83 module->BackOffTimerExpired();
84 }
85}
86
87void
93
94void
96{
97 if (module->debug_)
98 std::cout << module->getEpoch() << "::" << NOW << "::Uwpolling_NODE(" << module->addr
99 << ")::RX_POLL_TIMER::EXPIRED" << std::endl;
100 timer_status = UWPOLLING_EXPIRED;
101 module->RxPollTimerExpired();
102}
103
104void
106{
107 if (module->debug_)
108 std::cout << module->getEpoch() << "::" << NOW << "::Uwpolling_NODE(" << module->addr
109 << ")::DATA_TIMER::EXPIRED" << std::endl;
110 timer_status = UWPOLLING_EXPIRED;
111 module->stateTxData();
112}
113
114void
123
124bool Uwpolling_NODE::initialized = false;
125map<Uwpolling_NODE::UWPOLLING_NODE_STATUS, string> Uwpolling_NODE::status_info;
126map<Uwpolling_NODE::UWPOLLING_NODE_REASON, string> Uwpolling_NODE::reason_info;
127map<Uwpolling_NODE::UWPOLLING_PKT_TYPE, string> Uwpolling_NODE::pkt_type_info;
128
130 : T_poll(0)
131 , T_poll_guard(0)
132 , backoff_tuner(0)
133 , max_payload(0)
135 , node_id(0)
136 , sea_trial(0)
137 , print_stats(0)
138 , n_run(0)
140 , polled(false)
141 , RxPollEnabled(false)
142 , Triggered(false)
143 , LastPacket(false)
144 , MaxTimeStamp(0)
145 , T_in(0)
146 , T_fin(0)
147 , BOffTime(0)
148 , AUV_mac_addr(0)
149 , N_data_pkt_2_TX(0)
150 , packet_index(0)
151 , n_probe_sent(0)
152 , n_times_polled(0)
154 , N_polled_node(0)
155 , PROBE_uid(0)
156 , curr_data_pkt(0)
157 , curr_probe_pkt(0)
158 , curr_poll_pkt(0)
160 , backoff_timer(this)
161 , rx_poll_timer(this)
162 , tx_data_timer(this)
163 , fout(0)
164 , out_file_stats(0)
166 , n_poll_dropped(0)
168
169{
170
171 bind("T_poll_guard_", (double *) &T_poll_guard);
172 bind("backoff_tuner_", (double *) &backoff_tuner);
173 bind("max_payload_", (int *) &max_payload);
174 bind("buffer_data_pkts_", (int *) &buffer_data_pkts);
175 bind("Max_DATA_Pkts_TX_", (int *) &max_data_pkt_tx);
176 bind("node_id_", (uint *) &node_id);
177 bind("print_stats_", (int *) &print_stats);
178 bind("sea_trial_", (int *) &sea_trial);
179 bind("intra_data_guard_time_", (double *) &Intra_data_Guard_Time);
180 bind("n_run_", (int *) &n_run);
181 bind("useAdaptiveTpoll_", (int *) &useAdaptiveTpoll);
182
183
184 if (T_poll_guard <= 0)
188 if (buffer_data_pkts <= 0)
192 }
193 if (max_data_pkt_tx == 0) {
194 max_data_pkt_tx = 1;
195 }
196}
197
201
202int
203Uwpolling_NODE::command(int argc, const char *const *argv)
204{
205 Tcl &tcl = Tcl::instance();
206 if (argc == 2) {
207 if (strcasecmp(argv[1], "initialize") == 0) {
208 if (!initialized)
209 initInfo();
210 return TCL_OK;
211 } else if (strcasecmp(argv[1], "getDataQueueSize") == 0) {
212 tcl.resultf("%d", Q_data.size());
213 return TCL_OK;
214 } else if (strcasecmp(argv[1], "getDataQueueLog") == 0) {
216 return TCL_OK;
217 } else if (strcasecmp(argv[1], "getProbeSent") == 0) {
218 tcl.resultf("%d", getProbeSent());
219 return TCL_OK;
220 } else if (strcasecmp(argv[1], "getTimesPolled") == 0) {
221 tcl.resultf("%d", getTimesPolled());
222 return TCL_OK;
223 } else if (strcasecmp(argv[1], "getTriggerReceived") == 0) {
224 tcl.resultf("%d", getTriggerReceived());
225 return TCL_OK;
226 } else if (strcasecmp(argv[1], "getTriggerDropped") == 0) {
227 tcl.resultf("%d", getTriggerDropped());
228 return TCL_OK;
229 } else if (strcasecmp(argv[1], "getPollDropped") == 0) {
230 tcl.resultf("%d", getPollDropped());
231 return TCL_OK;
232 }
233
234 } else if (argc == 3) {
235 if (strcasecmp(argv[1], "setMacAddr") == 0) {
236 addr = atoi(argv[2]);
237 return TCL_OK;
238 }
239 }
240 return MMac::command(argc, argv);
241}
242
243int
245{
246 switch (m->type()) {
247 default:
248 return MMac::crLayCommand(m);
249 }
250}
251
252void
254{
255 initialized = true;
256
257 if (sea_trial && print_stats) {
258 std::stringstream stat_file;
259 stat_file << "./Uwpolling_NODE_" << addr << "_" << n_run << ".out";
260 std::cout << stat_file.str().c_str() << endl;
261 out_file_stats.open(stat_file.str().c_str(), std::ios_base::app);
262 out_file_stats << left << getEpoch() << "::" << NOW
263 << "::Uwpolling_NODE(" << addr << ")::NS_START" << endl;
264 }
265
267 status_info[UWPOLLING_NODE_STATUS_RX_POLL] = "Receiving POLL from AUV";
269 "Receiving Trigger from AUV";
270 status_info[UWPOLLING_NODE_STATUS_TX_DATA] = "Transmitting Data to AUV";
271 status_info[UWPOLLING_NODE_STATUS_TX_PROBE] = "Transmitting Probe to AUV";
273 "Waiting for the reception of POLL packet";
274
275 pkt_type_info[UWPOLLING_DATA_PKT] = "Data Packet from Application Layer";
276 pkt_type_info[UWPOLLING_POLL_PKT] = "Poll packet";
277 pkt_type_info[UWPOLLING_TRIGGER_PKT] = "Trigger packet";
278 pkt_type_info[UWPOLLING_PROBE_PKT] = "Probe packet";
279
280 reason_info[UWPOLLING_NODE_REASON_NOT_SET] = "Reason not set";
282 "BackOff expired";
284 "Receving POLL Time-Out";
285 reason_info[UWPOLLING_NODE_REASON_TX_DATA] = "Data transmission";
287 "Receiving a poll from the AUV";
289 "Receiving a trigger from the AUV";
291 "Transmitting probe to the AUV";
294 "Received a Corrupted Packet";
296 "Packet not for this receiver";
298 "Receiving a Packet in Wrong State (--> NOT enabled to receive "
299 "packets)";
301 "Receiving a Packet of Wrong Type";
303 "This receiver is in the polling list but is not polled";
305 "This receiver is not in the polling list";
306}
307
308void
310{
311 if (Triggered) {
315 if (probehdr->n_pkts() > 0) {
316 PROBE_uid++;
317 probehdr->PROBE_uid_ = PROBE_uid;
318 if (sea_trial && print_stats)
319 out_file_stats << left << getEpoch() << "::" << NOW
320 << "::Uwpolling_NODE(" << addr
321 << ")::TX_PROBE_ID_" << PROBE_uid
322 << "_N_PKTS=" << (uint) probehdr->n_pkts_
323 << endl;
324 if (debug_)
325 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_NODE(" << addr
326 << ")::STATE_TX_PROBE_ID_" << PROBE_uid
327 << "_N_PKTS=" << (uint) probehdr->n_pkts_ << endl;
328 TxPRobe();
329 } else {
330 if (debug_)
331 std::cout
332 << getEpoch() << "::" << NOW << "::Uwpolling_NODE(" << addr
333 << ")::STATE_TX_PROBE::NOT_TX_PROBE--->Empty Data Queue"
334 << std::endl;
336 Packet::free(curr_probe_pkt);
337 stateIdle();
338 }
339 }
340}
341
342void
344{
345 incrCtrlPktsTx();
348}
349
350void
352{
354 if (debug_)
355 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_NODE(" << addr
356 << ")::STATE_WAIT_POLL---> Timer_rx_poll = "
357 << rx_poll_timer.getDuration() << std::endl;
358 RxPollEnabled = true;
359 if (T_poll < 0) {
360 cerr << "Scheduling POLL timer ----> negative value " << T_poll << endl;
361 T_poll = 60;
362 }
364}
365
366void
368{
369 if (RxPollEnabled) {
372 if (debug_)
373 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_NODE(" << addr
374 << ")::STATE_RX_POLL::Node_POLLED = " << pollh->id_
375 << std::endl;
376 int polled_node = pollh->id_;
377 if (useAdaptiveTpoll) {
379 //std::cout << "Poll timer rescheduled " << pollh->POLL_time() << std::endl;
380 }
381 if (node_id == (uint) polled_node) {
382 polled = true;
383 if (sea_trial && print_stats)
384 out_file_stats << left << getEpoch() << "::" << NOW
385 << "::Uwpolling_NODE(" << addr
386 << ")::POLLED_POLL_ID_" << pollh->POLL_uid_
387 << endl;
389 Packet::free(curr_poll_pkt);
391 stateTxData();
392
393 } else {
396 }
397 } else {
398 if (debug_)
399 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_NODE(" << addr
400 << ")::STATE_RX_POLL::NODE_NOT_POLLED" << endl;
403 }
404}
405
406void
408{
409 if ((int) Q_data.size() < buffer_data_pkts) {
410 hdr_uwcbr *cbrh = HDR_UWCBR(p);
411 if (debug_)
412 std::cout << getEpoch() << "::" << NOW << "::UWPOLLING_NODE(" << addr
413 << ")::RECV_FROM_U_LAYERS_ID_" << cbrh->sn_ << endl;
414 if (sea_trial && print_stats)
415 out_file_stats << left << getEpoch() << "::" << NOW
416 << "::Uwpolling_NODE(" << addr
417 << ")::RECV_FROM_U_LAYERS_ID_" << cbrh->sn_ << endl;
418 //add Header
419
420 Q_data.push(p);
421 } else {
422 if (sea_trial && print_stats)
423 out_file_stats << left << getEpoch() << "::" << NOW
424 << "Uwpolling_NODE(" << addr << ")::DROP_FULL_QUEUE"
425 << endl;
426 if (debug_)
427 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_NODE(" << addr
428 << ")::DROP_FULL_QUEUE" << std::endl;
429 incrDiscardedPktsTx();
431 }
432}
433
434void
436{
437 if (polled) {
439 packet_index = 1;
440 LastPacket = false;
441 } else {
442 packet_index++;
443 }
445 curr_data_pkt = Q_data.front();
446 Q_data.pop();
448 if (debug_)
449 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_NODE(" << addr
450 << ")::STATE_TX_DATA_ " << packet_index
451 << "::OF::" << N_data_pkt_2_TX
452 << "_PACKET_INDEX_" << cbrh->sn_ << std::endl;
453 if (sea_trial && print_stats)
454 out_file_stats << left << getEpoch() << "::" << NOW
455 << "::Uwpolling_NODE(" << addr << ")::TX_DATA_"
456 << packet_index << "_OF_" << N_data_pkt_2_TX
457 << "_PACKET_INDEX_" << cbrh->sn_ << endl;
459 LastPacket = true;
460 hdr_mac *mach = HDR_MAC(curr_data_pkt);
461 mach->macSA() = addr;
462 mach->macDA() = AUV_mac_addr;
463 TxData();
464 }
465}
466
467void
469{
470 MMac::Mac2PhyStartTx(p);
471}
472
473void
475{
476 incrDataPktsTx();
478}
479
480void
482{
483 switch (curr_state) {
487 break;
488 }
491 if (LastPacket) {
492 stateIdle();
493 } else {
494 Packet *dummy = Packet::alloc();
495 hdr_cmn *ch = HDR_CMN(dummy);
496 ch->size() = max_payload;
497 hdr_mac *mach = HDR_MAC(dummy);
498 mach->macDA() = AUV_mac_addr;
499 // double dataPacket_duration = Mac2PhyTxDuration(dummy);
500 // double dataPacket_duration =
501 // (max_payload*8)/modem_data_bit_rate;
502 double dataPacket_duration = Intra_data_Guard_Time;
503 // cout << "Data Packet duration" << dataPacket_duration <<
504 // endl;
505 Packet::free(dummy);
506 /*
507 * Instead of transmit the new packet just after the
508 * transmission of the previous one
509 * i wait for a little time (the duration of the reception of
510 * the old one).
511 * This way, the AUV doesn't drop the new one because it is
512 * synchronized on the old one
513 */
514 if (dataPacket_duration < 0) {
515 cerr << "Scheduling Tx_Data timer ----> negative value "
516 << dataPacket_duration << endl;
517 dataPacket_duration = 8;
518 }
519 tx_data_timer.schedule(dataPacket_duration);
520 }
521 break;
522 }
523 default: {
524 if (debug_)
525 std::cerr << getEpoch() << "::" << NOW << "::UWPOLLING_NODE(" << addr
526 << ")::PHY2MACENDTX::logical_error,state = "
528 << ", prev_state = " << status_info[prev_state]
529 << std::endl;
530 }
531 }
532}
533
534void
536{
537 if (pkt_type == UWPOLLING_PROBE_PKT) {
538 Packet *p = Packet::alloc();
539 hdr_PROBE *probehdr = HDR_PROBE(p);
540 hdr_cmn *ch = hdr_cmn::access(p);
541 hdr_mac *mach = HDR_MAC(p);
542 if (Q_data.size() > 0) {
543 hdr_cmn *chd = hdr_cmn::access(Q_data.back());
544 MaxTimeStamp = chd->timestamp();
545 if (debug_)
546 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_NODE(" << addr
547 << ")::INIT_PROBE::"
548 "Backoff_time="
549 << BOffTime << "::MaxTimeStamp=" << MaxTimeStamp
550 << "::Number of pkts to TX=" << Q_data.size()
551 << std::endl;
552 ch->ptype() = PT_PROBE;
553 // ch->size() += sizeof (hdr_PROBE);
554 ch->size() = sizeof(hdr_PROBE);
555 // probehdr->backoff_time() = BOffTime;
556 // probehdr->ts() = MaxTimeStamp;
557 // probehdr->backoff_time() = (uint16_t)(BOffTime * 100);
558 probehdr->ts() = (uint16_t)(MaxTimeStamp * 100);
559 probehdr->id_node() = node_id;
560 if ((int) Q_data.size() <= max_data_pkt_tx) {
561 probehdr->n_pkts() = (int) Q_data.size();
562 N_data_pkt_2_TX = (int) Q_data.size();
563 } else {
564 probehdr->n_pkts() = (int) max_data_pkt_tx;
566 }
567 mach->set(MF_CONTROL, addr, AUV_mac_addr);
568 mach->macDA() = AUV_mac_addr;
569 mach->macSA() = addr;
570 } else {
571 probehdr->n_pkts() = 0;
572 }
573 curr_probe_pkt = p->copy();
574 Packet::free(p);
575 }
576}
577
578void
580{
581 if (debug_)
582 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_NODE(" << addr << ")::IDLE_STATE"
583 << std::endl;
585 polled = false;
586 Triggered = false;
587 RxPollEnabled = false;
588 backoff_timer.force_cancel();
589 rx_poll_timer.force_cancel();
590}
591
592void
594{
596 Triggered = true;
597 if (RxPollEnabled) { //probe was sent, but no poll has been received by AUV
598 RxPollEnabled = false;
599 rx_poll_timer.force_cancel();
600 }
603 hdr_mac *mach = HDR_MAC(curr_trigger_pkt);
604 if (sea_trial && print_stats)
605 out_file_stats << left << getEpoch() << "::" << NOW
606 << "::Uwpolling_NODE(" << addr << ")::RX_TRIGGER_ID_"
607 << triggerhdr->TRIGGER_uid_ << endl;
608 if (debug_) {
609 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_NODE(" << addr
610 << ")::STATE_RX_TRIGGER --> HEADER :: T_fin = "
611 << triggerhdr->t_fin() << " T_in = " << triggerhdr->t_in()
612 << std::endl;
613 }
614 AUV_mac_addr = mach->macSA();
615 T_fin = (double) triggerhdr->t_fin() / 100;
616 T_in = (double) triggerhdr->t_in() / 100;
619 if (BOffTime < 0) {
620 cerr << "Scheduling Backoff timer ---> negative value " << BOffTime
621 << endl;
622 BOffTime = 5;
623 }
625 Packet::free(curr_trigger_pkt);
626}
627
628double
630{
631 double random = ((double)(RNG::defaultrng()->uniform(INT_MAX) % (int)((T_fin-T_in)*100)))/100 + T_in;
632 if (debug_)
633 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_NODE(" << addr
634 << ")::BACKOFF_TIMER_VALUE = " << backoff_tuner * random
635 << std::endl;
636 return (backoff_tuner * random);
637}
638
639void
641{
642 hdr_cmn *ch = HDR_CMN(p);
643 packet_t rx_pkt_type = ch->ptype();
644 hdr_mac *mach = HDR_MAC(p);
645 int dest_mac = mach->macDA();
646 if (ch->error()) {
647
648 if (ch->ptype() == PT_TRIGGER) {
649 if (debug_)
650 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_NODE(" << addr
651 << ")::PHY2MACENDRX::DROP_TRIGGER" << std::endl;
652 if (sea_trial && print_stats)
653 out_file_stats << left << getEpoch() << "::" << NOW
654 << "::Uwpolling_NODE(" << addr
655 << ")::PKT_TRIGGER_DROP_ERROR" << endl;
657 } else if (ch->ptype() == PT_POLL) {
658 if (debug_)
659 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_NODE(" << addr
660 << ")::PHY2MACENDRX::DROP_POLL" << std::endl;
661 if (sea_trial && print_stats)
662 out_file_stats << left << getEpoch() << "::" << NOW
663 << "::Uwpolling_NODE(" << addr
664 << ")::PKT_POLL_DROP_ERROR" << endl;
666 }
669 } else if ((dest_mac == addr) || (dest_mac == (int) MAC_BROADCAST)) {
670 if (rx_pkt_type == PT_TRIGGER) {
672 curr_trigger_pkt = p->copy();
673 Packet::free(p);
675 } else if (rx_pkt_type == PT_POLL) {
677 hdr_POLL *pollh = HDR_POLL(p);
678 if (debug_)
679 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_NODE(" << addr
680 << ")::PHY2MACENDRX::RX_POLL::POLLED_NODE= "
681 << pollh->id_ << std::endl;
682 rx_poll_timer.force_cancel();
683 curr_poll_pkt = p->copy();
684 Packet::free(p);
685 stateRxPoll();
686 } else {
688 }
689 } else {
690 incrXCtrlPktsRx();
691 if (rx_pkt_type == PT_TRIGGER) {
692 if (debug_)
693 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_NODE(" << addr
694 << ")::PHY2MACENDRX::WARNING!!TRIGGER packet not in "
695 "broadcast!!"
696 << std::endl;
697
698 } else if (rx_pkt_type == PT_POLL) {
699 if (debug_)
700 std::cout << getEpoch() << "::" << NOW << "::Uwpolling_NODE(" << addr
701 << ")::PHY2MACENDRX::WARNING!!POLL packet not in "
702 "broadcast!!"
703 << std::endl;
704 }
706 }
707}
708
709void
711{
712 std::string response;
713 std::cout << "Press Enter to continue";
714 std::getline(std::cin, response);
715}
Class that represents the binding with the tcl configuration script.
UwpollingModule_NODE_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 expire(Event *e)
Method call when the timer expire.
Uwpolling_NODE *UWPOLLING_TIMER_STATUS timer_status
< Pointer to an object of type Uwpolling_AUV
virtual void schedule(double val)
Schedules a timer.
double getDuration()
Returns the counter of the timer.
Class used to represents the UWPOLLING MAC layer of a node.
virtual void stateTxData()
State of the protocol in which a DATA packet is sent.
virtual void incrProbeSent()
Increment the number of sent PROBE packets.
double T_fin
Upper bound of the range in which choose randomly the backoff time (sent by the AUV in the TRIGGER me...
Tx_Data_Timer tx_data_timer
Timer between two consequent DATA packet transmission.
int max_data_pkt_tx
Max number of DATA packets to transmit each cycle.
virtual void Phy2MacEndRx(Packet *p)
Method called when the Phy Layer finish to receive a Packet.
Packet * curr_poll_pkt
Pointer ot the current POLL packet.
int getTimesPolled()
Return the number of times the node are polled by the AUV.
uint N_polled_node
Number of node polled in this POLL message.
bool LastPacket
true if the node has just sent the last packet of the queue and has to exit from the TxData state,...
uint node_id
Unique Node ID.
int n_times_polled
Number of times that the node has been polled by the AUV.
virtual void stateRxTrigger()
State of the protocol in which a TRIGGER packet is received.
virtual void stateRxPoll()
State of the protocol in which a POLL packet is received.
double BOffTime
Backoff time chosen.
bool polled
true if the node is polled, false otherwise
static map< Uwpolling_NODE::UWPOLLING_NODE_REASON, string > reason_info
Textual info of the reason.
double T_poll_guard
Guard time for initial POLL timer.
BackOffTimer backoff_timer
Backoff timer.
UWPOLLING_NODE_STATUS curr_state
Current state of the protocol.
virtual void stateTxProbe()
State of the protocol in which a PROBE packet is sent.
virtual void initInfo()
Initializes the protocol at the beginning of the simulation.
bool Triggered
true if the node has correctly received a TRIGGER, false otherwise
std::ofstream fout
Output stream for the textual file of debug.
int max_payload
Payload of Application Layer in bytes.
int getProbeSent()
Returns the number of PROBE packets sent during the simulation.
void incrTriggerReceived()
Increments the number of TRIGGER packets received.
int buffer_data_pkts
Length of buffer of DATA pkts in number of pkts.
unsigned long int getEpoch()
Calculate the epoch of the event.
virtual void incrTimesPolled()
Increments the number of times that the node has been polled by the AUV.
virtual void refreshReason(UWPOLLING_NODE_REASON reason)
Refresh the reason for the changing of the state.
Packet * curr_probe_pkt
Pointer to the current PROBE packet.
static map< Uwpolling_NODE::UWPOLLING_NODE_STATUS, string > status_info
Textual info of the state.
int getPollDropped()
Return the number of POLL dropped by the node because of erroneous CRC.
Rx_Poll_Timer rx_poll_timer
Receiving POLL Timer.
virtual void Mac2PhyStartTx(Packet *p)
Pass the packet to the PHY layer.
double T_poll
Duration of RxPOLLTimer.
double backoff_tuner
Multiplying value to the backoff value.
virtual void refreshState(UWPOLLING_NODE_STATUS state)
Refresh the state of the protocol.
Uwpolling_NODE()
Constructor of the Uwpolling_NODE class.
virtual void waitForUser()
Used for debug purposes.
uint PROBE_uid
PROBE Unique ID.
int getTriggerReceived()
Return the number of TRIGGER packets received by the NODE.
std::queue< Packet * > Q_data
Queue of DATA in number of packets.
int n_trigger_received
Number of TRIGGER packets received.
virtual void recvFromUpperLayers(Packet *p)
Receives the packet from the upper layer (e.g.
virtual void RxPollTimerExpired()
Methods called by the Expire event of the timer.
int packet_index
Index of the packet just sent to the AUV.
static bool initialized
true if the protocol is initialized, false otherwise
int n_trigger_dropped
Number of TRIGGER packet dropped.
virtual void BackOffTimerExpired()
Method called by the Expire event of the timer.
virtual void TxPRobe()
The PROBE Packet is sended down to the PHY layer.
int AUV_mac_addr
MAC address of the AUV.
Packet * curr_data_pkt
Pointer to the current DATA packet.
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 ...
virtual void TxData()
The DATA Packet is sended down to the PHY layer.
virtual int crLayCommand(ClMessage *m)
Cross-Layer messages interpreter.
double T_in
Lower bound of the range in which choose randomly the backoff time (sent by the AUV in the TRIGGER me...
UWPOLLING_NODE_STATUS prev_state
Previous state of the protocol.
int getTriggerDropped()
Return the number of TRIGGER dropped by the node because of erroneous CRC.
int sea_trial
Sea Trial flag: To activate if the protocol is going to be tested at the sea.
virtual void Phy2MacEndTx(const Packet *p)
Method called when the PHY layer finish to transmit the packet.
double MaxTimeStamp
Timestamp of the most recent data packet generated.
@ UWPOLLING_NODE_REASON_NOT_IN_LIST
@ UWPOLLING_NODE_REASON_LIST_NOT_POLLED
@ UWPOLLING_NODE_REASON_BACKOFF_TIMER_EXPIRED
@ UWPOLLING_NODE_REASON_RX_POLL_TIMER_EXPIRED
@ UWPOLLING_NODE_REASON_WRONG_RECEIVER
@ UWPOLLING_NODE_REASON_WRONG_STATE
@ UWPOLLING_NODE_REASON_EMPTY_DATA_QUEUE
virtual void stateWaitPoll()
State in which the protocol set up the timer to wait the reception of the POLL packet.
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
int n_poll_dropped
Number of POLL packet dropped.
int useAdaptiveTpoll
True if an adaptive T_poll is used.
void incrPollDropped()
Increments the number of POLL packets dropped because of erroneous CRC.
int N_data_pkt_2_TX
Number of DATA packets to transmit to the AUV.
int print_stats
Print protocol's statistics of the protocol.
virtual void stateIdle()
IDLE state.
Packet * curr_trigger_pkt
Pointer to the current TRIGGER packet.
void incrTriggerDropped()
Increments the number of TRIGGER packets dropped because of erroneous CRC.
bool RxPollEnabled
true if the node is enabled to receive the POLL, false otherwise
virtual double getBackOffTime()
The backoff timer is calculated choosing randomly using a Uniform random variable and multiplying it ...
uint n_probe_sent
Number of PROBE packets sent to the AUV.
static map< Uwpolling_NODE::UWPOLLING_PKT_TYPE, string > pkt_type_info
Textual info of the type of the packet.
double Intra_data_Guard_Time
Guard Time between one data packet and the following.
std::ofstream out_file_stats
virtual ~Uwpolling_NODE()
Destructor of the Uwpolling_NODE class.
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 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.
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.
Provides the UWCBR packets header description and the definition of the class UWCBR.
#define HDR_UWCBR(p)
UwpollingModule_NODE_Class class_module_uwpolling_node
Class that represents a node of UWPOLLING.
#define UWPOLLING_NODE_DROP_REASON_WRONG_STATE
The node cannot receive this kind of packet in this state.
#define UWPOLLING_NODE_DROP_REASON_WRONG_RECEIVER
The packet is for another node.
#define UWPOLLING_NODE_DROP_REASON_BUFFER_FULL
Buffer of the node is full.
#define UWPOLLING_NODE_DROP_REASON_ERROR
Packet corrupted.
#define UWPOLLING_NODE_DROP_REASON_UNKNOWN_TYPE
Packet type unknown.
#define UWPOLLING_NODE_DROP_REASON_NOT_POLLED
The node is not in the polling list.
Common structures and variables in the protocol.
static const double MIN_T_POLL
Minimum duration of the POLL timer.
#define HDR_POLL(p)
alias defined to access the POLL HEADER
static const int MAX_BUFFER_SIZE
Maximum size of the queue in number of packets.
#define HDR_TRIGGER(p)
alias defined to access the TRIGGER HEADER \
#define HDR_PROBE(p)
alias defined to access the PROBE HEADER