Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes

NicEntryDebug Class Reference
[connectionManager - channel and connection related classes]

NicEntry is used by ConnectionManager to store the necessary information for each nic. More...

#include <NicEntryDebug.h>

Inherits NicEntry.

Collaboration diagram for NicEntryDebug:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 NicEntryDebug (bool debug)
 Constructor, initializes all members.
virtual ~NicEntryDebug ()
 Removes all dynamically created out-/ingates.
virtual void connectTo (NicEntry *other)
 Connect two nics.
virtual void disconnectFrom (NicEntry *other)
 Disconnect two nics.

Protected Types

typedef std::vector< cGate * > GateStack

Protected Member Functions

cGate * requestInGate (void)
 Returns a free in gate of the nic.
cGate * requestOutGate (void)
 Returns a free out gate of the nic.
int collectGates (const char *pattern, GateStack &gates)
 Collects all free gates with a certain pattern as names and puts them on a stack.
void collectFreeGates ()
 Iterates over all existing gates of this NicEntries nic and host and checks wether they are useable by this nic entry.

Protected Attributes

int inCnt
 Number of in gates allocated for the nic so far.
int outCnt
 Number of out gates allocated for the nic so far.
bool checkFreeGates
 Check for unknown free gates before next gate request.
GateStack freeInGates
 In Gates that were once used but are not connected now.
GateStack freeOutGates
 Out Gates that were once used but are not connected now.

Detailed Description

NicEntry is used by ConnectionManager to store the necessary information for each nic.

Author:
Daniel Willkomm
See also:
ConnectionManager, NicEntry

Definition at line 38 of file NicEntryDebug.h.


Member Function Documentation

void NicEntryDebug::collectFreeGates (  )  [protected]

Iterates over all existing gates of this NicEntries nic and host and checks wether they are useable by this nic entry.

This method is necessary if a nic was unregistered from its connection manager during a simulation and is then again registered with one. When unregistered the gates created by this NicEntryDebug are not deleted so they can be collected and reused again when the nic is registered again.

Definition at line 95 of file NicEntryDebug.cc.

References checkFreeGates, collectGates(), freeInGates, freeOutGates, inCnt, and outCnt.

Referenced by requestInGate(), and requestOutGate().

{
  if(!checkFreeGates)
    return;

  inCnt = collectGates("in%d-%d", freeInGates);
  nicEV << "found " << inCnt << " already existing usable in-gates." << endl;


  outCnt = collectGates("out%d-%d", freeOutGates);
  nicEV << "found " << inCnt << " already existing usable out-gates." << endl;

  checkFreeGates = false;
}

int NicEntryDebug::collectGates ( const char *  pattern,
GateStack &  gates 
) [protected]

Collects all free gates with a certain pattern as names and puts them on a stack.

Parameters:
pattern The naming pattern of the gates, something like "out%d-%d" where the first d is filled with the nic id and the second with an incrementing counter.
gates The gate stack in which to put the found gates.
Returns:
the number of free gates found.

Definition at line 69 of file NicEntryDebug.cc.

References NicEntry::nicId, and NicEntry::nicPtr.

Referenced by collectFreeGates().

{
  cModule* host = nicPtr->getParentModule();
  int i = 1;
  char gateName[20];
  //create the unique name for the gate (composed of the nic module id and a counter)
  sprintf(gateName, pattern, nicId, i);
  while(host->hasGate(gateName))
  {
    cGate* hostGate = host->gate(gateName);
    if(hostGate->isConnectedOutside()) {
      opp_error("Gate %s is still connected but not registered with this "
            "NicEntry. Either the last NicEntry for this NIC did not "
            "clean up correctly or another gate creation module is "
            "interfering with this one!", gateName);
    }
    assert(hostGate->isConnectedInside());
    gates.push_back(hostGate);

    ++i;
    sprintf(gateName, pattern, nicId, i);
  }

  return i - 1;
}

void NicEntryDebug::connectTo ( NicEntry other  )  [virtual]

Connect two nics.

Establish unidirectional connection with other nic

Parameters:
other reference to remote nic (other NicEntry)

This function acquires an in gate at the remote nic and an out gate at this nic, connects the two and updates the freeInGate, freeOutGate and outConns data sets.

Implements NicEntry.

Definition at line 32 of file NicEntryDebug.cc.

References NicEntry::nicId, NicEntry::outConns, requestInGate(), and requestOutGate().

                                             {
  nicEV<<"connecting nic #"<<nicId<< " and #"<<other->nicId<<endl;

  NicEntryDebug* otherNic = (NicEntryDebug*) other;

  cGate *localoutgate = requestOutGate();
  localoutgate->connectTo(otherNic->requestInGate());
  outConns[other] = localoutgate->getPathStartGate();
}

void NicEntryDebug::disconnectFrom ( NicEntry other  )  [virtual]

Disconnect two nics.

Release unidirectional connection with other nic

Parameters:
other reference to remote nic (other NicEntry)

Implements NicEntry.

Definition at line 43 of file NicEntryDebug.cc.

References freeInGates, freeOutGates, NicEntry::nicId, and NicEntry::outConns.

                                                  {
  nicEV<<"disconnecting nic #"<<nicId<< " and #"<<other->nicId<<endl;

  NicEntryDebug* otherNic = (NicEntryDebug*) other;

  //search the connection in the outConns list
  GateList::iterator p = outConns.find(other);
  //no need to check whether entry is valid; is already check by ConnectionManager isConnected
  //get the hostGate
  //order is phyGate->nicGate->hostGate
  cGate* hostGate = p->second->getNextGate()->getNextGate();

  // release local out gate
  freeOutGates.push_back(hostGate);

  // release remote in gate
  otherNic->freeInGates.push_back(hostGate->getNextGate());

  //reset gates
  //hostGate->getNextGate()->connectTo(0);
  hostGate->disconnect();

  //delete the connection
  outConns.erase(p);
}

cGate * NicEntryDebug::requestInGate ( void   )  [protected]

Returns a free in gate of the nic.

This checks the list of free in gates, if one is available it is returned. Otherwise, a new in gate is added to the nic.

Definition at line 111 of file NicEntryDebug.cc.

References collectFreeGates(), freeInGates, inCnt, NicEntry::nicId, and NicEntry::nicPtr.

Referenced by connectTo().

                                        {
  collectFreeGates();

  // gate of the host
  cGate *hostGate;

  if (!freeInGates.empty()) {
    hostGate = freeInGates.back();
    freeInGates.pop_back();
  } else {
    char gateName[20];

    // we will have one more in gate
    ++inCnt;

    //get a unique name for the gate (composed of the nic module id and a counter)
    sprintf(gateName, "in%d-%d", nicId, inCnt);

    // create a new gate for the host module
    nicPtr->getParentModule()->addGate(gateName, cGate::INPUT);
    hostGate = nicPtr->getParentModule()->gate(gateName);

    // gate of the nic
    cGate *nicGate;

    // create a new gate for the nic module
    nicPtr->addGate(gateName, cGate::INPUT);
    nicGate = nicPtr->gate(gateName);

    // connect the hist gate with the nic gate
    hostGate->connectTo(nicGate);

    // pointer to the phy module
    ChannelAccess* phyModule;
    // gate of the phy module
    cGate *phyGate;

    // to avoid unnecessary dynamic_casting we check for a "phy"-named submodule first
    if ((phyModule = static_cast<ChannelAccess *> (nicPtr->getSubmodule("phy"))) == NULL)
      phyModule = FindModule<ChannelAccess*>::findSubModule(nicPtr);
    assert(phyModule != 0);

    // create a new gate for the phy module
    phyModule->addGate(gateName, cGate::INPUT);
    phyGate = phyModule->gate(gateName);

    // connect the nic gate (the gate of the compound module) to
    // a "real" gate -- the gate of the phy module
    nicGate->connectTo(phyGate);
  }

  return hostGate;
}

cGate * NicEntryDebug::requestOutGate ( void   )  [protected]

Returns a free out gate of the nic.

returns a free out gate. If none is available it is created. See NicEntry::requestInGate for a detailed description

Definition at line 165 of file NicEntryDebug.cc.

References collectFreeGates(), freeOutGates, NicEntry::nicId, NicEntry::nicPtr, and outCnt.

Referenced by connectTo().

                                         {
  collectFreeGates();

  // gate of the host
  cGate *hostGate;

  if (!freeOutGates.empty()) {
    hostGate = freeOutGates.back();
    freeOutGates.pop_back();
  } else {
    char gateName[20];

    // we will have one more out gate
    ++outCnt;

    //get a unique name for the gate (composed of the nic module id and a counter)
    sprintf(gateName, "out%d-%d", nicId, outCnt);

    // create a new gate for the host module
    nicPtr->getParentModule()->addGate(gateName, cGate::OUTPUT);
    hostGate = nicPtr->getParentModule()->gate(gateName);

    // gate of the nic
    cGate *nicGate;
    // create a new gate for the nic module
    nicPtr->addGate(gateName, cGate::OUTPUT);
    nicGate = nicPtr->gate(gateName);

    // connect the hist gate with the nic gate
    nicGate->connectTo(hostGate);

    // pointer to the phy module
    ChannelAccess* phyModule;
    // gate of the phy module
    cGate *phyGate;

    // to avoid unnecessary dynamic_casting we check for a "phy"-named submodule first
    if ((phyModule = static_cast<ChannelAccess *> (nicPtr->getSubmodule("phy"))) == NULL)
      phyModule = FindModule<ChannelAccess*>::findSubModule(nicPtr);
    assert(phyModule != 0);

    // create a new gate for the phy module
    phyModule->addGate(gateName, cGate::OUTPUT);
    phyGate = phyModule->gate(gateName);

    // connect the nic gate (the gate of the compound module) to
    // a "real" gate -- the gate of the phy module
    phyGate->connectTo(nicGate);
  }

  return hostGate;
}


Member Data Documentation

Check for unknown free gates before next gate request.

This flag is true after creation of the NicEntryDebug and assures that it checks for already existing in- and out-gates from a previous NicEntryDebug (which can happen if the same NIC is unregistered and later again registered with a connection manager.

Definition at line 54 of file NicEntryDebug.h.

Referenced by collectFreeGates().


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