43#include "mphy_pktheader.h"
66 : TclClass(
"Module/UW/POLLING/SINK")
87 , RxDataEnabled(false)
89 , triggerEnabled(true)
95 , n_trigger_received(0)
96 , n_trigger_dropped(0)
103 , expected_last_id(0)
104 , prev_expect_last_id(0)
110 , curr_trigger_pkt(0)
113 , curr_state(UWPOLLING_SINK_STATUS_IDLE)
114 , prev_state(UWPOLLING_SINK_STATUS_IDLE)
115 , backoff_timer(this)
116 , rx_data_timer(this)
122 , useAdaptiveTdata(0)
127 , modem_data_bit_rate(900)
131 bind(
"sink_id_", (uint *) &
sink_id);
133 bind(
"n_run_", (
int *) &
n_run);
138 bind(
"T_guard_", (
double *) &
T_guard);
153 Tcl &tcl = Tcl::instance();
155 if (strcasecmp(argv[1],
"initialize") == 0) {
159 }
else if (strcasecmp(argv[1],
"getProbeSent") == 0) {
162 }
else if (strcasecmp(argv[1],
"getAckSent") == 0) {
165 }
else if (strcasecmp(argv[1],
"getTriggerReceived") == 0) {
168 }
else if (strcasecmp(argv[1],
"getTriggerDropped") == 0) {
171 }
else if (strcasecmp(argv[1],
"getDuplicatedPkts") == 0) {
175 }
else if (argc == 3) {
176 if (strcasecmp(argv[1],
"setMacAddr") == 0) {
177 addr = atoi(argv[2]);
181 return MMac::command(argc, argv);
189 return MMac::crLayCommand(m);
196 if (module->debug_) {
197 std::cout << NOW <<
"Uwpolling_SINK(" <<
module->addr
198 << ")::BACKOFF_TIMER::EXPIRED" << std::endl;
201 module->BackOffTimerExpired();
207 if (module->debug_) {
208 std::cout << NOW <<
"Uwpolling_SINK(" <<
module->addr
209 << ")::RX_DATA_TIMER::EXPIRED" << std::endl;
212 module->RxDataTimerExpired();
218 hdr_cmn *ch = HDR_CMN(p);
219 hdr_mac *mach = HDR_MAC(p);
220 int dest_mac = mach->macDA();
225 std::cout << NOW <<
"Uwpolling_SINK(" << addr
226 <<
")::PHY2MACENDRX::DROP_TRIGGER" << std::endl;
229 <<
"::Uwpolling_SINK(" << addr
230 <<
")::PKT_TRIGGER_DROP_ERROR" << endl;
236 if (dest_mac == addr || dest_mac == (
int) MAC_BROADCAST) {
254 std::cout << NOW <<
"Uwpolling_SINK(" << addr
255 <<
")::Resched rx data timer, timeout="
274 std::cout << NOW <<
"Uwpolling_SINK(" << addr <<
")::IDLE_STATE"
303 std::cout << NOW <<
"Uwpolling_SINK(" << addr
304 <<
")::STATE_RX_TRIGGER, rx from MAC="
313 std::cerr <<
"Negative backoff value " << std::endl;
321 std::cout << NOW <<
"Uwpolling_SINK(" << addr
322 <<
")::RX_TRIGGER_NOT_ENABLED" << std::endl;
329 double random = ((double)(RNG::defaultrng()->uniform(INT_MAX) % (int)((
T_fin-
T_in)*100)))/100 +
T_in;
331 std::cout << NOW <<
"Uwpolling_SINK(" << addr
345 std::cout << NOW <<
"Uwpolling_SINK(" << addr
346 <<
") Backoff timer expired but node not triggered"
361 <<
"::Uwpolling_SINK(" << addr
362 <<
")::TX_PROBE_ID_" << probehdr->
PROBE_uid() << std::endl;
365 std::cout << NOW <<
"Uwpolling_SINK(" << addr
366 <<
")::STATE_TX_PROBE_ID_" << probehdr->
PROBE_uid()
377 Packet *p = Packet::alloc();
379 hdr_cmn *ch = hdr_cmn::access(p);
380 hdr_mac *mach = HDR_MAC(p);
383 mach->ftype() = MF_CONTROL;
385 mach->macSA() = addr;
396 Packet *p = Packet::alloc();
398 hdr_cmn *ch = hdr_cmn::access(p);
399 hdr_mac *mach = HDR_MAC(p);
402 mach->ftype() = MF_CONTROL;
404 mach->macSA() = addr;
405 std::vector<uint16_t> & ack = ackh->
id_ack();
411 std::cout <<
"Uwpolling_SINK(" << addr <<
")::max number of "
412 <<
"ack reached" << std::endl;
419 std::cout <<
"Uwpolling_SINK(" << addr <<
")::max number "
420 <<
"of ack reached" << std::endl;
425 ch->size() = ack.size() *
sizeof(uint16_t);
427 std::cout << NOW <<
"Uwpolling_SINK(" << addr
428 <<
")::ack list size=" << ack.size() << std::endl;
446 MMac::Mac2PhyStartTx(p);
452 hdr_cmn* ch = HDR_CMN(p);
469 std::cout << NOW <<
"Uwpolling_SINK(" << addr
470 <<
")STATE_WAIT_DATA::Data_Timer = " <<
T_data << std::endl;
487 uint16_t auv_uid = auvh->
pkt_uid();
493 double expected_pkts = 0;
502 if (ph->duration > 0) {
508 double new_dataTO = (expected_pkts-1)*duration;
509 new_dataTO = new_dataTO + 0.5*new_dataTO;
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;
519 <<
"::Uwpolling_SINK(" << addr
520 <<
")::STATE_RX_DATA::RX_DATA_ID_" << cbrh->
sn_
521 <<
"_FROM_NODE_" << mach->macSA() << endl;
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;
532 }
else if(auv_uid >
last_rx+1){
533 uint16_t n_miss = (auv_uid-1) -
last_rx;
540 std::list<uint16_t>::iterator it =
548 std::cout << NOW <<
"Uwpolling_SINK(" << addr
549 <<
")received duplicate packet with id2 "
550 << auv_uid << std::endl;
604 for (uint16_t i = 1; i <= n_pkts; i++) {
621 std::cout << NOW <<
"Uwpolling_SINK(" << addr
622 <<
")stateTxAck()" << std::endl;
644 std::stringstream stat_file;
645 stat_file <<
"./Uwpolling_SINK_" << addr <<
"_" <<
n_run <<
".out";
646 std::cout << stat_file.str().c_str() << endl;
649 <<
"::Uwpolling_SINK(" << addr <<
")::NS_START" << endl;
656 "Waiting for the reception of DATA packet";
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";
679 "Data timer expired Time-Out";
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 "
696 std::string response;
697 std::cout <<
"Press Enter to continue";
698 std::getline(std::cin, response);
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.
@ UWPOLLING_SINK_STATUS_WAIT_DATA
@ UWPOLLING_SINK_STATUS_RX_DATA
@ UWPOLLING_SINK_STATUS_TX_ACK
@ UWPOLLING_SINK_STATUS_TX_PROBE
@ UWPOLLING_SINK_STATUS_RX_TRIGGER
@ UWPOLLING_SINK_STATUS_IDLE
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_RX_TRIGGER
@ UWPOLLING_SINK_REASON_BACKOFF_TIMER_EXPIRED
@ UWPOLLING_SINK_REASON_TX_PROBE
@ UWPOLLING_SINK_REASON_WRONG_TYPE
@ UWPOLLING_SINK_REASON_PKT_ERROR
@ UWPOLLING_SINK_REASON_NOT_SET
@ UWPOLLING_SINK_REASON_TX_ACK
@ UWPOLLING_SINK_REASON_WRONG_STATE
@ UWPOLLING_SINK_REASON_WRONG_RECEIVER
@ UWPOLLING_SINK_REASON_RX_DATA_TIMER_EXPIRED
@ UWPOLLING_SINK_REASON_MAX_DATA_RECEIVED
@ UWPOLLING_SINK_REASON_RX_DATA
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.
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.
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.