DESERT 3.5.1
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 <uwip-module.h>
48#include <uwudp-module.h>
49
50#include <module.h>
51#include <iostream>
52#include <fstream>
53#include <string>
54#include <sstream>
55#include <climits>
56
57#define UWCBR_DROP_REASON_UNKNOWN_TYPE \
58 "UKT"
59#define UWCBR_DROP_REASON_OUT_OF_SEQUENCE \
60 "OOS"
61#define UWCBR_DROP_REASON_DUPLICATED_PACKET \
62 "DPK"
64#define HDR_UWCBR(p) (hdr_uwcbr::access(p))
65
66
67
68extern packet_t PT_UWCBR;
69
73typedef struct hdr_uwcbr {
74 uint16_t sn_;
75 float rftt_;
77 char priority_;
79 uint16_t traffic_type_;
81 static int offset_;
86 inline static int &
88 {
89 return offset_;
90 }
91
92 inline static struct hdr_uwcbr *
93 access(const Packet *p)
94 {
95 return (struct hdr_uwcbr *) p->access(offset_);
96 }
97
101 inline uint16_t &
103 {
104 return sn_;
105 }
106
110 inline bool &
112 {
113 return rftt_valid_;
114 }
115
119 inline char &
121 {
122 return priority_;
123 }
124
128 inline float &
130 {
131 return (rftt_);
132 }
133
137 inline uint16_t &
139 {
140 return (traffic_type_);
141 }
143
144class UwCbrModule;
145
150class UwSendTimer : public TimerHandler
151{
152public:
154 : TimerHandler()
155 {
156 module = m;
157 }
158
159protected:
160 virtual void expire(Event *e);
161 UwCbrModule *module;
162};
163
168class UwCbrModule : public Module
169{
170 friend class UwSendTimer;
171
172public:
176 UwCbrModule();
177
181 virtual ~UwCbrModule();
182
188 virtual void recv(Packet *);
189
196 virtual void recv(Packet *p, Handler *h);
197
208 virtual int command(int argc, const char *const *argv);
209
210 virtual int crLayCommand(ClMessage *m);
211
217 virtual double GetRTT() const;
218
224 virtual double GetFTT() const;
230 virtual double GetTxTime() const;
236 virtual double GetPER() const;
237
243 virtual double GetTHR() const;
244
250 virtual double GetRTTstd() const;
251
257 virtual double GetFTTstd() const;
258
262 virtual void resetStats();
263
267 inline void
269 {
270 std::cout << "UWCBR packets IDs:" << std::endl;
271 std::cout << "PT_UWCBR: \t\t" << PT_UWCBR << std::endl;
272 }
273
274protected:
275 static int uidcnt_;
276 uint16_t dstPort_;
277 std::string log_suffix;
278 nsaddr_t dstAddr_;
280 std::ofstream tracefile;
281 std::string tracefilename;
282
283 bool *sn_check;
287 int debug_;
294 int txsn;
295 int hrsn;
296 int
300 int
307 int cnt;
309 double rftt;
310 double srtt;
311 double sftt;
312 double lrtime;
313 double sthr;
315 double period_;
318 /* Cumulative statistics */
319 double sumrtt;
320 double sumrtt2;
323 double sumftt;
324 double sumftt2;
326 double sumtxtimes = 0;
328 double sumbytes;
329 double sumdt;
331 uint32_t esn;
341 virtual void initPkt(Packet *p);
342
349 virtual void sendPkt();
350
357 virtual void sendPktLowPriority();
358
365 virtual void sendPktHighPriority();
366
372 virtual void transmit();
373
377 virtual void start();
378
382 virtual void stop();
383
389 virtual void updateRTT(const double &);
390
396 virtual void updateFTT(const double &);
397
404 virtual void updateThroughput(const int &, const double &);
405
411 virtual void incrPktLost(const int &);
412
416 virtual void incrPktRecv();
417
421 virtual void incrPktOoseq();
422
426 virtual void incrPktInvalid();
427
435 virtual double getTimeBeforeNextPkt();
436
442 virtual void printReceivedPacket(Packet *p);
443
449 static inline int
451 {
452 return sizeof(hdr_uwcbr);
453 }
454};
455
456#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 int crLayCommand(ClMessage *m)
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 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.
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 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 void recv(Packet *)
Performs the reception of packets from upper and lower layers.
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).
virtual ~UwCbrModule()
Destructor of UwCbrModule class.
int fttsamples
Number of FTT samples.
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
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.