39#include <clmsg-discovery.h>
57 TclObject*
create(
int,
const char*
const*)
77 Tcl &tcl = Tcl::instance();
80 if(strcasecmp(argv[1],
"getDiscardedPacket") == 0)
88 if(strcasecmp(argv[1],
"addUpLayer") == 0)
93 else if(strcasecmp(argv[1],
"addLowLayer") == 0)
101 if(strcasecmp(argv[1],
"addLowLayer") == 0)
106 else if (strcasecmp(argv[1],
"setBufferFeatures") == 0)
114 if (strcasecmp(argv[1],
"setBufferFeatures") == 0)
121 return Module::command(argc, argv);
126 m.addSenderData((
const PlugIn*)
this, getLayer(), getId(), getStackId(), name() , getTag());
128 DiscoveryStorage up_layer_storage = m.findTag(tag.c_str());
130 std::cout <<
"UwMultiTrafficControl::addUpLayerFromTag(" << traffic_id <<
"," << tag <<
")"
131 << up_layer_storage.getSize() << std::endl;
132 if (up_layer_storage.getSize() == 1)
135 std::cout <<
"UwMultiTrafficControl::addUpLayerFromTag(" << traffic_id <<
"," << tag <<
")" <<
136 (*up_layer_storage.begin()).first << std::endl;
143 m.addSenderData((
const PlugIn*)
this, getLayer(), getId(), getStackId(), name() , getTag());
144 sendSyncClMsgDown(&m);
145 DiscoveryStorage low_layer_storage = m.findTag(tag.c_str());
146 DiscoveryData low_layer = (*low_layer_storage.begin()).second;
148 std::cout << NOW <<
"UwMultiTrafficControl::addLowLayerFromTag(" << traffic_id <<
","
149 << tag <<
") disc size " << low_layer_storage.getSize() << endl;
150 if (low_layer_storage.getSize() == 1)
153 std::cout << NOW <<
"UwMultiTrafficControl::addLowLayerFromTag(" << traffic_id <<
","
154 << tag <<
") disc data tr = "<< traffic_id <<
" m_id = " << low_layer.getId()
155 <<
" st_id = " << low_layer.getStackId() <<
" " << behavior << std::endl;
162 hdr_cmn *ch = HDR_CMN(p);
163 if(ch->direction() == hdr_cmn::UP)
168 std::cout << NOW <<
" UwMultiTrafficControl::recv type = " << traf_type <<std::endl;
179 hdr_cmn *ch = HDR_CMN(p);
180 assert(ch->direction() == hdr_cmn::DOWN);
185 std::cout << NOW <<
" UwMultiTrafficControl::recvFromUpperLayers" << std::endl;
194 std::cout <<
"UwMultiTrafficControl::insertInBuffer. ERROR. Buffer not "
195 <<
"configured. Traffic " << traffic << std::endl;
200 DownTrafficBuffer::iterator it =
down_buffer.find(traffic);
202 uint n_elem = it->second->size();
203 if (n_elem < it_feat->second.max_size) {
206 std::cout << NOW <<
" UwMultiTrafficControl::insertInBuffer, traffic = "
207 << traffic <<
", buffer size =" << it->second->size()
213 std::cout << NOW <<
"UwMultiTrafficControl::insertInBuffer, traffic = "
214 << traffic <<
", circular buffer full. Discard first element"
220 std::cout << NOW <<
"UwMultiTrafficControl::insertInBuffer, traffic = "
221 << traffic <<
", buffer full. Discard incoming packet "
228 std::queue<Packet*> *
q =
new std::queue<Packet*>;
232 std::cout << NOW <<
" UwMultiTrafficControl::insertInBuffer, traffic = "
233 << traffic <<
", buffer size =" << 1 << std::endl;
241 std::cout <<
"UwMultiTrafficControl::insertInBuffer. ERROR. Buffer not "
242 <<
"configured. Traffic " << traffic << std::endl;
245 DownTrafficBuffer::iterator it =
down_buffer.find(traffic);
248 it_feat->second.getUpdatedDelay(NOW));
250 std::cout << NOW <<
"UwMultiTrafficControl::manageBuffer(" << traffic <<
")" << std::endl;
257 DownTrafficBuffer::iterator it =
down_buffer.find(traffic);
258 if (it !=
down_buffer.end() && ! it->second->empty()) {
259 p = it->second->front();
262 std::cout << NOW <<
" UwMultiTrafficControl::removeFromBuffer(" << traffic
263 <<
"), packet in buffer = " << it->second->size() << std::endl;
271 DownTrafficBuffer::iterator it =
down_buffer.find(traffic);
272 if (it !=
down_buffer.end() && ! it->second->empty()) {
274 std::cout << NOW <<
" UwMultiTrafficControl::getFromBuffer(" << traffic
275 <<
"), packet in buffer = " << it->second->size() << std::endl;
276 p = it->second->front();
283 DownTrafficMap::iterator it =
down_map.find(traffic);
286 BehaviorMap::iterator it_b = temp.begin();
287 for (; it_b!=temp.end(); ++it_b)
289 if (it_b->second.second ==
DEFAULT)
292 std::cout << NOW <<
" UwMultiTrafficControl::getBestLowerLayer("
293 << traffic <<
"), id = "
294 << it_b->second.first << std::endl;
295 return it_b->second.first;
304 UpTrafficMap::iterator it =
up_map.find(traffic);
307 std::cout << NOW <<
" UwMultiTrafficControl::getUpperLayer(" <<traffic<<
") = "
308 << it->second << std::endl;
316 DownTrafficMap::iterator it =
down_map.find(traffic);
319 BehaviorMap::iterator it_layer = behav.find(lower_layer_stack);
320 if(it_layer != behav.end())
321 behav.erase(lower_layer_stack);
322 if(behav.size() == 0)
329 UpTrafficMap::iterator it =
up_map.find(traffic);
337 UpTrafficMap::iterator it =
up_map.find(traffic);
344 bool is_circular,
double send_down_delay)
352 std::cout <<
"Inserted buffer features for traffic " << traffic_id
353 <<
" with max size " << max_size <<
" Is circular "
354 << is_circular << std::endl;
361 it->second.pkts_lost++;
363 std::cout <<
"UwMultiTrafficControl::incrPktLoss. ERROR. Buffer not "
364 <<
"configured. Traffic " << traffic_id << std::endl;
373 std::cout <<
"UwMultiTrafficControl::incrPktLoss. ERROR. Buffer not "
374 <<
"configured. Traffic " << traffic_id << std::endl;
377 return it->second.pkts_lost;
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.
UwMultiTrafficControlClass()
Constructor of the class.
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 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
hdr_uwcbr describes UWCBR packets.
uint16_t & traffic_type()
Reference to the rftt_ variable.
Provides the UWCBR packets header description and the definition of the class UWCBR.
UwMultiTrafficControlClass class_traffic_control
std::map< int, BehaviorItem > BehaviorMap
stack_id, behavior>