56        : TclClass(
"Module/UW/ALOHA")
 
 
 
   73        if (module->uwaloha_debug)
 
   74            cout << NOW << 
"  UWAloha (" << 
module->addr
 
   75                 << ") timer expire() current state = "
 
   76                 << module->status_info[module->curr_state]
 
   77                 << "; ACK not received, next state = 
" 
   78                 << module->status_info[UWALOHA_STATE_BACKOFF] << endl; 
   80        module->refreshReason(UWALOHA_REASON_ACK_TIMEOUT); 
   81        module->stateBackoff(); 
   83        if (module->uwaloha_debug) 
   84            cout << NOW << "  UWAloha (
" << module->addr 
   85                 << ")::AckTimer::expired() 
" << endl; 
 
   90UWAloha::BackOffTimer::expire(Event *e) 
   92    timer_status = UWALOHA_EXPIRED; 
   93    if (module->curr_state == UWALOHA_STATE_BACKOFF) { 
   95        if (module->uwaloha_debug) 
   96            cout << NOW << "  UWAloha (
" << module->addr 
   97                 << ") timer 
expire() current state = "
 
   99                 << "; backoff expired, next state = "
 
  106        if (module->uwaloha_debug)
 
  107            cout << NOW << 
"  UWAloha (" << 
module->addr
 
  108                 << ")::BackOffTimer::expired() " << endl;
 
 
  141    mac2phy_delay_ = 1e-19;
 
  143    bind(
"HDR_size_", (
int *) &
HDR_size);
 
  144    bind(
"ACK_size_", (
int *) &
ACK_size);
 
  150    bind(
"alpha_", (
double *) &
alpha_);
 
 
  171    Tcl &tcl = Tcl::instance();
 
  173        if (strcasecmp(argv[1], 
"setAckMode") == 0) {
 
  176        } 
else if (strcasecmp(argv[1], 
"setNoAckMode") == 0) {
 
  179        } 
else if (strcasecmp(argv[1], 
"initialize") == 0) {
 
  183                fout.open(
"/tmp/ALOHAstateTransitions.txt", ios_base::app);
 
  185        } 
else if (strcasecmp(argv[1], 
"printTransitions") == 0) {
 
  189        else if (strcasecmp(argv[1], 
"getQueueSize") == 0) {
 
  192        } 
else if (strcasecmp(argv[1], 
"getUpLayersDataRx") == 0) {
 
  196    } 
else if (argc == 3) {
 
  197        if (strcasecmp(argv[1], 
"setMacAddr") == 0) {
 
  198            addr = atoi(argv[2]);
 
  200                cout << 
"Aloha MAC address of current node is " << addr << endl;
 
  204    return MMac::command(argc, argv);
 
 
  214        system(
"rm -f /tmp/ALOHAstateTransitions.txt");
 
  215        system(
"touch /tmp/ALOHAstateTransitions.txt");
 
  231            "Check Backoff timeout state";
 
  241            "DATA dropped due to max tx rounds";
 
 
  259    sumrtt2 += curr_rtt * curr_rtt;
 
 
  273        cout << NOW << 
"  UWAloha (" << addr
 
  274             << 
")::updateAckTimeout() curr ACK_timeout = " << 
ACK_timeout 
 
  288    incrTotalBackoffTimes();
 
  289    double random = RNG::defaultrng()->uniform_double();
 
  296    double backoff_duration =
 
  299    backoffSumDuration(backoff_duration);
 
  302        cout << NOW << 
"  UWAloha (" << addr
 
  303             << 
")::getBackoffTime() backoff time = " << backoff_duration
 
  306    return backoff_duration;
 
 
  313    Packet *temp_data_pkt;
 
  314    map<pktSeqNum, Packet *>::iterator it_p;
 
  319            temp_data_pkt = ((*it_p).second)->copy();
 
  321            hdr_cmn *ch = HDR_CMN(temp_data_pkt);
 
  324            temp_data_pkt = Packet::alloc();
 
  325            hdr_cmn *ch = HDR_CMN(temp_data_pkt);
 
  329        temp_data_pkt = Packet::alloc();
 
  330        hdr_cmn *ch = HDR_CMN(temp_data_pkt);
 
  333    duration = Mac2PhyTxDuration(temp_data_pkt);
 
  334    Packet::free(temp_data_pkt);
 
 
  363        incrDiscardedPktsTx();
 
 
  371    hdr_cmn *ch = hdr_cmn::access(p);
 
  372    hdr_mac *mach = HDR_MAC(p);
 
  374    int curr_size = ch->size();
 
  386            mach->macSA() = addr;
 
  387            mach->macDA() = dest_addr;
 
 
  396        cout << NOW << 
"  UWAloha (" << addr
 
  397             << 
")::Mac2PhyStartTx() start tx packet" << endl;
 
  399    MMac::Mac2PhyStartTx(p);
 
 
  407        cout << NOW << 
"  UWAloha (" << addr
 
  408             << 
")::Phy2MacEndTx() end tx packet" << endl;
 
  417                    cout << NOW << 
"  UWAloha (" << addr
 
  418                         << 
")::Phy2MacEndTx() DATA sent,from " 
  426                    cout << NOW << 
"  UWAloha (" << addr
 
  427                         << 
")::Phy2MacEndTx() DATA sent, from " 
  439                cout << NOW << 
"  UWAloha (" << addr
 
  440                     << 
")::Phy2MacEndTx() ack sent, from " 
  447            cout << NOW << 
"  UWAloha (" << addr
 
  448                 << 
")::Phy2MacEndTx() logical error, current state = " 
 
  460        cout << NOW << 
"  UWAloha (" << addr << 
")::Phy2MacStartRx() rx Packet " 
 
  467    hdr_cmn *ch = HDR_CMN(p);
 
  468    packet_t rx_pkt_type = ch->ptype();
 
  469    hdr_mac *mach = HDR_MAC(p);
 
  470    hdr_MPhy *ph = HDR_MPHY(p);
 
  472    int source_mac = mach->macSA();
 
  473    int dest_mac = mach->macDA();
 
  475    double gen_time = ph->txtime;
 
  476    double received_time = ph->rxtime;
 
  477    double diff_time = received_time - gen_time;
 
  482        cout << NOW << 
"  UWAloha (" << addr << 
")::Phy2MacEndRx() " 
  484             << 
", received a pkt type = " << ch->ptype()
 
  485             << 
", src addr = " << mach->macSA()
 
  486             << 
" dest addr = " << mach->macDA()
 
  487             << 
", estimated distance between nodes = " << distance << 
" m " 
  493            cout << NOW << 
"  UWAloha (" << addr
 
  494                 << 
")::Phy2MacEndRx() dropping corrupted pkt " << endl;
 
  501        if (dest_mac == addr || dest_mac == MAC_BROADCAST) {
 
 
  540    Packet *ack_pkt = Packet::alloc();
 
 
  553        cout << NOW << 
"  UWAloha (" << addr << 
")::stateCheckAckExpired()" 
  556    map<pktSeqNum, AckTimer>::iterator it_a;
 
  561    if (((*it_a).second).isActive()) {
 
  564    } 
else if (((*it_a).second).isExpired()) {
 
  568        cerr << NOW << 
"  UWAloha (" << addr
 
  569             << 
")::stateCheckAckExpired() ack_timer logical error, current " 
 
  583        cout << NOW << 
"  UWAloha (" << addr << 
")::stateCheckBackoffExpired()" 
  595        cerr << NOW << 
"  UWAloha (" << addr
 
  596             << 
")::stateCheckBackoffExpired() backoff_timer logical error, " 
  597                "current timer state = " 
 
  611        cout << NOW << 
"  UWAloha (" << addr
 
  612             << 
")::stateIdle() queue size = " << 
mapPacket.size() << endl;
 
 
  645        cout << NOW << 
"  UWAloha (" << addr << 
")::stateBackoff() " << endl;
 
 
  666        cout << NOW << 
"  UWAloha (" << addr << 
")::stateTxData() " << endl;
 
  670    map<pktSeqNum, Packet *>::iterator it_p;
 
  676    map<pktSeqNum, AckTimer>::iterator it_a;
 
  683        ((*it_a).second).resetCounter();
 
  693            ((*it_a).second).resetCounter();
 
  708                    cout << NOW << 
"  UWAloha (" << addr
 
  709                         << 
")::statePreTxData() curr_tx_rounds " 
 
  725    map<pktSeqNum, AckTimer>::iterator it_a;
 
  728    ((*it_a).second).stop();
 
  732        cout << NOW << 
"  UWAloha (" << addr << 
")::stateWaitAck() " << endl;
 
  736    ((*it_a).second).incrCounter();
 
 
  755        cout << NOW << 
"  UWAloha (" << addr << 
")::stateTxAck() dest addr " 
  756             << dest_addr << endl;
 
 
  770        cout << NOW << 
"  UWAloha (" << addr << 
")::stateRxData() " << endl;
 
  773    hdr_mac *mach = HDR_MAC(data_pkt);
 
  774    int dst_addr = mach->macSA();
 
  776    hdr_cmn *ch = hdr_cmn::access(data_pkt);
 
 
  792    map<pktSeqNum, AckTimer>::iterator it_a;
 
  795    ((*it_a).second).stop();
 
  798        cout << NOW << 
" UWAloha (" << addr << 
")::stateRxAck() " << endl;
 
 
  818        cout << NOW << 
" UWAloha (" << addr << 
")::printStateInfo() " 
  824        fout << left << setw(10) << NOW << 
"  UWAloha (" << addr
 
  825             << 
")::printStateInfo() " 
  829             << 
". Backoff duration = " << delay << endl;
 
  831        fout << left << setw(10) << NOW << 
"  UWAloha (" << addr
 
  832             << 
")::printStateInfo() " 
 
  842    std::string response;
 
  843    std::cout << 
"Press Enter to continue";
 
  844    std::getline(std::cin, response);
 
 
Class that describe the binding with tcl scripting language.
 
UWALOHAModuleClass()
Constructor of the class.
 
TclObject * create(int, const char *const *)
 
virtual void expire(Event *e)
What a node is going to do when a timer expire.
 
virtual void unFreeze()
It starts the timer from where it was stopped.
 
double getDuration()
This methods provide the duration of a timer.
 
virtual void stop()
Stop the timer any way.
 
int getCounter()
It provides, how many times a timer ran.
 
virtual void freeze()
It freezes or in another word, it stops the timer for some time.
 
void resetCounter()
Reset the timer counter.
 
UWAloha *UWALOHA_TIMER_STATUS timer_status
< Pointer of UWAloha module.
 
virtual void schedule(double val)
Schedule the time, i.e., how long a timer is going to run.
 
void incrCounter()
Increment the timer counter.
 
bool isActive()
It tells whether the timer is active or not.
 
bool isExpired()
Tells whether the timer is expired or not.
 
bool isFrozen()
It tells whether the timer is in freeze mode or not.
 
This is the base class of UWAloha protocol, which is a derived class of MMac.
 
void putAckTimerInMap(int seq_num)
Put acknowledgement timer in the container.
 
int rttsamples
Number of RTT samples.
 
int txsn
Sequence number of the packet which is transmitted.
 
static map< UWALOHA_STATUS, string > status_info
Container which stores all the status information.
 
double start_tx_time
Time when a packet start transmitting.
 
virtual void waitForUser()
 
static map< UWALOHA_REASON_STATUS, string > reason_info
Container which stores all the reason information.
 
UWALOHA_STATUS prev_prev_state
Enum variable.
 
BackOffTimer backoff_timer
An object of the backoff timer class.
 
void eraseItemFromPktQueue(int seq_num)
It erases the packet from the container.
 
virtual ~UWAloha()
Destructor of UWAloha Class.
 
UWAloha()
Constructor of UWAloha Class.
 
static bool initialized
It checks whether UWAloha protocol is initialized or not.
 
virtual void stateTxData()
If a node has packet to transmits.
 
int max_payload
Maximum number of payload in a packet.
 
int last_sent_data_id
sequence number of the last sent packet
 
virtual void txData()
This method transmits Data packets from MAC layer to PHY layer.
 
virtual void Phy2MacStartRx(const Packet *p)
PHY layer informs the MAC layer that it is receiving a packet.
 
virtual void stateRxData(Packet *p)
It process the packet which is received.
 
virtual void stateRxAck(Packet *p)
The node comes to this state if it receives an ACK packet.
 
UWALOHA_PKT_TYPE
Enumeration class of UWAloha packet type.
 
bool print_transitions
Whether to print the state of the nodes.
 
int buffer_pkts
Number of packets a node can store in the container.
 
double srtt
Smoothed Round Trip Time, calculated as for TCP.
 
virtual void stateWaitAck()
After transmitting a Data packet, a node waits for the ACK packet.
 
UWALOHA_STATUS prev_state
Enum variable.
 
virtual void stateCheckAckExpired()
It checks whether the ack timer is already expired while it was busy with other activities.
 
double ACK_timeout
ACK timeout for the initial packet.
 
double backoff_tuner
Tunes the backoff duration.
 
virtual void stateIdle()
Node is in Idle state.
 
int getUpLayersDataPktsRx()
 
virtual void resetCurrTxRounds()
If a node is going to transmit a new packet, it resets the tx counter.
 
virtual void updateRTT(double rtt)
Update the Round Trip Time (RTT) which is necessary to compute the acknowledgement duration as well a...
 
@ UWALOHA_REASON_BACKOFF_PENDING
 
@ UWALOHA_REASON_DATA_PENDING
 
@ UWALOHA_REASON_DATA_EMPTY
 
@ UWALOHA_REASON_WAIT_ACK_PENDING
 
@ UWALOHA_REASON_START_RX
 
@ UWALOHA_REASON_BACKOFF_TIMEOUT
 
@ UWALOHA_REASON_MAX_TX_TRIES
 
@ UWALOHA_REASON_ACK_TIMEOUT
 
@ UWALOHA_REASON_PKT_ERROR
 
@ UWALOHA_REASON_PKT_NOT_FOR_ME
 
virtual void initInfo()
This function is used to initialize the UWAloha protocol.
 
virtual double computeTxTime(UWALOHA_PKT_TYPE type)
Compute the transmission time of a packet.
 
int curr_tx_rounds
How many times a packet is transmitted.
 
virtual void stateCheckBackoffExpired()
It checks whether the backoff timer is already expired while it was busy with other activities.
 
virtual void stateRxIdle()
If a node start receiving a packet in Idle state.
 
UWALOHA_STATUS curr_state
Enum variable.
 
@ UWALOHA_STATE_CHK_ACK_TIMEOUT
 
@ UWALOHA_STATE_RX_BACKOFF
 
@ UWALOHA_STATE_RX_WAIT_ACK
 
@ UWALOHA_STATE_CHK_BACKOFF_TIMEOUT
 
@ UWALOHA_STATE_WRONG_PKT_RX
 
double sumrtt
Sum of RTT samples.
 
virtual void Phy2MacEndTx(const Packet *p)
It infroms that a packet transmission end.
 
int getPktSeqNum(Packet *p)
This method is used to get the sequence number from a packet.
 
virtual void stateRxBackoff()
If a node start receiving a packet when it is in backoff state.
 
virtual void exitBackoff()
It stops the backoff timer.
 
int last_data_id_rx
The sequence number of last received packet.
 
int max_backoff_counter
Maximum number of backoff it will consider while it increases the backoff exponentially.
 
virtual void Phy2MacEndRx(Packet *p)
PHY layer informs the MAC layer that the reception of the packet is over.
 
static const double prop_speed
Speed of the sound signal.
 
bool has_buffer_queue
Whether the node has buffer to store data or not.
 
virtual double getBackoffTime()
This function calculates the backoff duration and return the backoff time.It employs the exponential ...
 
virtual void incrCurrTxRounds()
Increments the current transmission round of a packet.
 
void putPktInQueue(Packet *p)
A node receives packet(s) from upper layer and store them in the container.
 
AckTimer ack_timer
An object of the AckTimer class.
 
virtual void Mac2PhyStartTx(Packet *p)
It informs that a packet transmission started.
 
map< pktSeqNum, AckTimer > mapAckTimer
Container where acknowledgement timer(s) is stored.
 
UWALOHA_ACK_MODES ack_mode
Enum variable.
 
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
 
int max_tx_tries
Maximum number of transmissions for one packet.
 
static map< UWALOHA_PKT_TYPE, string > pkt_type_info
Container which stores all the packet type information of UWAloha.
 
UWALOHA_REASON_STATUS last_reason
Enum variable which stores the last reason why a node changes its state.
 
virtual void stateBackoff()
If ACK packet is not received within the acknowledgement expire time.
 
virtual void initPkt(Packet *p, UWALOHA_PKT_TYPE pkt_type, int dest_addr=0)
This method, initialize the packet.
 
void eraseItemFrommapAckTimer(int seq_num)
Erase an item from acknowledgement stored container.
 
int ACK_size
Size of the ACK, if the node uses ARQ technique.
 
double sumrtt2
Sum of (RTT^2)
 
virtual void stateRxWaitAck()
If a node receives any packet while it was waiting for ACK packet, it moves to this state.
 
int recv_data_id
The sequence number of the packet which is received.
 
double wait_constant
This fixed time is used to componsate different time variations.
 
map< pktSeqNum, Packet * > mapPacket
Container where Data packets are stored.
 
virtual void incrUpperDataRx()
Increment the number of Data packet receive for the upper layer.
 
virtual void refreshState(UWALOHA_STATUS state)
Refreshes the states of the node.
 
int uwaloha_debug
Debuging Flag.
 
virtual void recvFromUpperLayers(Packet *p)
This function receives the packet from upper layer and save it in the queue.
 
ofstream fout
An object of ofstream class.
 
virtual void stateTxAck(int dest_addr)
If the protocl uses ARQ technique, in that case, after receiving a Data packet the node sends an ACK ...
 
virtual void updateAckTimeout(double rtt)
Like updateRTT() function.
 
virtual void printStateInfo(double delay=0)
This methods print the state information of the nodes.
 
virtual void refreshReason(UWALOHA_REASON_STATUS reason)
To know the reason why a node is in this current state.
 
double alpha_
This variable is used to tune the RTT.
 
Packet * curr_data_pkt
Pointer of the latest selected data packet.
 
int HDR_size
Size of the HDR if any.
 
virtual void txAck(int dest_addr)
This methods transmits ACK packet from MAC layer to PHY layer.
 
@ SESSION_DISTANCE_NOT_SET
 
UWALOHAModuleClass class_module_uwaloha
 
Your can find the brief description of this protocol in the paper, named "On ARQ Strategies over Rand...
 
#define UWALOHA_DROP_REASON_ERROR
 
#define UWALOHA_DROP_REASON_BUFFER_FULL
 
#define UWALOHA_DROP_REASON_WRONG_RECEIVER
 
std::pair< int, int > counter
counter of collisions