![]() |
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 00031 #include <WIMAC/relay/RelayMapper.hpp> 00032 00033 #include <WNS/ldk/Layer.hpp> 00034 #include <WNS/ldk/Classifier.hpp> 00035 00036 #include <WIMAC/ACKSwitch.hpp> 00037 #include <WIMAC/Classifier.hpp> 00038 #include <WIMAC/services/ConnectionManager.hpp> 00039 00040 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00041 wimac::relay::BSRelayMapper, 00042 wns::ldk::FunctionalUnit, 00043 "wimac.relay.BSRelayMapper", 00044 wns::ldk::FUNConfigCreator); 00045 00046 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00047 wimac::relay::RSRelayMapper, 00048 wns::ldk::FunctionalUnit, 00049 "wimac.relay.RSRelayMapper", 00050 wns::ldk::FUNConfigCreator); 00051 00052 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00053 wimac::relay::SSRelayMapper, 00054 wns::ldk::FunctionalUnit, 00055 "wimac.relay.SSRelayMapper", 00056 wns::ldk::FUNConfigCreator); 00057 00058 using namespace wimac::relay; 00059 00060 RelayMapper::RelayMapper( wns::ldk::fun::FUN* fun, const wns::pyconfig::View& ) 00061 : wns::ldk::CommandTypeSpecifier<RelayMapperCommand>(fun) 00062 {} 00063 00064 void BSRelayMapper::processOutgoing( const wns::ldk::CompoundPtr& compound ) 00065 { 00066 RelayMapperCommand* command = dynamic_cast<RelayMapperCommand*> 00067 (getFUN()->getProxy()->activateCommand( compound->getCommandPool(), this )); 00068 00069 command->peer.direction_ = 00070 RelayMapperCommand::Down; 00071 } 00072 00073 BSRelayMapper::BSRelayMapper( wns::ldk::fun::FUN* fun, const wns::pyconfig::View& config ) 00074 : RelayMapper( fun, config ) 00075 {} 00076 00077 RSRelayMapper::RSRelayMapper( wns::ldk::fun::FUN* fun, const wns::pyconfig::View& config ) 00078 : RelayMapper( fun, config ) 00079 { 00080 } 00081 00082 void RSRelayMapper::onFUNCreated() 00083 { 00084 downRelayInject_ = 00085 getFUN()->getFunctionalUnit( "downRelayInject" ); 00086 upRelayInject_ = 00087 getFUN()->getFunctionalUnit( "upRelayInject" ); 00088 classifier_ = 00089 getFUN()->findFriend<wimac::ConnectionClassifier*>( "classifier" ); 00090 assure( classifier_, "classifier not found in FUN" ); 00091 00092 ackSwitch_ = 0; 00093 if( getFUN()->knowsFunctionalUnit("ackSwitch") ) 00094 { 00095 ackSwitch_ = 00096 getFUN()->findFriend<wimac::ACKSwitch*>("ackSwitch"); 00097 assure( ackSwitch_, "ackSwitch not found in FUN"); 00098 } 00099 } 00100 00101 void RSRelayMapper::processOutgoing( const wns::ldk::CompoundPtr& 00102 #ifndef NDEBUG 00103 compound 00104 #endif 00105 ) 00106 { 00107 assure(getFUN()->getProxy()->commandIsActivated(compound->getCommandPool(), this), 00108 "RelayMapper Command should be activated for outgoing compounds."); 00109 } 00110 00111 void RSRelayMapper::processIncoming( const wns::ldk::CompoundPtr& compound ) 00112 { 00113 wns::ldk::ClassifierCommand* clcom = 00114 classifier_->getCommand( compound->getCommandPool() ); 00115 00116 RelayMapping mapping = 00117 findMapping( clcom->peer.id ); 00118 if ( mapping == RelayMapping() ) 00119 { 00120 std::stringstream ss; 00121 ss << "no mapping registered for CID " << clcom->peer.id; 00122 assure( 0, ss.str() ); 00123 } 00124 wns::ldk::CommandPool* injection = 00125 getFUN()->getProxy()->createCommandPool(); 00126 00127 getFUN()->getProxy() 00128 ->partialCopy( this, injection, compound->getCommandPool() ); 00129 00130 if ( ackSwitch_ 00131 && getFUN()->getProxy()->commandIsActivated( compound->getCommandPool(), ackSwitch_ ) ) 00132 { 00133 // we need to switch the CID of the ACK too 00134 wimac::AckSwitchCommand* ackCom = 00135 ackSwitch_->getCommand( compound->getCommandPool() ); 00136 wimac::AckSwitchCommand* injectACKCom = 00137 ackSwitch_->getCommand( injection ); 00138 RelayMapping ackMapping = 00139 findMapping( ackCom->peer.originalCID ); 00140 if ( ackCom->peer.originalCID == ackMapping.upperConnection_ ) 00141 injectACKCom->peer.originalCID = ackMapping.lowerConnection_; 00142 else 00143 injectACKCom->peer.originalCID = ackMapping.upperConnection_; 00144 } 00145 00146 wns::ldk::ClassifierCommand* injectClcom = 00147 classifier_->getCommand( injection ); 00148 wns::ldk::CompoundPtr injectCompound( new wns::ldk::Compound(injection, compound->getData())); 00149 00150 if ( clcom->peer.id == mapping.upperConnection_ ) 00151 { 00152 LOG_INFO(getFUN()->getLayer()->getName(), 00153 " maps compound CID from ", clcom->peer.id, " down to ", 00154 mapping.lowerConnection_ ); 00155 injectClcom->peer.id = mapping.lowerConnection_; 00156 00157 00158 RelayMapperCommand* rCommand = 00159 this->activateCommand(injectCompound->getCommandPool()); 00160 rCommand->peer.direction_ = RelayMapperCommand::Down; 00161 00162 downRelayInject_->sendData( injectCompound ); 00163 } 00164 else 00165 { 00166 LOG_INFO(getFUN()->getLayer()->getName(), 00167 " maps compound CID from ", clcom->peer.id, " up to ", 00168 mapping.upperConnection_ ); 00169 injectClcom->peer.id = mapping.upperConnection_; 00170 00171 RelayMapperCommand* rCommand = 00172 this->activateCommand(injectCompound->getCommandPool()); 00173 rCommand->peer.direction_ = RelayMapperCommand::Up; 00174 00175 upRelayInject_->sendData( injectCompound ); 00176 } 00177 } 00178 00179 RSRelayMapper::RelayMapping 00180 RSRelayMapper::findMapping( const wimac::ConnectionIdentifier::CID& id ) const 00181 { 00182 for ( Mappings::const_iterator it = mappings_.begin(); 00183 it != mappings_.end(); 00184 ++it ) 00185 { 00186 if ( id == it->upperConnection_ || id == it->lowerConnection_ ) 00187 return *it; 00188 } 00189 return RelayMapping(); 00190 } 00191 00192 void RSRelayMapper::addMapping( const wimac::relay::RSRelayMapper::RelayMapping& mapping ) 00193 { 00194 mappings_.push_back( mapping ); 00195 } 00196 00197 bool RSRelayMapper::RelayMapping::operator==(const RelayMapping& rhs ) const 00198 { 00199 return upperConnection_ == rhs.upperConnection_ 00200 && lowerConnection_ == rhs.lowerConnection_ ; 00201 } 00202 00203 SSRelayMapper::SSRelayMapper( wns::ldk::fun::FUN* fun, const wns::pyconfig::View& config ) 00204 : RelayMapper( fun, config ) 00205 {} 00206 00207 void SSRelayMapper::processOutgoing( const wns::ldk::CompoundPtr& compound ) 00208 { 00209 RelayMapperCommand* command = dynamic_cast<RelayMapperCommand*> 00210 (getFUN()->getProxy()->activateCommand( compound->getCommandPool(), this )); 00211 00212 command->peer.direction_ = 00213 RelayMapperCommand::Up; 00214 }
1.5.5