DESERT 3.5.1
Loading...
Searching...
No Matches
uwmulti-destination.h
Go to the documentation of this file.
1//
2// Copyright (c) 2018 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
38#ifndef UWMULTI_DESTINATION_H
39#define UWMULTI_DESTINATION_H
40
41#include <climits>
42#include <cmath>
43#include <iostream>
44#include <map>
45#include <list>
46#include <module.h>
47#include <packet.h>
48#include <rng.h>
49#include <string.h>
50#include <tclcl.h>
51#include <uwip-module.h>
52
53typedef struct IP_range
54{
55 int min_IP;
56 int max_IP;
58 IP_range(int min, int max)
59 :
60 min_IP(min),
61 max_IP(max)
62 {
63 }
64
71 {
72 return overlappingRange(range.min_IP, range.max_IP);
73 }
74
81 bool overlappingRange(int min, int max)
82 {
83 return !(min_IP > max || max_IP < min);
84 }
85
91 bool isInRange(int addr)
92 {
93 return (addr >= min_IP && addr <= max_IP);
94 }
96
97typedef std::pair<int, IP_range> layer_IPrange;
98
99
103class UwMultiDestination : public Module
104{
105
106public:
107 // constant definitions
108 static int const layer_not_exist;
115
120 {
121 }
122
134 virtual int command(int, const char *const *);
135
144 virtual bool addLayer(IP_range range, int id);
145
151 virtual void recv(Packet *p);
152
153protected:
154 // Variables
160
161 int debug_;
167 std::list<layer_IPrange> layer_list;
177 virtual void recvFromUpperLayers(Packet *p);
178
188 virtual int getDestinationLayer(Packet *p);
189
197 virtual bool checkNotOverlap(IP_range range);
198
199private:
200 // Variables
201};
202
203#endif /* UWMULTI_DESTINATION_H */
Class used to represents the UwMultiDestination layer of a node.
UwMultiDestination()
Constructor of UwMultiDestination class.
int default_lower_id
Maps a layer id into an IP_range.
std::list< layer_IPrange > layer_list
int lower_id_active_
Id of the current lower layer active.
@ UW_AUTOMATIC_SWITCH
State to switch-mode automatically.
@ UW_MANUAL_SWITCH
State to switch-mode manually.
virtual void recvFromUpperLayers(Packet *p)
Default lower id to use if dest adress is not found in the considered IP ranges.
static int const layer_not_exist
This constant is returned when a searched layer does not exist>
int debug_
Flag to activate debug verbosity.
virtual bool checkNotOverlap(IP_range range)
return true if there is not overlap between the new range and the previous rnage in the list
virtual ~UwMultiDestination()
Destructor of UwMultiDestination class.
Mode switch_mode_
Current switch mode (either AUTOMATIC or MANUAL).
virtual int command(int, const char *const *)
TCL command interpreter.
virtual void recv(Packet *p)
recv method.
virtual bool addLayer(IP_range range, int id)
Add a layer in the layer map if the IP range is valide, i.e., if the range doesn't overlap with an ex...
virtual int getDestinationLayer(Packet *p)
Return the best layer to forward the packet when the system works in AUTOMATIC_MODE.
IP_range(int min, int max)
bool isInRange(int addr)
Check if the given IP addr is in the range.
int max_IP
Maximum IP address of the range.
int min_IP
Minimum IP address of the range.
bool overlappingRange(IP_range range)
Return true if the 2 ranges are not overlapped.
bool overlappingRange(int min, int max)
Return true if the 2 ranges are overlapped.
Provides the UWIP packets header description. Definition of the class that define the network layer.
struct IP_range range_IP
std::pair< int, IP_range > layer_IPrange