#include <FailureManager.h>
Protected Member Functions | |
virtual void | initialize () |
virtual void | handleMessage (cMessage *msg) |
virtual void | processCommand (const cXMLElement &node) |
virtual void | replaceNode (cModule *mod, const char *newNodeType) |
virtual void | reconnectNode (cModule *old, cModule *n) |
virtual void | reconnectAllGates (cModule *old, cModule *n) |
virtual void | reconnectGates (cModule *old, cModule *n, const char *gateName, int gateIndex=-1) |
virtual void | reconnectGate (cGate *oldGate, cGate *newGate) |
virtual cModule * | getTargetNode (const char *target) |
Static Private Member Functions | |
static cChannel * | copyChannel (cChannel *channel) |
static void | copyParams (cComponent *from, cComponent *to) |
TODO documentation
Definition at line 28 of file FailureManager.h.
cChannel * FailureManager::copyChannel | ( | cChannel * | channel | ) | [static, private] |
Definition at line 165 of file FailureManager.cc.
Referenced by reconnectGate().
{ cChannel *copy = channel->getChannelType()->create(channel->getName()); copyParams(channel, copy); return copy; }
void FailureManager::copyParams | ( | cComponent * | from, | |
cComponent * | to | |||
) | [static, private] |
Definition at line 172 of file FailureManager.cc.
Referenced by copyChannel(), and reconnectNode().
{ for(int i = 0; i < from->getNumParams(); i++) to->par(i) = from->par(i); }
cModule * FailureManager::getTargetNode | ( | const char * | target | ) | [protected, virtual] |
Definition at line 32 of file FailureManager.cc.
Referenced by processCommand().
{
cModule *mod = simulation.getModuleByPath(target);
ASSERT(mod);
return mod;
}
void FailureManager::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
Definition at line 27 of file FailureManager.cc.
{
ASSERT(false);
}
void FailureManager::initialize | ( | ) | [protected, virtual] |
Definition at line 22 of file FailureManager.cc.
{
// so far no initialization
}
void FailureManager::processCommand | ( | const cXMLElement & | node | ) | [protected, virtual] |
Called by ScenarioManager whenever a script command needs to be carried out by the module.
The command is represented by the XML element or element tree. The command name can be obtained as:
const char *command = node->getTagName()
Parameters are XML attributes, e.g. a "neighbour" parameter can be retrieved as:
const char *attr = node->getAttribute("neighbour")
More complex input can be passed in child elements.
Implements IScriptable.
Definition at line 39 of file FailureManager.cc.
{ cModule *target = getTargetNode(node.getAttribute("target")); if (!strcmp(node.getTagName(), "shutdown")) { target->getDisplayString().setTagArg("i2",0,"status/cross"); if(!strcmp(target->getModuleType()->getName(), "RSVP_LSR")) replaceNode(target, "inet.nodes.mpls.RSVP_FAILED"); else if(!strcmp(target->getModuleType()->getName(), "LDP_LSR")) replaceNode(target, "inet.nodes.mpls.LDP_FAILED"); else ASSERT(false); } else if(!strcmp(node.getTagName(), "startup")) { target->getDisplayString().removeTag("i2"); if(!strcmp(target->getModuleType()->getName(), "RSVP_FAILED")) replaceNode(target, "inet.nodes.mpls.RSVP_LSR"); else if(!strcmp(target->getModuleType()->getName(), "LDP_FAILED")) replaceNode(target, "inet.nodes.mpls.LDP_LSR"); else ASSERT(false); } else ASSERT(false); }
void FailureManager::reconnectAllGates | ( | cModule * | old, | |
cModule * | n | |||
) | [protected, virtual] |
Definition at line 96 of file FailureManager.cc.
Referenced by reconnectNode().
{ std::vector<const char*> gateNames = old->getGateNames(); for (std::vector<const char*>::const_iterator it=gateNames.begin(); it!=gateNames.end(); ++it) { const char* gateName = *it; if (old->isGateVector(gateName)) { unsigned int size = old->gateSize(gateName); n->setGateSize(gateName, size); for (unsigned int i = 0; i < size; i++) reconnectGates(old, n, gateName, i); } else { reconnectGates(old, n, gateName); } } }
void FailureManager::reconnectGate | ( | cGate * | oldGate, | |
cGate * | newGate | |||
) | [protected, virtual] |
Definition at line 132 of file FailureManager.cc.
Referenced by reconnectGates().
{ cGate::Type gateType = oldGate->getType(); if (gateType == cGate::OUTPUT) { if(oldGate->isConnected()) { cGate *to = oldGate->getNextGate(); cChannel *ch = copyChannel(oldGate->getChannel()); std::string displayString = oldGate->getChannel()->getDisplayString().str(); oldGate->disconnect(); newGate->connectTo(to, ch); ch->setDisplayString(displayString.c_str()); } } else if (gateType == cGate::INPUT) { if (oldGate->isConnected()) { cGate *from = oldGate->getPreviousGate(); cChannel *ch = copyChannel(from->getChannel()); std::string displayString = from->getChannel()->getDisplayString().str(); from->disconnect(); from->connectTo(newGate, ch); ch->setDisplayString(displayString.c_str()); } } else { error("Unexpected gate type: %d", (int)gateType); } }
void FailureManager::reconnectGates | ( | cModule * | old, | |
cModule * | n, | |||
const char * | gateName, | |||
int | gateIndex = -1 | |||
) | [protected, virtual] |
Definition at line 116 of file FailureManager.cc.
Referenced by reconnectAllGates().
{ cGate::Type gateType = old->gateType(gateName); if (gateType == cGate::INOUT) { std::string ingateName = (std::string(gateName)+"$i"); std::string outgateName = (std::string(gateName)+"$o"); reconnectGate(old->gate(ingateName.c_str(), gateIndex), n->gate(ingateName.c_str(), gateIndex)); reconnectGate(old->gate(outgateName.c_str(), gateIndex), n->gate(outgateName.c_str(), gateIndex)); } else { reconnectGate(old->gate(gateName, gateIndex), n->gate(gateName, gateIndex)); } }
void FailureManager::reconnectNode | ( | cModule * | old, | |
cModule * | n | |||
) | [protected, virtual] |
Definition at line 87 of file FailureManager.cc.
Referenced by replaceNode().
{ copyParams(old, n); n->finalizeParameters(); n->setDisplayString(old->getDisplayString().str()); reconnectAllGates(old, n); }
void FailureManager::replaceNode | ( | cModule * | mod, | |
const char * | newNodeType | |||
) | [protected, virtual] |
Definition at line 68 of file FailureManager.cc.
Referenced by processCommand().
{ ASSERT(mod); cModuleType *nodeType = cModuleType::find(newNodeType); if (!nodeType) error("Cannot replace module `%s' with a module of type `%s': No such module type", mod->getFullPath().c_str(), newNodeType); cModule *nodeMod = nodeType->create(mod->getName(), simulation.getSystemModule()); ASSERT(nodeMod); reconnectNode(mod, nodeMod); delete mod; nodeMod->buildInside(); nodeMod->scheduleStart(simTime()); nodeMod->callInitialize(); }