User Manual, Developers Guide and API Documentation

Component.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. 16, 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 <TCP/Component.hpp>
00029 #include <TCP/Service.hpp>
00030 #include <TCP/LowerConvergence.hpp>
00031 #include <TCP/IPDataHandler.hpp>
00032 #include <TCP/UpperConvergence.hpp>
00033 
00034 #include <WNS/ldk/utils.hpp>
00035 #include <WNS/ldk/Group.hpp>
00036 
00037 #include <WNS/ldk/ControlServiceInterface.hpp>
00038 #include <WNS/service/dll/FlowEstablishmentAndRelease.hpp>
00039 #include <WNS/service/dll/Handler.hpp>
00040 
00041 using namespace tcp;
00042 
00043 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00044     Component,
00045     wns::node::component::Interface,
00046     "tcp.Component",
00047     wns::node::component::ConfigCreator
00048     );
00049 
00050 Component::Component(
00051     wns::node::Interface* node,
00052     const wns::pyconfig::View& config) :
00053 
00054     wns::node::component::Component(node, config),
00055     fun(NULL),
00056     subFUN(NULL),
00057     tlService(NULL),
00058     upperConvergence(NULL),
00059     ipDataHandler(new IPDataHandler()),
00060     lowerConvergence(NULL),
00061     ipDataTransmission(NULL),
00062     flowSeparator(NULL),
00063     handshakeStrategy(NULL),
00064     logger(config.get<wns::pyconfig::View>("logger")),
00065     tcpFlowHandler(NULL),
00066     fear(NULL),
00067     dllNotification(NULL)
00068 {
00069 } // Component
00070 
00071 
00072 void
00073 Component::doStartup()
00074 {
00075     wns::pyconfig::View config = this->getConfig();
00076 
00077     // build FUN
00078     fun = new wns::ldk::fun::Main(this);
00079     // build Sub-FUN
00080     subFUN = new wns::ldk::fun::Sub(fun);
00081 
00082     wns::ldk::configureFUN(fun, config.get<wns::pyconfig::View>("fun"));
00083 
00084     lowerConvergence = dynamic_cast<LowerConvergence*>(
00085         fun->getFunctionalUnit(
00086             getConfig().get<std::string>("lowerConvergence.commandName")));
00087 
00088     ipDataTransmission = getService<wns::service::nl::Service*>(config.get<std::string>("ipDataTransmission"));
00089 
00090     // configure ipDataHandler with Dispatcher from FUN
00091     ipDataHandler->setLowerConvergence(lowerConvergence);
00092 
00093     upperConvergence = dynamic_cast<UpperConvergence*>(
00094         fun->getFunctionalUnit(
00095             getConfig().get<std::string>("upperConvergence.commandName")));
00096 
00097     flowSeparator = dynamic_cast<wns::ldk::FlowSeparator*>(
00098         fun->getFunctionalUnit(
00099             getConfig().get<std::string>("flowSeparator.commandName")));
00100 
00101     wns::ldk::ControlServiceRegistry* csr = NULL;
00102 
00103     // DLL FlowHandling:
00104     // if FlowEstablishmentAndRelease is being used.
00105 
00106     tcpFlowHandler = new tcp::FlowHandler();
00107 
00108     if (!config.isNone("flowEstablishmentAndRelease"))
00109     {
00110         fear = getService<wns::service::dll::FlowEstablishmentAndRelease*> (config.get<std::string>("flowEstablishmentAndRelease"));
00111     }
00112     if (!config.isNone("dllNotification"))
00113     {
00114         dllNotification = getService<wns::service::dll::Notification*> (config.get<std::string>("dllNotification"));
00115         dllNotification->registerFlowHandler(tcpFlowHandler);
00116     }
00117 
00118     tlService = new Service(upperConvergence, lowerConvergence, flowSeparator, config.get<wns::pyconfig::View>("serviceConfig"),tcpFlowHandler, fear,  csr);
00119     addService(getConfig().get<std::string>("service"), tlService);
00120     fun->getLayer()->addControlService("fip", tlService);
00121 
00122     tcpFlowHandler->setTLService(tlService);
00123     lowerConvergence->setTLService(tlService);
00124 
00125     subFUN->onFUNCreated();
00126     MESSAGE_SINGLE(NORMAL, logger, "Constructed subFUN");
00127 
00128     fun->onFUNCreated();
00129     MESSAGE_SINGLE(NORMAL, logger, "Constructed FUN");
00130 }
00131 
00132 
00133 Component::~Component()
00134 {
00135     delete ipDataHandler;
00136     delete fun;
00137     delete subFUN;
00138 } // ~Component
00139 
00140 void
00141 Component::onNodeCreated()
00142 {
00143     MESSAGE_SINGLE(NORMAL, logger, fun->getName() << ": onNodeCreated(), connecting to IP");
00144 
00145     //tcp service needs to know the ip address for setting the flow id
00146     tlService->setDataTransmissionService(
00147         getService<wns::service::nl::Service*>(
00148             getConfig().get<std::string>("ipDataTransmission")));
00149 
00150     lowerConvergence->setDataTransmissionService(getService<wns::service::nl::Service*>(
00151                                                      getConfig().get<std::string>("ipDataTransmission")));
00152 
00153     wns::service::nl::protocolNumber protocolNr = stringToProtocolNumber(getConfig().get<std::string>("protocolNumber"));
00154 
00155     lowerConvergence->setProtocolNumber(protocolNr);
00156     getService<wns::service::nl::Notification*>(
00157         getConfig().get<std::string>("ipNotification"))->registerHandler(protocolNr, ipDataHandler);
00158 
00159 }
00160 
00161 void
00162 Component::onWorldCreated()
00163 {
00164     tlService->setDNSService(
00165         getService<wns::service::nl::DNSService*>(
00166             getConfig().get<std::string>("dnsService")));
00167 }
00168 
00169 void
00170 Component::onShutdown()
00171 {
00172 }
00173 
00174 wns::service::nl::protocolNumber
00175 Component::stringToProtocolNumber(std::string _protNr)
00176 {
00177     if (_protNr == "TCP")
00178     {
00179         return wns::service::nl::TCP;
00180     }
00181     else if (_protNr == "UDP")
00182     {
00183         return wns::service::nl::UDP;
00184     }
00185     else
00186     {
00187         assure(false, "Unknown protocol type");
00188     }
00189 
00190     return wns::service::nl::TCP;
00191 }

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