40#include <mphy_pktheader.h>
43#include <mmac-clmsg.h>
46#include <clmsg-discovery.h>
86 os <<
"<PriorityMap(debug_=" << obj.
debug_ <<
", ";
88 os <<
"defaultPriorities={";
93 os << it->first <<
": " << it->second <<
", ";
97 os <<
"customPriorities={";
98 for (std::map<LocalConnection, int>::const_iterator it = obj.
customPriorities.begin();
102 os << it->first <<
": " << it->second <<
", ";
122 TclObject*
create(
int,
const char*
const*)
139 Tcl& tcl = Tcl::instance();
143 if(strcasecmp(argv[1],
"initialize") == 0) {
148 }
else if (argc == 4) {
150 if(strcasecmp(argv[1],
"setResilienceTimeout") == 0) {
152 int tclId = atoi(argv[2]);
155 double timeout = atof(argv[3]);
161 if(strcasecmp(argv[1],
"setProbeTimeout") == 0) {
163 int tclId = atoi(argv[2]);
166 double timeout = atof(argv[3]);
172 if(strcasecmp(argv[1],
"setMacResilience") == 0)
175 int tclId = atoi(argv[2]);
178 int score = atoi(argv[3]);
184 if(strcasecmp(argv[1],
"setDefaultPriority") == 0) {
186 int tclId = atoi(argv[2]);
189 int priority = atoi(argv[3]);
195 if(strcasecmp(argv[1],
"getBestMac") == 0) {
196 int remoteIP = atoi(argv[2]);
197 int trafficType = atoi(argv[3]);
198 int bestMacID = this->
getBestMacID(trafficType, remoteIP);
200 tcl.resultf(
"%d", bestMacID);
204 }
else if (argc == 5) {
206 if(strcasecmp(argv[1],
"addCustomPriority") == 0) {
208 int tclId = atoi(argv[2]);
214 int priority = atoi(argv[4]);
221 return Module::command(argc, argv);
228 m.addSenderData((
const PlugIn*)
this, getLayer(), getId(), getStackId(), name() , getTag());
229 this->sendSyncClMsgDown(&m);
230 DiscoveryStorage a = m.copyStorage();
236 for (DBIt it=a.begin(); it!=a.end(); it++) {
238 int layerId = it->second.getId();
241 if (
id == 0)
continue;
244 this->
macIDs.push_back(layerId);
250 std::cout <<
"UwMultiPhyControl::initialize::tclId(" <<
id <<
")"
251 <<
"::layerId(" << layerId <<
")" << std::endl;
257 this->sendSyncClMsg(&msg);
260 std::cout <<
"UwMultiPhyControl::initialize::localIP(" << this->
localIP <<
")" << std::endl;
266 std::cerr <<
"UwMultiPhyControl: a Packet is received without source module ID" << std::endl;
272 hdr_cmn *ch = HDR_CMN(p);
274 if (ch->direction() == hdr_cmn::DOWN) {
286 hdr_cmn* cmn = HDR_CMN(p);
288 int dst_ip = uwip->
daddr();
296 <<
"::UwMultiPhyControl::recvFromLowerLayers"
297 <<
"::localIP(" << this->
localIP <<
")"
298 <<
"::localMAC(" << macID <<
")"
299 <<
"::remoteIP(" << c.
remoteIP <<
")"
300 <<
"::destIP(" << dst_ip <<
")"
301 <<
"::pktType(" <<
printType(cmn->ptype()) <<
")"
322 bool packet_sent =
false;
323 unsigned int n_stored_packets = this->
packet_queue.size();
324 for (
unsigned int i = 0; i < n_stored_packets; i++) {
344 uwip->
daddr() == this->localIP) {
346 Packet* pongPacket = Packet::alloc();
349 hdr_cmn* pongCmn = HDR_CMN(pongPacket);
366 <<
"::UwMultiPhyControl::sendPong"
367 <<
"::localIP(" << this->
localIP <<
")"
369 <<
"::remoteIP(" << c.
remoteIP <<
")"
370 <<
"::pktType(" <<
printType(pongCmn->ptype()) <<
")"
379 hdr_cmn* cmn = HDR_CMN(p);
387 int remoteIP = uwip->
daddr();
391 <<
"::UwMultiPhyControl::recvFromUpperLayers"
392 <<
"::pktID(" << HDR_CMN(p)->uid_ <<
")"
393 <<
"::localIP(" << this->
localIP <<
")"
394 <<
"::remoteIP(" << remoteIP <<
")"
395 <<
"::pktType(" <<
printType(cmn->ptype()) <<
")"
396 <<
"::trafficType(" << trafficType <<
")"
400 int bestMacID = this->
getBestMacID(trafficType, remoteIP);
403 if (bestMacID != -1) {
404 this->sendDown(bestMacID, p);
408 <<
"::UwMultiPhyControl::sendDown"
409 <<
"::localIP(" << this->
localIP <<
")"
410 <<
"::localMAC(" << bestMacID <<
")"
411 <<
"::remoteIP(" << remoteIP <<
")"
412 <<
"::pktType(" <<
printType(cmn->ptype()) <<
")"
418 for (uint i=0; i < this->
macIDs.size(); i++) {
437 <<
"::UwMultiPhyControl::sendPing"
438 <<
"::localIP(" << this->
localIP <<
")"
439 <<
"::remoteIP(" << c.
remoteIP <<
")"
441 <<
"::(ping to be sent while in " << this->
linkStatuses[c] <<
")"
449 Packet* pingPacket = Packet::alloc();
451 hdr_cmn* ch = HDR_CMN(pingPacket);
464 <<
"::UwMultiPhyControl::sendPing"
465 <<
"::localIP(" << this->
localIP <<
")"
467 <<
"::remoteIP(" << c.
remoteIP <<
")"
468 <<
"::pktType(" <<
printType(ch->ptype()) <<
")"
475 if ( this->
probeTimers.find(c) == this->probeTimers.end() ) {
486 std::cout << NOW <<
"::"
487 <<
"UwMultiPhyControl::updateAvailability"
488 <<
"::localIP(" << this->
localIP <<
")"
490 <<
"::remoteIP(" << c.
remoteIP <<
")"
491 <<
"::new status " << status << std::endl;
497 if (this->
probeTimers.find(c) != this->probeTimers.end()) {
500 std::cout << NOW <<
"::"
501 <<
"UwMultiPhyControl::updateAvailability"
502 <<
"::localIP(" << this->
localIP <<
")"
504 <<
"::remoteIP(" << c.
remoteIP <<
")"
505 <<
"::Reset probe timer" << std::endl;
527 int bestPriority = -1;
529 for (uint i=0; i < this->
macIDs.size(); i++) {
544 if (currentPriority > bestPriority) {
546 bestPriority = currentPriority;
556 if (this->module == NULL) {
560 if (this->module->debug_) {
562 <<
"::UwMultiPhyControl::ResilienceTimer::Expire"
563 <<
"::localIP(" << this->
module->localIP << ")"
564 << "::localMAC(" << this->conn.localMacID << ")"
565 << "::remoteIP(" << this->conn.remoteIP << ")"
568 this->
module->updateAvailability(this->conn, LINK_UNKNOWN);
573 if (this->module == NULL) {
577 if (this->module->debug_) {
579 <<
"::UwMultiPhyControl::ProbeTimer::Expire"
580 <<
"::localIP(" << this->
module->localIP << ")"
581 << "::localMAC(" << this->conn.localMacID << ")"
582 << "::remoteIP(" << this->conn.remoteIP << ")"
586 this->
module->linkStatuses[this->conn] = LINK_UNKNOWN;
587 this->
module->sendPing(this->conn);
packet_t PT_UWMULTIPHY_PONG
packet_t PT_UWMULTIPHY_PING
packet_t PT_UWMULTIPHY_DATA
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.
Class used to answer to UWIPClMsgReqAddr cross layer messages.
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.
UwMultiPhyControlClass()
Constructor of the class.
virtual void expire(Event *e)
Timer expire procedure: handles the PROBE timeout.
virtual void expire(Event *e)
Timer expire procedure: handles the PROBE timeout.
Class used to represents the UwMultiPhyControl layer of a node.
std::map< RemoteConnection, ResilienceTimer > resilienceTimers
UwMultiPhyControl()
Constructor of UwMultiPhy class.
std::vector< int > macIDs
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)
void recvFromUpperLayers(Packet *p)
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...
hdr_uwcbr describes UWCBR packets.
uint16_t & traffic_type()
Reference to the rftt_ variable.
hdr_uwip describes UWIP packets.
uint8_t & daddr()
Reference to the daddr_ variable.
uint8_t & saddr()
Reference to the saddr_ variable.
Cross layer messages definition for the UWIP Module.
ostream & operator<<(ostream &os, const PriorityMap &obj)
UwMultiPhyControlClass class_stack_controller
Definition of UwMultiPhyControl class.
std::string printType(packet_t ptype)