User Manual, Developers Guide and API Documentation

Dropping.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 <WNS/ldk/buffer/Dropping.hpp>
00029 
00030 using namespace wns::ldk;
00031 using namespace wns::ldk::buffer;
00032 using namespace wns::ldk::buffer::dropping;
00033 
00034 
00035 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00036     Dropping,
00037     Buffer,
00038     "wns.buffer.Dropping",
00039     FUNConfigCreator);
00040 
00041 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00042     Dropping,
00043     FunctionalUnit,
00044     "wns.buffer.Dropping",
00045     FUNConfigCreator);
00046 
00047 //
00048 // strategies
00049 //
00050 
00051 // Drop strategies
00052 using namespace wns::ldk::buffer::dropping::drop;
00053 
00054 CompoundPtr
00055 Tail::operator()(ContainerType& container) const
00056 {
00057     CompoundPtr it = container.back();
00058     container.pop_back();
00059     return it;
00060 } // Tail()
00061 STATIC_FACTORY_REGISTER(Tail, Drop, "Tail");
00062 
00063 
00064 CompoundPtr
00065 Front::operator()(ContainerType& container) const
00066 {
00067     CompoundPtr it = container.front();
00068     container.pop_front();
00069     return it;
00070 } // Front()
00071 STATIC_FACTORY_REGISTER(Front, Drop, "Front");
00072 
00073 
00074 //
00075 // FunctionalUnit implementation
00076 //
00077 
00078 Dropping::Dropping(fun::FUN* fuNet, const wns::pyconfig::View& config) :
00079         Buffer(fuNet, config),
00080 
00081         fu::Plain<Dropping>(fuNet),
00082         Delayed<Dropping>(),
00083 
00084         buffer(ContainerType()),
00085         maxSize(config.get<int>("size")),
00086         currentSize(0),
00087         sizeCalculator(),
00088         dropper(),
00089         totalPDUs(),
00090         droppedPDUs(),
00091         logger("WNS", config.get<std::string>("name"))
00092 {
00093     {
00094         std::string pluginName = config.get<std::string>("sizeUnit");
00095         sizeCalculator = std::auto_ptr<SizeCalculator>(SizeCalculator::Factory::creator(pluginName)->create());
00096     }
00097 
00098     {
00099         std::string pluginName = config.get<std::string>("drop");
00100         dropper = std::auto_ptr<Drop>(Drop::Factory::creator(pluginName)->create());
00101     }
00102 } // Dropping
00103 
00104 Dropping::Dropping(const Dropping& other) :
00105     CompoundHandlerInterface<FunctionalUnit>(other),
00106     CommandTypeSpecifierInterface(other),
00107     HasReceptorInterface(other),
00108     HasConnectorInterface(other),
00109     HasDelivererInterface(other),
00110     CloneableInterface(other),
00111     IOutputStreamable(other),
00112     PythonicOutput(other),
00113     FunctionalUnit(other),
00114     DelayedInterface(other),
00115     Buffer(other),
00116     fu::Plain<Dropping>(other),
00117     Delayed<Dropping>(other),
00118     buffer(other.buffer),
00119     maxSize(other.maxSize),
00120     currentSize(other.currentSize),
00121     sizeCalculator(wns::clone(other.sizeCalculator)),
00122     dropper(wns::clone(other.dropper)),
00123     totalPDUs(other.totalPDUs),
00124     droppedPDUs(other.droppedPDUs),
00125     logger(other.logger)
00126 {
00127 }
00128 
00129 Dropping::~Dropping()
00130 {
00131 } // ~Dropping
00132 
00133 
00134 //
00135 // Delayed interface
00136 //
00137 void
00138 Dropping::processIncoming(const CompoundPtr& compound)
00139 {
00140     getDeliverer()->getAcceptor(compound)->onData(compound);
00141 } // processIncoming
00142 
00143 
00144 bool
00145 Dropping::hasCapacity() const
00146 {
00147     return true;
00148 } // hasCapacity
00149 
00150 
00151 void
00152 Dropping::processOutgoing(const CompoundPtr& compound)
00153 {
00154     buffer.push_back(compound);
00155     currentSize += (*sizeCalculator)(compound);
00156 
00157     while(currentSize > maxSize) {
00158 
00159         MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName());
00160         m << " dropping a PDU! maxSize reached : " << maxSize;
00161         m << " current size is " << currentSize;
00162         MESSAGE_END();
00163 
00164         CompoundPtr toDrop = (*dropper)(buffer);
00165         int pduSize = (*sizeCalculator)(toDrop);
00166         currentSize -= pduSize;
00167         increaseDroppedPDUs(pduSize);
00168     }
00169 
00170     increaseTotalPDUs();
00171     probe();
00172 } // processOutgoing
00173 
00174 
00175 const CompoundPtr
00176 Dropping::hasSomethingToSend() const
00177 {
00178     if(buffer.empty())
00179         return CompoundPtr();
00180 
00181     return buffer.front();
00182 } // somethingToSend
00183 
00184 
00185 CompoundPtr
00186 Dropping::getSomethingToSend()
00187 {
00188     CompoundPtr compound = buffer.front();
00189     buffer.pop_front();
00190 
00191     currentSize -= (*sizeCalculator)(compound);
00192     probe();
00193 
00194     return compound;
00195 } // getSomethingToSend
00196 
00197 
00198 //
00199 // Buffer interface
00200 //
00201 
00202 unsigned long int
00203 Dropping::getSize()
00204 {
00205     return currentSize;
00206 } // getSize
00207 
00208 
00209 unsigned long int
00210 Dropping::getMaxSize()
00211 {
00212     return maxSize;
00213 } // getMaxSize
00214 
00215 

Generated on Wed May 23 03:31:36 2012 for openWNS by  doxygen 1.5.5