DESERT 3.5.1
Loading...
Searching...
No Matches
uwmulti-stack-controller.cc
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
39
43static class UwMultiStackControllerClass : public TclClass
44{
45public:
49 UwMultiStackControllerClass() : TclClass("Module/UW/MULTI_STACK_CONTROLLER") {}
54 TclObject* create(int, const char*const*)
55 {
56 return (new UwMultiStackController);
57 }
59
61
63:
64 Module(),
65 debug_(0),
66 min_delay_(0),
67 switch_mode_(UW_MANUAL_SWITCH),
68 lower_id_active_(0),
69 signaling_pktSize_(1)
70{
71 bind("debug_", &debug_);
72 bind("min_delay_", &min_delay_);
73 bind("switch_mode_", (int*) &switch_mode_);
74 bind("set_lower_id_active_", &lower_id_active_);
75 bind("signaling_pktSize_", &signaling_pktSize_);
76}
77
78int UwMultiStackController::command(int argc, const char*const* argv)
79{
80 if (argc == 2)
81 {
82 if(strcasecmp(argv[1], "setAutomaticSwitch") == 0)
83 {
85 return TCL_OK;
86 }
87 else if(strcasecmp(argv[1], "setManualSwitch") == 0)
88 {
90 return TCL_OK;
91 }
92 }
93 else if (argc == 3)
94 {
95 if(strcasecmp(argv[1], "setManualLowerlId") == 0)
96 {
97 lower_id_active_ = atoi(argv[2]);
98 return TCL_OK;
99 }
100 }
101 else if (argc == 4)
102 {
107 if(strcasecmp(argv[1], "addLayer") == 0)
108 {
109 addLayer(atoi(argv[2]),atoi(argv[3]));
110 return TCL_OK;
111 }
112 }
113 else if (argc == 5)
114 {
118 if(strcasecmp(argv[1], "addThreshold") == 0)
119 {
120 addThreshold(atoi(argv[2]),atoi(argv[3]),atof(argv[4]));
121 return TCL_OK;
122 }
123 }
124
125 return Module::command(argc, argv);
126} /* UwMultiStackController::command */
127
128void UwMultiStackController::addLayer(int id, int order)
129{
130 assert(order > 0);
131 id2order.erase(id);
132 id2order.insert((std::pair<int,int>(id,order)));
133 order2id.erase(order);
134 order2id.insert((std::pair<int,int>(order,id)));
135}
136
137void UwMultiStackController::addThreshold(int i, int j, double thres_ij){
138 assert (id2order.find(i) != id2order.end() && id2order.find(j) != id2order.end() && i!=j);
139 setThreshold(i,j,thres_ij);
140}
141
143{
144 hdr_cmn *ch = HDR_CMN(p);
145 if(ch->direction() == hdr_cmn::UP)
146 {
147 sendUp(p, min_delay_);
148 }
149 else
150 {
151 //direction DOWN: packet is coming from upper layers
153 }
154}
155
157{
158 /*hdr_cmn *ch = HDR_CMN(p);*/
159
160 if(switch_mode_ == UW_AUTOMATIC_SWITCH) /*&& ch->ptype() == CONTROLLED)*/
161 {
162 sendDown( getBestLayer(p), p, min_delay_);
163 }
164 else
165 {
166 sendDown(lower_id_active_, p, min_delay_);
167 }
168}
169
171{
172 return id2order.find(id) != id2order.end();
173}
174
176{
177 ClMsgController m(id, p);
178 sendSyncClMsgDown(&m);
179 return m.getMetrics();
180}
181
182bool UwMultiStackController::getThreshold(int i, int j, double& thres_ij) {
183 ThresMatrix::iterator it = threshold_map.find(i);
184 if (it != threshold_map.end()) {
185 ThresMap thres_i = it->second;
186 ThresMap::iterator it_thres_ij = thres_i.find(j);
187 if(it_thres_ij != thres_i.end()) {
188 thres_ij = it_thres_ij->second;
189 return true;
190 }
191 else
192 return false;
193 }
194 return false;
195}
196
198 ThresMatrix::iterator it = threshold_map.find(i);
199 if (it != threshold_map.end()) {
200 ThresMap thres_i = it->second;
201 ThresMap::iterator it_thres_ij = thres_i.find(j);
202 if(it_thres_ij != thres_i.end())
203 thres_i.erase(j);
204 if(thres_i.size() == 0)
205 threshold_map.erase(i);
206 }
207}
Class that represents the binding with the tcl configuration script.
TclObject * create(int, const char *const *)
Creates the TCL object needed for the tcl language interpretation.
UwMultiStackControllerClass()
Constructor of the class.
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.
virtual int getBestLayer(Packet *p)
Return the best layer to forward the packet when the system works in AUTOMATIC_MODE.
@ 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.
UwMultiStackControllerClass class_stack_controller
Definition of UwMultiStackController class.
std::map< int, double > ThresMap
Threshoold map <PHY_order, threshold>