User Manual, Developers Guide and API Documentation

BERMeasurementReporting.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  * WNS (Wireless Network Simulator)                                           *
00003  * __________________________________________________________________________ *
00004  *                                                                            *
00005  * Copyright (C) 2004-2006                                                    *
00006  * Chair of Communication Networks (ComNets)                                  *
00007  * Kopernikusstr. 16, D-52074 Aachen, Germany                                 *
00008  * phone: ++49-241-80-27910 (phone), fax: ++49-241-80-22242                   *
00009  * email: wns@comnets.rwth-aachen.de                                          *
00010  * www: http://wns.comnets.rwth-aachen.de                                     *
00011  ******************************************************************************/
00012 
00013 #include <GLUE/BERMeasurementReporting.hpp>
00014 
00015 using namespace glue;
00016 using namespace wns::ldk;
00017 
00018 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00019     BERMeasurementReporting,
00020     wns::ldk::FunctionalUnit,
00021     "glue.BERMeasurementReporting",
00022     FUNConfigCreator);
00023 
00024 BERMeasurementReporting::BERMeasurementReporting(
00025     wns::ldk::fun::FUN* fuNet,
00026     const wns::pyconfig::View& _config) :
00027 
00028     wns::ldk::CommandTypeSpecifier<BERMeasurementReportingCommand>(fuNet),
00029     HasReceptor<>(),
00030     HasConnector<>(),
00031     HasDeliverer<>(),
00032     wns::Cloneable<BERMeasurementReporting>(),
00033     headerSize(_config.get<int>("headerSize")),
00034     summedBER(0.0),
00035     summedPacketSize(0),
00036     numberOfPackets(0),
00037     hasSomethingToSend(false),
00038     compoundToBeSent(),
00039     config(_config),
00040     logger(_config.get<wns::pyconfig::View>("logger"))
00041 {
00042     friends.berProvider = NULL;
00043     startPeriodicTimeout(config.get<double>("transmissionInterval"),
00044                  config.get<double>("transmissionInterval"));
00045 }
00046 
00047 
00048 BERMeasurementReporting::~BERMeasurementReporting()
00049 {
00050 } // ~BERMeasurement
00051 
00052 
00053 void
00054 BERMeasurementReporting::doOnData(const CompoundPtr& compound)
00055 {
00056     BERMeasurementReportingCommand* berCommand = getCommand(compound->getCommandPool());
00057 
00058     MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName());
00059     m << " Received BER measurement report from peer entity\n"
00060       << " BER: " << berCommand->peer.BER
00061       << ", packet size: " << berCommand->magic.packetSize;
00062     MESSAGE_END();
00063 
00064     notifyBERConsumers(berCommand->peer.BER, berCommand->magic.packetSize);
00065 } // doOnData
00066 
00067 
00068 void
00069 BERMeasurementReporting::onFUNCreated()
00070 {
00071     friends.berProvider = getFUN()->findFriend<BERProvider*>(config.get<std::string>("BERProvider"));
00072     friends.berProvider->attachBERConsumer(this);
00073 } // onFUNCreated
00074 
00075 
00076 void
00077 BERMeasurementReporting::calculateSizes(const CommandPool* commandPool, Bit& commandPoolSize, Bit& dataSize) const
00078 {
00079     getFUN()->calculateSizes(commandPool, commandPoolSize, dataSize, this);
00080 
00081     commandPoolSize += headerSize;
00082 } // calculateSizes
00083 
00084 
00085 void
00086 BERMeasurementReporting::onBERProviderDeleted()
00087 {
00088     MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName());
00089     m << " Lost BERProvider!";
00090     MESSAGE_END();
00091 } // BERProviderDeleted
00092 
00093 
00094 void
00095 BERMeasurementReporting::onNewMeasurement(double BER, int packetSize)
00096 {
00097     if (BER < 0.0 || BER > 0.5)
00098     {
00099         std::stringstream ss;
00100 
00101         ss << "Invalid BER: " << BER << "! "
00102            << "BER has to be in interval [0.0; 0.5].";
00103 
00104         throw wns::Exception(ss.str());
00105     }
00106     else if (packetSize < 1)
00107     {
00108         std::stringstream ss;
00109 
00110         ss << "Invalid packet size: " << packetSize << "! "
00111            << "Packet size has to be in interval [1, oo).";
00112 
00113         throw wns::Exception(ss.str());
00114     }
00115 
00116     summedBER += BER * packetSize;
00117     summedPacketSize += packetSize;
00118     ++numberOfPackets;
00119 } // reportBER
00120 
00121 
00122 void
00123 BERMeasurementReporting::periodically()
00124 {
00125     hasSomethingToSend = false;
00126 
00127     if (numberOfPackets)
00128     {
00129         CompoundPtr compound = CompoundPtr(new Compound(getFUN()->getProxy()->createCommandPool()));
00130 
00131         MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName());
00132         m << " Generating BER measurement report for peer entity";
00133         MESSAGE_END();
00134 
00135         BERMeasurementReportingCommand* berCommand = activateCommand(compound->getCommandPool());
00136         berCommand->peer.BER = summedBER / summedPacketSize;
00137         berCommand->magic.packetSize = summedPacketSize / numberOfPackets;
00138 
00139         hasSomethingToSend = true;
00140         compoundToBeSent = compound;
00141         wakeup();
00142     }
00143 
00144     summedBER = 0.0;
00145     summedPacketSize = 0;
00146     numberOfPackets = 0;
00147 } // periodically
00148 
00149 
00150 void
00151 BERMeasurementReporting::doWakeup()
00152 {
00153     if (hasSomethingToSend && getConnector()->hasAcceptor(compoundToBeSent))
00154     {
00155         MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName());
00156         m << " Transmitting BER measurement report to peer entity";
00157         MESSAGE_END();
00158 
00159         getConnector()->getAcceptor(compoundToBeSent)->sendData(compoundToBeSent);
00160         hasSomethingToSend = false;
00161     }
00162 } // wakeup
00163 
00164 
00165 

Generated on Mon May 21 03:32:02 2012 for openWNS by  doxygen 1.5.5