AccessNet Class Reference

#include <AccessNet.h>

List of all members.


Detailed Description

Configuration module for access networks.

Public Member Functions

virtual int size ()
 Returns number of nodes at this access router.
virtual cModule * getAccessNode ()
 Getter for router module.
virtual int addOverlayNode (cModule *overlayNode, bool migrate=false)
 Gathers some information about the terminal and appends it to the overlay terminal vector.
int getRandomNodeId ()
 returns a random ID
virtual cModule * removeOverlayNode (int ID)
 Removes a node from the access net.
virtual cModule * getOverlayNode (int ID)
 searches overlayTerminal[] for a given node
void selectChannel (const std::string &type)
 set access type

Protected Member Functions

virtual int numInitStages () const
 OMNeT number of init stages.
virtual void initialize (int stage)
 Gather some information about the router node.
virtual void handleMessage (cMessage *msg)
 OMNeT handleMessage method.
virtual void updateDisplayString ()
 Displays the current number of terminals connected to this access net.

Protected Attributes

NodeInfo router
 this access router
std::vector< TerminalInfooverlayTerminal
 the terminals at this access router
uint32_t lastIP
 last assigned IP address
std::string channelTypeStr
 the different possible channel types
cOutVector lifetimeVector
 vector of node lifetimes

Member Function Documentation

virtual int AccessNet::size (  )  [inline, virtual]

Returns number of nodes at this access router.

Returns:
number of nodes
00086     {
00087         return overlayTerminal.size();
00088     }

virtual cModule* AccessNet::getAccessNode (  )  [inline, virtual]

Getter for router module.

Returns:
pointer to router module
00096     {
00097         return router.module;
00098     }

int AccessNet::addOverlayNode ( cModule *  overlayNode,
bool  migrate = false 
) [virtual]

Gathers some information about the terminal and appends it to the overlay terminal vector.

Gathers some information about the terminal and appends it to the overlay terminal vector. (called by IPv4UnderlayConfigurator in stage MAX_STAGE_UNDERLAY)

Referenced by IPv4UnderlayConfigurator::migrateNode().

00070 {
00071     Enter_Method("addOverlayNode()");
00072 
00073     TerminalInfo terminal;
00074     terminal.module = node;
00075     terminal.interfaceTable = IPAddressResolver().interfaceTableOf(node);
00076     terminal.remoteInterfaceTable = router.interfaceTable;
00077     terminal.routingTable = IPAddressResolver().routingTableOf(node);
00078     terminal.PPPInterface = node->submodule("ppp", 0);
00079     terminal.createdAt = simTime();
00080 
00081     // find unassigned ip address:
00082     //   Start at last given address, check if next address is valid and free.
00083     bool ip_test = false;
00084     for (uint32 ipOffset = lastIP + 1; ipOffset != lastIP; ipOffset++) {
00085         if ( ipOffset == 0x10000) {
00086             // Netmask = 255.255.0.0, so roll over if offset = 2**16
00087             ipOffset = 0;
00088             continue;
00089         }
00090 
00091         uint ip = router.IPAddress + ipOffset;
00092 
00093         // Check if IP is valid:
00094         //   Reject x.y.z.0 or x.y.z.255 or x.y.255.z
00095         if ( ((ip & 0xff) == 0) || ((ip & 0xff) == 0xff)
00096              || ((ip & 0xff00) == 0xff00) ) {
00097             continue;
00098         }
00099 
00100         // Check if IP is free
00101         ip_test = true;
00102         for (uint i = 0; i < overlayTerminal.size(); i++) {
00103             if (overlayTerminal[i].IPAddress == ip) {
00104                 ip_test = false;
00105                 break;
00106             }
00107         }
00108 
00109         // found valid IP
00110         if (ip_test) {
00111             terminal.IPAddress = ip;
00112             lastIP = ipOffset;
00113             break;
00114         }
00115     }
00116     if (!ip_test)
00117         opp_error ("Error creating node: No available IP in access net!");
00118 
00119     // update ip display string
00120     if (ev.isGUI()) {
00121         const char* ip_disp = const_cast<char*>
00122             (IPAddress(terminal.IPAddress).str().c_str());
00123         terminal.module->displayString().insertTag("t", 0);
00124         terminal.module->displayString().setTagArg("t", 0, ip_disp);
00125         terminal.module->displayString().setTagArg("t", 1, "l");
00126     }
00127 
00128 
00129     //
00130     // Create new remote ppp interface module for this terminal
00131     //
00132 
00133     // create ppp interface module
00134 
00135     int k = 1;
00136     while ( router.module->findSubmodule("ppp", k) != -1 )
00137         k++;
00138 
00139     cModuleType* pppInterfaceModuleType = findModuleType("PPPInterface");
00140     terminal.remotePPPInterface = pppInterfaceModuleType->
00141         create("ppp", router.module, 0, k);
00142 
00143 
00144     // set up gate sizes
00145     terminal.remotePPPInterface->setGateSize("physIn", 1);
00146     terminal.remotePPPInterface->setGateSize("physOut", 1);
00147     terminal.remotePPPInterface->setGateSize("netwIn", 1);
00148     terminal.remotePPPInterface->setGateSize("netwOut", 1);
00149 
00150 
00151     //
00152     // Connect all gates
00153     //
00154 
00155     // connect terminal to access router and vice versa
00156     cGate* routerInGate = firstUnusedGate(router.module, "in");
00157     cGate* routerOutGate = firstUnusedGate(router.module, "out");
00158 
00159     cChannelType* channelType = findChannelType( channelTypeStr.c_str() );
00160     if (!channelType) opp_error("Could not find Channel Type. Most likely "
00161                     "parameter channelTypes does not match the channels defined "
00162                     "in channels.ned");
00163 
00164     terminal.module->gate("out", 0)->connectTo(routerInGate,
00165                                 channelType->create(channelTypeStr.c_str()));
00166     routerOutGate->connectTo(terminal.module->gate("in", 0),
00167                              channelType->create(channelTypeStr.c_str()));
00168 
00169     // connect ppp interface module to router module and vice versa
00170     routerInGate->connectTo(terminal.remotePPPInterface->gate("physIn", 0));
00171     terminal.remotePPPInterface->gate("physOut", 0)->connectTo(routerOutGate);
00172 
00173     // connect ppp interface module to network layer module and vice versa
00174     cModule* netwModule = router.module->submodule("networkLayer");
00175 
00176     cGate* netwInGate = firstUnusedGate(netwModule, "ifIn");
00177     cGate* netwOutGate = firstUnusedGate(netwModule, "ifOut");
00178 
00179     netwOutGate->connectTo(terminal.remotePPPInterface->gate("netwIn", 0));
00180     terminal.remotePPPInterface->gate("netwOut", 0)->connectTo(netwInGate);
00181 
00182     // connect network layer module to ip and arp modules
00183     cModule* ipModule = router.module->submodule("networkLayer")->
00184         submodule("ip");
00185 
00186 #ifndef _MAX_SPEED
00187     cModule* arpModule = router.module->submodule("networkLayer")->submodule("arp"); //comment out for speed-hack
00188 #endif
00189 
00190 #ifndef _MAX_SPEED
00191     cGate* arpOut = firstUnusedGate(arpModule, "nicOut"); //comment out for speed-hack
00192 #endif
00193     cGate* ipIn = firstUnusedGate(ipModule, "queueIn");
00194 #ifndef _MAX_SPEED
00195     cGate* ipOut = firstUnusedGate(ipModule, "queueOut"); //comment out for speed-hack
00196 
00197     arpOut->connectTo(netwOutGate);     //comment out for speed-hack
00198 #endif
00199 
00200     netwInGate->connectTo(ipIn);
00201 
00202 
00203     //
00204     // Start ppp interface modules
00205     //
00206 
00207     terminal.remotePPPInterface->setDisplayString("i=block/ifcard");
00208     terminal.remotePPPInterface->buildInside();
00209     terminal.remotePPPInterface->scheduleStart(simulation.simTime());
00210     terminal.remotePPPInterface->callInitialize();
00211 
00212     if ( !migrate) {
00213         // we are already in stage 4 and need to call initialize
00214         // for all previous stages manually
00215         for (int i=0; i < MAX_STAGE_UNDERLAY + 1; i++) {
00216             terminal.module->callInitialize(i);
00217         }
00218     }
00219 
00220     terminal.remoteInterfaceEntry = router.interfaceTable->interfaceAt(
00221         router.interfaceTable->numInterfaces() - 1);
00222     terminal.interfaceEntry = terminal.interfaceTable->interfaceByName("ppp0");
00223 
00224 
00225     //
00226     // Fill in interface table.
00227     //
00228 
00229     // router
00230     IPv4InterfaceData* interfaceData = new IPv4InterfaceData;
00231     interfaceData->setInetAddress(router.IPAddress);
00232     interfaceData->setNetmask(IPAddress::ALLONES_ADDRESS);
00233     terminal.remoteInterfaceEntry->setIPv4Data(interfaceData);
00234 
00235     // terminal
00236     terminal.interfaceEntry->ipv4()->setInetAddress(
00237         IPAddress(terminal.IPAddress));
00238     terminal.interfaceEntry->ipv4()->setNetmask(IPAddress::ALLONES_ADDRESS);
00239 
00240     //
00241     // Fill in routing table.
00242     //
00243 
00244     // router
00245     RoutingEntry* re = new RoutingEntry();
00246     re->host = IPAddress(terminal.IPAddress);
00247     re->netmask = IPAddress(IPAddress::ALLONES_ADDRESS);
00248     re->interfaceName = terminal.remoteInterfaceEntry->name();
00249     re->interfacePtr = terminal.remoteInterfaceEntry;
00250     re->type = RoutingEntry::DIRECT;
00251     re->source = RoutingEntry::MANUAL;
00252     router.routingTable->addRoutingEntry(re);
00253     terminal.remoteRoutingEntry = re;
00254 
00255     // terminal
00256     RoutingEntry* te = new RoutingEntry();
00257     te->host = IPAddress::UNSPECIFIED_ADDRESS;
00258     te->netmask = IPAddress::UNSPECIFIED_ADDRESS;
00259     te->gateway = router.IPAddress;
00260     te->interfaceName = terminal.interfaceEntry->name();
00261     te->interfacePtr = terminal.interfaceEntry;
00262     te->type = RoutingEntry::REMOTE;
00263     te->source = RoutingEntry::MANUAL;
00264     terminal.routingTable->addRoutingEntry(te);
00265     terminal.routingEntry = te;
00266 
00267 
00268     // append module to overlay terminal vector
00269     overlayTerminal.push_back(terminal);
00270     int ID = terminal.module->id();
00271 
00272     updateDisplayString();
00273 
00274     return ID;
00275 }

int AccessNet::getRandomNodeId (  ) 

returns a random ID

00278 {
00279     Enter_Method("getRandomNodeId()");
00280 
00281     return overlayTerminal[intuniform(0, overlayTerminal.size() - 1)].module->id();
00282 }

cModule * AccessNet::removeOverlayNode ( int  ID  )  [virtual]

Removes a node from the access net.

Referenced by IPv4UnderlayConfigurator::handleTimerEvent(), and IPv4UnderlayConfigurator::migrateNode().

00285 {
00286     Enter_Method("removeOverlayNode()");
00287 
00288     cModule* node = NULL;
00289     TerminalInfo terminal;
00290     int index;
00291 
00292     for(unsigned int i=0; i<overlayTerminal.size(); i++) {
00293         if(overlayTerminal[i].module->id() == ID) {
00294             terminal = overlayTerminal[i];
00295             node = terminal.module;
00296             index = i;
00297         }
00298     }
00299 
00300     if(node == NULL) return NULL;
00301 
00302     cModule* ppp = terminal.remotePPPInterface;
00303 
00304     // disconnect terminal
00305     node->gate("out")->disconnect();
00306     node->gate("in")->fromGate()->disconnect();
00307 
00308     // disconnect ip and arp modules
00309     ppp->gate("netwIn", 0)->sourceGate()->disconnect();
00310     ppp->gate("netwOut", 0)->toGate()->disconnect();
00311 
00312     // remove associated ppp interface module
00313     ppp->callFinish();
00314     ppp->deleteModule();
00315 
00316     // remove associated interface table entry
00317     router.interfaceTable->deleteInterface(terminal.remoteInterfaceEntry);
00318 
00319     // remove routing entries
00320     terminal.routingTable->deleteRoutingEntry(terminal.routingEntry);
00321     router.routingTable->deleteRoutingEntry(terminal.remoteRoutingEntry);
00322 
00323     // statistics
00324     lifetimeVector.record(simTime() - overlayTerminal[index].createdAt);
00325 
00326     // remove terminal from overlay terminal vector
00327     overlayTerminal.erase(overlayTerminal.begin() + index);
00328 
00329     updateDisplayString();
00330 
00331     return node;
00332 }

cModule * AccessNet::getOverlayNode ( int  ID  )  [virtual]

searches overlayTerminal[] for a given node

Parameters:
ID position of the node in overlayTerminal
Returns:
the nodeId if found, -1 else

Referenced by IPv4UnderlayConfigurator::preKillNode().

00335 {
00336     Enter_Method("getOverlayNode()");
00337 
00338     cModule* node = NULL;
00339 
00340     for(unsigned int i=0; i<overlayTerminal.size(); i++) {
00341         if(overlayTerminal[i].module->id() == ID)
00342             node = overlayTerminal[i].module;
00343     }
00344     return node;
00345 }

void AccessNet::selectChannel ( const std::string &  type  )  [inline]

set access type

Parameters:
type access type

Referenced by IPv4UnderlayConfigurator::initializeUnderlay().

00134     {
00135         channelTypeStr = type;
00136     }

virtual int AccessNet::numInitStages ( void   )  const [inline, protected, virtual]

OMNeT number of init stages.

Returns:
neede number of init stages
00149     {
00150         return MAX_STAGE_UNDERLAY + 1;
00151     }

void AccessNet::initialize ( int  stage  )  [protected, virtual]

Gather some information about the router node.

00045 {
00046     if(stage != MIN_STAGE_UNDERLAY + 1)
00047         return;
00048 
00049     router.module = parentModule();
00050     router.interfaceTable = IPAddressResolver().interfaceTableOf(parentModule());
00051     router.routingTable = IPAddressResolver().routingTableOf(parentModule());
00052     router.IPAddress = IPAddressResolver().addressOf(parentModule()).get4().getInt();
00053 
00054     // statistics
00055     lifetimeVector.setName("Terminal Lifetime");
00056 
00057     WATCH_VECTOR(overlayTerminal);
00058 
00059     lastIP = 0;
00060 
00061     updateDisplayString();
00062 }

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

OMNeT handleMessage method.

Parameters:
msg the message to handle
00065 {
00066     error("this module doesn't handle messages, it runs only in initialize()");
00067 }

void AccessNet::updateDisplayString (  )  [protected, virtual]

Displays the current number of terminals connected to this access net.

Referenced by addOverlayNode(), initialize(), and removeOverlayNode().

00348 {
00349     if (ev.isGUI()) {
00350         char buf[80];
00351         if ( overlayTerminal.size() == 1 ) {
00352             sprintf(buf, "1 terminal connected");
00353         } else {
00354             sprintf(buf, "%i terminals connected", overlayTerminal.size());
00355         }
00356         displayString().setTagArg("t", 0, buf);
00357         displayString().setTagArg("t", 2, "blue");
00358     }
00359 }


Member Data Documentation

this access router

Referenced by addOverlayNode(), getAccessNode(), initialize(), and removeOverlayNode().

std::vector<TerminalInfo> AccessNet::overlayTerminal [protected]

uint32_t AccessNet::lastIP [protected]

last assigned IP address

Referenced by addOverlayNode(), and initialize().

std::string AccessNet::channelTypeStr [protected]

the different possible channel types

Referenced by addOverlayNode(), and selectChannel().

cOutVector AccessNet::lifetimeVector [protected]

vector of node lifetimes

Referenced by initialize(), and removeOverlayNode().


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

Generated on Fri Sep 19 13:05:05 2008 for ITM OverSim by  doxygen 1.5.5