60 : TclClass(
"Module/UW/POLLING/NODE")
79 std::cout <<
module->getEpoch() << "::" << NOW << "::Uwpolling_NODE(" << module->addr
80 << ")::BACKOFF_TIMER::EXPIRED" << std::endl;
82 if (module->Triggered) {
83 module->BackOffTimerExpired();
98 std::cout <<
module->getEpoch() << "::" << NOW << "::Uwpolling_NODE(" << module->addr
99 << ")::RX_POLL_TIMER::EXPIRED" << std::endl;
101 module->RxPollTimerExpired();
108 std::cout <<
module->getEpoch() << "::" << NOW << "::Uwpolling_NODE(" << module->addr
109 << ")::DATA_TIMER::EXPIRED" << std::endl;
111 module->stateTxData();
176 bind(
"node_id_", (uint *) &
node_id);
180 bind(
"n_run_", (
int *) &
n_run);
205 Tcl &tcl = Tcl::instance();
207 if (strcasecmp(argv[1],
"initialize") == 0) {
211 }
else if (strcasecmp(argv[1],
"getDataQueueSize") == 0) {
212 tcl.resultf(
"%d",
Q_data.size());
214 }
else if (strcasecmp(argv[1],
"getDataQueueLog") == 0) {
217 }
else if (strcasecmp(argv[1],
"getProbeSent") == 0) {
220 }
else if (strcasecmp(argv[1],
"getTimesPolled") == 0) {
223 }
else if (strcasecmp(argv[1],
"getTriggerReceived") == 0) {
226 }
else if (strcasecmp(argv[1],
"getTriggerDropped") == 0) {
229 }
else if (strcasecmp(argv[1],
"getPollDropped") == 0) {
234 }
else if (argc == 3) {
235 if (strcasecmp(argv[1],
"setMacAddr") == 0) {
236 addr = atoi(argv[2]);
240 return MMac::command(argc, argv);
248 return MMac::crLayCommand(m);
258 std::stringstream stat_file;
259 stat_file <<
"./Uwpolling_NODE_" << addr <<
"_" <<
n_run <<
".out";
260 std::cout << stat_file.str().c_str() << endl;
263 <<
"::Uwpolling_NODE(" << addr <<
")::NS_START" << endl;
269 "Receiving Trigger from AUV";
273 "Waiting for the reception of POLL packet";
284 "Receving POLL Time-Out";
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 "
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";
315 if (probehdr->
n_pkts() > 0) {
320 <<
"::Uwpolling_NODE(" << addr
322 <<
"_N_PKTS=" << (uint) probehdr->
n_pkts_
325 std::cout <<
getEpoch() <<
"::" << NOW <<
"::Uwpolling_NODE(" << addr
327 <<
"_N_PKTS=" << (uint) probehdr->
n_pkts_ << endl;
332 <<
getEpoch() <<
"::" << NOW <<
"::Uwpolling_NODE(" << addr
333 <<
")::STATE_TX_PROBE::NOT_TX_PROBE--->Empty Data Queue"
355 std::cout <<
getEpoch() <<
"::" << NOW <<
"::Uwpolling_NODE(" << addr
356 <<
")::STATE_WAIT_POLL---> Timer_rx_poll = "
360 cerr <<
"Scheduling POLL timer ----> negative value " <<
T_poll << endl;
373 std::cout <<
getEpoch() <<
"::" << NOW <<
"::Uwpolling_NODE(" << addr
374 <<
")::STATE_RX_POLL::Node_POLLED = " << pollh->
id_
376 int polled_node = pollh->
id_;
381 if (
node_id == (uint) polled_node) {
385 <<
"::Uwpolling_NODE(" << addr
386 <<
")::POLLED_POLL_ID_" << pollh->
POLL_uid_
399 std::cout <<
getEpoch() <<
"::" << NOW <<
"::Uwpolling_NODE(" << addr
400 <<
")::STATE_RX_POLL::NODE_NOT_POLLED" << endl;
412 std::cout <<
getEpoch() <<
"::" << NOW <<
"::UWPOLLING_NODE(" << addr
413 <<
")::RECV_FROM_U_LAYERS_ID_" << cbrh->
sn_ << endl;
416 <<
"::Uwpolling_NODE(" << addr
417 <<
")::RECV_FROM_U_LAYERS_ID_" << cbrh->
sn_ << endl;
424 <<
"Uwpolling_NODE(" << addr <<
")::DROP_FULL_QUEUE"
427 std::cout <<
getEpoch() <<
"::" << NOW <<
"::Uwpolling_NODE(" << addr
428 <<
")::DROP_FULL_QUEUE" << std::endl;
429 incrDiscardedPktsTx();
449 std::cout <<
getEpoch() <<
"::" << NOW <<
"::Uwpolling_NODE(" << addr
452 <<
"_PACKET_INDEX_" << cbrh->
sn_ << std::endl;
455 <<
"::Uwpolling_NODE(" << addr <<
")::TX_DATA_"
457 <<
"_PACKET_INDEX_" << cbrh->
sn_ << endl;
461 mach->macSA() = addr;
470 MMac::Mac2PhyStartTx(p);
494 Packet *dummy = Packet::alloc();
495 hdr_cmn *ch = HDR_CMN(dummy);
497 hdr_mac *mach = HDR_MAC(dummy);
514 if (dataPacket_duration < 0) {
515 cerr <<
"Scheduling Tx_Data timer ----> negative value "
516 << dataPacket_duration << endl;
517 dataPacket_duration = 8;
525 std::cerr <<
getEpoch() <<
"::" << NOW <<
"::UWPOLLING_NODE(" << addr
526 <<
")::PHY2MACENDTX::logical_error,state = "
538 Packet *p = Packet::alloc();
540 hdr_cmn *ch = hdr_cmn::access(p);
541 hdr_mac *mach = HDR_MAC(p);
543 hdr_cmn *chd = hdr_cmn::access(
Q_data.back());
546 std::cout <<
getEpoch() <<
"::" << NOW <<
"::Uwpolling_NODE(" << addr
550 <<
"::Number of pkts to TX=" <<
Q_data.size()
569 mach->macSA() = addr;
582 std::cout <<
getEpoch() <<
"::" << NOW <<
"::Uwpolling_NODE(" << addr <<
")::IDLE_STATE"
606 <<
"::Uwpolling_NODE(" << addr <<
")::RX_TRIGGER_ID_"
609 std::cout <<
getEpoch() <<
"::" << NOW <<
"::Uwpolling_NODE(" << addr
610 <<
")::STATE_RX_TRIGGER --> HEADER :: T_fin = "
611 << triggerhdr->
t_fin() <<
" T_in = " << triggerhdr->
t_in()
616 T_in = (double) triggerhdr->
t_in() / 100;
620 cerr <<
"Scheduling Backoff timer ---> negative value " <<
BOffTime
631 double random = ((double)(RNG::defaultrng()->uniform(INT_MAX) % (int)((
T_fin-
T_in)*100)))/100 +
T_in;
633 std::cout <<
getEpoch() <<
"::" << NOW <<
"::Uwpolling_NODE(" << addr
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();
650 std::cout <<
getEpoch() <<
"::" << NOW <<
"::Uwpolling_NODE(" << addr
651 <<
")::PHY2MACENDRX::DROP_TRIGGER" << std::endl;
654 <<
"::Uwpolling_NODE(" << addr
655 <<
")::PKT_TRIGGER_DROP_ERROR" << endl;
657 }
else if (ch->ptype() ==
PT_POLL) {
659 std::cout <<
getEpoch() <<
"::" << NOW <<
"::Uwpolling_NODE(" << addr
660 <<
")::PHY2MACENDRX::DROP_POLL" << std::endl;
663 <<
"::Uwpolling_NODE(" << addr
664 <<
")::PKT_POLL_DROP_ERROR" << endl;
669 }
else if ((dest_mac == addr) || (dest_mac == (
int) MAC_BROADCAST)) {
675 }
else if (rx_pkt_type ==
PT_POLL) {
679 std::cout <<
getEpoch() <<
"::" << NOW <<
"::Uwpolling_NODE(" << addr
680 <<
")::PHY2MACENDRX::RX_POLL::POLLED_NODE= "
681 << pollh->
id_ << std::endl;
693 std::cout <<
getEpoch() <<
"::" << NOW <<
"::Uwpolling_NODE(" << addr
694 <<
")::PHY2MACENDRX::WARNING!!TRIGGER packet not in "
698 }
else if (rx_pkt_type ==
PT_POLL) {
700 std::cout <<
getEpoch() <<
"::" << NOW <<
"::Uwpolling_NODE(" << addr
701 <<
")::PHY2MACENDRX::WARNING!!POLL packet not in "
712 std::string response;
713 std::cout <<
"Press Enter to continue";
714 std::getline(std::cin, response);
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
@ UWPOLLING_NODE_STATUS_IDLE
@ UWPOLLING_NODE_STATUS_RX_POLL
@ UWPOLLING_NODE_STATUS_WAIT_POLL
@ UWPOLLING_NODE_STATUS_RX_TRIGGER
@ UWPOLLING_NODE_STATUS_TX_DATA
@ UWPOLLING_NODE_STATUS_TX_PROBE
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_TX_DATA
@ UWPOLLING_NODE_REASON_NOT_IN_LIST
@ UWPOLLING_NODE_REASON_WRONG_TYPE
@ UWPOLLING_NODE_REASON_LIST_NOT_POLLED
@ UWPOLLING_NODE_REASON_BACKOFF_TIMER_EXPIRED
@ UWPOLLING_NODE_REASON_RX_TRIGGER
@ UWPOLLING_NODE_REASON_NOT_SET
@ UWPOLLING_NODE_REASON_RX_POLL
@ UWPOLLING_NODE_REASON_RX_POLL_TIMER_EXPIRED
@ UWPOLLING_NODE_REASON_PKT_ERROR
@ UWPOLLING_NODE_REASON_WRONG_RECEIVER
@ UWPOLLING_NODE_REASON_TX_PROBE
@ 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.
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.
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