DESERT 3.5.1
Loading...
Searching...
No Matches
uwmulti-traffic-control.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_TRAFFIC_Control_H
39#define UWMULTI_TRAFFIC_Control_H
40
41#include <rng.h>
42#include <packet.h>
43#include <module.h>
44#include <tclcl.h>
45#include <map>
46#include <queue>
47#include <iostream>
48#include <string.h>
49#include <cmath>
50#include <climits>
51#include <algorithm>
52
53// DEFINE BEHAVIORS
54#define DEFAULT 1
55
56struct BufferType {
58 DISCARD_INCOMING = 0, // Discard incoming packets
59 CIRCULAR // Discard old packets (first packets in the queue)
60 };
61 uint max_size;
63 double send_delay;
64 uint pkts_lost;
67 BufferType(uint size, BufferBehavior behav, double del)
68 :
69 max_size(size),
70 behavior_buff(behav),
71 send_delay(del),
72 pkts_lost(0),
74 {
75 }
76
77 double getUpdatedDelay(double time_instant) {
78 if ((time_instant - last_sched_tx) >= send_delay) {
79 last_sched_tx = time_instant;
80 return 0; //last_sched_tx - time_instant
81 } else {
83 return std::max(last_sched_tx - time_instant, 0.0); //max to avoid problem with double precision
84 }
85 }
86};
87
88// DEFINE STATES
89
90typedef std::map <int, int> UpTrafficMap;
91typedef std::pair <int, int> BehaviorItem;
92typedef std::map <int, BehaviorItem> BehaviorMap;
93typedef std::map <int, BehaviorMap> DownTrafficMap;
94typedef std::queue<Packet*> Buffer;
95typedef std::map <int, Buffer*> DownTrafficBuffer;
97typedef std::map <int,BufferType> BufferTrafficFeature;
98
102class UwMultiTrafficControl : public Module {
103
104
105public:
106
111
116
126 virtual int command(int, const char*const*);
127
133 virtual void recv(Packet *p);
134
135protected:
136
137 int debug_;
148 virtual void recvFromUpperLayers(Packet *p);
149
156 virtual void manageBuffer(int traffic);
157
164 virtual void insertInBuffer(Packet *p, int traffic);
165
173 virtual Packet * removeFromBuffer(int traffic);
174
182 virtual Packet * getFromBuffer(int traffic);
183
190 void inline insertTraffic2UpLayer(int traffic, int upper_layer_id) {
191 up_map[traffic] = upper_layer_id;
192 }
193
201 void inline insertTraffic2LowerLayer(int traffic, int lower_layer_stack, int lower_layer_id, int behavior) {
202 down_map[traffic][lower_layer_stack] = std::make_pair(lower_layer_id, behavior);
203 //std::cout << "down_map(" << traffic << ", " << lower_layer_stack << ") = " << (down_map[traffic][lower_layer_stack]).first << std::endl;
204 }
205
213 virtual int getBestLowerLayer(int traffic, Packet *p= NULL);
214
222 virtual int getUpperLayer(int traffic);
223
231 virtual void eraseTraffic2LowerLayer(int traffic, int lower_layer_stack);
232
239 virtual void eraseTraffic2Low(int traffic);
240
247 virtual void eraseTraffic2Up(int traffic);
248
255 virtual void addUpLayerFromTag(int traffic_id, std::string tag);
256
264 virtual void addLowLayerFromTag(int traffic_id, std::string tag, int behavior);
265
274 void setBufferFeature(int traffic_id, int max_size, bool is_circular,
275 double send_down_delay=0);
276
281 virtual void incrPktLoss(int traffic_id);
282
289 virtual uint getDiscardedPacket(int traffic_id) const;
290
291private:
292 //Variables
293};
294
295#endif /* UWMULTI_TRAFFIC_Control_H */
Class used to represents the UwMultiTrafficControl layer of a node.
BufferTrafficFeature buffer_feature_map
Map with features of each buffer.
DownTrafficBuffer down_buffer
Map of buffer per traffic types.
virtual ~UwMultiTrafficControl()
Destructor of UwMultiPhy class.
virtual void recvFromUpperLayers(Packet *p)
Handle a packet coming from upper layers.
void setBufferFeature(int traffic_id, int max_size, bool is_circular, double send_down_delay=0)
set buffer features for the given traffic type
virtual int command(int, const char *const *)
TCL command interpreter.
UwMultiTrafficControl()
Constructor of UwMultiPhy class.
virtual int getUpperLayer(int traffic)
return the Upper Layer id where to forward the received packet of traffic type
int debug_
Flag to activate debug verbosity.
virtual void addLowLayerFromTag(int traffic_id, std::string tag, int behavior)
add a lower layer from the tag name in the map
virtual void manageBuffer(int traffic)
manage to tx a packet of traffic type
DownTrafficMap down_map
Map of lower layers.
virtual int getBestLowerLayer(int traffic, Packet *p=NULL)
return the Best Lower Layer id where to forward the packet of traffic type
UpTrafficMap up_map
Map of upper layers.
virtual Packet * getFromBuffer(int traffic)
get a packet of a certain type from the buffer and return it
virtual Packet * removeFromBuffer(int traffic)
remove a packet of a certain type from the buffer and return it
virtual void eraseTraffic2Low(int traffic)
remove the traffic from the lower layers matrix
virtual void recv(Packet *p)
recv method.
virtual void addUpLayerFromTag(int traffic_id, std::string tag)
add an upper layer from the tag name in the map
virtual void eraseTraffic2LowerLayer(int traffic, int lower_layer_stack)
remove the behavior from the traffic lower layers matrix
virtual void incrPktLoss(int traffic_id)
Increment by 1 the number of lost packets for the given traffic.
virtual uint getDiscardedPacket(int traffic_id) const
get discarded packets
virtual void eraseTraffic2Up(int traffic)
remove the traffic from the upper layers matrix
void insertTraffic2UpLayer(int traffic, int upper_layer_id)
Set to which upper layer forward a specific kind of traffic received from the lower layers.
void insertTraffic2LowerLayer(int traffic, int lower_layer_stack, int lower_layer_id, int behavior)
Set to which upper layer forward a specific kind of traffic received from the lower layers.
virtual void insertInBuffer(Packet *p, int traffic)
insert a packet of a certain type in the buffer
double last_sched_tx
Last scheduled transmission time.
BufferBehavior behavior_buff
Buffer behavior.
double getUpdatedDelay(double time_instant)
uint pkts_lost
Packet lost for buffer overflow.
double send_delay
Send down delay.
uint max_size
Maximum buffer size.
BufferType(uint size, BufferBehavior behav, double del)
std::pair< int, int > BehaviorItem
module_id, behavior>
std::map< int, Buffer * > DownTrafficBuffer
app_type, PacketQueue
std::map< int, BehaviorItem > BehaviorMap
stack_id, behavior>
std::map< int, BehaviorMap > DownTrafficMap
app_type, BehaviorMap
std::queue< Packet * > Buffer
std::map< int, BufferType > BufferTrafficFeature
traffic, buffer type
std::map< int, int > UpTrafficMap
app_type, module_id>