xorp

damping.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 // vim:set sts=4 ts=8:
00003 
00004 // Copyright (c) 2001-2011 XORP, Inc and Others
00005 //
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License, Version 2, June
00008 // 1991 as published by the Free Software Foundation. Redistribution
00009 // and/or modification of this program under the terms of any other
00010 // version of the GNU General Public License is not permitted.
00011 // 
00012 // This program is distributed in the hope that it will be useful, but
00013 // WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00015 // see the GNU General Public License, Version 2, a copy of which can be
00016 // found in the XORP LICENSE.gpl file.
00017 // 
00018 // XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00019 // http://xorp.net
00020 
00021 
00022 #ifndef __BGP_DAMPING_HH__
00023 #define __BGP_DAMPING_HH__
00024 
00025 #include "libxorp/timer.hh"
00026 #include "libxorp/eventloop.hh"
00027 
00028 /* Route Flap Damping (RFC2439)
00029  *
00030  * The damping parameters plus general support code.
00031  */
00032 class Damping {
00033  public:
00034     static const uint32_t FIXED = 1000;
00035 
00036     Damping(EventLoop& eventloop);
00037 
00038     void set_damping(bool damping);
00039 
00040     bool get_damping() const;
00041 
00042     void set_half_life(uint32_t half_life);
00043 
00044     void set_max_hold_down(uint32_t max_hold_down);
00045 
00046     void set_reuse(uint32_t reuse);
00047 
00048     void set_cutoff(uint32_t cutoff);
00049 
00053     uint32_t get_tick() const {
00054     return _tick;
00055     }
00056 
00060     uint32_t get_merit() const {
00061     return FIXED;
00062     }
00063 
00067     uint32_t compute_merit(uint32_t last_time, uint32_t last_merit) const;
00068 
00072     bool cutoff(uint32_t merit) const {
00073     return merit > _cutoff;
00074     }
00075 
00079     bool reuse(uint32_t merit) const {
00080     return merit > _reuse;
00081     }
00082 
00087     uint32_t get_reuse_time(uint32_t merit) const;
00088     
00089  private:
00090     EventLoop& _eventloop;
00091     bool _damping;      // True if damping is enabled.
00092     uint32_t _half_life;    // Half life in minutes.
00093     uint32_t _max_hold_down;    // Maximum hold down time in minutes.
00094     uint32_t _reuse;        // Reuse threshold.
00095     uint32_t _cutoff;       // Cutoff threshold.
00096 
00097     vector<uint32_t> _decay;    // Per tick delay.
00098     uint32_t _tick;     // incremented every tick.
00099     XorpTimer _tick_tock;   // Timer to increment the tick.
00100 
00104     void init();
00105 
00109     void halt();
00110 
00111     /*
00112      * Called every clock tick.
00113      */
00114     bool tick();
00115 };
00116 
00117 #endif // __BGP_DAMPING_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations