FailureManager Class Reference

#include <FailureManager.h>

Inheritance diagram for FailureManager:

IScriptable

List of all members.


Detailed Description

TODO documentation

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)

Member Function Documentation

void FailureManager::initialize (  )  [protected, virtual]

00023 {
00024     // so far no initialization
00025 }

void FailureManager::handleMessage ( cMessage *  msg  )  [protected, virtual]

00028 {
00029     ASSERT(false);
00030 }

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.

See also:
cXMLElement

Implements IScriptable.

00040 {
00041     cModule *target = getTargetNode(node.getAttribute("target"));
00042 
00043     if (!strcmp(node.getTagName(), "shutdown"))
00044     {
00045         target->getDisplayString().setTagArg("i2",0,"status/cross");
00046         if(!strcmp(target->getModuleType()->getName(), "RSVP_LSR"))
00047             replaceNode(target, "inet.nodes.mpls.RSVP_FAILED");
00048         else if(!strcmp(target->getModuleType()->getName(), "LDP_LSR"))
00049             replaceNode(target, "inet.nodes.mpls.LDP_FAILED");
00050         else
00051             ASSERT(false);
00052     }
00053     else if(!strcmp(node.getTagName(), "startup"))
00054     {
00055         target->getDisplayString().removeTag("i2");
00056         if(!strcmp(target->getModuleType()->getName(), "RSVP_FAILED"))
00057             replaceNode(target, "inet.nodes.mpls.RSVP_LSR");
00058         else if(!strcmp(target->getModuleType()->getName(), "LDP_FAILED"))
00059             replaceNode(target, "inet.nodes.mpls.LDP_LSR");
00060         else
00061             ASSERT(false);
00062     }
00063     else
00064         ASSERT(false);
00065 
00066 }

void FailureManager::replaceNode ( cModule *  mod,
const char *  newNodeType 
) [protected, virtual]

Referenced by processCommand().

00069 {
00070     ASSERT(mod);
00071 
00072     cModuleType *nodeType = cModuleType::find(newNodeType);
00073     if (!nodeType)
00074         error("Cannot replace module `%s' with a module of type `%s': No such module type", mod->getFullPath().c_str(), newNodeType);
00075 
00076     cModule *nodeMod = nodeType->create(mod->getName(), simulation.getSystemModule());
00077     ASSERT(nodeMod);
00078 
00079     reconnectNode(mod, nodeMod);
00080     delete mod;
00081 
00082     nodeMod->buildInside();
00083     nodeMod->scheduleStart(simTime());
00084     nodeMod->callInitialize();
00085 }

void FailureManager::reconnectNode ( cModule *  old,
cModule *  n 
) [protected, virtual]

Referenced by replaceNode().

00088 {
00089     copyParams(old, n);
00090     n->finalizeParameters();
00091     n->setDisplayString(old->getDisplayString().str());
00092 
00093     reconnectAllGates(old, n);
00094 }

void FailureManager::reconnectAllGates ( cModule *  old,
cModule *  n 
) [protected, virtual]

Referenced by reconnectNode().

00097 {
00098     std::vector<const char*> gateNames = old->getGateNames();
00099     for (std::vector<const char*>::const_iterator it=gateNames.begin(); it!=gateNames.end(); ++it)
00100     {
00101         const char* gateName = *it;
00102         if (old->isGateVector(gateName))
00103         {
00104             unsigned int size = old->gateSize(gateName);
00105             n->setGateSize(gateName, size);
00106             for (unsigned int i = 0; i < size; i++)
00107                 reconnectGates(old, n, gateName, i);
00108         }
00109         else
00110         {
00111             reconnectGates(old, n, gateName);
00112         }
00113     }
00114 }

void FailureManager::reconnectGates ( cModule *  old,
cModule *  n,
const char *  gateName,
int  gateIndex = -1 
) [protected, virtual]

Referenced by reconnectAllGates().

00117 {
00118     cGate::Type gateType = old->gateType(gateName);
00119     if (gateType == cGate::INOUT)
00120     {
00121         std::string ingateName = (std::string(gateName)+"$i");
00122         std::string outgateName = (std::string(gateName)+"$o");
00123         reconnectGate(old->gate(ingateName.c_str(), gateIndex), n->gate(ingateName.c_str(), gateIndex));
00124         reconnectGate(old->gate(outgateName.c_str(), gateIndex), n->gate(outgateName.c_str(), gateIndex));
00125     }
00126     else
00127     {
00128         reconnectGate(old->gate(gateName, gateIndex), n->gate(gateName, gateIndex));
00129     }
00130 }

void FailureManager::reconnectGate ( cGate *  oldGate,
cGate *  newGate 
) [protected, virtual]

Referenced by reconnectGates().

00133 {
00134     cGate::Type gateType = oldGate->getType();
00135     if (gateType == cGate::OUTPUT)
00136     {
00137         if(oldGate->isConnected())
00138         {
00139             cGate *to = oldGate->getNextGate();
00140             cChannel *ch = copyChannel(oldGate->getChannel());
00141             std::string displayString = oldGate->getChannel()->getDisplayString().str();
00142             oldGate->disconnect();
00143             newGate->connectTo(to, ch);
00144             ch->setDisplayString(displayString.c_str());
00145         }
00146     }
00147     else if (gateType == cGate::INPUT)
00148     {
00149         if (oldGate->isConnected())
00150         {
00151             cGate *from = oldGate->getPreviousGate();
00152             cChannel *ch = copyChannel(from->getChannel());
00153             std::string displayString = from->getChannel()->getDisplayString().str();
00154             from->disconnect();
00155             from->connectTo(newGate, ch);
00156             ch->setDisplayString(displayString.c_str());
00157         }
00158     }
00159     else
00160     {
00161         error("Unexpected gate type: %d", (int)gateType);
00162     }
00163 }

cModule * FailureManager::getTargetNode ( const char *  target  )  [protected, virtual]

Referenced by processCommand().

00033 {
00034     cModule *mod = simulation.getModuleByPath(target);
00035     ASSERT(mod);
00036     return mod;
00037 }

cChannel * FailureManager::copyChannel ( cChannel *  channel  )  [static, private]

Referenced by reconnectGate().

00166 {
00167     cChannel *copy = channel->getChannelType()->create(channel->getName());
00168     copyParams(channel, copy);
00169     return copy;
00170 }

void FailureManager::copyParams ( cComponent *  from,
cComponent *  to 
) [static, private]

Referenced by copyChannel(), and reconnectNode().

00173 {
00174     for(int i = 0; i < from->getNumParams(); i++)
00175         to->par(i) = from->par(i);
00176 }


The documentation for this class was generated from the following files:

Generated on Fri Mar 20 18:51:19 2009 for INET Framework for OMNeT++/OMNEST by  doxygen 1.5.5