#include <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. | |
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< 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 |
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] |
void AccessNet::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
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.
00138 { 00139 return MAX_STAGE_UNDERLAY + 1; 00140 }
cModule * AccessNet::removeOverlayNode | ( | int | index | ) | [virtual] |
Removes a node from the access net.
00268 { 00269 Enter_Method("removeOverlayNode()"); 00270 00271 if ( index >= (int)overlayTerminal.size() ) 00272 return NULL; 00273 00274 TerminalInfo terminal = overlayTerminal[index]; 00275 cModule* node = terminal.module; 00276 cModule* ppp = terminal.remotePPPInterface; 00277 00278 // disconnect terminal 00279 node->gate("out")->disconnect(); 00280 node->gate("in")->fromGate()->disconnect(); 00281 00282 // disconnect ip and arp modules 00283 ppp->gate("netwIn", 0)->sourceGate()->disconnect(); 00284 ppp->gate("netwOut", 0)->toGate()->disconnect(); 00285 00286 // remove associated ppp interface module 00287 ppp->callFinish(); 00288 ppp->deleteModule(); 00289 00290 // remove associated interface table entry 00291 router.interfaceTable->deleteInterface(terminal.remoteInterfaceEntry); 00292 00293 // remove routing entries 00294 terminal.routingTable->deleteRoutingEntry(terminal.routingEntry); 00295 router.routingTable->deleteRoutingEntry(terminal.remoteRoutingEntry); 00296 00297 // statistics 00298 lifetimeVector.record(simTime() - overlayTerminal[index].createdAt); 00299 00300 // remove terminal from overlay terminal vector 00301 overlayTerminal.erase(overlayTerminal.begin() + index); 00302 00303 updateDisplayString(); 00304 00305 return node; 00306 }
void AccessNet::selectChannel | ( | const std::string & | type | ) | [inline] |
virtual int AccessNet::size | ( | ) | [inline, virtual] |
Returns number of nodes at this access router.
00088 { 00089 return overlayTerminal.size(); 00090 }
void AccessNet::updateDisplayString | ( | ) | [protected, virtual] |
Displays the current number of terminals connected to this access net.
00309 { 00310 if ( ev.isGUI() ) { 00311 char buf[80]; 00312 if ( overlayTerminal.size() == 1 ) { 00313 sprintf(buf, "1 terminal connected"); 00314 } else { 00315 sprintf(buf, "%i terminals connected", overlayTerminal.size()); 00316 } 00317 displayString().setTagArg("t", 0, buf); 00318 displayString().setTagArg("t", 2, "blue"); 00319 } 00320 }
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