DESERT 3.6.0
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
41#ifndef UWAPPLICATION_MODULE_H
42#define UWAPPLICATION_MODULE_H
43
45#include <module.h>
46
47#include <arpa/inet.h>
48#include <netdb.h>
49#include <netinet/in.h>
50#include <sys/socket.h>
51#include <sys/types.h>
52
53#include <atomic>
54#include <chrono>
55#include <mutex>
56#include <queue>
57#include <thread>
58
59#define UWAPPLICATION_DROP_REASON_UNKNOWN_TYPE \
60 "DPUT"
61#define UWAPPLICATION_DROP_REASON_DUPLICATED_PACKET \
62 "DPD"
63#define UWAPPLICATION_DROP_REASON_OUT_OF_SEQUENCE \
64 "DOOS"
67
72class uwSendTimerAppl : public TimerHandler
73{
74public:
76 : TimerHandler()
77 {
78 module = m;
79 }
80
81protected:
82 virtual void expire(Event *e);
83 uwApplicationModule *module;
84};
85
86class uwApplicationModule : public Module
87{
88 friend class uwSendTimerAppl;
89
90public:
95
99 virtual ~uwApplicationModule();
100
111 virtual int command(int argc, const char *const *argv) override;
112
118 virtual void recv(Packet *) override;
119
120 virtual double GetFTT() const;
127 virtual double GetFTTstd() const;
134 virtual double GetPER() const;
135
141 virtual double GetTHR() const;
142
148 virtual double GetRTT() const;
149
155 virtual double GetRTTstd() const;
156
162 virtual int
164 {
165 return txsn - 1;
166 }
167
173 virtual int
175 {
176 return pkts_lost;
177 }
178
184 virtual int
186 {
187 return pkts_recv;
188 }
189
195 virtual int
197 {
198 return pkts_ooseq;
199 }
200
206 virtual int
208 {
209 return pkts_invalid;
210 }
211
217 virtual int
219 {
220 return pkts_push_queue;
221 }
222
228 virtual double
229 getPeriod() const
230 {
231 return period;
232 }
233
238 std::string
239 getEpoch() const
240 {
241 unsigned long int timestamp =
242 (unsigned long int) (std::chrono::duration_cast<
243 std::chrono::milliseconds>(
244 std::chrono::system_clock::now().time_since_epoch())
245 .count());
246
247 return to_string(timestamp);
248 }
249
260 virtual void
261 printOnLog(Logger::LogLevel log_level, const std::string &module,
262 const std::string &message) const override
263 {
264 if (enable_log) {
265 if (sea_trial)
266 logger.printOnLog(log_level,
267 "[" + getEpoch() + "]::" + module + "(" +
268 to_string(node_id) + ")::" + message);
269 else
270 PlugIn::printOnLog(log_level, module, message);
271 }
272 }
273
274protected:
282 virtual void transmit();
283
288 virtual bool listenTCP();
289
294 virtual void acceptTCP();
295
302 virtual void readFromTCP(int clnSock);
303
311 virtual bool openConnectionUDP();
312
318 virtual void readFromUDP();
319
326 virtual void stop();
327
334 virtual bool
336 {
337 return !socket_active;
338 }
339
345 virtual bool
347 {
348 return socket_tcp;
349 }
350
358 virtual bool
360 {
361 return (poisson_traffic == 1) ? true : false;
362 }
363
371 virtual bool
373 {
374 return (drop_out_of_order == 1) ? true : false;
375 }
376
381 virtual void
383 {
384 txsn++;
385 }
386
390 virtual void
391 incrPktLost(int npkts)
392 {
393 pkts_lost += npkts;
394 }
395
399 virtual void
401 {
402 pkts_recv++;
403 }
407 virtual void
409 {
410 pkts_ooseq++;
411 }
415 virtual void
417 {
418 pkts_invalid++;
419 }
420
425 virtual void
427 {
429 }
430
438 virtual double getTimeBeforeNextPkt();
439
445 virtual void updateRTT(double rtt);
446
459 virtual void updateFTT(double ftt);
460
466 virtual void updateThroughput(int bytes, double dt);
467
472 bool *sn_check;
473 uint8_t dst_addr;
480 int uidcnt;
482 int hrsn;
483 int txsn;
484 int rftt;
503 uint32_t esn;
506 double period;
507 double lrtime;
508 double sumrtt;
509 double sumrtt2;
510 double sumftt;
511 double sumftt2;
512 double sumbytes;
513 double sumdt;
515 struct sockaddr_in servAddr;
516 struct sockaddr_in clnAddr;
517 std::thread socket_thread;
518 std::mutex socket_mutex;
519 std::atomic<bool> receiving;
521 std::queue<Packet *> queuePckReadTCP;
524 std::queue<Packet *> queuePckReadUDP;
530 static uint MAX_READ_LEN;
532};
533#endif /* UWAPPLICATION_MODULE_H */
virtual void updateThroughput(int bytes, double dt)
Update the Throughput after the reception of a new packet.
virtual int getPktsInvalidRx() const
return the number of DATA packets received with error by the server
virtual bool withoutSocket()
Check if the communication take place without socket.
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 ...
virtual void readFromTCP(int clnSock)
Method that reads a TCP byte stream from external application and converts it to a Packet.
int rttsamples
Number of RTT samples.
std::atomic< bool > receiving
virtual int getPktsPushQueue() const
Return the number of DATA packets sorted in the server queue.
double sumftt2
Sum of (FTT^2).
int hrsn
Highest received sequence number.
std::thread socket_thread
Object with the socket rx thread.
virtual void incrPktOoseq()
Increase the number of DATA packets received out of order by the server.
virtual double getTimeBeforeNextPkt()
Compute the DATA generation rate, that can be constant and equal to the period established by the use...
int node_id
Node id to be print in log output.
int pkts_last_reset
Used for error checking after stats are reset.
virtual int getPktLost() const
return the number of DATA packets lost by the server
double sumftt
Sum of FTT samples.
virtual int getPktRecv() const
return the number of DATA packet correctly received by the server
uint32_t esn
Expected serial number.
virtual double getPeriod() const
Return period generation time.
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.
virtual void readFromUDP()
Method that waits for UDP packets from external application and converts it to a Packet.
int drop_out_of_order
Ordering of data packet received 1 enabled 0 not enabled.
virtual bool openConnectionUDP()
When socket communication is used, this method establish a connection between client and server.
int servSockDescr
Socket descriptor for server.
double sumrtt
Sum of RTT samples.
int rftt
Forward round trip time.
virtual void incrPktLost(int npkts)
Increase the number of DATA packets lost by the server.
bool socket_tcp
Flag set to true if packets are received from external application.
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 int getPktSent() const
return the number of packets sent by the server
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 void recv(Packet *) override
Performs the reception of packets from upper and lower layers.
virtual double GetFTT() const
int servPort
Socket server port.
virtual double GetTHR() const
Return the Throughput calculated [bps].
virtual void incrPktsPushQueue()
Increase the number of DATA packets stored in the Server queue.
virtual void updateFTT(double ftt)
Returns the average Forward Trip Time.
virtual void transmit()
Set all the field of the DATA packet that must be send down after the creation to the below level.
virtual int command(int argc, const char *const *argv) override
TCL command interpreter.
int uidcnt
Identifier counter that identify uniquely the DATA packet generated.
double sumbytes
Sum of bytes received.
int sea_trial
Set to 1 to enable epoch time in log output.
std::mutex socket_mutex
Mutex associated with the socket rx thread.
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 a...
virtual bool listenTCP()
Method that binds the listening TCP socket.
int pkts_lost
Counter of the packet lost during the transmission.
virtual void acceptTCP()
Method that puts in place a listening TCP socket.
int clnSockDescr
Socket descriptor for client.
int pkts_invalid
Counter of the packets received with errors by the server.
uwSendTimerAppl * chkTimerPeriod
Timer that schedule the period between successive generation of DATA packets.
bool * sn_check
Flag set to true if the external application is connected via a TCP socket, false if UDP.
int payloadsize
Size of each data packet payaload generated.
struct sockaddr_in servAddr
Server address.
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.
std::string getEpoch() const
Calculate the epoch of the event.
static uint MAX_READ_LEN
Maximum size (bytes) of a single read of the socket.
int poisson_traffic
Poisson process for generation of data packets 1 enabled 0 not enabled.
virtual int getPktsOOSequence() const
return the number of DATA packets received out of order by the server
int port_num
Destination port number.
struct sockaddr_in clnAddr
Client address.
uint8_t dst_addr
Destination IP address.
double period
Time between successive generation data packets.
virtual void printOnLog(Logger::LogLevel log_level, const std::string &module, const std::string &message) const override
Method to send the log message to the logger.
virtual bool useTCP()
Check if the socket protocol is TCP or UDP.
std::queue< Packet * > queuePckReadTCP
Atomic boolean variable that controls the socket rx looping thread.
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.
double lrtime
Time of last packet reception.
virtual void updateRTT(double rtt)
Update the RTT after the reception of a new packet.
uwSendTimerAppl is used to handle the scheduling period of uwApplicationModule packets.
virtual void expire(Event *e)
uwSendTimerAppl(uwApplicationModule *m)
log_level
Definition uw-csma-ca.h:86
Provides the headers of the DATA packet.