xorp

peer_manager.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/peer_manager.hh,v 1.100 2008/10/02 21:57:48 bms Exp $
00022 
00023 #ifndef __OSPF_PEER_MANAGER_HH__
00024 #define __OSPF_PEER_MANAGER_HH__
00025 
00026 template <typename A> class Ospf;
00027 template <typename A> class PeerOut;
00028 template <typename A> class AreaRouter;
00029 template <typename A> class RouteEntry;
00030 template <typename A> class External;
00031 template <typename A> class Vlink;
00032 
00045 template <typename A>
00046 class PeerManager {
00047  public:
00048     PeerManager(Ospf<A>& ospf)
00049     : _ospf(ospf), _next_peerid(OspfTypes::ALLPEERS + 1),
00050       _external(ospf, _areas)
00051     {}
00052 
00053     ~PeerManager();
00054 
00060     bool check_area_type(OspfTypes::AreaID area,
00061              OspfTypes::AreaType area_type);
00062 
00069     bool create_area_router(OspfTypes::AreaID area,
00070                 OspfTypes::AreaType area_type,
00071                 bool permissive = true);
00072 
00073     AreaRouter<A> *get_area_router(OspfTypes::AreaID area);
00074 
00078     bool change_area_router_type(OspfTypes::AreaID area,
00079                  OspfTypes::AreaType area_type);
00080 
00084     bool destroy_area_router(OspfTypes::AreaID area);
00085 
00089     bool area_range_add(OspfTypes::AreaID area, IPNet<A> net, bool advertise);
00090 
00094     bool area_range_delete(OspfTypes::AreaID area, IPNet<A> net);
00095 
00099     bool area_range_change_state(OspfTypes::AreaID area, IPNet<A> net,
00100                  bool advertise);
00101 
00115     bool get_lsa(const OspfTypes::AreaID area, const uint32_t index,
00116          bool& valid, bool& toohigh, bool& self, vector<uint8_t>& lsa);
00117 
00121     bool get_area_list(list<OspfTypes::AreaID>& areas) const;
00122 
00126     bool get_neighbour_list(list<OspfTypes::NeighbourID>& neighbours) const;
00127 
00135     bool get_neighbour_info(OspfTypes::NeighbourID nid,
00136                 NeighbourInfo& ninfo) const;
00137 
00142     OspfTypes::PeerID get_peerid(const string& interface, const string& vif) 
00143     throw(BadPeer);
00144 
00148     bool get_interface_vif_by_peerid(OspfTypes::PeerID peerid,
00149                      string& interface, string& vif) const;
00150 
00158     bool enabled(const string& interface, const string& vif, A address);
00159 
00170     OspfTypes::PeerID create_peer(const string& interface, const string& vif,
00171                   A source,
00172                   OspfTypes::LinkType linktype,
00173                   OspfTypes::AreaID area)
00174     throw(BadPeer);
00175     
00179     bool delete_peer(const OspfTypes::PeerID);
00180 
00184     bool set_state_peer(const OspfTypes::PeerID, bool state);
00185 
00189     bool set_link_status_peer(const OspfTypes::PeerID, bool state);
00190 
00194     bool add_address_peer(const string& interface, const string& vif,
00195               OspfTypes::AreaID area, A addr);
00196 
00200     bool remove_address_peer(const OspfTypes::PeerID, OspfTypes::AreaID area,
00201                  A addr);
00202 
00206     bool set_address_state_peer(const OspfTypes::PeerID,
00207                 OspfTypes::AreaID area, A addr, bool enable);
00208 
00214     bool activate_peer(const string& interface, const string& vif,
00215                OspfTypes::AreaID area);
00216 
00221     bool update_peer(const string& interface, const string& vif,
00222              OspfTypes::AreaID area);
00223 
00228     bool recompute_addresses_peer(const OspfTypes::PeerID,
00229                   OspfTypes::AreaID area);
00230 
00235     void vif_status_change(const string& interface, const string& vif,
00236                bool state);
00237 
00242     void address_status_change(const string& interface, const string& vif,
00243                    A source, bool state);
00244 
00248     bool add_neighbour(const OspfTypes::PeerID,
00249                OspfTypes::AreaID area, A neighbour_address,
00250                OspfTypes::RouterID);
00251 
00255     bool remove_neighbour(const OspfTypes::PeerID,
00256               OspfTypes::AreaID area, A neighbour_address,
00257               OspfTypes::RouterID rid);
00258 
00259 
00263     bool transmit(const string& interface, const string& vif,
00264           A dst, A src,
00265           uint8_t* data, uint32_t len);
00266 
00277     bool receive(const string& interface, const string& vif, A dst, A src,
00278          Packet *packet)
00279     throw(BadPeer);
00280 
00284     bool clear_database();
00285 
00297     bool queue_lsa(const OspfTypes::PeerID peerid,
00298            const OspfTypes::PeerID peer,
00299            OspfTypes::NeighbourID nid, Lsa::LsaRef lsar,
00300            bool &multicast_on_peer);
00301 
00305     bool push_lsas(const OspfTypes::PeerID peerid, const char* msg);
00306 
00310     uint32_t get_interface_id(const OspfTypes::PeerID peerid);
00311 
00315     bool get_attached_routers(const OspfTypes::PeerID peerid,
00316                   OspfTypes::AreaID area,
00317                   list<RouterInfo>& routers);
00318     
00319     /*
00320      * Does this address fall into a configured OSPF network making it
00321      * a valid nexthop address.
00322      *
00323      * @param address under test
00324      *
00325      * @return true if this address falls into a configured OSPF network.
00326      */
00327     bool configured_network(const A address) const;
00328     
00329     /*
00330      * Is this one of the routers interface addresses, used to try and
00331      * detect self-originated LSAs.
00332      *
00333      * @param address under test
00334      *
00335      * @return true if this a known interface address.
00336      */
00337     bool known_interface_address(const A address) const;
00338 
00348     bool neighbours_exchange_or_loading(const OspfTypes::PeerID peerid,
00349                     OspfTypes::AreaID area);
00350 
00363     bool neighbour_at_least_two_way(const OspfTypes::PeerID peerid,
00364                     OspfTypes::AreaID area,
00365                     OspfTypes::RouterID rid, bool& twoway);
00366 
00378     bool get_neighbour_address(const OspfTypes::PeerID peerid,
00379                    OspfTypes::AreaID area,
00380                    OspfTypes::RouterID rid,
00381                    uint32_t interface_id, A& neighbour_address);
00382 
00391     bool on_link_state_request_list(const OspfTypes::PeerID peerid,
00392                     OspfTypes::AreaID area,
00393                     const OspfTypes::NeighbourID nid,
00394                     Lsa::LsaRef lsar);
00395     
00405     bool event_bad_link_state_request(const OspfTypes::PeerID peerid,
00406                       OspfTypes::AreaID area,
00407                       const OspfTypes::NeighbourID nid);
00408 
00420     bool send_lsa(const OspfTypes::PeerID peerid, OspfTypes::AreaID area,
00421           const OspfTypes::NeighbourID nid,
00422           Lsa::LsaRef lsar);
00423 
00433     void adjacency_changed(const OspfTypes::PeerID peerid,
00434                OspfTypes::RouterID rid,
00435                bool up);
00436 
00443     void area_border_router_transition(bool up) const;
00444 
00450     void refresh_router_lsas() const;
00451 
00455     bool create_virtual_peer(OspfTypes::RouterID rid);
00456 
00460     bool delete_virtual_peer(OspfTypes::RouterID rid);
00461 
00467     bool virtual_link_endpoint(OspfTypes::AreaID area) const;
00468 
00474     bool create_virtual_link(OspfTypes::RouterID rid);
00475 
00479     bool transit_area_virtual_link(OspfTypes::RouterID rid,
00480                    OspfTypes::AreaID transit_area);
00481 
00487     bool delete_virtual_link(OspfTypes::RouterID rid);
00488 
00497     void up_virtual_link(OspfTypes::RouterID rid, A source,
00498              uint16_t interface_cost, A destination);
00499 
00503     void down_virtual_link(OspfTypes::RouterID rid);
00504     
00509     bool receive_virtual_link(A dst, A src, Packet *packet);
00510 
00514     uint32_t area_count(OspfTypes::AreaType area_type) const;
00515 
00519     bool internal_router_p() const;
00520 
00524     bool area_border_router_p() const;
00525 
00529     bool backbone_router_p() const;
00530 
00534     bool as_boundary_router_p() const;
00535 
00542     uint32_t compute_options(OspfTypes::AreaType area_type);
00543 
00544     // Config (begin)
00545 
00549     void router_id_changing();
00550 
00551 #if 0
00552 
00555     bool set_options(const PeerID, OspfTypes::AreaID area,
00556              uint32_t options);
00557 #endif
00558 
00562     bool set_interface_address(const OspfTypes::PeerID, A address);
00563 
00567     bool set_hello_interval(const OspfTypes::PeerID, OspfTypes::AreaID area,
00568                 uint16_t hello_interval);
00569 
00573     bool set_router_priority(const OspfTypes::PeerID, OspfTypes::AreaID area,
00574                  uint8_t priority);
00575 
00579     bool set_router_dead_interval(const OspfTypes::PeerID,
00580                   OspfTypes::AreaID area,
00581                   uint32_t router_dead_interval);
00582 
00586     bool set_interface_cost(const OspfTypes::PeerID, OspfTypes::AreaID area,
00587                 uint16_t interface_cost);
00588 
00592     bool set_retransmit_interval(const OspfTypes::PeerID,
00593                  OspfTypes::AreaID area,
00594                  uint16_t retransmit_interval);
00595 
00599     bool set_inftransdelay(const OspfTypes::PeerID, OspfTypes::AreaID area,
00600                uint16_t inftransdelay);
00601 
00614     bool set_simple_authentication_key(const OspfTypes::PeerID peerid,
00615                        OspfTypes::AreaID area,
00616                        const string& password,
00617                        string& error_msg);
00618 
00630     bool delete_simple_authentication_key(const OspfTypes::PeerID peerid,
00631                       OspfTypes::AreaID area,
00632                       string& error_msg);
00633 
00650     bool set_md5_authentication_key(const OspfTypes::PeerID peerid,
00651                     OspfTypes::AreaID area, uint8_t key_id,
00652                     const string& password,
00653                     const TimeVal& start_timeval,
00654                     const TimeVal& end_timeval,
00655                     const TimeVal& max_time_drift,
00656                     string& error_msg);
00657 
00671     bool delete_md5_authentication_key(const OspfTypes::PeerID peerid,
00672                        OspfTypes::AreaID area, uint8_t key_id,
00673                        string& error_msg);
00674 
00678     bool set_passive(const OspfTypes::PeerID, OspfTypes::AreaID area,
00679              bool passive, bool host);
00680 
00685     bool originate_default_route(OspfTypes::AreaID area, bool enable);
00686 
00691     bool stub_default_cost(OspfTypes::AreaID area, uint32_t cost);
00692 
00696     bool summaries(OspfTypes::AreaID area, bool enable);
00697 
00698     // Config (end)
00699 
00703     size_t number_of_areas() const { return _areas.size(); }
00704 
00711     void summary_announce(OspfTypes::AreaID area, IPNet<A> net,
00712               RouteEntry<A>& rt);
00713 
00721     void summary_withdraw(OspfTypes::AreaID area, IPNet<A> net,
00722               RouteEntry<A>& rt);
00723 
00731     void summary_replace(OspfTypes::AreaID area, IPNet<A> net,
00732              RouteEntry<A>& rt,
00733              RouteEntry<A>& previous_rt,
00734              OspfTypes::AreaID previous_area);
00735 
00743     void summary_push(OspfTypes::AreaID area);
00744 
00755     bool area_range_covered(OspfTypes::AreaID area, IPNet<A> net,
00756                 bool& advertise);
00757     
00765     bool area_range_configured(OspfTypes::AreaID area);
00766 
00778     bool external_announce(OspfTypes::AreaID area, Lsa::LsaRef lsar);
00779 
00784     bool external_announce(const IPNet<A>& net, const A& nexthop,
00785                const uint32_t& metric,
00786                const PolicyTags& policytags);
00787 
00792     bool external_withdraw(OspfTypes::AreaID area, Lsa::LsaRef lsar);
00793 
00798     bool external_withdraw(const IPNet<A>& net);
00799 
00803     bool external_announce_complete(OspfTypes::AreaID area);
00804 
00810     void external_push(OspfTypes::AreaID area);
00811 
00815     void external_push_routes();
00816 
00822     void external_suppress_lsas(OspfTypes::AreaID area);
00823 
00827     void routing_recompute_all_areas();
00828 
00832     void routing_recompute_all_transit_areas();
00833 
00834  private:
00835     Ospf<A>& _ospf;         // Reference to the controlling class.
00836     
00837     OspfTypes::PeerID _next_peerid; // Next PeerID to allocate.
00838     map<string, OspfTypes::PeerID> _pmap;// Map from interface/vif to PeerID.
00839 
00840     map<OspfTypes::PeerID, PeerOut<A> *> _peers;    // All of our peers
00841 
00842     map<OspfTypes::AreaID, AreaRouter<A> *> _areas; // All the areas
00843 
00844     External<A> _external;      // Management of AS-External-LSAs.
00845     Vlink<A> _vlink;            // Management of virtual links
00846 
00847     uint32_t    _normal_cnt;        // Number of normal areas.
00848     uint32_t    _stub_cnt;      // Number of stub areas.
00849     uint32_t    _nssa_cnt;      // Number of nssa areas.
00850 
00857     OspfTypes::PeerID create_peerid(const string& interface, const string& vif)
00858     throw(BadPeer);
00859 
00863     void destroy_peerid(const string& interface, const string& vif)
00864     throw(BadPeer);
00865 
00869     bool summary_candidate(OspfTypes::AreaID area, IPNet<A> net,
00870                RouteEntry<A>& rt);
00871 
00875     struct Summary {
00876     Summary()
00877     {}
00878     Summary(OspfTypes::AreaID area, RouteEntry<A>& rt)
00879         : _area(area), _rtentry(rt)
00880     {}
00881 
00882     OspfTypes::AreaID _area;
00883     RouteEntry<A> _rtentry;
00884     };
00885 
00886     map<IPNet<A>, Summary> _summaries;
00887 
00895     void track_area_count(OspfTypes::AreaType area_type, bool up);
00896 };
00897 
00898 #endif // __OSPF_PEER_MANAGER_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations