DESERT 3.5.1
Loading...
Searching...
No Matches
sun-ipr-node.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_NODE_H
42#define SUN_NODE_H
43
45#include "sun-hdr-ack.h"
46#include "sun-hdr-data.h"
48
49#include <uwip-module.h>
50#include <uwip-clmsg.h>
51#include <uwcbr-module.h>
52
53#include "mphy.h"
54#include "packet.h"
55#include <module.h>
56#include <tclcl.h>
57
58#include <cmath>
59#include <limits>
60#include <sstream>
61#include <string>
62#include <iostream>
63#include <rng.h>
64#include <ctime>
65#include <vector>
66#include <fstream>
67#include <map>
68
69
70
72
81class SinkProbeTimer : public TimerHandler
82{
83public:
85 : TimerHandler()
86 {
87 module = m;
88 }
89
90protected:
94 virtual void expire(Event *e);
95
97 *module;
98};
99
105class RemoveHopTableTimer : public TimerHandler
106{
107
108public:
110 : TimerHandler()
111 {
112 module = m;
113 }
114
115protected:
117 *module;
122 virtual void expire(Event *e);
123};
124
126// * AckWaiting class is used to handle the timer of acks.
127// * When a node sends a packet it waits for and ack
128// * for a period managed by an AckWaiting object.
129// */
130// class AckWaiting : public TimerHandler {
131//
132// public:
133// AckWaiting(SunIPRoutingNode* m) : TimerHandler() {
134// module = m;
135// }
136//
137// protected:
138// SunIPRoutingNode* module; /**< Pointer to an objet of type
139// SunIPRoutingNode. */
140//
141// /**
142// * Method invoked when the AckWaiting timer expires.
143// */
144// virtual void expire(Event *e);
145//};
146
150class BufferTimer : public TimerHandler
151{
152
153public:
155 : TimerHandler()
156 {
157 module = m;
158 }
159
160protected:
162 *module;
167 virtual void expire(Event *e);
168};
169
173class SearchPathTimer : public TimerHandler
174{
175
176public:
178 : TimerHandler()
179 {
180 module = m;
181 }
182
183protected:
185 *module;
190 virtual void expire(Event *e);
191};
192
196class SunIPRoutingNode : public Module
197{
198
205
211 friend class AckWaiting;
212
218 friend class SinkProbeTimer;
219
225 friend class BufferTimer;
226
232 friend class SearchPathTimer;
233
234public:
239
243 virtual ~SunIPRoutingNode();
244
245 static const int LISTLENGTH = 30;
247 static const int MINUTE =
248 60;
251protected:
252 /*****************************
253 | Internal Functions |
254 *****************************/
265 virtual int command(int, const char *const *);
266
272 virtual void recv(Packet *);
273
281 virtual int recvSyncClMsg(ClMessage *);
282
291 virtual int recvAsyncClMsg(ClMessage *);
292
296 virtual void clearHops();
297
306 virtual void initialize();
307
311 virtual void printHopTable() const;
312
317 virtual void printSelectedRoutes() const;
318
325 inline const long &
327 {
328 return n_paths_established;
329 }
330
338 static string printIP(const nsaddr_t &);
339
347 static string printIP(const ns_addr_t &);
348
356 static nsaddr_t str2addr(const char *);
357
366 inline const double
367 getDelay(const double &period_) const
368 {
369 if (PoissonTraffic_)
370 return (-log(RNG::defaultrng()->uniform_double()) /
371 (1.0 / period_));
372 else
373 return 0;
374 }
375
388 inline const bool
389 isZero(const double &value) const
390 {
391 return std::fabs(value) < std::numeric_limits<double>::epsilon();
392 }
393
401 virtual const int &setNumberOfHopToSink(const int &);
402
413 virtual const int &getNumberOfHopToSink() const;
414
423 virtual void receiveProbe(const Packet *);
424
425 /*****************************
426 | Path Establishment Search |
427 *****************************/
436 virtual void searchPath();
437
444 virtual void initPktPathEstSearch(Packet *) const;
445
458 virtual void replyPathEstSearch(Packet *);
459
471 virtual const bool addMyIpInList(Packet *);
472
482 virtual const bool isMyIpInList(const Packet *) const;
483
490 virtual void updateQuality(Packet *);
491
492 /*****************************
493 | Path Establishment Answer |
494 *****************************/
503 virtual void answerPath(
504 const Packet *); // invoked only by a node with ho count = 1
505
515 virtual void initPktPathEstAnswer(Packet *,
516 const Packet *); // invoked only by a node with ho count = 1
517
527 virtual void sendRouteBack(Packet *);
528
540 virtual const int &evaluatePath(const Packet *);
541
542 /*****************************
543 | Data |
544 *****************************/
551 virtual void initPktDataPacket(Packet *);
552
563 virtual void forwardDataPacket(Packet *);
564
565 /*****************************
566 | Acks |
567 *****************************/
580 virtual void sendBackAck(const Packet *);
581
589 virtual void initPktAck(Packet *);
590
603 virtual void createRouteError(const Packet *, Packet *);
604
611 virtual void sendRouteErrorBack(Packet *);
612
613 /*****************************
614 | Load |
615 *****************************/
620 virtual void updatePacketsCount();
621
626 virtual void updateAcksCount();
627
636 virtual const int getPacketsLastMinute() const;
645 virtual const int getAcksLastMinute() const;
646
655 virtual const double getLoad() const;
656
657 /*****************************
658 | Buffering |
659 *****************************/
663 virtual void bufferManager();
664
665 /*****************************
666 | Statistics |
667 *****************************/
673 static inline const int
675 {
676 return sizeof(hdr_sun_ack);
677 }
678
684 static inline const int
686 {
687 return sizeof(hdr_sun_data);
688 }
689
695 static inline const int
697 {
698 return sizeof(hdr_sun_path_est);
699 }
700
706 inline const long &
708 {
709 return number_of_ackpkt_;
710 }
711
717 inline const long &
719 {
720 return number_of_datapkt_;
721 }
722
728 inline const long &
730 {
732 }
733
740 inline const long &
745
752 inline const long &
754 {
756 }
757
765 inline const long &
770
771 /*****************************
772 | Timers |
773 *****************************/
782 virtual void expTimerHopTable();
783
791 virtual void lostSink();
792
798 virtual void searchPathExpire();
799
800 /*****************************
801 | Trace file |
802 *****************************/
809 virtual void tracePacket(
810 const Packet *const, const string &position = "UNDEF___");
811
816 virtual string createTraceString(const string &, const double &,
817 const int &, const int &, const int &, const int &, const int &,
818 const int &, const int &, const double &, const int &, const int &);
819
826 virtual void writeInTrace(const string &);
827
828 enum {
832 };
834 // Variables
839 double
844 int
864 int
869 // Load
870 double
872 [LISTLENGTH];
888 bool
891 double alpha_;
894 // Acks
904 // Buffer
908 long
911 long pkt_tx_;
913 int
919 // Timers
932 // Trace file
933 bool trace_;
935 char
944 // Statistics
952 std::map<uint8_t, uint> paths_selected;
959 static long
963 static long number_of_datapkt_;
965 static long number_of_ackpkt_;
967 static long
976 static long
983private:
992};
993
994#endif // SUN_NODE_H
AckWaiting class is used to handle the timer of acks.
BufferTimer(SunIPRoutingNode *m)
SunIPRoutingNode *virtual void expire(Event *e)
< Pointer to an objet of type SunIPRoutingNode.
RemoveHopTableTimer class is used to handle the validity time of hop tables.
RemoveHopTableTimer(SunIPRoutingNode *m)
SunIPRoutingNode *virtual void expire(Event *e)
< Pointer to an objet of type SunIPRoutingNode.
SearchPathTimer class is used to handle the timer of Search Path requests.
SunIPRoutingNode *virtual void expire(Event *e)
< Pointer to an objet of type SunIPRoutingNode.
SearchPathTimer(SunIPRoutingNode *m)
SinkProbeTimer class is used to handle the validity time of a probe message.
virtual void expire(Event *e)
Method invoked when the SinkProbeTimer timer expires.
SinkProbeTimer(SunIPRoutingNode *m)
SunIPRoutingNode class is used to represent the routing layer of a node.
long list_acks_max_time_
Clock of the last ack received by the node.
virtual void replyPathEstSearch(Packet *)
Replies to Path Establishment Search packets.
static string printIP(const nsaddr_t &)
Returns a string with an IP in the classic form "x.x.x.x" converting an ns2 nsaddr_t address.
int pointer_packets_
Pointer of the first avaiable space in list_packets list.
double timer_route_validity_
Maximum validity time for a route entry.
uint max_retx_
Maximum Number of transmissions performed: real retransmissions counter the counter is increased only...
const long & getPathEstablishmentCount() const
Returns the number of Path Establishment packets processed by the entire network.
virtual void writeInTrace(const string &)
Opens the trace file, writes the string passed as input and closes the file.
vector< buffer_element > buffer_data
Buffer used to store data packets.
virtual void printSelectedRoutes() const
Print the nodes that were chosen as relay nodes to rach the sink and how many times each node was cho...
double timer_sink_probe_validity_
Maximum validity time for a sink probe.
ostringstream osstream_
Used to convert to string.
const long & getNPathsEstablished()
Print how many times the node was established as relay node for other nodes of the netwok.
char trace_separator_
Used as separator among elements in an entr of the tracefile.
static const int LISTLENGTH
Used by the load metric to set the number of the acks tracked.
bool search_path_enable_
Flag to enable or disable the possibility to send search_path packets.
static long number_of_datapkt_
Comulative number of Data packets processed by SunIPRoutingNode objects.
virtual int command(int, const char *const *)
TCL command interpreter.
const long & getForwardedCount() const
Returns the number of Data packets forwarded by the entire network.
virtual void initPktDataPacket(Packet *)
Initializes a data packet passed as argument with the default values.
virtual void createRouteError(const Packet *, Packet *)
Used to create a route error packet.
virtual void clearHops()
Clears all the route information of the current node.
double probe_min_snr_
Value below which if a node receives a probe it discards it.
static const int getDataPktHeaderSize()
Returns the size in byte of a hdr_sun_data packet header.
nsaddr_t * hop_table
List of IPs to reach the sink.
long n_paths_established
Number of times the node is established as realy node by the other nodes of the network.
virtual void forwardDataPacket(Packet *)
Forwards a data packet to the next hop.
virtual const int getPacketsLastMinute() const
Returns the number of packets processed by the current node in the last interval of time (MINUTE).
long list_packets_max_time_
Clock of the last packet received by the node.
int disable_path_error_
Flag to enable or disable the possibility to send Path Error packets.
std::map< uint8_t, uint > paths_selected
Map containing the nodes selected as relay to the sink and the number of times each node was selected...
bool trace_
Flag used to enable or disable the trace file for nodes,.
static long number_of_ackpkt_
Comulative number of Ack packets processed by SunIPRoutingNode objects.
virtual const int & getNumberOfHopToSink() const
Returns the number of hops that separate the node to the 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".
virtual void updatePacketsCount()
Updates the number of packets processed by the current node.
virtual const int & evaluatePath(const Packet *)
Evaluates the route information contained in a Path Establishment packet, and according to different ...
virtual void bufferManager()
Manage the buffer of the data packets.
const long & getDataDropsCountBuffer() const
Returns the number of packets dropped by the entire network for the reason: buffer is full.
int hop_table_length
Current length of the hop_table.
SinkProbeTimer sinkProbeTimer_
SinkProbeTimer object.
virtual const bool isMyIpInList(const Packet *) const
Checks if the IP of the current node is in the header of the packet passed as argument.
virtual void expTimerHopTable()
This function is invoked when the timer of the routing table expires.
int data_and_hops[MAX_HOP_NUMBER]
Structure that contains the number of data packets sent by the current node to the sink,...
virtual const int getAcksLastMinute() const
Returns the number of acks received by the current node in the last interval of time (MINUTE).
virtual void initPktPathEstSearch(Packet *) const
Initializes a Path Establishment Search packet (previously allocated).
SunIPRoutingNode(const SunIPRoutingNode &)
Copy constructor declared as private.
virtual void sendRouteBack(Packet *)
Forwards a Path Establishment Answer Packet.
ofstream trace_file_
Ofstream used to write the trace file in the disk.
char * trace_file_name_
Name of the trace file writter for the current 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 accepts a list of string and create an entry for the trace file.
int reset_buffer_if_error_
If == 1 when a node identify a broken link it will automatically free its buffer.
static long number_of_pathestablishment_
Comulative number of Path Establishment packets processed by SunIPRoutingNode objects.
static const int MINUTE
Used by the load metric to set the period to consider for the evaluation of the metric.
double snr_to_sink_
SNR between the sink and the current node.
static long number_of_pkt_forwarded_
Comulative number of Data packets forwarded by the network.
virtual void initPktAck(Packet *)
Initializes an ack packet passed as argument with the default values.
virtual void updateQuality(Packet *)
Updates the field quality in the packet passed as parameter.
double period_status_
Period of the Poisson traffic for status and ack packets.
BufferTimer bufferTmr_
BufferTimer object.
nsaddr_t sink_associated
IP of the sink associated to the node.
virtual void updateAcksCount()
Updates the number of acks received by the current node.
static const int getPathEstHeaderSize()
Returns the size in byte of a hdr_sun_path_est packet header.
double timer_buffer_
Timer for buffer management.
virtual void receiveProbe(const Packet *)
Invoked when the node receives a probe packet from a sink.
virtual const int & setNumberOfHopToSink(const int &)
Sets the number of hops that the current node needs to reach the sink.
double period_data_
Period of the Poisson traffic for data packets in the buffer.
virtual void sendBackAck(const Packet *)
Creates an ack packet and sends it to the previous hop using the information contained in the header ...
double list_acks[LISTLENGTH]
List of the last LISTLENGTH temporal instants in which the node received acks.
double alpha_
Parameters used by Load metric.
SearchPathTimer searchPathTmr_
SearchPathTimer object.
SunIPRoutingNode()
Constructor of SunIPRoutingNode class.
bool ack_error_state
true if the node is not in an error state (that means that it discovered a broken link),...
const long & getDataCount() const
Returns the number of Data packets processed by the entire network.
int PoissonTraffic_
Enable (1) or disable (0) the Poisson traffic for SUN packets.
const double getDelay(const double &period_) const
Returns a delay value to use in transmission.
static const int getAckHeaderSize()
Returns the size in byte of a hdr_sun_ack packet header.
const long & getAckCount() const
Returns the number of Ack packets processed by the entire network.
double quality_link
Quality of the link from the node to the sink.
virtual void lostSink()
This function removes all the information about routing information and sink association.
virtual void searchPath()
Sends a Path Establishment Packet with the option field sets to Search.
const long & getDataDropsCountMaxRetx() const
Returns the number of packets dropped by the entire network for the reason: maximum number of retrans...
uint32_t buffer_max_size_
Maximum length of the data buffer.
virtual void printHopTable() const
Prints in the stdout the routing table of the current node.
double list_packets[LISTLENGTH]
List of the last LISTLENGTH temporal instants in which the node received data packets.
virtual int recvSyncClMsg(ClMessage *)
Cross-Layer messages synchronous interpreter.
int ack_warnings_counter_
Number of acks lost since the last reset.
int max_ack_error_
Maximum number of Ack errors tollerated by the node.
virtual void searchPathExpire()
This function enable the possibility to send a new Seath Path packet.
int printDebug_
Flag to enable or disable dirrefent levels of debug.
virtual void sendRouteErrorBack(Packet *)
Send back an error packet to the previous hop.
virtual ~SunIPRoutingNode()
Destructor of SunIPRoutingNode class.
long pkt_stored_
Keep track of the total number of packet transmitted.
virtual void initialize()
Initializes a SunIPRoutingNode node.
static long number_of_drops_buffer_full_
Comulative number of packets dropped by SunIPRoutingNode objects, reason: the buffer is full.
virtual void tracePacket(const Packet *const, const string &position="UNDEF___")
Traces a packet.
virtual const double getLoad() const
Returns the load index of the current node combining the information from getPacketsLastMinute() and ...
nsaddr_t ipAddr_
IP of the current node.
int pointer_acks_
Pointer of the first avaiable space in list_acks list.
virtual const bool addMyIpInList(Packet *)
Adds the IP of the current node in the header of a Path Establishment packet passed as argument.
int metrics_
Metric used by the current node.
virtual int recvAsyncClMsg(ClMessage *)
Cross-Layer messages asynchronous interpreter.
RemoveHopTableTimer rmhopTableTmr_
RemoveHopTableTimer object.
long pkt_tx_
Keep track of the total number of packet retransmitted.
double timer_search_path_
Timer for the search path mechanism.
virtual void initPktPathEstAnswer(Packet *, const Packet *)
Initializes a Path Establishment Answer packet (previously allocated) retrieving the information from...
virtual void recv(Packet *)
Performs the reception of packets from upper and lower layers.
static long number_of_drops_maxretx_
Comulative number of packets dropped by SunIPRoutingNode objects, reason: max number of retransmissio...
virtual void answerPath(const Packet *)
Creates and sends an Path Establishment Answer packet.
const bool isZero(const double &value) const
Evaluates is the number passed as input is equal to zero.
int num_hop_to_sink
Number of hops needed to reach the sink using tha path saved tn the routing table.
int safe_timer_buffer_
Enables a mechanism used to modify the timer_buffer_ in case of the sending time is shorter than the ...
bool acks_array_full
true if list of acks is full, false otherwise.
bool packets_array_full
true if list of packets is full, false otherwise.
hdr_sun_ack describes acks packets used by UWSUN.
Definition sun-hdr-ack.h:52
hdr_sun_data describes data packets used by UWSUN
hdr_sun_path_est describes path establishment packets used by UWSUN
Provides the Ack Messages header description.
Provides the Data Messages header description.
Provides the Path Establishment Messages header description.
Common structures and definition used by SUN.
Provides the UWCBR packets header description and the definition of the class UWCBR.
static const int MAX_HOP_NUMBER
Maximum number of hops contained in a SUN Path Establishment packet.
Cross layer messages definition for the UWIP Module.
Provides the UWIP packets header description. Definition of the class that define the network layer.