xorp

plumbing.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 // $XORP: xorp/bgp/plumbing.hh,v 1.46 2008/11/08 06:14:37 mjh Exp $
00022 
00023 #ifndef __BGP_PLUMBING_HH__
00024 #define __BGP_PLUMBING_HH__
00025 
00026 
00027 #include "route_table_ribin.hh"
00028 #include "route_table_damping.hh"
00029 #include "route_table_deletion.hh"
00030 #include "route_table_ribout.hh"
00031 #include "route_table_decision.hh"
00032 #include "route_table_aggregation.hh"
00033 #include "route_table_fanout.hh"
00034 #include "route_table_dump.hh"
00035 #include "route_table_filter.hh"
00036 #include "route_table_cache.hh"
00037 #include "route_table_nhlookup.hh"
00038 #include "route_table_policy.hh"
00039 #include "route_table_policy_sm.hh"
00040 #include "route_table_policy_im.hh"
00041 #include "route_table_policy_ex.hh"
00042 #include "peer.hh"
00043 #include "rib_ipc_handler.hh"
00044 #include "next_hop_resolver.hh"
00045 #include "parameter.hh"
00046 #include "policy/backend/policy_filters.hh"
00047 #include "path_attribute.hh"
00048 
00049 class BGPPlumbing;
00050 
00051 template <class A>
00052 class RouteTableReader;
00053 
00054 template <class A>
00055 class BGPPlumbingAF {
00056 public:
00057     BGPPlumbingAF(const string& ribname, BGPPlumbing& master,
00058           NextHopResolver<A>& next_hop_resolver);
00059     ~BGPPlumbingAF();
00060     int add_peering(PeerHandler* peer_handler);
00061     int stop_peering(PeerHandler* peer_handler);
00062     int peering_went_down(PeerHandler* peer_handler);
00063     int peering_came_up(PeerHandler* peer_handler);
00064     int delete_peering(PeerHandler* peer_handler);
00065 
00066     void flush(PeerHandler* peer_handler);
00067     int add_route(const IPNet<A>& net, 
00068           FPAListRef& pa_list,
00069           const PolicyTags& policytags,
00070           PeerHandler* peer_handler);
00071     int delete_route(InternalMessage<A> &rtmsg, 
00072              PeerHandler* peer_handler);
00073     int delete_route(const IPNet<A> &net, 
00074              PeerHandler* peer_handler);
00075     const SubnetRoute<A>* 
00076       lookup_route(const IPNet<A> &net) const;
00077     void push(PeerHandler* peer_handler);
00078     void output_no_longer_busy(PeerHandler* peer_handler);
00079 
00083     uint32_t get_prefix_count(PeerHandler* peer_handler) const;
00084 
00089     NextHopResolver<A>& next_hop_resolver() {return _next_hop_resolver;}
00090     uint32_t create_route_table_reader(const IPNet<A>& prefix);
00091     bool read_next_route(uint32_t token, 
00092              const SubnetRoute<A>*& route, 
00093              IPv4& peer_id);
00094 
00095 
00104     bool status(string& reason) const;
00105 
00109     void push_routes();
00110 
00111 private:
00115     void dump_entire_table(FilterTable<A> *filter_out, string ribname);
00116 
00117     void configure_inbound_filter(PeerHandler* peer_handler,
00118                   FilterTable<A>* filter_in);
00119     void configure_outbound_filter(PeerHandler* peer_handler,
00120                    FilterTable<A>* filter_out);
00121     void reconfigure_filters(PeerHandler* peer_handler);
00122 
00123     const A& get_local_nexthop(const PeerHandler *peer_handler) const;
00124 
00129     bool directly_connected(const PeerHandler *peer_handler,
00130                 IPNet<A>& subnet, A& peer) const;
00131 
00132     list <RibInTable<A>*> ribin_list() const;
00133 
00134     map <PeerHandler*, RibInTable<A>* > _in_map;
00135     map <RibOutTable<A>*,  PeerHandler*> _reverse_out_map;
00136     map <PeerHandler*, RibOutTable<A>*> _out_map;
00137     DecisionTable<A> *_decision_table;
00138     PolicyTableSourceMatch<A>* _policy_sourcematch_table;
00139     AggregationTable<A> *_aggregation_table;
00140     FanoutTable<A> *_fanout_table;
00141     RibInTable<A> *_ipc_rib_in_table;
00142     RibOutTable<A> *_ipc_rib_out_table;
00143     /* _tables is all the tables not covered above*/
00144     set <BGPRouteTable<A>*> _tables;
00145 
00146     uint32_t _max_reader_token;
00147     map <uint32_t, RouteTableReader<A>*> _route_table_readers;
00148 
00149     bool _awaits_push;
00150     string _ribname;
00151     BGPPlumbing& _master;
00152 
00153     NextHopResolver<A>& _next_hop_resolver;
00154 };
00155 
00156 
00157 /*
00158  * BGP plumbing is the class that sets up all the BGP route tables,
00159  * from RIB-In to RIB-Out, plus everything in between.
00160  */
00161 
00162 class RibIpcHandler;
00163 
00164 class BGPPlumbing {
00165 public:
00166     BGPPlumbing(const Safi safi,
00167         RibIpcHandler* rib_handler,
00168         AggregationHandler* aggr_handler,
00169         NextHopResolver<IPv4>&,
00170 #ifdef HAVE_IPV6
00171         NextHopResolver<IPv6>&,
00172 #endif
00173         PolicyFilters&,
00174         BGPMain& bgp);
00175 
00176     int add_peering(PeerHandler* peer_handler);
00177     int stop_peering(PeerHandler* peer_handler);
00178     int peering_went_down(PeerHandler* peer_handler);
00179     int peering_came_up(PeerHandler* peer_handler);
00180     int delete_peering(PeerHandler* peer_handler);
00181 
00182     void flush(PeerHandler* peer_handler);
00183     int add_route(const IPv4Net& net, 
00184           FPAList4Ref& pa_list,
00185           const PolicyTags& policytags,
00186           PeerHandler* peer_handler);
00187     int delete_route(InternalMessage<IPv4> &rtmsg, 
00188              PeerHandler* peer_handler);
00189     int delete_route(const IPNet<IPv4> &net, 
00190              PeerHandler* peer_handler);
00191     template<class A> void push(PeerHandler* peer_handler);
00192     void output_no_longer_busy(PeerHandler* peer_handler);
00193     const SubnetRoute<IPv4>* 
00194       lookup_route(const IPNet<IPv4> &net) const;
00195 
00199     uint32_t get_prefix_count(const PeerHandler* peer_handler);
00200 
00201     RibIpcHandler *rib_handler() const {return _rib_handler;}
00202     AggregationHandler *aggr_handler() const {return _aggr_handler;}
00203     BGPPlumbingAF<IPv4>& plumbing_ipv4() {
00204     return _plumbing_ipv4;
00205     }
00206 
00207     template <typename A> uint32_t
00208     create_route_table_reader(const IPNet<A>& prefix);
00209 
00210     bool read_next_route(uint32_t token, 
00211              const SubnetRoute<IPv4>*& route, 
00212              IPv4& peer_id);
00213 
00222     bool status(string& reason) const;
00223 
00227     Safi safi() const {return _safi;}
00228 
00232     BGPMain& main() const { return _bgp; }
00233     
00237     void push_routes();
00238 
00239     PolicyFilters& policy_filters() { return _policy_filters; }
00240 
00242 #ifdef HAVE_IPV6
00243     int add_route(const IPv6Net& net, 
00244           FPAList6Ref& pa_list,
00245           const PolicyTags& policytags,
00246           PeerHandler* peer_handler);
00247 
00248     int delete_route(InternalMessage<IPv6> &rtmsg, 
00249              PeerHandler* peer_handler);
00250     int delete_route(const IPNet<IPv6> &net,
00251              PeerHandler* peer_handler);
00252     const SubnetRoute<IPv6>* 
00253       lookup_route(const IPNet<IPv6> &net) const;
00254     BGPPlumbingAF<IPv6>& plumbing_ipv6() {
00255     return _plumbing_ipv6;
00256     }
00257     bool read_next_route(uint32_t token, 
00258              const SubnetRoute<IPv6>*& route, 
00259              IPv4& peer_id);
00260 #endif // ipv6
00261 
00262 private:
00263     BGPMain &_bgp;
00264 
00265     RibIpcHandler *_rib_handler;
00266     AggregationHandler *_aggr_handler;
00267 
00268     NextHopResolver<IPv4>& _next_hop_resolver_ipv4;
00269     const Safi _safi;
00270 
00271     PolicyFilters& _policy_filters;
00272 
00273     BGPPlumbingAF<IPv4> _plumbing_ipv4;
00274 
00275 #ifdef HAVE_IPV6
00276     NextHopResolver<IPv6>& _next_hop_resolver_ipv6;
00277     BGPPlumbingAF<IPv6> _plumbing_ipv6;
00278 #endif
00279 
00280 };
00281 
00282 #endif // __BGP_PLUMBING_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations