![]() |
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 <WIMAC/frame/FrameHeadCollector.hpp> 00027 00028 #include <WNS/ldk/Compound.hpp> 00029 #include <WNS/ldk/fcf/TimingControl.hpp> 00030 #include <WNS/logger/Logger.hpp> 00031 00032 #include <WIMAC/Component.hpp> 00033 #include <WIMAC/PhyUser.hpp> 00034 #include <WIMAC/Utilities.hpp> 00035 #include <WIMAC/services/ConnectionManager.hpp> 00036 00037 using namespace wimac::frame; 00038 00039 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00040 wimac::frame::FrameHeadCollector, 00041 wns::ldk::FunctionalUnit, 00042 "wimac.frame.FrameHeadCollector", 00043 wns::ldk::FUNConfigCreator ); 00044 00045 00046 FrameHeadCollector::FrameHeadCollector( wns::ldk::fun::FUN* fun, const wns::pyconfig::View& config ) : 00047 wns::ldk::fcf::CompoundCollector( config ), 00048 wns::ldk::CommandTypeSpecifier<FrameHeadCommand>(fun), 00049 phyUser_(NULL), 00050 phyMode_( wns::SmartPtr<const wns::service::phy::phymode::PhyModeInterface> 00051 (wns::service::phy::phymode::createPhyMode( config.getView("phyMode") ) ) ) 00052 { 00053 } 00054 00055 void FrameHeadCollector::onFUNCreated() 00056 { 00057 assureType(getFUN()->getLayer(), wimac::Component*); 00058 layer_ = dynamic_cast<wimac::Component*>(getFUN()->getLayer()); 00059 00060 phyUser_ = getFUN()->findFriend<wimac::PhyUser*>("phyUser"); 00061 assure( phyUser_, "PhyUser is not of type wimac::PhyUser"); 00062 00063 connectionManager_ = 00064 layer_->getManagementService<service::ConnectionManager> 00065 ("connectionManager"); 00066 00067 if(layer_->getStationType() != wns::service::dll::StationTypes::AP()) 00068 { 00069 channelQualityObserver_ = layer_->getControlService<service::IChannelQualityObserver> 00070 ("associationControl"); 00071 } 00072 00073 wns::ldk::fcf::CompoundCollector::onFUNCreated(); 00074 } 00075 00076 void FrameHeadCollector::doStart(int mode) 00077 { 00078 switch (mode) { 00079 case CompoundCollector::Sending: 00080 { 00081 wns::ldk::CompoundPtr compound ( 00082 new wns::ldk::Compound( getFUN()->getProxy()->createCommandPool() ) ); 00083 00084 FrameHeadCommand* command = activateCommand( compound->getCommandPool() ); 00085 command->peer.baseStationID = layer_->getID(); 00086 command->local.duration = 00087 getCurrentDuration() - Utilities::getComputationalAccuracyFactor(); 00088 00089 PhyUserCommand* phyCommand = dynamic_cast<PhyUserCommand*>( 00090 getFUN()->getProxy()->activateCommand( compound->getCommandPool(), 00091 phyUser_ ) ); 00092 phyCommand->peer.destination_ = 0; 00093 phyCommand->peer.cellID_ = layer_->getCellID(); 00094 phyCommand->peer.source_ = layer_->getNode(); 00095 assureNotNull(phyMode_.getPtr()); 00096 phyCommand->peer.phyModePtr = phyMode_; 00097 phyCommand->magic.sourceComponent_ = layer_; 00098 phyCommand->magic.frameHead_ = true; 00099 00100 wns::simulator::Time now = wns::simulator::getEventScheduler()->getTime(); 00101 phyCommand->local.pAFunc_.reset 00102 ( new BroadcastPhyAccessFunc); 00103 phyCommand->local.pAFunc_->transmissionStart_ = now; 00104 phyCommand->local.pAFunc_->transmissionStop_ = now + command->local.duration 00105 - Utilities::getComputationalAccuracyFactor(); 00106 phyCommand->local.pAFunc_->phyMode_ = phyMode_; 00107 00108 assure( command->local.duration <= this->getMaximumDuration(), 00109 "FrameHeadWriter: PDU overun the maximum duration of the frame phase!"); 00110 00111 setTimeout( command->local.duration ); 00112 00113 LOG_INFO( getFrameBuilder()->getFUN()->getName(), 00114 ": frame head started with duration: ", command->local.duration); 00115 00116 getConnector()->getAcceptor( compound )->sendData( compound ); 00117 break; 00118 } 00119 case CompoundCollector::Receiving: 00120 break; 00121 default: 00122 throw wns::Exception("Unknown activation in FrameHeadCollector"); 00123 } 00124 } 00125 00126 void 00127 FrameHeadCollector::onTimeout() 00128 { 00129 getFrameBuilder()->finishedPhase( this ); 00130 } 00131 00132 00133 void FrameHeadCollector::doOnData( const wns::ldk::CompoundPtr& compound ) 00134 { 00135 FrameHeadCommand* command = 00136 getCommand( compound->getCommandPool() ); 00137 00138 LOG_INFO( getFUN()->getLayer()->getName(), ": received FCH from station:",command->peer.baseStationID); 00139 00140 if(channelQualityObserver_) 00141 { 00142 PhyUserCommand* phyCommand = phyUser_->getCommand(compound->getCommandPool()); 00143 channelQualityObserver_->storeMeasurement(command->peer.baseStationID, 00144 phyCommand->magic.rxMeasurement); 00145 } 00146 00147 getFrameBuilder()->getTimingControl()->finishedPhase( this ); 00148 }
1.5.5