[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Token Bucket Filter



Joerg,

Thanks for reminding us.  I patched tbf.cc and tbf.h as suggested.

  -Yuri

Joerg Diederich <[email protected]> writes:

> Hi,
> 
> the following bug report / patch to use more than one TBF
> simultaneously was send to this list some time ago. As I think, it is
> very useful (it is at least for me), I would like to know if it will
> be included into the main ns-tree.
> 
> Best regards,
> 
> /J"org Diederich
> ----
> J"org Diederich
> Institute of Operating Systems and Computer Networks, 
> Technical University Braunschweig, Germany
> e-mail: [email protected]
> 
> -------------
> From: [email protected] (Ludovic Kuty)
> Newsgroups: ibr.mailinglists.ns-users
> Subject: Patch to bug in TBF
> Date: 29 Apr 1999 11:12:32 +0200
>  
> The following bug has been fixed the following way:
>  
> BUG: static variable 'init' is defined in the function TBF::recv.
> In C++ there is only one copy of a member function for a given
> class (common to all objects), hence the variable is initialised
> once when the first TBF object calls the function for the first time.
> Subsequent calls to the function by any other TBF object will always
> get 'init' with a value of 0. So, any other TBF object won't get
> a full bucket the first time it receives a packet.
>  
> CONSEQUENCE: TBF objects excluding the first one will get an
> undefined value for the variable 'lastupdatetime_' causing a strange
> behaviour of the bucket. More precisely 'tokens_' will often have
> a big negative value causing the bucket to reject all the traffic.
>  
> PATCH: I don't know if the following patch is aesthetically good C++
> but it allowed to resolve our previous problems with TBF.
>  
> ### 'diff -c' for tbf.cc ###
>  
> *** tbf.cc      Tue Mar 16 05:20:17 1999
> --- ../../ns-2.1b5/tbf.cc       Thu Apr 29 10:02:16 1999
> ***************
> *** 29,35 ****
>   #include "queue.h"
>   #include "tbf.h"
>   
> ! TBF::TBF() :tokens_(0),tbf_timer_(this)
>   {
>         q_=new PacketQueue();
>         bind_bw("rate_",&rate_);
> --- 29,35 ----
>   #include "queue.h"
>   #include "tbf.h"
>   
> ! TBF::TBF() :tokens_(0),tbf_timer_(this),init(1)
>   {
>         q_=new PacketQueue();
>         bind_bw("rate_",&rate_);
> ***************
> *** 51,58 ****
>   
>   void TBF::recv(Packet *p, Handler *)
>   {
> -       static int init=1;
> - 
>         //start with a full bucket
>         if (init) {
>                 tokens_=bucket_;
> --- 51,56 ----
>  
> ### 'diff -c' for tbf.h ###
>  
> *** tbf.h       Tue Mar 16 05:20:17 1999
> --- ../../ns-2.1b5/tbf.h        Thu Apr 29 09:31:12 1999
> ***************
> *** 51,56 ****
> --- 51,57 ----
>         double lastupdatetime_;
>         PacketQueue *q_;
>         TBF_Timer tbf_timer_;
> +       int init;
>   };
>   
>   #endif
>  
>  
> Ludovic Kuty
> Lidia Yamamoto