![]() |
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 #ifndef WNS_LDK_ARQ_HPP 00029 #define WNS_LDK_ARQ_HPP 00030 00031 #include <WNS/ldk/arq/statuscollector/Interface.hpp> 00032 00033 #include <WNS/ldk/FunctionalUnit.hpp> 00034 #include <WNS/ldk/Command.hpp> 00035 #include <WNS/ldk/FUNConfigCreator.hpp> 00036 #include <WNS/ldk/Delayed.hpp> 00037 00038 #include <WNS/Birthmark.hpp> 00039 #include <WNS/Cloneable.hpp> 00040 #include <WNS/pyconfig/View.hpp> 00041 #include <WNS/StaticFactory.hpp> 00042 00043 namespace wns { namespace ldk { namespace arq { 00044 00051 class ARQCommand : 00052 public Command 00053 { 00054 public: 00055 ARQCommand() : 00056 localTransmissionCounter(0) 00057 { 00058 } 00059 00066 typedef long long int SequenceNumber; 00067 00068 virtual bool 00069 isACK() const = 0; 00070 00071 size_t localTransmissionCounter; 00072 }; 00073 00100 class ARQ : 00101 virtual public FunctionalUnit, 00102 virtual public DelayedInterface 00103 { 00104 public: 00105 ARQ(const wns::pyconfig::View& config) : 00106 isPreferingACK(true) 00107 { 00108 pyconfig::View statusCollectorConfig(config, "arqStatusCollector"); 00109 std::string statusCollectorName = statusCollectorConfig.get<std::string>("__plugin__"); 00110 this->statusCollector = statuscollector::StatusCollectorFactory::creator(statusCollectorName)->create(statusCollectorConfig); 00111 } 00112 00113 virtual 00114 ~ARQ() 00115 { 00116 delete this->statusCollector; 00117 } 00118 00123 void 00124 preferACK(bool _isPreferingACK) 00125 { 00126 isPreferingACK = _isPreferingACK; 00127 } 00128 00133 bool 00134 preferACK() const 00135 { 00136 return isPreferingACK; 00137 } 00138 00139 // 00140 // partial Delayed interface implementation 00141 // 00142 00143 virtual const CompoundPtr 00144 hasSomethingToSend() const 00145 { 00146 CompoundPtr it; 00147 if(preferACK()) 00148 { 00149 it = hasACK(); 00150 if(!it) 00151 { 00152 it = hasData(); 00153 } 00154 } 00155 else 00156 { 00157 it = hasData(); 00158 if(!it) 00159 { 00160 it = hasACK(); 00161 } 00162 } 00163 return it; 00164 } // hasSomethingToSend() 00165 00166 virtual CompoundPtr 00167 getSomethingToSend() 00168 { 00169 assure( 00170 hasSomethingToSend(), 00171 "hasSomethingToSend has not been called to check wheter there is something to send."); 00172 00173 if(preferACK()) 00174 { 00175 if(hasACK()) 00176 { 00177 return getACK(); 00178 } 00179 return getData(); 00180 } 00181 else 00182 { 00183 if(hasData()) 00184 { 00185 return getData(); 00186 } 00187 return getACK(); 00188 } 00189 } // getSomethingToSend 00190 00195 double 00196 getSuccessRate(const CompoundPtr& compound) 00197 { 00198 return(this->statusCollector->getSuccessRate(compound)); 00199 } 00200 00204 void 00205 resetStatusCollector() 00206 { 00207 this->statusCollector->reset(); 00208 } 00209 00210 protected: 00218 virtual const CompoundPtr 00219 hasACK() const = 0; 00220 00228 virtual const CompoundPtr 00229 hasData() const = 0; 00230 00238 virtual CompoundPtr 00239 getACK() = 0; 00240 00248 virtual CompoundPtr 00249 getData() = 0; 00250 00251 statuscollector::Interface* statusCollector; 00252 00253 // /** 00254 // * @brief Returns the distance between two sequence numbres 00255 // * 00256 // * @intern This method enables different implementations of 00257 // * sequence numbers. For the implementation we're currently 00258 // * using (long long int) the method is very easy. For real sequence 00259 // * numbers, that warp around, it's a little bit harder (see 00260 // * commented code below). 00261 // */ 00262 // static int 00263 // distance( 00264 // const ARQCommand::SequenceNumber& a, 00265 // const ARQCommand::SequenceNumber& b) 00266 // { 00267 // assure(a>=0, "Negative Sequence Number"); 00268 // assure(b>=0, "Negative Sequence Number"); 00269 00270 // return a - b; 00271 00272 // // assure(windowSize>=2, "Bad windowSize"); 00273 // // assure(sequenceNumberSize>= 2*windowSize, "Too small modDivisor"); 00274 // // return (a - b + sequenceNumberSize) % sequenceNumberSize; 00275 // } 00276 00277 private: 00278 bool isPreferingACK; 00279 }; 00280 00281 typedef FUNConfigCreator<ARQ> ARQCreator; 00282 typedef wns::StaticFactory<ARQCreator> ARQFactory; 00283 00284 00285 }}} 00286 00287 #endif // NOT defined WNS_LDK_ARQ_HPP 00288 00289 00290
1.5.5