DESERT 3.6.0
Loading...
Searching...
No Matches
uwcbr-module.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
44#ifndef UWCBR_MODULE_H
45#define UWCBR_MODULE_H
46
47#include <module.h>
48#include <uwip-module.h>
49#include <uwudp-module.h>
50#include <climits>
51
52#define UWCBR_DROP_REASON_UNKNOWN_TYPE \
53 "UKT"
54#define UWCBR_DROP_REASON_OUT_OF_SEQUENCE \
55 "OOS"
56#define UWCBR_DROP_REASON_DUPLICATED_PACKET \
57 "DPK"
59#define HDR_UWCBR(p) (hdr_uwcbr::access(p))
60
61extern packet_t PT_UWCBR;
62
66typedef struct hdr_uwcbr {
67 uint16_t sn_;
68 float rftt_;
70 char priority_;
72 uint16_t traffic_type_;
74 static int offset_;
79 static int &
81 {
82 return offset_;
83 }
84
85 static struct hdr_uwcbr *
86 access(const Packet *p)
87 {
88 return (struct hdr_uwcbr *) p->access(offset_);
89 }
90
94 uint16_t &
96 {
97 return sn_;
98 }
99
103 bool &
105 {
106 return rftt_valid_;
107 }
108
112 char &
114 {
115 return priority_;
116 }
117
121 float &
123 {
124 return (rftt_);
125 }
126
130 uint16_t &
132 {
133 return (traffic_type_);
134 }
136
137class UwCbrModule;
138
143class UwSendTimer : public TimerHandler
144{
145public:
147 : TimerHandler()
148 {
149 module = m;
150 }
151
152protected:
153 virtual void expire(Event *e);
154 UwCbrModule *module;
155};
156
161class UwCbrModule : public Module
162{
163 friend class UwSendTimer;
164
165public:
169 UwCbrModule();
170
174 virtual ~UwCbrModule() = default;
175
181 virtual void recv(Packet *) override;
182
189 virtual void recv(Packet *p, Handler *h) override;
190
201 virtual int command(int argc, const char *const *argv) override;
202
208 virtual double GetRTT() const;
209
215 virtual double GetFTT() const;
216
222 virtual double GetTxTime() const;
223
229 virtual double GetPER() const;
230
236 virtual double GetTHR() const;
237
243 virtual double GetRTTstd() const;
244
250 virtual double GetFTTstd() const;
251
255 virtual void resetStats();
256
260 void
262 {
263 std::cout << "UWCBR packets IDs:" << std::endl;
264 std::cout << "PT_UWCBR: \t\t" << PT_UWCBR << std::endl;
265 }
266
267protected:
268 static int uidcnt_;
270 uint16_t dstPort_;
271 std::string log_suffix;
272 nsaddr_t dstAddr_;
274 std::ofstream tracefile;
275 std::string tracefilename;
276
277 bool *sn_check;
281 int debug_;
288 int txsn;
289 int hrsn;
299 int cnt;
302 double rftt;
303 double srtt;
304 double sftt;
305 double lrtime;
306 double sthr;
308 double period_;
311 /* Cumulative statistics */
312 double sumrtt;
313 double sumrtt2;
316 double sumftt;
317 double sumftt2;
319 double sumtxtimes = 0;
321 double sumbytes;
322 double sumdt;
324 uint32_t esn;
335 virtual void initPkt(Packet *p);
336
343 virtual void sendPkt();
344
351 virtual void sendPktLowPriority();
352
359 virtual void sendPktHighPriority();
360
366 virtual void transmit();
367
371 virtual void start();
372
376 virtual void stop();
377
383 virtual void updateRTT(const double &);
384
390 virtual void updateFTT(const double &);
391
398 virtual void updateThroughput(const int &, const double &);
399
405 virtual void incrPktLost(const int &);
406
410 virtual void incrPktRecv();
411
415 virtual void incrPktOoseq();
416
420 virtual void incrPktInvalid();
421
429 virtual double getTimeBeforeNextPkt();
430
436 virtual void printReceivedPacket(Packet *p);
437
443 static int
445 {
446 return sizeof(hdr_uwcbr);
447 }
448};
449
450#endif // UWCBR_MODULE_H
UwCbrModule class is used to manage UWCBR packets and to collect statistics about them.
double sumdt
Sum of the delays.
UwCbrModule()
Constructor of UwCbrModule class.
virtual void incrPktRecv()
Increases by one the number of received packets.
virtual void initPkt(Packet *p)
Initializes a data packet passed as argument with the default values.
static int getCbrHeaderSize()
Returns the size in byte of a hdr_uwcbr packet header.
std::string tracefilename
static int uidcnt_
Unique id of the packet generated.
virtual int command(int argc, const char *const *argv) override
TCL command interpreter.
virtual void sendPktLowPriority()
Allocates, initialize and sends a packet with the default priority flag set from tcl.
virtual double getTimeBeforeNextPkt()
Returns the amount of time to wait before the next transmission.
double rftt
Forward Trip Time seen for last received packet.
double sumbytes
Sum of bytes received.
int txsn
Sequence number of the next packet to be transmitted.
int pkts_lost
Total number of lost packets, including packets received out of sequence.
virtual double GetRTTstd() const
Returns the Round Trip Time Standard Deviation.
virtual void stop()
Stop to send packets.
virtual void incrPktInvalid()
Increases by one the number of invalid packets.
uint32_t esn
Expected serial number.
double sumftt2
Sum of (FTT^2).
double sthr
Smoothed throughput calculation.
virtual void incrPktLost(const int &)
Increases the number of packets lost.
uint16_t dstPort_
Destination port.
int pkts_ooseq
Total number of packets received out of sequence.
virtual double GetTHR() const
Returns the mean Throughput.
std::string log_suffix
Possibility to insert a log suffix.
int debug_
Flag to enable several levels of debug.
bool * sn_check
Used to keep track of the packets already received.
double sumftt
Sum of FTT samples.
double srtt
Smoothed Round Trip Time, calculated as for TCP.
uint traffic_type_
Traffic type of the packets.
virtual void printReceivedPacket(Packet *p)
Print to tracefile details about a received packet.
void printIdsPkts() const
Prints the IDs of the packet's headers defined by UWCBR.
char priority_
Priority of the data packets.
virtual double GetTxTime() const
Returns the mean transmission time.
int drop_out_of_order_
Flag to enable or disable the check for out of order packets.
double sftt
Smoothed Forward Trip Time, calculated as srtt.
virtual double GetFTTstd() const
Returns the mean Forward Trip Time Standard Deviation.
virtual void incrPktOoseq()
Increases by one the number of out of sequence packets received.
virtual void updateThroughput(const int &, const double &)
Updates the Throughput.
virtual void updateRTT(const double &)
Updates the Round Trip Time.
int tracefile_enabler_
True if enable tracefile of received packets, default disabled.
nsaddr_t dstAddr_
IP of the destination.
virtual void recv(Packet *) override
Performs the reception of packets from upper and lower layers.
int pkts_recv
Total number of received packets.
UwSendTimer sendTmr_
Timer which schedules packet transmissions.
virtual void start()
Start to send packets.
double lrtime
Time of last packet reception.
virtual ~UwCbrModule()=default
Destructor of UwCbrModule class.
virtual void sendPktHighPriority()
Allocates, initialize and sends a packet with the default priority flag set from tcl.
double sumrtt
Sum of RTT samples.
virtual double GetFTT() const
Returns the mean Forward Trip Time.
virtual double GetPER() const
Returns the mean Packet Error Rate.
virtual void transmit()
Creates and transmits a packet and schedules a new transmission.
int pktSize_
UWCBR packets payload size.
int hrsn
Highest received sequence number.
int pkts_invalid
Total number of invalid packets received.
double sumtxtimes
Sum of transmission times
double sumrtt2
Sum of (RTT^2).
int fttsamples
Number of FTT samples.
std::ofstream tracefile
virtual double GetRTT() const
Returns the mean Round Trip Time.
virtual void updateFTT(const double &)
Updates the Forward Trip Time.
int pkts_last_reset
Used for error checking after stats are reset.
int cnt
Used for check if is the first time that tracefile<ip of sink> is opened.
virtual void resetStats()
Resets all the statistics of the UWCBR module.
double period_
Period between two consecutive packet transmissions.
virtual void sendPkt()
Allocates, initialize and sends a packet with the default priority flag set from tcl.
int PoissonTraffic_
1 if the traffic is generated according to a poissonian distribution, 0 otherwise.
int rttsamples
Number of RTT samples.
UwSendTimer class is used to handle the scheduling period of UWCBR packets.
UwSendTimer(UwCbrModule *m)
virtual void expire(Event *e)
hdr_uwcbr describes UWCBR packets.
float & rftt()
Reference to the rftt_ variable.
char priority_
Priority flag: 1 means high priority, 0 normal priority.
uint16_t traffic_type_
Traffic type: (video, audio, image, etc..) meaning left to the user.
static int & offset()
Reference to the offset_ variable.
char & priority()
Reference to the priority_ variable.
bool rftt_valid_
Flag used to set the validity of the fft field.
uint16_t & traffic_type()
Reference to the rftt_ variable.
bool & rftt_valid()
Reference to the rftt_valid_ variable.
float rftt_
Forward Trip Time of the packet.
uint16_t sn_
Serial number of the packet.
uint16_t & sn()
Reference to the sn_ variable.
static struct hdr_uwcbr * access(const Packet *p)
static int offset_
Required by the PacketHeaderManager.
Provides the UWIP packets header description. Definition of the class that define the network layer.
Provides the UWUDP packets header description and the definition of the class UWUDP.