DESERT 3.5.1
Loading...
Searching...
No Matches
uwicrp-module-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
40#ifndef UWICRP_MODULE_NODE_H
41#define UWICRP_MODULE_NODE_H
42
43#include "uwicrp-hdr-ack.h"
44#include "uwicrp-hdr-data.h"
45#include "uwicrp-hdr-status.h"
46#include "uwicrp-common.h"
47#include <uwip-module.h>
48#include <uwip-clmsg.h>
49
50#include "packet.h"
51#include <sstream>
52#include <string>
53#include <iostream>
54#include <rng.h>
55#include <ctime>
56#include <climits>
57#include <module.h>
58#include <tclcl.h>
59#include <vector>
60
61
62
63class UwIcrpNode;
64
70class AckWaiting : public TimerHandler
71{
72public:
74 : TimerHandler()
75 {
76 module = m;
77 }
78
79protected:
80 virtual void expire(Event *e);
81 UwIcrpNode *module;
82};
83
87class UwIcrpNode : public Module
88{
89 friend class AckWaiting;
90
91public:
95 UwIcrpNode();
96
100 ~UwIcrpNode();
101
102protected:
110 virtual int recvSyncClMsg(ClMessage *);
111
120 virtual int recvAsyncClMsg(ClMessage *);
121
132 virtual int command(int, const char *const *);
133
139 virtual void recv(Packet *);
140
149 virtual void initialize();
150
156 virtual void clearRouteTable(const int &);
157
161 virtual void clearAllRouteTable();
162
168 virtual void initPkt(Packet *);
169
175 virtual void addRouteEntry(Packet *);
176
185 virtual int findInRouteTable(nsaddr_t);
186
197 virtual bool isIpInList(Packet *, nsaddr_t);
198
209 virtual bool addIpInList(Packet *, nsaddr_t);
210
214 virtual void printHopTable();
215
223 virtual string printIP(const uint8_t);
224
232 nsaddr_t str2addr(const char *);
233
240 virtual void sendBackAck(const Packet *p);
241
247 virtual void initPktAck(Packet *p);
248
252 virtual void ackLost();
253
259 static inline const int
261 {
262 return sizeof(hdr_uwicrp_ack);
263 }
264
270 static inline const int
272 {
273 return sizeof(hdr_uwicrp_data);
274 }
275
281 static inline const int
283 {
284 return sizeof(hdr_uwicrp_status);
285 }
286
287 uint8_t ipAddr_;
288 uint8_t ipSink_;
297private:
298 static long numberofstatuspkt_;
300 static long numberofdatapkt_;
302 static long
305};
306
307#endif // UWICRP_MODULE_NODE_H
AckWaiting class is used to handle the timer of acks.
AckWaiting(UwIcrpNode *m)
virtual void expire(Event *e)
UwIcrpNode class is used to represent the routing layer of a node.
virtual void clearAllRouteTable()
Clears completely the routing table of the node.
virtual void addRouteEntry(Packet *)
Adds the information received from a Status packet in the routing table of the node.
virtual void sendBackAck(const Packet *p)
Creates an ack packet after the reception a data packet received correctly.
nsaddr_t str2addr(const char *)
Returns a nsaddr_t address from an IP written as a string in the form "x.x.x.x".
uint8_t ipSink_
IP of the sink associated.
virtual string printIP(const uint8_t)
Return a string with an IP in the classic form "x.x.x.x" converting an ns2 nsaddr_t address.
virtual void ackLost()
Resets all the routing information because the lost of an ack.
double max_validity_time_
Maximum validity time of a route.
virtual void initPktAck(Packet *p)
Initializes an Ack packet (previously allocated).
static const int getStatusPktHeaderSize()
Returns the size in byte of a hdr_uwicrp_status packet header.
virtual int command(int, const char *const *)
TCL command interpreter.
static long numberofstatuspkt_
Comulative number of Status packets processed by UwIcrpNode objects.
virtual bool addIpInList(Packet *, nsaddr_t)
Adds an IP passed as argument in the header of a Data packet passed as argument.
virtual void initialize()
Initializes a UwIcrpNode node.
uint8_t ipAddr_
IP of the current node.
static long numberofackpkt_
Comulative number of Ack packets processed by UwIcrpNode objects.
static const int getAckPktHeaderSize()
Returns the size in byte of a hdr_uwicrp_ack packet header.
routing_table_entry route_table[HOP_TABLE_LENGTH]
Node routing table.
virtual int recvAsyncClMsg(ClMessage *)
Initializes a UwIcrpSink node.
AckWaiting ackwaitingTmr_
AckWaiting object.
virtual void initPkt(Packet *)
Initializes a Data packet (previously allocated).
static long numberofdatapkt_
Comulative number of Data packets processed by UwIcrpNode objects.
virtual bool isIpInList(Packet *, nsaddr_t)
Checks if a specific IP is in the header of the packet passed as argument.
virtual void printHopTable()
Prints in the stdout the routing table of the current node.
virtual int findInRouteTable(nsaddr_t)
Seeks for an entry in the routing table that contains information to a specific address passed as arg...
static const int getDataPktHeaderSize()
Returns the size in byte of a hdr_uwicrp_data packet header.
UwIcrpNode()
Constructor of UwIcrpNode class.
~UwIcrpNode()
Destructor of UwIcrpNode class.
virtual int recvSyncClMsg(ClMessage *)
Cross-Layer messages synchronous interpreter.
virtual void recv(Packet *)
Performs the reception of packets from upper and lower layers.
int printDebug_
Flag to enable or disable dirrefent levels of debug.
virtual void clearRouteTable(const int &)
Removes a specific entry in the routing table of the node.
double timer_ack_waiting_
Ack waiting timer.
hdr_uwicrp_ack describes acks packets used by UWICRP.
hdr_uwicrp_data describes data packets used by UWICRP
hdr_uwicrp_status describes status packets used by UWICRP
routing_table_entry describes an entry in the routing table used by UWICRP.
Common structures and definition used by UWICRP.
static const int HOP_TABLE_LENGTH
Maximum length of the routing table of a node FOR UWICRP.
Provides the Ack Messages header description.
Provides the Data Messages header description.
Provides the Status Messages header description.
Cross layer messages definition for the UWIP Module.
Provides the UWIP packets header description. Definition of the class that define the network layer.