User Manual, Developers Guide and API Documentation

AssociationControl.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 
00026 #include <WIMAC/services/AssociationControl.hpp>
00027 
00028 #include <WIMAC/services/ConnectionManager.hpp>
00029 #include <WNS/service/dll/StationTypes.hpp>
00030 #include <WIMAC/relay/RelayMapper.hpp>
00031 #include <WIMAC/StationManager.hpp>
00032 
00033 using namespace wimac::service::associationcontrol;
00034 using namespace wimac::service;
00035 using namespace wimac;
00036 
00037 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00038     wimac::service::associationcontrol::Fixed,
00039     wns::ldk::ControlServiceInterface,
00040     "wimac.services.AssociationControl.Fixed",
00041     wns::ldk::CSRConfigCreator);
00042 
00043 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00044     wimac::service::associationcontrol::BestAtGivenTime,
00045     wns::ldk::ControlServiceInterface,
00046     "wimac.services.AssociationControl.BestAtGivenTime",
00047     wns::ldk::CSRConfigCreator);
00048 
00049 STATIC_FACTORY_REGISTER(BestPathloss, IDecideBest, "wimac.services.AssociationControl.Best.BestPathloss");
00050 STATIC_FACTORY_REGISTER(BestRxPower, IDecideBest, "wimac.services.AssociationControl.Best.BestRxPower");
00051 STATIC_FACTORY_REGISTER(BestSINR, IDecideBest, "wimac.services.AssociationControl.Best.BestSINR");
00052 
00053 BestAtGivenTime::BestAtGivenTime(wns::ldk::ControlServiceRegistry* csr,
00054                                       wns::pyconfig::View& config) :
00055     AssociationControl(csr, config),
00056     deciderStrategy_(NULL),
00057     decisionTime_(config.get<wns::simulator::Time>("decisionTime"))
00058 {
00059     std::string pluginName = config.get<std::string>("decisionStrategy.__plugin__");
00060     deciderStrategy_ = IDecideBest::Factory::creator(pluginName)->create();
00061 }
00062 
00063 BestAtGivenTime::~BestAtGivenTime()
00064 {
00065     assure(deciderStrategy_, "Decider strategy is NULL");
00066 
00067     delete deciderStrategy_;
00068 }
00069 
00070 void
00071 BestAtGivenTime::doOnCSRCreated()
00072 {
00073     wns::simulator::getEventScheduler()->scheduleDelay(
00074         boost::bind(&BestAtGivenTime::associateNow, this),
00075         decisionTime_);
00076 }
00077 
00078 void
00079 BestAtGivenTime::doStoreMeasurement(StationID source,
00080     const wns::service::phy::power::PowerMeasurementPtr& pm)
00081 {
00082     assure(deciderStrategy_, "Decider strategy is NULL");
00083 
00084     deciderStrategy_->put(source, pm);
00085 }
00086 
00087 void
00088 BestAtGivenTime::associateNow()
00089 {
00090     assure(deciderStrategy_, "Decider strategy is NULL");
00091     assure(deciderStrategy_->isInitialized(), 
00092         "Decision strategy did not receive any measurements yet.");
00093 
00094     associateTo(deciderStrategy_->getBest());
00095 }
00096 
00097 
00098 Fixed::Fixed(wns::ldk::ControlServiceRegistry* csr,
00099                                       wns::pyconfig::View& config) :
00100     AssociationControl(csr, config),
00101     associatedWithID_(0)
00102 {
00103     assure(!config.isNone("associatedWith"), "Missing association target ID in PyConfig");
00104 
00105     associatedWithID_ = config.get<wimac::StationID>("associatedWith");
00106 }
00107 
00108 Fixed::~Fixed()
00109 {
00110 }
00111 
00112 void
00113 Fixed::doOnCSRCreated()
00114 {
00115     associateTo(associatedWithID_);
00116 }
00117 
00118 void
00119 Fixed::doStoreMeasurement(StationID, 
00120     const wns::service::phy::power::PowerMeasurementPtr&)
00121 {
00122 }
00123 
00124 AssociationControl::AssociationControl( wns::ldk::ControlServiceRegistry* csr,
00125                                       wns::pyconfig::View& config ) :
00126     wns::ldk::ControlService(csr)
00127 {
00128 }
00129 
00130 
00131 
00132 void
00133 AssociationControl::onCSRCreated()
00134 {
00135     friends_.connectionManager = getCSR()->getLayer()
00136         ->getManagementService<wimac::service::ConnectionManager>("connectionManager");
00137     assure(friends_.connectionManager,
00138            "ConnectionManager must be of type wimac::service::ConnectionManager");
00139 
00140     doOnCSRCreated();        
00141 }
00142 
00143 void
00144 AssociationControl::storeMeasurement(StationID source, 
00145     const wns::service::phy::power::PowerMeasurementPtr& pm)
00146 {
00147     doStoreMeasurement(source, pm);
00148 }
00149 
00150 
00151 void
00152 AssociationControl::associateTo(StationID associateTo)
00153 {
00154 
00155     LOG_INFO(getCSR()->getLayer()->getName(), ": associate to Station:", associateTo);
00156 
00157     wimac::Component* layer( dynamic_cast<wimac::Component*>( getCSR()->getLayer() ) );
00158     assure(layer, "Layer is not of type wimac::Component");
00159 
00160     StationID stationID = layer->getID();
00161 
00162     wimac::Component* destination (
00163         static_cast<wimac::Component*>
00164         ( TheStationManager::getInstance()->getStationByID( associateTo ) ) );
00165     assure( destination, "destination is not of type wimac::Component");
00166 
00167 
00168     if( layer->getStationType() != wns::service::dll::StationTypes::AP() ) {
00169         // create CID 0 (Initinal Ranging) in SS, to declare to wich BS we are associated
00170         ConnectionIdentifier connection ( associateTo,
00171                                           0,
00172                                           stationID,
00173                                           stationID,
00174                                           ConnectionIdentifier::InitialRanging,
00175                                           ConnectionIdentifier::Bidirectional,
00176                                           ConnectionIdentifier::Signaling );
00177 
00178         friends_.connectionManager->appendConnection( connection );
00179     }
00180 
00181     // create basic connection
00182     ConnectionIdentifier bCI( associateTo,
00183                               stationID,
00184                               stationID,
00185                               ConnectionIdentifier::Basic,
00186                               ConnectionIdentifier::Bidirectional,
00187                               ConnectionIdentifier::Signaling );
00188 
00189     // create primary connection
00190     ConnectionIdentifier pmCI( associateTo,
00191                                stationID,
00192                                stationID,
00193                                ConnectionIdentifier::PrimaryManagement,
00194                                ConnectionIdentifier::Bidirectional,
00195                                ConnectionIdentifier::Signaling );
00196 
00197     // create downlink data connections
00198     ConnectionIdentifier dlBECI( associateTo,
00199                                stationID,
00200                                stationID,
00201                                ConnectionIdentifier::Data,
00202                                ConnectionIdentifier::Downlink,
00203                                ConnectionIdentifier::BE);
00204 
00205     ConnectionIdentifier dlRtPSCI( associateTo,
00206                                stationID,
00207                                stationID,
00208                                ConnectionIdentifier::Data,
00209                                ConnectionIdentifier::Downlink,
00210                                ConnectionIdentifier::rtPS);
00211 
00212     ConnectionIdentifier dlNrtPSCI( associateTo,
00213                                stationID,
00214                                stationID,
00215                                ConnectionIdentifier::Data,
00216                                ConnectionIdentifier::Downlink,
00217                                ConnectionIdentifier::nrtPS);
00218 
00219     ConnectionIdentifier dlUGSCI( associateTo,
00220                                stationID,
00221                                stationID,
00222                                ConnectionIdentifier::Data,
00223                                ConnectionIdentifier::Downlink,
00224                                ConnectionIdentifier::UGS);
00225 
00226 
00227     // create uplink data connections
00228     ConnectionIdentifier ulBECI( associateTo,
00229                                stationID,
00230                                stationID,
00231                                ConnectionIdentifier::Data,
00232                                ConnectionIdentifier::Uplink,
00233                                ConnectionIdentifier::BE);
00234 
00235     ConnectionIdentifier ulRtPSCI( associateTo,
00236                                stationID,
00237                                stationID,
00238                                ConnectionIdentifier::Data,
00239                                ConnectionIdentifier::Uplink,
00240                                ConnectionIdentifier::rtPS);
00241 
00242     ConnectionIdentifier ulNrtPSCI( associateTo,
00243                                stationID,
00244                                stationID,
00245                                ConnectionIdentifier::Data,
00246                                ConnectionIdentifier::Uplink,
00247                                ConnectionIdentifier::nrtPS);
00248 
00249     ConnectionIdentifier ulUGSCI( associateTo,
00250                                stationID,
00251                                stationID,
00252                                ConnectionIdentifier::Data,
00253                                ConnectionIdentifier::Uplink,
00254                                ConnectionIdentifier::UGS);
00255 
00256 
00257 
00258     // get master ConnectionManager from destination access point
00259     wimac::service::ConnectionManager* destinationConnectionManager
00260         = destination->getManagementService<service::ConnectionManager>("connectionManager");
00261 
00262     // append ConnectionIdentifier to access point and get CID
00263     bCI =  destinationConnectionManager->appendConnection( bCI );
00264     pmCI = destinationConnectionManager->appendConnection( pmCI );
00265 
00266     dlBECI = destinationConnectionManager->appendConnection( dlBECI );
00267     dlRtPSCI = destinationConnectionManager->appendConnection( dlRtPSCI );
00268     dlNrtPSCI = destinationConnectionManager->appendConnection( dlNrtPSCI );
00269     dlUGSCI = destinationConnectionManager->appendConnection( dlUGSCI );
00270 
00271     ulBECI = destinationConnectionManager->appendConnection( ulBECI );
00272     ulRtPSCI = destinationConnectionManager->appendConnection( ulRtPSCI );
00273     ulNrtPSCI = destinationConnectionManager->appendConnection( ulNrtPSCI );
00274     ulUGSCI = destinationConnectionManager->appendConnection( ulUGSCI );
00275 
00276     //append ConnectionIdentifier myself
00277     friends_.connectionManager->appendConnection( bCI );
00278     friends_.connectionManager->appendConnection( pmCI );
00279 
00280     friends_.connectionManager->appendConnection( dlBECI );
00281     friends_.connectionManager->appendConnection( dlRtPSCI );
00282     friends_.connectionManager->appendConnection( dlNrtPSCI );
00283     friends_.connectionManager->appendConnection( dlUGSCI );
00284 
00285     friends_.connectionManager->appendConnection( ulBECI );
00286     friends_.connectionManager->appendConnection( ulRtPSCI );
00287     friends_.connectionManager->appendConnection( ulNrtPSCI );
00288     friends_.connectionManager->appendConnection( ulUGSCI );
00289 
00290 
00291     if( destination->getStationType() == wns::service::dll::StationTypes::FRS() )
00292     {
00293         destination
00294             ->getControlService<service::AssociationControl>("associationControl")
00295             ->createRecursiveConnection(bCI.cid_,
00296                                         pmCI.cid_,
00297                                         dlBECI.cid_,
00298                                         dlRtPSCI.cid_,
00299                                         dlNrtPSCI.cid_,
00300                                         dlUGSCI.cid_,
00301                                         ulBECI.cid_,
00302                                         ulRtPSCI.cid_,
00303                                         ulNrtPSCI.cid_,
00304                                         ulUGSCI.cid_,
00305                                         stationID);
00306     }
00307 
00308     Component* layer2 =
00309         dynamic_cast<Component*>(getCSR()->getLayer());
00310     assure(layer2, "AssociationControl only works in a dll::Layer2.");
00311 }
00312 
00313 void
00314 AssociationControl::createRecursiveConnection(ConnectionIdentifier::CID basicCID,
00315                                              ConnectionIdentifier::CID primaryCID,
00316                                              ConnectionIdentifier::CID downlinkBETransportCID,
00317                                              ConnectionIdentifier::CID downlinkRtPSTransportCID,
00318                                              ConnectionIdentifier::CID downlinkNrtPSTransportCID,
00319                                              ConnectionIdentifier::CID downlinkUGSTransportCID,
00320                                              ConnectionIdentifier::CID uplinkBETransportCID,
00321                                              ConnectionIdentifier::CID uplinkRtPSTransportCID,
00322                                              ConnectionIdentifier::CID uplinkNrtPSTransportCID,
00323                                              ConnectionIdentifier::CID uplinkUGSTransportCID,
00324                                              ConnectionIdentifier::StationID remote)
00325 {
00326     wimac::Component* layer = dynamic_cast<wimac::Component*>(getCSR()->getLayer());
00327     assure(layer, "Layer must be of type dll::Layer2");
00328 
00329     assure( layer->getStationType() == wns::service::dll::StationTypes::FRS(),
00330             "recursive connections only possible in relay stations" );
00331 
00332     ConnectionIdentifier::StationID associatedWithID =
00333         friends_.connectionManager
00334         ->getBasicConnectionFor( layer->getID() )->baseStation_;
00335 
00336     wimac::Component* associatedWith = static_cast<wimac::Component*>
00337         ( TheStationManager::getInstance()->getStationByID(associatedWithID) );
00338     assure( associatedWith, "Station is not of type wimac::Component");
00339 
00340 
00341     // Basic CI
00342     ConnectionIdentifier bCI( associatedWith->getID(),
00343                               layer->getID(),
00344                               remote,
00345                               ConnectionIdentifier::Basic,
00346                               ConnectionIdentifier::Bidirectional,
00347                               ConnectionIdentifier::Signaling );
00348 
00349     // Primary Management CI
00350     ConnectionIdentifier pmCI( associatedWith->getID(),
00351                                layer->getID(),
00352                                remote,
00353                                ConnectionIdentifier::PrimaryManagement,
00354                                ConnectionIdentifier::Bidirectional,
00355                                ConnectionIdentifier::Signaling );
00356 
00357     // create downlink data connections
00358     ConnectionIdentifier dlBECI( associatedWith->getID(),
00359                                 layer->getID(),
00360                                 remote,
00361                                ConnectionIdentifier::Data,
00362                                ConnectionIdentifier::Downlink,
00363                                ConnectionIdentifier::BE);
00364 
00365     ConnectionIdentifier dlRtPSCI( associatedWith->getID(),
00366                                 layer->getID(),
00367                                 remote,
00368                                ConnectionIdentifier::Data,
00369                                ConnectionIdentifier::Downlink,
00370                                ConnectionIdentifier::rtPS);
00371 
00372     ConnectionIdentifier dlNrtPSCI( associatedWith->getID(),
00373                                 layer->getID(),
00374                                 remote,
00375                                ConnectionIdentifier::Data,
00376                                ConnectionIdentifier::Downlink,
00377                                ConnectionIdentifier::nrtPS);
00378 
00379     ConnectionIdentifier dlUGSCI( associatedWith->getID(),
00380                                 layer->getID(),
00381                                 remote,
00382                                ConnectionIdentifier::Data,
00383                                ConnectionIdentifier::Downlink,
00384                                ConnectionIdentifier::UGS);
00385 
00386 
00387     // create uplink data connections
00388     ConnectionIdentifier ulBECI( associatedWith->getID(),
00389                                 layer->getID(),
00390                                 remote,
00391                                ConnectionIdentifier::Data,
00392                                ConnectionIdentifier::Uplink,
00393                                ConnectionIdentifier::BE);
00394 
00395     ConnectionIdentifier ulRtPSCI( associatedWith->getID(),
00396                                 layer->getID(),
00397                                 remote,
00398                                ConnectionIdentifier::Data,
00399                                ConnectionIdentifier::Uplink,
00400                                ConnectionIdentifier::rtPS);
00401 
00402     ConnectionIdentifier ulNrtPSCI( associatedWith->getID(),
00403                                 layer->getID(),
00404                                 remote,
00405                                ConnectionIdentifier::Data,
00406                                ConnectionIdentifier::Uplink,
00407                                ConnectionIdentifier::nrtPS);
00408 
00409     ConnectionIdentifier ulUGSCI( associatedWith->getID(),
00410                                 layer->getID(),
00411                                 remote,
00412                                ConnectionIdentifier::Data,
00413                                ConnectionIdentifier::Uplink,
00414                                ConnectionIdentifier::UGS);
00415 
00416 
00417     // get master ConnectionManager from destination access point
00418     wimac::service::ConnectionManager* associatedWithConnectionManager = 
00419         associatedWith->getManagementService<service::ConnectionManager>("connectionManager");
00420 
00421     // append ConnectionIdentifier to access point and get CID
00422     bCI = associatedWithConnectionManager->appendConnection( bCI );
00423     pmCI = associatedWithConnectionManager->appendConnection( pmCI );
00424 
00425     dlBECI = associatedWithConnectionManager->appendConnection( dlBECI );
00426     dlRtPSCI = associatedWithConnectionManager->appendConnection( dlRtPSCI );
00427     dlNrtPSCI = associatedWithConnectionManager->appendConnection( dlNrtPSCI );
00428     dlUGSCI = associatedWithConnectionManager->appendConnection( dlUGSCI );
00429 
00430     ulBECI = associatedWithConnectionManager->appendConnection( ulBECI );
00431     ulRtPSCI = associatedWithConnectionManager->appendConnection( ulRtPSCI );
00432     ulNrtPSCI = associatedWithConnectionManager->appendConnection( ulNrtPSCI );
00433     ulUGSCI = associatedWithConnectionManager->appendConnection( ulUGSCI );
00434 
00435     //append ConnectionIdentifier myself
00436     friends_.connectionManager->appendConnection( bCI );
00437     friends_.connectionManager->appendConnection( pmCI );
00438 
00439     friends_.connectionManager->appendConnection( dlBECI );
00440     friends_.connectionManager->appendConnection( dlRtPSCI );
00441     friends_.connectionManager->appendConnection( dlNrtPSCI );
00442     friends_.connectionManager->appendConnection( dlUGSCI );
00443 
00444     friends_.connectionManager->appendConnection( ulBECI );
00445     friends_.connectionManager->appendConnection( ulRtPSCI );
00446     friends_.connectionManager->appendConnection( ulNrtPSCI );
00447     friends_.connectionManager->appendConnection( ulUGSCI );
00448 
00449     // append to relayMapper
00450     relay::RSRelayMapper* relayMapper = layer->getFUN()
00451         ->findFriend<relay::RSRelayMapper*>("relayMapper");
00452 
00453     relayMapper->addMapping( relay::RSRelayMapper::RelayMapping(bCI.cid_, basicCID) );
00454     relayMapper->addMapping( relay::RSRelayMapper::RelayMapping(pmCI.cid_, primaryCID) );
00455     relayMapper->addMapping( relay::RSRelayMapper::RelayMapping(dlBECI.cid_, downlinkBETransportCID) );
00456     relayMapper->addMapping( relay::RSRelayMapper::RelayMapping(dlRtPSCI.cid_, downlinkRtPSTransportCID) );
00457     relayMapper->addMapping( relay::RSRelayMapper::RelayMapping(dlNrtPSCI.cid_, downlinkNrtPSTransportCID) );
00458     relayMapper->addMapping( relay::RSRelayMapper::RelayMapping(dlUGSCI.cid_, downlinkUGSTransportCID) );
00459     relayMapper->addMapping( relay::RSRelayMapper::RelayMapping(ulBECI.cid_, uplinkBETransportCID) );
00460     relayMapper->addMapping( relay::RSRelayMapper::RelayMapping(ulRtPSCI.cid_, uplinkRtPSTransportCID) );
00461     relayMapper->addMapping( relay::RSRelayMapper::RelayMapping(ulNrtPSCI.cid_, uplinkNrtPSTransportCID) );
00462     relayMapper->addMapping( relay::RSRelayMapper::RelayMapping(ulUGSCI.cid_, uplinkUGSTransportCID) );
00463 
00464     if ( associatedWith->getStationType() == wns::service::dll::StationTypes::FRS() )
00465     {
00466         associatedWith
00467             ->getControlService<AssociationControl>("associationControl")
00468             ->createRecursiveConnection(bCI.cid_,
00469                                         pmCI.cid_,
00470                                         dlBECI.cid_,
00471                                         dlRtPSCI.cid_,
00472                                         dlNrtPSCI.cid_,
00473                                         dlUGSCI.cid_,
00474                                         ulBECI.cid_,
00475                                         ulRtPSCI.cid_,
00476                                         ulNrtPSCI.cid_,
00477                                         ulUGSCI.cid_,
00478                                         remote);
00479     }
00480 
00481     Component* layer2 =
00482         dynamic_cast<Component*>(getCSR()->getLayer());
00483     assure(layer2, "AssociationControl only works in a wimac component.");
00484 }
00485 

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