xorp

external.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/external.hh,v 1.24 2008/10/02 21:57:47 bms Exp $
00022 
00023 #ifndef __OSPF_EXTERNAL_HH__
00024 #define __OSPF_EXTERNAL_HH__
00025 
00026 #include <libxorp/trie.hh>
00027 
00031 class ASExternalDatabase {
00032  public:
00033     struct compare {
00034     bool operator ()(const Lsa::LsaRef a, const Lsa::LsaRef b) const {
00035         if (a->get_header().get_link_state_id() ==
00036         b->get_header().get_link_state_id())
00037         return a->get_header().get_advertising_router() <
00038             b->get_header().get_advertising_router();
00039         return a->get_header().get_link_state_id() <
00040         b->get_header().get_link_state_id();
00041     }
00042     };
00043 
00044     typedef set <Lsa::LsaRef, compare>::iterator iterator;
00045 
00046     iterator begin() { return _lsas.begin(); }
00047     iterator end() { return _lsas.end(); }
00048     void erase(iterator i) { _lsas.erase(i); }
00049     void insert(Lsa::LsaRef lsar) { _lsas.insert(lsar); }
00050     void clear();
00051 
00052     iterator find(Lsa::LsaRef lsar);
00053 
00054  private:
00055     set <Lsa::LsaRef, compare> _lsas;       // Stored AS-external-LSAs.
00056 };
00057 
00061 template <typename A>
00062 class External {
00063  public:
00064     External(Ospf<A>& ospf, map<OspfTypes::AreaID, AreaRouter<A> *>& areas);
00065 
00075     bool announce(OspfTypes::AreaID area, Lsa::LsaRef lsar);
00076 
00080     bool announce_complete(OspfTypes::AreaID area);
00081 
00085     void push(AreaRouter<A> *area_router);
00086 
00090     bool announce(IPNet<A> net, A nexthop, uint32_t metric,
00091           const PolicyTags& policytags);
00092 
00096     bool withdraw(const IPNet<A>& net);
00097 
00101     bool clear_database();
00102 
00110     void suppress_lsas(OspfTypes::AreaID area);
00111 
00115     void suppress_route_announce(OspfTypes::AreaID area, IPNet<A> net,
00116                  RouteEntry<A>& rt);
00117 
00121     void suppress_route_withdraw(OspfTypes::AreaID area, IPNet<A> net,
00122                  RouteEntry<A>& rt);
00123 
00127     bool as_boundary_router_p() const {
00128     return _originating != 0;
00129     }
00130     
00134     void push_routes();
00135 
00136  private:
00137     Ospf<A>& _ospf;         // Reference to the controlling class.
00138     map<OspfTypes::AreaID, AreaRouter<A> *>& _areas;    // All the areas
00139 
00140     ASExternalDatabase _lsas;       // Stored AS-external-LSAs.
00141     uint32_t _originating;      // Number of AS-external-LSAs
00142                     // that are currently being originated.
00143     uint32_t _lsid;         // OSPFv3 only next Link State ID.
00144     map<IPNet<IPv6>, uint32_t> _lsmap;  // OSPFv3 only
00145     list<Lsa::LsaRef> _suppress_temp;   // LSAs that could possibly
00146                     // suppress self originated LSAs
00147 #ifdef SUPPRESS_DB
00148     Trie<A, Lsa::LsaRef> _suppress_db;  // Database of suppressed self
00149                     // originated LSAs
00150 #endif
00151 
00155     ASExternalDatabase::iterator find_lsa(Lsa::LsaRef lsar);
00156 
00161     void update_lsa(Lsa::LsaRef lsar);
00162 
00166     void delete_lsa(Lsa::LsaRef lsar);
00167 
00172     void maxage_reached(Lsa::LsaRef lsar);
00173 
00181     void unique_link_state_id(Lsa::LsaRef lsar);
00182 
00192     ASExternalDatabase::iterator unique_find_lsa(Lsa::LsaRef lsar,
00193                          const IPNet<A>& net);
00194 
00198     void set_net_nexthop_lsid(ASExternalLsa *aselsa, IPNet<A> net, A nexthop);
00199 
00200 
00204     void announce_lsa(Lsa::LsaRef lsar);
00205 
00209     bool do_filtering(IPNet<A>& network, A& nexthop, uint32_t& metric,
00210               bool& e_bit, uint32_t& tag, bool& tag_set,
00211               const PolicyTags& policytags);
00212 
00216     void start_refresh_timer(Lsa::LsaRef lsar);
00217 
00221     void refresh(Lsa::LsaRef lsar);
00222 
00227     Lsa::LsaRef clone_lsa(Lsa::LsaRef lsar);
00228 
00232     bool suppress_candidate(Lsa::LsaRef lsar, IPNet<A> net, A nexthop,
00233                 uint32_t metric);
00234       
00235 #ifdef  SUPPRESS_DB
00236 
00240     void suppress_database_add(Lsa::LsaRef lsar, const IPNet<A>& net);
00241     
00246     void suppress_database_delete(const IPNet<A>& net, bool invalidate);
00247 #endif
00248 
00253     void suppress_self(Lsa::LsaRef lsar);
00254 
00259     bool suppress_self_check(Lsa::LsaRef lsar);
00260 
00264     Lsa::LsaRef find_lsa_by_net(IPNet<A> net);
00265 
00271     void suppress_queue_lsa(Lsa::LsaRef lsar);
00272 
00277     void suppress_maxage(Lsa::LsaRef lsar);
00278 
00283     void suppress_release_lsa(Lsa::LsaRef lsar);
00284 };
00285 
00286 #endif // __OSPF_EXTERNAL_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations