xorp

route_table_fanout.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/route_table_fanout.hh,v 1.27 2008/11/08 06:14:39 mjh Exp $
00022 
00023 #ifndef __BGP_ROUTE_TABLE_FANOUT_HH__
00024 #define __BGP_ROUTE_TABLE_FANOUT_HH__
00025 
00026 
00027 #include "route_table_base.hh"
00028 #include "peer_route_pair.hh"
00029 #include "route_queue.hh"
00030 #include "crash_dump.hh"
00031 
00032 
00033 template<class A> class DumpTable;
00034 
00035 template<class A>
00036 class NextTableMapIterator {
00037 public:
00038     NextTableMapIterator() {};
00039     NextTableMapIterator(const typename multimap<uint32_t, PeerTableInfo<A>*>::iterator& iter) {
00040     _iter = iter;
00041     }
00042     BGPRouteTable<A>* first() { return _iter->second->route_table(); }
00043     PeerTableInfo<A>& second() { return *(_iter->second); }
00044     void operator ++(int) { _iter++; }
00045     bool operator==(const NextTableMapIterator& them) const {
00046     return _iter == them._iter;
00047     }
00048 private:
00049     typename multimap <uint32_t, PeerTableInfo<A>*>::iterator _iter;
00050 };
00051 
00060 template<class A> 
00061 class NextTableMap  {
00062 public:
00063     typedef NextTableMapIterator<A> iterator;
00064     NextTableMap() {};
00065     ~NextTableMap();
00066     void insert(BGPRouteTable<A> *next_table,
00067         const PeerHandler *ph, uint32_t genid);
00068     void erase(iterator& iter);
00069     iterator find(BGPRouteTable<A> *next_table);
00070     iterator begin();
00071     iterator end();
00072 private:
00073     map<BGPRouteTable<A> *, PeerTableInfo<A>* > _next_tables;
00074     multimap<uint32_t, PeerTableInfo<A>* > _next_table_order;
00075 };
00076 
00077 template<class A>
00078 class FanoutTable : public BGPRouteTable<A>, CrashDumper  {
00079 public:
00080     FanoutTable(string tablename,
00081         Safi safi,
00082         BGPRouteTable<A> *parent,
00083         PeerHandler *aggr_handler,
00084         BGPRouteTable<A> *aggr_table);
00085     ~FanoutTable();
00086     int add_next_table(BGPRouteTable<A> *next_table,
00087                const PeerHandler *ph, uint32_t genid);
00088     int remove_next_table(BGPRouteTable<A> *next_table);
00089     int replace_next_table(BGPRouteTable<A> *old_next_table,
00090                BGPRouteTable<A> *new_next_table);
00091     int add_route(InternalMessage<A> &rtmsg,
00092           BGPRouteTable<A> *caller);
00093     int replace_route(InternalMessage<A> &old_rtmsg,
00094               InternalMessage<A> &new_rtmsg,
00095               BGPRouteTable<A> *caller);
00096     int delete_route(InternalMessage<A> &rtmsg, 
00097              BGPRouteTable<A> *caller);
00098     int route_dump(InternalMessage<A> &rtmsg,
00099            BGPRouteTable<A> *caller,
00100            const PeerHandler *dump_peer);
00101     int push(BGPRouteTable<A> *caller);
00102     const SubnetRoute<A> *lookup_route(const IPNet<A> &net,
00103                        uint32_t& genid,
00104                        FPAListRef& pa_list) const;
00105 
00106     RouteTableType type() const {return FANOUT_TABLE;}
00107     string str() const;
00108 
00109     void peer_table_info(list<const PeerTableInfo<A>*>& peer_list);
00110 
00111     int dump_entire_table(BGPRouteTable<A> *child_to_dump_to, Safi safi,
00112               string ribname);
00113     /* mechanisms to implement flow control in the output plumbing */
00114     bool get_next_message(BGPRouteTable<A> *next_table);
00115 
00116     void peering_went_down(const PeerHandler *peer, uint32_t genid,
00117                BGPRouteTable<A> *caller);
00118     void peering_down_complete(const PeerHandler *peer, uint32_t genid,
00119                    BGPRouteTable<A> *caller);
00120     void peering_came_up(const PeerHandler *peer, uint32_t genid,
00121              BGPRouteTable<A> *caller);
00122 
00123     void crash_dump() const {
00124     CrashDumper::crash_dump();
00125     }
00126     string dump_state() const;
00127 
00128     void print_queue();
00129 private:
00130     void add_to_queue(RouteQueueOp operation,
00131               InternalMessage<A> &rtmsg,
00132               const list<PeerTableInfo<A>*>& queued_peers);
00133     void add_replace_to_queue(InternalMessage<A> &old_rtmsg,
00134                   InternalMessage<A> &new_rtmsg,
00135                   const list<PeerTableInfo<A>*>& queued_peers);
00136     void add_push_to_queue(const list<PeerTableInfo<A>*>& queued_peers,
00137                const PeerHandler *origin_peer);
00138     void set_queue_positions(const list<PeerTableInfo<A>*>& queued_peers);
00139     void skip_entire_queue(BGPRouteTable<A> *next_table);
00140     void wakeup_downstream(list <PeerTableInfo<A>*>& queued_peers);
00141 
00142     void add_dump_table(DumpTable<A> *dump_table); 
00143     void remove_dump_table(DumpTable<A> *dump_table);
00144     NextTableMap<A> _next_tables;
00145 
00146     list <const RouteQueueEntry<A>*> _output_queue;
00147     set <DumpTable<A>*> _dump_tables;
00148 
00149     PeerTableInfo<A> *_aggr_peerinfo;
00150 };
00151 
00152 #endif // __BGP_ROUTE_TABLE_FANOUT_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations