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 160 : AuthenticationKey() : id(-1), start_time(0) {
26 160 : }
27 :
28 : bool operator<(const AuthenticationKey &rhs) const;
29 : bool operator==(const AuthenticationKey &rhs) const;
30 0 : void Reset() {
31 0 : value = "";
32 0 : start_time = 0;
33 0 : }
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 0 : 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 320 : KeyType key_type() const { return key_type_; }
72 256 : void set_key_type(KeyType in_type) {
73 256 : key_type_ = in_type;
74 256 : }
75 384 : const AuthenticationKeyChain &key_chain() const { return key_chain_; }
76 128 : void set_key_chain(const AuthenticationKeyChain &in_chain) {
77 128 : key_chain_ = in_chain;
78 128 : }
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 935 : explicit BgpFamilyAttributesConfig(const std::string &family)
92 935 : : family(family), loop_count(0), prefix_limit(0), idle_timeout(0) {
93 935 : }
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 160 : int operator()(const BgpFamilyAttributesConfig lhs,
108 : const BgpFamilyAttributesConfig rhs) const {
109 160 : KEY_COMPARE(lhs.family, rhs.family);
110 160 : KEY_COMPARE(lhs.loop_count, rhs.loop_count);
111 160 : KEY_COMPARE(lhs.prefix_limit, rhs.prefix_limit);
112 160 : KEY_COMPARE(lhs.idle_timeout, rhs.idle_timeout);
113 160 : KEY_COMPARE(lhs.default_tunnel_encap_list,
114 : rhs.default_tunnel_encap_list);
115 160 : 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 81711 : const std::string &name() const { return name_; }
164 287 : void set_name(const std::string &name) { name_ = name; }
165 :
166 576 : const std::string &uuid() const { return uuid_; }
167 154 : void set_uuid(const std::string &uuid) { uuid_ = uuid; }
168 :
169 961 : const std::string &instance_name() const { return instance_name_; }
170 588 : void set_instance_name(const std::string &instance_name) {
171 588 : instance_name_ = instance_name;
172 588 : }
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 493 : bool admin_down() const { return admin_down_; }
183 1 : void set_admin_down(bool admin_down) { admin_down_ = admin_down; }
184 :
185 493 : bool passive() const { return passive_; }
186 383 : void set_passive(bool passive) { passive_ = passive; }
187 :
188 201 : bool as_override() const { return as_override_; }
189 235 : void set_as_override(bool as_override) { as_override_ = as_override; }
190 :
191 109 : std::string private_as_action() const { return private_as_action_; }
192 241 : void set_private_as_action(const std::string &private_as_action) {
193 241 : private_as_action_ = private_as_action;
194 241 : }
195 :
196 199 : uint32_t cluster_id() const { return cluster_id_; }
197 12 : void set_cluster_id(uint32_t cluster_id) { cluster_id_ = cluster_id; }
198 :
199 26390 : uint32_t peer_as() const { return peer_as_; }
200 493 : void set_peer_as(uint32_t peer_as) { peer_as_ = peer_as; }
201 :
202 26444 : const IpAddress &peer_address() const { return address_; }
203 482 : 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 365 : void set_peer_identifier(uint32_t identifier) {
208 365 : identifier_ = identifier;
209 365 : }
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 338 : uint16_t port() const { return port_; }
218 466 : void set_port(uint16_t port) { port_ = port; }
219 :
220 10586 : uint16_t source_port() const { return source_port_; }
221 365 : void set_source_port(uint16_t source_port) { source_port_ = source_port; }
222 :
223 95257 : std::string router_type() const { return router_type_; }
224 68 : void set_router_type(const std::string &router_type) {
225 68 : router_type_ = router_type;
226 68 : }
227 :
228 199 : int hold_time() const { return hold_time_; }
229 365 : void set_hold_time(int hold_time) { hold_time_ = hold_time; }
230 :
231 574 : uint8_t loop_count() const { return loop_count_; }
232 246 : void set_loop_count(uint8_t loop_count) { loop_count_ = loop_count; }
233 :
234 46383 : uint32_t local_as() const { return local_as_; }
235 376 : void set_local_as(uint32_t local_as) { local_as_ = local_as; }
236 :
237 21133 : uint32_t local_identifier() const { return local_identifier_; }
238 376 : void set_local_identifier(uint32_t identifier) {
239 376 : local_identifier_ = identifier;
240 376 : }
241 9 : std::string local_identifier_string() const {
242 18 : return Ip4Address(ntohl(local_identifier_)).to_string();
243 : }
244 :
245 128 : const AuthenticationData &auth_data() const {
246 128 : return auth_data_;
247 : }
248 128 : void set_keydata(const AuthenticationData &in_auth_data) {
249 128 : auth_data_ = in_auth_data;
250 128 : }
251 :
252 : AddressFamilyList GetAddressFamilies() const;
253 :
254 50210 : const FamilyAttributesList &family_attributes_list() const {
255 50210 : return family_attributes_list_;
256 : }
257 :
258 526 : void set_family_attributes_list(
259 : const FamilyAttributesList &family_attributes_list) {
260 526 : family_attributes_list_ = family_attributes_list;
261 526 : }
262 :
263 0 : uint64_t last_change_at() const { return last_change_at_; }
264 32 : 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 32 : bool operator!=(const BgpNeighborConfig &rhs) const {
271 32 : return CompareTo(rhs) != 0;
272 : }
273 :
274 202 : const OriginOverrideConfig &origin_override() const {
275 202 : 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 64 : PrefixMatchConfig(std::string to_match, std::string match_type)
353 64 : : prefix_to_match(to_match), prefix_match_type(match_type) {
354 64 : }
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 63 : const std::string &name() const { return name_; }
407 0 : void set_last_change_at(uint64_t tstamp) const { last_change_at_ = tstamp; }
408 0 : void add_term(const RoutingPolicyTermConfig &term) {
409 0 : terms_.push_back(term);
410 0 : }
411 89 : 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 5511 : const std::string &name() const { return name_; }
434 :
435 939 : const NeighborList &neighbor_list() const { return neighbor_list_; }
436 32 : void add_neighbor(const std::string &neighbor) {
437 32 : neighbor_list_.insert(neighbor);
438 32 : }
439 0 : void delete_neighbor(const std::string &neighbor) {
440 0 : neighbor_list_.erase(neighbor);
441 0 : }
442 :
443 7247 : const RouteTargetList &import_list() const { return import_list_; }
444 379 : void set_import_list(const RouteTargetList &import_list) {
445 379 : import_list_ = import_list;
446 379 : }
447 5948 : const RouteTargetList &export_list() const { return export_list_; }
448 181 : void set_export_list(const RouteTargetList &export_list) {
449 181 : export_list_ = export_list;
450 181 : }
451 :
452 141 : bool has_pnf() const { return has_pnf_; }
453 0 : void set_has_pnf(bool has_pnf) { has_pnf_ = has_pnf; }
454 :
455 5692 : const std::string &virtual_network() const { return virtual_network_; }
456 0 : void set_virtual_network(const std::string &virtual_network) {
457 0 : virtual_network_ = virtual_network;
458 0 : }
459 :
460 6835 : int virtual_network_index() const { return virtual_network_index_; }
461 0 : void set_virtual_network_index(int virtual_network_index) {
462 0 : virtual_network_index_ = virtual_network_index;
463 0 : }
464 :
465 182 : bool virtual_network_allow_transit() const {
466 182 : return virtual_network_allow_transit_;
467 : }
468 0 : void set_virtual_network_allow_transit(bool allow_transit) {
469 0 : virtual_network_allow_transit_ = allow_transit;
470 0 : }
471 :
472 182 : bool virtual_network_pbb_evpn_enable() const {
473 182 : return virtual_network_pbb_evpn_enable_;
474 : }
475 0 : void set_virtual_network_pbb_evpn_enable(bool pbb_evpn) {
476 0 : virtual_network_pbb_evpn_enable_ = pbb_evpn;
477 0 : }
478 :
479 :
480 141 : int vxlan_id() const { return vxlan_id_; }
481 0 : void set_vxlan_id(int vxlan_id) { vxlan_id_ = vxlan_id; }
482 :
483 0 : uint64_t last_change_at() const { return last_change_at_; }
484 300 : 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 0 : const ServiceChainList &service_chain_list() const {
490 0 : return service_chain_list_;
491 : }
492 0 : void swap_service_chain_list(ServiceChainList *list) {
493 0 : std::swap(service_chain_list_, *list);
494 0 : }
495 : const ServiceChainConfig *service_chain_info(SCAddress::Family family)
496 : const;
497 :
498 278 : const RoutingPolicyConfigList &routing_policy_list() const {
499 278 : return routing_policies_;
500 : }
501 181 : void swap_routing_policy_list(RoutingPolicyConfigList *list) {
502 181 : std::swap(routing_policies_, *list);
503 181 : }
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 181 : void set_index(int index) { index_ = index; }
510 100 : int index() const { return index_; }
511 :
512 141 : const std::string &routing_instance_vxlan() const {
513 141 : return routing_instance_vxlan_;
514 : }
515 0 : void set_routing_instance_vxlan(const std::string &routing_instance_vxlan) {
516 0 : routing_instance_vxlan_ = routing_instance_vxlan;
517 0 : }
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 20 : const std::string &instance_name() const {
550 20 : return instance_name_;
551 : }
552 :
553 : int CompareTo(const BgpProtocolConfig &rhs) const;
554 :
555 20 : bool admin_down() const { return admin_down_; }
556 40 : void set_admin_down(bool admin_down) { admin_down_ = admin_down; }
557 :
558 20 : uint32_t cluster_id() const { return cluster_id_; }
559 40 : void set_cluster_id(uint32_t cluster_id) { cluster_id_ = cluster_id; }
560 :
561 5131 : uint32_t identifier() const { return identifier_; }
562 20 : void set_identifier(uint32_t identifier) { identifier_ = identifier; }
563 :
564 20 : const std::string& subcluster_name() const { return subcluster_name_; }
565 0 : void set_subcluster_name(const std::string& name) {
566 0 : subcluster_name_ = name;
567 0 : }
568 40 : void reset_subcluster_name() { subcluster_name_ = ""; }
569 :
570 955 : uint32_t subcluster_id() const { return subcluster_id_; }
571 0 : void set_subcluster_id(uint32_t id) {
572 0 : subcluster_id_ = id;
573 0 : }
574 40 : void reset_subcluster_id() { subcluster_id_ = 0; }
575 :
576 5132 : uint32_t autonomous_system() const { return autonomous_system_; }
577 40 : void set_autonomous_system(uint32_t autonomous_system) {
578 40 : autonomous_system_ = autonomous_system;
579 40 : }
580 :
581 20 : uint32_t local_autonomous_system() const {
582 20 : return local_autonomous_system_;
583 : }
584 40 : void set_local_autonomous_system(uint32_t local_autonomous_system) {
585 40 : local_autonomous_system_ = local_autonomous_system;
586 40 : }
587 :
588 20 : int port() const { return port_; }
589 40 : void set_port(int port) { port_ = port; }
590 :
591 1599 : uint32_t hold_time() const { return hold_time_; }
592 40 : 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 20 : 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 60 : BgpGlobalSystemConfig() :
618 60 : last_change_at_(0), gr_time_(0), llgr_time_(0),
619 60 : end_of_rib_timeout_(kEndOfRibTime), gr_enable_(false),
620 60 : gr_bgp_helper_(false), gr_xmpp_helper_(false),
621 60 : enable_4byte_as_(false),
622 60 : bgpaas_port_start_(0),
623 60 : bgpaas_port_end_(0),
624 60 : fc_enabled_(false),
625 60 : nh_check_enabled_(false),
626 60 : always_compare_med_(false),
627 60 : rd_cluster_seed_(0),
628 60 : xmpp_hold_time_(90),
629 60 : all_tags_are_global_(false) {
630 60 : }
631 60 : ~BgpGlobalSystemConfig() { }
632 :
633 422 : uint16_t gr_time() const { return gr_time_; }
634 90 : void set_gr_time(uint16_t gr_time) { gr_time_ = gr_time; }
635 480 : uint32_t llgr_time() const { return llgr_time_; }
636 90 : 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 30 : void set_last_change_at(uint32_t tstamp) const { last_change_at_ = tstamp; }
639 1590 : uint16_t end_of_rib_timeout() const { return end_of_rib_timeout_; }
640 90 : void set_end_of_rib_timeout(uint16_t time) { end_of_rib_timeout_ = time; }
641 293 : bool gr_bgp_helper() const { return gr_bgp_helper_; }
642 60 : void set_gr_bgp_helper(bool helper) { gr_bgp_helper_ = helper; }
643 167 : bool gr_xmpp_helper() const { return gr_xmpp_helper_; }
644 60 : void set_gr_xmpp_helper(bool helper) { gr_xmpp_helper_ = helper; }
645 1481 : bool gr_enable() const { return gr_enable_; }
646 90 : void set_gr_enable(bool enable) { gr_enable_ = enable; }
647 12786 : bool enable_4byte_as() const { return enable_4byte_as_; }
648 0 : void set_enable_4byte_as(bool as_4byte) { enable_4byte_as_ = as_4byte; }
649 36391 : bool fc_enabled() const {
650 36391 : return fc_enabled_;
651 : }
652 24 : void set_fc_enabled(bool enable) {
653 24 : fc_enabled_ = enable;
654 24 : }
655 140 : bool nh_check_enabled() const {
656 140 : return nh_check_enabled_;
657 : }
658 24 : void set_nh_check_enabled(bool enable) {
659 24 : nh_check_enabled_ = enable;
660 24 : }
661 22798 : bool always_compare_med() const { return always_compare_med_; }
662 2 : void set_always_compare_med(bool always_compare_med) {
663 2 : always_compare_med_ = always_compare_med;
664 2 : }
665 2005 : uint8_t xmpp_hold_time() const {
666 2005 : return xmpp_hold_time_;
667 : }
668 0 : void set_xmpp_hold_time(uint8_t hold_time) {
669 0 : xmpp_hold_time_ = hold_time;
670 0 : }
671 9457 : uint16_t rd_cluster_seed() const {
672 9457 : return rd_cluster_seed_;
673 : }
674 0 : void set_rd_cluster_seed(uint16_t seed) {
675 0 : rd_cluster_seed_ = seed;
676 0 : }
677 174 : uint16_t bgpaas_port_start() const { return bgpaas_port_start_; }
678 40 : void set_bgpaas_port_start(uint16_t bgpaas_port_start) {
679 40 : bgpaas_port_start_ = bgpaas_port_start;
680 40 : }
681 174 : uint16_t bgpaas_port_end() const { return bgpaas_port_end_; }
682 40 : void set_bgpaas_port_end(uint16_t bgpaas_port_end) {
683 40 : bgpaas_port_end_ = bgpaas_port_end;
684 40 : }
685 28772 : bool all_tags_are_global() const { return all_tags_are_global_; }
686 0 : void set_all_tags_are_global(bool all_tags_are_global) {
687 0 : all_tags_are_global_ = all_tags_are_global;
688 0 : }
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 40 : BgpGlobalQosConfig() :
714 40 : last_change_at_(0), control_dscp_(0), analytics_dscp_(0) {
715 40 : }
716 40 : ~BgpGlobalQosConfig() { }
717 : uint64_t last_change_at() const { return last_change_at_; }
718 0 : void set_last_change_at(uint64_t tstamp) const { last_change_at_ = tstamp; }
719 181 : uint8_t control_dscp() const { return control_dscp_; }
720 0 : void set_control_dscp(uint8_t value) { control_dscp_ = value; }
721 7 : uint8_t analytics_dscp() const { return analytics_dscp_; }
722 0 : 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 40 : 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 436 : 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__
|