xorp

area_router.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-2009 XORP, Inc.
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/ospf/area_router.hh,v 1.141 2008/10/02 21:57:47 bms Exp $
00022 
00023 #ifndef __OSPF_AREA_ROUTER_HH__
00024 #define __OSPF_AREA_ROUTER_HH__
00025 
00026 class DataBaseHandle;
00027 class LsaTempStore;
00028 
00033 template <typename A>
00034 class AreaRouter : public ServiceBase {
00035  public:
00036     AreaRouter(Ospf<A>& ospf, OspfTypes::AreaID area,
00037            OspfTypes::AreaType area_type);
00038 
00045     int startup();
00046 
00053     int shutdown();
00054 
00058     void add_peer(OspfTypes::PeerID peer);
00059 
00063     void delete_peer(OspfTypes::PeerID peer);
00064 
00068     bool peer_up(OspfTypes::PeerID peer);
00069 
00073     bool peer_down(OspfTypes::PeerID peer);
00074 
00081     void area_border_router_transition(bool up);
00082 
00086     void change_area_router_type(OspfTypes::AreaType area_type);
00087 
00101     bool find_global_address(uint32_t adv, uint16_t type,
00102                  LsaTempStore& lsa_temp_store,
00103                  A& global_address) const;
00104 
00108     bool configured_virtual_link() const;
00109 
00113     bool add_virtual_link(OspfTypes::RouterID rid);
00114 
00118     bool remove_virtual_link(OspfTypes::RouterID rid);
00119 
00123     void start_virtual_link();
00124 
00131     void check_for_virtual_linkV2(const RouteCmd<Vertex>& rc,
00132                   Lsa::LsaRef lsar);
00133 
00141     void check_for_virtual_linkV3(const RouteCmd<Vertex>& rc,
00142                   Lsa::LsaRef lsar,
00143                   LsaTempStore& lsa_temp_store);
00144 
00148     void end_virtual_link();
00149 
00150 
00156     bool find_interface_address(Lsa::LsaRef src, Lsa::LsaRef dst,
00157                 A& interface)const;
00158 
00164     bool find_interface_address(OspfTypes::RouterID rid, uint32_t interface_id,
00165                 A& interface);
00166 
00170     bool area_range_add(IPNet<A> net, bool advertise);
00171 
00175     bool area_range_delete(IPNet<A> net);
00176 
00180     bool area_range_change_state(IPNet<A> net, bool advertise);
00181 
00186     bool area_range_covered(IPNet<A> net, bool& advertise);
00187 
00192     bool area_range_covering(IPNet<A> net, IPNet<A>& sumnet);
00193 
00197     bool area_range_configured();
00198 
00203     bool originate_default_route(bool enable);
00204 
00209     bool stub_default_cost(uint32_t cost);
00210 
00214     bool summaries(bool enable);
00215 
00219     bool get_lsa(const uint32_t index, bool& valid, bool& toohigh, bool& self,
00220          vector<uint8_t>& lsa);
00221     
00225     bool new_router_links(OspfTypes::PeerID peer,
00226               const list<RouterLink>& router_link);
00227 
00235     void refresh_router_lsa(bool timer = false);
00236 
00242     void stub_networksV3(bool timer);
00243 
00254     void summary_announce(OspfTypes::AreaID area, IPNet<A> net,
00255               RouteEntry<A>& rt, bool push);
00256 
00262     void summary_withdraw(OspfTypes::AreaID area, IPNet<A> net,
00263               RouteEntry<A>& rt);
00264 
00269     void summary_replace(OspfTypes::AreaID area, IPNet<A> net,
00270              RouteEntry<A>& rt, RouteEntry<A>& previous_rt,
00271              OspfTypes::AreaID previous_area);
00272 
00277     bool external_area_type() const;
00278  
00286     void external_copy_net_nexthop(A,
00287                    ASExternalLsa *dst,
00288                    ASExternalLsa *src);
00289 
00295     Lsa::LsaRef external_generate_type7(Lsa::LsaRef lsar, bool& indb);
00296 
00300     Lsa::LsaRef external_generate_external(Lsa::LsaRef lsar);
00301 
00317     void external_announce(Lsa::LsaRef lsar, bool push, bool redist);
00318 
00322     void external_announce_complete();
00323 
00329     void external_refresh(Lsa::LsaRef lsar);
00330 
00337     void external_withdraw(Lsa::LsaRef lsar);
00338 
00342     bool add_link_lsa(OspfTypes::PeerID peerid, Lsa::LsaRef lsar);
00343 
00347     bool update_link_lsa(OspfTypes::PeerID peerid, Lsa::LsaRef lsar);
00348 
00352     bool withdraw_link_lsa(OspfTypes::PeerID peerid, Lsa::LsaRef lsar);
00353 
00357     void refresh_link_lsa(OspfTypes::PeerID peerid, Lsa::LsaRef lsar);
00358 
00362     bool generate_network_lsa(OspfTypes::PeerID peer,
00363                   OspfTypes::RouterID link_state_id,
00364                   list<RouterInfo>& attached_routers,
00365                   uint32_t network_mask);
00366 
00370     bool update_network_lsa(OspfTypes::PeerID peer,
00371                 OspfTypes::RouterID link_state_id,
00372                 list<RouterInfo>& attached_routers,
00373                 uint32_t network_mask);
00374 
00378     bool withdraw_network_lsa(OspfTypes::PeerID peer,
00379                   OspfTypes::RouterID link_state_id);
00380 
00389     void refresh_network_lsa(OspfTypes::PeerID peerid, Lsa::LsaRef lsar,
00390                  bool timer = false);
00391 
00400     bool check_link_lsa(LinkLsa *nllsa, LinkLsa *ollsa);
00401 
00408     void update_intra_area_prefix_lsa(OspfTypes::PeerID peerid);
00409 
00421     bool generate_intra_area_prefix_lsa(OspfTypes::PeerID peerid,
00422                     Lsa::LsaRef lsar,
00423                     uint32_t interface_id);
00424 
00435     uint32_t populate_prefix(OspfTypes::PeerID peeridid,
00436                  uint32_t interface_id, 
00437                  OspfTypes::RouterID router_id,
00438                  list<IPv6Prefix>& prefixes);
00439     
00451     uint32_t update_intra_area_prefix_lsa(OspfTypes::PeerID peer,
00452                       uint16_t referenced_ls_type,
00453                       OspfTypes::RouterID interface_id,
00454                       const list<RouterInfo>& 
00455                       attached_routers);
00456 
00466     bool withdraw_intra_area_prefix_lsa(OspfTypes::PeerID peer,
00467                     uint16_t referenced_ls_type,
00468                     uint32_t interface_id);
00469                     
00470 
00481     void refresh_intra_area_prefix_lsa(OspfTypes::PeerID peerid,
00482                        uint16_t referenced_ls_type,
00483                        uint32_t interface_id);
00484 
00489     void generate_default_route();
00490 
00494     bool find_default_route(size_t& index);
00495 
00496     // Temporary storage used by save_default_route() and
00497     // restore_default_route().
00498     Lsa::LsaRef _saved_default_route;
00499     
00505     void save_default_route();
00506 
00512     void restore_default_route();
00513 
00518     void withdraw_default_route();
00519 
00525     void refresh_default_route();
00526 
00530 //     void add_network(OspfTypes::PeerID peer, IPNet<A> network);
00531 
00535 //     void remove_network(OspfTypes::PeerID peer, IPNet<A> network);
00536 
00540     OspfTypes::AreaType get_area_type() const { return _area_type; }
00541 
00547     uint32_t get_options() {
00548     return _ospf.get_peer_manager().compute_options(get_area_type());
00549     }
00550 
00565     void receive_lsas(OspfTypes::PeerID peerid, OspfTypes::NeighbourID nid,
00566               list<Lsa::LsaRef>& lsas, 
00567               list<Lsa_header>& direct_ack,
00568               list<Lsa_header>& delayed_ack,
00569               bool is_router_dr, bool is_router_bdr,
00570               bool is_neighbour_dr);
00571 
00575     enum LsaSearch {
00576     NOMATCH,    // No matching LSA was found.
00577     EQUIVALENT, // The two LSAs are considered equivalent.
00578     NEWER,      // The offered LSA is newer than the database copy.
00579     OLDER,      // The offered LSA is older than the database copy.
00580     };
00581 
00590     LsaSearch compare_lsa(const Lsa_header& candidate,
00591               const Lsa_header& current) const;
00592 
00600     LsaSearch compare_lsa(const Lsa_header&) const;
00601 
00605     bool newer_lsa(const Lsa_header&) const;
00606 
00620     bool get_lsas(const list<Ls_request>& requests,
00621           list<Lsa::LsaRef>& lsas);
00622 
00632     DataBaseHandle open_database(OspfTypes::PeerID peerid, bool& empty);
00633 
00641     bool valid_entry_database(OspfTypes::PeerID peerid, size_t index);
00642 
00650     bool subsequent(DataBaseHandle& dbh);
00651 
00659     Lsa::LsaRef get_entry_database(DataBaseHandle& dbh, bool& last);
00660 
00666     void close_database(DataBaseHandle& dbh);
00667 
00675     void clear_database(bool preserve_link_lsas = false);
00676 
00680     void maxage_type_database(uint16_t type);
00681 
00685     bool backbone() const {
00686     return OspfTypes::BACKBONE == _area;
00687     }
00688 
00689     bool backbone(OspfTypes::AreaID area) const {
00690     return OspfTypes::BACKBONE == area;
00691     }
00692 #ifndef UNFINISHED_INCREMENTAL_UPDATE
00693     bool get_transit_capability() const {
00694     return _TransitCapability;
00695     }
00696 #endif
00697 
00701     void routing_total_recompute();
00702 
00706     void testing_routing_total_recompute() {
00707     routing_total_recompute();
00708     }
00709 
00713     void testing_print_link_state_database() const;
00714 
00719     bool testing_replace_router_lsa(Lsa::LsaRef lsar) {
00720     RouterLsa *rlsa = dynamic_cast<RouterLsa *>(lsar.get());
00721     XLOG_ASSERT(rlsa);
00722     XLOG_ASSERT(rlsa->get_self_originating());
00723     switch (_ospf.get_version()) {
00724     case OspfTypes::V2:
00725         XLOG_ASSERT(_ospf.get_router_id() ==
00726             rlsa->get_header().get_link_state_id());
00727         break;
00728     case OspfTypes::V3:
00729         break;
00730     }
00731     XLOG_ASSERT(_ospf.get_router_id() ==
00732             rlsa->get_header().get_advertising_router());
00733 
00734     size_t index;
00735     if (find_lsa(_router_lsa, index)) {
00736         delete_lsa(_router_lsa, index, true);
00737     }
00738     _router_lsa = lsar;
00739     add_lsa(_router_lsa);
00740     return true;
00741     }
00742 
00746     bool testing_add_lsa(Lsa::LsaRef lsar) {
00747     return add_lsa(lsar);
00748     }
00749 
00753     bool testing_delete_lsa(Lsa::LsaRef lsar) {
00754     size_t index;
00755     if (find_lsa(lsar, index)) {
00756         delete_lsa(lsar, index, true);
00757         return true;
00758     }
00759     XLOG_FATAL("Attempt to delete LSA that is not in database \n%s",
00760            cstring(*lsar));
00761     return false;
00762     }
00763 
00764     string str() {
00765     return "Area " + pr_id(_area);
00766     }
00767 
00768  private:
00769     Ospf<A>& _ospf;         // Reference to the controlling class.
00770 
00771     OspfTypes::AreaID _area;        // Area: That is represented.
00772     OspfTypes::AreaType _area_type; // Type of this area.
00773     map<OspfTypes::RouterID,bool> _vlinks;  // Virtual link endpoints.
00774     set<OspfTypes::RouterID> _tmp;  // temporary storage for
00775                     // virtual links.
00776     bool _summaries;            // True if summaries should be
00777                     // generated into a stub area.
00778     bool _stub_default_announce;    // Announce a default route into
00779                     // stub or nssa
00780     uint32_t _stub_default_cost;    // The cost of the default
00781                     // route that is injected into
00782                     // a stub area.
00783     bool _external_flooding;        // True if AS-External-LSAs
00784                     // are being flooded.
00785 
00786 #ifdef  UNFINISHED_INCREMENTAL_UPDATE
00787     Spt<Vertex> _spt;           // SPT computation unit.
00788 #endif
00789 
00790     Lsa::LsaRef _invalid_lsa;       // An invalid LSA to overwrite slots
00791     Lsa::LsaRef _router_lsa;        // This routers router LSA.
00792     vector<Lsa::LsaRef> _db;        // Database of LSAs.
00793     deque<size_t> _empty_slots;     // Available slots in the Database.
00794     uint32_t _last_entry;       // One past last entry in
00795                     // database. A value of 0 is
00796                     // an empty database.
00797     uint32_t _allocated_entries;    // Number of allocated entries.
00798     
00799     uint32_t _readers;          // Number of database readers.
00800     
00801     DelayQueue<Lsa::LsaRef> _queue; // Router LSA queue.
00802 
00803     XorpTimer _reincarnate_timer;   // Wait for the LSAs to be purged.
00804     list<Lsa::LsaRef> _reincarnate; // Self-originated LSAs where
00805                     // the sequence number has
00806                     // reached MaxSequenceNumber.
00807 
00808     uint32_t _lsid;         // OSPFv3 only next Link State ID.
00809     map<IPNet<IPv6>, uint32_t> _lsmap;  // OSPFv3 only
00810 
00811 #ifdef  UNFINISHED_INCREMENTAL_UPDATE
00812     uint32_t _TransitCapability;    // Used by the spt computation.
00813 
00814     // XXX - This needs a better name.
00815     struct Bucket {
00816     Bucket(size_t index, bool known) : _index(index), _known(known)
00817     {}
00818     size_t _index;
00819     bool _known;
00820     };
00821 
00822     list<Bucket> _new_lsas;     // Indexes of new LSAs that
00823                     // have arrived recently.
00824 #else
00825     bool _TransitCapability;        // Does this area support
00826                     // transit traffic?
00827 
00828     void set_transit_capability(bool t) {
00829     _TransitCapability = t;
00830     }
00831 
00832 #endif
00833 
00837     struct PeerState {
00838     PeerState()
00839         : _up(false)
00840     {}
00841     bool _up;           // True if peer is enabled.
00842     list<RouterLink> _router_links; // Router links for this peer
00843     };
00844 
00845     typedef ref_ptr<PeerState> PeerStateRef;
00846     typedef map<OspfTypes::PeerID, PeerStateRef> PeerMap;
00847     PeerMap _peers;     // Peers of this area.
00848 
00849     uint32_t _routing_recompute_delay;  // How many seconds to wait
00850                     // before recompting.
00851     XorpTimer _routing_recompute_timer; // Timer to cause recompute.
00852     
00853     // How to handle Type-7 LSAs at the border.
00854     OspfTypes::NSSATranslatorRole _translator_role;
00855     OspfTypes::NSSATranslatorState _translator_state;
00856     bool _type7_propagate;      // How to set the propagate bit.
00857 
00861     struct Range {
00862     bool _advertise;    // Should this range be advertised.
00863     };
00864 
00865     Trie<A, Range> _area_range; // Area range for summary generation.
00866 
00874     void unique_link_state_id(Lsa::LsaRef lsar);
00875 
00882     bool unique_find_lsa(Lsa::LsaRef lsar, const IPNet<A>& net, size_t& index);
00883 
00887     void summary_network_lsa_set_net_lsid(SummaryNetworkLsa *snlsa,
00888                       IPNet<A> net);
00889 
00890 
00891     Lsa::LsaRef summary_network_lsa(IPNet<A> net, RouteEntry<A>& rt);
00892 
00898     Lsa::LsaRef summary_network_lsa_intra_area(OspfTypes::AreaID area,
00899                            IPNet<A> net,
00900                            RouteEntry<A>& rt,
00901                            bool& announce);
00907     Lsa::LsaRef summary_build(OspfTypes::AreaID area, IPNet<A> net,
00908                   RouteEntry<A>& rt, bool& announce);
00909 
00914     void refresh_summary_lsa(Lsa::LsaRef lsar);
00915 
00922     bool age_lsa(Lsa::LsaRef lsar);
00923 
00928     void maxage_reached(Lsa::LsaRef lsar, size_t index);
00929 
00934     void premature_aging(Lsa::LsaRef lsar, size_t index);
00935 
00940     void increment_sequence_number(Lsa::LsaRef lsar);
00941 
00947     void update_age_and_seqno(Lsa::LsaRef lsar, const TimeVal& now);
00948 
00952     void max_sequence_number_reached(Lsa::LsaRef lsar);
00953 
00958     bool reincarnate();
00959 
00968     bool add_lsa(Lsa::LsaRef lsar);
00969 
00979     bool delete_lsa(Lsa::LsaRef lsar, size_t index, bool invalidate);
00980 
00988     bool update_lsa(Lsa::LsaRef lsar, size_t index);
00989 
00998     bool find_lsa(const Ls_request& lsr, size_t& index) const;
00999 
01008     bool find_lsa(Lsa::LsaRef lsar, size_t& index) const;
01009 
01018     bool find_network_lsa(uint32_t link_state_id, size_t& index) const;
01019 
01033     bool find_router_lsa(uint32_t advertising_router, size_t& index) const;
01034 
01043     LsaSearch compare_lsa(const Lsa_header&, size_t& index) const;
01044 
01053     bool update_router_links();
01054 
01055     /*
01056      * Send this LSA to all our peers.
01057      *
01058      * @param peerid The peer this LSA arrived on.
01059      * @param nid The neighbour this LSA arrived on so don't reflect.
01060      * @param lsar The LSA to publish
01061      * @param multicast_on_peer Did this LSA get multicast on this peer.
01062      */
01063     void publish(const OspfTypes::PeerID peerid,
01064          const OspfTypes::NeighbourID nid,
01065          Lsa::LsaRef lsar, bool& multicast_on_peer) const;
01066 
01067     /*
01068      * Send this LSA to all our peers.
01069      *
01070      * @param lsar The LSA to publish
01071      */
01072     void publish_all(Lsa::LsaRef lsar);
01073 
01077     void push_lsas(const char* msg);
01078 
01082     bool external_propagate_bit(Lsa::LsaRef lsar) const {
01083     XLOG_ASSERT(lsar->type7());
01084     return Options(_ospf.get_version(),lsar->get_header().get_options())
01085         .get_p_bit();
01086     }
01087 
01092     void external_type7_translate(Lsa::LsaRef lsar);
01093 
01101     void external_flood_all_areas(Lsa::LsaRef lsar);
01102 
01106     void external_push_all_areas();
01107 
01111     bool neighbours_exchange_or_loading() const;
01112 
01119     bool neighbour_at_least_two_way(OspfTypes::RouterID rid) const;
01120 
01131     bool get_neighbour_address(OspfTypes::RouterID rid, uint32_t interface_id,
01132                    A& neighbour_address)
01133     const;
01134 
01142     bool on_link_state_request_list(const OspfTypes::PeerID peerid,
01143                     const OspfTypes::NeighbourID nid,
01144                     Lsa::LsaRef lsar) const;
01145 
01152     bool event_bad_link_state_request(const OspfTypes::PeerID peerid,
01153                       const OspfTypes::NeighbourID nid) const;
01154 
01165     bool send_lsa(const OspfTypes::PeerID peerid,
01166           const OspfTypes::NeighbourID nid,
01167           Lsa::LsaRef lsar) const;
01168 
01177     bool self_originated_by_interface(Lsa::LsaRef lsar, A = A::ZERO()) const;
01178 
01191     bool self_originated(Lsa::LsaRef lsar, bool match, size_t index);
01192 
01196     void RouterVertex(Vertex& v);
01197 
01201     void routing_begin();
01202 
01212     void routing_add(Lsa::LsaRef lsar, bool known);
01213 
01220     void routing_delete(Lsa::LsaRef lsar);
01221 
01227     void routing_end();
01228 
01232     void routing_schedule_total_recompute();
01233 
01237     void routing_timer();
01238 
01242     void routing_total_recomputeV2();
01243     void routing_total_recomputeV3();
01244 
01249     void routing_table_add_entry(RoutingTable<A>& routing_table,
01250                  IPNet<A> net,
01251                  RouteEntry<A>& route_entry, const char* msg);
01252 
01256     void routing_area_ranges(list<RouteCmd<Vertex> >& r);
01257     void routing_area_rangesV2(const list<RouteCmd<Vertex> >& r);
01258     void routing_area_rangesV3(const list<RouteCmd<Vertex> >& r,
01259                    LsaTempStore& lsa_temp_store);
01260 
01264     void routing_inter_area();
01265     void routing_inter_areaV2();
01266     void routing_inter_areaV3();
01267 
01271     void routing_transit_area();
01272     void routing_transit_areaV2();
01273     void routing_transit_areaV3();
01274 
01278     void routing_as_external();
01279     void routing_as_externalV2();
01280     void routing_as_externalV3();
01281 
01282 
01283 #if 0
01284 
01294     bool associated_prefixesV3(const RouterLsa *rlsa,
01295                    const list<IntraAreaPrefixLsa *>& iapl,
01296                    list<IPv6Prefix>& prefixes);
01297 
01309     bool associated_prefixesV3(NetworkLsa *nlsa,
01310                    const list<IntraAreaPrefixLsa *>& iapl,
01311                    list<IPv6Prefix>& prefixes);
01312 #endif
01313 
01325     bool associated_prefixesV3(uint16_t ls_type,
01326                    uint32_t referenced_link_state_id,
01327                    const list<IntraAreaPrefixLsa *>& lsai,
01328                    list<IPv6Prefix>& prefixes) const;
01329 
01336     bool routing_compare_externals(Lsa::LsaRef current,
01337                    Lsa::LsaRef candidate) const;
01338 
01355     bool bidirectionalV2(RouterLink::Type rl_type,
01356              const uint32_t link_state_id,
01357              const RouterLink& rl,
01358              RouterLsa *rlsa,
01359              uint16_t& metric,
01360              uint32_t& interface_address);
01361 
01370     bool bidirectional(const uint32_t link_state_id_or_adv,
01371                const RouterLink& rl,
01372                NetworkLsa *nlsa) const;
01373 
01381     bool bidirectionalV2(RouterLsa *rlsa, NetworkLsa *nlsa,
01382              uint32_t& interface_address);
01383 
01393     bool bidirectionalV3(RouterLsa *rlsa, NetworkLsa *nlsa,
01394                uint32_t& interface_id);
01395 
01409     bool bidirectionalV3(RouterLink::Type rl_type,
01410              uint32_t advertising_router,
01411              RouterLsa *rlsa,
01412              uint16_t& metric);
01413 
01417     void routing_router_lsaV2(Spt<Vertex>& spt, const Vertex& src,
01418                   RouterLsa *rlsa);
01419 
01420     void routing_router_link_p2p_vlinkV2(Spt<Vertex>& spt, const Vertex& src,
01421                      RouterLsa *rlsa, RouterLink rl);
01422 
01423     void routing_router_link_transitV2(Spt<Vertex>& spt, const Vertex& src,
01424                        RouterLsa *rlsa, RouterLink rl);
01425 
01426     void routing_router_link_stubV2(Spt<Vertex>& spt, const Vertex& src,
01427                     RouterLsa *rlsa, RouterLink rl);
01428 
01432     void routing_router_lsaV3(Spt<Vertex>& spt, const Vertex& src,
01433                   RouterLsa *rlsa);
01434 
01435     void routing_router_link_p2p_vlinkV3(Spt<Vertex>& spt, const Vertex& src,
01436                      RouterLsa *rlsa, RouterLink rl);
01437 
01438     void routing_router_link_transitV3(Spt<Vertex>& spt, const Vertex& src,
01439                        RouterLsa *rlsa, RouterLink rl);
01440 };
01441 
01447 class DataBaseHandle {
01448  public:
01449     DataBaseHandle() : _position(0), _last_entry(0), _valid(false),
01450                _peerid(OspfTypes::ALLPEERS)
01451     {}
01452 
01453     DataBaseHandle(bool v, uint32_t last_entry, OspfTypes::PeerID peerid)
01454     : _position(0), _last_entry(last_entry), _valid(v),
01455       _peerid(peerid)
01456     {}
01457 
01458     uint32_t position() const {
01459     XLOG_ASSERT(valid());
01460     return _position;
01461     }
01462 
01463     uint32_t last() const {
01464     XLOG_ASSERT(valid());
01465     return _last_entry;
01466     }
01467 
01468     void advance(bool& last) { 
01469     XLOG_ASSERT(valid());
01470     XLOG_ASSERT(_last_entry != _position);
01471     _position++; 
01472     last = _last_entry == _position;
01473     }
01474 
01475     bool valid() const { return _valid; }
01476 
01477     void invalidate() { _valid = false; }
01478 
01479     OspfTypes::PeerID get_peerid() const { return _peerid; }
01480 
01481  private:
01482     uint32_t _position;     // Position in database.
01483     uint32_t _last_entry;   // One past last entry, for an empty
01484                 // database value would be 0.
01485     bool _valid;        // True if this handle is valid.
01486     OspfTypes::PeerID _peerid;  // The Peer ID that opened the database.
01487 };
01488 
01498 class LsaTempStore {
01499 public:
01500     void add_router_lsa(Lsa::LsaRef lsar) {
01501     _router_lsas[lsar->get_header().get_advertising_router()].
01502         push_back(lsar);
01503     }
01504 
01505     list<Lsa::LsaRef>& get_router_lsas(OspfTypes::RouterID rid) {
01506     return _router_lsas[rid];
01507     }
01508 
01509     void add_intra_area_prefix_lsa(IntraAreaPrefixLsa *iaplsa) {
01510     XLOG_ASSERT(iaplsa);
01511     _intra_area_prefix_lsas[iaplsa->get_header().get_advertising_router()].
01512         push_back(iaplsa);
01513     }
01514 
01515     list<IntraAreaPrefixLsa *>& 
01516     get_intra_area_prefix_lsas(OspfTypes::RouterID rid) {
01517     return _intra_area_prefix_lsas[rid];
01518     }
01519 
01520 private:
01521     map<OspfTypes::RouterID, list<Lsa::LsaRef> > _router_lsas;
01522     map<OspfTypes::RouterID, list<IntraAreaPrefixLsa *> > 
01523     _intra_area_prefix_lsas;
01524 };
01525 
01526 #endif // __OSPF_AREA_ROUTER_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations