![]() |
User Manual, Developers Guide and API Documentation |
![]() |
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/sar/Soft.hpp> 00029 #include <WNS/ldk/Layer.hpp> 00030 #include <WNS/ldk/fun/FUN.hpp> 00031 #include <WNS/Ttos.hpp> 00032 00033 using namespace wns::ldk; 00034 using namespace wns::ldk::sar; 00035 00036 STATIC_FACTORY_REGISTER_WITH_CREATOR(Soft, FunctionalUnit, "wns.sar.Soft", FUNConfigCreator); 00037 00038 SoftCommand::SoftCommand() 00039 : SARCommand() 00040 { 00041 PER = 0.0; 00042 } // SoftCommand 00043 00044 double 00045 SoftCommand::getErrorRate() const 00046 { 00047 return PER; 00048 } 00049 00050 void 00051 SoftCommand::setPER(const double _PER) 00052 { 00053 PER = _PER; 00054 } 00055 00056 Soft::Soft(fun::FUN* fuNet, const wns::pyconfig::View& config) : 00057 SAR<SoftCommand>(fuNet, config), 00058 HasReceptor<>(), 00059 HasConnector<>(), 00060 HasDeliverer<>(), 00061 Delayed<Soft>(), 00062 Cloneable<Soft>(), 00063 00064 incoming(), 00065 fragmentNumber(0), 00066 PERProviderName(config.get<std::string>("PERProvider")), 00067 useProbe(config.get<bool>("useProbe")), 00068 probeName(config.get<std::string>("probeName")), 00069 perProbeBus( new wns::probe::bus::ContextCollector(wns::probe::bus::ContextProviderCollection(&getFUN()->getLayer()->getContextProviderCollection()), 00070 probeName)) 00071 { 00072 friends.PERProvider = NULL; 00073 } // Soft 00074 00075 Soft::~Soft() 00076 {} 00077 00078 void 00079 Soft::onFUNCreated() 00080 { 00081 friends.PERProvider = getFUN()->findFriend<FunctionalUnit*>(PERProviderName); 00082 assure(friends.PERProvider, "SoftSAR requires a PERProvider friend with name '" + PERProviderName + "'"); 00083 00084 } 00085 00086 void 00087 Soft::processIncoming(const CompoundPtr& compound) 00088 { 00089 SoftCommand* command = getCommand(compound->getCommandPool()); 00090 00091 ErrorRateProviderInterface* ppi = dynamic_cast<ErrorRateProviderInterface*>( 00092 friends.PERProvider->getCommand(compound->getCommandPool())); 00093 00094 assure(ppi, "Expected a ErrorRateProviderInterface instance."); 00095 00096 PERStorageEntry received; 00097 received.first = compound; 00098 received.second = ppi->getErrorRate(); 00099 00100 incoming.push_back(received); 00101 00102 MESSAGE_BEGIN(NORMAL, logger, m, ""); 00103 m << "received fragment " 00104 << " pos " 00105 << command->magic.pos 00106 << " with PER: " 00107 << received.second 00108 << " lastFragment " 00109 << ( command->peer.lastFragment ? "yes" : "no" ) 00110 ; 00111 MESSAGE_END(); 00112 00113 assure(command->magic.fragmentNumber == fragmentNumber, 00114 "Missing fragment number: " + wns::Ttos(fragmentNumber) + 00115 ", received fragment number: " + wns::Ttos(command->magic.fragmentNumber)); 00116 00117 if(!command->peer.lastFragment) 00118 { 00119 ++fragmentNumber; 00120 return; 00121 } 00122 00123 MESSAGE_BEGIN(NORMAL, logger, m, ""); 00124 m << " -> compound complete, starting reassembly"; 00125 MESSAGE_END(); 00126 00127 CommandPool* reassembledPCI = getFUN()->createCommandPool(); 00128 getFUN()->getProxy()->partialCopy(this, reassembledPCI, compound->getCommandPool()); 00129 CompoundPtr reassembled(new Compound(reassembledPCI, compound->getData())); 00130 00131 double packetGood = 1.0; 00132 int counter = 0; 00133 00134 for ( PERStorageContainer::iterator it = incoming.begin() ; 00135 it != incoming.end() ; 00136 it++ ) 00137 { 00138 MESSAGE_BEGIN(NORMAL, logger, m, ""); 00139 m << "fragment " << counter 00140 << " PER = " << (*it).second; 00141 MESSAGE_END(); 00142 00143 packetGood *= (1 - (*it).second); 00144 counter++; 00145 } 00146 double resultingPER = 1 - packetGood; 00147 00148 MESSAGE_BEGIN(NORMAL, logger, m, ""); 00149 m << "Resulting overall PER = " << resultingPER ; 00150 MESSAGE_END(); 00151 00152 perProbeBus->put(resultingPER); 00153 00154 SoftCommand* myCommand = activateCommand(reassembledPCI); 00155 myCommand->setPER( resultingPER ); 00156 00157 incoming.clear(); 00158 fragmentNumber = 0; 00159 00160 getDeliverer()->getAcceptor(reassembled)->onData(reassembled); 00161 00162 } // processIncoming 00163 00164
1.5.5