46 : TclClass(
"Module/UW/CSMA_ALOHA/TRIGGER/NODE")
65 cout << NOW <<
" UwCsmaAloha_Trigger_NODE(" <<
module->addr
66 << ") timer expire() current state = "
67 << module->status_info[module->curr_state]
68 << "; listening period expired, next state =
"
69 << module->status_info[UW_CS_ALOHA_TRIG_NODE_STATE_TX_DATA]
72 module->refreshReason(UW_CS_ALOHA_TRIG_NODE_REASON_LISTEN_TIMEOUT);
73 module->stateTxData();
77 << ")::ListenTimer::expired()
" << endl;
82UwCsmaAloha_Trigger_NODE::TransmissionTimer::expire(Event *e)
84 timer_status = UW_CS_ALOHA_TRIG_NODE_EXPIRED;
85 if (module->can_transmit == true) {
88 << ") Transmission timer
expire() current state = "
93 std::cerr <<
"Transmission Timer expired, can_transmit == false"
102map<UwCsmaAloha_Trigger_NODE::UW_CS_ALOHA_TRIG_NODE_STATUS, string>
104map<UwCsmaAloha_Trigger_NODE::UW_CS_ALOHA_TRIG_NODE_REASON_STATUS, string>
122 mac2phy_delay_ = 1e-19;
124 bind(
"HDR_size_", (
int *) &
HDR_size);
125 bind(
"debug_", (
double *) &debug_);
146 Tcl &tcl = Tcl::instance();
148 if (strcasecmp(argv[1],
"initialize") == 0) {
151 }
else if (strcasecmp(argv[1],
"getQueueSize") == 0) {
152 tcl.resultf(
"%d",
Q.size());
156 return MMac::command(argc, argv);
165 return Module::crLayCommand(m);
181 "Start rx Listen state";
183 "Check Listen timeout state";
185 "Wrong Pkt Rx state";
187 "Received a TRIGGER packet from AUV";
190 "DATA pending from upper layers";
195 "DATA pending, listening to channel";
197 "DATA pending, end of listening period";
200 "Received an erroneous pkt";
202 "Listen to channel pending";
205 "Received a TRIGGER packet from AUV";
207 "TRIGGER received ---> Listen to the channel";
225 cerr << showpoint << NOW <<
" " << __PRETTY_FUNCTION__
226 <<
" transmitting packet" << endl;
229 incrDiscardedPktsTx();
237 hdr_cmn *ch = hdr_cmn::access(p);
238 int curr_size = ch->size();
249 cout << NOW <<
" UwCsmaAloha_Trigger_NODE(" << addr
250 <<
")::Mac2PhyStartTx() start tx packet" << endl;
252 MMac::Mac2PhyStartTx(p);
260 cout << NOW <<
" UwCsmaAloha_Trigger_NODE(" << addr
261 <<
")::Phy2MacEndTx() end tx packet" << endl;
269 cout << NOW <<
" UwCsmaAloha_Trigger_NODE(" << addr
270 <<
")::Phy2MacEndTx() DATA sent, from "
278 cout << NOW <<
" UwCsmaAloha_Trigger_NODE(" << addr
279 <<
")::Phy2MacEndTx() logical error, current state = "
289 cout << NOW <<
" UwCsmaAloha_Trigger_NODE(" << addr
290 <<
")::Phy2MacStartRx() rx Packet " << endl;
305 std::cerr << NOW <<
" UwCsmaAloha_Trigger_NODE(" << addr
306 <<
")::Phy2MacStartRx() logical warning, current "
316 hdr_cmn *ch = HDR_CMN(p);
317 packet_t rx_pkt_type = ch->ptype();
318 hdr_mac *mach = HDR_MAC(p);
319 hdr_MPhy *ph = HDR_MPHY(p);
321 int dest_mac = mach->macDA();
323 double gen_time = ph->txtime;
324 double received_time = ph->rxtime;
325 double diff_time = received_time - gen_time;
330 cout << NOW <<
" UwCsmaAloha_Trigger_NODE(" << addr
332 <<
", received a pkt type = " << ch->ptype()
333 <<
", src addr = " << mach->macSA()
334 <<
" dest addr = " << mach->macDA()
335 <<
", estimated distance between nodes = " << distance <<
" m "
341 cout << NOW <<
" UwCsmaAloha_Trigger_NODE(" << addr
342 <<
")::Phy2MacEndRx() dropping corrupted pkt " << endl;
349 if (dest_mac == (
int) addr || dest_mac == (
int) MAC_BROADCAST) {
368 cout << NOW <<
"Csma_Aloha_NODE(" << addr
369 <<
")::stateRxTrigger---> can_transmit" <<
can_transmit << endl;
380 cout << NOW <<
"Csma_Aloha_NODE(" << addr
381 <<
")::stateRxTrigger---> can_transmit already true " << endl;
400 cout << NOW <<
" UwCsmaAloha_Trigger_NODE(" << addr
401 <<
")::stateRxPacketNotForMe() pkt for another address. Dropping "
421 cerr << NOW <<
" UwCsmaAloha_Trigger_NODE(" << addr
422 <<
")::stateRxPacketNotForMe() logical error, prev state "
435 cout << NOW <<
" UwCsmaAloha_Trigger_NODE(" << addr
436 <<
")::stateCheckListenExpired()" << endl;
449 cerr << NOW <<
" UwCsmaAloha_Trigger_NODE(" << addr
450 <<
")::stateCheckListenExpired() listen_timer logical error, "
451 "current timer state = "
469 cout << NOW <<
" UwCsmaAloha_Trigger_NODE(" << addr
470 <<
")::stateIdle() queue size = " <<
Q.size() << endl;
499 cout << NOW <<
" UwCsmaAloha_Trigger_NODE(" << addr
500 <<
")::stateListen() listen time = " << time << endl;
518 cout << NOW <<
" UwCsmaAloha_Trigger_NODE(" << addr
519 <<
")::stateTxData() " << endl;
530 cout << NOW <<
" UwCsmaAloha_Trigger_NODE(" << addr
531 <<
")::stateTxData() ---> Not Allowed To Transmit " << endl;
541 cout << NOW <<
" UwCsmaAloha_Trigger_NODE(" << addr
542 <<
")::stateRxData() " << endl;
548 hdr_cmn *ch = hdr_cmn::access(data_pkt);
556 hdr_cmn *ch = hdr_cmn::access(data_pkt);
566 cerr << NOW <<
" UwCsmaAloha_Trigger_NODE(" << addr
567 <<
")::stateRxData() logical error, prev state = "
575 std::string response;
576 std::cout <<
"Press Enter to continue";
577 std::getline(std::cin, response);
TclObject * create(int, const char *const *)
UwCsmaAloha_Trigger_NODEModuleClass()
virtual void schedule(double val)
schedule a timer
bool isActive()
Checks if the timer is ACTIVE.
UwCsmaAloha_Trigger_NODE *UW_CS_ALOHA_TRIG_NODE_TIMER_STATUS timer_status
< Pointer of an object of type UwCsmaAloha_Triggered
void incrCounter()
Increments the counter of the timer.
void resetCounter()
Resets the counter of the timer.
bool isExpired()
Checks if the timer is EXPIRED.
virtual void stop()
stops the timer
virtual void expire(Event *e)
Method called when the timer expire.
Class that describes a CsmaAloha_TRIGGERED module of the node.
@ UW_CS_ALOHA_TRIG_NODE_EXPIRED
static bool initialized
true if the protocol is initialized
virtual int crLayCommand(ClMessage *m)
Cross-Layer messages interpreter.
double wait_costant
Adding factor in the calculation of the listen time.
static const double prop_speed
Typical sound propagation speed in underwater enviroment.
UW_CS_ALOHA_TRIG_NODE_STATUS prev_state
Previous state of the protocol.
virtual void stateRxData(Packet *p)
State in which a DATA packet is received.
virtual void refreshState(UW_CS_ALOHA_TRIG_NODE_STATUS state)
Refresh the State of the protocol.
UW_CS_ALOHA_TRIG_NODE_REASON_STATUS last_reason
Reason for the state transitions.
double listen_time
Time in which the node sense the channel.
virtual void waitForUser()
Used for debug purposes.
bool has_buffer_queue
flag that indicates if a node has a buffer where store DATA packets
virtual void Phy2MacStartRx(const Packet *p)
Method called when the Phy Layer start to receive a Packet.
UW_CS_ALOHA_TRIG_NODE_STATUS prev_prev_state
Previous previous state of the protocol.
UwCsmaAloha_Trigger_NODE()
Constructor of the UwCsmaAloha_Trigger_NODE class.
virtual void stateRxIdle()
A reception is occuring while the protocol is in IDLE state.
int buffer_pkts
Length of the data buffer in number of packets.
std::queue< int > data_sn_queue
Queue of the sequence number of the packets.
static map< UW_CS_ALOHA_TRIG_NODE_STATUS, string > status_info
Textual description of the protocol states.
int tx_timer_duration
Duration of the time in which the node is allowed to transmit.
virtual void stateRxListen()
State in which a reception is occuring while the node is listening the channel.
virtual void Mac2PhyStartTx(Packet *p)
Pass the packet to the PHY layer.
virtual void stateTxData()
State in which the protocol allows the node to transmit a data packet.
int u_data_id
DATA packete ID.
virtual void Phy2MacEndRx(Packet *p)
Method called when the Phy Layer finish to receive a Packet.
virtual void Phy2MacEndTx(const Packet *p)
Method called when the PHY layer finish to transmit the packet.
int HDR_size
Size (in bytes) of the header added by the protocol.
virtual ~UwCsmaAloha_Trigger_NODE()
Destructor of the UwCsmaAloha_Trigger_NODE class.
virtual void txData()
Transmits the DATA packet (calling Mac2PhyStartTx) and increment the counter of transmitted data pack...
virtual void stateIdle()
IDLE state.
static map< UW_CS_ALOHA_TRIG_NODE_REASON_STATUS, string > reason_info
Textual description of the protocol reason for the change of the state.
TransmissionTimer tx_timer
int max_payload
Maximum dimension of the data payload in bytes.
static int u_pkt_id
simulation-unique packet ID
std::queue< Packet * > Q
Packet queue.
@ UW_CS_ALOHA_TRIG_NODE_REASON_DATA_RX
@ UW_CS_ALOHA_TRIG_NODE_REASON_LISTEN_AFTER_TRIGGER
@ UW_CS_ALOHA_TRIG_NODE_REASON_DATA_TX
@ UW_CS_ALOHA_TRIG_NODE_REASON_PKT_ERROR
@ UW_CS_ALOHA_TRIG_NODE_REASON_LISTEN_TIMEOUT
@ UW_CS_ALOHA_TRIG_NODE_REASON_NOT_SET
@ UW_CS_ALOHA_TRIG_NODE_REASON_LISTEN_PENDING
@ UW_CS_ALOHA_TRIG_NODE_REASON_LISTEN
@ UW_CS_ALOHA_TRIG_NODE_REASON_PKT_NOT_FOR_ME
@ UW_CS_ALOHA_TRIG_NODE_REASON_DATA_EMPTY
@ UW_CS_ALOHA_TRIG_NODE_REASON_START_RX
@ UW_CS_ALOHA_TRIG_NODE_REASON_TRIGGER_RX
@ UW_CS_ALOHA_TRIG_NODE_REASON_DATA_PENDING
int last_sent_data_id
ID of the last sent packet.
Packet * curr_data_pkt
Pointer to the current data packet.
virtual void stateRxTrigger(Packet *p)
State of the protocol in which a TRIGGER packet is received.
virtual void recvFromUpperLayers(Packet *p)
Receives the packet from the upper layer (e.g.
UW_CS_ALOHA_TRIG_NODE_STATUS curr_state
Current state of the protocol.
virtual void incrUpperDataRx()
Increase the number of Data packet Received from the Upper layers.
virtual void initInfo()
Initializes the protocol at the beginning of the simulation.
virtual void stateCheckListenExpired()
Checks if the Listen period is expired.
bool can_transmit
Flag that indicates if the node can transmit data packets to the sink.
virtual void stateCheckTxTimerExpired()
Checks if the Time period is expired.
virtual void stateListen()
State in which the node is listening the channel.
virtual void initPkt(Packet *p)
Init the packet with the MAC address of the receiver and the sender, the size of the packet and the t...
@ UW_CS_ALOHA_TRIG_NODE_STATE_RX_IDLE
@ UW_CS_ALOHA_TRIG_NODE_STATE_RX_TRIGGER
@ UW_CS_ALOHA_TRIG_NODE_STATE_IDLE
@ UW_CS_ALOHA_TRIG_NODE_STATE_CHK_LISTEN_TIMEOUT
@ UW_CS_ALOHA_TRIG_NODE_STATE_TX_DATA
@ UW_CS_ALOHA_TRIG_NODE_STATE_DATA_RX
@ UW_CS_ALOHA_TRIG_NODE_STATE_RX_LISTEN
@ UW_CS_ALOHA_TRIG_NODE_STATE_WRONG_PKT_RX
@ UW_CS_ALOHA_TRIG_NODE_STATE_LISTEN
virtual void stateRxPacketNotForMe(Packet *p)
state in which a wrong Packet is received
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
virtual void queuePop(bool flag=true)
Pop the first element of the data packet queue.
int last_data_id_rx
ID of the last DATA packet received.
virtual void refreshReason(UW_CS_ALOHA_TRIG_NODE_REASON_STATUS reason)
Refresh the reason for the change of state.
@ SESSION_DISTANCE_NOT_SET
UwCsmaAloha_Trigger_NODEModuleClass class_module_uw_csma_aloha_triggered_node
#define UW_CS_ALOHA_TRIG_NODE_DROP_REASON_BUFFER_FULL
The Buffer of DATA packets is full.
#define UW_CS_ALOHA_TRIG_NODE_DROP_REASON_ERROR
Packet corrupted.