xorp

route_table_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-2009 XORP, Inc.
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 // $XORP: xorp/bgp/route_table_damping.hh,v 1.8 2008/11/08 06:14:38 mjh Exp $
00022 
00023 #ifndef __BGP_ROUTE_TABLE_DAMPING_HH__
00024 #define __BGP_ROUTE_TABLE_DAMPING_HH__
00025 
00026 #include "libxorp/trie.hh"
00027 #include "route_table_base.hh"
00028 #include "damping.hh"
00029 #include "peer_handler.hh"
00030 
00038 class Damp {
00039  public:
00040     Damp(uint32_t time, uint32_t merit) : _time(time),
00041                       _merit(merit),
00042                       _damped(false)
00043     {}
00044 
00045     uint32_t _time; // Last time the route was announced or withdrawn.
00046     uint32_t _merit;    // Figure of merit.
00047     bool _damped;   // True if this route is currently damped.
00048 };
00049 
00053 template<class A>
00054 class DampRoute {
00055 public:
00056     DampRoute(const SubnetRoute<A>* route, uint32_t genid) 
00057     : _routeref(route), _genid(genid) {}
00058     const SubnetRoute<A>* route() const { return _routeref.route(); }
00059     uint32_t genid() const { return _genid; }
00060     XorpTimer& timer() { return _timer; }
00061 private:
00062     SubnetRouteConstRef<A> _routeref;
00063     uint32_t _genid;
00064     XorpTimer _timer;   // If this route is damped time when it should
00065             // be released. 
00066 };
00067 
00076 template<class A>
00077 class DampingTable : public BGPRouteTable<A>  {
00078 public:
00079     DampingTable(string tablename, Safi safi, BGPRouteTable<A>* parent,
00080          const PeerHandler *peer,
00081          Damping& damping);
00082     ~DampingTable();
00083     int add_route(InternalMessage<A> &rtmsg,
00084           BGPRouteTable<A> *caller);
00085     int replace_route(InternalMessage<A> &old_rtmsg,
00086               InternalMessage<A> &new_rtmsg,
00087               BGPRouteTable<A> *caller);
00088     int delete_route(InternalMessage<A> &rtmsg, 
00089              BGPRouteTable<A> *caller);
00090     int push(BGPRouteTable<A> *caller);
00091     int route_dump(InternalMessage<A> &rtmsg,
00092            BGPRouteTable<A> *caller,
00093            const PeerHandler *dump_peer);
00094 
00095     const SubnetRoute<A> *lookup_route(const IPNet<A> &net,
00096                        uint32_t& genid,
00097                        FPAListRef& pa_list) const;
00098     void route_used(const SubnetRoute<A>* route, bool in_use);
00099 
00100     RouteTableType type() const {return DAMPING_TABLE;}
00101 
00102 
00103     string str() const;
00104 
00105  private:
00106 
00107     bool damping() const {
00108     if (_peer->ibgp())
00109         return false;
00110 
00111     if (0 != _damp_count)
00112         return true;
00113 
00114     return _damping.get_damping();
00115     }
00116 
00117     bool damping_global() const { return _damping.get_damping(); }
00118 
00124     bool update_figure_of_merit(Damp&damp, const InternalMessage<A> &rtmsg);
00125 
00129     bool is_this_route_damped(const IPNet<A> &net) const;
00130 
00134     void undamp(IPNet<A> net);
00135 
00136     EventLoop& eventloop() const;
00137 
00138  private:
00139     const PeerHandler *_peer;
00140     Damping& _damping;
00141     
00142     Trie<A, Damp> _damp;
00143     RefTrie<A, DampRoute<A> > _damped;
00144     uint32_t _damp_count;   // Number of damped routes.
00145 };
00146 
00147 #endif // __BGP_ROUTE_TABLE_DAMPING_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations