xorp

dump_iterators.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/dump_iterators.hh,v 1.21 2008/10/02 21:56:15 bms Exp $
00021 
00022 #ifndef __BGP_DUMP_ITERATORS_HH__
00023 #define __BGP_DUMP_ITERATORS_HH__
00024 
00025 
00026 
00027 #include "path_attribute.hh"
00028 #include "bgp_trie.hh"
00029 #include "route_queue.hh"
00030 #include "peer_route_pair.hh"
00031 #include "route_table_aggregation.hh"
00032 
00033 class BGPPlumbing;
00034 class PeerHandler;
00035 template <class A> class InternalMessage;
00036 
00037 typedef enum {
00038     STILL_TO_DUMP,
00039     CURRENTLY_DUMPING,
00040     DOWN_DURING_DUMP,
00041     DOWN_BEFORE_DUMP,
00042     COMPLETELY_DUMPED,
00043     NEW_PEER,
00044     FIRST_SEEN_DURING_DUMP
00045 } PeerDumpStatus;
00046     
00047 template <class A>
00048 class PeerDumpState {
00049 public:
00050     PeerDumpState(const PeerHandler* peer,
00051           PeerDumpStatus status,
00052           uint32_t genid);
00053     ~PeerDumpState();
00054     string str() const;
00055     const PeerHandler* peer_handler() const { return _peer; }
00056 
00057     const IPNet<A>& last_net() const { return _last_net_before_down; }
00058     
00059     void set_down_during_dump(IPNet<A>& last_net, uint32_t genid) {
00060     XLOG_ASSERT(genid == _genid);
00061     _status = DOWN_DURING_DUMP;
00062     _last_net_before_down = last_net;
00063     set_delete_occurring(genid);
00064     }
00065 
00066     void set_down(uint32_t genid) {
00067     XLOG_ASSERT(_status == STILL_TO_DUMP 
00068             || _status == CURRENTLY_DUMPING);
00069     _status = DOWN_BEFORE_DUMP;
00070     set_delete_occurring(genid);
00071     }
00072 
00073     void start_dump() {
00074     XLOG_ASSERT(_status == STILL_TO_DUMP);
00075     _status = CURRENTLY_DUMPING;
00076     }
00077 
00078     void set_dump_complete() {
00079     XLOG_ASSERT(_status == CURRENTLY_DUMPING);
00080     _status = COMPLETELY_DUMPED;
00081     }
00082 
00083     uint32_t genid() const { return _genid; }
00084     void set_genid(uint32_t genid) { _genid = genid; }
00085     
00086     PeerDumpStatus status() const { return _status; }
00087 
00088     void set_delete_complete(uint32_t genid);
00089     void set_delete_occurring(uint32_t genid) { 
00090     _deleting_genids.insert(genid); 
00091     }
00092     bool delete_complete() const { return _deleting_genids.empty(); }
00093 private:
00094     const PeerHandler* _peer;
00095     bool _routes_dumped;
00096     IPNet<A> _last_net_before_down;
00097     uint32_t _genid;
00098     set <uint32_t> _deleting_genids;
00099     PeerDumpStatus _status;
00100 };
00101 
00102 template <class A>
00103 class DumpIterator {
00104 public:
00105     DumpIterator(const PeerHandler* peer,
00106          const list <const PeerTableInfo<A>*>& peers_to_dump);
00107     ~DumpIterator();
00108     string str() const;
00109     void route_dump(const InternalMessage<A> &rtmsg);
00110     const PeerHandler* current_peer() const { 
00111     return _current_peer->peer_handler(); 
00112     }
00113     const PeerHandler* peer_to_dump_to() const { return _peer; }
00114     bool is_valid() const;
00115     bool route_iterator_is_valid() const { return _route_iterator_is_valid; }
00116     bool next_peer();
00117     const typename BgpTrie<A>::iterator& route_iterator() const {
00118     return _route_iterator;
00119     }
00120     const typename RefTrie<A, const AggregateRoute<A> >::iterator& aggr_iterator() const {
00121     return _aggr_iterator;
00122     }
00123     //    const IPNet<A>& net() const { return _route_iterator_net; }
00124     void set_route_iterator(typename BgpTrie<A>::iterator& new_iter) {
00125     _route_iterator = new_iter;
00126     _route_iterator_is_valid = true;
00127     }
00128     void set_aggr_iterator(typename RefTrie<A, const AggregateRoute<A> >::iterator& new_iter) {
00129     _aggr_iterator = new_iter;
00130     _route_iterator_is_valid = true;
00131     }
00132     //void set_route_iterator_net(const IPNet<A>& net) {
00133     //      _route_iterator_net = net;
00134     //    }
00135 
00136     //    uint32_t rib_version() const { return _rib_version; }
00137     //    void set_rib_version(uint32_t version) { _rib_version = version; }
00138     bool route_change_is_valid(const PeerHandler* origin_peer,
00139                    const IPNet<A>& net,
00140                    uint32_t genid, RouteQueueOp op);
00141 
00146     void peering_is_down(const PeerHandler *peer, uint32_t genid);
00147 
00151     void peering_went_down(const PeerHandler *peer, uint32_t genid);
00152 
00156     void peering_down_complete(const PeerHandler *peer, uint32_t genid);
00157 
00161     void peering_came_up(const PeerHandler *peer, uint32_t genid);
00162 
00166     bool waiting_for_deletion_completion() const;
00167 
00171     bool iterator_got_moved(IPNet<A> new_net) const;
00172 private:
00173     const PeerHandler *_peer;
00174 
00178     list <PeerTableInfo<A> > _peers_to_dump;
00179     typename list <PeerTableInfo<A> >::iterator _current_peer;
00180     PeerTableInfo<A>* _current_peer_debug; //XXX just to aid debugging in gdb
00181 
00182     bool _route_iterator_is_valid;
00183     typename BgpTrie<A>::iterator _route_iterator;
00184     typename RefTrie<A, const AggregateRoute<A> >::iterator _aggr_iterator;
00185 
00186     bool _routes_dumped_on_current_peer;
00187     IPNet<A> _last_dumped_net;
00188 
00189     map <const PeerHandler*, PeerDumpState<A>* > _peers;
00190 
00191 };
00192 
00193 #endif // __BGP_DUMP_ITERATORS_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations