![]() |
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/ARPResolver.hpp> 00029 #include <IP/container/DataLink.hpp> 00030 00031 using namespace ip; 00032 00033 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00034 ARPResolver, 00035 wns::ldk::FunctionalUnit, 00036 "ip.arpresolver", 00037 wns::ldk::FUNConfigCreator); 00038 00039 ARPResolver::ARPResolver(wns::ldk::fun::FUN* fun, const wns::pyconfig::View& config): 00040 wns::ldk::CommandTypeSpecifier<>(fun), 00041 wns::ldk::HasReceptor<>(), 00042 wns::ldk::HasConnector<>(), 00043 wns::ldk::HasDeliverer<>(), 00044 wns::Cloneable<ARPResolver>(), 00045 log(config.get("logger")), 00046 ipHeaderReader(NULL), 00047 macID() 00048 { 00049 } 00050 00051 void 00052 ARPResolver::onFUNCreated() 00053 { 00054 ipHeaderReader = getFUN()->getCommandReader("ip.ipHeader"); 00055 assure(ipHeaderReader, "No reader for the IP Header available!"); 00056 } 00057 00058 void 00059 ARPResolver::doSendData(const wns::ldk::CompoundPtr& compound) 00060 { 00061 assure(this->isAccepting(compound), "doSendData called although ARPResolver is not accepting"); 00062 00063 assure(ipHeaderReader, "No reader for the IP Header available!"); 00064 00065 IPCommand* ipHeader = ipHeaderReader->readCommand<IPCommand>(compound->getCommandPool()); 00066 00067 if (this->macID == wns::service::dll::UnicastAddress()) 00068 { 00069 // Address is not resolved, we cannot accept but start address resolution 00070 std::string arpZone = std::string(ipHeader->local.arpZone); 00071 00072 VirtualARP* arp = TheARPService::Instance().getZoneManager(arpZone); 00073 00074 arp->request(*this, ipHeader->local.nextHop); 00075 00076 this->buffer = compound; 00077 } 00078 else 00079 { 00080 // Address is resolved 00081 00082 ipHeader->local.macID = this->macID; 00083 00084 if (this->getConnector()->hasAcceptor(compound)) 00085 { 00086 this->getConnector()->getAcceptor(compound)->sendData(compound); 00087 } 00088 else 00089 { 00090 throw wns::Exception("ARPResolver has no acceptor but should have!"); 00091 } 00092 } 00093 } 00094 00095 void 00096 ARPResolver::doOnData(const wns::ldk::CompoundPtr& compound) 00097 { 00098 if (this->getDeliverer()->getAcceptor(compound)) 00099 { 00100 this->getDeliverer()->getAcceptor(compound)->onData(compound); 00101 } 00102 else 00103 { 00104 throw wns::Exception("ARPResolver does not have a acceptor"); 00105 } 00106 } 00107 00108 bool 00109 ARPResolver::doIsAccepting(const wns::ldk::CompoundPtr& compound) const 00110 { 00111 assure(compound, "sendData called with an invalid compound."); 00112 00113 if (this->buffer == wns::ldk::CompoundPtr()) 00114 { 00115 return getConnector()->hasAcceptor(compound); 00116 } 00117 else 00118 { 00119 return false; 00120 } 00121 } 00122 00123 void 00124 ARPResolver::onAddressResolved(wns::service::dll::UnicastAddress dest) 00125 { 00126 // We have something to send 00127 assure(ipHeaderReader, "No reader for the IP Header available!"); 00128 00129 IPCommand* ipHeader = ipHeaderReader->readCommand<IPCommand>(this->buffer->getCommandPool()); 00130 00131 this->macID = dest; 00132 00133 MESSAGE_BEGIN(NORMAL, log, m, "ARP Response : "); 00134 m << ipHeader->local.nextHop << " is at " 00135 << this->macID; 00136 MESSAGE_END(); 00137 00138 if ( this-> buffer != wns::ldk::CompoundPtr()) 00139 { 00140 00141 ipHeader->local.macID = this->macID; 00142 00143 if (this->getConnector()->hasAcceptor(buffer)) 00144 { 00145 this->getConnector()->getAcceptor(buffer)->sendData(buffer); 00146 this->buffer = wns::ldk::CompoundPtr(); 00147 } 00148 else 00149 { 00150 throw wns::Exception("ARPResolver has no acceptor but should have!"); 00151 } 00152 } 00153 00154 wakeup(); 00155 } 00156 00157 void 00158 ARPResolver::doWakeup() 00159 { 00160 this->getReceptor()->wakeup(); 00161 }
1.5.5