DESERT 3.5.1
Loading...
Searching...
No Matches
uwApplication_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
39#ifndef UWAPPLICATION_MODULE_H
40#define UWAPPLICATION_MODULE_H
41
42#include <uwip-module.h>
43#include <uwudp-module.h>
44
45#include <module.h>
46#include <iostream>
47#include <sstream>
48#include <climits>
49#include <time.h>
50#include <math.h>
51#include <assert.h>
52#include <errno.h>
53#include <stddef.h>
54
55#include <stdlib.h>
56#include <stdio.h>
57#include <fstream>
58#include <string.h>
59#include <sys/stat.h>
60#include <fcntl.h>
61
62#include <signal.h>
63
64#include <unistd.h>
65#include <syslog.h>
66#include <sys/types.h>
67#include <sys/socket.h>
68#include <netinet/in.h>
69#include <netdb.h>
70
71#include <arpa/inet.h>
72#include <deque>
73#include <list>
74#include <queue>
75#include <rng.h>
76#include <fstream>
77#include <ostream>
78#include <chrono>
79
80#define UWAPPLICATION_DROP_REASON_UNKNOWN_TYPE \
81 "DPUT"
82#define UWAPPLICATION_DROP_REASON_DUPLICATED_PACKET \
83 "DPD"
84#define UWAPPLICATION_DROP_REASON_OUT_OF_SEQUENCE \
85 "DOOS"
88extern packet_t
91class uwApplicationModule : public Module
92{
93 // friend class uwSendTimerAppl;
94public:
102 virtual ~uwApplicationModule();
113 virtual int command(int argc, const char *const *argv);
114
122 virtual int crLayCommand(ClMessage *m);
123
130 virtual void handleTCPclient(int clnSock);
131
132 // virtual void handleUDPclient(int clnSock);
133
138 virtual void
140 {
142 }
143
148 inline unsigned long int
150 {
151 unsigned long int timestamp =
152 (unsigned long int) (std::chrono::duration_cast<std::chrono::milliseconds>(
153 std::chrono::system_clock::now().time_since_epoch()).count() );
154 return timestamp;
155 }
156
159 struct sockaddr_in servAddr;
160 struct sockaddr_in clnAddr;
162 std::queue<Packet *>
166 std::queue<Packet *>
170 std::ofstream out_log;
175
177 static uint MAX_READ_LEN;
178
179protected:
181 class uwSendTimerAppl : public TimerHandler
182 {
183 public:
185 : TimerHandler()
186 {
187 m_ = m;
188 }
189
191 {
192 }
193
194 protected:
195 virtual void expire(Event *e);
197 }; // End uwSendTimer class
198
199 /**************************************************************************
200 * METHODS *
201 **************************************************************************/
206 virtual void recv(Packet *);
211 virtual void statistics(Packet *p);
217 // virtual void start_generation_pck_wth_socket();
218 virtual void start_generation();
226 // virtual void initialize_DATA_pck_wth_socket();
227 virtual void init_Packet();
233 virtual int openConnectionTCP();
240 // virtual void initialize_DATA_pck_wth_TCP();
241 virtual void init_Packet_TCP();
247 virtual int openConnectionUDP();
254 // virtual void initialize_DATA_pck_wth_UDP();
255 virtual void init_Packet_UDP();
262 virtual void stop();
270 // virtual bool withoutSocket() {bool test;SOCKET_CMN == 0 ? test = true :
271 // test = false; return test;}
272 // virtual bool withoutSocket() {bool test; socket_active == false ? test =
273 // true : test = false; return test;}
274 virtual bool
276 {
277 bool test;
278 socket_active == false ? test = true : test = false;
279 return test;
280 }
288 // virtual bool useTCP() {bool test;TCP_CMN == 1 ? test = true : test =
289 // false; return test;}
290 virtual bool
292 {
293 bool test;
294 tcp_udp == 1 ? test = true : test = false;
295 return test;
296 }
305 virtual inline bool
307 {
308 bool test;
309 poisson_traffic == 1 ? test = true : test = false;
310 return test;
311 }
322 virtual inline bool
324 {
325 bool test;
326 drop_out_of_order == 1 ? test = true : test = false;
327 return test;
328 }
329
330 /**************************************************************************
331 * METHODS GET and SET *
332 **************************************************************************/
337 virtual inline void
339 {
340 txsn++;
341 }
345 virtual inline void
346 incrPktLost(const int &npkts)
347 {
348 pkts_lost += npkts;
349 }
353 virtual inline void
355 {
356 pkts_recv++;
357 }
361 virtual inline void
363 {
364 pkts_ooseq++;
365 }
369 virtual inline void
371 {
372 pkts_invalid++;
373 }
379 virtual inline int
381 {
382 return txsn - 1;
383 }
389 virtual inline int
391 {
392 return pkts_lost;
393 }
399 virtual inline int
401 {
402 return pkts_recv;
403 }
409 virtual inline int
411 {
412 return pkts_ooseq;
413 }
419 virtual inline int
421 {
422 return pkts_invalid;
423 }
429 virtual inline int
431 {
432 return pkts_push_queue;
433 }
439 virtual inline double
441 {
442 return PERIOD;
443 }
449 virtual inline int
451 {
452 return payloadsize;
453 }
454
462 virtual double getTimeBeforeNextPkt();
468 virtual double GetRTT() const;
474 virtual double GetRTTstd() const;
480 virtual void updateRTT(const double &rtt);
487 virtual double GetFTT() const;
493 virtual double GetFTTstd() const;
499 virtual double GetPER() const;
505 virtual double GetTHR() const;
511 virtual void updateFTT(const double &ftt);
517 virtual void updateThroughput(const int &bytes, const double &dt);
518
519 /**************************************************************************
520 * VARIABLES *
521 **************************************************************************/
522 // TCL VARIABLES
523 int debug_;
525 double PERIOD;
527 // int SOCKET_CMN; /**< Enable or not the communication with socket <i>1</i>
528 // enabled <i>0</i> not enabled*/
537 // int TCP_CMN; /**< Enable or not the use of TCP protocol when is used the
538 // socket communication <i>1</i> use TCP <i>0</i> use UDP*/
539 uint8_t dst_addr;
541 // TIMER VARIABLES
546 // STATISTICAL VARIABLES
549 int tcp_udp; // 1 for tcp, 0 for udp, -1 for none
550 bool *sn_check;
551 int uidcnt;
553 int txsn;
554 int rftt;
568 double lrtime;
569 double sumrtt;
570 double sumrtt2;
572 double sumftt;
573 double sumftt2;
575 uint32_t esn;
576 double sumbytes;
577 double sumdt;
578 int hrsn;
580}; // end uwApplication_module class
581#endif /* UWAPPLICATION_MODULE_H */
582extern "C" {
583void *read_process_TCP(void *arg);
584}
585
586extern "C" {
587void *read_process_UDP(void *arg);
588}
< uwSenderTimer class that manage the timer
virtual bool withoutSocket()
Verify if the communication take place with socket or the data payload is generated in a randomly way...
int pkts_push_queue
Counter of DATA packets received by server and not yet passed to the below levels of ISO/OSI stack pr...
virtual void stop()
Close the socket connection in the case the communication take place with socket, otherwise stop the ...
int rttsamples
Number of RTT samples.
double sumftt2
Sum of (FTT^2).
int hrsn
Highest received sequence number.
virtual void incrPktOoseq()
Increase the number of DATA packets received out of order by the server.
virtual void init_Packet()
Set all the field of the DATA packet that must be send down after the creation to the below level.
virtual void updateRTT(const double &rtt)
Update the RTT after the reception of a new packet.
virtual double getTimeBeforeNextPkt()
Compute the DATA generation rate, that can be constant and equal to the PERIOD established by the use...
virtual void recv(Packet *)
Handle the transmission of DATA packets between CBR layer and the below level.
int pkts_last_reset
Used for error checking after stats are reset.
double sumftt
Sum of FTT samples.
uwSendTimerAppl chkTimerPeriod
Timer that schedule the period between two successive generation of DATA packets.
uint32_t esn
Expected serial number.
int pkts_ooseq
Counter of the packets received out of order by the server.
int pkts_recv
Counter of the packets correctly received by the server.
int drop_out_of_order
Enable or not the ordering of data packet received 1 enabled 0 not enabled.
int servSockDescr
socket descriptor for server
double sumrtt
Sum of RTT samples.
virtual void start_generation()
Start the process to generate DATA packets without sockets.
int rftt
Forward trip time.
int debug_
Used for debug purposes 1 debug activated 0 debug not activated.
std::queue< Packet * > queuePckReadUDP
Queue that store the DATA packets recevied from the client by the server using a UDP protocol.
virtual void incrPktSent()
Increase the sequence number and so the number of packets sent by the server.
virtual ~uwApplicationModule()
Destructor of uwApplicationModule class.
virtual double GetRTT() const
Returns the average Round Trip Time.
double sumdt
Sum of the delays.
virtual double GetPER() const
Rerturn the Packet Error Rate calculated.
int fttsamples
Number of FTT samples.
virtual bool useDropOutOfOrder()
If the communication take place without sockets verify if the data packets received by the server is ...
virtual int getPktsOOSequence()
return the number of DATA packets received out of order by the server
virtual int openConnectionUDP()
When socket communication is used, this method establish a connection between client and server.
virtual int getPktRecv()
return the number of DATA packet correctly received by the server
virtual void handleTCPclient(int clnSock)
Handle the communication between server and client.
virtual void updateFTT(const double &ftt)
Update the FTT after the reception of a new packet.
virtual void init_Packet_UDP()
Set all the field of DATA packet and take from the specific queue the payload of DATA packet that wil...
virtual double GetFTT() const
Returns the average Forward Trip Time.
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
double PERIOD
Interval time between two successive generation data packets.
virtual double GetTHR() const
Return the Throughput calculated [bps].
virtual void incrPktsPushQueue()
Increase the number of DATA packets stored in the Server queue.
int uidcnt
Identifier counter that identify uniquely the DATA packet generated.
double sumbytes
Sum of bytes received.
virtual int openConnectionTCP()
When socket communication is used, this method establish a connection between client and server.
double sumrtt2
Sum of (RTT^2).
virtual bool usePoissonTraffic()
If the communication take place without sockets verify if the data generation period is constant or i...
int pkts_lost
Counter of the packet lost during the transmission.
virtual int getPktSent()
return the number of packets sent by the server
int clnSockDescr
*socket descriptor for client
int pkts_invalid
Counter of the packets received with errors by the server.
unsigned long int getEpoch()
Calculate the epoch of the event.
bool * sn_check
Used to keep track of the packets already received.
int payloadsize
Size of each data packet payaload generated.
virtual int getPktsPushQueue()
return the number of DATA packets sotred in the server queue
struct sockaddr_in servAddr
Server address.
virtual int getPktLost()
return the number of DATA packets lost by the server
virtual void incrPktInvalid()
Increse the number of DATA packets received with error by the server.
virtual double GetRTTstd() const
Return the standard deviation of the Round Trip Time calculated.
uwApplicationModule()
Constructor of uwApplicationModule class.
virtual int getpayloadsize()
return the size of DATA packet payload
virtual void incrPktLost(const int &npkts)
Increase the number of DATA packets lost by the server.
std::ofstream out_log
Variable that handle the file in which the protocol write the statistics.
virtual void statistics(Packet *p)
Comupte some statistics as the number of packets sent and receive between two layer,...
static uint MAX_READ_LEN
Maximum size (bytes) of a single read of the socket.
int poisson_traffic
Enable or not the Poisson process for generation of data packets 1 enabled 0 not enabled.
int port_num
Number of the port in which the server provide the service.
struct sockaddr_in clnAddr
Client address.
uint8_t dst_addr
IP destination address.
virtual double getPeriod()
return period generation time
virtual bool useTCP()
If the communication take place using sockets verify if the protocol used is TCP or UDP.
virtual int crLayCommand(ClMessage *m)
Cross-Layer messages interpreter.
std::queue< Packet * > queuePckReadTCP
Queue that store the DATA packets recevied from the client by the server using a TCP protocol.
virtual void init_Packet_TCP()
Set all the field of DATA packet and take from the specific queue the payload of DATA packet that wil...
int txsn
Transmission sequence number of DATA packet.
virtual void incrPktRecv()
Increase the number of DATA packet correctly received by the server.
virtual double GetFTTstd() const
Return the standard deviation of the Forward Trip Time calculated.
virtual void updateThroughput(const int &bytes, const double &dt)
Update the Throughput after the reception of a new packet.
double lrtime
Time of last packet reception.
virtual int getPktsInvalidRx()
return the number of DATA packets received with error by the server
packet_t PT_DATA_APPLICATION
Trigger packet type for UFetch protocol.
void * read_process_TCP(void *arg)
void * read_process_UDP(void *arg)
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.