xorp

route_table_dump.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_dump.hh,v 1.27 2008/11/08 06:14:39 mjh Exp $
00021 
00022 #ifndef __BGP_ROUTE_TABLE_DUMP_HH__
00023 #define __BGP_ROUTE_TABLE_DUMP_HH__
00024 
00025 #include "route_table_base.hh"
00026 #include "peer_handler.hh"
00027 #include "bgp_trie.hh"
00028 #include "dump_iterators.hh"
00029 #include "peer_route_pair.hh"
00030 
00031 #define AUDIT_ENABLE
00032 #define AUDIT_LEN 1000
00033 
00034 class EventLoop;
00035 
00036 template<class A>
00037 class DumpTable : public BGPRouteTable<A>  {
00038 public:
00039     DumpTable(string tablename,
00040           const PeerHandler *peer,
00041           const list <const PeerTableInfo<A>*>& peer_list,
00042           BGPRouteTable<A> *parent,
00043           Safi safi);
00044     int add_route(InternalMessage<A> &rtmsg,
00045           BGPRouteTable<A> *caller);
00046     int replace_route(InternalMessage<A> &old_rtmsg,
00047               InternalMessage<A> &new_rtmsg,
00048               BGPRouteTable<A> *caller);
00049     int delete_route(InternalMessage<A> &rtmsg, 
00050              BGPRouteTable<A> *caller);
00051     int route_dump(InternalMessage<A> &rtmsg,
00052            BGPRouteTable<A> *caller,
00053            const PeerHandler *dump_peer);
00054     int push(BGPRouteTable<A> *caller);
00055     const SubnetRoute<A> *lookup_route(const IPNet<A> &net,
00056                        uint32_t& genid,
00057                        FPAListRef& pa_list) const;
00058     void route_used(const SubnetRoute<A>* route, bool in_use);
00059 
00060 
00061     RouteTableType type() const {return DUMP_TABLE;}
00062     string str() const;
00063 
00064     /* mechanisms to implement flow control in the output plumbing */
00065     bool get_next_message(BGPRouteTable<A> *next_table);
00066 
00067     void initiate_background_dump();
00068     void suspend_dump();
00069 
00074     void peering_is_down(const PeerHandler *peer, uint32_t genid);
00075 
00079     void peering_went_down(const PeerHandler *peer, uint32_t genid,
00080                BGPRouteTable<A> *caller);
00081 
00085     void peering_down_complete(const PeerHandler *peer, uint32_t genid,
00086                    BGPRouteTable<A> *caller);
00087 
00091     void peering_came_up(const PeerHandler *peer, uint32_t genid,
00092              BGPRouteTable<A> *caller);
00093 
00097     void wakeup();
00098 
00099 #ifdef AUDIT_ENABLE
00100     void print_and_clear_audit();
00101 #endif
00102 private:
00106     void completed();
00107     void schedule_unplumb_self();
00108     void unplumb_self();
00109     void wakeup_downstream();
00110     bool do_next_route_dump();
00111     EventLoop& eventloop() const {return _peer->eventloop();}
00112 
00113     const PeerHandler *_peer;
00114     DumpIterator<A> _dump_iter;
00115     bool _output_busy;
00116 
00117     int _dumped;
00118     bool _dump_active;  // true if the dump is in progress
00119     bool _triggered_event;   // true if DumpTable has been woken up by
00120                  // a triggered event (in which case we
00121                  // shouldn't do any dumping or we may
00122                  // surprise the upstream by dumping in
00123                  // the middle of an event )
00124     XorpTimer _dump_timer;
00125 
00126     //if we get to the end of the route dump, and some peers that went
00127     //down during our dump have not yet finished their deletion
00128     //process, we need to delay unplumbing ourself until they finish
00129     //to avoid propagating unnecessary deletes downstream.
00130     bool _waiting_for_deletion_completion;
00131 
00132     //The dump table has done its job and can be removed.
00133     bool _completed;
00134 
00135 #ifdef AUDIT_ENABLE
00136     //audit trail for debugging - keep a log of last few events, use
00137     //this as a circular buffer
00138     string _audit_entry[AUDIT_LEN];
00139     int _first_audit, _last_audit, _audit_entries;
00140     void add_audit(const string& log_entry);
00141 
00142 #endif
00143 
00144 };
00145 
00146 #endif // __BGP_ROUTE_TABLE_DUMP_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations