59 : TclClass(
"Module/UW/CSMA_CA")
76 Tcl &tcl = Tcl::instance();
79 if (!strcasecmp(argv[1],
"initialize")) {
83 if (!strcasecmp(argv[1],
"setAckMode")) {
87 if (!strcasecmp(argv[1],
"setNoAckMode")) {
91 if (!strcasecmp(argv[1],
"getCTSDropped")) {
95 if (!strcasecmp(argv[1],
"getRTSDropped")) {
99 if (!strcasecmp(argv[1],
"getDataDropped")) {
103 if (!strcasecmp(argv[1],
"getQueueSize")) {
107 if (!strcasecmp(argv[1],
"getUpDataRx")) {
108 tcl.resultf(
"%d", up_data_pkts_rx);
111 if (!strcasecmp(argv[1],
"getRTSRx")) {
115 if (!strcasecmp(argv[1],
"getCTSRx")) {
121 if (!strcasecmp(argv[1],
"setMacAddr")) {
122 addr = atoi(argv[2]);
127 return MMac::command(argc, argv);
142 , data_pkt_dropped(0)
147 , actual_data_packet(0)
148 , logfile(
"/dev/null")
154 bind(
"bitrate_", (
int *) &
bitrate);
170 module->data_timer_fired();
173 module->backoff_timer_fired();
176 module->cts_timer_fired();
179 module->ack_timer_fired();
188 LOGERR(
"Ack timer fired but not waiting for an ACK\n");
200 LOGERR(
"Backoff timer expired but not in backoff");
212 LOGERR(
"CTS timer expired but not waiting for a CTS");
220 LOGINFO(
"Data timer expired ");
223 LOGERR(
"Data timer expired but not waiting for a DATA");
230 stringstream strs(
"");
231 strs <<
"CSMA_CA_" << addr;
236 cout <<
"Error creating log for Csma-Ca" << endl;
243 MMac::Mac2PhyStartTx(p);
249 hdr_cmn *ch = HDR_CMN(p);
250 packet_t rx_pkt_type = ch->ptype();
251 hdr_mac *mach = HDR_MAC(p);
258 LOGWRN(
"Drop packet due to error");
259 drop(p, 1,
"REASON_ERROR");
265 rts_ret =
stateRxRTS(rts, mach->macSA(), mach->macDA());
283 cts_ret =
stateRxCTS(cts, mach->macSA(), mach->macDA());
311 if (rx_data_ret == -1) {
313 }
else if (rx_data_ret == -2) {
323 hdr_mac *mac = HDR_MAC(ack);
324 if (mac->macDA() == addr) {
331 LOGERR(
"Received an ACK but not waiting for it\n");
334 }
else if ((uint32_t) mac->macDA() == MAC_BROADCAST) {
335 LOGERR(
"Received a broadcast ACK\n");
338 LOGWRN(
"Received an ACK not for us\n");
355 hdr_mac *mach = HDR_MAC(p);
356 if (mach->macDA() == addr) {
362 LOGDBG(
"Sending ACK for Data\n");
365 LOGDBG(
"No ACK Mode Activated\n");
370 LOGWRN(
"Received a Data Packet while not waiting for it");
374 LOGWRN(
"Received a Data Packet not for me");
382 const int WRONG_STATE = -1;
383 const int NOT_FOR_US = -2;
384 const int ERROR = -3;
386 if (mac_dst == addr) {
392 LOGERR(
"Actual actual_expected_tx_time is 0");
403 LOGWRN(
"Received an RTS and not in state IDLE");
404 return (WRONG_STATE);
406 }
else if ((uint32_t) mac_dst == MAC_BROADCAST) {
407 LOGERR(
"Just received a broadcast RTS");
410 LOGDBG(
"Received an RTS not for us");
422 LOGERR(
"Error sending CTS ");
439 const int NOT_FOR_ME = -1;
449 LOGERR(
"Overheared a CTS not for me and not in IDLE. Discarding \
450 and not setting up backoff");
474 LOGDBG(
"Starting Rx a Packet");
475 MMac::Phy2MacStartRx(p);
490 hdr_cmn *ch = HDR_CMN(p);
525 LOGINFO(
"Extracting Data Packet from queue and sending RTS");
531 if (!
txRTS(mach->macDA())) {
532 LOGERR(
"Error sending RTS");
609 LOGINFO(
"Waiting for DATA Packet");
617 (*rts)->set_tx_time(tx_time);
623 (*cts)->set_tx_time(tx_time);
633 hdr_cmn *ch_r = hdr_cmn::access(p);
634 hdr_mac *mac_r = HDR_MAC(p);
637 mac_r->set(MF_CONTROL, addr, mac_dest);
643 hdr_cmn *ch_c = hdr_cmn::access(p);
644 hdr_mac *mac_c = HDR_MAC(p);
647 mac_c->set(MF_CONTROL, addr, mac_dest);
653 hdr_cmn *ch_c = hdr_cmn::access(p);
654 hdr_mac *mac_c = HDR_MAC(p);
657 mac_c->set(MF_CONTROL, addr, mac_dest);
661 LOGERR(
"Called buidPacket for unknown packet type");
CSMACAModuleClass()
Constructor of the class.
TclObject * create(int, const char *const *)
Creates the TCL object needed for the tcl language interpretation.
CsmaCa *csma_ca_timers_t timer_type
virtual void expire(Event *e)
Class that describes a CsmaAloha module.
string logfile
File name of log.
int cts_wait_val
Timer duration of CTS.
int max_queue_size
Maximum dimension of Queue.
void extractDataPacket()
Extract data packet from queue.
int cts_pkt_dropped
CTS packet dropped.
Packet * buildPacket(int mac_dest, csma_ca_pkt_type_t type, uint8_t tx_time)
Build a generic packet.
virtual void state_Wait_ACK()
Wait for an ACK after a data transmission.
time_t getEpoch()
Return the system epoch.
virtual int stateTxData()
Transmission of a DATA packet.
csma_ca_states_t state
Current state of the protocol.
int n_rts_rx
RTS received.
int n_cts_rx
CTS received.
virtual int stateRxACK(Packet *ack)
Reception of an ACK packet.
int data_pkt_dropped
DATA packet dropped.
virtual void initializeLog()
Initializes the protocol at the beginning of the simulation.
int data_wait_val
Timer duration of DATA.
void ack_timer_fired()
ACK timer is expired.
int txData()
Actually transmit a DATA packet.
void data_timer_fired()
data timer is expired
virtual void Phy2MacStartRx(const Packet *p)
Method called when the Phy Layer start to receive a Packet.
CsmaCaTimer ack_timer
ACK timer.
std::queue< Packet * > data_q
Size of DATA packet.
virtual void state_Backoff(int tx_time)
Backoff state.
string getLogFile()
Return name of the log file.
int actual_mac_data_src
Source MAC of DATA packet we are handling.
virtual int stateRxCTS(hdr_ca_CTS *cts, int mac_src, int mac_dst)
Reception of an CTS packet.
virtual void state_Idle()
Protocol in IDLE state.
void buildRTShdr(hdr_ca_RTS **rts, uint8_t tx_time)
Build an RTS header.
void backoff_timer_fired()
backoff timer is expired
void buildCTShdr(hdr_ca_CTS **cts, uint8_t tx_time)
Build an CTS header.
void printonLog(csma_ca_log_level_t level, string log)
Print a message on log file.
virtual void dropPacket(Packet *p, csma_ca_pkt_type_t type, char *reason)
Drop the packet logging the reason and incrementing the counters.
virtual void state_Wait_CTS()
Waiting for CTS packet.
virtual int stateRxData(Packet *p)
Transmit a data packet.
int getQueueSize()
Return the size of the data packet queue.
virtual void stateTxCTS()
Transmission of a CTS packet.
int data_size
Size of DATA packet.
CsmaCaTimer backoff_timer
Backoff timer.
int txRTS(int mac_dest)
Actually transmit a RTS packet.
Packet * actual_data_packet
Pointer to DATA packet we are handling.
int ack_pkt_dropped
ACK packet dropped.
int backoff_max
Maximum value in range of backoff.
virtual int stateRxRTS(hdr_ca_RTS *rts, int mac_src, int mac_dst)
Reception of an RTS packet.
int actual_expected_tx_time
Tx time of DATA packet we are handling.
csma_ca_log_level_t getLogLevel()
Return the current log level of the protocol.
virtual void stateTxAck(int mac_dst)
Tranmission of an ACK.
int computeTxTime()
Compute transmission time of a packet using known bitrate.
int ack_wait_val
Timer duration of ACK.
CsmaCaTimer data_timer
Data timer.
virtual void Mac2PhyStartTx(Packet *p)
Pass the packet to the PHY layer.
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
virtual void state_Wait_Data()
Waiting for DATA packet.
int bitrate
Bit rate adopted.
int txCTS(int mac_dest)
Actually transmit a CTS packet.
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.
std::ofstream outLog
Stdout stream of log.
int backoff_delta
Delta value (configurable) to be added to backoff.
void cts_timer_fired()
CTS timer is expired.
CsmaCaTimer cts_timer
CTS timer.
virtual void recvFromUpperLayers(Packet *p)
Receives the packet from the upper layer (e.g.
void updateState(csma_ca_states_t s)
Update the state of the protocol.
ack_modes_t ack_mode
ACK mode (configurable.
csma_ca_states_t getState()
Get the state of the protocol.
int rts_pkt_dropped
RTS packet dropped.
Provides the headers of ctrl packets of uw-csma-ca module.
#define CA_CTS_HDR_ACCESS(p)
#define CA_RTS_HDR_ACCESS(p)
CSMACAModuleClass class_module_csmaca
Provides the description of CsmaCa Class.
#define DROP_REASON_GENERICERROR
#define DROP_REASON_NOTRIGHTSTATE
enum CSMA_CA_PKT_TYPE csma_ca_pkt_type_t
#define DROP_REASON_NOTFORME
enum log_level csma_ca_log_level_t
string log_level_string[]