![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /******************************************************************************* 00002 * This file is part of openWNS (open Wireless Network Simulator) 00003 * _____________________________________________________________________________ 00004 * 00005 * Copyright (C) 2004-2007 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 5, D-52074 Aachen, Germany 00008 * phone: ++49-241-80-27910, 00009 * fax: ++49-241-80-22242 00010 * email: info@openwns.org 00011 * www: http://www.openwns.org 00012 * _____________________________________________________________________________ 00013 * 00014 * openWNS is free software; you can redistribute it and/or modify it under the 00015 * terms of the GNU Lesser General Public License version 2 as published by the 00016 * Free Software Foundation; 00017 * 00018 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00019 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00020 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00021 * details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public License 00024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00025 * 00026 ******************************************************************************/ 00027 00028 #include <IP/Component.hpp> 00029 #include <IP/UpperConvergence.hpp> 00030 #include <IP/LowerConvergence.hpp> 00031 #include <IP/Forwarding.hpp> 00032 00033 #include <IP/Routing.hpp> 00034 #include <IP/Resolver.hpp> 00035 #include <IP/VirtualARP.hpp> 00036 #include <IP/VirtualDNS.hpp> 00037 00038 #include <WNS/module/Base.hpp> 00039 00040 #include <WNS/ldk/fun/Main.hpp> 00041 #include <WNS/ldk/utils.hpp> 00042 00043 using namespace ip; 00044 00045 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00046 Component, 00047 wns::node::component::Interface, 00048 "ip.IPv4", 00049 wns::node::component::ConfigCreator); 00050 00051 Component::Component(wns::node::Interface* _node, const wns::pyconfig::View& _pyco) : 00052 wns::node::component::Component(_node, _pyco), 00053 log(_pyco.get("logger")), 00054 domainName(_pyco.get<wns::service::nl::FQDN>("domainName")), 00055 dns(NULL), 00056 upperConvergence(NULL), 00057 lowerConvergence(NULL) 00058 { 00059 } 00060 00061 void 00062 Component::doStartup() 00063 { 00064 // build FUN 00065 fun = new wns::ldk::fun::Main(this, getConfig()); 00066 wns::ldk::configureFUN(fun, getConfig().get<wns::pyconfig::View>("fun")); 00067 fun->onFUNCreated(); 00068 00069 00070 // create IPFlowHandlerService and register the RuleController: 00071 iRuleControl = fun->findFriend<wns::service::dll::IRuleControl*>("postroutingChain"); 00072 assure(iRuleControl, "RuleController not set."); 00073 00074 // configure upper convergence (services, MAC address) 00075 upperConvergence = 00076 dynamic_cast<UpperConvergence*>( 00077 fun->getFunctionalUnit( 00078 getConfig().get<std::string>("upperConvergence.commandName"))); 00079 00080 lowerConvergence = 00081 dynamic_cast<LowerConvergence*>( 00082 fun->getFunctionalUnit( 00083 getConfig().get<std::string>("lowerConvergence.commandName"))); 00084 00085 addService(getConfig().get<std::string>("dataTransmission"), upperConvergence); 00086 addService(getConfig().get<std::string>("notification"), upperConvergence); 00087 addService(getConfig().get<std::string>("dns"), this); 00088 } 00089 00090 Component::~Component() 00091 { 00092 while (!resolvers.empty()) 00093 { 00094 delete *resolvers.begin(); 00095 resolvers.pop_front(); 00096 } 00097 delete fun; 00098 } 00099 00100 wns::service::nl::Address 00101 Component::lookup(wns::service::nl::FQDN name) 00102 { 00103 assure(dns, "No Dynamic Domain Name Service found!"); 00104 00105 return dns->request(name); 00106 } 00107 00108 trace::TraceCollector* 00109 Component::getTraceCollector() 00110 { 00111 static trace::TraceCollector tc = trace::TraceCollector("iptrace.cap.junk"); 00112 return &tc; 00113 } 00114 00115 void 00116 Component::onNodeCreated() 00117 { 00118 MESSAGE_BEGIN(NORMAL, log, m, "Connecting to DLL components : "); 00119 MESSAGE_END(); 00120 00121 for (int ii=0; ii < getConfig().len("dataLinkLayers"); ++ii) 00122 { 00123 00124 // We build the container::DataLink Structure here 00125 00126 wns::pyconfig::View entry = getConfig().get<wns::pyconfig::View>("dataLinkLayers", ii); 00127 00128 MESSAGE_BEGIN(NORMAL, log, m, " Attaching to DLL : "); 00129 m << entry.get<std::string>("dllDataTransmission"); 00130 MESSAGE_END(); 00131 00132 wns::service::dll::UnicastDataTransmission* dts = NULL; 00133 std::string dtsname = entry.get<std::string>("dllDataTransmission"); 00134 dts = getService<wns::service::dll::UnicastDataTransmission*>(dtsname); 00135 00136 wns::service::dll::Notification* notify = NULL; 00137 std::string notname = entry.get<std::string>("dllNotification"); 00138 notify = getService<wns::service::dll::Notification*>(notname); 00139 notify->registerHandler(wns::service::dll::IP, lowerConvergence); 00140 00141 notify->registerIRuleControl(iRuleControl); 00142 00143 wns::pyconfig::View arconf = entry.get("addressResolver"); 00144 std::string plugin = arconf.get<std::string>("nameInResolverFactory"); 00145 00146 resolver::Creator* cc = resolver::Factory::creator(plugin); 00147 00148 // create and add the Component to this Node 00149 resolver::ResolverInterface* ri = cc->create(arconf); 00150 resolvers.push_back(ri); 00151 00152 std::string arpZone = entry.get<std::string>("arpZone"); 00153 00154 // Is this link pointToPoint 00155 // If this is true all traffic goes to the gateway, no local 00156 // delivery 00157 00158 bool pointToPoint = entry.get<bool>("pointToPoint"); 00159 00160 // Do we trace this DLL 00161 00162 bool traceEnabled = entry.get<bool>("traceEnabled"); 00163 00164 dlls.insert(entry.get<std::string>("name"), container::DataLink(entry.get<std::string>("name"), 00165 dts, 00166 notify, 00167 arpZone, 00168 ri, 00169 pointToPoint, 00170 traceEnabled, 00171 getTraceCollector())); 00172 } 00173 00174 if(!getConfig().isNone("tunnelExitNotification")) 00175 { 00176 MESSAGE_BEGIN(NORMAL, log, m, "Connecting to TunnelExitPoint"); 00177 MESSAGE_END(); 00178 00179 std::string tunExitName = getConfig().get<std::string>("tunnelExitNotification"); 00180 getService<wns::service::dll::Notification*>(tunExitName)->registerHandler(wns::service::dll::IP, this->lowerConvergence); 00181 } 00182 } 00183 00184 void 00185 Component::onWorldCreated() 00186 { 00187 leaseAddresses(); 00188 setupARP(); 00189 setupDNS(); 00190 setupForwarding(); 00191 setupRoutingTable(); 00192 setupLowerConvergence(); 00193 } 00194 00195 00196 void 00197 Component::leaseAddresses() 00198 { 00199 for(container::DataLinkContainer::const_iterator it = dlls.begin(); it != dlls.end(); ++it) 00200 { 00201 it->second.resolver->resolve(); 00202 } 00203 00204 } 00205 00206 void 00207 Component::setupARP() 00208 { 00209 for(container::DataLinkContainer::const_iterator it = dlls.begin(); it != dlls.end(); ++it) 00210 { 00211 VirtualARP* arp = TheARPService::Instance().getZoneManager(it->second.arpZone); 00212 00213 arp->bind(it->second.dts->getMACAddress(), it->second.resolver->getAddress()); 00214 } 00215 } 00216 00217 void 00218 Component::setupDNS() 00219 { 00220 // For now we set our source Address to the first DLL that was added 00221 wns::service::nl::Address sourceAddress = dlls.begin()->second.resolver->getAddress(); 00222 00223 dns = TheDNSService::Instance().getZoneManager(getConfig().get<std::string>("dnsZone")); 00224 00225 assure(dns, "No Dynamic Domain Name Service found!"); 00226 00227 dns->bind(domainName, sourceAddress); 00228 } 00229 00230 void 00231 Component::setupForwarding() 00232 { 00233 Forwarding* forwarding = 00234 dynamic_cast<Forwarding*>( 00235 fun->getFunctionalUnit( 00236 getConfig().get<std::string>("forwarding.commandName"))); 00237 00238 00239 for(container::DataLinkContainer::const_iterator it = dlls.begin(); it != dlls.end(); ++it) 00240 { 00241 forwarding->addListeningAddress(it->second.resolver->getAddress()); 00242 } 00243 } 00244 00245 void 00246 Component::setupRoutingTable() 00247 { 00248 Routing* routing = 00249 dynamic_cast<Routing*>( 00250 fun->getFunctionalUnit( 00251 getConfig().get<std::string>("routing.commandName"))); 00252 00253 for(container::DataLinkContainer::const_iterator it = dlls.begin(); it != dlls.end(); ++it) 00254 { 00255 if (!it->second.pointToPoint) 00256 { 00257 routing->addRoute( 00258 // Address on this dll 00259 it->second.resolver->getAddress() & it->second.resolver->getSubnetMask(), 00260 // No gateway - local delivery route 00261 wns::service::nl::Address("0.0.0.0"), 00262 // Subnet Mask for this dll 00263 it->second.resolver->getSubnetMask(), 00264 // Dll name 00265 it->first); 00266 } 00267 } 00268 routing->printRoutingTable(); 00269 00270 routing->setDLLs(dlls); 00271 } 00272 00273 void 00274 Component::setupLowerConvergence() 00275 { 00276 LowerConvergence* lowerConvergence = 00277 dynamic_cast<LowerConvergence*>( 00278 fun->getFunctionalUnit( 00279 getConfig().get<std::string>("lowerConvergence.commandName"))); 00280 00281 lowerConvergence->setDLLs(dlls); 00282 } 00283 00284 void 00285 Component::onShutdown() 00286 { 00287 if (getTraceCollector()->hasSomethingToWrite()) 00288 { 00289 getTraceCollector()->write(); 00290 } 00291 } 00292 00293
1.5.5