![]() |
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-2009 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 5, D-52074 Aachen, Germany 00008 * email: info@openwns.org 00009 * www: http://www.openwns.org 00010 * _____________________________________________________________________________ 00011 * 00012 * openWNS is free software; you can redistribute it and/or modify it under the 00013 * terms of the GNU Lesser General Public License version 2 as published by the 00014 * Free Software Foundation; 00015 * 00016 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00017 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00018 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00019 * details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public License 00022 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00023 * 00024 ******************************************************************************/ 00025 00026 #include <WNS/service/nl/Address.hpp> 00027 #include <WNS/service/dll/ProtocolNumber.hpp> 00028 #include <WNS/ReferenceModifier.hpp> 00029 #include <WNS/ReferenceModifier.hpp> 00030 00031 00032 #include <WIMAC/UpperConvergence.hpp> 00033 #include <WIMAC/RANG.hpp> 00034 #include <WIMAC/Logger.hpp> 00035 00036 using namespace wimac; 00037 00038 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00039 UpperConvergence, 00040 wns::ldk::FunctionalUnit, 00041 "wimac.UpperConvergence", 00042 wns::ldk::FUNConfigCreator); 00043 00044 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00045 NoUpperConvergence, 00046 wns::ldk::FunctionalUnit, 00047 "wimac.NoUpperConvergence", 00048 wns::ldk::FUNConfigCreator); 00049 00050 long int UpperConvergence::dllFlowID = 0; 00051 00052 00053 UpperConvergence::UpperConvergence(wns::ldk::fun::FUN* fun, const wns::pyconfig::View&) : 00054 wns::ldk::CommandTypeSpecifier<UpperCommand>(fun), 00055 wns::ldk::HasReceptor<>(), 00056 wns::ldk::HasConnector<wns::ldk::FirstServeConnector>(), 00057 wns::ldk::HasDeliverer<>(), 00058 sourceMACAddress_(), 00059 dataHandler_(NULL), 00060 rang_(NULL) 00061 {} 00062 00063 void 00064 UpperConvergence::onFUNCreated() 00065 { 00066 } 00067 00068 00069 void 00070 UpperConvergence::sendData( 00071 const wns::service::dll::UnicastAddress& peer, 00072 const wns::SmartPtr<wns::osi::PDU>& pdu, 00073 wns::service::dll::protocolNumber protocol, 00074 wns::service::dll::FlowID _dllFlowID) 00075 { 00076 pdu->setPDUType(protocol); 00077 00078 LOG_INFO(getFUN()->getName(), 00079 ": doSendData() called in convergence::Upper, target DLLAddress: " , 00080 peer, " DLLFlowID: ", _dllFlowID); 00081 00082 wns::ldk::CompoundPtr compound(new wns::ldk::Compound(getFUN()->createCommandPool(), pdu)); 00083 00084 activateCommand(compound->getCommandPool()); 00085 00086 UpperCommand* sgc = getCommand(compound->getCommandPool()); 00087 00088 sgc->peer.targetMACAddress = peer; 00089 sgc->peer.sourceMACAddress = sourceMACAddress_; 00090 sgc->local.dllFlowID = _dllFlowID; 00091 00092 if(flowID2QosClass.find(_dllFlowID) != flowID2QosClass.end()) 00093 { 00094 sgc->local.qosClass = flowID2QosClass[_dllFlowID]; 00095 00096 LOG_INFO(getFUN()->getName(), 00097 ": doSendData() called in convergence::Upper, QoS class: ", 00098 sgc->local.qosClass); 00099 } 00100 00101 if(this->getConnector()->hasAcceptor(compound)) 00102 { 00103 this->wns::ldk::FunctionalUnit::sendData(compound); 00104 } 00105 else 00106 { 00107 LOG_INFO("Dropped Outgoing Compound because DLL cannot handle it."); 00108 } 00109 } 00110 00111 void 00112 UpperConvergence::setMACAddress(const wns::service::dll::UnicastAddress& sourceMACAddress) 00113 { 00114 sourceMACAddress_ = sourceMACAddress; 00115 } 00116 00117 wns::service::dll::UnicastAddress 00118 UpperConvergence::getMACAddress() const 00119 { 00120 return sourceMACAddress_; 00121 } 00122 00123 void 00124 UpperConvergence::doOnData(const wns::ldk::CompoundPtr& compound) 00125 { 00126 UpperCommand* myCommand = getCommand(compound->getCommandPool()); 00127 00128 LOG_INFO( getFUN()->getName(), 00129 ": doOnData(), forwarding to upper Component (IP). DLLFlowID: ", 00130 myCommand->local.dllFlowID, " QoS class: ", myCommand->local.qosClass); 00131 00132 if(dataHandler_ != NULL) 00133 dataHandler_->onData(compound->getData(), myCommand->local.dllFlowID); 00134 else if (rang_ != NULL) 00135 { 00136 00137 if(flowID2QosClass.find(myCommand->local.dllFlowID) == flowID2QosClass.end()) 00138 { 00139 LOG_INFO( getFUN()->getName(), 00140 ": doOnData(), mapping DLLFlowID: ", 00141 myCommand->local.dllFlowID, " to QoS class: ", myCommand->local.qosClass); 00142 00143 flowID2QosClass[myCommand->local.dllFlowID] = myCommand->local.qosClass; 00144 } 00145 00146 rang_->onData(compound->getData(), 00147 myCommand->peer.sourceMACAddress, 00148 this, myCommand->local.dllFlowID); 00149 } 00150 else 00151 assure(false, "No data handler registered"); 00152 00153 LOG_TRACE(getFUN()->getName(), ": Compound backtrace", 00154 compound->dumpJourney()); 00155 } 00156 00157 wns::ldk::CommandPool* 00158 UpperConvergence::createReply(const wns::ldk::CommandPool* original) const 00159 { 00160 wns::ldk::CommandPool* reply = getFUN()->createCommandPool(); 00161 00162 UpperCommand* originalCommand = getCommand(original); 00163 UpperCommand* replyCommand = activateCommand(reply); 00164 00165 replyCommand->peer.sourceMACAddress = sourceMACAddress_; 00166 replyCommand->peer.targetMACAddress = 00167 originalCommand->peer.sourceMACAddress; 00168 00169 return reply; 00170 } 00171 00172 bool 00173 UpperConvergence::doIsAccepting(const wns::ldk::CompoundPtr& compound) const 00174 { 00175 return getConnector()->hasAcceptor(compound); 00176 } 00177 00178 void 00179 UpperConvergence::doSendData(const wns::ldk::CompoundPtr& compound) 00180 { 00181 getConnector()->getAcceptor(compound)->sendData(compound); 00182 } 00183 00184 void 00185 UpperConvergence::doWakeup() 00186 { 00187 getReceptor()->wakeup(); 00188 } 00189 00190 void UpperConvergence::registerHandler(wns::service::dll::protocolNumber, 00191 wns::service::dll::Handler* handler) 00192 { 00193 assureNotNull(handler); 00194 00195 // Quick hack neded to call right function in onData 00196 rang_ = dynamic_cast<RANG*>(handler); 00197 if(rang_ == NULL) 00198 dataHandler_ = handler; 00199 00200 LOG_INFO("Registering data handler"); 00201 } 00202 00203 void 00204 UpperConvergence::registerFlowHandler(wns::service::dll::FlowHandler* flowHandler) 00205 { 00206 tlFlowHandler = flowHandler; 00207 LOG_INFO("FlowHandler Registered"); 00208 } 00209 00210 void 00211 UpperConvergence::establishFlow(wns::service::tl::FlowID flowID, wns::service::qos::QoSClass qosClass) 00212 { 00213 assure(tlFlowHandler, "No TL FlowHandler set"); 00214 00215 dllFlowID++; 00216 00217 LOG_INFO("FlowEstablishment called from TL for: ", 00218 flowID, " QoS class: ", qosClass, " DLLFlowID ", dllFlowID); 00219 00220 flowID2QosClass[dllFlowID] = ConnectionIdentifier::QoSCategory(qosClass); 00221 tlFlowHandler->onFlowEstablished(flowID, dllFlowID); 00222 00223 00224 } // establishFlow 00225 00226
1.5.5