xorp

route_table_aggregation.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2001-2009 XORP, Inc.
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, Version 2, June
00007 // 1991 as published by the Free Software Foundation. Redistribution
00008 // and/or modification of this program under the terms of any other
00009 // version of the GNU General Public License is not permitted.
00010 // 
00011 // This program is distributed in the hope that it will be useful, but
00012 // WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00014 // see the GNU General Public License, Version 2, a copy of which can be
00015 // found in the XORP LICENSE.gpl file.
00016 // 
00017 // XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00018 // http://xorp.net
00019 
00020 // $XORP: xorp/bgp/route_table_aggregation.hh,v 1.19 2008/11/08 06:14:38 mjh Exp $
00021 
00022 #ifndef __BGP_ROUTE_TABLE_AGGREGATION_HH__
00023 #define __BGP_ROUTE_TABLE_AGGREGATION_HH__
00024 
00025 #include "peer_handler.hh"
00026 #include "route_table_base.hh"
00027 #include "libxorp/ref_trie.hh"
00028 
00029 
00081 class XrlStdRouter;
00082 
00083 template<class A>
00084 class DumpIterator;
00085 
00086 template<class A>
00087 class AggregationTable;
00088 
00089 template<class A>
00090 class ComponentRoute {
00091 public:
00092     ComponentRoute(const SubnetRoute<A>* route,
00093            const PeerHandler *origin,
00094            uint32_t genid,
00095            bool from_previous_peering) : _routeref(route) {
00096     _origin_peer = origin;
00097     _genid = genid;
00098     _from_previous_peering = from_previous_peering;
00099     }
00100     const SubnetRoute<A>* route() const { return _routeref.route(); }
00101     const PeerHandler* origin_peer() const { return _origin_peer; }
00102     uint32_t genid() const { return _genid; }
00103     bool from_previous_peering() const { return _from_previous_peering; }
00104 private:
00105     SubnetRouteConstRef<A> _routeref;
00106     const PeerHandler *_origin_peer;
00107     uint32_t _genid;
00108     bool _from_previous_peering;
00109 };
00110 
00111 
00112 template<class A>
00113 class AggregateRoute {
00114 public:
00115     AggregateRoute(IPNet<A> net,
00116            bool brief_mode,
00117            IPv4 bgp_id,
00118            AsNum asnum)
00119         : _net(net), _brief_mode(brief_mode),
00120       _was_announced(0), _is_suppressed(0) 
00121     {
00122     OriginAttribute origin_att(IGP);
00123     FPAListRef fpa_list = new FastPathAttributeList<A>(A::ZERO(), 
00124                                ASPath(), 
00125                                origin_att);
00126     _pa_list = new PathAttributeList<A>(fpa_list);
00127     
00128     _aggregator_attribute = new AggregatorAttribute(bgp_id, asnum);
00129     }
00130 
00131     ~AggregateRoute() 
00132     {
00133     if (_components_table.begin() != _components_table.end())
00134         XLOG_WARNING("ComponentsTable trie was not empty on deletion\n");
00135     delete _aggregator_attribute;
00136     }
00137     PAListRef<A> pa_list() const        { return _pa_list; }
00138     const IPNet<A> net() const      { return _net; }
00139     bool was_announced() const      { return _was_announced; }
00140     bool is_suppressed() const      { return _is_suppressed; }
00141     bool brief_mode() const     { return _brief_mode; }
00142     void was_announced(bool value)  { _was_announced = value; }
00143     void is_suppressed(bool value)  { _is_suppressed = value; }
00144     void brief_mode(bool value)     { _brief_mode = value; }
00145     void reevaluate(AggregationTable<A> *parent);
00146     RefTrie<A, const ComponentRoute<A> > *components_table() {
00147     return &_components_table;
00148     }
00149 
00150 private:
00151     const IPNet<A> _net;
00152     bool _brief_mode;
00153     AggregatorAttribute *_aggregator_attribute;
00154 
00155     RefTrie<A, const ComponentRoute<A> > _components_table;
00156     PAListRef<A> _pa_list;
00157     bool _was_announced;
00158     bool _is_suppressed;
00159 };
00160 
00161 
00162 template<class A>
00163 class AggregationTable : public BGPRouteTable<A>  {
00164 public:
00165     AggregationTable(string tablename,
00166              BGPPlumbing& master,
00167              BGPRouteTable<A> *parent);
00168     ~AggregationTable();
00169     int add_route(InternalMessage<A> &rtmsg,
00170                   BGPRouteTable<A> *caller);
00171     int replace_route(InternalMessage<A> &old_rtmsg,
00172                       InternalMessage<A> &new_rtmsg,
00173                       BGPRouteTable<A> *caller);
00174     int delete_route(InternalMessage<A> &rtmsg,
00175                      BGPRouteTable<A> *caller);
00176     int push(BGPRouteTable<A> *caller);
00177 
00178     bool dump_next_route(DumpIterator<A>& dump_iter);
00179     int route_dump(InternalMessage<A> &rtmsg,
00180            BGPRouteTable<A> *caller,
00181            const PeerHandler *dump_peer);
00182 
00183     const SubnetRoute<A> *lookup_route(const IPNet<A> &net,
00184                                        uint32_t& genid,
00185                        FPAListRef& pa_list) const;
00186     void route_used(const SubnetRoute<A>* route, bool in_use);
00187 
00188     RouteTableType type() const {return AGGREGATION_TABLE;}
00189     string str() const;
00190 
00191     /* mechanisms to implement flow control in the output plumbing */
00192     bool get_next_message(BGPRouteTable<A> *next_table);
00193 
00194     int route_count() const {
00195         return _aggregates_table.route_count(); // XXX is this OK?
00196     }
00197 
00198     void peering_went_down(const PeerHandler *peer, uint32_t genid,
00199                            BGPRouteTable<A> *caller);
00200     void peering_down_complete(const PeerHandler *peer, uint32_t genid,
00201                                BGPRouteTable<A> *caller);
00202     void peering_came_up(const PeerHandler *peer, uint32_t genid,
00203                          BGPRouteTable<A> *caller);
00204 
00205 private:
00206     friend class AggregateRoute<A>;
00207 
00208     RefTrie<A, const AggregateRoute<A> > _aggregates_table;
00209     BGPPlumbing& _master_plumbing;
00210 };
00211 
00212 
00213 class AggregationHandler : public PeerHandler {
00214 public:
00215     AggregationHandler();
00216 
00217     virtual PeerType get_peer_type() const {
00218     return PEER_TYPE_INTERNAL;
00219     }
00220 
00221     uint32_t get_unique_id() const  { return _fake_unique_id; }
00222     virtual bool originate_route_handler() const { return true; }
00223     const uint32_t _fake_unique_id;
00224 };
00225 
00226 
00227 #endif // __BGP_ROUTE_TABLE_AGGREGATION_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations