User Manual, Developers Guide and API Documentation

ACKSwitch.cpp

Go to the documentation of this file.
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/ACKSwitch.hpp>
00032 
00033 #include <WNS/Exception.hpp>
00034 #include <WNS/ldk/fun/FUN.hpp>
00035 #include <WNS/ldk/HasReceptor.hpp>
00036 #include <WNS/ldk/HasConnector.hpp>
00037 #include <WNS/ldk/HasDeliverer.hpp>
00038 #include <WNS/ldk/Layer.hpp>
00039 #include <WNS/ldk/arq/ARQ.hpp>
00040 
00041 #include <WIMAC/services/ConnectionManager.hpp>
00042 
00043 
00044 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00045     wimac::ACKSwitch,
00046     wns::ldk::FunctionalUnit,
00047     "wimac.ACKSwitch",
00048     wns::ldk::FUNConfigCreator);
00049 
00050 using namespace wimac;
00051 using namespace wimac::service;
00052 
00053 ACKSwitch::ACKSwitch( wns::ldk::fun::FUN* fun, const wns::pyconfig::View& ):
00054     wns::ldk::CommandTypeSpecifier<AckSwitchCommand>(fun),
00055     wns::ldk::HasConnector<>(),
00056     wns::ldk::HasReceptor<>(),
00057     wns::ldk::HasDeliverer<>(),
00058     wns::ldk::Processor<ACKSwitch>(),
00059     arq_(0),
00060     classifier_(0),
00061     connectionManager_(0)
00062 {
00063 }
00064 
00065 void ACKSwitch::onFUNCreated()
00066 {
00067     arq_ = getFUN()->findFriend<wns::ldk::arq::ARQ*>("arq");
00068     assure( arq_, "ARQ with name \"arq\" not found in FUN");
00069 
00070     classifier_ = getFUN()->findFriend<wns::ldk::CommandTypeSpecifier<wns::ldk::ClassifierCommand> *>("classifier");
00071     assure( classifier_, "classifier with name \"classifier\" not found in FUN" );
00072 
00073     connectionManager_ =
00074         getFUN()->getLayer()->getManagementService<service::ConnectionManagerInterface>
00075         ("connectionManager");
00076     assure( connectionManager_, "ConnectionManager not found in Configuration" );
00077 }
00078 
00079 void ACKSwitch::processOutgoing( const wns::ldk::CompoundPtr& compound )
00080 {
00081     wns::ldk::arq::ARQCommand* arqCommand =
00082         dynamic_cast<wns::ldk::arq::ARQCommand*>(arq_->getCommand( compound->getCommandPool() ) );
00083     assure( arqCommand, "Command is not of type ARQCommand" );
00084 
00085     if ( arqCommand->isACK() )
00086     {
00087         // this is an ACK, CID must be switched
00088         AckSwitchCommand* ackSwitchCommand = activateCommand( compound->getCommandPool() );
00089         wns::ldk::ClassifierCommand* classifierCommand =
00090             classifier_->getCommand( compound->getCommandPool() );
00091 
00092         // backup original CID
00093         ackSwitchCommand->peer.originalCID = classifierCommand->peer.id;
00094 
00095         // get the ConnectionIdentifier for the basic compound
00096         ConnectionIdentifierPtr basicConnection =
00097             connectionManager_->getBasicConnectionFor( classifierCommand->peer.id );
00098 
00099         LOG_INFO( "ACKSwitch: switching outgoing ACK from CID ",
00100                   classifierCommand->peer.id, " to basic CID ",
00101                   basicConnection->getID() );
00102 
00103         // do the switch
00104         classifierCommand->peer.id = basicConnection->getID();
00105     }
00106 }
00107 
00108 void ACKSwitch::processIncoming( const wns::ldk::CompoundPtr& compound )
00109 {
00110     if ( getFUN()->getProxy()->commandIsActivated( compound->getCommandPool(), this ) )
00111     {
00112         // commandPool is activated -> this is an ACK
00113         AckSwitchCommand* switchCommand = getCommand( compound->getCommandPool() );
00114         wns::ldk::ClassifierCommand* classifierCommand =
00115             classifier_->getCommand( compound->getCommandPool() );
00116         LOG_INFO( "ACKSwitch: switching incoming ACK from basic CID ",
00117                   classifierCommand->peer.id, " to data CID ",
00118                   switchCommand->peer.originalCID );
00119         classifierCommand->peer.id = switchCommand->peer.originalCID;
00120     }
00121 }

Generated on Mon May 21 03:32:16 2012 for openWNS by  doxygen 1.5.5