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