User Manual, Developers Guide and API Documentation

CRC.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/crc/CRC.hpp>
00029 
00030 #include <WNS/ldk/fun/FUN.hpp>
00031 #include <WNS/ldk/Layer.hpp>
00032 #include <WNS/ldk/ErrorRateProviderInterface.hpp>
00033 
00034 #include <WNS/StaticFactory.hpp>
00035 #include <WNS/module/Base.hpp>
00036 #include <WNS/probe/bus/utils.hpp>
00037 
00038 #include <WNS/rng/RNGen.hpp>
00039 
00040 using namespace wns::ldk;
00041 using namespace wns::ldk::crc;
00042 
00043 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00044     CRC,
00045     FunctionalUnit,
00046     "wns.crc.CRC",
00047     FUNConfigCreator);
00048 
00049 CRC::CRC(fun::FUN* fuNet, const wns::pyconfig::View& config) :
00050     fu::Plain<CRC, CRCCommand>(fuNet),
00051     SuspendSupport(fuNet, config),
00052     dis(),
00053     checkSumLength(config.get<int>("CRCsize")),
00054     PERProviderName(config.get<std::string>("PERProvider")),
00055     behaviour( config.get<bool>("isDropping") ? DROPPING : MARKING ),
00056     friends(),
00057     logger(config.get("logger"))
00058 {
00059     // read the localIDs from the config
00060     wns::probe::bus::ContextProviderCollection localContext(&fuNet->getLayer()->getContextProviderCollection());
00061 
00062     for (int ii = 0; ii<config.len("localIDs.keys()"); ++ii)
00063     {
00064         std::string key = config.get<std::string>("localIDs.keys()",ii);
00065         unsigned long int value  = config.get<unsigned long int>("localIDs.values()",ii);
00066         localContext.addProvider( wns::probe::bus::contextprovider::Constant(key, value) );
00067     }
00068 
00069     friends.PERProvider = NULL;
00070     lossRatio = wns::probe::bus::collector(localContext, config, "lossRatioProbeName");
00071 } // CRC
00072 
00073 CRC::~CRC()
00074 {
00075     friends.PERProvider = NULL;
00076 }
00077 
00078 void
00079 CRC::onFUNCreated()
00080 {
00081     friends.PERProvider = getFUN()->findFriend<FunctionalUnit*>(PERProviderName);
00082     assure(friends.PERProvider, "CRC requires a PERProvider friend with name '" + PERProviderName + "'");
00083 }  // onFUNCreated
00084 
00085 void
00086 CRC::doSendData(const CompoundPtr& compound)
00087 {
00088     activateCommand(compound->getCommandPool());
00089 
00090     MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName());
00091     m << " passing through CRC outgoing";
00092     MESSAGE_END();
00093 
00094     getConnector()->getAcceptor(compound)->sendData(compound);
00095 }
00096 
00097 void
00098 CRC::doOnData(const CompoundPtr& compound)
00099 {
00100     assure( (behaviour==DROPPING || behaviour==MARKING), "Unknown CRC behaviour" );
00101 
00102     CRCCommand* command = getCommand(compound->getCommandPool());
00103 
00104     ErrorRateProviderInterface* ppi = dynamic_cast<ErrorRateProviderInterface*>(
00105         friends.PERProvider->getCommand(compound->getCommandPool()));
00106 
00107     assure(ppi, "Expected a ErrorRateProviderInterface instance.");
00108 
00109     double per = ppi->getErrorRate();
00110     // if no known friends exist, the per should be
00111     if ( dis() < per ){
00112 
00113         if (lossRatio != NULL)
00114         {
00115             lossRatio->put(compound, 1);
00116         }
00117 
00118         MESSAGE_SINGLE(VERBOSE, logger, ppi->getInfo());
00119 
00120         if (behaviour == DROPPING)
00121         {
00122             MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName());
00123             m << " CRCheck - failed - dropping compound";
00124             MESSAGE_END();
00125             return;
00126         }
00127         else
00128         {
00129             command->local.checkOK = false;
00130             MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName());
00131             m << " CRCheck - failed - compound marked";
00132             MESSAGE_END();
00133         }
00134     }
00135     else
00136     {
00137         command->local.checkOK = true;
00138 
00139         if (lossRatio != NULL)
00140         {
00141             lossRatio->put(compound, 0);
00142         }
00143 
00144         MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName());
00145         m << " CRCheck - success";
00146         MESSAGE_END();
00147     }
00148     if(getDeliverer()->size())
00149         getDeliverer()->getAcceptor(compound)->onData(compound);
00150 }
00151 
00152 
00153 bool
00154 CRC::doIsAccepting(const CompoundPtr& compound) const
00155 {
00156     CompoundPtr compoundCopy = compound->copy();
00157 
00158     activateCommand(compoundCopy->getCommandPool());
00159 
00160     return getConnector()->hasAcceptor(compoundCopy);
00161 } // doIsAccepting
00162 
00163 
00164 void
00165 CRC::calculateSizes(const CommandPool* commandPool, Bit& commandPoolSize, Bit& sduSize) const
00166 {
00167     //What are the sizes in the upper Layers
00168     getFUN()->calculateSizes(commandPool, commandPoolSize, sduSize, this);
00169     commandPoolSize += checkSumLength;
00170 
00171 } // calculateSizes
00172 
00173 
00174 bool
00175 CRC::isMarking() const
00176 {
00177     return behaviour == MARKING;
00178 } // isMarking
00179 
00180 
00181 

Generated on Mon May 21 03:31:44 2012 for openWNS by  doxygen 1.5.5