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/Layer2.hpp>
00029 #include <DLL/StationManager.hpp>
00030 #include <DLL/UpperConvergence.hpp>
00031 
00032 #include <WNS/ldk/ControlServiceInterface.hpp>
00033 #include <WNS/ldk/ManagementServiceInterface.hpp>
00034 #include <WNS/service/dll/StationTypes.hpp>
00035 #include <WNS/service/phy/ofdma/Handler.hpp>
00036 #include <WNS/service/phy/ofdma/DataTransmission.hpp>
00037 #include <WNS/ldk/utils.hpp>
00038 #include <WNS/module/Base.hpp>
00039 #include <WNS/pyconfig/Parser.hpp>
00040 
00041 #include <sstream>
00042 
00043 using namespace dll;
00044 
00045 ILayer2::StationIDType ILayer2::invalidStationID = -1;
00046 ILayer2::StationIDType ILayer2::broadcastStationID = -2;
00047 
00048 Layer2::Layer2(wns::node::Interface* _node, const wns::pyconfig::View& _config, StationManager* _sm) :
00049     wns::node::component::Component(_node, _config),
00050 
00051     config(_config),
00052     logger(_config.get("logger")),
00053     stationManager( (_sm == NULL) ? TheStationManager::getInstance() : _sm),
00054     stationID(config.get<StationIDType>("stationID")),
00055     type(wns::service::dll::StationTypes::fromString(config.get<std::string>("stationType"))),
00056     address(config.get<wns::service::dll::UnicastAddress>("address")),
00057     ring(config.get<unsigned long int>("ring")),
00058     air(),
00059     agent()
00060 {
00061 }
00062 
00063 
00064 void
00065 Layer2::doStartup()
00066 {
00067     {
00068         if (!agent.knows("MAC.Id"))
00069         { // new method for ProbeBus
00070             agent.setContext("MAC.Id", stationID);
00071             agent.setContext("MAC.Ring", ring);
00072             agent.setContext("MAC.StationType", type);
00073 
00074             wns::probe::bus::ContextProviderCollection& collection =
00075                 getNode()->getContextProviderCollection();
00076 
00077             collection.addProvider(wns::probe::bus::contextprovider::Container(&this->agent));
00078         }
00079     }
00080 
00081     //create the DLL-FUN
00082     wns::pyconfig::View funConfig(config, "fun");
00083     fun = new wns::ldk::fun::Main(this, config);
00084     wns::ldk::configureFUN(fun, funConfig);
00085 
00086     // fire up control and management Services
00087     { // do control services
00088         for (int ii = 0; ii<config.len("controlServices"); ++ii){
00089             wns::pyconfig::View controlServiceView = config.get("controlServices",ii);
00090             std::string serviceName = controlServiceView.get<std::string>("serviceName");
00091             std::string creatorName = controlServiceView.get<std::string>("nameInServiceFactory");
00092             wns::ldk::ControlServiceCreator* serviceCreator = wns::ldk::ControlServiceFactory::creator(creatorName);
00093             wns::ldk::ControlServiceInterface* service = serviceCreator->create(getCSR(), controlServiceView);
00094             addControlService(serviceName, service);
00095             MESSAGE_BEGIN(NORMAL, logger, m, getName());
00096             m << " Registered Control Service: " << serviceName;
00097             MESSAGE_END();
00098         }
00099         // do management services @todo pab: get rid of copy and paste patterns
00100         for (int ii = 0; ii<config.len("managementServices"); ++ii){
00101             wns::pyconfig::View managementServiceView = config.get("managementServices",ii);
00102             std::string serviceName = managementServiceView.get<std::string>("serviceName");
00103             std::string creatorName = managementServiceView.get<std::string>("nameInServiceFactory");
00104             wns::ldk::ManagementServiceCreator* serviceCreator = wns::ldk::ManagementServiceFactory::creator(creatorName);
00105             wns::ldk::ManagementServiceInterface* service = serviceCreator->create(getMSR(), managementServiceView);
00106             addManagementService(serviceName, service);
00107             MESSAGE_BEGIN(NORMAL, logger, m, getName());
00108             m << " Registered Management Service: " << serviceName;
00109             MESSAGE_END();
00110         }
00111     }
00112 
00116     // resolve intra-FUN dependencies
00117     // fun->onFUNCreated();
00118 
00119     // global station registry
00120     stationManager->registerStation(stationID, address, this);
00121 
00122     if(!config.isNone("upperConvergenceName"))
00123     {
00124         std::string upperConvergenceName = config.get<std::string>("upperConvergenceName");
00125         UpperConvergence* upperConvergence =
00126             getFUN()->findFriend<UpperConvergence*>(upperConvergenceName);
00127 
00128         // register UpperConvergence as the DLL DataTransmissionService
00129         addService(config.get<std::string>("dataTransmission"), upperConvergence);
00130         addService(config.get<std::string>("notification"), upperConvergence);
00131         addService(config.get<std::string>("flowEstablishmentAndRelease"), upperConvergence);
00132         upperConvergence->setMACAddress(address);
00133     }
00134 
00135 } // Layer2
00136 
00137 Layer2::~Layer2()
00138 {
00139     if (fun != NULL) {
00140     delete fun;
00141     fun = NULL;
00142     }
00143 } // ~Layer2
00144 
00145 Layer2::StationIDType
00146 Layer2::getID() const
00147 {
00148     return stationID;
00149 } // getID
00150 
00151 wns::service::dll::UnicastAddress
00152 Layer2::getDLLAddress() const
00153 {
00154     return address;
00155 }
00156 
00157 // pab: 2006-07-21 This function is to vanish soon.
00158 std::string
00159 Layer2::getName() const
00160 {
00161     return getNode()->getName();
00162 } // getName
00163 
00164 Layer2::StationType
00165 Layer2::getStationType() const
00166 {
00167     return type;
00168 } // getType
00169 
00170 StationManager*
00171 Layer2::getStationManager()
00172 {
00173     return stationManager;
00174 } // getStationManager
00175 
00176 void
00177 Layer2::addAssociationInfoProvider(const std::string& id, dll::services::control::AssociationInfo* provider)
00178 {
00179     if (! air.knows(id) )
00180     {
00181         AssociationInfoContainer tmp;
00182         air.insert(id, tmp);
00183     }
00184 
00185     AssociationInfoContainer tmp2(air.find(id));
00186     tmp2.push_back(provider);
00187     air.update(id, tmp2);
00188 }
00189 
00190 const Layer2::AssociationInfoContainer&
00191 Layer2::getAssociationInfoProvider(const std::string& id) const
00192 {
00193     return air.find(id);
00194 }
00195 
00196 void
00197 Layer2::ContextAgent::doVisit(wns::probe::bus::IContext& context) const
00198 {
00199     ContextIterator iter = myContextInfo.begin();
00200     ContextIterator end  = myContextInfo.end();
00201 
00202     for( ; iter != end; ++iter)
00203     {
00204         context.insertInt( iter->first, iter->second );
00205     }
00206 }
00207 
00208 
00209 

Generated on Sat Feb 11 03:31:32 2012 for openWNS by  doxygen 1.5.5