User Manual, Developers Guide and API Documentation

GoBackN.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_GOBACKN_HPP
00029 #define WNS_LDK_ARQ_GOBACKN_HPP
00030 
00031 #include <WNS/pyconfig/View.hpp>
00032 
00033 #include <WNS/ldk/arq/ARQ.hpp>
00034 #include <WNS/ldk/CommandTypeSpecifier.hpp>
00035 #include <WNS/ldk/HasReceptor.hpp>
00036 #include <WNS/ldk/HasConnector.hpp>
00037 #include <WNS/ldk/HasDeliverer.hpp>
00038 #include <WNS/ldk/Delayed.hpp>
00039 #include <WNS/ldk/SuspendableInterface.hpp>
00040 #include <WNS/ldk/SuspendSupport.hpp>
00041 #include <WNS/ldk/DelayedDeliveryInterface.hpp>
00042 #include <WNS/ldk/fu/Plain.hpp>
00043 
00044 #include <WNS/Cloneable.hpp>
00045 #include <WNS/events/CanTimeout.hpp>
00046 #include <WNS/logger/Logger.hpp>
00047 #include <WNS/probe/bus/ContextCollector.hpp>
00048 
00049 #include <list>
00050 #include <cmath>
00051 
00052 namespace wns { namespace ldk { namespace arq {
00053 
00054     namespace tests {
00055         class GoBackNTest;
00056     }
00057 
00063     class GoBackNCommand :
00064         public ARQCommand
00065     {
00066     public:
00072         typedef enum {I, ACK, NAK} FrameType;
00073 
00074         GoBackNCommand()
00075         {
00076             peer.type = I;
00077             peer.NS = 0;
00078         }
00079 
00080         void
00081         setNS(const SequenceNumber& SN)
00082         {
00083             peer.NS = SN;
00084         }
00085 
00086         SequenceNumber
00087         getNS() const
00088         {
00089             return peer.NS;
00090         }
00091 
00092         FrameType
00093         getFrameType() const
00094         {
00095             return peer.type;
00096         }
00097 
00098         bool
00099         isACK() const
00100         {
00101             return (peer.type == ACK) || (peer.type == NAK);
00102         }
00103 
00104         struct {} local;
00105         struct {
00106             FrameType type;
00107             int NS;
00108         } peer;
00109         struct {
00110         } magic;
00111     };
00112 
00113 
00119     class GoBackN :
00120         public ARQ,
00121         public wns::ldk::fu::Plain<GoBackN, GoBackNCommand>,
00122         public Delayed<GoBackN>,
00123         virtual public SuspendableInterface,
00124         public SuspendSupport,
00125         virtual public DelayedDeliveryInterface,
00126         public events::CanTimeout
00127     {
00128         friend class ::wns::ldk::arq::tests::GoBackNTest;
00129         typedef std::list<CompoundPtr> CompoundContainer;
00130 
00131     public:
00132         // FUNConfigCreator interface realisation
00133         //GoBackN(FUN* fun, wns::pyconfig::View& config);
00134         GoBackN(fun::FUN* fuNet, const wns::pyconfig::View& config);
00135 
00136         virtual
00137         ~GoBackN();
00138 
00139         // CanTimeout interface realisation
00140         virtual void
00141         onTimeout();
00142 
00143         // Delayed interface realisation
00152         virtual bool
00153         hasCapacity() const;
00154 
00158         virtual void
00159         processOutgoing(const CompoundPtr& sdu);
00160 
00164         virtual void
00165         processIncoming(const CompoundPtr& compound);
00166 
00167         // ARQ interface realization
00171         virtual const wns::ldk::CompoundPtr
00172         hasACK() const;
00173 
00177         virtual const wns::ldk::CompoundPtr
00178         hasData() const;
00179 
00180         virtual wns::ldk::CompoundPtr
00181         getACK();
00182 
00187         virtual wns::ldk::CompoundPtr
00188         getData();
00189 
00190         // Overload of CommandTypeSpecifier Interface
00191         void
00192         calculateSizes(const CommandPool* commandPool, Bit& commandPoolSize, Bit& sduSize) const;
00193 
00194     protected:
00195         // Internal handlers for I- and ACK-Frames
00196         void
00197         onIFrame(const CompoundPtr& compound);
00198 
00199         void
00200         onACKFrame(const CompoundPtr& compound);
00201 
00202         void
00203         onNAKFrame(const CompoundPtr& compound);
00204 
00205         // remove ACKed PDU from list
00206         void
00207         removeACKed(const ARQCommand::SequenceNumber ackedNS, CompoundContainer& container);
00208 
00209         // prepare list of frames to retransmit
00210         void
00211         prepareRetransmission();
00212 
00213         // retransmissionState
00217         bool
00218         retransmissionState() const;
00219 
00223         void
00224         show_seqnr_list(const char* name, CompoundContainer& compoundList) const;
00225 
00226         virtual bool
00227         onSuspend() const;
00228 
00229         virtual void
00230         doDelayDelivery();
00231 
00232         virtual void
00233         doDeliver();
00234 
00238         int windowSize;
00239 
00243         int sequenceNumberSize;
00244 
00248         int bitsPerIFrame; // = (int) ceil(log(sequenceNumberSize) / log(2));
00249 
00253         int bitsPerACKFrame; // = (int) ceil(log(sequenceNumberSize) / log(2));
00254 
00258         ARQCommand::SequenceNumber NS;
00259 
00263         ARQCommand::SequenceNumber NR;
00264 
00268         ARQCommand::SequenceNumber LA; // LA=1 means seqnr=0 was acked before
00269 
00273         CompoundPtr activeCompound;
00274 
00278         CompoundContainer sentPDUs;
00279 
00283         CompoundContainer toRetransmit;
00284 
00288         CompoundContainer ackPDUs;
00289 
00293         CompoundContainer receivedPDUs;
00294 
00298         bool sendNow;
00299 
00303         double resendTimeout;
00304 
00310         wns::probe::bus::ContextCollectorPtr transmissionAttempts;
00311 
00312         bool delayingDelivery;
00313 
00314         ARQCommand::SequenceNumber delayedDeliveryNR;
00315 
00316         logger::Logger logger;
00317 
00318     };
00319 
00320 }}}
00321 
00322 #endif // NOT defined WNS_LDK_ARQ_GOBACKN_HPP
00323 
00324 

Generated on Thu May 24 03:31:36 2012 for openWNS by  doxygen 1.5.5