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
00088     {
00089         return overlayTerminal.size();
00090     }

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

Getter for router module.

Returns:
pointer to router module
00098     {
00099         return router.module;
00100     }

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)

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

int AccessNet::getRandomNodeId (  ) 

returns a random ID

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

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

Removes a node from the access net.

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

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

searches overlayTerminal[] for a given node

Parameters:
index position of the node in overlayTerminal
Returns:
the nodeId if found, -1 else
00336 {
00337     Enter_Method("getOverlayNode()");
00338 
00339     cModule* node = NULL;
00340 
00341     for(unsigned int i=0; i<overlayTerminal.size(); i++) {
00342         if(overlayTerminal[i].module->id() == ID)
00343             node = overlayTerminal[i].module;
00344     }
00345     return node;
00346 }

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

set access type

Parameters:
type access type
00136     {
00137         channelTypeStr = type;
00138     }

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

OMNeT number of init stages.

Returns:
neede number of init stages
00151     {
00152         return MAX_STAGE_UNDERLAY + 1;
00153     }

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

Gather some information about the router node.

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

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

OMNeT handleMessage method.

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

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

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

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


Member Data Documentation

NodeInfo AccessNet::router [protected]

this access router

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

the terminals at this access router

uint32_t AccessNet::lastIP [protected]

last assigned IP address

std::string AccessNet::channelTypeStr [protected]

the different possible channel types

cOutVector AccessNet::lifetimeVector [protected]

vector of node lifetimes


The documentation for this class was generated from the following files:
Generated on Tue Jul 24 16:51:17 2007 for ITM OverSim by  doxygen 1.5.1