User Manual, Developers Guide and API Documentation

FlowHandler.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 <LTE/controlplane/flowmanagement/flowhandler/FlowHandler.hpp>
00029 #include <LTE/controlplane/flowmanagement/FlowManager.hpp>
00030 #include <LTE/macg/MACg.hpp>
00031 #include <LTE/helper/Keys.hpp>
00032 
00033 #include <DLL/StationManager.hpp>
00034 #include <DLL/Layer2.hpp>
00035 
00036 #include <WNS/service/dll/StationTypes.hpp>
00037 
00038 #define A2N(a) (((a).getInteger()>0) ? layer2->getStationManager()->getStationByMAC(a)->getName() : "DLL<0")
00039 
00040 using namespace lte::controlplane::flowmanagement::flowhandler;
00041 
00042 FlowHandler::FlowHandler(wns::ldk::fun::FUN* fun, const wns::pyconfig::View& config) :
00043   wns::ldk::CommandTypeSpecifier<FlowHandlerCommand>(fun),
00044   wns::ldk::HasReceptor<>(),
00045   wns::ldk::HasDeliverer<>(),
00046   helper::HasModeName(config),
00047   fun(fun),
00048   layer2(fun->getLayer<dll::ILayer2*>()),
00049   macg(NULL),
00050   rlcReader(NULL),
00051   flowManager(NULL),
00052   associationService(NULL),
00053   logger(config.get("logger")),
00054   commandSize(config.get<Bit>("commandSize")),
00055   lowerFlowGate(NULL),
00056   flowSeparatorNames()
00057 {
00058   for(int i = 0; i < config.len("flowSeparators"); ++i)
00059     {
00060       std::string fsName = config.get<std::string>("flowSeparators", i);
00061       flowSeparatorNames.push_back(fsName);
00062 
00063       MESSAGE_BEGIN(NORMAL, logger, m, " " );
00064       m << "Added Flowseparator: " << fsName;
00065       MESSAGE_END();
00066     }
00067 }
00068 
00069 FlowHandler::~FlowHandler()
00070 {
00071 }
00072 
00073 void
00074 FlowHandler::onFUNCreated()
00075 {
00076   associationService = layer2->getControlService<dll::services::control::Association>("ASSOCIATION"+modeBase);
00077   assure(associationService, "AssociationService not set.");
00078   //get flow separators from config
00079   for(std::list<std::string>::iterator iter = flowSeparatorNames.begin(); iter != flowSeparatorNames.end(); ++iter)
00080     {
00081       MESSAGE_SINGLE(NORMAL, logger, "Added FlowSeparator for: "<< *iter);
00082       wns::ldk::FlowSeparator* flowSeparator = fun->findFriend<wns::ldk::FlowSeparator*>(*iter);
00083       flowSeparators.push_back(flowSeparator);
00084     }
00085 
00086   std::string flowmanagername="FlowManager";
00087   if (layer2->getStationType() == wns::service::dll::StationTypes::UE()) {
00088     flowmanagername += "UT";
00089   } else { // BS
00090     flowmanagername += "BS";
00091   }
00092   flowManager = layer2->getControlService<lte::controlplane::flowmanagement::FlowManager>(flowmanagername);
00093   assure(flowManager, "FlowManager not set.");
00094   rlcReader = fun->getCommandReader("rlc");
00095   assure(rlcReader, "rlc not set.");
00096 
00097   dll::services::control::Association* associationService = layer2->getControlService<dll::services::control::Association>("ASSOCIATION"+modeBase);
00098 
00099   // Register as Observer at the association info provider
00100   // Do not register in RN in UT task. Would lead to double calls to FlowManagerRN::onDisassociated()
00101   // We want to be informed about a completed disassociationAck, so that we can remove the controlPlaneFlowIds.
00102   if (!((layer2->getStationType() == wns::service::dll::StationTypes::FRS()) && (taskID == "UT"))) {
00103     MESSAGE_SINGLE(NORMAL, logger, "Starting to observe AssociationInfoProvider. taskID=\""<<taskID<<"\", mode=\""<<mode<<"\"");
00104     //dll::Layer2::AssociationInfoContainer ais = layer2->getAssociationInfoProvider(modeBase);
00105     dll::ILayer2::AssociationInfoContainer ais = layer2->getAssociationInfoProvider(mode);
00106     dll::ILayer2::AssociationInfoContainer::const_iterator iter = ais.begin();
00107     for (; iter != ais.end(); ++iter)
00108       this->startObserving(*iter);
00109   } else {
00110     MESSAGE_SINGLE(NORMAL, logger, "Refusing to observe AssociationInfoProvider. taskID=\""<<taskID<<"\"");
00111   }
00112 } // onFUNCreated
00113 
00114 void
00115 FlowHandler::doSendData(const wns::ldk::CompoundPtr&)
00116 {
00117   assure(false, "Should never be called!");
00118 }
00119 
00120 bool
00121 FlowHandler::doIsAccepting(const wns::ldk::CompoundPtr&  /*compound*/) const
00122 {
00123   return true;
00124 }
00125 
00126 void
00127 FlowHandler::doWakeup()
00128 {}
00129 
00130 void
00131 FlowHandler::calculateSizes(const wns::ldk::CommandPool* commandPool,
00132                 Bit& commandPoolSize,
00133                 Bit& dataSize) const
00134 {
00135   fun->calculateSizes(commandPool, commandPoolSize, dataSize, this);
00136 
00137   // add my commandSize. No Data to add.
00138   commandPoolSize += this->commandSize;
00139 }
00140 
00141 void
00142 FlowHandler::destroyFlow(wns::service::dll::FlowID flowID)
00143 {
00144   wns::ldk::ConstKeyPtr key(new lte::helper::key::FlowID(flowID));
00145 
00146   // delete instances of flowSeparators
00147   for (std::list<wns::ldk::FlowSeparator*>::iterator iter = flowSeparators.begin();
00148        iter != flowSeparators.end(); ++iter)
00149     {
00150       if ((*iter)->getInstance(key) != NULL)
00151     {
00152       (*iter)->removeInstance(key);
00153       lowerFlowGate->destroyFlow(key);
00154       MESSAGE_SINGLE(NORMAL, logger, "Deleted lower FlowSeparator and FlowGate for FlowID="<< flowID);
00155     }
00156       else
00157     {
00158       MESSAGE_SINGLE(NORMAL, logger, "No instances to delete found for FlowID="<< flowID);
00159     }
00160     }
00161 }
00162 
00163 void
00164 FlowHandler::closeFlow(wns::service::dll::FlowID flowID)
00165 {
00166   wns::ldk::ConstKeyPtr key(new lte::helper::key::FlowID(flowID));
00167   lowerFlowGate->closeFlow(key);
00168   MESSAGE_SINGLE(NORMAL, logger, "Lower Flow closed for FlowID: "<< flowID);
00169 }
00170 
00171 void
00172 FlowHandler::onAssociated(wns::service::dll::UnicastAddress userAdr, wns::service::dll::UnicastAddress dstAdr)
00173 {
00174   assure(flowManager, "FlowManager not set.");
00175   flowManager->onAssociated(userAdr,dstAdr);
00176 }
00177 
00178 // called from AckOnAirCallback::callback() triggered by PhyUser sending the very last "AssociationAck" packet
00179 void
00180 FlowHandler::onDisassociated(wns::service::dll::UnicastAddress userAdr, wns::service::dll::UnicastAddress dstAdr)
00181 {
00182   MESSAGE_SINGLE(NORMAL, logger, "onDisassociated(from "<<A2N(userAdr)<<" to "<<A2N(dstAdr)<<")");
00183   assure(flowManager, "FlowManager not set.");
00184   if (dstAdr == layer2->getDLLAddress()) { // we are meant (dstAdr=RAP)
00185     MESSAGE_SINGLE(NORMAL, logger, "onDisassociated: calling flowManager->onDisassociated");
00186     flowManager->onDisassociated(userAdr,dstAdr);
00187   } else if (userAdr == layer2->getDLLAddress()) { // we are meant (userAdr==UT)
00188     assure(layer2->getStationType() == wns::service::dll::StationTypes::UE(),"wrong stationType");
00189     MESSAGE_SINGLE(NORMAL, logger, "onDisassociated: calling flowManager->onDisassociated");
00190     flowManager->onDisassociated(userAdr,dstAdr);
00191   } else {
00192     // we are BS in a Multihop case (dstAdr=via=RN) and do not delete the controlPlaneFlowId between BS and RN
00193     // therefore we don't call flowManager->onDisassociated(userAdr,dstAdr);
00194     //MESSAGE_SINGLE(NORMAL, logger, "onDisassociated(from "<<A2N(userAdr)<<" via "<<A2N(dstAdr)<<")");
00195   }
00196 }

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