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 getOverlayNodeId (int index)
virtual cModule * removeOverlayNode (int index)
 Removes a node from the access net.
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

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 
00162     terminal.module->gate("out", 0)->connectTo(routerInGate,
00163                                 channelType->create(channelTypeStr.c_str()));
00164     routerOutGate->connectTo(terminal.module->gate("in", 0),
00165                              channelType->create(channelTypeStr.c_str()));
00166 
00167     // connect ppp interface module to router module and vice versa
00168     routerInGate->connectTo(terminal.remotePPPInterface->gate("physIn", 0));
00169     terminal.remotePPPInterface->gate("physOut", 0)->connectTo(routerOutGate);
00170 
00171     // connect ppp interface module to network layer module and vice versa
00172     cModule* netwModule = router.module->submodule("networkLayer");
00173 
00174     cGate* netwInGate = firstUnusedGate(netwModule, "ifIn");
00175     cGate* netwOutGate = firstUnusedGate(netwModule, "ifOut");
00176 
00177     netwOutGate->connectTo(terminal.remotePPPInterface->gate("netwIn", 0));
00178     terminal.remotePPPInterface->gate("netwOut", 0)->connectTo(netwInGate);
00179 
00180     // connect network layer module to ip and arp modules
00181     cModule* ipModule = router.module->submodule("networkLayer")->
00182         submodule("ip");
00183     //cModule* arpModule = router.module->submodule("networkLayer")->submodule("arp"); //comment out for speed-hack
00184 
00185     //cGate* arpOut = firstUnusedGate(arpModule, "nicOut"); //comment out for speed-hack
00186     cGate* ipIn = firstUnusedGate(ipModule, "queueIn");
00187     //cGate* ipOut = firstUnusedGate(ipModule, "queueOut"); //comment out for speed-hack
00188 
00189     //arpOut->connectTo(netwOutGate);   //comment out for speed-hack
00190     netwInGate->connectTo(ipIn);
00191 
00192 
00193     //
00194     // Start ppp interface modules
00195     //
00196 
00197     terminal.remotePPPInterface->setDisplayString("i=block/ifcard");
00198     terminal.remotePPPInterface->buildInside();
00199     terminal.remotePPPInterface->scheduleStart(simulation.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->interfaceAt(
00211         router.interfaceTable->numInterfaces() - 1);
00212     terminal.interfaceEntry = terminal.interfaceTable->interfaceByName("ppp0");
00213 
00214 
00215     //
00216     // Fill in interface table.
00217     //
00218 
00219     // router
00220     IPv4InterfaceData* interfaceData = new IPv4InterfaceData;
00221     interfaceData->setInetAddress(router.IPAddress);
00222     interfaceData->setNetmask(IPAddress::ALLONES_ADDRESS);
00223     terminal.remoteInterfaceEntry->setIPv4Data(interfaceData);
00224 
00225     // terminal
00226     terminal.interfaceEntry->ipv4()->setInetAddress(
00227         IPAddress(terminal.IPAddress));
00228     terminal.interfaceEntry->ipv4()->setNetmask(IPAddress::ALLONES_ADDRESS);
00229 
00230     //
00231     // Fill in routing table.
00232     //
00233 
00234     // router
00235     RoutingEntry* re = new RoutingEntry();
00236     re->host = IPAddress(terminal.IPAddress);
00237     re->netmask = IPAddress(IPAddress::ALLONES_ADDRESS);
00238     re->interfaceName = terminal.remoteInterfaceEntry->name();
00239     re->interfacePtr = terminal.remoteInterfaceEntry;
00240     re->type = RoutingEntry::DIRECT;
00241     re->source = RoutingEntry::MANUAL;
00242     router.routingTable->addRoutingEntry(re);
00243     terminal.remoteRoutingEntry = re;
00244 
00245     // terminal
00246     RoutingEntry* te = new RoutingEntry();
00247     te->host = IPAddress::UNSPECIFIED_ADDRESS;
00248     te->netmask = IPAddress::UNSPECIFIED_ADDRESS;
00249     te->gateway = router.IPAddress;
00250     te->interfaceName = terminal.interfaceEntry->name();
00251     te->interfacePtr = terminal.interfaceEntry;
00252     te->type = RoutingEntry::REMOTE;
00253     te->source = RoutingEntry::MANUAL;
00254     terminal.routingTable->addRoutingEntry(te);
00255     terminal.routingEntry = te;
00256 
00257 
00258     // append module to overlay terminal vector
00259     overlayTerminal.push_back(terminal);
00260     int index = overlayTerminal.size() - 1;
00261 
00262     updateDisplayString();
00263 
00264     return index;
00265 }

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

Getter for router module.

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

int AccessNet::getOverlayNodeId ( int  index  ) 

00269 {
00270     Enter_Method("getOverlayNodeId()");
00271 
00272     if ( index >= (int)overlayTerminal.size() )
00273         return -1;
00274 
00275     return overlayTerminal[index].module->id();
00276 }

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::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 }

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

OMNeT number of init stages.

Returns:
neede number of init stages
00140     {
00141         return MAX_STAGE_UNDERLAY + 1;
00142     }

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

Removes a node from the access net.

00279 {
00280     Enter_Method("removeOverlayNode()");
00281 
00282     if ( index >= (int)overlayTerminal.size() )
00283         return NULL;
00284 
00285     TerminalInfo terminal = overlayTerminal[index];
00286     cModule* node = terminal.module;
00287     cModule* ppp = terminal.remotePPPInterface;
00288 
00289     // disconnect terminal
00290     node->gate("out")->disconnect();
00291     node->gate("in")->fromGate()->disconnect();
00292 
00293     // disconnect ip and arp modules
00294     ppp->gate("netwIn", 0)->sourceGate()->disconnect();
00295     ppp->gate("netwOut", 0)->toGate()->disconnect();
00296 
00297     // remove associated ppp interface module
00298     ppp->callFinish();
00299     ppp->deleteModule();
00300 
00301     // remove associated interface table entry
00302     router.interfaceTable->deleteInterface(terminal.remoteInterfaceEntry);
00303 
00304     // remove routing entries
00305     terminal.routingTable->deleteRoutingEntry(terminal.routingEntry);
00306     router.routingTable->deleteRoutingEntry(terminal.remoteRoutingEntry);
00307 
00308     // statistics
00309     lifetimeVector.record(simTime() - overlayTerminal[index].createdAt);
00310 
00311     // remove terminal from overlay terminal vector
00312     overlayTerminal.erase(overlayTerminal.begin() + index);
00313 
00314     updateDisplayString();
00315 
00316     return node;
00317 }

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

set access type

Parameters:
type access type
00125     {
00126         channelTypeStr = type;
00127     }

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

Returns number of nodes at this access router.

Returns:
number of nodes
00088     {
00089         return overlayTerminal.size();
00090     }

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

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

00320 {
00321     if ( ev.isGUI() ) {
00322         char buf[80];
00323         if ( overlayTerminal.size() == 1 ) {
00324             sprintf(buf, "1 terminal connected");
00325         } else {
00326             sprintf(buf, "%i terminals connected", overlayTerminal.size());
00327         }
00328         displayString().setTagArg("t", 0, buf);
00329         displayString().setTagArg("t", 2, "blue");
00330     }
00331 }


Member Data Documentation

std::string AccessNet::channelTypeStr [protected]

the different possible channel types

uint32_t AccessNet::lastIP [protected]

last assigned IP address

cOutVector AccessNet::lifetimeVector [protected]

vector of node lifetimes

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

the terminals at this access router

NodeInfo AccessNet::router [protected]

this access router


The documentation for this class was generated from the following files:
Generated on Wed Apr 4 13:37:06 2007 for ITM OverSim by  doxygen 1.4.7