User Manual, Developers Guide and API Documentation

Layer2.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-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 5, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 #include <DLL/StationManager.hpp>
00029 
00030 #include <LTE/main/Layer2.hpp>
00031 #include <LTE/timing/TimingScheduler.hpp>
00032 #include <LTE/helper/idprovider/HopCount.hpp>
00033 #include <LTE/helper/idprovider/Distance.hpp>
00034 #include <LTE/helper/idprovider/QoSClass.hpp>
00035 #include <LTE/helper/idprovider/PeerId.hpp>
00036 #include <LTE/macr/PhyUser.hpp>
00037 #include <LTE/timing/ResourceSchedulerInterface.hpp>
00038 
00039 #include <LTE/macr/Mode.hpp>
00040 #include <LTE/controlplane/AssociationsProxy.hpp>
00041 
00042 #include <WNS/service/dll/StationTypes.hpp>
00043 #include <WNS/service/phy/ofdma/Handler.hpp>
00044 #include <WNS/service/phy/ofdma/DataTransmission.hpp>
00045 #include <WNS/ldk/utils.hpp>
00046 #include <WNS/pyconfig/Parser.hpp>
00047 
00048 #include <WNS/service/phy/ofdma/Measurements.hpp>
00049 
00050 #include <DLL/services/control/Association.hpp>
00051 
00052 #include <sstream>
00053 
00054 using namespace lte;
00055 using namespace lte::main;
00056 
00057 STATIC_FACTORY_REGISTER_WITH_CREATOR(Layer2,
00058                      wns::node::component::Interface,
00059                      "lte.Layer2",
00060                      wns::node::component::ConfigCreator);
00061 
00062 Layer2::Layer2(wns::node::Interface* _node, const wns::pyconfig::View& _config) :
00063   dll::Layer2(_node, _config, NULL)
00064 {
00065 } // Layer2
00066 
00067 void
00068 Layer2::doStartup()
00069 {
00070   dll::Layer2::doStartup();
00071   // Trigger all FUs in the FUN to perform their dependency resolution with
00072   // other FUs and related tasks
00073   fun->onFUNCreated();
00074 
00075   // register HopCount, QoSClass and PeerId IDProvider
00076   getNode()->getContextProviderCollection().addProvider(lte::helper::idprovider::HopCount(fun));
00077   getNode()->getContextProviderCollection().addProvider(lte::helper::idprovider::QoSClass(fun));
00078   getNode()->getContextProviderCollection().addProvider(lte::helper::idprovider::PeerId(fun));
00079 
00080   MESSAGE_BEGIN(NORMAL, logger, m, "Done Creating Layer2 component in ");
00081   m << this->getNode()->getName()
00082     << ". MAC-Address is: "
00083     << address;
00084   MESSAGE_END();
00085 }
00086 
00087 Layer2::~Layer2()
00088 {} // ~Layer2
00089 
00090 void
00091 Layer2::onNodeCreated()
00092 {
00093   MESSAGE_SINGLE(NORMAL, logger, "Layer2::onNodeCreated()");
00094 
00095   // Initialize management and control services
00096   getMSR()->onMSRCreated();
00097   getCSR()->onCSRCreated();
00098 
00099 
00100 
00101   // First obtain the dicts with the PHY service names.
00102   wns::pyconfig::View phyDataTransView(config, "phyDataTransmission");
00103   wns::pyconfig::View phyNotifyView(config, "phyNotification");
00104   wns::pyconfig::View phyMeasurementsView(config, "phyMeasurements");
00105 
00106   // register IDProvider for per-compound distance Calculation
00107   std::string modeName = phyDataTransView.get<std::string>("keys()", 0);
00108   wns::ldk::CommandReaderInterface* cmdReader;
00109   cmdReader = getFUN()->getCommandReader(modeName + "_phyUser");
00110 
00111   getNode()->getContextProviderCollection().
00112     addProvider(lte::helper::idprovider::Distance(fun, cmdReader));
00113 
00114 
00115   // Check whether the dicts are complete (i.e., contain equal number of modes.)
00116   int numModes  = phyDataTransView.get<int>("__len__()");
00117   int numModes2 = phyNotifyView.get<int>("__len__()");
00118 
00119   assure(numModes == numModes2, "unequal size of phyDataTransmission and phyNotification service dicts");
00120 
00121   for(int i=0; i<numModes; i++) // forall modes
00122     {
00123       // obtain mode name from keys() list in the dict
00124       std::string modeName = phyDataTransView.get<std::string>("keys()", i);
00125 
00126       // Safety check: make sure that the ordering [i] is the same for both Dicts
00127       assure( modeName == phyNotifyView.get<std::string>("keys()", i),
00128           "mode name mismatch between phyDataTransmission and phyNotification service dicts" );
00129 
00130       // obtain PHY service names from values() list in the dicts
00131       std::string transServiceName       = phyDataTransView.get<std::string>("values()", i);
00132       std::string notifyServiceName      = phyNotifyView.get<std::string>("values()", i);
00133 
00134       MESSAGE_SINGLE(NORMAL, logger, "onNodeCreated(): setting physical layer for mode " << modeName);
00135 
00136       // obtain pointer to mode-specific PhyUser in the FUN
00137       lte::macr::PhyUser* phyUser =
00138     getFUN()->findFriend<lte::macr::PhyUser*>(modeName+"_phyUser");
00139 
00140       // Set services in PhyUser to establish the connection of my FUN with lower layer
00141       // obtain and set DataTransmission Service
00142       wns::service::phy::ofdma::DataTransmission* phyDataTx =
00143     getService<wns::service::phy::ofdma::DataTransmission*>( transServiceName );
00144       phyUser->setDataTransmissionService( phyDataTx );
00145       // obtain and set Notification Service
00146       wns::service::phy::ofdma::Notification* phyNotification =
00147     getService<wns::service::phy::ofdma::Notification*>( notifyServiceName );
00148       phyUser->setNotificationService( phyNotification );
00149 
00150       // Inform PhyUser about our MAC Address
00151       phyUser->setMACAddress(address);
00152       // Inform PhyUser about our Mobility Service
00153       phyUser->setMobility( getNode()->getService<wns::PositionableInterface*>("mobility") );
00154 
00155       lte::timing::SchedulerFUInterface* rstx =
00156       getFUN()->findFriend<lte::timing::SchedulerFUInterface*>(modeName+"_resourceSchedulerTX");
00157       rstx->onNodeCreated();
00158       lte::timing::SchedulerFUInterface* rsrx =
00159       getFUN()->findFriend<lte::timing::SchedulerFUInterface*>(modeName+"_resourceSchedulerRX");
00160       rsrx->onNodeCreated();
00161     }
00162 }
00163 
00164 void
00165 Layer2::onWorldCreated()
00166 {
00167     // initial associations, if present
00168     if(config.knows("associations"))
00169     {
00170         for(int i = 0; i < config.len("associations"); ++i) { // forall associations
00171             // get route of "associations" (containing source=this,destination,mode)
00172             wns::pyconfig::View routeConfig = wns::pyconfig::View(config, "associations", i);
00173             // source
00174             assure(dynamic_cast<lte::main::Layer2*>(
00175                        stationManager->getStationByID(
00176                            routeConfig.get<Layer2::StationIDType>("source.stationID")))==this,
00177                    "Tried to handle somebody else's association!");
00178             // destination
00179             ILayer2::StationIDType destinationID =
00180                 routeConfig.get<Layer2::StationIDType>("destination.stationID");
00181             dll::ILayer2* destination = stationManager->getStationByID(destinationID);
00182             // get mode string
00183             lte::macr::Mode mode = routeConfig.get<lte::macr::Mode>("mode");
00184             // association from this to the master
00185             getControlService<dll::services::control::Association>("ASSOCIATION"+mode)
00186                 ->associate(this, destination);
00187 
00188     if (this->getStationType() == wns::service::dll::StationTypes::FRS())
00189       {
00190         destination->getControlService<lte::controlplane::AssociationsProxyBS>("AssociationsProxy")
00191           ->addRAPofREC(this->getDLLAddress());
00192       }// this is RN
00193     else
00194       {
00195         assure(false,"static associations for UT,BS not allowed anymore");
00196       }
00197       }// forall associations
00198     } // if
00199   // init TimingScheduler services
00202   for (int ii = 0; ii<config.len("managementServices"); ++ii){
00203     wns::pyconfig::View managementServiceView = config.get("managementServices",ii);
00204     std::string serviceName = managementServiceView.get<std::string>("serviceName");
00205     lte::timing::TimingScheduler* ts = NULL;
00206     wns::ldk::ManagementServiceInterface* ms = NULL;
00207     ms = this->getManagementService<wns::ldk::ManagementServiceInterface>(serviceName);
00208     ts = dynamic_cast<lte::timing::TimingScheduler*>(ms);
00209     if (ts)
00210       ts->onWorldCreated();
00211   }
00212 
00213 }
00214 
00215 
00216 void Layer2::onShutdown()
00217 {}

Generated on Sun May 27 03:31:36 2012 for openWNS by  doxygen 1.5.5