DESERT 3.5.1
Loading...
Searching...
No Matches
uwpolling_NODE.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_NODE_H
41#define Uwpolling_HDR_NODE_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 <chrono>
53
54#define UWPOLLING_NODE_DROP_REASON_BUFFER_FULL \
55 "DBF"
56#define UWPOLLING_NODE_DROP_REASON_ERROR "DERR"
57#define UWPOLLING_NODE_DROP_REASON_UNKNOWN_TYPE \
58 "DUT"
59#define UWPOLLING_NODE_DROP_REASON_WRONG_RECEIVER \
60 "DWR"
61#define UWPOLLING_NODE_DROP_REASON_WRONG_STATE \
62 "DWS"
63#define UWPOLLING_NODE_DROP_REASON_PACKET_NOT_FOR_ME \
64 "DPNFM"
65#define UWPOLLING_NODE_DROP_REASON_IMINLIST_NOT_POLLED \
66 "DPLNP"
68#define UWPOLLING_NODE_DROP_REASON_NOT_POLLED \
69 "DNP"
74class Uwpolling_NODE : public MMac
75{
76public:
84 virtual ~Uwpolling_NODE();
95 virtual int command(int argc, const char *const *argv);
103 virtual int crLayCommand(ClMessage *m);
104
105protected:
115
123
141
149
153 class Uwpolling_NODE_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
401 {
402 public:
411
416 {
417 }
418
419 protected:
424 virtual void expire(Event *e);
425 };
431 virtual void recvFromUpperLayers(Packet *p);
437 virtual void Mac2PhyStartTx(Packet *p);
443 virtual void Phy2MacEndTx(const Packet *p);
449 virtual void
450 Phy2MacStartRx(const Packet *p)
451 {
452 }
458 virtual void Phy2MacEndRx(Packet *p);
464 virtual void initPkt(UWPOLLING_PKT_TYPE pkt_type);
472 virtual void initInfo();
473
478 virtual void
480 {
481 last_reason = reason;
482 }
483
488 virtual void
490 {
492 curr_state = state;
493 }
494
498 virtual void
500 {
501 n_probe_sent++;
502 }
503
507 virtual void
509 {
511 }
512
516 inline void
521
525 inline void
530
534 inline void
536 {
538 }
539
540 inline void
542 {
543 std::cout << getEpoch() << "::" << NOW
544 << "::Uwpolling_NODE(" << addr
545 << ")::DATA_QUEUE_SIZE--> " << Q_data.size()
546 << std::endl;
547 }
548
553 inline int
555 {
556 return n_probe_sent;
557 }
558
563 inline int
565 {
566 return n_times_polled;
567 }
568
573 inline int
575 {
576 return n_trigger_received;
577 }
578
583 inline int
585 {
586 return n_trigger_dropped;
587 }
588
593 inline int
595 {
596 return n_poll_dropped;
597 }
602 virtual void waitForUser();
606 virtual void stateIdle();
614 virtual void stateTxData();
622 virtual void stateRxTrigger();
630 virtual void stateTxProbe();
638 virtual void stateRxPoll();
643 virtual void BackOffTimerExpired();
649 virtual void RxPollTimerExpired();
655 virtual double getBackOffTime();
659 virtual void TxData();
663 virtual void TxPRobe();
668 virtual void stateWaitPoll();
669
674 inline unsigned long int
676 {
677 unsigned long int timestamp =
678 (unsigned long int) (std::chrono::duration_cast<std::chrono::milliseconds>(
679 std::chrono::system_clock::now().time_since_epoch()).count() );
680 return timestamp;
681 }
682
683 /*************************
684 * input values from TCL *
685 *************************/
686 double T_poll;
692 int
695 uint node_id;
699 int n_run; /*< ID of the experiments (used during sea trial) */
703 std::queue<Packet *> Q_data;
705 static bool initialized;
708 bool
715 bool
720 double
723 double T_in;
725 double T_fin;
727 double BOffTime;
748 static map<Uwpolling_NODE::UWPOLLING_NODE_STATUS, string>
750 static map<Uwpolling_NODE::UWPOLLING_NODE_REASON, string>
752 static map<Uwpolling_NODE::UWPOLLING_PKT_TYPE, string>
760 std::ofstream fout;
761 std::ofstream out_file_stats;
762
767};
768#endif
Class (inherited from Uwpolling_NODE_Timer) used to handle the time of backoff of the node before tra...
BackOffTimer(Uwpolling_NODE *m)
Conscructor of ProbeTimer class.
virtual void expire(Event *e)
Method call when the timer expire.
virtual ~BackOffTimer()
Destructor of DataTimer class.
Class (inherited from Uwpolling_NODE_Timer) used to handle the time in which the NODE wait for the PO...
virtual void expire(Event *e)
Method call when the timer expire.
Rx_Poll_Timer(Uwpolling_NODE *m)
Conscructor of Rx_Poll_Timer class.
virtual ~Rx_Poll_Timer()
Destructor of ProbeTimer class.
Class (inherited from Uwpolling_NODE_Timer) used to handle the time between the transmission of the D...
virtual void expire(Event *e)
Method call when the timer expire.
Tx_Data_Timer(Uwpolling_NODE *m)
Conscructor of Tx_Data_Timer class.
virtual ~Tx_Data_Timer()
Destructor of Tx_Data_Timer class.
Class that describes the timer in the AUV.
bool isRunning()
Checks if the timer is RUNNING.
Uwpolling_NODE *UWPOLLING_TIMER_STATUS timer_status
< Pointer to an object of type Uwpolling_AUV
virtual void freeze()
Freeze the timer.
int getCounter()
Returns the counter of the timer.
Uwpolling_NODE_Timer(Uwpolling_NODE *m)
Constructor of the Uwpolling_NODE_Timer class.
virtual void stop()
stops the timer
double start_time
Start Time of the timer.
virtual void schedule(double val)
Schedules a timer.
virtual void unFreeze()
unFreeze is used to resume the timer starting from the point where it was freezed
bool isExpired()
Checks if the timer is EXPIRED.
bool isFrozen()
Checks if the timer is FROZEN.
bool isActive()
Checks if the timer is ACTIVE.
void resetCounter()
Resets the counter of the timer.
double left_duration
Left duration of the timer.
double getDuration()
Returns the counter of the timer.
bool isIdle()
Checks if the timer is IDLE.
virtual ~Uwpolling_NODE_Timer()
Destructor of the Uwpolling_NODE_Timer class.
void incrCounter()
Increments 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.
UWPOLLING_NODE_REASON last_reason
Last reason to the change of state.
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 Phy2MacStartRx(const Packet *p)
Method called when the Phy Layer start to receive a Packet.
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
UWPOLLING_NODE_STATUS
< Variable that rapresents the status of the protocol machine state
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.
std::pair< int, int > counter
counter of collisions
Common structures and variables in the protocol.