DESERT 3.5.1
Loading...
Searching...
No Matches
uwpolling_SINK.h
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
40#ifndef Uwpolling_HDR_SINK_H
41#define Uwpolling_HDR_SINK_H
42
43#include "uwpolling_cmn_hdr.h"
44#include "mmac.h"
45
46#include <iostream>
47#include <string>
48#include <map>
49#include <set>
50#include <queue>
51#include <fstream>
52#include <list>
53#include <chrono>
54
55#define UWPOLLING_SINK_DROP_REASON_BUFFER_FULL \
56 "DBF"
57#define UWPOLLING_SINK_DROP_REASON_ERROR "DERR"
58#define UWPOLLING_SINK_DROP_REASON_UNKNOWN_TYPE \
59 "DUT"
60#define UWPOLLING_SINK_DROP_REASON_WRONG_RECEIVER \
61 "DWR"
62#define UWPOLLING_SINK_DROP_REASON_WRONG_STATE \
63 "DWS"
64#define UWPOLLING_SINK_DROP_REASON_PACKET_NOT_FOR_ME \
65 "DPNFM"
66#define UWPOLLING_SINK_DROP_REASON_IMINLIST_NOT_POLLED \
67 "DPLNP"
69#define UWPOLLING_SINK_DROP_REASON_NOT_POLLED \
70 "DNP"
75class Uwpolling_SINK : public MMac
76{
77public:
85 virtual ~Uwpolling_SINK();
96 virtual int command(int argc, const char *const *argv);
104 virtual int crLayCommand(ClMessage *m);
105
106protected:
116
125
141
149
153 class Uwpolling_SINK_Timer : public TimerHandler
154 {
155 public:
161 : TimerHandler()
162 , start_time(0.0)
163 , left_duration(0.0)
164 , counter(0)
165 , module(m)
167 {
168 assert(m != NULL);
169 }
170
175 {
176 }
177
181 virtual void
183 {
185 left_duration -= (NOW - start_time);
186 if (left_duration <= 0.0) {
187 left_duration = module->mac2phy_delay_;
188 }
189 force_cancel();
191 }
192
197 virtual void
199 {
201 start_time = NOW;
202 assert(left_duration > 0);
203 sched(left_duration);
205 }
206
210 virtual void
212 {
214 force_cancel();
215 }
216
221 virtual void
222 schedule(double val)
223 {
224 start_time = NOW;
225 left_duration = val;
227 resched(val);
228 }
229
234 bool
236 {
237 return (timer_status == UWPOLLING_IDLE);
238 }
239
244 bool
246 {
248 }
249
254 bool
256 {
258 }
259
264 bool
266 {
267 return (timer_status == UWPOLLING_FROZEN);
268 }
269
274 bool
276 {
277 return (timer_status == UWPOLLING_FROZEN ||
279 }
280
284 void
286 {
287 counter = 0;
288 }
289
293 void
295 {
296 ++counter;
297 }
298
303 int
305 {
306 return counter;
307 }
308
313 double
315 {
316 return left_duration;
317 }
318
319 protected:
320 double start_time;
324 *module;
326 };
327
336 {
337 public:
346
351 {
352 }
353
354 protected:
359 virtual void expire(Event *e);
360 };
361
367 {
368 public:
377
382 {
383 }
384
385 protected:
390 virtual void expire(Event *e);
391 };
392
398 virtual void Mac2PhyStartTx(Packet *p);
399
405 virtual void Phy2MacEndTx(const Packet *p);
406
412 virtual void
413 Phy2MacStartRx(const Packet *p)
414 {
415 }
416
422 virtual void Phy2MacEndRx(Packet *p);
428 virtual void initPkt(UWPOLLING_PKT_TYPE pkt_type);
436 virtual void initInfo();
437
442 virtual void
444 {
445 last_reason = reason;
446 }
447
452 virtual void
454 {
456 curr_state = state;
457 }
458
462 virtual void
464 {
465 n_probe_sent++;
466 }
467
471 virtual void
473 {
474 n_ack_sent++;
475 }
476
480 inline void
485
489 inline void
494
499 inline int
501 {
502 return n_probe_sent;
503 }
504
509 inline int
511 {
512 return n_ack_sent;
513 }
514
519 inline int
521 {
522 return n_trigger_received;
523 }
524
529 inline int
531 {
532 return n_trigger_dropped;
533 }
534
535 inline uint
537 {
538 return duplicate_pkts;
539 }
540
541 inline void
543 {
545 }
550 virtual void waitForUser();
554 virtual void stateIdle();
555
563 virtual void stateRxTrigger();
564
573 virtual void stateTxProbe();
574
579 virtual void BackOffTimerExpired();
580
585 virtual void RxDataTimerExpired();
586
592 virtual double getBackOffTime();
593
597 virtual void txAck();
598
602 virtual void TxProbe();
603
608 virtual void stateWaitData();
609
613 virtual void stateRxData();
614
619 virtual void addMissPkt2List(uint16_t n_pkts);
620
624 virtual void stateTxAck();
625
630 inline unsigned long int
632 {
633 unsigned long int timestamp =
634 (unsigned long int) (std::chrono::duration_cast<std::chrono::milliseconds>(
635 std::chrono::system_clock::now().time_since_epoch()).count() );
636 return timestamp;
637 }
638
639 /*************************
640 * input values from TCL *
641 *************************/
642 double T_data;
646 uint sink_id;
648 static bool initialized;
658 double T_in;
660 double T_fin;
662 double BOffTime;
672
675 uint16_t expected_id;
676 uint16_t last_rx;
677 bool send_ACK;
679 std::list<uint16_t> missing_id_list;
682 uint16_t prev_expect_last_id; /*Expected last id of the previous round.
683 Needed to find which are the retx packets. */
694 Packet *curr_ack_pkt;
701 static map<Uwpolling_SINK::UWPOLLING_SINK_STATUS, string>
703 static map<Uwpolling_SINK::UWPOLLING_SINK_REASON, string>
705 static map<Uwpolling_SINK::UWPOLLING_PKT_TYPE, string>
712 std::ofstream fout;
713 std::ofstream out_file_stats;
718 int n_run; /*< ID of the experiments (used during sea trial) */
719
724 double T_guard;
727};
728#endif
Class (inherited from Uwpolling_SINK_Timer) used to handle the time of backoff of the node before tra...
virtual ~BackOffTimer()
Destructor of DataTimer class.
BackOffTimer(Uwpolling_SINK *m)
Conscructor of ProbeTimer class.
virtual void expire(Event *e)
Method call when the timer expire.
Class (inherited from Uwpolling_SINK_Timer) used to handle the time in which the NODE wait for the DA...
virtual ~Rx_Data_Timer()
Destructor of ProbeTimer class.
virtual void expire(Event *e)
Method call when the timer expire.
Rx_Data_Timer(Uwpolling_SINK *m)
Conscructor of Rx_Data_Timer class.
Class that describes the timer in the SINK.
virtual ~Uwpolling_SINK_Timer()
Destructor of the Uwpolling_SINK_Timer class.
Uwpolling_SINK_Timer(Uwpolling_SINK *m)
Constructor of the Uwpolling_SINK_Timer class.
bool isFrozen()
Checks if the timer is FROZEN.
double start_time
Start Time of the timer.
bool isActive()
Checks if the timer is ACTIVE.
virtual void unFreeze()
unFreeze is used to resume the timer starting from the point where it was freezed
bool isRunning()
Checks if the timer is RUNNING.
double getDuration()
Returns the counter of the timer.
int getCounter()
Returns the counter of the timer.
void incrCounter()
Increments the counter of the timer.
bool isExpired()
Checks if the timer is EXPIRED.
virtual void freeze()
Freeze the timer.
virtual void schedule(double val)
Schedules a timer.
void resetCounter()
Resets the counter of the timer.
double left_duration
Left duration of the timer.
Uwpolling_SINK *UWPOLLING_TIMER_STATUS timer_status
< Pointer to an object of type Uwpolling_SINK
bool isIdle()
Checks if the timer is IDLE.
virtual void stop()
stops the timer
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.
UWPOLLING_SINK_STATUS prev_state
Previous state of the protocol.
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.
std::ofstream fout
Output stream for the textual file of debug.
virtual void stateIdle()
IDLE state.
virtual void txAck()
The ACK Packet is sent down to the PHY layer.
UWPOLLING_SINK_STATUS
< Variable that rapresents the status of the protocol machine state
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.
UWPOLLING_SINK_REASON last_reason
Last reason to the change of state.
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.
UWPOLLING_SINK_STATUS curr_state
Current state of the protocol.
uint16_t prev_expect_last_id
Expected Unique ID of the last packet in the round.
int n_trigger_received
Number of TRIGGER packets received.
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.
uint16_t expected_id
Expected ID of the next data packet received.
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.
int n_trigger_dropped
Number of TRIGGER packet dropped.
Uwpolling_SINK()
Constructor of the Uwpolling_SINK class.
virtual void Phy2MacStartRx(const Packet *p)
Method called when the Phy Layer start to receive a Packet.
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 ...
int n_probe_sent
Number of PROBE packets sent to the AUV.
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
std::pair< int, int > counter
counter of collisions
Common structures and variables in the protocol.