User Manual, Developers Guide and API Documentation

SelectiveRepeat.hpp

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 #ifndef WNS_LDK_ARQ_SELECTIVEREPEAT_HPP
00029 #define WNS_LDK_ARQ_SELECTIVEREPEAT_HPP
00030 
00031 #include <WNS/pyconfig/View.hpp>
00032 
00033 #include <WNS/ldk/arq/ARQ.hpp>
00034 #include <WNS/ldk/Delayed.hpp>
00035 #include <WNS/ldk/SuspendableInterface.hpp>
00036 #include <WNS/ldk/SuspendSupport.hpp>
00037 #include <WNS/ldk/DelayedDeliveryInterface.hpp>
00038 #include <WNS/ldk/fu/Plain.hpp>
00039 
00040 #include <WNS/logger/Logger.hpp>
00041 #include <WNS/probe/bus/ContextCollector.hpp>
00042 #include <WNS/events/CanTimeout.hpp>
00043 
00044 #include <list>
00045 #include <cmath>
00046 
00047 namespace wns { namespace ldk { namespace arq {
00048 
00049     namespace tests {
00050         class SelectiveRepeatTest;
00051     }
00052 
00057     class SelectiveRepeatCommand :
00058         public ARQCommand
00059     {
00060     public:
00061         /*
00062          * I - Information Frame
00063          * ACK - received Packet (ACK)
00064          */
00065         typedef enum {I, ACK} FrameType;
00066 
00067         SelectiveRepeatCommand()
00068         {
00069             peer.type = I;
00070             peer.ns = 0;
00071             local.lastSentTime = 0.0;
00072             local.firstSentTime = 0.0;
00073             magic.ackSentTime = 0.0;
00074         }
00075 
00076         void setNS(SequenceNumber sn)
00077         {
00078             peer.ns = sn;
00079         }
00080 
00081         SequenceNumber getNS() const
00082         {
00083             return peer.ns;
00084         }
00085 
00086         bool isACK() const
00087         {
00088             return peer.type == ACK;
00089         }
00090 
00091         struct {
00092             simTimeType lastSentTime;
00093             simTimeType firstSentTime;
00094         } local;
00095         struct {
00096             FrameType type;
00097             SequenceNumber ns;
00098         } peer;
00099         struct {
00100             simTimeType ackSentTime;
00101         } magic;
00102     };
00103 
00104 
00129     class SelectiveRepeat :
00130         public ARQ,
00131         public wns::ldk::fu::Plain<SelectiveRepeat, SelectiveRepeatCommand>,
00132         public Delayed<SelectiveRepeat>,
00133         virtual public SuspendableInterface,
00134         public SuspendSupport,
00135         virtual public DelayedDeliveryInterface,
00136         public events::CanTimeout
00137     {
00138         friend class tests::SelectiveRepeatTest;
00139         typedef std::list<CompoundPtr> CompoundContainer;
00140 
00141     public:
00142         // FUNConfigCreator interface realisation
00143         SelectiveRepeat(fun::FUN* fuNet, const wns::pyconfig::View& config);
00144         ~SelectiveRepeat();
00145 
00146         // CanTimeout interface realisation
00147         virtual void onTimeout();
00148 
00149         // Delayed interface realisation
00150         virtual bool hasCapacity() const;
00151         virtual void processOutgoing(const CompoundPtr& sdu);
00152         // virtual const CompoundPtr hasSomethingToSend() const; // implemented by ARQ
00153         // virtual CompoundPtr getSomethingToSend(); // implemented by ARQ
00154         virtual void processIncoming(const CompoundPtr& compound);
00155 
00156         // ARQ interface realization
00157         virtual const wns::ldk::CompoundPtr hasACK() const;
00158         virtual const wns::ldk::CompoundPtr hasData() const;
00159         virtual wns::ldk::CompoundPtr getACK();
00160         virtual wns::ldk::CompoundPtr getData();
00161 
00162         // Overload of CommandTypeSpecifier Interface
00163         void calculateSizes(const CommandPool* commandPool, Bit& commandPoolSize, Bit& sduSize) const;
00164 
00165     protected:
00166         // Internal handlers for I- and ACK-Frames
00167         void onIFrame(const CompoundPtr& compound);
00168         void onACKFrame(const CompoundPtr& compound);
00169 
00170         // sort into given Compound List
00171         void keepSorted(const CompoundPtr& compound, CompoundContainer& conatiner);
00172 
00173         // remove ACKed PDU from list
00174         void removeACKed(const CompoundPtr& ackCompound, CompoundContainer& container);
00175 
00176         // prepare list of frames to retransmit
00177         void prepareRetransmission();
00178 
00179         // retransmissionState
00180         bool retransmissionState() const;
00181 
00182         virtual bool onSuspend() const;
00183 
00184         virtual void doDelayDelivery();
00185         virtual void doDeliver();
00186 
00190         int windowSize;
00191 
00195         int sequenceNumberSize;
00196 
00200         int commandSize;
00201 
00205         ARQCommand::SequenceNumber NS;
00206 
00210         ARQCommand::SequenceNumber NR;
00211 
00215         ARQCommand::SequenceNumber LA;
00216 
00220         CompoundPtr activeCompound;
00221 
00225         CompoundContainer sentPDUs;
00226 
00230         CompoundContainer toRetransmit;
00231 
00235         CompoundContainer ackPDUs;
00236 
00240         CompoundContainer receivedPDUs;
00241 
00245         CompoundContainer receivedACKs;
00246 
00250         bool sendNow;
00251 
00256         double resendTimeout;
00257 
00262         double retransmissionInterval;
00263 
00269         wns::probe::bus::ContextCollectorPtr transmissionAttemptsProbeBus;
00270         wns::probe::bus::ContextCollectorPtr ackDelayProbeBus;
00271         wns::probe::bus::ContextCollectorPtr roundTripTimeProbeBus;
00272 
00273         bool delayingDelivery;
00274 
00275         logger::Logger logger;
00276 
00277     };
00278 
00279 }}}
00280 
00281 #endif // NOT defined WNS_LDK_ARQ_SELECTIVEREPEAT_HPP
00282 
00283 

Generated on Fri May 25 03:31:40 2012 for openWNS by  doxygen 1.5.5