LCOV - code coverage report
Current view: top level - bgp - bgp_config.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 274 274 100.0 %
Date: 2026-11-09 02:10:49 Functions: 160 160 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : #ifndef SRC_BGP_BGP_CONFIG_H__
       6             : #define SRC_BGP_BGP_CONFIG_H__
       7             : 
       8             : #include <algorithm>
       9             : #include <map>
      10             : #include <set>
      11             : #include <string>
      12             : #include <utility>
      13             : #include <vector>
      14             : 
      15             : #include "base/util.h"
      16             : #include "base/address.h"
      17             : #include "bgp/bgp_common.h"
      18             : #include "bgp/routing-instance/iservice_chain_mgr.h"
      19             : #include "io/tcp_session.h"
      20             : #include "schema/vnc_cfg_types.h"
      21             : 
      22             : class BgpServer;
      23             : 
      24             : struct AuthenticationKey {
      25       69878 :     AuthenticationKey() : id(-1), start_time(0) {
      26       69878 :     }
      27             : 
      28             :     bool operator<(const AuthenticationKey &rhs) const;
      29             :     bool operator==(const AuthenticationKey &rhs) const;
      30           6 :     void Reset() {
      31           6 :         value = "";
      32           6 :         start_time = 0;
      33           6 :     }
      34             : 
      35             :     int id;
      36             :     std::string value;
      37             :     time_t start_time;
      38             : };
      39             : 
      40             : typedef std::vector<AuthenticationKey> AuthenticationKeyChain;
      41             : 
      42             : class AuthenticationData {
      43             : public:
      44             :     enum KeyType {
      45             :         NIL = 0,
      46             :         MD5,
      47             :     };
      48             :     typedef AuthenticationKeyChain::iterator iterator;
      49             :     typedef AuthenticationKeyChain::const_iterator const_iterator;
      50             : 
      51             :     iterator begin() { return key_chain_.begin(); }
      52             :     iterator end() { return key_chain_.end(); }
      53         202 :     const_iterator begin() const { return key_chain_.begin(); }
      54             :     const_iterator end() const { return key_chain_.end(); }
      55             : 
      56             :     AuthenticationData();
      57             :     AuthenticationData(KeyType type, const AuthenticationKeyChain &chain);
      58             : 
      59             :     bool operator==(const AuthenticationData &rhs) const;
      60             :     bool operator<(const AuthenticationData &rhs) const;
      61             :     AuthenticationData &operator=(const AuthenticationData &rhs);
      62             : 
      63             :     const AuthenticationKey *Find(int key_id) const;
      64             :     bool IsMd5() const { return key_type_ == MD5; }
      65             :     bool Empty() const;
      66             :     void Clear();
      67             :     std::string KeyTypeToString() const;
      68             :     static std::string KeyTypeToString(KeyType key_type);
      69             :     void AddKeyToKeyChain(const AuthenticationKey &key);
      70             : 
      71      164036 :     KeyType key_type() const { return key_type_; }
      72      118833 :     void set_key_type(KeyType in_type) {
      73      118833 :         key_type_ = in_type;
      74      118833 :     }
      75      184577 :     const AuthenticationKeyChain &key_chain() const { return key_chain_; }
      76       59521 :     void set_key_chain(const AuthenticationKeyChain &in_chain) {
      77       59521 :         key_chain_ = in_chain;
      78       59521 :     }
      79             :     std::vector<std::string> KeysToString() const;
      80             :     std::vector<std::string> KeysToStringDetail() const;
      81             : 
      82             : private:
      83             :     KeyType key_type_;
      84             :     AuthenticationKeyChain key_chain_;
      85             : };
      86             : 
      87             : //
      88             : // Per address family configuration for a BGP neighbor.
      89             : //
      90             : struct BgpFamilyAttributesConfig {
      91       44989 :     explicit BgpFamilyAttributesConfig(const std::string &family)
      92       44989 :         : family(family), loop_count(0), prefix_limit(0), idle_timeout(0) {
      93       44989 :     }
      94             :     bool operator==(const BgpFamilyAttributesConfig &rhs) const;
      95             : 
      96             :     std::string family;
      97             :     uint8_t loop_count;
      98             :     uint32_t prefix_limit;
      99             :     uint32_t idle_timeout;
     100             :     std::vector<std::string> default_tunnel_encap_list;
     101             : };
     102             : 
     103             : //
     104             : // Comparator for BgpFamilyAttributesConfig.
     105             : //
     106             : struct BgpFamilyAttributesConfigCompare {
     107       28111 :     int operator()(const BgpFamilyAttributesConfig lhs,
     108             :                    const BgpFamilyAttributesConfig rhs) const {
     109       28111 :         KEY_COMPARE(lhs.family, rhs.family);
     110       28085 :         KEY_COMPARE(lhs.loop_count, rhs.loop_count);
     111       28085 :         KEY_COMPARE(lhs.prefix_limit, rhs.prefix_limit);
     112       28037 :         KEY_COMPARE(lhs.idle_timeout, rhs.idle_timeout);
     113       28037 :         KEY_COMPARE(lhs.default_tunnel_encap_list,
     114             :                     rhs.default_tunnel_encap_list);
     115       28031 :         return 0;
     116             :     }
     117             : };
     118             : 
     119             : //
     120             : // The configuration associated with a BGP neighbor.
     121             : //
     122             : // BgpNeighborConfig represents a single session between the local bgp-router
     123             : // and a remote bgp-router.  There may be multiple BgpNeighborConfigs for one
     124             : // BgpIfmapPeeringConfig, though there's typically just one.
     125             : //
     126             : // Each BgpNeighborConfig causes creation of a BgpPeer. BgpPeer has a pointer
     127             : // to the BgpNeighborConfig. This pointer is invalidated and cleared when the
     128             : // BgpPeer is undergoing deletion.
     129             : //
     130             : // BgpNeighborConfigs get created/updated/deleted when the
     131             : // BgpIfmapPeeringConfig is created/updated/deleted.
     132             : //
     133             : // The uuid_ field is used is there are multiple sessions to the same remote
     134             : // bgp-router i.e. there's multiple BgpNeighborConfigs for a BgpPeeringConfig.
     135             : //
     136             : // The name_ field contains the fully qualified name for the peer.  If uuid_
     137             : // is non-empty i.e. there's multiple sessions to the same remote bgp-router,
     138             : // the uuid_ is appended to the remote peer's name to make it unique.
     139             : //
     140             : class BgpNeighborConfig {
     141             : public:
     142             :     typedef std::vector<std::string> AddressFamilyList;
     143             :     typedef std::vector<BgpFamilyAttributesConfig> FamilyAttributesList;
     144             : 
     145             :     enum Type {
     146             :         UNSPECIFIED,
     147             :         IBGP,
     148             :         EBGP,
     149             :     };
     150             : 
     151             :     struct OriginOverrideConfig {
     152             :         OriginOverrideConfig();
     153             :         bool operator<(const OriginOverrideConfig &rhs) const;
     154             : 
     155             :         bool origin_override;
     156             :         std::string origin;
     157             :     };
     158             : 
     159             :     BgpNeighborConfig();
     160             : 
     161             :     void CopyValues(const BgpNeighborConfig &rhs);
     162             : 
     163      125091 :     const std::string &name() const { return name_; }
     164       31238 :     void set_name(const std::string &name) { name_ = name; }
     165             : 
     166       84638 :     const std::string &uuid() const { return uuid_; }
     167       30784 :     void set_uuid(const std::string &uuid) { uuid_ = uuid; }
     168             : 
     169       26368 :     const std::string &instance_name() const { return instance_name_; }
     170       31239 :     void set_instance_name(const std::string &instance_name) {
     171       31239 :         instance_name_ = instance_name;
     172       31239 :     }
     173             : 
     174           2 :     const std::string &group_name() const { return group_name_; }
     175           1 :     void set_group_name(const std::string &group_name) {
     176           1 :         group_name_ = group_name;
     177           1 :     }
     178             : 
     179           2 :     Type peer_type() const { return type_; }
     180           1 :     void set_peer_type(Type type) { type_ = type; }
     181             : 
     182       33937 :     bool admin_down() const { return admin_down_; }
     183         265 :     void set_admin_down(bool admin_down) { admin_down_ = admin_down; }
     184             : 
     185       33841 :     bool passive() const { return passive_; }
     186       29699 :     void set_passive(bool passive) { passive_ = passive; }
     187             : 
     188       20427 :     bool as_override() const { return as_override_; }
     189       29183 :     void set_as_override(bool as_override) { as_override_ = as_override; }
     190             : 
     191       10079 :     std::string private_as_action() const { return private_as_action_; }
     192       29189 :     void set_private_as_action(const std::string &private_as_action) {
     193       29189 :         private_as_action_ = private_as_action;
     194       29189 :     }
     195             : 
     196       20425 :     uint32_t cluster_id() const { return cluster_id_; }
     197          12 :     void set_cluster_id(uint32_t cluster_id) { cluster_id_ = cluster_id; }
     198             : 
     199       44478 :     uint32_t peer_as() const { return peer_as_; }
     200       31144 :     void set_peer_as(uint32_t peer_as) { peer_as_ = peer_as; }
     201             : 
     202       44156 :     const IpAddress &peer_address() const { return address_; }
     203       31133 :     void set_peer_address(const IpAddress &address) { address_ = address; }
     204           4 :     std::string peer_address_string() const { return address_.to_string(); }
     205             : 
     206           5 :     uint32_t peer_identifier() const { return identifier_; }
     207       31080 :     void set_peer_identifier(uint32_t identifier) {
     208       31080 :         identifier_ = identifier;
     209       31080 :     }
     210           7 :     std::string peer_identifier_string() const {
     211          14 :         return Ip4Address(ntohl(identifier_)).to_string();
     212             :     }
     213             : 
     214             :     const IpAddress &gateway_address(Address::Family family) const;
     215             :     void set_gateway_address(Address::Family family, const IpAddress &address);
     216             : 
     217       30752 :     uint16_t port() const { return port_; }
     218       31117 :     void set_port(uint16_t port) { port_ = port; }
     219             : 
     220       20641 :     uint16_t source_port() const { return source_port_; }
     221       31080 :     void set_source_port(uint16_t source_port) { source_port_ = source_port; }
     222             : 
     223      170679 :     std::string router_type() const { return router_type_; }
     224       31083 :     void set_router_type(const std::string &router_type) {
     225       31083 :         router_type_ = router_type;
     226       31083 :     }
     227             : 
     228       20533 :     int hold_time() const { return hold_time_; }
     229       31392 :     void set_hold_time(int hold_time) { hold_time_ = hold_time; }
     230             : 
     231       32600 :     uint8_t loop_count() const { return loop_count_; }
     232       29194 :     void set_loop_count(uint8_t loop_count) { loop_count_ = loop_count; }
     233             : 
     234       75610 :     uint32_t local_as() const { return local_as_; }
     235       31091 :     void set_local_as(uint32_t local_as) { local_as_ = local_as; }
     236             : 
     237       33818 :     uint32_t local_identifier() const { return local_identifier_; }
     238       31078 :     void set_local_identifier(uint32_t identifier) {
     239       31078 :         local_identifier_ = identifier;
     240       31078 :     }
     241           9 :     std::string local_identifier_string() const {
     242          18 :         return Ip4Address(ntohl(local_identifier_)).to_string();
     243             :     }
     244             : 
     245       50986 :     const AuthenticationData &auth_data() const {
     246       50986 :         return auth_data_;
     247             :     }
     248       59312 :     void set_keydata(const AuthenticationData &in_auth_data) {
     249       59312 :         auth_data_ = in_auth_data;
     250       59312 :     }
     251             : 
     252             :     AddressFamilyList GetAddressFamilies() const;
     253             : 
     254       82071 :     const FamilyAttributesList &family_attributes_list() const {
     255       82071 :         return family_attributes_list_;
     256             :     }
     257             : 
     258       32777 :     void set_family_attributes_list(
     259             :         const FamilyAttributesList &family_attributes_list) {
     260       32777 :         family_attributes_list_ = family_attributes_list;
     261       32777 :     }
     262             : 
     263           5 :     uint64_t last_change_at() const { return last_change_at_; }
     264       16900 :     void set_last_change_at(uint64_t tstamp) const { last_change_at_ = tstamp; }
     265             : 
     266             :     std::string AuthKeyTypeToString() const;
     267             :     std::vector<std::string> AuthKeysToString() const;
     268             : 
     269             :     int CompareTo(const BgpNeighborConfig &rhs) const;
     270       21662 :     bool operator!=(const BgpNeighborConfig &rhs) const {
     271       21662 :         return CompareTo(rhs) != 0;
     272             :     }
     273             : 
     274       20428 :     const OriginOverrideConfig &origin_override() const {
     275       20428 :         return origin_override_;
     276             :     }
     277             :     void SetOriginOverride(bool origin_override, std::string origin);
     278             : 
     279             : private:
     280             :     std::string name_;
     281             :     std::string uuid_;
     282             :     std::string instance_name_;
     283             :     std::string group_name_;
     284             :     Type type_;
     285             :     std::string router_type_;
     286             :     bool admin_down_;
     287             :     bool passive_;
     288             :     bool as_override_;
     289             :     std::string private_as_action_;
     290             :     uint32_t cluster_id_;
     291             :     uint32_t peer_as_;
     292             :     uint32_t identifier_;
     293             :     IpAddress address_;
     294             :     IpAddress inet_gateway_address_;
     295             :     IpAddress inet6_gateway_address_;
     296             :     uint16_t port_;
     297             :     uint16_t source_port_;
     298             :     TcpSession::Endpoint remote_endpoint_;
     299             :     int hold_time_;
     300             :     uint8_t loop_count_;
     301             :     uint32_t local_as_;
     302             :     uint32_t local_identifier_;
     303             :     mutable uint64_t last_change_at_;
     304             :     AuthenticationData auth_data_;
     305             :     FamilyAttributesList family_attributes_list_;
     306             :     OriginOverrideConfig origin_override_;
     307             : 
     308             :     DISALLOW_COPY_AND_ASSIGN(BgpNeighborConfig);
     309             : };
     310             : 
     311             : //
     312             : // AggregateRouteConfig represents the route-aggregation config on a
     313             : // routing instance. This config is derived from routing-instance to
     314             : // route-aggregate link in schema. "route-aggregate" is a config object
     315             : // containing information about prefix to aggregate and nexthop.
     316             : // Routing instance may refer to multiple route-aggregate config object hence
     317             : // a list of AggregateRouteConfig is maintained in BgpInstanceConfig
     318             : // This list is not an ordered list.
     319             : //
     320             : struct AggregateRouteConfig {
     321             :     IpAddress aggregate;
     322             :     int prefix_length;
     323             :     IpAddress nexthop;
     324             : };
     325             : 
     326             : struct ServiceChainConfig {
     327             :     SCAddress::Family family;
     328             :     std::string routing_instance;
     329             :     std::vector<std::string> prefix;
     330             :     std::string service_chain_address;
     331             :     std::string service_instance;
     332             :     std::string source_routing_instance;
     333             :     std::string service_chain_id;
     334             :     bool sc_head;
     335             :     bool retain_as_path;
     336             : };
     337             : 
     338             : struct StaticRouteConfig {
     339             :     bool operator<(const StaticRouteConfig &rhs) const;
     340             :     IpAddress address;
     341             :     int prefix_length;
     342             :     IpAddress nexthop;
     343             :     std::vector<std::string> route_targets;
     344             :     std::vector<std::string> communities;
     345             : };
     346             : 
     347             : typedef std::vector<as_t> AsnList;
     348             : typedef std::vector<std::string> CommunityList;
     349             : typedef std::vector<std::string> ProtocolList;
     350             : 
     351             : struct PrefixMatchConfig {
     352         292 :     PrefixMatchConfig(std::string to_match, std::string match_type)
     353         292 :         : prefix_to_match(to_match), prefix_match_type(match_type) {
     354         292 :     }
     355             :     std::string prefix_to_match;
     356             :     std::string prefix_match_type;
     357             : };
     358             : 
     359             : typedef std::vector<PrefixMatchConfig> PrefixMatchConfigList;
     360             : 
     361             : struct RoutingPolicyMatchConfig {
     362             :     ProtocolList protocols_match;
     363             :     PrefixMatchConfigList prefixes_to_match;
     364             :     CommunityList community_match;
     365             :     bool community_match_all;
     366             :     CommunityList ext_community_match;
     367             :     bool ext_community_match_all;
     368             :     std::string ToString() const;
     369             : };
     370             : 
     371             : struct ActionUpdate {
     372             :     AsnList aspath_expand;
     373             :     CommunityList community_set;
     374             :     CommunityList community_add;
     375             :     CommunityList community_remove;
     376             :     CommunityList ext_community_set;
     377             :     CommunityList ext_community_add;
     378             :     CommunityList ext_community_remove;
     379             :     uint32_t local_pref;
     380             :     uint32_t med;
     381             : };
     382             : 
     383             : struct RoutingPolicyActionConfig {
     384             :     enum ActionType {
     385             :         ACCEPT,
     386             :         REJECT,
     387             :         NEXT_TERM
     388             :     };
     389             :     ActionUpdate update;
     390             :     ActionType action;
     391             :     std::string ToString() const;
     392             : };
     393             : 
     394             : struct RoutingPolicyTermConfig {
     395             :     RoutingPolicyMatchConfig match;
     396             :     RoutingPolicyActionConfig action;
     397             : };
     398             : 
     399             : // Route Policy configuration.
     400             : class BgpRoutingPolicyConfig {
     401             : public:
     402             :     typedef std::vector<RoutingPolicyTermConfig> RoutingPolicyTermList;
     403             :     explicit BgpRoutingPolicyConfig(const std::string &name);
     404             :     virtual ~BgpRoutingPolicyConfig();
     405             : 
     406         767 :     const std::string &name() const { return name_; }
     407         439 :     void set_last_change_at(uint64_t tstamp) const { last_change_at_ = tstamp; }
     408         477 :     void add_term(const RoutingPolicyTermConfig &term) {
     409         477 :         terms_.push_back(term);
     410         477 :     }
     411        1163 :     const RoutingPolicyTermList &terms() const { return terms_;}
     412             :     void Clear();
     413             : 
     414             : private:
     415             :     std::string name_;
     416             :     mutable uint64_t last_change_at_;
     417             :     RoutingPolicyTermList terms_;
     418             :     DISALLOW_COPY_AND_ASSIGN(BgpRoutingPolicyConfig);
     419             : };
     420             : 
     421             : // Instance configuration.
     422             : class BgpInstanceConfig {
     423             : public:
     424             :     typedef std::set<std::string> NeighborList;
     425             :     typedef std::set<std::string> RouteTargetList;
     426             :     typedef std::set<StaticRouteConfig> StaticRouteList;
     427             :     typedef std::vector<ServiceChainConfig> ServiceChainList;
     428             :     typedef std::vector<AggregateRouteConfig> AggregateRouteList;
     429             : 
     430             :     explicit BgpInstanceConfig(const std::string &name);
     431             :     virtual ~BgpInstanceConfig();
     432             : 
     433      453683 :     const std::string &name() const { return name_; }
     434             : 
     435       51697 :     const NeighborList &neighbor_list() const { return neighbor_list_; }
     436        9417 :     void add_neighbor(const std::string &neighbor) {
     437        9417 :         neighbor_list_.insert(neighbor);
     438        9417 :     }
     439        6719 :     void delete_neighbor(const std::string &neighbor) {
     440        6719 :         neighbor_list_.erase(neighbor);
     441        6719 :     }
     442             : 
     443      513158 :     const RouteTargetList &import_list() const { return import_list_; }
     444      154894 :     void set_import_list(const RouteTargetList &import_list) {
     445      154894 :         import_list_ = import_list;
     446      154894 :     }
     447      482645 :     const RouteTargetList &export_list() const { return export_list_; }
     448      124446 :     void set_export_list(const RouteTargetList &export_list) {
     449      124446 :         export_list_ = export_list;
     450      124446 :     }
     451             : 
     452       69807 :     bool has_pnf() const { return has_pnf_; }
     453        4221 :     void set_has_pnf(bool has_pnf) { has_pnf_ = has_pnf; }
     454             : 
     455      240847 :     const std::string &virtual_network() const { return virtual_network_; }
     456       74292 :     void set_virtual_network(const std::string &virtual_network) {
     457       74292 :         virtual_network_ = virtual_network;
     458       74292 :     }
     459             : 
     460      259433 :     int virtual_network_index() const { return virtual_network_index_; }
     461       74292 :     void set_virtual_network_index(int virtual_network_index) {
     462       74292 :         virtual_network_index_ = virtual_network_index;
     463       74292 :     }
     464             : 
     465       88433 :     bool virtual_network_allow_transit() const {
     466       88433 :         return virtual_network_allow_transit_;
     467             :     }
     468       74292 :     void set_virtual_network_allow_transit(bool allow_transit) {
     469       74292 :         virtual_network_allow_transit_ = allow_transit;
     470       74292 :     }
     471             : 
     472       88432 :     bool virtual_network_pbb_evpn_enable() const {
     473       88432 :         return virtual_network_pbb_evpn_enable_;
     474             :     }
     475       74292 :     void set_virtual_network_pbb_evpn_enable(bool pbb_evpn) {
     476       74292 :         virtual_network_pbb_evpn_enable_ = pbb_evpn;
     477       74292 :     }
     478             : 
     479             : 
     480       69817 :     int vxlan_id() const { return vxlan_id_; }
     481       74292 :     void set_vxlan_id(int vxlan_id) { vxlan_id_ = vxlan_id; }
     482             : 
     483         220 :     uint64_t last_change_at() const { return last_change_at_; }
     484      161085 :     void set_last_change_at(uint64_t tstamp) const { last_change_at_ = tstamp; }
     485             : 
     486             :     const StaticRouteList &static_routes(Address::Family family) const;
     487             :     void swap_static_routes(Address::Family family, StaticRouteList *list);
     488             : 
     489         220 :     const ServiceChainList &service_chain_list() const {
     490         220 :         return service_chain_list_;
     491             :     }
     492        4221 :     void swap_service_chain_list(ServiceChainList *list) {
     493        4221 :         std::swap(service_chain_list_, *list);
     494        4221 :     }
     495             :     const ServiceChainConfig *service_chain_info(SCAddress::Family family)
     496             :         const;
     497             : 
     498       57944 :     const RoutingPolicyConfigList &routing_policy_list() const {
     499       57944 :         return routing_policies_;
     500             :     }
     501      124446 :     void swap_routing_policy_list(RoutingPolicyConfigList *list) {
     502      124446 :         std::swap(routing_policies_, *list);
     503      124446 :     }
     504             : 
     505             :     const AggregateRouteList &aggregate_routes(Address::Family family) const;
     506             :     void swap_aggregate_routes(Address::Family family,
     507             :                                AggregateRouteList *list);
     508             :     void Clear();
     509      124446 :     void set_index(int index) { index_ = index; }
     510       51120 :     int index() const { return index_; }
     511             : 
     512       69583 :     const std::string &routing_instance_vxlan() const {
     513       69583 :         return routing_instance_vxlan_;
     514             :     }
     515       74292 :     void set_routing_instance_vxlan(const std::string &routing_instance_vxlan) {
     516       74292 :         routing_instance_vxlan_ = routing_instance_vxlan;
     517       74292 :     }
     518             : 
     519             : private:
     520             :     friend class BgpInstanceConfigTest;
     521             : 
     522             :     std::string name_;
     523             :     NeighborList neighbor_list_;
     524             :     RouteTargetList import_list_;
     525             :     RouteTargetList export_list_;
     526             :     bool has_pnf_;
     527             :     std::string virtual_network_;
     528             :     int virtual_network_index_;
     529             :     bool virtual_network_allow_transit_;
     530             :     bool virtual_network_pbb_evpn_enable_;
     531             :     int index_;
     532             :     int vxlan_id_;
     533             :     mutable uint64_t last_change_at_;
     534             :     StaticRouteList inet_static_routes_;
     535             :     StaticRouteList inet6_static_routes_;
     536             :     AggregateRouteList inet_aggregate_routes_;
     537             :     AggregateRouteList inet6_aggregate_routes_;
     538             :     ServiceChainList service_chain_list_;
     539             :     RoutingPolicyConfigList routing_policies_;
     540             :     std::string routing_instance_vxlan_;
     541             : 
     542             :     DISALLOW_COPY_AND_ASSIGN(BgpInstanceConfig);
     543             : };
     544             : 
     545             : // Local configuration.
     546             : class BgpProtocolConfig {
     547             : public:
     548             :     explicit BgpProtocolConfig(const std::string &instance_name);
     549        9050 :     const std::string &instance_name() const {
     550        9050 :         return instance_name_;
     551             :     }
     552             : 
     553             :     int CompareTo(const BgpProtocolConfig &rhs) const;
     554             : 
     555        7671 :     bool admin_down() const { return admin_down_; }
     556       15702 :     void set_admin_down(bool admin_down) { admin_down_ = admin_down; }
     557             : 
     558        7671 :     uint32_t cluster_id() const { return cluster_id_; }
     559       15702 :     void set_cluster_id(uint32_t cluster_id) { cluster_id_ = cluster_id; }
     560             : 
     561      146903 :     uint32_t identifier() const { return identifier_; }
     562        7670 :     void set_identifier(uint32_t identifier) { identifier_ = identifier; }
     563             : 
     564        2694 :     const std::string& subcluster_name() const { return subcluster_name_; }
     565          16 :     void set_subcluster_name(const std::string& name) {
     566          16 :         subcluster_name_ = name;
     567          16 :     }
     568       15702 :     void reset_subcluster_name() { subcluster_name_ = ""; }
     569             : 
     570       61332 :     uint32_t subcluster_id() const { return subcluster_id_; }
     571          16 :     void set_subcluster_id(uint32_t id) {
     572          16 :         subcluster_id_ = id;
     573          16 :     }
     574       15702 :     void reset_subcluster_id() { subcluster_id_ = 0; }
     575             : 
     576      146903 :     uint32_t autonomous_system() const { return autonomous_system_; }
     577       15702 :     void set_autonomous_system(uint32_t autonomous_system) {
     578       15702 :         autonomous_system_ = autonomous_system;
     579       15702 :     }
     580             : 
     581        7671 :     uint32_t local_autonomous_system() const {
     582        7671 :         return local_autonomous_system_;
     583             :     }
     584       15702 :     void set_local_autonomous_system(uint32_t local_autonomous_system) {
     585       15702 :         local_autonomous_system_ = local_autonomous_system;
     586       15702 :     }
     587             : 
     588        7671 :     int port() const { return port_; }
     589       15702 :     void set_port(int port) { port_ = port; }
     590             : 
     591        7678 :     uint32_t hold_time() const { return hold_time_; }
     592       15702 :     void set_hold_time(uint32_t hold_time) { hold_time_ = hold_time; }
     593             : 
     594             :     uint64_t last_change_at() const { return last_change_at_; }
     595        9050 :     void set_last_change_at(uint64_t tstamp) const { last_change_at_ = tstamp; }
     596             : 
     597             : private:
     598             :     std::string instance_name_;
     599             :     bool admin_down_;
     600             :     uint32_t cluster_id_;
     601             :     uint32_t autonomous_system_;
     602             :     uint32_t local_autonomous_system_;
     603             :     uint32_t identifier_;
     604             :     std::string subcluster_name_;
     605             :     uint32_t subcluster_id_;
     606             :     int port_;
     607             :     uint32_t hold_time_;
     608             :     mutable uint64_t last_change_at_;
     609             : 
     610             :     DISALLOW_COPY_AND_ASSIGN(BgpProtocolConfig);
     611             : };
     612             : 
     613             : // Global system configuration.
     614             : class BgpGlobalSystemConfig {
     615             : public:
     616             :     static const int kEndOfRibTime = 300; // seconds
     617       19870 :     BgpGlobalSystemConfig() :
     618       19870 :             last_change_at_(0), gr_time_(0), llgr_time_(0),
     619       19870 :             end_of_rib_timeout_(kEndOfRibTime), gr_enable_(false),
     620       19870 :             gr_bgp_helper_(false), gr_xmpp_helper_(false),
     621       19870 :             enable_4byte_as_(false),
     622       19870 :             bgpaas_port_start_(0),
     623       19870 :             bgpaas_port_end_(0),
     624       19870 :             fc_enabled_(false),
     625       19870 :             nh_check_enabled_(false),
     626       19870 :             always_compare_med_(false),
     627       19870 :             rd_cluster_seed_(0),
     628       19870 :             xmpp_hold_time_(90),
     629       19870 :             all_tags_are_global_(false) {
     630       19870 :     }
     631       19870 :     ~BgpGlobalSystemConfig() { }
     632             : 
     633        9334 :     uint16_t gr_time() const { return gr_time_; }
     634        2035 :     void set_gr_time(uint16_t gr_time) { gr_time_ = gr_time; }
     635       12430 :     uint32_t llgr_time() const { return llgr_time_; }
     636        2035 :     void set_llgr_time(uint64_t llgr_time) { llgr_time_ = llgr_time; }
     637           2 :     uint32_t last_change_at() const { return last_change_at_; }
     638         840 :     void set_last_change_at(uint32_t tstamp) const { last_change_at_ = tstamp; }
     639       47658 :     uint16_t end_of_rib_timeout() const { return end_of_rib_timeout_; }
     640        1593 :     void set_end_of_rib_timeout(uint16_t time) { end_of_rib_timeout_ = time; }
     641        7650 :     bool gr_bgp_helper() const { return gr_bgp_helper_; }
     642        1122 :     void set_gr_bgp_helper(bool helper) { gr_bgp_helper_ = helper; }
     643        2768 :     bool gr_xmpp_helper() const { return gr_xmpp_helper_; }
     644        1028 :     void set_gr_xmpp_helper(bool helper) { gr_xmpp_helper_ = helper; }
     645       58947 :     bool gr_enable() const { return gr_enable_; }
     646        1595 :     void set_gr_enable(bool enable) { gr_enable_ = enable; }
     647      223748 :     bool enable_4byte_as() const { return enable_4byte_as_; }
     648         566 :     void set_enable_4byte_as(bool as_4byte) { enable_4byte_as_ = as_4byte; }
     649      648247 :     bool fc_enabled() const {
     650      648247 :         return fc_enabled_;
     651             :     }
     652          58 :     void set_fc_enabled(bool enable) {
     653          58 :         fc_enabled_ = enable;
     654          58 :     }
     655        2961 :     bool nh_check_enabled() const {
     656        2961 :         return nh_check_enabled_;
     657             :     }
     658          28 :     void set_nh_check_enabled(bool enable) {
     659          28 :         nh_check_enabled_ = enable;
     660          28 :     }
     661     2356404 :     bool always_compare_med() const { return always_compare_med_; }
     662          12 :     void set_always_compare_med(bool always_compare_med) {
     663          12 :         always_compare_med_ = always_compare_med;
     664          12 :     }
     665       10328 :     uint8_t xmpp_hold_time() const {
     666       10328 :         return xmpp_hold_time_;
     667             :     }
     668          38 :     void set_xmpp_hold_time(uint8_t hold_time) {
     669          38 :         xmpp_hold_time_ = hold_time;
     670          38 :     }
     671       28657 :     uint16_t rd_cluster_seed() const {
     672       28657 :         return rd_cluster_seed_;
     673             :     }
     674          72 :     void set_rd_cluster_seed(uint16_t seed) {
     675          72 :         rd_cluster_seed_ = seed;
     676          72 :     }
     677        4314 :     uint16_t bgpaas_port_start() const { return bgpaas_port_start_; }
     678        1352 :     void set_bgpaas_port_start(uint16_t bgpaas_port_start) {
     679        1352 :         bgpaas_port_start_ = bgpaas_port_start;
     680        1352 :     }
     681        4314 :     uint16_t bgpaas_port_end() const { return bgpaas_port_end_; }
     682        1352 :     void set_bgpaas_port_end(uint16_t bgpaas_port_end) {
     683        1352 :         bgpaas_port_end_ = bgpaas_port_end;
     684        1352 :     }
     685      465728 :     bool all_tags_are_global() const { return all_tags_are_global_; }
     686           8 :     void set_all_tags_are_global(bool all_tags_are_global) {
     687           8 :         all_tags_are_global_ = all_tags_are_global;
     688           8 :     }
     689             : private:
     690             :     mutable uint64_t last_change_at_;
     691             :     uint16_t gr_time_;
     692             :     uint32_t llgr_time_;
     693             :     uint16_t end_of_rib_timeout_;
     694             :     bool gr_enable_;
     695             :     bool gr_bgp_helper_;
     696             :     bool gr_xmpp_helper_;
     697             :     bool enable_4byte_as_;
     698             :     uint16_t bgpaas_port_start_;
     699             :     uint16_t bgpaas_port_end_;
     700             :     bool fc_enabled_;
     701             :     bool nh_check_enabled_;
     702             :     bool always_compare_med_;
     703             :     uint16_t rd_cluster_seed_;
     704             :     uint8_t xmpp_hold_time_;
     705             :     bool all_tags_are_global_;
     706             : 
     707             :     DISALLOW_COPY_AND_ASSIGN(BgpGlobalSystemConfig);
     708             : };
     709             : 
     710             : // Global Qos configuration.
     711             : class BgpGlobalQosConfig {
     712             : public:
     713       17792 :     BgpGlobalQosConfig() :
     714       17792 :         last_change_at_(0), control_dscp_(0), analytics_dscp_(0) {
     715       17792 :     }
     716       17792 :     ~BgpGlobalQosConfig() { }
     717             :     uint64_t last_change_at() const { return last_change_at_; }
     718           9 :     void set_last_change_at(uint64_t tstamp) const { last_change_at_ = tstamp; }
     719        8740 :     uint8_t control_dscp() const { return control_dscp_; }
     720          18 :     void set_control_dscp(uint8_t value) { control_dscp_ = value; }
     721          23 :     uint8_t analytics_dscp() const { return analytics_dscp_; }
     722          12 :     void set_analytics_dscp(uint8_t value) { analytics_dscp_ = value; }
     723             : 
     724             : private:
     725             :     mutable uint64_t last_change_at_;
     726             :     uint8_t control_dscp_;
     727             :     uint8_t analytics_dscp_;
     728             : 
     729             :     DISALLOW_COPY_AND_ASSIGN(BgpGlobalQosConfig);
     730             : };
     731             : 
     732             : /*
     733             :  * BgpConfigManager defines the interface between the BGP server and the
     734             :  * configuration sub-system. Multiple configuration sub-systems are
     735             :  * supported.
     736             :  */
     737             : class BgpConfigManager {
     738             : public:
     739             :     enum EventType {
     740             :         CFG_NONE,
     741             :         CFG_ADD,
     742             :         CFG_CHANGE,
     743             :         CFG_DELETE
     744             :     };
     745             : 
     746             :     typedef boost::function<void(const BgpProtocolConfig *, EventType)>
     747             :         BgpProtocolObserver;
     748             :     typedef boost::function<void(const BgpInstanceConfig *, EventType)>
     749             :         BgpInstanceObserver;
     750             :     typedef boost::function<void(const BgpNeighborConfig *, EventType)>
     751             :         BgpNeighborObserver;
     752             :     typedef boost::function<void(const BgpRoutingPolicyConfig *, EventType)>
     753             :         BgpRoutingPolicyObserver;
     754             :     typedef boost::function<void(const BgpGlobalSystemConfig *, EventType)>
     755             :         BgpGlobalSystemConfigObserver;
     756             :     typedef boost::function<void(const BgpGlobalQosConfig *, EventType)>
     757             :         BgpGlobalQosConfigObserver;
     758             : 
     759             :     struct Observers {
     760             :         BgpProtocolObserver protocol;
     761             :         BgpInstanceObserver instance;
     762             :         BgpNeighborObserver neighbor;
     763             :         BgpRoutingPolicyObserver policy;
     764             :         BgpGlobalSystemConfigObserver system;
     765             :         BgpGlobalQosConfigObserver qos;
     766             :     };
     767             : 
     768             :     typedef std::map<std::string, BgpRoutingPolicyConfig *> RoutingPolicyMap;
     769             :     typedef std::pair<RoutingPolicyMap::const_iterator,
     770             :             RoutingPolicyMap::const_iterator> RoutingPolicyMapRange;
     771             :     typedef std::map<std::string, BgpInstanceConfig *> InstanceMap;
     772             :     typedef std::pair<InstanceMap::const_iterator,
     773             :             InstanceMap::const_iterator> InstanceMapRange;
     774             :     typedef std::map<std::string, BgpNeighborConfig *> NeighborMap;
     775             :     typedef std::pair<NeighborMap::const_iterator,
     776             :             NeighborMap::const_iterator> NeighborMapRange;
     777             : 
     778             :     static const char *kMasterNetwork;
     779             :     static const char *kMasterInstance;
     780             :     static const char *kFabricInstance;
     781             :     static const int kDefaultPort;
     782             :     static const uint32_t kDefaultAutonomousSystem;
     783             : 
     784             :     explicit BgpConfigManager(BgpServer *server);
     785             :     virtual ~BgpConfigManager();
     786             : 
     787       11821 :     void RegisterObservers(const Observers &obs) { obs_.push_back(obs); }
     788             : 
     789             :     virtual void Terminate() = 0;
     790             :     virtual const std::string &localname() const = 0;
     791             : 
     792             :     virtual RoutingPolicyMapRange RoutingPolicyMapItems(
     793             :         const std::string &start_policy = std::string()) const = 0;
     794             :     virtual InstanceMapRange InstanceMapItems(
     795             :         const std::string &start_instance = std::string()) const = 0;
     796             :     virtual NeighborMapRange NeighborMapItems(
     797             :         const std::string &instance_name) const = 0;
     798             : 
     799             :     virtual int NeighborCount(const std::string &instance_name) const = 0;
     800             : 
     801             :     virtual void ResetRoutingInstanceIndexBit(int index) = 0;
     802             :     virtual const BgpInstanceConfig *FindInstance(
     803             :         const std::string &name) const = 0;
     804             :     virtual const BgpRoutingPolicyConfig *FindRoutingPolicy(
     805             :         const std::string &name) const = 0;
     806             :     virtual const BgpProtocolConfig *GetProtocolConfig(
     807             :         const std::string &instance_name) const = 0;
     808             :     virtual const BgpNeighborConfig *FindNeighbor(
     809             :         const std::string &instance_name, const std::string &name) const = 0;
     810             : 
     811             :     // Invoke registered observer
     812             :     template <typename BgpConfigObject>
     813             :     void Notify(const BgpConfigObject *, EventType);
     814             : 
     815      114148 :     const BgpServer *server() { return server_; }
     816             : 
     817             : private:
     818             :     BgpServer *server_;
     819             :     std::vector<Observers> obs_;
     820             : 
     821             :     DISALLOW_COPY_AND_ASSIGN(BgpConfigManager);
     822             : };
     823             : 
     824             : #endif  // SRC_BGP_BGP_CONFIG_H__

Generated by: LCOV version 1.14