DESERT 3.5.1
Loading...
Searching...
No Matches
uwmulti-stack-controller.h
Go to the documentation of this file.
1//
2// Copyright (c) 2014 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_STACK_CONTROLLER_H
39#define UWMULTI_STACK_CONTROLLER_H
40
41#include <rng.h>
42#include <packet.h>
43#include <module.h>
44#include <tclcl.h>
45#include <map>
46
47#include <iostream>
48#include <string.h>
49#include <cmath>
50#include <climits>
51#include "controller-clmsg.h"
52
53typedef std::map <int, double> ThresMap;
54typedef std::map <int, ThresMap> ThresMatrix;
59class UwMultiStackController : public Module {
60
61
62public:
63
64 // constant definitions
65 static int const layer_not_exist;
71
76
86 virtual int command(int, const char*const*);
87
94 virtual void addLayer(int id, int order);
95
104 virtual void addThreshold(int i, int j, double thres_ij);
105
111 virtual void recv(Packet *p);
112
120 int inline getOrder(int layer_id) { return id2order.find(layer_id)==id2order.end() ?
122 id2order.find(layer_id)->second; }
123
131 int inline getId(int layer_order) { return order2id.find(layer_order)==order2id.end() ?
133 order2id.find(layer_order)->second; }
134protected:
135 // Variables
142
143 int debug_;
144 double min_delay_;
147 std::map<int, int> id2order;
149 std::map<int, int> order2id;
156 virtual void recvFromUpperLayers(Packet *p);
157
166 virtual inline int getBestLayer(Packet *p) { assert(switch_mode_ == UW_AUTOMATIC_SWITCH);
167 return lower_id_active_; }
168
176 virtual bool isLayerAvailable(int id);
177
187 virtual double getMetricFromSelectedLowerLayer(int id, Packet* p);
188
198 virtual bool getThreshold(int i, int j, double& thres_ij);
199
208 virtual void eraseThreshold(int i, int j);
209
217 void inline setThreshold(int i, int j, double thres_ij) { threshold_map[i][j] = thres_ij; }
218
219private:
220 //Variables
221};
222
223#endif /* UWMULTI_STACK_CONTROLLER_H */
Class used to represents the UwMultiStackController layer of a node.
virtual void addThreshold(int i, int j, double thres_ij)
set the threshold value for the transition from layer i to layer j, checking first whether the layers...
int debug_
Flag to activate debug verbosity.
int getOrder(int layer_id)
return the order of the id for the controller logic
virtual int getBestLayer(Packet *p)
Return the best layer to forward the packet when the system works in AUTOMATIC_MODE.
virtual ~UwMultiStackController()
Destructor of UwMultiPhy class.
@ UW_AUTOMATIC_SWITCH
State to switch-mode automatically.
@ UW_MANUAL_SWITCH
State to switch-mode manually.
std::map< int, int > order2id
Return the layer order given its order in the threshold matrix.
virtual void addLayer(int id, int order)
Add a layer in the layer map.
virtual double getMetricFromSelectedLowerLayer(int id, Packet *p)
return the new metrics value obtained from the selected lower layer, in proactive way via ClMessage
virtual int command(int, const char *const *)
TCL command interpreter.
int lower_id_active_
<Current switch mode (either AUTOMATIC or MANUAL).
virtual void eraseThreshold(int i, int j)
remove the threshold value for the transition from layer i to layer j, checking first whether the lay...
virtual void recv(Packet *p)
recv method.
static int const layer_not_exist
This constant is returned when a searched layer does not exist>
virtual bool isLayerAvailable(int id)
return if the specified layer, identified by id, is available
UwMultiStackController()
Constructor of UwMultiPhy class.
virtual void recvFromUpperLayers(Packet *p)
By default the signaling is not employed, if it is needed, here where to set the signaling packet siz...
ThresMatrix threshold_map
Returns the switch layer theshold given a layer order.
void setThreshold(int i, int j, double thres_ij)
set the threshold value for the transition from layer i to layer j
virtual bool getThreshold(int i, int j, double &thres_ij)
get the threshold value for the transition from layer i to layer j, checking first whether the layers...
std::map< int, int > id2order
Maps each layer id to its order in the threshold matrix.
int getId(int layer_order)
return the id of the controlled layer given its order in the controller logic
std::map< int, double > ThresMap
Threshoold map <PHY_order, threshold>
std::map< int, ThresMap > ThresMatrix
Thresholds matrix.