DESERT 3.5.1
Loading...
Searching...
No Matches
uw-mac-DACAP-alter.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
39#ifndef MMAC_UW_DACAP_H
40#define MMAC_UW_DACAP_H
41
42#include <mmac.h>
43#include <queue>
44#include <string>
45#include <map>
46#include <fstream>
47#include <iostream>
48#include <mphy.h>
49
50#define HDR_DACAP(P) (hdr_dacap::access(P))
51
52#define DACAP_DROP_REASON_WRONG_STATE \
53 "WST"
55#define DACAP_DROP_REASON_WRONG_RECEIVER \
56 "WRCV"
57#define DACAP_DROP_REASON_UNKNOWN_TYPE \
58 "UPT"
59#define DACAP_DROP_REASON_BUFFER_FULL \
60 "DBF"
62extern packet_t PT_DACAP;
63
67typedef struct hdr_dacap {
68
69 double ts;
70 int sn;
72 packet_t orig_type;
73 int data_sn;
77 static int offset_;
81 inline static int &
83 {
84 return offset_;
85 }
90 inline static struct hdr_dacap *
91 access(const Packet *p)
92 {
93 return (struct hdr_dacap *) p->access(offset_);
94 }
95
97
98class MMacDACAP;
99
103class DACAPTimer : public TimerHandler
104{
105
106public:
112 : TimerHandler()
113 {
114 module = m;
115 }
116
117protected:
122 virtual void expire(Event *e);
123 MMacDACAP *module;
125};
129class DACAPBTimer : public TimerHandler
130{
131public:
137 : TimerHandler()
138 {
139 module = m;
140 }
141
142protected:
147 virtual void expire(Event *e);
148 MMacDACAP *module;
150};
151
155class MMacDACAP : public MMac
156{
157 friend class DACAPTimer;
158 friend class DACAPBTimer;
160public:
164 MMacDACAP();
168 virtual ~MMacDACAP();
179 virtual int command(int argc, const char *const *argv);
187 virtual int crLayCommand(ClMessage *m);
188
189protected:
190 /***********************************
191 | Internal variable and functions |
192 ***********************************/
198 virtual void recvFromUpperLayers(Packet *p);
199
205 virtual void Phy2MacEndTx(const Packet *p);
211 virtual void Phy2MacStartRx(const Packet *p);
217 virtual void Phy2MacEndRx(Packet *p);
228 virtual double computeWaitTime(int mode, double distance);
237 virtual double computeTxTime(int type);
245 virtual void initPkt(Packet *p, int pkt_type);
250 virtual double getBackoffTime();
255 virtual double getRecontendTime();
259 virtual void txAck();
264 virtual void txData();
269 virtual void txRts();
273 virtual void txCts();
277 virtual void txWrn();
284 virtual void rxStateIdle(Packet *p);
291 virtual void rxStateBackoff(Packet *p);
298 virtual void rxStateWaitCTS(Packet *p);
305 virtual void rxStateWaitACK(Packet *p);
312 virtual void rxStateWaitData(Packet *p);
319 virtual void rxStateWaitXCts(Packet *p);
326 virtual void rxStateWaitXData(Packet *p);
333 virtual void rxStateWaitXAck(Packet *p);
341 virtual void rxStateWaitXWarning(Packet *p);
349 virtual void rxStateWaitWarning(Packet *p);
357 virtual void rxStateSendWarning(Packet *p);
365 virtual void rxStateRecontendWindow(Packet *p);
369 virtual void stateIdle();
374 virtual void stateSendRTS();
380 virtual void stateBackoff();
386 virtual void stateWaitCTS();
393 virtual void stateDeferData();
398 virtual void stateSendData();
402 virtual void stateWaitACK();
406 virtual void stateCTSReceived();
412 virtual void stateWaitData();
417 virtual void stateDataReceived(Packet *data_pkt);
425 virtual void stateWaitXCts();
433 virtual void stateWaitXData();
442 virtual void stateWaitXAck();
448 virtual void stateWaitXWarning();
454 virtual void stateSendAck();
459 virtual void stateSendCTS();
466 virtual void stateWaitWarning();
474 virtual void stateSendWarning();
480 virtual void stateRecontendWindow();
486 virtual void printStateInfo(double delay = 0);
493 virtual void initInfo();
498 virtual void
499 refreshState(int state)
500 {
502 curr_state = state;
503 }
509 virtual void setBackoffNodes(double node, double node_b);
513 virtual void exitBackoff();
519 virtual void exitSleep();
523 virtual void freezeBackoff();
527 virtual int
529 {
530 return Q.size();
531 }
535 virtual void
536 queuePop(bool flag = true)
537 {
538 Packet::free(Q.front());
539 Q.pop();
540 waitEndTime(flag);
541 }
546 virtual void waitForUser();
547
548 /*******************
549 * stats functions *
550 ******************/
551
552 inline int
554 {
555 return up_data_pkts_rx;
556 }
557
561 virtual void
563 {
564 wrn_pkts_tx++;
565 }
569 virtual void
571 {
572 wrn_pkts_rx++;
573 }
577 virtual void
579 {
580 rts_pkts_tx++;
581 }
585 virtual void
587 {
588 rts_pkts_rx++;
589 }
593 virtual void
595 {
596 cts_pkts_tx++;
597 }
601 virtual void
603 {
604 cts_pkts_rx++;
605 }
609 virtual void
618 virtual void
620 {
621 wrn_pkts_tx = 0;
622 wrn_pkts_rx = 0;
623 defer_times_no = 0;
624 return MMac::resetStats();
625 }
630 virtual int
632 {
633 return (up_data_pkts_rx - Q.size());
634 }
638 virtual int
640 {
641 return wrn_pkts_tx;
642 }
646 virtual int
648 {
649 return wrn_pkts_rx;
650 }
654 virtual int
656 {
657 return rts_pkts_tx;
658 }
662 virtual int
664 {
665 return rts_pkts_rx;
666 }
670 virtual int
672 {
673 return cts_pkts_tx;
674 }
678 virtual int
680 {
681 return cts_pkts_rx;
682 }
686 virtual int
688 {
689 return defer_times_no;
690 }
694 virtual void
696 {
698 }
705 virtual void
706 deferEndTime(double duration)
707 {
708 sum_defer_time += duration;
709 }
713 virtual void
715 {
716 double duration = NOW - backoff_first_start;
717 backoffSumDuration(duration);
718 }
722 virtual double
724 {
725 if (defer_times_no > 0)
727 else
728 return (0.0);
729 }
730
741 double srtt;
742 double sumrtt;
743 double sumrtt2;
746 std::queue<Packet *> Q;
748 bool TxActive;
749 bool RxActive;
750 bool
758 bool
773 double t_min;
774 double T_W_min;
775 double delta_D;
778 double delta_data;
790 int
794 double alpha_;
826 static int u_pkt_id;
832 int txsn;
835 static map<int, string> info;
838 ofstream
841};
842
843#endif /* MMAC_UW_DACAP_H */
Class that represents the backoff timer in DACAP.
DACAPBTimer(MMacDACAP *m)
Costructor of the class DACAPBTimer.
virtual void expire(Event *e)
Method called when the timer expire.
MMacDACAP *int wait_reason
< Pointer to an object of MMacDACAP class
Class that represents the timers in DACAP.
virtual void expire(Event *e)
Method call when the timer expire.
DACAPTimer(MMacDACAP *m)
Costructor of the class DACAPTimer.
MMacDACAP *int wait_reason
< Pointer to an object of MMacDACAP class
Class that represents a DACAP node.
double wait_costant
Additive factor in the calculation of ACK timer.
ofstream fout
Object that handle the file where the state transitions is written (if the print_transitions option i...
DACAPBTimer backoff_timer
backoff timer
int op_mode
Indicates if the ACK_mode or no_ACK_mode is activated.
virtual int getWrnPktsRx()
virtual void stateWaitXCts()
The protocol is in WaitXCts state.
virtual void waitForUser()
Used for debug purposes.
virtual double getMeanDeferTime()
bool warning_sent
true if a WRN packet has been just sent
MMacDACAP()
Costructor of the MMacDACAP class.
virtual int getTotalDeferTimes()
int ACK_size
Size (in bytes) of the ACK packet.
bool print_transitions
true if the state-transitions of the protocol is printed on a file
virtual int getRtsPktsTx()
virtual void txRts()
Pass a RTS packet to transmit to the PHY layer.
virtual void incrWrnPktsRx()
Increases the counter of WRN packets received.
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
Packet * curr_data_pkt
Pointer to the current data packet.
virtual void stateDeferData()
The protocol is in the DeferData state.
int last_reason
last reason for the change of state
bool backoff_freeze_mode
true if the backoff-timer is freezed
int u_data_id
simulation-unique DATA packet ID
bool has_buffer_queue
true if the node has a buffer queue to store data packets
int WRN_size
Size (in bytes) of the WRN packet.
double alpha_
smoothing factor used for statistics using first order IIR filter
double max_tx_tries
Maximum transmission tries for one packet before discarding the packet.
virtual int getCtsPktsRx()
double max_prop_delay
One way maximum propagation delay (in seconds) in the network.
double session_distance
Distance between sender and receiver in the current session.
double sumrtt2
sum of (RTT^2)
int last_data_id_tx
Unique ID of the last data packet transmitted.
int CTS_size
Size (in bytes) of the CTS packet.
static int u_pkt_id
simulation-unique packet ID
int txsn
serial number of the DATA packet transmitted
virtual int getQueueSize()
double backoff_remaining
Backoff time remaining (if the timer is freezed)
virtual void stateSendWarning()
The protocol is in the SendWarning state.
int rts_pkts_tx
Counter of RTS packets TX.
virtual void stateWaitXAck()
The protocol is in WaitXAck state.
int curr_dest_addr
MAC address of the current node involved in this session.
virtual void rxStateIdle(Packet *p)
The case of reception while the protocol is in IDLE state is handled.
virtual void incrRtsPktsTx()
Increases the counter of RTS packets transmitted.
double sum_defer_time
Sum of the defer timers.
int buffer_pkts
Dimension (in packets) of the buffer queue.
double defer_times_no
Counter of defer times.
virtual double computeTxTime(int type)
Computes the time that is needed to transmit a packet, implementing a CrLayMessage for asking the PHY...
virtual void backoffStartTime()
Sets the start time of the backoff timer to NOW.
int prev_state
Previous state of the protocol.
virtual void Phy2MacStartRx(const Packet *p)
Method called when the Phy Layer start to receive a Packet.
virtual void rxStateWaitXData(Packet *p)
The case of reception while the protocol is in WaitXData state is handled.
virtual void rxStateWaitXCts(Packet *p)
The case of reception while the protocol is in WaitXCts state is handled.
std::queue< Packet * > Q
MAC queue used for packet scheduling.
virtual void resetStats()
Resets all the stats counters.
int max_payload
Dimension of the maximum allowed data paylaod in bytes.
virtual void rxStateWaitWarning(Packet *p)
The case of reception while the protocol is in WaitWarning state is handled.
int sleep_node_2
MAC address of sleep_node 2.
double start_tx_time
Timestamp at which a packet is transmitted.
double delta_D
Value (in m) that indicates how far we want the CTS propagates over the sender before initiate the da...
int RTS_size
Size (in bytes) of the RTS packet.
bool TxActive
true if a transmission process is occuring
virtual void rxStateWaitXAck(Packet *p)
The case of reception while the protocol is in WaitXAck state is handled.
bool backoff_pending
true if the backoff-timer is active (i.e.
bool multihop_mode
true if the multihop mode is active to simulate a multihop scenario with routing
double backoff_start_time
Backoff starting time.
virtual void txAck()
Pass an ACK packet to transmit to the PHY layer.
virtual void deferEndTime(double duration)
Sets the end time of the defer summing the duration to the actual duration of defer.
virtual void refreshState(int state)
Refresh the state of the protocol.
virtual void setBackoffNodes(double node, double node_b)
Saves the MAC address of another couple of nodes that is the handshake procedure in order to access t...
int HDR_size
Size (in bytes) of the header added by DACAP.
virtual void rxStateSendWarning(Packet *p)
The case of reception while the protocol is in SendWarning state is handled.
double max_backoff_counter
Number of times a backoff is calculated.
virtual void queuePop(bool flag=true)
Pop the first element of the queue.
virtual void stateDataReceived(Packet *data_pkt)
The protocol is in the DataReceived state.
virtual void rxStateWaitData(Packet *p)
The case of reception while the protocol is in WaitDATA state is handled.
virtual double getRecontendTime()
Used in multihop mode.
int last_data_id_rx
Unique ID of the last data packet received.
int wrn_pkts_rx
Counter of WRN packets RX.
virtual void rxStateBackoff(Packet *p)
The case of reception while the protocol is in BACKOFF state is handled.
virtual void initPkt(Packet *p, int pkt_type)
Initializes the packet with the correct MAC source address and destination address,...
bool RxActive
true if a reception process is occuring
virtual double getBackoffTime()
Calculate the backoff time if the node didn't received the ACK.
int rttsamples
num of RTT samples
virtual int getWrnPktsTx()
int cts_pkts_tx
Counter of CTS packets TX.
virtual int getRemainingPkts()
virtual void recvFromUpperLayers(Packet *p)
Receive the packet from the upper layer (e.g.
virtual void incrCtsPktsRx()
Increases the counter of CTS packets received.
double srtt
Smoothed Round Trip Time, calculated as for TCP.
virtual void stateSendAck()
The protocol is in SendAck state.
bool session_active
true if a session is active (i.e.
virtual void rxStateWaitXWarning(Packet *p)
The case of reception while the protocol is in WaitXWarning state is handled.
virtual void stateWaitWarning()
The protocol is in WaitWarning state.
int rts_pkts_rx
Counter of RTS packets RX.
virtual void stateWaitXWarning()
The protocol is in WaitXWarning state.
virtual void incrWrnPktsTx()
Increases the counter of WRN packets transmitted.
virtual void stateCTSReceived()
The protocol is in the CTSReceived state.
int sleep_node_1
MAC address of sleep_node 1.
virtual void stateWaitData()
The protocol is in the WaitData state.
virtual void stateSendData()
The protocol is in the SendData state.
virtual void rxStateRecontendWindow(Packet *p)
The case of reception while the protocol is in RecontendWindow state is handled.
virtual void incrTotalDeferTimes()
Increases the number of times a transmission is deferred.
virtual void initInfo()
Initializes the protocol at the beginning of the simulation.
virtual void stateBackoff()
The protocol is in Backoff state.
virtual void rxStateWaitACK(Packet *p)
The case of reception while the protocol is in WaitACK state is handled.
double t_min
Minimum time needed to do an hand-shaking.
int curr_state
Current state of the protocol.
virtual void incrCtsPktsTx()
Increases the counter of CTS packets transmitted.
virtual void stateWaitCTS()
The protocol is in the WaitCTS state.
double backoff_duration
Backoff duration.
virtual void txWrn()
Pass a WRN packet to transmit to the PHY layer.
virtual int getCtsPktsTx()
virtual void freezeBackoff()
Freezes the Backoff timer.
virtual void Phy2MacEndTx(const Packet *p)
Method called when the PHY layer finish to transmit the packet.
double T_W_min
Minimum Warning Time in sencods.
virtual void rxStateWaitCTS(Packet *p)
The case of reception while the protocol is in WaitCTS state is handled.
DACAPTimer timer
ACK timer.
double sumrtt
sum of RTT samples
int getUpLayersDataPktsRx()
int cts_pkts_rx
Counter of CTS packets RX.
double RTS_sent_time
Timestamp at which the RTS packet is sent.
double delta_data
Dimension difference (in bytes) among data packets ( 0 if the packets have always the same dimension...
virtual void stateRecontendWindow()
The protocol is in RecontendWindow state.
virtual void incrRtsPktsRx()
Increases the counter of RTS packets received.
virtual void exitSleep()
This method erase the MAC address of the two nodes that have intiated a handshake procedure if this h...
virtual void exitBackoff()
The backoff timer is stopped.
virtual void Phy2MacEndRx(Packet *p)
Method called when the Phy Layer finish to receive a Packet.
virtual void txCts()
Pass a CTS packet to transmit to the PHY layer.
int backoff_counter
Number of times a backoff timer is set up.
virtual int crLayCommand(ClMessage *m)
Cross-Layer messages interpreter.
virtual int getRtsPktsRx()
bool defer_data
true if a node has to defer the transmission of a data packet
virtual ~MMacDACAP()
Destructor of the MMacDACAP class.
virtual void printStateInfo(double delay=0)
Prints a file with every state change for debug purposes.
int wrn_pkts_tx
Counter of WRN packets TX.
static map< int, string > info
Relationship between the state and its textual description.
virtual double computeWaitTime(int mode, double distance)
Computes the T_w parameter, that is the minimum time that the sender has to wait between the receptio...
virtual void backoffEndTime()
calculates the End Time of the backoff timer
virtual void stateIdle()
The protocol is in the IDLE state.
virtual void txData()
Pass a DATA packet to transmit to the PHYl layer.
double backoff_tuner
Multiplicative factor in the calculation of backoff.
double backoff_first_start
Timestamp at which the backoff timer is started for the first time (if the timer has been freezed man...
virtual void stateWaitACK()
The protocol is in the WaitACK state.
virtual void stateSendRTS()
The protocol is in SendRTS state.
virtual void stateWaitXData()
The protocol is in WaitXData state.
virtual void stateSendCTS()
The protocol is in SendCTS state.
Definition of the header of DACAP packets.
int sn
sequence number of this packet
static int offset_
Required by the PacketHeaderManager.
static int & offset()
Reference to the offset variable.
int dacap_type
sequence number of this packet
int tx_tries
Number of transmission tries of the packet.
int data_sn
Sequence number of the packet.
static struct hdr_dacap * access(const Packet *p)
Access to this header in the Packet.
double ts
packet timestamp, i.e., its generation time)
packet_t orig_type
Original type of the packet.