DESERT 3.5.1
Loading...
Searching...
No Matches
uwsr.h
Go to the documentation of this file.
1//
2// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova.
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions
7// are met:
8// 1. Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// 2. Redistributions in binary form must reproduce the above copyright
11// notice, this list of conditions and the following disclaimer in the
12// documentation and/or other materials provided with the distribution.
13// 3. Neither the name of the University of Padova (SIGNET lab) nor the
14// names of its contributors may be used to endorse or promote products
15// derived from this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28//
29
49#ifndef UWSR_H
50#define UWSR_H
51
52#include <mac.h>
53#include <mmac.h>
54#include <iostream>
55#include <string>
56#include <map>
57#include <set>
58#include <utility>
59#include <fstream>
60
61#include <mphy.h>
62
63#define UWSR_DROP_REASON_WRONG_STATE "WST"
64#define UWSR_DROP_REASON_WRONG_RECEIVER "WRCV"
65#define UWSR_DROP_REASON_UNKNOWN_TYPE "UPT"
66#define UWSR_DROP_REASON_BUFFER_FULL "DBF"
67#define UWSR_DROP_REASON_ERROR "ERR"
68
69extern packet_t PT_MMAC_ACK;
70
71typedef int pktSeqNum;
72typedef double txStartTime;
73typedef int macAddress;
74typedef int txRounds;
75typedef pair<macAddress, pktSeqNum> usrPair;
76typedef pair<double, double> rttPair;
77typedef pair<int, int> txStatusPair;
78
84class MMacUWSR : public MMac
85{
86
87public:
91 MMacUWSR();
92
96 virtual ~MMacUWSR();
97
106 virtual int command(int argc, const char *const *argv);
107
108protected:
137
165
171
182
188
193 class UWSRTimer : public TimerHandler
194 {
195
196 public:
201 : TimerHandler()
202 , start_time(0.0)
203 , left_duration(0.0)
204 , counter(0)
205 , module(m)
207 {
208 assert(m != NULL);
209 }
210
214 virtual ~UWSRTimer()
215 {
216 }
217
224 virtual void
226 {
227 assert(timer_status == UWSR_RUNNING);
228 left_duration -= (NOW - start_time);
229 if (left_duration <= 0.0)
230 left_duration = module->mac2phy_delay_;
231 force_cancel();
233 }
234
239 virtual void
241 {
242 assert(timer_status == UWSR_FROZEN);
243 start_time = NOW;
244 assert(left_duration > 0);
245 sched(left_duration);
247 }
248
252 virtual void
254 {
256 force_cancel();
257 }
258
263 virtual void
264 schedule(double val)
265 {
266 start_time = NOW;
267 left_duration = val;
269 resched(val);
270 }
271
276 bool
278 {
279 return (timer_status == UWSR_IDLE);
280 }
281
286 bool
288 {
289 return (timer_status == UWSR_RUNNING);
290 }
291
296 bool
298 {
299 return (timer_status == UWSR_EXPIRED);
300 }
301
306 bool
308 {
309 return (timer_status == UWSR_FROZEN);
310 }
311
316 bool
318 {
319 return (timer_status == UWSR_FROZEN ||
321 }
322
326 void
328 {
329 counter = 0;
330 }
331
336 void
338 {
339 ++counter;
340 }
341
346 int
348 {
349 return counter;
350 }
351
356 double
358 {
359 return left_duration;
360 }
361
366 double
368 {
369 return NOW - start_time;
370 }
371
372 protected:
373 double start_time;
379 MMacUWSR *module;
382 };
383
387 class BackOffTimer : public UWSRTimer
388 {
389
390 public:
395 : UWSRTimer(m)
396 {
397 }
398
403 {
404 }
405
406 protected:
411 virtual void expire(Event *e);
412 };
413
417 class AckTimer : public UWSRTimer
418 {
419
420 public:
425 : UWSRTimer(m)
426 {
427 }
428
432 virtual ~AckTimer()
433 {
434 }
435
436 protected:
441 virtual void expire(Event *e);
442 };
443
447 class ListenTimer : public UWSRTimer
448 {
449
450 public:
455 : UWSRTimer(m)
456 {
457 }
458
462 virtual ~ListenTimer()
463 {
464 }
465
466 protected:
471 virtual void expire(Event *e);
472 };
473
477 class WaitTxTimer : public UWSRTimer
478 {
479
480 public:
485 : UWSRTimer(m)
486 {
487 }
488
492 virtual ~WaitTxTimer()
493 {
494 }
495
496 protected:
501 virtual void expire(Event *e);
502 };
503
509 virtual void recvFromUpperLayers(Packet *p);
510
515 virtual void Mac2PhyStartTx(Packet *p);
516
521 virtual void Phy2MacEndTx(const Packet *p);
522
527 virtual void Phy2MacStartRx(const Packet *p);
528
533 virtual void Phy2MacEndRx(Packet *p);
534
541 virtual double computeTxTime(UWSR_PKT_TYPE type);
542
553 virtual void initPkt(Packet *p, UWSR_PKT_TYPE pkt_type, int dest_addr = 0);
554
560 virtual double getBackoffTime();
561
565 inline void
567 {
569 }
570
576 inline int
578 {
579 return backoff_count;
580 }
581
586 virtual void statePreTxData();
587
592 virtual void txAck(int dest_addr);
593
598 virtual void stateIdle();
599
603 virtual void stateRxIdle();
604
609 virtual void stateTxData();
610
614 virtual void stateTxAck(int dest_addr);
615
620 virtual void stateBackoff();
621
627 virtual void stateRxBackoff();
628
633 virtual void stateWaitAck();
634
639 virtual void stateRxinPreTxData();
640
647 virtual void stateRxWaitAck();
648
652 virtual void stateListen();
653
657 virtual void stateRxListen();
658
663 virtual void stateCheckListenExpired();
664
669 virtual void stateCheckAckExpired();
670
675 virtual void stateCheckBackoffExpired();
676
681 virtual void stateCheckWaitTxExpired();
682
688 virtual void stateRxData(Packet *p);
689
695 virtual void stateRxAck(Packet *p);
696
702 virtual void stateRxPacketNotForMe(Packet *p);
703
708 virtual void printStateInfo(double delay = 0);
709
713 virtual void initInfo();
714
721 virtual void
728
733 virtual void
735 {
736 last_reason = reason;
737 }
738
742 virtual void exitBackoff();
743
748 virtual double
750 {
751 return (rttsamples > 0) ? sumrtt / rttsamples : 0;
752 }
753
758 virtual void
760 {
761 last_data_id_rx = id;
762 }
763 virtual void waitForUser();
764
765 // stats functions
771 virtual int
773 {
774 return (up_data_pkts_rx - mapPacket.size());
775 }
776
780 virtual void
782 {
783 up_data_pkts_rx++;
784 }
785
791 virtual int
792 getPktSeqNum(Packet *p)
793 {
794 hdr_cmn *ch = hdr_cmn::access(p);
795 return ch->uid();
796 }
797
804 virtual int
805 getMacAddress(Packet *p)
806 {
807 hdr_mac *mach = HDR_MAC(p);
808 return mach->macDA();
809 }
810
812
819 inline bool chkItemInmapTxRounds(int mac_addr, int seq_num);
820
826 inline void
827 setCurrTxRounds(int mac_addr, int seq_num)
828 {
829 curr_tx_rounds = 1;
830 mapTxRounds.insert(
831 make_pair(make_pair(mac_addr, seq_num), curr_tx_rounds));
832 }
833
839 inline void
840 incrCurrTxRounds(int mac_addr, int seq_num)
841 {
842 map<usrPair, txRounds>::iterator it_t;
843 it_t = mapTxRounds.find(make_pair(mac_addr, seq_num));
844 (*it_t).second += 1;
845 }
846
853 inline int
854 getCurrTxRounds(int mac_addr, int seq_num)
855 {
856 map<usrPair, txRounds>::iterator it_t;
857 it_t = mapTxRounds.find(make_pair(mac_addr, seq_num));
858 return ((*it_t).second);
859 }
860
867 inline void
868 eraseItemFromTxRounds(int mac_addr, int seq_num)
869 {
870 map<usrPair, txRounds>::iterator it_t;
871 it_t = mapTxRounds.find(make_pair(mac_addr, seq_num));
872 mapTxRounds.erase((*it_t).first);
873 }
874
876
880 inline void
881 putPktInQueue(Packet *p)
882 {
883 mapPacket.insert(
884 make_pair(make_pair(getMacAddress(p), getPktSeqNum(p)), p));
885 }
886
891 inline void
892 eraseItemFromPktQueue(int mac_addr, int seq_num)
893 {
894 map<usrPair, Packet *>::iterator it_p;
895 it_p = mapPacket.find(make_pair(mac_addr, seq_num));
896 Packet::free((*it_p).second);
897 mapPacket.erase((*it_p).first);
898 }
899
901
907 inline void
908 putAckTimerInMap(int mac_addr, int seq_num)
909 {
910 mapAckTimer.insert(make_pair(make_pair(mac_addr, seq_num), ack_timer));
911 }
912
919 inline void
920 eraseItemFrommapAckTimer(int mac_addr, int seq_num)
921 {
922 map<usrPair, AckTimer>::iterator it_a;
923 it_a = mapAckTimer.find(make_pair(mac_addr, seq_num));
924 mapAckTimer.erase((*it_a).first);
925 }
926
932 inline void
933 putStartTxTimeInMap(int mac_addr, int seq_num, double start_tx_time)
934 {
935 mapCalcAck.insert(
936 make_pair(make_pair(mac_addr, seq_num), start_tx_time));
937 }
938
945 inline void
946 eraseItemFrommapCalcAck(int mac_addr, int seq_num)
947 {
948 map<usrPair, txStartTime>::iterator it_ca;
949 it_ca = mapCalcAck.find(make_pair(mac_addr, seq_num));
950 mapCalcAck.erase((*it_ca).first);
951 }
952
960 virtual int checkAckTimer(CHECK_ACK_TIMER type);
961
967
975 virtual bool checkMultipleTx(int rcv_mac_addr);
976
983 virtual int getPktsCanSendIn1RTT(int mac_addr);
984
992 virtual void putRTTInMap(int mac_addr, double rtt);
993
999 inline double
1000 getRTTInMap(int mac_addr)
1001 {
1002 map<macAddress, rttPair>::iterator it_d;
1003 it_d = mapRTT.find(mac_addr);
1004 return (it_d->second).first;
1005 }
1006
1010 inline void
1012 {
1014 }
1015
1019 inline void
1021 {
1022 pkts_sent_1RTT = 0;
1023 }
1024
1029 inline int
1031 {
1032 return pkts_sent_1RTT;
1033 }
1034
1039 inline void
1041 {
1042 acks_rcv_1RTT++;
1043 }
1044
1048 inline void
1050 {
1051 acks_rcv_1RTT = 0;
1052 }
1053
1058 inline int
1060 {
1061 return acks_rcv_1RTT;
1062 }
1063
1067 inline void
1069 {
1071 }
1072
1076 inline void
1078 {
1080 }
1081
1086 inline int
1088 {
1089 return pkts_lost_counter;
1090 }
1091
1101 virtual bool prepBeforeTx(int mac_addr, int seq_num);
1102
1109 virtual double calcWaitTxTime(int mac_addr);
1110
1119 inline void updateTxStatus(macAddress mac_addr, int rcv_acks);
1120
1126 virtual int calWindowSize(macAddress mac_addr);
1127
1131 inline void
1137
1141 inline double
1143 {
1144 double x = (double) total_pkts_tx / (double) hit_count;
1145 return x;
1146 }
1147
1158 double alpha_;
1163 double guard_time;
1165 double node_speed;
1166 double var_k;
1169
1170 static bool initialized;
1174 static const double prop_speed;
1178 bool
1183 double srtt;
1184 double sumrtt;
1185 double sumrtt2;
1202 double sumwtt;
1206 int
1213 int txsn;
1215 double
1220 int
1241 static map<UWSR_STATUS, string>
1244 static map<UWSR_REASON_STATUS, string>
1247 static map<UWSR_PKT_TYPE, string>
1251 map<usrPair, Packet *>
1253 map<usrPair, txRounds> mapTxRounds;
1256 map<usrPair, AckTimer> mapAckTimer;
1258 map<usrPair, txStartTime> mapCalcAck;
1261 map<macAddress, rttPair> mapRTT;
1263 map<macAddress, txStatusPair> mapTxStatus;
1268 ofstream fout;
1269};
1270
1271#endif /* UWSR_H */
Base class of AckTimer, which is a derived class of UWSRTimer.
Definition uwsr.h:418
AckTimer(MMacUWSR *m)
Constructor of AckTimer Class.
Definition uwsr.h:424
virtual ~AckTimer()
Destructor of AckTimer Class.
Definition uwsr.h:432
virtual void expire(Event *e)
What a node is going to do when a timer expire.
Definition uwsr.cpp:70
Base class of BackoffTimer.
Definition uwsr.h:388
virtual void expire(Event *e)
What a node is going to do when a timer expire.
Definition uwsr.cpp:97
virtual ~BackOffTimer()
Destructor of BackOffTimer.
Definition uwsr.h:402
BackOffTimer(MMacUWSR *m)
Constructor of BackOffTimer Class.
Definition uwsr.h:394
Base class of ListenTimer, which is a derived class of UWSRTimer.
Definition uwsr.h:448
ListenTimer(MMacUWSR *m)
Constructor of ListenTimer class.
Definition uwsr.h:454
virtual void expire(Event *e)
What a node is going to do when a timer expire.
Definition uwsr.cpp:120
virtual ~ListenTimer()
Destructor of ListenTimer class.
Definition uwsr.h:462
Base class of all the timer used in this protocol.
Definition uwsr.h:194
int counter
How many times a timer ran.
Definition uwsr.h:377
UWSRTimer(MMacUWSR *m)
Constructor of UWSRTimer Class.
Definition uwsr.h:200
virtual void stop()
Stop the timer any way.
Definition uwsr.h:253
MMacUWSR *UWSR_TIMER_STATUS timer_status
< Pointer of MMacUWSR module.
Definition uwsr.h:381
void resetCounter()
Reset the timer counter.
Definition uwsr.h:327
bool isIdle()
It tells whether the timer is in Idle state or not.
Definition uwsr.h:277
bool isRunning()
This method tells whether the timer is in Running state or not.
Definition uwsr.h:287
double leftDuration()
This methods provide the remaining duration of a timer.
Definition uwsr.h:367
virtual ~UWSRTimer()
Destructor of UWSRTimer Class.
Definition uwsr.h:214
virtual void unFreeze()
It starts the timer from where it was stopped.
Definition uwsr.h:240
bool isFrozen()
It tells whether the timer is in freeze mode or not.
Definition uwsr.h:307
double start_time
Start time of a timer.
Definition uwsr.h:373
void incrCounter()
Increment the timer counter.
Definition uwsr.h:337
virtual void schedule(double val)
Schedule the time, i.e., how long a timer is going to run.
Definition uwsr.h:264
virtual void freeze()
It freezes or in another word, it stops the timer for some time.
Definition uwsr.h:225
double left_duration
How long a timer is going to run more.
Definition uwsr.h:375
double getDuration()
This methods provide the duration of a timer.
Definition uwsr.h:357
int getCounter()
It provides, how many times a timer ran.
Definition uwsr.h:347
bool isActive()
It tells whether the timer is active or not.
Definition uwsr.h:317
bool isExpired()
Tells whether the timer is expired or not.
Definition uwsr.h:297
Base class of WaitTxTimer, which is a derived class of UWSRTimer.
Definition uwsr.h:478
virtual ~WaitTxTimer()
Destructor of WaitTxTimer class.
Definition uwsr.h:492
virtual void expire(Event *e)
What a node is going to do when a timer expire.
Definition uwsr.cpp:143
WaitTxTimer(MMacUWSR *m)
Constructor of WaitTxTimer class.
Definition uwsr.h:484
This is the base class of MMacUWSR protocol, which is a derived class of MMac.
Definition uwsr.h:85
static bool initialized
It checks whether MMacUWSR protocol is initialized or not.
Definition uwsr.h:1170
virtual void refreshState(UWSR_STATUS state)
Refreshes the states of the node.
Definition uwsr.h:722
void eraseItemFromPktQueue(int mac_addr, int seq_num)
Erase the packet which is delivered to the destination correctly or other reasons.
Definition uwsr.h:892
int rttsamples
Number of RTT samples.
Definition uwsr.h:1186
double wait_constant
This fixed time is employed to componsate different time variations.
Definition uwsr.h:1151
double ACK_timeout
ACK timeout for the initial packet.
Definition uwsr.h:1156
virtual void printStateInfo(double delay=0)
This methods print the state information of the nodes.
Definition uwsr.cpp:1584
virtual void stateCheckWaitTxExpired()
It checks whether the wait transmit timer is already expired while it was busy with other activities.
Definition uwsr.cpp:1161
void setBackoffCount()
It sets the number of times backoff cpounter is run.
Definition uwsr.h:566
AckTimer ack_timer
An object of the AckTimer class.
Definition uwsr.h:1225
double var_k
It is employed to decrease the window size.
Definition uwsr.h:1166
int ACK_size
Size of the ACK.
Definition uwsr.h:1155
void putPktInQueue(Packet *p)
handling packets
Definition uwsr.h:881
UWSR_TIMER_STATUS
Enumeration class of MMacUWSR timer status.
Definition uwsr.h:176
@ UWSR_FROZEN
Definition uwsr.h:179
@ UWSR_EXPIRED
Definition uwsr.h:180
@ UWSR_IDLE
Definition uwsr.h:177
@ UWSR_RUNNING
Definition uwsr.h:178
int getBackoffCount()
It returns the number of time backoff counter is run in the whole communication period.
Definition uwsr.h:577
double sumwtt
Summation of total waiting time.
Definition uwsr.h:1202
virtual void updateLastDataIdRx(int id)
It updates the sequence number of the last data packet rx.
Definition uwsr.h:759
void updateTxStatus(macAddress mac_addr, int rcv_acks)
How many acknowledgements receive for the transmitting packets in a single RTT.
Definition uwsr.cpp:344
virtual bool checkMultipleTx(int rcv_mac_addr)
This method checks whether the node is capable of sending multiple packets in a single RTT.
Definition uwsr.cpp:495
bool print_transitions
Whether to print the state of the nodes.
Definition uwsr.h:1177
map< macAddress, txStatusPair > mapTxStatus
Container which stores the number of packets transmitted in a single RTT to a receiving node and numb...
Definition uwsr.h:1263
virtual void stateTxData()
If a node has packet to transmits.
Definition uwsr.cpp:997
void putAckTimerInMap(int mac_addr, int seq_num)
managing ack
Definition uwsr.h:908
virtual void stateListen()
A short time which is used to sense the channel condision.
Definition uwsr.cpp:1257
int total_pkts_tx
Total number of packets transmit.
Definition uwsr.h:1223
void putStartTxTimeInMap(int mac_addr, int seq_num, double start_tx_time)
It stores the initial transmission start time in a container.
Definition uwsr.h:933
virtual void waitForUser()
Definition uwsr.cpp:1609
int pkts_sent_1RTT
Packets already sent in single RTT.
Definition uwsr.h:1205
UWSR_STATUS prev_prev_state
Enum variable.
Definition uwsr.h:1238
int hit_count
This is a counter which is employed to calculate average number of packets transmit in a sigle RTT.
Definition uwsr.h:1221
UWSR_STATUS curr_state
Enum variable.
Definition uwsr.h:1233
ListenTimer listen_timer
An object of the ListenTimer class.
Definition uwsr.h:1227
void incrPktsLostCount()
Increments the number of packets lost in a single RTT.
Definition uwsr.h:1068
virtual int checkAckTimer(CHECK_ACK_TIMER type)
It checks whether any acknowledgement timer expire.
Definition uwsr.cpp:541
void incrPktsSentIn1RTT()
Increments the number of Data packets sent in single RTT.
Definition uwsr.h:1011
map< macAddress, rttPair > mapRTT
Container where RTT between various sender-receiver pairs are stored.
Definition uwsr.h:1261
int txsn
Sequence number of the transmitted packet.
Definition uwsr.h:1213
virtual void eraseExpiredItemsFrommapAckandCalc()
Erases those items whose acknowledgement timer expire from AckTimer containter and also from start tr...
Definition uwsr.cpp:606
virtual void initPkt(Packet *p, UWSR_PKT_TYPE pkt_type, int dest_addr=0)
This method, initialize the packet.
Definition uwsr.cpp:713
WaitTxTimer wait_tx_timer
An object of the WaitTxTimer class.
Definition uwsr.h:1228
int backoff_count
This variable counts how many times a node move to the backoff state.
Definition uwsr.h:1193
int getCurrTxRounds(int mac_addr, int seq_num)
Returns the current transmission round of a Data packet.
Definition uwsr.h:854
virtual double calcWaitTxTime(int mac_addr)
Calcultes the time a node has to wait before transmitting another packet in a single RTT.
Definition uwsr.cpp:459
MMacUWSR()
Constructor of MMacUWSR Class.
Definition uwsr.cpp:173
virtual void incrUpperDataRx()
Increment the number of Data packet receive for the upper layer.
Definition uwsr.h:781
map< usrPair, txRounds > mapTxRounds
Container where retransmission information of various packets are stored.
Definition uwsr.h:1253
CHECK_ACK_TIMER
This enumeration class is employed to know the current acknowledgement timer status.
Definition uwsr.h:187
@ CHECK_IDLE
Definition uwsr.h:187
@ CHECK_ACTIVE
Definition uwsr.h:187
@ CHECK_EXPIRED
Definition uwsr.h:187
int uwsr_debug
Debuging flag.
Definition uwsr.h:1167
virtual void Mac2PhyStartTx(Packet *p)
It informs that a packet transmission started.
Definition uwsr.cpp:738
double node_speed
Speed of the mobile node [m/s].
Definition uwsr.h:1165
virtual int getPktSeqNum(Packet *p)
This method is used to get the sequence number from a packet.
Definition uwsr.h:792
bool chkItemInmapTxRounds(int mac_addr, int seq_num)
handling transmission round
Definition uwsr.cpp:445
int prv_mac_addr
Previous mac address.
Definition uwsr.h:1218
void incrAcksRcvIn1RTT()
Increments the number of ACK packets receive by a node in single RTT.
Definition uwsr.h:1040
virtual void stateRxPacketNotForMe(Packet *p)
The receive packet is not intended for this node.
Definition uwsr.cpp:1030
virtual int getPktsCanSendIn1RTT(int mac_addr)
Number of packets a node can transmits to a receiving node in a single RTT.
Definition uwsr.cpp:406
virtual void stateTxAck(int dest_addr)
After receiving a Data packet the node sends an ACK packet.
Definition uwsr.cpp:1478
double srtt
Smoothed Round Trip Time, calculated as for TCP.
Definition uwsr.h:1183
virtual int getRemainingPkts()
Number of packets which MAC layer receives form upper layer(s) but were not transmitted.
Definition uwsr.h:772
virtual bool prepBeforeTx(int mac_addr, int seq_num)
It checks how many times a packet is transmitted.
Definition uwsr.cpp:1323
double guard_time
A time which is used to componsate variating in timing.
Definition uwsr.h:1163
virtual void recvFromUpperLayers(Packet *p)
This function receives the packet from upper layer and save it in the queue.
Definition uwsr.cpp:693
void calTotalPktsTx()
Total number of packets transmitted by a node.
Definition uwsr.h:1132
double max_backoff_counter
Maximum number of backoff it will consider while it increases the backoff exponentially.
Definition uwsr.h:1159
int last_data_id_rx
The sequence number of last received packet.
Definition uwsr.h:1190
map< usrPair, txStartTime > mapCalcAck
Container where starting transmission time of various packets are stored.
Definition uwsr.h:1258
virtual void stateIdle()
Node is in Idle state.
Definition uwsr.cpp:1222
double latest_ack_timeout
Latest timeout of an acknowledgement packet.
Definition uwsr.h:1216
double getAvgPktsTxIn1RTT()
Average number of packets transmitted in a single RTT.
Definition uwsr.h:1142
virtual void initInfo()
This function is used to initialize the UWAloha protocol.
Definition uwsr.cpp:282
void rstPktsSentIn1RTT()
Resets the number of Data packets sent in single RTT.
Definition uwsr.h:1020
int curr_tx_rounds
How many times the same packet is (re)transmitted.
Definition uwsr.h:1188
virtual double getRTT()
This method is used to get the average RTT over all the receives RTT.
Definition uwsr.h:749
UWSR_PKT_TYPE
Enumeration class of packet type.
Definition uwsr.h:170
@ UWSR_DATAMAX_PKT
Definition uwsr.h:170
@ UWSR_ACK_PKT
Definition uwsr.h:170
@ UWSR_DATA_PKT
Definition uwsr.h:170
ofstream fout
An object of ofstream class.
Definition uwsr.h:1268
virtual void stateRxIdle()
If a node starts receiving a packet in Idle state.
Definition uwsr.cpp:1248
virtual int calWindowSize(macAddress mac_addr)
Number of packets a node can transmits to a receving node in a single RTT.
Definition uwsr.cpp:361
virtual double computeTxTime(UWSR_PKT_TYPE type)
Compute the transmission time of a packet.
Definition uwsr.cpp:634
virtual void stateCheckAckExpired()
It checks whether the ack timer is already expired while it was busy with other activities.
Definition uwsr.cpp:1106
static const double prop_speed
Speed of the sound signal.
Definition uwsr.h:1174
virtual void Phy2MacStartRx(const Packet *p)
PHY layer informs the MAC layer that it is receiving a packet.
Definition uwsr.cpp:896
void eraseItemFrommapAckTimer(int mac_addr, int seq_num)
If a node receives an ACK for its transmitted packet, it erases the related AckTimer object of that p...
Definition uwsr.h:920
UWSR_REASON_STATUS
Enumeration class which tells the nodes the reason why it is in this state.
Definition uwsr.h:142
@ UWSR_REASON_ACK_RX
Definition uwsr.h:147
@ UWSR_REASON_DATA_PENDING
Definition uwsr.h:143
@ UWSR_REASON_WAIT_TX
Definition uwsr.h:161
@ UWSR_REASON_LISTEN_TIMEOUT
Definition uwsr.h:155
@ UWSR_REASON_DATA_TX
Definition uwsr.h:145
@ UWSR_REASON_DATA_RX
Definition uwsr.h:144
@ UWSR_REASON_ACK_TIMEOUT
Definition uwsr.h:149
@ UWSR_REASON_ACK_TX
Definition uwsr.h:146
@ UWSR_REASON_BACKOFF_PENDING
Definition uwsr.h:153
@ UWSR_REASON_DATA_EMPTY
Definition uwsr.h:150
@ UWSR_REASON_WAIT_ACK_PENDING
Definition uwsr.h:159
@ UWSR_REASON_LISTEN_PENDING
Definition uwsr.h:156
@ UWSR_REASON_BACKOFF_TIMEOUT
Definition uwsr.h:148
@ UWSR_REASON_MAX_TX_TRIES
Definition uwsr.h:152
@ UWSR_REASON_LISTEN
Definition uwsr.h:154
@ UWSR_REASON_WAIT_TX_TIMEOUT
Definition uwsr.h:163
@ UWSR_REASON_PKT_ERROR
Definition uwsr.h:160
@ UWSR_REASON_NOT_SET
Definition uwsr.h:151
@ UWSR_REASON_PKT_NOT_FOR_ME
Definition uwsr.h:158
@ UWSR_REASON_START_RX
Definition uwsr.h:157
@ UWSR_REASON_WAIT_TX_PENDING
Definition uwsr.h:162
void rstPktsLostCount()
Resets the number of packets lost in single RTT.
Definition uwsr.h:1077
double backoff_tuner
Tunes the backoff duration.
Definition uwsr.h:1150
virtual ~MMacUWSR()
Destructor of MMacUWSR Class.
Definition uwsr.cpp:239
int max_tx_tries
Maximum number of retransmissions attempt.
Definition uwsr.h:1149
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
Definition uwsr.cpp:245
virtual void stateRxinPreTxData()
If a node starts receiving a packet when it was waiting for transmitting another packet in a singlet ...
Definition uwsr.cpp:1469
UWSR_STATUS
Enumeration class of MMacUWSR status.
Definition uwsr.h:112
@ UWSR_STATE_RX_BACKOFF
Definition uwsr.h:127
@ UWSR_STATE_NOT_SET
Definition uwsr.h:120
@ UWSR_STATE_CHK_LISTEN_TIMEOUT
Definition uwsr.h:123
@ UWSR_STATE_IDLE
Definition uwsr.h:113
@ UWSR_STATE_TX_DATA
Definition uwsr.h:115
@ UWSR_STATE_CHK_WAIT_TX_TIMEOUT
Definition uwsr.h:131
@ UWSR_STATE_ACK_RX
Definition uwsr.h:119
@ UWSR_STATE_RX_IN_PRE_TX_DATA
Definition uwsr.h:135
@ UWSR_STATE_TX_ACK
Definition uwsr.h:116
@ UWSR_STATE_PRE_TX_DATA
Definition uwsr.h:134
@ UWSR_STATE_RX_IDLE
Definition uwsr.h:125
@ UWSR_STATE_CHK_ACK_TIMEOUT
Definition uwsr.h:122
@ UWSR_STATE_RX_DATA_TX_DATA
Definition uwsr.h:133
@ UWSR_STATE_CHK_BACKOFF_TIMEOUT
Definition uwsr.h:124
@ UWSR_STATE_RX_LISTEN
Definition uwsr.h:126
@ UWSR_STATE_LISTEN
Definition uwsr.h:121
@ UWSR_STATE_DATA_RX
Definition uwsr.h:118
@ UWSR_STATE_WRONG_PKT_RX
Definition uwsr.h:129
@ UWSR_STATE_WAIT_TX
Definition uwsr.h:130
@ UWSR_STATE_WAIT_ACK_WAIT_TX
Definition uwsr.h:132
@ UWSR_STATE_BACKOFF
Definition uwsr.h:114
@ UWSR_STATE_RX_WAIT_ACK
Definition uwsr.h:128
@ UWSR_STATE_WAIT_ACK
Definition uwsr.h:117
int max_payload
Maximum number of payload in a packet.
Definition uwsr.h:1153
virtual void stateRxListen()
If a node starts receiving a packet when it was listening the channel.
Definition uwsr.cpp:1278
double wait_tx_time
Waiting time before transmitting a packet in a single RTT.
Definition uwsr.h:1200
virtual void stateBackoff()
If ACK packet is not received within the acknowledgement expire time.
Definition uwsr.cpp:1287
int getAcksRcvIn1RTT()
Returns number of ACK packets receive by a node in single RTT.
Definition uwsr.h:1059
virtual void stateRxData(Packet *p)
It process the packet which is received.
Definition uwsr.cpp:1493
void eraseItemFrommapCalcAck(int mac_addr, int seq_num)
Erases the transmission start time of a packet when an ACK is received correctly.
Definition uwsr.h:946
int pkt_tx_count
Number of packets transmitted.
Definition uwsr.h:1195
int getPktsSentIn1RTT()
Returns number of Data packets transmit in single RTT.
Definition uwsr.h:1030
static map< UWSR_STATUS, string > status_info
Container which stores all the status information.
Definition uwsr.h:1242
UWSR_REASON_STATUS last_reason
Enum variable which stores the last reason why a node changes its state.
Definition uwsr.h:1230
virtual double getBackoffTime()
This function calculates the backoff duration and return the backoff time.It employs the exponential ...
Definition uwsr.cpp:669
double start_tx_time
Time when a packet start transmitting.
Definition uwsr.h:1182
void eraseItemFromTxRounds(int mac_addr, int seq_num)
Erase an Item form the container where transmission round of various transmit packet are stored.
Definition uwsr.h:868
static map< UWSR_PKT_TYPE, string > pkt_type_info
Container which stores all the packet type information of MMacUWSR.
Definition uwsr.h:1248
double getRTTInMap(int mac_addr)
Returns the RTT between a sender-receiver pair.
Definition uwsr.h:1000
double round_trip_time
RTT time.
Definition uwsr.h:1199
virtual void Phy2MacEndTx(const Packet *p)
It infroms that a packet transmission end.
Definition uwsr.cpp:749
virtual void stateRxBackoff()
If a node starts receiving a packet when it is in backoff state.
Definition uwsr.cpp:1313
int recv_data_id
The sequence number of the packet which is received.
Definition uwsr.h:1191
int last_sent_data_id
sequence number of the latest sent packet
Definition uwsr.h:1175
int getPktsLostCount()
Returns number of packets lost in single RTT.
Definition uwsr.h:1087
UWSR_STATUS prev_state
Enum variable.
Definition uwsr.h:1236
Packet * curr_data_pkt
Pointer of the latest selected data packet.
Definition uwsr.h:1197
double listen_time
A short channel sensing time.
Definition uwsr.h:1162
virtual void txAck(int dest_addr)
This methods transmits ACK packet from MAC layer to PHY layer.
Definition uwsr.cpp:1020
int pkts_lost_counter
Number of packets lost in a single RTT.
Definition uwsr.h:1209
virtual int getMacAddress(Packet *p)
This method returns the destination mac address of the node which transmits the packet.
Definition uwsr.h:805
void rstAcksRcvIn1RTT()
Resets the number of ACK packets receive by a node in single RTT.
Definition uwsr.h:1049
virtual void statePreTxData()
This method finds out whether there is any packet to be transmitted to the destination.
Definition uwsr.cpp:1361
void incrCurrTxRounds(int mac_addr, int seq_num)
Increment the number of times a packet is transmitted.
Definition uwsr.h:840
int HDR_size
Size of the HDR if any.
Definition uwsr.h:1154
int buffer_pkts
Number of packets a node can store in the container.
Definition uwsr.h:1157
int wttsamples
Number of waiting time samples.
Definition uwsr.h:1203
double alpha_
This variable is used to tune the RTT.
Definition uwsr.h:1158
static map< UWSR_REASON_STATUS, string > reason_info
Container which stores all the reason information.
Definition uwsr.h:1245
map< usrPair, Packet * > mapPacket
Container where Data packets are stored.
Definition uwsr.h:1252
int window_size
Maximum number of packets a node can transmit in a single RTT.
Definition uwsr.h:1210
virtual void Phy2MacEndRx(Packet *p)
PHY layer informs the MAC layer that the reception of the packet is over.
Definition uwsr.cpp:935
int acks_rcv_1RTT
Number of ACK packets receive in single RTT.
Definition uwsr.h:1207
virtual void exitBackoff()
It stops the backoff timer.
Definition uwsr.cpp:663
BackOffTimer backoff_timer
An object of the BackOffTimer class.
Definition uwsr.h:1226
virtual void stateCheckListenExpired()
It checks whether the listen timer is already expired while it was busy with other activities.
Definition uwsr.cpp:1075
bool has_buffer_queue
Whether the node has buffer to store data or not.
Definition uwsr.h:1179
virtual void stateCheckBackoffExpired()
It checks whether the backoff timer is already expired while it was busy with other activities.
Definition uwsr.cpp:1135
virtual void stateRxAck(Packet *p)
The node comes to this state if it receives an ACK packet.
Definition uwsr.cpp:1513
void setCurrTxRounds(int mac_addr, int seq_num)
It sets the current tranmission round of a packet.
Definition uwsr.h:827
double sumrtt2
Sum of (RTT^2)
Definition uwsr.h:1185
double sumrtt
Sum of RTT samples.
Definition uwsr.h:1184
virtual void putRTTInMap(int mac_addr, double rtt)
Put RTT of all the nodes which are whithin the transmission range of a node.
Definition uwsr.cpp:381
virtual void stateRxWaitAck()
If a node receives any packet while it was waiting for ACK packet, it moves to this state.
Definition uwsr.cpp:1460
virtual void stateWaitAck()
After transmitting a Data packet, a node waits for the ACK packet.
Definition uwsr.cpp:1448
map< usrPair, AckTimer > mapAckTimer
Container where AckTimer objects for variuous packets are stored.
Definition uwsr.h:1256
virtual void refreshReason(UWSR_REASON_STATUS reason)
To know the reason why a node in this current state.
Definition uwsr.h:734
std::pair< int, int > counter
counter of collisions
int pktSeqNum
Definition uwsr.h:71
pair< double, double > rttPair
Definition uwsr.h:76
pair< int, int > txStatusPair
Definition uwsr.h:77
int txRounds
Definition uwsr.h:74
pair< macAddress, pktSeqNum > usrPair
Definition uwsr.h:75
double txStartTime
Definition uwsr.h:72
int macAddress
Definition uwsr.h:73