xorp

route_table_decision.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2001-2011 XORP, Inc and Others
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_decision.hh,v 1.29 2008/11/08 06:14:38 mjh Exp $
00021 
00022 #ifndef __BGP_ROUTE_TABLE_DECISION_HH__
00023 #define __BGP_ROUTE_TABLE_DECISION_HH__
00024 
00025 
00026 #include "route_table_base.hh"
00027 #include "dump_iterators.hh"
00028 #include "peer_handler.hh"
00029 #include "next_hop_resolver.hh"
00030 #include "peer_route_pair.hh"
00031 
00037 template<class A>
00038 class RouteData {
00039 public:
00040     RouteData(const SubnetRoute<A>* route, 
00041           FPAListRef pa_list,
00042           BGPRouteTable<A>* parent_table,
00043           const PeerHandler* peer_handler,
00044           uint32_t genid) 
00045     : _route(route), _pa_list(pa_list), _parent_table(parent_table), 
00046       _peer_handler(peer_handler), _genid(genid) {}
00047 
00048     /* main reason for defining operator= is to keep the refcount
00049        correct on _pa_list */
00050     RouteData<A>& operator=(const RouteData<A>& him) {
00051     _route = him._route;
00052     _pa_list = him._pa_list;
00053     _parent_table = him._parent_table;
00054     _peer_handler = him.peer_handler;
00055     _genid = him._genid;
00056     }
00057 
00058     void set_is_not_winner() {
00059     _parent_table->route_used(_route, false);
00060     _route->set_is_not_winner();
00061     }
00062     void set_is_winner(int igp_distance) {
00063     _parent_table->route_used(_route, true);
00064     _route->set_is_winner(igp_distance);
00065     }
00066     const SubnetRoute<A>* route() const { return _route; }
00067     const FPAListRef& attributes() const { return _pa_list; }
00068     const PeerHandler* peer_handler() const { return _peer_handler; }
00069     BGPRouteTable<A>* parent_table() const { return _parent_table; }
00070     uint32_t genid() const { return _genid; }
00071 private:
00072     const SubnetRoute<A>* _route;
00073     FPAListRef _pa_list;
00074     BGPRouteTable<A>* _parent_table;
00075     const PeerHandler* _peer_handler;
00076     uint32_t _genid;
00077 };
00078 
00102 template<class A>
00103 class DecisionTable : public BGPRouteTable<A>  {
00104 public:
00105     DecisionTable(string tablename,
00106           Safi safi,
00107           NextHopResolver<A>& next_hop_resolver);
00108     ~DecisionTable();
00109     int add_parent(BGPRouteTable<A> *parent,
00110            PeerHandler *peer_handler,
00111            uint32_t genid);
00112     int remove_parent(BGPRouteTable<A> *parent);
00113 
00114     int add_route(InternalMessage<A> &rtmsg,
00115           BGPRouteTable<A> *caller);
00116     int replace_route(InternalMessage<A> &old_rtmsg,
00117               InternalMessage<A> &new_rtmsg,
00118               BGPRouteTable<A> *caller);
00119     int delete_route(InternalMessage<A> &rtmsg, 
00120              BGPRouteTable<A> *caller);
00121     int route_dump(InternalMessage<A> &rtmsg,
00122            BGPRouteTable<A> *caller,
00123            const PeerHandler *peer);
00124     int push(BGPRouteTable<A> *caller);
00125     const SubnetRoute<A> *lookup_route(const IPNet<A> &net,
00126                        uint32_t& genid,
00127                        FPAListRef& pa_list) const;
00128 
00129     //don't call this on a DecisionTable - it's meaningless
00130     BGPRouteTable<A> *parent() { abort(); return NULL; }
00131 
00132     RouteTableType type() const {return DECISION_TABLE;}
00133     string str() const;
00134 
00135     bool get_next_message(BGPRouteTable<A> */*next_table*/) {
00136     abort();
00137     return false;
00138     }
00139 
00140     bool dump_next_route(DumpIterator<A>& dump_iter);
00146     virtual void igp_nexthop_changed(const A& bgp_nexthop);
00147 
00148     void peering_went_down(const PeerHandler *peer, uint32_t genid,
00149                BGPRouteTable<A> *caller);
00150     void peering_down_complete(const PeerHandler *peer, uint32_t genid,
00151                    BGPRouteTable<A> *caller);
00152     void peering_came_up(const PeerHandler *peer, uint32_t genid,
00153              BGPRouteTable<A> *caller);
00154 
00155 private:
00156     const SubnetRoute<A> *lookup_route(const BGPRouteTable<A>* ignore_parent,
00157                        const IPNet<A> &net,
00158                        const PeerHandler*& best_routes_peer,
00159                        BGPRouteTable<A>*& best_routes_parent
00160                        ) const;
00161 
00162     RouteData<A>* 
00163         find_alternative_routes(const BGPRouteTable<A> *caller,
00164                 const IPNet<A>& net,
00165                 list <RouteData<A> >& alternatives) const;
00166     uint32_t local_pref(const FPAListRef& pa_list) const;
00167     uint32_t med(const FPAListRef& pa_list) const;
00168     bool resolvable(const A) const;
00169     uint32_t igp_distance(const A) const;
00170     RouteData<A>* find_winner(list<RouteData<A> >& alternatives) const;
00171     map<BGPRouteTable<A>*, PeerTableInfo<A>* > _parents;
00172     map<uint32_t, PeerTableInfo<A>* > _sorted_parents;
00173 
00174     NextHopResolver<A>& _next_hop_resolver;
00175 };
00176 
00177 #endif // __BGP_ROUTE_TABLE_DECISION_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations