DESERT 3.5.1
Loading...
Searching...
No Matches
uwflooding-sec.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
40#ifndef UWFLOODINGSEC_H
41#define UWFLOODINGSEC_H
42
43#define TTL_EQUALS_TO_ZERO \
44 "TEZ"
46#include "uwflooding-hdr.h"
47
48#include <uwip-module.h>
49#include <uwip-clmsg.h>
50#include <uwcbr-module.h>
51
52#include "mphy.h"
53#include "packet.h"
54#include <module.h>
55#include <tclcl.h>
56
57#include <cmath>
58#include <limits>
59#include <sstream>
60#include <string>
61#include <iostream>
62#include <rng.h>
63#include <ctime>
64#include <vector>
65#include <fstream>
66#include <map>
67#include <list>
68
69#include "uwbase_reputation.h"
70
71
73class UwFloodingSec;
74
79class NeighborReputationHandler : public TimerHandler
80{
81public:
82
90 NeighborReputationHandler(uint8_t neigh_addr, UwFloodingSec* m,
91 double alpha_val, int dbg);
92
97
104 bool addUnconfirmedPkt(int uid, double expire_time);
105
112 bool checkUnconfirmedPkt(int uid);
113
119 void updateChannelMetrics(double val_snr, double last_noise_val);
120
125 void updateInstantNoise(double inst_noise_val);
126
127protected:
128
136 bool getNextPacket(int& uid, double& exp_time) const;
137
141 void removeOldPackets();
142
147 virtual void expire(Event *e);
148
149 UwFloodingSec* module;
151 std::map<int, double> unconfirmed_pkts;
156 double avg_snr;
157 double alpha;
160 double last_noise;
161 double inst_noise;
162 int debug;
163};
164
168class UwFloodingSec : public Module
169{
171
172public:
177
181 virtual ~UwFloodingSec();
182
183protected:
184 /*****************************
185 | Internal Functions |
186 *****************************/
197 virtual int command(int, const char *const *);
198
204 virtual void recv(Packet *);
205
213 virtual int recvSyncClMsg(ClMessage *);
214
223 virtual int recvAsyncClMsg(ClMessage *);
224
232 static nsaddr_t str2addr(const char *);
233
239 virtual void writePathInTrace(const Packet *, const string &);
240
248 static string printIP(const nsaddr_t &);
249
255 void addToNeighbor(uint8_t neighbor_addr);
256
261 void printNeighbor();
262
269 bool checkUnconfirmedPkt(uint8_t neighbor_addr, int uid);
270
276 void sendDown(Packet* p, double delay=0);
277
284 virtual void sendStatsClMsg(int neighbor_addr);
285
291 void retrieveInstantNoise(int neighbor_addr);
292
293private:
294 // Variables
295
297 int ttl_;
304 char
312 typedef std::map<uint16_t, double> map_packets;
315 typedef std::map<uint8_t, map_packets>
321 std::map<uint16_t,uint8_t> ttl_traffic_map;
325 typedef std::map<uint8_t, uint> neighbor_map;
329 typedef std::map<uint8_t, NeighborReputationHandler> neighbor_timer_map;
333 double fwd_to;
340 double alpha_snr;
354
362 uint8_t getTTL(Packet* p) const;
363};
364
365#endif // UWFLOODING_H
Provides the header description for UWFLOODING packets.
This class defines the timer used to check the packet forwarding by the neighbor and handle reputatio...
double inst_noise
Instantaneous noise level.
double avg_snr
Uid of the packet that should be forwarded.
bool addUnconfirmedPkt(int uid, double expire_time)
Add in the map the unconfirmed packets with the corresponidg timeout.
void updateInstantNoise(double inst_noise_val)
Update the value of the instantaneous noise.
std::map< int, double > unconfirmed_pkts
Map with the uid of the unconfirmed packets, with the corresponding forwarding timeout.
bool is_running
True if a timer has been already scheduled and not expired yet.
double alpha
weight for the new SNR value.
virtual void expire(Event *e)
Method called when the timer expire.
virtual ~NeighborReputationHandler()
Class destructor.
void removeOldPackets()
Removes packet with an old expire time.
double last_noise
Boolean variable to check if the packet is the first received one or not.
UwFloodingSec *uint8_t neighbor_addr
< Pointer to the uwflooding module.
void updateChannelMetrics(double val_snr, double last_noise_val)
Update average SNR.
bool getNextPacket(int &uid, double &exp_time) const
Returns as reference the uid of the next packet that id going to expire.
bool checkUnconfirmedPkt(int uid)
Check if the packet with the given uid is an unconfirmed one and set it as confirmed.
UwFloodingSec class is used to represent the routing layer of a node.
double alpha_snr
Value to be used by the NeighborReputationHandler object to combine new snr values and average snr.
std::map< uint8_t, map_packets > map_forwarded_packets
Typedef for a map of the packet forwarded (saddr, map_packets).
void retrieveInstantNoise(int neighbor_addr)
Send ClMsgStats to retreive instantaneous noise.
std::map< uint16_t, double > map_packets
Typedef for a packet id: (serial_number, timestamp).
virtual int recvSyncClMsg(ClMessage *)
Cross-Layer messages synchronous interpreter.
std::map< uint16_t, uint8_t > ttl_traffic_map
Map with ttl per traffic.
double fwd_to
Time out within which the forwarding is expected.
bool valid_phy_id
True if the id of the phy layer from which obtain the statistics is a valid one.
virtual int recvAsyncClMsg(ClMessage *)
Cross-Layer messages asynchronous interpreter.
uint8_t prev_hop_temp
Previous hop IP address of the last received packet.
virtual int command(int, const char *const *)
TCL command interpreter.
neighbor_map neighbor
Map with the neighbor.
int stats_phy_id
id of the physical layer from which collect the statistics.
int optimize_
Flag used to enable the mechanism to drop packets processed twice.
std::map< uint8_t, uint > neighbor_map
Typdef for a map of the neighbor with the number of packets received from him.
ostringstream osstream_
Used to convert to string.
virtual ~UwFloodingSec()
Destructor of UwFloodingSec class.
void addToNeighbor(uint8_t neighbor_addr)
Adds a node in the neighbor map, updating the number of packets received from that node.
neighbor_timer_map neighbor_tmr
Map with the neighbor timer.
virtual void sendStatsClMsg(int neighbor_addr)
Send ClMsgStats message when triggered by the reception of an overherd packets.
int ttl_
Time to leave of the UWFLOODING packets.
virtual void recv(Packet *)
Performs the reception of packets from upper and lower layers.
bool checkUnconfirmedPkt(uint8_t neighbor_addr, int uid)
Check if the received packets is an unconfirmed one.
UwFloodingSec(const UwFloodingSec &)
Copy constructor declared as private.
ofstream trace_file_path_
Ofstream used to write the path trace file in the disk.
UwReputationInterface * reputation
Reputation of the neighbor.
bool use_reputation
True if the reputation system is used.
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".
void printNeighbor()
Prints the neighbor list togheter with the number of packets received from the neighbor.
bool trace_path_
Flag used to enable or disable the path trace file for nodes,.
std::map< uint8_t, NeighborReputationHandler > neighbor_timer_map
Typedef for the forwardig timer of the neigbors.
char * trace_file_path_name_
Name of the trace file that contains the list of paths of the data packets received.
map_forwarded_packets my_forwarded_packets_
Map of the packet forwarded.
long packets_forwarded_
Number of packets forwarded by this module.
virtual void writePathInTrace(const Packet *, const string &)
Writes in the Path Trace file the path contained in the Packet.
UwFloodingSec()
Constructor of UwFloodingSec class.
double maximum_cache_time_
Validity time of a packet entry.
uint8_t getTTL(Packet *p) const
Get the value of the TTL.
void sendDown(Packet *p, double delay=0)
Send down packets and start forwarding timer.
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.
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.