AccessNet Class Reference

#include <AccessNet.h>

List of all members.


Detailed Description

Configuration module for access networks.

Definition at line 76 of file AccessNet.h.


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< TerminalInfo > overlayTerminal
 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

Definition at line 85 of file AccessNet.h.

00086     {
00087         return overlayTerminal.size();
00088     }

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

Getter for router module.

Returns:
pointer to router module

Definition at line 95 of file AccessNet.h.

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 InetUnderlayConfigurator in stage MAX_STAGE_UNDERLAY)

Definition at line 69 of file AccessNet.cc.

Referenced by InetUnderlayConfigurator::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->getSubmodule("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         uint32_t 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 (uint32_t 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->getDisplayString().insertTag("t", 0);
00124         terminal.module->getDisplayString().setTagArg("t", 0, ip_disp);
00125         terminal.module->getDisplayString().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 = cModuleType::get("inet.linklayer.ppp.PPPInterface");
00140     terminal.remotePPPInterface = pppInterfaceModuleType->
00141         create("ppp", router.module, 0, k);
00142 
00143 
00144     //
00145     // Connect all gates
00146     //
00147 
00148     // connect terminal to access router and vice versa
00149     cGate* routerInGate = firstUnusedGate(router.module, "pppg", cGate::INPUT);
00150     cGate* routerOutGate = firstUnusedGate(router.module, "pppg", cGate::OUTPUT);
00151 
00152     cChannelType* channelType = cChannelType::find( channelTypeStr.c_str() );
00153     if (!channelType) opp_error("Could not find Channel Type. Most likely "
00154                     "parameter channelTypes does not match the channels defined "
00155                     "in channels.ned");
00156 
00157     terminal.module->gate("pppg$o", 0)->connectTo(routerInGate,
00158                                 channelType->create(channelTypeStr.c_str()));
00159     routerOutGate->connectTo(terminal.module->gate("pppg$i", 0),
00160                              channelType->create(channelTypeStr.c_str()));
00161 
00162     // connect ppp interface module to router module and vice versa
00163     routerInGate->connectTo(terminal.remotePPPInterface->gate("phys$i"));
00164     terminal.remotePPPInterface->gate("phys$o")->connectTo(routerOutGate);
00165 
00166     // connect ppp interface module to network layer module and vice versa
00167     cModule* netwModule = router.module->getSubmodule("networkLayer");
00168 
00169     cGate* netwInGate = firstUnusedGate(netwModule, "ifIn");
00170     cGate* netwOutGate = firstUnusedGate(netwModule, "ifOut");
00171 
00172     netwOutGate->connectTo(terminal.remotePPPInterface->gate("netwIn"));
00173     terminal.remotePPPInterface->gate("netwOut")->connectTo(netwInGate);
00174 
00175     // connect network layer module to ip and arp modules
00176     cModule* ipModule = router.module->getSubmodule("networkLayer")->
00177         getSubmodule("ip");
00178 
00179     cGate* ipIn = firstUnusedGate(ipModule, "queueIn");
00180     netwInGate->connectTo(ipIn);
00181 
00182 #ifdef _ORIG_INET
00183     cModule* arpModule = router.module->getSubmodule("networkLayer")->getSubmodule("arp"); //comment out for speed-hack
00184 
00185     cGate* arpOut = firstUnusedGate(arpModule, "nicOut"); //comment out for speed-hack
00186 
00187     //cGate* ipOut = firstUnusedGate(ipModule, "queueOut"); //comment out for speed-hack
00188     cGate* ipOut = ipModule->gate("queueOut");
00189 
00190     arpOut->connectTo(netwOutGate);     //comment out for speed-hack
00191 #endif
00192 
00193     //
00194     // Start ppp interface modules
00195     //
00196     terminal.remotePPPInterface->finalizeParameters();
00197     terminal.remotePPPInterface->setDisplayString("i=block/ifcard");
00198     terminal.remotePPPInterface->buildInside();
00199     terminal.remotePPPInterface->scheduleStart(simTime());
00200     terminal.remotePPPInterface->callInitialize();
00201 
00202     if ( !migrate) {
00203         // we are already in stage 4 and need to call initialize
00204         // for all previous stages manually
00205         for (int i=0; i < MAX_STAGE_UNDERLAY + 1; i++) {
00206             terminal.module->callInitialize(i);
00207         }
00208     }
00209 
00210     terminal.remoteInterfaceEntry = router.interfaceTable->getInterface(
00211         router.interfaceTable->getNumInterfaces() - 1);
00212     terminal.interfaceEntry = terminal.interfaceTable->getInterfaceByName("ppp0");
00213 
00214 
00215     //
00216     // Fill in interface table.
00217     //
00218 
00219     // router
00220     IPv4InterfaceData* interfaceData = new IPv4InterfaceData;
00221     interfaceData->setIPAddress(router.IPAddress);
00222     interfaceData->setNetmask(IPAddress::ALLONES_ADDRESS);
00223     terminal.remoteInterfaceEntry->setIPv4Data(interfaceData);
00224 
00225     // terminal
00226     terminal.interfaceEntry->ipv4Data()->setIPAddress(IPAddress(terminal.IPAddress));
00227     terminal.interfaceEntry->ipv4Data()->setNetmask(IPAddress::ALLONES_ADDRESS);
00228 
00229     //
00230     // Fill in routing table.
00231     //
00232 
00233     // router
00234     IPRoute* re = new IPRoute();
00235     re->setHost(IPAddress(terminal.IPAddress));
00236     re->setNetmask(IPAddress(IPAddress::ALLONES_ADDRESS));
00237     re->setInterface(terminal.remoteInterfaceEntry);
00238     re->setType(IPRoute::DIRECT);
00239     re->setSource(IPRoute::MANUAL);
00240     router.routingTable->addRoute(re);
00241     terminal.remoteRoutingEntry = re;
00242 
00243     // terminal
00244     IPRoute* te = new IPRoute();
00245     te->setHost(IPAddress::UNSPECIFIED_ADDRESS);
00246     te->setNetmask(IPAddress::UNSPECIFIED_ADDRESS);
00247     te->setGateway(router.IPAddress);
00248     te->setInterface(terminal.interfaceEntry);
00249     te->setType(IPRoute::REMOTE);
00250     te->setSource(IPRoute::MANUAL);
00251     terminal.routingTable->addRoute(te);
00252     terminal.routingEntry = te;
00253 
00254 
00255     // append module to overlay terminal vector
00256     overlayTerminal.push_back(terminal);
00257     int ID = terminal.module->getId();
00258 
00259     updateDisplayString();
00260 
00261     return ID;
00262 }

int AccessNet::getRandomNodeId (  ) 

returns a random ID

Definition at line 264 of file AccessNet.cc.

00265 {
00266     Enter_Method("getRandomNodeId()");
00267 
00268     return overlayTerminal[intuniform(0, overlayTerminal.size() - 1)].module->getId();
00269 }

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

Removes a node from the access net.

Definition at line 271 of file AccessNet.cc.

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

00272 {
00273     Enter_Method("removeOverlayNode()");
00274 
00275     cModule* node = NULL;
00276     TerminalInfo terminal;
00277     int index;
00278 
00279     for(unsigned int i=0; i<overlayTerminal.size(); i++) {
00280         if(overlayTerminal[i].module->getId() == ID) {
00281             terminal = overlayTerminal[i];
00282             node = terminal.module;
00283             index = i;
00284         }
00285     }
00286 
00287     if(node == NULL) return NULL;
00288 
00289     cModule* ppp = terminal.remotePPPInterface;
00290 
00291     // disconnect terminal
00292     node->gate("pppg$o", 0)->disconnect();
00293     node->gate("pppg$i", 0)->getPreviousGate()->disconnect();
00294 
00295     // disconnect ip and arp modules
00296     ppp->gate("netwIn")->getPathStartGate()->disconnect();
00297     ppp->gate("netwOut")->getNextGate()->disconnect();
00298 
00299     // remove associated ppp interface module
00300     ppp->callFinish();
00301     ppp->deleteModule();
00302 
00303     // remove associated interface table entry
00304     router.interfaceTable->deleteInterface(terminal.remoteInterfaceEntry);
00305 
00306     // remove routing entries
00307     terminal.routingTable->deleteRoute(terminal.routingEntry);
00308     router.routingTable->deleteRoute(terminal.remoteRoutingEntry);
00309 
00310     // statistics
00311     lifetimeVector.record(simTime() - overlayTerminal[index].createdAt);
00312 
00313     // remove terminal from overlay terminal vector
00314     overlayTerminal.erase(overlayTerminal.begin() + index);
00315 
00316     updateDisplayString();
00317 
00318     return node;
00319 }

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

Definition at line 321 of file AccessNet.cc.

Referenced by InetUnderlayConfigurator::preKillNode().

00322 {
00323     Enter_Method("getOverlayNode()");
00324 
00325     cModule* node = NULL;
00326 
00327     for(unsigned int i=0; i<overlayTerminal.size(); i++) {
00328         if(overlayTerminal[i].module->getId() == ID)
00329             node = overlayTerminal[i].module;
00330     }
00331     return node;
00332 }

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

set access type

Parameters:
type access type

Definition at line 133 of file AccessNet.h.

Referenced by InetUnderlayConfigurator::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

Definition at line 148 of file AccessNet.h.

00149     {
00150         return MAX_STAGE_UNDERLAY + 1;
00151     }

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

Gather some information about the router node.

Definition at line 44 of file AccessNet.cc.

00045 {
00046     if(stage != MIN_STAGE_UNDERLAY + 1)
00047         return;
00048 
00049     router.module = getParentModule();
00050     router.interfaceTable = IPAddressResolver().interfaceTableOf(getParentModule());
00051     router.routingTable = IPAddressResolver().routingTableOf(getParentModule());
00052     router.IPAddress = IPAddressResolver().addressOf(getParentModule()).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

Definition at line 64 of file AccessNet.cc.

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.

Definition at line 334 of file AccessNet.cc.

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

00335 {
00336     if (ev.isGUI()) {
00337         char buf[80];
00338         if ( overlayTerminal.size() == 1 ) {
00339             sprintf(buf, "1 terminal connected");
00340         } else {
00341             sprintf(buf, "%i terminals connected", overlayTerminal.size());
00342         }
00343         getDisplayString().setTagArg("t", 0, buf);
00344         getDisplayString().setTagArg("t", 2, "blue");
00345     }
00346 }


Member Data Documentation

this access router

Definition at line 140 of file AccessNet.h.

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

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

the terminals at this access router

Definition at line 141 of file AccessNet.h.

Referenced by addOverlayNode(), getOverlayNode(), getRandomNodeId(), initialize(), removeOverlayNode(), size(), and updateDisplayString().

uint32_t AccessNet::lastIP [protected]

last assigned IP address

Definition at line 170 of file AccessNet.h.

Referenced by addOverlayNode(), and initialize().

std::string AccessNet::channelTypeStr [protected]

the different possible channel types

Definition at line 172 of file AccessNet.h.

Referenced by addOverlayNode(), and selectChannel().

cOutVector AccessNet::lifetimeVector [protected]

vector of node lifetimes

Definition at line 174 of file AccessNet.h.

Referenced by initialize(), and removeOverlayNode().


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

Generated on Wed Mar 25 16:32:51 2009 for OverSim by  doxygen 1.5.5