DESERT 3.5.1
Loading...
Searching...
No Matches
uwmulti-multiphy-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_MULTIPHY_CONTROLLER_H
39#define UWMULTI_MULTIPHY_CONTROLLER_H
40
41#include <rng.h>
42#include <uwip-module.h>
43#include <uwcbr-module.h>
44#include <uwmulti-cmn-hdr.h>
45#include <packet.h>
46#include <module.h>
47#include <tclcl.h>
48#include <map>
49#include <vector>
50#include <queue>
51
52#include <iostream>
53#include <string.h>
54#include <cmath>
55#include <climits>
56#include <limits>
57
58std::string printType(packet_t ptype) {
59 if (ptype == PT_UWMULTIPHY_DATA) {
60 return "PT_UWMULTIPHY_DATA";
61 }
62 if (ptype == PT_UWMULTIPHY_PING) {
63 return "PT_UWMULTIPHY_PING";
64 }
65 if (ptype == PT_UWMULTIPHY_PONG) {
66 return "PT_UWMULTIPHY_PONG";
67 }
68 return "Unknown packet";
69}
70
72
73std::ostream& operator<<(std::ostream &o, LinkStatus s)
74{
75 switch (s) {
76 case LINK_UNKNOWN: return o << "LINK_UNKNOWN";
77 case LINK_OK: return o << "LINK_OK";
78 case LINK_PROBING: return o << "LINK_PROBING";
79 default: return o<<"(invalid value)";
80 }
81}
82
83// connection between local application and local MAC layer
87
88 bool operator==(const LocalConnection &o) const
89 {
90 return trafficType == o.trafficType && localMacID == o.localMacID;
91 }
92
93 bool operator<(const LocalConnection &o) const
94 {
95 // this total order relationship has no actual meaning, only needed
96 // to use struct as key in a map
98 }
99
100 friend std::ostream& operator<<(std::ostream& os, const LocalConnection &c)
101 {
102 os << "<LocalConnection(trafficType=" << c.trafficType << "," << "localMacID=" << c.localMacID << ")>";
103 return os;
104 }
105};
106
107// connection between local MAC layer and remote destination IP
111
112 bool operator==(const RemoteConnection &o) const
113 {
114 return remoteIP == o.remoteIP && localMacID == o.localMacID;
115 }
116
117 bool operator<(const RemoteConnection &o) const
118 {
119 // this total order relationship has no actual meaning, only needed
120 // to use struct as key in a map
121 return remoteIP < o.remoteIP || localMacID < o.localMacID;
122 }
123
124 friend std::ostream& operator<<(std::ostream& os, const RemoteConnection &c)
125 {
126 os << "<RemoteConnection(localMacID=" << c.localMacID << "," << "remoteIP=" << c.remoteIP << ")>";
127 return os;
128 }
129};
130
132private:
134
135 //* default priority for each MAC
136 std::map<int, int> defaultPriorities;
137
138 //* custom priority for a given (local) traffic on each available MAC module
139 std::map<LocalConnection, int > customPriorities;
140
141public:
142 PriorityMap();
143
144 PriorityMap(int debug_);
145
152 void addCustomPriority(LocalConnection c, int priority);
153
160 void setDefaultPriority(int macID, int priority);
161
170
171 friend std::ostream& operator<< (std::ostream&, const PriorityMap&);
172};
173
177class UwMultiPhyControl : public Module {
178private:
180
181 // characterize current node
183 std::vector<int> macIDs;
184
185 std::queue<Packet*> packet_queue;
186
187 //* each MAC state gets LINK_UNKNOWN after a timeout
188 class ResilienceTimer;
189 std::map<int, double> resilienceTimeouts;
190 std::map<RemoteConnection, ResilienceTimer> resilienceTimers;
191
192 //* each MAC state gets probed again after a timeout
193 class ProbeTimer;
194
195 std::map<int, double> probeTimeouts;
196 std::map<RemoteConnection, ProbeTimer> probeTimers;
197
198 // encode here how to choose the MAC for an application that
199 // wants to communicate to a remote destination
201
202 std::map<RemoteConnection, int> linkStatuses;
203
207 std::map<int, int> macResilience;
208
209 std::map<int, int> macTclIdLayerId;
210
211 void initialize();
212
213 int getBestMacID(int trafficType, int remoteIP);
214
216
218 void recvFromUpperLayers(Packet *p);
219
220 void recvFromLowerLayers(Packet *p, int macID);
221
222public:
227
231 virtual ~UwMultiPhyControl() { }
232
233 virtual int command(int, const char*const*);
234
235 void recv(Packet *p);
236
237 void recv(Packet *p, int idSrc);
238
239 // timer classes
240private:
241
242 class ResilienceTimer : public TimerHandler {
243 private:
244 UwMultiPhyControl* module;
247
252 virtual void expire(Event *e);
253
254 public:
255 // default constructor is needed to be value of a map
256 // set meaningless values then
257 ResilienceTimer() : TimerHandler()
258 {
259 this->module = NULL;
260
262 c.localMacID = 0;
263 c.remoteIP = 0;
264
265 this->conn = c;
266 };
267
269 TimerHandler()
270 {
271 this->module = m;
272 this->conn = c;
273 if (this->module != NULL && this->module->debug_ >= 3) {
274 std::cout << NOW
275 << "::UwMultiPhyControl::ResilienceTimer::constructor"
276 << "::localIP(" << this->module->localIP << ")"
277 << "::localMAC(" << this->conn.localMacID << ")"
278 << "::remoteIP(" << this->conn.remoteIP << ")"
279 << std::endl;
280 }
281 }
283 if (this->module != NULL && this->module->debug_ >= 3) {
284 std::cout << NOW
285 << "::UwMultiPhyControl::ResilienceTimer::destructor"
286 << "::localMacID(" << this->conn.localMacID << ")"
287 << "::remoteIP(" << this->conn.remoteIP << ")"
288 << "::module(" << this->module << ")"
289 << "::this(" << this << ")"
290 << std::endl;
291 }
292 }
293 };
294
295 class ProbeTimer : public TimerHandler {
296 private:
297 UwMultiPhyControl* module;
299
304 virtual void expire(Event *e);
305
306 public:
307 // default constructor is needed to be value of a map
308 // set meaningless values then
309 ProbeTimer() : TimerHandler()
310 {
311 this->module = NULL;
312
314 c.localMacID = 0;
315 c.remoteIP = 0;
316
317 this->conn = c;
318 };
319
321 {
322 this->module = m;
323 this->conn = c;
324 };
325
327 if (this->module != NULL && this->module->debug_ >= 3) {
328 std::cout << NOW
329 << "::UwMultiPhyControl::ProbeTimer::destructor"
330 << "::localMacID(" << this->conn.localMacID << ")"
331 << "::remoteIP(" << this->conn.remoteIP << ")"
332 << "::module(" << this->module << ")"
333 << "::this(" << this << ")"
334 << std::endl;
335 }
336 }
337 };
338};
339
340#endif
friend std::ostream & operator<<(std::ostream &, const PriorityMap &)
std::map< int, int > defaultPriorities
void addCustomPriority(LocalConnection c, int priority)
Set MAC priority for packets coming from a specific traffic type.
int getPriority(LocalConnection c)
Get priority of a certain MAC for packets of given traffic type (using default priority if a custom o...
std::map< LocalConnection, int > customPriorities
void setDefaultPriority(int macID, int priority)
Set MAC default priority regardless of origin traffic type.
ProbeTimer(UwMultiPhyControl *m, RemoteConnection c)
UwMultiPhyControl *RemoteConnection conn
virtual void expire(Event *e)
Timer expire procedure: handles the PROBE timeout.
UwMultiPhyControl *RemoteConnection conn
< Pointer to the module class where the timer is used
virtual void expire(Event *e)
Timer expire procedure: handles the PROBE timeout.
ResilienceTimer(UwMultiPhyControl *m, RemoteConnection c)
Class used to represents the UwMultiPhyControl layer of a node.
std::map< RemoteConnection, ResilienceTimer > resilienceTimers
UwMultiPhyControl()
Constructor of UwMultiPhy class.
std::map< RemoteConnection, int > linkStatuses
std::map< int, double > resilienceTimeouts
std::queue< Packet * > packet_queue
std::map< int, int > macTclIdLayerId
int getBestMacID(int trafficType, int remoteIP)
void updateAvailability(RemoteConnection c, LinkStatus status)
std::map< RemoteConnection, ProbeTimer > probeTimers
void sendPing(RemoteConnection c)
virtual int command(int, const char *const *)
void recvFromLowerLayers(Packet *p, int macID)
std::map< int, double > probeTimeouts
std::map< int, int > macResilience
<macID, resilience> where resilience score enstablish an order across local MAC layers: if a less rob...
virtual ~UwMultiPhyControl()
Destructor of UwMultiPhy class.
bool operator<(const LocalConnection &o) const
friend std::ostream & operator<<(std::ostream &os, const LocalConnection &c)
bool operator==(const LocalConnection &o) const
friend std::ostream & operator<<(std::ostream &os, const RemoteConnection &c)
bool operator<(const RemoteConnection &o) const
bool operator==(const RemoteConnection &o) const
Provides the UWCBR packets header description and the definition of the class UWCBR.
Provides the UWIP packets header description. Definition of the class that define the network layer.
std::ostream & operator<<(std::ostream &o, LinkStatus s)
std::string printType(packet_t ptype)