DESERT 3.5.1
Loading...
Searching...
No Matches
sun-ipr-sink.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 SUN_SINK_H
42#define SUN_SINK_H
43
45#include "sun-hdr-ack.h"
47#include "sun-hdr-probe.h"
48#include "sun-hdr-data.h"
49
50#include <uwip-module.h>
51#include <uwip-clmsg.h>
52#include <uwcbr-module.h>
53
54#include "packet.h"
55#include <module.h>
56#include <tclcl.h>
57
58#include <stdio.h>
59#include <stdlib.h>
60#include <iostream>
61#include <string>
62#include <sstream>
63#include <vector>
64#include <rng.h>
65#include <fstream>
66
67
68
72class SunIPRoutingSink : public Module
73{
74
75 friend class SendTimer;
76
77public:
81 class SendTimer : public TimerHandler
82 {
83 public:
85 : TimerHandler()
86 , module(m)
87 {
88 }
89
90 protected:
94 virtual void expire(Event *e);
95
97 *module;
98 };
99
104
108 virtual ~SunIPRoutingSink();
109
110protected:
111 /*****************************
112 | Internal Functions |
113 *****************************/
124 virtual int command(int, const char *const *);
125
131 virtual void recv(Packet *);
132
140 virtual int recvSyncClMsg(ClMessage *);
141
150 virtual int recvAsyncClMsg(ClMessage *);
151
160 virtual void initialize();
161
166 virtual void sendProbe();
167
175 static string printIP(const nsaddr_t &);
176
184 static string printIP(const ns_addr_t &);
185
193 static nsaddr_t str2addr(const char *);
194
203 inline const double
204 getDelay(const double &period_) const
205 {
206 if (PoissonTraffic_)
207 return (-log(RNG::defaultrng()->uniform_double()) /
208 (1.0 / period_));
209 else
210 return 0;
211 }
212
213 // Timer
217 virtual void start();
218
222 virtual void stop();
223
227 virtual void transmit();
228
234 virtual void setProbeTimer(const double &);
235
241 virtual const double &getProbeTimer() const;
242
243 /*****************************
244 | Acks |
245 *****************************/
256 virtual void sendBackAck(const Packet *);
257
264 virtual void initPktAck(Packet *);
265
266 /*****************************
267 | Statistics |
268 *****************************/
274 static inline const int
276 {
277 return sizeof(hdr_sun_probe);
278 }
279
285 static inline const int
287 {
288 return sizeof(hdr_sun_ack);
289 }
290
296 inline const long &
298 {
299 return probe_count_;
300 }
301
307 inline const long &
309 {
310 return number_of_ackpkt_;
311 }
312
313 /*****************************
314 | Trace file |
315 *****************************/
322 virtual void tracePacket(
323 const Packet *const, const string &position = "UNDEF___");
324
329 virtual string createTraceString(const string &, const double &,
330 const int &, const int &, const int &, const int &, const int &,
331 const int &, const int &, const double &, const int &, const int &);
332
339 virtual void writeInTrace(const string &);
340
346 virtual void writePathInTrace(const Packet *);
347
348 // Internal variables
350 double t_probe;
357 // Statistics
358 static long probe_count_;
360 static long number_of_ackpkt_;
362 int
365 unsigned int **arrayofstats_;
372 // Timer
375 // Trace file
376 bool trace_;
380 char
383 char
395private:
404};
405
406#endif // SUN_SINK_H
SendTimer class is used to handle the timer of probe messages.
SendTimer(SunIPRoutingSink *m)
virtual void expire(Event *e)
Method invoked when the SinkProbeTimer timer expires.
SunIPRoutingSink class is used to represent the routing layer of a sink.
static nsaddr_t str2addr(const char *)
Returns a nsaddr_t address from an IP written as a string in the form "x.x.x.x".
int PoissonTraffic_
Enable (1) or disable (0) the Poisson traffic for SUN packets.
virtual void start()
Starts to send Probe packets.
virtual void writePathInTrace(const Packet *)
Writes in the Path Trace file the path contained in the Packet.
SunIPRoutingSink()
Constructor of SunIPRoutingNode class.
static long number_of_ackpkt_
Comulative number of Ack packets processed by SunIPRoutingNode objects.
virtual ~SunIPRoutingSink()
Constructor of SunIPRoutingNode class.
bool trace_
Flag used to enable or disable the trace file for nodes,.
virtual int recvAsyncClMsg(ClMessage *)
Cross-Layer messages asynchronous interpreter.
virtual void setProbeTimer(const double &)
Sets the probe interval timer.
static const int getProbePktHeaderSize()
Returns the size in byte of a hdr_sun_probe packet header.
static const int getAckHeaderSize()
Returns the size in byte of a hdr_sun_ack packet header.
virtual void transmit()
Sends a single Probe packet.
virtual void initPktAck(Packet *)
Initializes an ack packet passed as argument with the default values.
const double getDelay(const double &period_) const
Returns a delay value to use in transmission.
virtual void sendProbe()
Creates and sends in broadcast a probe message to notify the presence of the sink.
const long & getAckCount() const
Returns the number of Ack packets processed by the entire network.
const long & getProbeCount() const
Returns the number of Probe packets processed by the entire network.
double periodPoissonTraffic_
Period of the Poisson traffic.
char trace_separator_
Used as separator among elements in an entr of the tracefile.
bool trace_path_
Flag used to enable or disable the path trace file for nodes,.
SendTimer sendTmr_
SendTimer object.
virtual const double & getProbeTimer() const
Returns the current time interval between two consecutive probes.
char * trace_file_path_name_
Name of the trace file that contains the list of paths of the data packets received.
virtual void sendBackAck(const Packet *)
Creates an ack packet and sends it to the previous hop using the information contained in the header ...
virtual void initialize()
Initializes a SunIPRoutingNode node.
virtual string createTraceString(const string &, const double &, const int &, const int &, const int &, const int &, const int &, const int &, const int &, const double &, const int &, const int &)
Function that accept a list of string and create an entry for the trace file.
nsaddr_t ipAddr_
IP of the current node.
ostringstream osstream_
Used to convert to string.
static string printIP(const nsaddr_t &)
Return a string with an IP in the classic form "x.x.x.x" converting an ns2 nsaddr_t address.
virtual int recvSyncClMsg(ClMessage *)
Cross-Layer messages synchronous interpreter.
virtual int command(int, const char *const *)
TCL command interpreter.
virtual void writeInTrace(const string &)
Opens the trace file, writes the string passed as input and closes the file.
virtual void recv(Packet *)
Performs the reception of packets from upper and lower layers.
SunIPRoutingSink(const SunIPRoutingSink &)
Copy constructor declared as private.
virtual void tracePacket(const Packet *const, const string &position="UNDEF___")
Traces a packet.
ofstream trace_file_
Ofstream used to write the trace file in the disk.
double t_probe
Period of the probing.
int numberofnodes_
Number of nodes in the network, used for statistic purposes.
int printDebug_
Flag to enable or disable dirrefent levels of debug.
char * trace_file_name_
Name of the trace file writter for the current node.
ofstream trace_file_path_
Ofstream used to write the path trace file in the disk.
unsigned int ** arrayofstats_
Structure that contains the number of data packets received by the the sink, for different nodes and ...
static long probe_count_
Comulative number of probes sent by SunIPRoutingSink objects.
virtual void stop()
Stops to send Probe packets.
hdr_sun_ack describes acks packets used by UWSUN.
Definition sun-hdr-ack.h:52
hdr_sun_probe describes probe packets used by UWSUN
Provides the Ack Messages header description.
Provides the Data Messages header description.
Provides the Path Establishment Messages header description.
Provides the Probe Messages header description.
Common structures and definition used by SUN.
Provides the UWCBR packets header description and the definition of the class UWCBR.
Cross layer messages definition for the UWIP Module.
Provides the UWIP packets header description. Definition of the class that define the network layer.