Line data Source code
1 : /*
2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3 : * Copyright Contributors to the OpenSDN project
4 : */
5 :
6 : #include "bgp/bgp_table.h"
7 :
8 : #include <boost/foreach.hpp>
9 :
10 : #include "sandesh/sandesh_trace.h"
11 : #include "base/task_annotations.h"
12 : #include "bgp/bgp_log.h"
13 : #include "bgp/bgp_membership.h"
14 : #include "bgp/bgp_peer.h"
15 : #include "bgp/bgp_peer_types.h"
16 : #include "bgp/bgp_ribout.h"
17 : #include "bgp/bgp_ribout_updates.h"
18 : #include "bgp/bgp_route.h"
19 : #include "bgp/bgp_server.h"
20 : #include "bgp/bgp_update.h"
21 : #include "bgp/inet/inet_table.h"
22 : #include "bgp/routing-instance/iroute_aggregator.h"
23 : #include "bgp/routing-instance/path_resolver.h"
24 : #include "bgp/routing-instance/routing_instance.h"
25 : #include "bgp/routing-instance/rtarget_group_mgr.h"
26 : #include "bgp/tunnel_encap/tunnel_encap.h"
27 : #include "net/community_type.h"
28 :
29 : using std::make_pair;
30 : using std::string;
31 :
32 : class BgpTable::DeleteActor : public LifetimeActor {
33 : public:
34 288605 : explicit DeleteActor(BgpTable *table)
35 288605 : : LifetimeActor(table->rtinstance_->server()->lifetime_manager()),
36 288605 : table_(table) {
37 288604 : }
38 577214 : virtual ~DeleteActor() {
39 577214 : }
40 294995 : virtual bool MayDelete() const {
41 294995 : return table_->MayDelete();
42 : }
43 :
44 288607 : virtual void Shutdown() {
45 288607 : table_->Shutdown();
46 288607 : }
47 :
48 : // Make sure that all notifications have been processed and all db
49 : // state have been cleared for all partitions, before we inform the
50 : // parent instance that this table deletion process is complete.
51 288607 : virtual void Destroy() {
52 288607 : table_->rtinstance_->DestroyDBTable(table_);
53 288607 : }
54 :
55 : private:
56 : BgpTable *table_;
57 : };
58 :
59 296880 : BgpTable::BgpTable(DB *db, const string &name)
60 : : RouteTable(db, name),
61 296855 : rtinstance_(NULL),
62 296855 : path_resolver_(NULL),
63 296880 : instance_delete_ref_(this, NULL) {
64 296889 : primary_path_count_ = 0;
65 296982 : secondary_path_count_ = 0;
66 296978 : infeasible_path_count_ = 0;
67 296954 : stale_path_count_ = 0;
68 296983 : llgr_stale_path_count_ = 0;
69 296980 : }
70 :
71 : //
72 : // Remove the table from the instance dependents before attempting to
73 : // destroy the DeleteActor which can have its Delete() method be called
74 : // via the reference.
75 : //
76 296990 : BgpTable::~BgpTable() {
77 296990 : assert(path_resolver_ == NULL),
78 296990 : instance_delete_ref_.Reset(NULL);
79 296990 : }
80 :
81 288601 : void BgpTable::set_routing_instance(RoutingInstance *rtinstance) {
82 288601 : rtinstance_ = rtinstance;
83 288601 : assert(rtinstance);
84 288601 : deleter_.reset(new DeleteActor(this));
85 288602 : instance_delete_ref_.Reset(rtinstance->deleter());
86 288604 : }
87 :
88 3039560 : BgpServer *BgpTable::server() {
89 3039560 : return rtinstance_->server();
90 : }
91 :
92 1768785 : const BgpServer *BgpTable::server() const {
93 1768785 : return rtinstance_->server();
94 : }
95 :
96 : //
97 : // Find the RibOut for the given RibExportPolicy.
98 : //
99 60 : RibOut *BgpTable::RibOutFind(const RibExportPolicy &policy) {
100 60 : RibOutMap::iterator loc = ribout_map_.find(policy);
101 60 : return (loc != ribout_map_.end()) ? loc->second : NULL;
102 : }
103 :
104 : //
105 : // Find or create the RibOut associated with the given RibExportPolicy.
106 : // If a new RibOut is created, an entry for the pair gets added to the
107 : // RibOutMap.
108 : //
109 83020 : RibOut *BgpTable::RibOutLocate(BgpUpdateSender *sender,
110 : const RibExportPolicy &policy) {
111 83020 : RibOutMap::iterator loc = ribout_map_.find(policy);
112 83020 : if (loc == ribout_map_.end()) {
113 35027 : RibOut *ribout = new RibOut(this, sender, policy);
114 35027 : ribout_map_.insert(make_pair(policy, ribout));
115 35027 : return ribout;
116 : }
117 47993 : return loc->second;
118 : }
119 :
120 : //
121 : // Delete the entry corresponding to the given RibExportPolicy from the
122 : // RibOutMap. Also deletes the RibOut itself.
123 : //
124 34995 : void BgpTable::RibOutDelete(const RibExportPolicy &policy) {
125 34995 : RibOutMap::iterator loc = ribout_map_.find(policy);
126 34995 : assert(loc != ribout_map_.end());
127 34995 : delete loc->second;
128 34995 : ribout_map_.erase(loc);
129 34995 : }
130 :
131 : // If both as2 and as4 aggregators are present then we need to choose one
132 248354 : void BgpTable::CheckAggregatorAttr(BgpAttr *attr) const {
133 248354 : if (attr->aggregator_as_num() && attr->aggregator_as4_num()) {
134 32 : if (attr->aggregator_as_num() != AS_TRANS) {
135 : // If as2 aggregator is not as_trans then we ignore as4 aggregator
136 : // and ignore as4_path also
137 16 : attr->set_as4_path(NULL);
138 16 : attr->set_as4_aggregator(0, attr->aggregator_adderess());
139 : } else {
140 : // If as2 aggregator is as_trans then we use as4 aggregator
141 16 : attr->set_aggregator(attr->aggregator_as4_num(),
142 16 : attr->aggregator_adderess());
143 16 : attr->set_as4_aggregator(0, attr->aggregator_adderess());
144 : }
145 : }
146 248367 : }
147 :
148 203652 : void BgpTable::PrependLocalAs(const RibOut *ribout, BgpAttr *clone,
149 : const IPeer* peer) const {
150 203652 : CheckAggregatorAttr(clone);
151 203654 : as_t local_as = ribout->local_as() ?:
152 466 : clone->attr_db()->server()->local_autonomous_system();
153 203653 : if (!server()->enable_4byte_as())
154 203334 : return PrependAsToAsPath2Byte(clone, (as2_t)local_as);
155 314 : if (ribout->as4_supported()) {
156 120 : if (clone->aspath_4byte())
157 48 : PrependAsToAsPath4Byte(clone, local_as);
158 : else
159 72 : CreateAsPath4Byte(clone, local_as);
160 : } else {
161 194 : if (!clone->as_path())
162 46 : CreateAsPath2Byte(clone);
163 194 : PrependAsToAsPath2Byte(clone, local_as);
164 : }
165 : }
166 :
167 82 : void BgpTable::RemovePrivateAs(const RibOut *ribout, BgpAttr *attr) const {
168 82 : bool all = ribout->remove_private_all();
169 82 : bool replace = ribout->remove_private_replace();
170 82 : bool peer_loop_check = ribout->remove_private_peer_loop_check();
171 :
172 82 : const AsPathSpec &spec = attr->as_path()->path();
173 82 : as_t peer_asn = peer_loop_check ? ribout->peer_as() : 0;
174 82 : as_t replace_asn = 0;
175 82 : if (replace) {
176 56 : if (ribout->peer_type() == BgpProto::EBGP) {
177 32 : replace_asn = server()->local_autonomous_system();
178 : } else {
179 24 : replace_asn = spec.AsLeftMostPublic();
180 : }
181 : }
182 82 : if (replace_asn > AS2_MAX) {
183 8 : if (!attr->as4_path())
184 8 : CreateAs4Path(attr);
185 8 : const As4PathSpec &spec = attr->as4_path()->path();
186 8 : As4PathSpec *new_spec = spec.RemovePrivate(all, replace_asn, peer_asn);
187 8 : attr->set_as4_path(new_spec);
188 8 : delete new_spec;
189 8 : replace_asn = AS_TRANS;
190 : }
191 82 : if (peer_asn > AS2_MAX)
192 8 : peer_asn = AS_TRANS;
193 :
194 82 : AsPathSpec *new_spec = spec.RemovePrivate(all, replace_asn, peer_asn);
195 82 : attr->set_as_path(new_spec);
196 82 : delete new_spec;
197 82 : }
198 :
199 24 : void BgpTable::RemovePrivate4ByteAs(const RibOut *ribout, BgpAttr *attr) const {
200 24 : bool all = ribout->remove_private_all();
201 24 : bool replace = ribout->remove_private_replace();
202 24 : bool peer_loop_check = ribout->remove_private_peer_loop_check();
203 :
204 24 : const AsPath4ByteSpec &spec = attr->aspath_4byte()->path();
205 24 : as_t peer_asn = peer_loop_check ? ribout->peer_as() : 0;
206 24 : as_t replace_asn = 0;
207 24 : if (replace) {
208 16 : if (ribout->peer_type() == BgpProto::EBGP) {
209 16 : replace_asn = server()->local_autonomous_system();
210 : } else {
211 0 : replace_asn = spec.AsLeftMostPublic();
212 : }
213 : }
214 :
215 24 : AsPath4ByteSpec *new_spec = spec.RemovePrivate(all, replace_asn, peer_asn);
216 24 : attr->set_aspath_4byte(new_spec);
217 24 : delete new_spec;
218 24 : }
219 :
220 8 : void BgpTable::RemovePrivateAs4(const RibOut *ribout, BgpAttr *attr) const {
221 8 : bool all = ribout->remove_private_all();
222 8 : bool replace = ribout->remove_private_replace();
223 8 : bool peer_loop_check = ribout->remove_private_peer_loop_check();
224 :
225 8 : const As4PathSpec &spec = attr->as4_path()->path();
226 8 : as_t peer_asn = peer_loop_check ? ribout->peer_as() : 0;
227 8 : as_t replace_asn = 0;
228 8 : if (replace) {
229 8 : if (ribout->peer_type() == BgpProto::EBGP) {
230 8 : replace_asn = server()->local_autonomous_system();
231 : } else {
232 0 : replace_asn = spec.AsLeftMostPublic();
233 : }
234 : }
235 :
236 8 : As4PathSpec *new_spec = spec.RemovePrivate(all, replace_asn, peer_asn);
237 8 : attr->set_as4_path(new_spec);
238 8 : delete new_spec;
239 8 : }
240 :
241 : //
242 : // Process Remove Private information.
243 : //
244 248363 : void BgpTable::ProcessRemovePrivate(const RibOut *ribout, BgpAttr *attr) const {
245 248363 : if (!ribout->IsEncodingBgp())
246 0 : return;
247 248363 : if (!ribout->remove_private_enabled())
248 248253 : return;
249 :
250 110 : if (attr->as_path())
251 82 : RemovePrivateAs(ribout, attr);
252 110 : if (attr->aspath_4byte())
253 24 : RemovePrivate4ByteAs(ribout, attr);
254 110 : if (attr->as4_path())
255 8 : RemovePrivateAs4(ribout, attr);
256 : }
257 :
258 : //
259 : // Process Remove Private information.
260 : //
261 203643 : void BgpTable::ProcessAsOverride(const RibOut *ribout, BgpAttr *attr) const {
262 203643 : if (ribout->as_override() && !attr->IsAsPathEmpty()) {
263 52 : as_t replace_as = ribout->local_as() ?:
264 52 : attr->attr_db()->server()->local_autonomous_system();
265 52 : if (attr->as_path()) {
266 44 : const AsPathSpec &as_path = attr->as_path()->path();
267 : // If peer_as is > 0xffff, it can't be in as_path
268 44 : if (ribout->peer_as() <= AS2_MAX) {
269 44 : if (replace_as > AS2_MAX) {
270 : // if replace_as > 0xffff, as4_path should be created if
271 : // not already there by copying data from as_path
272 12 : if (!attr->as4_path()) {
273 12 : CreateAs4Path(attr);
274 : }
275 12 : replace_as = AS_TRANS;
276 : }
277 44 : AsPathSpec *as_path_ptr = as_path.Replace(
278 44 : ribout->peer_as(), replace_as);
279 44 : attr->set_as_path(as_path_ptr);
280 44 : delete as_path_ptr;
281 : }
282 44 : if (attr->as4_path()) {
283 12 : As4PathSpec *as_path_ptr = attr->as4_path()->path().Replace(
284 : ribout->peer_as(), replace_as);
285 12 : attr->set_as4_path(as_path_ptr);
286 12 : delete as_path_ptr;
287 : }
288 : }
289 52 : if (attr->aspath_4byte()) {
290 8 : const AsPath4ByteSpec &as_path = attr->aspath_4byte()->path();
291 : AsPath4ByteSpec *as_path_ptr =
292 8 : as_path.Replace(ribout->peer_as(), replace_as);
293 8 : attr->set_aspath_4byte(as_path_ptr);
294 8 : delete as_path_ptr;
295 : }
296 : }
297 203650 : }
298 :
299 : //
300 : // Process Long Lived Graceful Restart state information.
301 : //
302 : // For LLGR_STALE paths, if the peer supports LLGR then attach LLGR_STALE
303 : // community. Otherwise, strip LLGR_STALE community, reduce LOCAL_PREF and
304 : // attach NO_EXPORT community instead.
305 : //
306 248371 : void BgpTable::ProcessLlgrState(const RibOut *ribout, const BgpPath *path,
307 : BgpAttr *attr, bool llgr_stale_comm) {
308 248371 : if (!server() || !server()->comm_db())
309 0 : return;
310 :
311 : // Skip LLGR specific attributes manipulation for rtarget routes.
312 248370 : if (family() == Address::RTARGET)
313 54995 : return;
314 :
315 : // If the path is not marked as llgr_stale or if it does not have the
316 : // LLGR_STALE community, then no action is necessary.
317 193374 : if (!path->IsLlgrStale() && !llgr_stale_comm)
318 187267 : return;
319 :
320 : // If peers support LLGR, then attach LLGR_STALE community and return.
321 6106 : if (ribout->llgr()) {
322 6094 : if (!llgr_stale_comm) {
323 : CommunityPtr comm = server()->comm_db()->AppendAndLocate(
324 6086 : attr->community(), CommunityType::LlgrStale);
325 6086 : attr->set_community(comm);
326 6086 : }
327 6094 : return;
328 : }
329 :
330 : // Peers do not understand LLGR. Bring down local preference instead to
331 : // make the advertised path less preferred.
332 12 : attr->set_local_pref(0);
333 :
334 : // Remove LLGR_STALE community as the peers do not support LLGR.
335 12 : if (llgr_stale_comm) {
336 : CommunityPtr comm = server()->comm_db()->RemoveAndLocate(
337 8 : attr->community(), CommunityType::LlgrStale);
338 8 : attr->set_community(comm);
339 8 : }
340 :
341 : // Attach NO_EXPORT community as well to make sure that this path does not
342 : // exits local AS, unless it is already present.
343 20 : if (!attr->community() ||
344 8 : !attr->community()->ContainsValue(CommunityType::NoExport)) {
345 : CommunityPtr comm = server()->comm_db()->AppendAndLocate(
346 12 : attr->community(), CommunityType::NoExport);
347 12 : attr->set_community(comm);
348 12 : }
349 : }
350 :
351 248372 : void BgpTable::ProcessDefaultTunnelEncapsulation(const RibOut *ribout,
352 : ExtCommunityDB *extcomm_db, BgpAttr *attr) const {
353 248372 : if (!ribout->ExportPolicy().default_tunnel_encap_list.empty()) {
354 8 : ExtCommunity::ExtCommunityList encap_list;
355 30 : BOOST_FOREACH(const string &encap_string,
356 : ribout->ExportPolicy().default_tunnel_encap_list) {
357 11 : TunnelEncap tunnel_encap(encap_string);
358 11 : encap_list.push_back(tunnel_encap.GetExtCommunity());
359 : }
360 8 : ExtCommunityPtr ext_community = attr->ext_community();
361 : ext_community =
362 16 : extcomm_db->ReplaceTunnelEncapsulationAndLocate(
363 8 : ext_community.get(), encap_list);
364 8 : attr->set_ext_community(ext_community);
365 8 : }
366 248371 : }
367 :
368 203529 : void BgpTable::PrependAsToAsPath2Byte(BgpAttr *attr, as2_t asn) const {
369 203529 : if (attr->as_path()) {
370 71943 : const AsPathSpec &as_path = attr->as_path()->path();
371 71942 : AsPathSpec *as_path_ptr = as_path.Add(asn);
372 71933 : attr->set_as_path(as_path_ptr);
373 71946 : delete as_path_ptr;
374 : } else {
375 131585 : AsPathSpec as_path;
376 131589 : AsPathSpec *as_path_ptr = as_path.Add(asn);
377 131567 : attr->set_as_path(as_path_ptr);
378 131595 : delete as_path_ptr;
379 131595 : }
380 203540 : }
381 :
382 194 : void BgpTable::PrependAsToAsPath2Byte(BgpAttr *attr, as_t asn) const {
383 194 : if (asn <= AS2_MAX) {
384 110 : if (attr->as_path() && attr->as4_path()) {
385 25 : PrependAsToAs4Path(attr, asn);
386 : }
387 110 : return PrependAsToAsPath2Byte(attr, static_cast<as2_t>(asn & AS2_MAX));
388 : }
389 84 : if (attr->as_path() && !attr->as4_path()) {
390 46 : CreateAs4Path(attr);
391 46 : assert(attr->as_path()->path().path_segments.size() ==
392 : attr->as4_path()->path().path_segments.size());
393 : }
394 84 : as2_t as_trans = AS_TRANS;
395 84 : PrependAsToAsPath2Byte(attr, as_trans);
396 84 : PrependAsToAs4Path(attr, asn);
397 : }
398 :
399 48 : void BgpTable::PrependAsToAsPath4Byte(BgpAttr *clone, as_t asn) const {
400 48 : if (clone->aspath_4byte()) {
401 48 : const AsPath4ByteSpec &as4_path = clone->aspath_4byte()->path();
402 48 : AsPath4ByteSpec *as4_path_ptr = as4_path.Add(asn);
403 48 : clone->set_aspath_4byte(as4_path_ptr);
404 48 : delete as4_path_ptr;
405 : } else {
406 0 : AsPath4ByteSpec as_path;
407 0 : AsPath4ByteSpec *as_path_ptr = as_path.Add(asn);
408 0 : clone->set_aspath_4byte(as_path_ptr);
409 0 : delete as_path_ptr;
410 0 : }
411 48 : }
412 :
413 109 : void BgpTable::PrependAsToAs4Path(BgpAttr* attr, as_t asn) const {
414 109 : if (attr->as4_path()) {
415 109 : const As4PathSpec &as4_path = attr->as4_path()->path();
416 109 : As4PathSpec *as4_path_ptr = as4_path.Add(asn);
417 109 : attr->set_as4_path(as4_path_ptr);
418 109 : delete as4_path_ptr;
419 : } else {
420 0 : As4PathSpec as_path;
421 0 : As4PathSpec *as_path_ptr = as_path.Add(asn);
422 0 : attr->set_as4_path(as_path_ptr);
423 0 : delete as_path_ptr;
424 0 : }
425 109 : }
426 :
427 : // Create as4_path by copying data from as_path
428 66 : void BgpTable::CreateAs4Path(BgpAttr *attr) const {
429 66 : if (!attr->as_path()) {
430 0 : return;
431 : }
432 :
433 66 : std::unique_ptr<As4PathSpec> new_as_path(new As4PathSpec);
434 66 : const AsPathSpec &as_path = attr->as_path()->path();
435 107 : for (size_t i = 0; i < as_path.path_segments.size(); i++) {
436 41 : As4PathSpec::PathSegment *ps4 = new As4PathSpec::PathSegment;
437 41 : AsPathSpec::PathSegment *ps = as_path.path_segments[i];
438 41 : ps4->path_segment_type = ps->path_segment_type;
439 108 : for (size_t j = 0; j < ps->path_segment.size(); j++) {
440 67 : as_t as = ps->path_segment[j];
441 67 : ps4->path_segment.push_back(as);
442 : }
443 41 : new_as_path->path_segments.push_back(ps4);
444 : }
445 66 : attr->set_as4_path(new_as_path.get());
446 66 : }
447 :
448 : // Check if aspath_4byte has any asn > 0xFFFF
449 62 : bool BgpTable::Has4ByteAsn(BgpAttr *attr) const {
450 62 : if (!attr->aspath_4byte())
451 13 : return false;
452 49 : const AsPath4ByteSpec &as_path4 = attr->aspath_4byte()->path();
453 69 : for (size_t i = 0; i < as_path4.path_segments.size(); ++i) {
454 49 : AsPath4ByteSpec::PathSegment *ps4 = as_path4.path_segments[i];
455 69 : for (size_t j = 0; j < ps4->path_segment.size(); ++j) {
456 49 : if (ps4->path_segment[j] > AS2_MAX)
457 29 : return true;
458 : }
459 : }
460 20 : return false;
461 : }
462 :
463 : // Create as_path (and as4_path) from as_path4byte
464 62 : void BgpTable::CreateAsPath2Byte(BgpAttr *attr) const {
465 62 : std::unique_ptr<AsPathSpec> new_as_path(new AsPathSpec);
466 62 : As4PathSpec *new_as4_path = NULL;
467 62 : bool has_4byte_asn = Has4ByteAsn(attr);
468 62 : if (has_4byte_asn)
469 29 : new_as4_path = new As4PathSpec;
470 62 : if (attr->aspath_4byte()) {
471 49 : const AsPath4ByteSpec &as_path4 = attr->aspath_4byte()->path();
472 114 : for (size_t i = 0; i < as_path4.path_segments.size(); i++) {
473 65 : AsPathSpec::PathSegment *ps = new AsPathSpec::PathSegment;
474 65 : As4PathSpec::PathSegment *as4_ps = NULL;
475 65 : AsPath4ByteSpec::PathSegment *ps4 = as_path4.path_segments[i];
476 65 : ps->path_segment_type = ps4->path_segment_type;
477 65 : if (has_4byte_asn) {
478 45 : as4_ps = new As4PathSpec::PathSegment;
479 45 : as4_ps->path_segment_type = ps4->path_segment_type;
480 : }
481 172 : for (size_t j = 0; j < ps4->path_segment.size(); ++j) {
482 107 : as_t as4 = ps4->path_segment[j];
483 107 : if (as4 > AS2_MAX) {
484 63 : as2_t as_trans = AS_TRANS;
485 63 : ps->path_segment.push_back(as_trans);
486 : } else {
487 44 : ps->path_segment.push_back(static_cast<as2_t>(
488 : as4 & AS2_MAX));
489 : }
490 107 : if (has_4byte_asn)
491 87 : as4_ps->path_segment.push_back(as4);
492 : }
493 65 : new_as_path->path_segments.push_back(ps);
494 65 : if (has_4byte_asn)
495 45 : new_as4_path->path_segments.push_back(as4_ps);
496 : }
497 49 : attr->set_aspath_4byte(NULL);
498 : }
499 62 : attr->set_as_path(new_as_path.get());
500 62 : if (has_4byte_asn) {
501 29 : attr->set_as4_path(new_as4_path);
502 29 : delete new_as4_path;
503 : }
504 62 : }
505 :
506 : // Create aspath_4byte by merging as_path and as4_path
507 76 : void BgpTable::CreateAsPath4Byte(BgpAttr *attr, as_t local_as) const {
508 76 : int as2_count = attr->as_path_count();
509 76 : int as4_count = attr->as4_path_count();
510 76 : if (as2_count < as4_count) {
511 8 : as4_count = 0;
512 8 : attr->set_as4_path(NULL);
513 : }
514 76 : AsPath4ByteSpec::PathSegment *ps4 = NULL;
515 76 : bool part_segment = false;
516 76 : std::unique_ptr <AsPath4ByteSpec> aspath_4byte(new AsPath4ByteSpec);
517 76 : if (attr->as_path()) {
518 32 : const AsPathSpec &as_path = attr->as_path()->path();
519 32 : int new_as_count = 0;
520 86 : for (size_t i = 0; i < as_path.path_segments.size() &&
521 32 : new_as_count < (as2_count - as4_count) ; ++i) {
522 30 : ps4 = new AsPath4ByteSpec::PathSegment;
523 30 : AsPathSpec::PathSegment *ps = as_path.path_segments[i];
524 30 : ps4->path_segment_type = ps->path_segment_type;
525 30 : if (ps->path_segment_type == AsPathSpec::PathSegment::AS_SET) {
526 0 : new_as_count++;
527 0 : for (size_t j = 0; j < ps->path_segment.size(); ++j) {
528 0 : as2_t as = ps->path_segment[j];
529 0 : ps4->path_segment.push_back(as);
530 : }
531 : } else {
532 130 : for (size_t j = 0; j < ps->path_segment.size() &&
533 54 : new_as_count < (as2_count - as4_count); ++j) {
534 46 : new_as_count++;
535 46 : as2_t as = ps->path_segment[j];
536 46 : ps4->path_segment.push_back(as);
537 : }
538 30 : if (new_as_count == (as2_count - as4_count)) {
539 30 : if (attr->as4_path()) {
540 8 : part_segment = true;
541 8 : break;
542 : }
543 : }
544 : }
545 22 : aspath_4byte->path_segments.push_back(ps4);
546 : }
547 32 : if (attr->as4_path()) {
548 10 : const As4PathSpec &as4_path = attr->as4_path()->path();
549 20 : for (size_t i = 0; i < as4_path.path_segments.size(); ++i) {
550 10 : if (!part_segment) {
551 2 : ps4 = new AsPath4ByteSpec::PathSegment;
552 : }
553 10 : part_segment = false;
554 10 : As4PathSpec::PathSegment *ps = as4_path.path_segments[i];
555 10 : ps4->path_segment_type = ps->path_segment_type;
556 10 : if (ps->path_segment_type == As4PathSpec::PathSegment::AS_SET) {
557 0 : new_as_count++;
558 0 : for (size_t j = 0; j < ps->path_segment.size(); ++j) {
559 0 : as2_t as = ps->path_segment[j];
560 0 : ps4->path_segment.push_back(as);
561 : }
562 : } else {
563 40 : for (size_t j = 0; j < ps->path_segment.size(); ++j) {
564 30 : as_t as = ps->path_segment[j];
565 30 : ps4->path_segment.push_back(as);
566 : }
567 : }
568 10 : aspath_4byte->path_segments.push_back(ps4);
569 : }
570 10 : attr->set_as4_path(NULL);
571 : }
572 32 : attr->set_as_path(NULL);
573 : }
574 76 : if (local_as) {
575 72 : std::unique_ptr<AsPath4ByteSpec> as_path_spec(aspath_4byte->Add(local_as));
576 72 : attr->set_aspath_4byte(as_path_spec.get());
577 72 : } else {
578 4 : attr->set_aspath_4byte(aspath_4byte.get());
579 : }
580 76 : }
581 :
582 897566 : UpdateInfo *BgpTable::GetUpdateInfo(RibOut *ribout, BgpRoute *route,
583 : const RibPeerSet &peerset) {
584 897566 : const BgpPath *path = route->BestPath();
585 :
586 : // Ignore if there is no best-path.
587 897609 : if (!path)
588 16 : return NULL;
589 :
590 : // Don't advertise infeasible paths.
591 897593 : if (!path->IsFeasible())
592 2992 : return NULL;
593 :
594 : // Check whether the route is contributing route
595 894584 : if (IsRouteAggregationSupported() && IsContributingRoute(route))
596 7 : return NULL;
597 :
598 : // Needs to be outside the if block so it's not destroyed prematurely.
599 894532 : BgpAttrPtr attr_ptr;
600 894532 : const BgpAttr *attr = path->GetAttr();
601 :
602 894546 : RibPeerSet new_peerset = peerset;
603 :
604 : // LocalPref, Med and AsPath manipulation is needed only if the RibOut
605 : // has BGP encoding. Similarly, well-known communities do not apply if
606 : // the encoding is not BGP.
607 894440 : if (ribout->IsEncodingBgp()) {
608 : // Handle well-known communities.
609 449210 : if (attr->community() != NULL &&
610 6953 : attr->community()->communities().size()) {
611 20709 : BOOST_FOREACH(uint32_t value, attr->community()->communities()) {
612 6977 : if (value == CommunityType::NoAdvertise)
613 99 : return NULL;
614 :
615 11388 : if ((ribout->peer_type() == BgpProto::EBGP) &&
616 4467 : ((value == CommunityType::NoExport) ||
617 : (value == CommunityType::NoExportSubconfed))) {
618 43 : return NULL;
619 : }
620 : }
621 : }
622 :
623 442154 : const IPeer *peer = path->GetPeer();
624 442153 : BgpAttr *clone = NULL;
625 449007 : bool llgr_stale_comm = attr->community() &&
626 6854 : attr->community()->ContainsValue(CommunityType::LlgrStale);
627 442150 : if (ribout->peer_type() == BgpProto::IBGP) {
628 : // Split horizon check.
629 87595 : if (peer && peer->CheckSplitHorizon(server()->cluster_id(),
630 : ribout->cluster_id()))
631 38080 : return NULL;
632 :
633 : // Handle route-target filtering.
634 49521 : if (IsVpnTable() && attr->ext_community() != NULL) {
635 23780 : server()->rtarget_group_mgr()->GetRibOutInterestedPeers(
636 : ribout, attr->ext_community(), peerset, &new_peerset);
637 23780 : if (new_peerset.empty())
638 4810 : return NULL;
639 : }
640 :
641 44711 : if (server()->cluster_id()) {
642 : // Check if there is a loop in cluster_list
643 8 : if (attr->cluster_list() && attr->cluster_list()->cluster_list()
644 0 : .ClusterListLoop(server()->cluster_id())) {
645 0 : return NULL;
646 : }
647 : }
648 :
649 44711 : if (server()->cluster_id() && (family() != Address::RTARGET)) {
650 : // route reflector should not reflect the route back to the peer
651 : // from which it received that route, for non rtarget routes
652 : // This is done by checking peer_router_id of all the feasible
653 : // paths of this route
654 8 : RibPeerSet route_peerset;
655 16 : for (Route::PathList::iterator it= route->GetPathList().begin();
656 32 : it != route->GetPathList().end(); it++) {
657 8 : BgpPath *ipath = static_cast<BgpPath *>(it.operator->());
658 8 : if (ipath->IsFeasible() && ipath->GetPeer()) {
659 8 : const IPeer *ipeer = ipath->GetPeer();
660 8 : const BgpPeer *bgp_peer = dynamic_cast<
661 8 : const BgpPeer *>(ipeer);
662 8 : if (bgp_peer)
663 2 : route_peerset.set(bgp_peer->GetIndex());
664 : }
665 : }
666 8 : RibOut::PeerIterator iter(ribout, new_peerset);
667 30 : while (iter.HasNext()) {
668 22 : int current_index = iter.index();
669 22 : IPeerUpdate *peer = iter.Next();
670 22 : const BgpPeer *bgp_peer = dynamic_cast<
671 22 : const BgpPeer *>(peer);
672 22 : if (bgp_peer && route_peerset.test(bgp_peer->GetIndex()))
673 2 : new_peerset.reset(current_index);
674 : }
675 8 : if (new_peerset.empty())
676 0 : return NULL;
677 8 : }
678 :
679 44711 : clone = new BgpAttr(*attr);
680 :
681 : // Retain LocalPref value if set, else set default to 100.
682 44714 : if (clone->local_pref() == 0)
683 0 : clone->set_local_pref(100);
684 :
685 : // Check aggregator attributes to identify which ones to be used
686 44714 : CheckAggregatorAttr(clone);
687 :
688 : // Should not normally be needed for iBGP, but there could be
689 : // complex configurations where this is useful.
690 44713 : ProcessRemovePrivate(ribout, clone);
691 :
692 : // Add Originator_Id if acting as route reflector and cluster_id
693 : // is not present
694 44712 : if (server()->cluster_id()) {
695 8 : if (clone->originator_id().is_unspecified()) {
696 8 : if (peer && (peer->bgp_identifier() != 0)) {
697 2 : clone->set_originator_id(Ip4Address(
698 2 : peer->bgp_identifier()));
699 : } else {
700 6 : clone->set_originator_id(Ip4Address(
701 : server()->bgp_identifier()));
702 : }
703 : }
704 8 : if (attr->cluster_list()) {
705 : const ClusterListSpec &cluster =
706 0 : clone->cluster_list()->cluster_list();
707 : ClusterListSpec *cl_ptr = new ClusterListSpec(
708 0 : server()->cluster_id(), &cluster);
709 0 : clone->set_cluster_list(cl_ptr);
710 0 : delete cl_ptr;
711 : } else {
712 : ClusterListSpec *cl_ptr = new ClusterListSpec(
713 8 : server()->cluster_id(), NULL);
714 8 : clone->set_cluster_list(cl_ptr);
715 8 : delete cl_ptr;
716 : }
717 : }
718 : // If the route is locally originated i.e. there's no AsPath,
719 : // then generate a Nil AsPath i.e. one with 0 length. No need
720 : // to modify the AsPath if it already exists since this is an
721 : // iBGP RibOut.
722 44712 : if (ribout->as4_supported() && !clone->aspath_4byte()) {
723 53 : if (attr->as_path()) {
724 4 : CreateAsPath4Byte(clone, 0);
725 : } else {
726 49 : AsPath4ByteSpec as_path;
727 49 : clone->set_aspath_4byte(&as_path);
728 49 : }
729 : }
730 44712 : if (!ribout->as4_supported() && !clone->as_path()) {
731 40760 : if (attr->aspath_4byte()) {
732 16 : CreateAsPath2Byte(clone);
733 : } else {
734 40744 : AsPathSpec as_path;
735 40744 : clone->set_as_path(&as_path);
736 40744 : }
737 : }
738 354551 : } else if (ribout->peer_type() == BgpProto::EBGP) {
739 : // Don't advertise routes from non-master instances if there's
740 : // no nexthop. The ribout has to be for bgpaas-clients because
741 : // that's the only case with bgp peers in non-master instance.
742 357045 : if (!rtinstance_->IsMasterRoutingInstance() &&
743 2503 : ribout->nexthop().is_unspecified()) {
744 0 : return NULL;
745 : }
746 :
747 : // Handle route-target filtering.
748 354537 : if (IsVpnTable() && attr->ext_community() != NULL) {
749 296573 : server()->rtarget_group_mgr()->GetRibOutInterestedPeers(
750 : ribout, attr->ext_community(), peerset, &new_peerset);
751 296749 : if (new_peerset.empty())
752 15068 : return NULL;
753 : }
754 :
755 : // Sender side AS path loop check and split horizon within RibOut.
756 339660 : if (!ribout->as_override()) {
757 339603 : if (attr->IsAsPathLoop(ribout->peer_as()))
758 136010 : return NULL;
759 : } else {
760 60 : if (peer && peer->PeerType() == BgpProto::EBGP) {
761 40 : ribout->GetSubsetPeerSet(&new_peerset, peer);
762 40 : if (new_peerset.empty())
763 0 : return NULL;
764 : }
765 : }
766 :
767 203636 : clone = new BgpAttr(*attr);
768 :
769 : // Remove non-transitive attributes.
770 : // Note that med is handled further down.
771 203661 : clone->set_originator_id(Ip4Address());
772 203658 : clone->set_cluster_list(NULL);
773 :
774 : // Update nexthop.
775 203657 : if (!ribout->nexthop().is_unspecified())
776 1623 : clone->set_nexthop(ribout->nexthop());
777 :
778 : // Reset LocalPref.
779 203657 : if (clone->local_pref())
780 203657 : clone->set_local_pref(0);
781 :
782 : // Reset Med if the path did not originate from an xmpp peer.
783 : // The AS path is NULL if the originating xmpp peer is locally
784 : // connected. It's non-NULL but empty if the originating xmpp
785 : // peer is connected to another bgp speaker in the iBGP mesh.
786 203653 : if (clone->med() && !clone->IsAsPathEmpty())
787 366 : clone->set_med(0);
788 :
789 : // Override the peer AS with local AS in AsPath.
790 203651 : ProcessAsOverride(ribout, clone);
791 :
792 : // Remove private processing must happen before local AS prepend.
793 203650 : ProcessRemovePrivate(ribout, clone);
794 :
795 : // Prepend the local AS to AsPath.
796 203651 : PrependLocalAs(ribout, clone, peer);
797 : }
798 :
799 248372 : assert(clone);
800 :
801 : // Update with the Default tunnel Encapsulation ordered List if
802 : // configured on the peer.
803 : // Note that all peers with the same list share the same Ribout, this is
804 : // ensured by making the Default Encapsulation List part of the Rib
805 : // Export policy.Note that, if there is Default Tunnel Encapsulation
806 : // configuration any tunnel encapsulation present is removed.
807 248372 : ProcessDefaultTunnelEncapsulation(ribout, server()->extcomm_db(),
808 : clone);
809 :
810 248371 : ProcessLlgrState(ribout, path, clone, llgr_stale_comm);
811 :
812 : // Locate the new BgpAttrPtr.
813 248367 : attr_ptr = clone->attr_db()->Locate(clone);
814 248376 : attr = attr_ptr.get();
815 : }
816 :
817 700563 : UpdateInfo *uinfo = new UpdateInfo;
818 700691 : uinfo->target = new_peerset;
819 700655 : uinfo->roattr = RibOutAttr(route, attr, ribout->IsEncodingXmpp());
820 700946 : return uinfo;
821 895013 : }
822 :
823 : // Bgp Path selection..
824 : // Based Attribute weight
825 1808812 : bool BgpTable::PathSelection(const Path &path1, const Path &path2) {
826 1808812 : const BgpPath &l_path = dynamic_cast<const BgpPath &> (path1);
827 1808812 : const BgpPath &r_path = dynamic_cast<const BgpPath &> (path2);
828 :
829 : // Check the weight of Path
830 1808813 : bool res = l_path.PathCompare(r_path, false) < 0;
831 :
832 1808809 : return res;
833 : }
834 :
835 17 : bool BgpTable::DeletePath(DBTablePartBase *root, BgpRoute *rt, BgpPath *path) {
836 34 : return InputCommon(root, rt, path, path->GetPeer(), NULL,
837 34 : DBRequest::DB_ENTRY_DELETE, NULL, path->GetPathId(), 0, 0, 0);
838 : }
839 :
840 539436 : bool BgpTable::InputCommon(DBTablePartBase *root, BgpRoute *rt, BgpPath *path,
841 : const IPeer *peer, DBRequest *req,
842 : DBRequest::DBOperation oper, BgpAttrPtr attrs,
843 : uint32_t path_id, uint32_t flags, uint32_t label,
844 : uint32_t l3_label) {
845 539436 : bool notify_rt = false;
846 :
847 539436 : switch (oper) {
848 288459 : case DBRequest::DB_ENTRY_ADD_CHANGE: {
849 288459 : assert(rt);
850 :
851 : // The entry may currently be marked as deleted.
852 288459 : rt->ClearDelete();
853 288455 : if (peer)
854 244407 : peer->UpdateCloseRouteStats(family(), path, flags);
855 :
856 : // Check whether peer already has a path.
857 288449 : if (path != NULL) {
858 58104 : if ((path->GetAttr() != attrs.get()) ||
859 23033 : (path->GetFlags() != flags) ||
860 60460 : (path->GetLabel() != label) ||
861 2220 : (path->GetL3Label() != l3_label)) {
862 : // Update Attributes and notify (if needed)
863 35211 : if (path->NeedsResolution())
864 1284 : path_resolver_->StopPathResolution(root->index(), path);
865 35211 : rt->DeletePath(path);
866 : } else {
867 : // Ignore duplicate update.
868 2216 : break;
869 : }
870 : }
871 :
872 : BgpPath *new_path;
873 572478 : new_path = new BgpPath(
874 286247 : peer, path_id, BgpPath::BGP_XMPP, attrs, flags, label, l3_label);
875 :
876 : // Start path resolution for the new path if
877 : // (1) Path flag has ResolveNextHop set in which case the path will
878 : // be resolved in the overlay routing table (or)
879 : // (2) Fast convergence knob is enabled in which case the path will
880 : // be marked for resolution in the underlay (default) routing table
881 : // (3) Path resolution in this case is needed only for routes
882 : // in the VRF routing tables and for INET, INET6 and EVPN
883 : // address families.
884 286251 : bool fc_family = false;
885 519385 : if (family() == Address::INET || family() == Address::INET6 ||
886 233135 : family() == Address::EVPN) {
887 100093 : fc_family = true;
888 : }
889 286243 : bool fc_enabled = (server()->IsNextHopCheckEnabled() &&
890 286237 : !rtinstance_->IsMasterRoutingInstance() && fc_family);
891 286237 : if (new_path->NeedsResolution() || fc_enabled) {
892 2833 : if (peer && !(peer->IsXmppPeer()) ) {
893 2708 : rt->add_peer_sources(peer->ToString());
894 : }
895 2833 : Address::Family family = new_path->GetAttr()->nexthop_family();
896 : BgpTable *table;
897 2833 : if (new_path->NeedsResolution()) {
898 2727 : table = rtinstance_->GetTable(family);
899 : } else {
900 : // Fast convergence knob is enabled.
901 : // Update path flag to indicate need for resolution.
902 106 : new_path->SetResolveNextHop();
903 :
904 : // Get the default table.
905 106 : RoutingInstanceMgr *mgr = server()->routing_instance_mgr();
906 106 : assert(mgr);
907 106 : RoutingInstance *master_ri = mgr->GetDefaultRoutingInstance();
908 106 : assert(master_ri);
909 106 : table = master_ri->GetTable(family);
910 : }
911 2833 : path_resolver_->StartPathResolution(rt, new_path, table);
912 : }
913 :
914 286234 : rt->InsertPath(new_path);
915 286243 : notify_rt = true;
916 286243 : break;
917 : }
918 :
919 250979 : case DBRequest::DB_ENTRY_DELETE: {
920 250979 : if (rt && !rt->IsDeleted()) {
921 250978 : if (peer && !(peer->IsXmppPeer()) ) {
922 154093 : rt->del_peer_sources(peer->ToString());
923 : }
924 273319 : BGP_LOG_ROUTE(this, const_cast<IPeer *>(peer), rt,
925 : "Delete BGP path");
926 :
927 : // Remove the Path from the route
928 250974 : if (path->NeedsResolution())
929 1549 : path_resolver_->StopPathResolution(root->index(), path);
930 250972 : rt->DeletePath(path);
931 251016 : notify_rt = true;
932 : }
933 251016 : break;
934 : }
935 :
936 0 : default: {
937 0 : assert(false);
938 : break;
939 : }
940 : }
941 539475 : return notify_rt;
942 : }
943 :
944 467706 : void BgpTable::Input(DBTablePartition *root, DBClient *client,
945 : DBRequest *req) {
946 467706 : const IPeer *peer = (static_cast<RequestKey *>(req->key.get()))->GetPeer();
947 467658 : RequestData *data = static_cast<RequestData *>(req->data.get());
948 :
949 467620 : if (req->oper == DBRequest::DB_ENTRY_ADD_CHANGE && peer) {
950 : // Skip if this peer is down.
951 239579 : if (!peer->IsReady())
952 21952 : return;
953 :
954 : // For xmpp peers, verify that agent is subscribed to the table and
955 : // the route add is from the same incarnation of table subscription.
956 229580 : if (peer->IsXmppPeer() && peer->IsRegistrationRequired()) {
957 59276 : BgpMembershipManager *mgr = rtinstance_->server()->membership_mgr();
958 59276 : int instance_id = -1;
959 59276 : uint64_t subscription_gen_id = 0;
960 : bool is_registered =
961 59276 : mgr->GetRegistrationInfo(const_cast<IPeer *>(peer), this,
962 : &instance_id, &subscription_gen_id);
963 86282 : if ((!is_registered && (family() != Address::RTARGET)) ||
964 27006 : (is_registered &&
965 27006 : (subscription_gen_id != data->subscription_gen_id()))) {
966 3 : return;
967 : }
968 : }
969 : }
970 :
971 : // Create route if it's not already present in case of add/change.
972 457617 : BgpRoute *rt = TableFind(root, req->key.get());
973 457620 : if (!rt) {
974 224021 : if ((req->oper == DBRequest::DB_ENTRY_DELETE) ||
975 213127 : (req->oper == DBRequest::DB_ENTRY_NOTIFY))
976 11269 : return;
977 :
978 212752 : rt = static_cast<BgpRoute *>(Add(req));
979 212717 : static_cast<DBTablePartition *>(root)->Add(rt);
980 230519 : BGP_LOG_ROUTE(this, const_cast<IPeer *>(peer), rt,
981 : "Insert new BGP path");
982 : }
983 :
984 446371 : if (req->oper == DBRequest::DB_ENTRY_NOTIFY) {
985 419 : root->Notify(rt);
986 419 : return;
987 : }
988 :
989 445952 : uint32_t path_id = 0;
990 445952 : uint32_t flags = 0;
991 445952 : uint32_t label = 0;
992 445952 : uint32_t l3_label = 0;
993 445952 : BgpPath *path = rt->FindPath(peer);
994 445994 : BgpAttrPtr attr = data ? data->attrs() : NULL;
995 446004 : if (req->oper == DBRequest::DB_ENTRY_ADD_CHANGE) {
996 273630 : assert(data);
997 273630 : const RequestData::NextHop &nexthop = data->nexthop();
998 273628 : if (nexthop.address_.is_v4())
999 269083 : path_id = nexthop.address_.to_v4().to_ulong();
1000 273625 : flags = nexthop.flags_;
1001 273625 : label = nexthop.label_;
1002 273625 : l3_label = nexthop.l3_label_;
1003 :
1004 273625 : attr = GetAttributes(rt, attr, peer);
1005 : } else {
1006 172374 : if (!path)
1007 249 : return;
1008 172125 : path_id = path->GetPathId();
1009 : }
1010 :
1011 445750 : bool notify_rt = InputCommon(root, rt, path, peer, req, req->oper,
1012 : attr, path_id, flags, label, l3_label);
1013 445766 : InputCommonPostProcess(root, rt, notify_rt);
1014 445985 : }
1015 :
1016 934718 : void BgpTable::InputCommonPostProcess(DBTablePartBase *root,
1017 : BgpRoute *rt, bool notify_rt) {
1018 934718 : if (!notify_rt)
1019 397765 : return;
1020 :
1021 536953 : if (rt->front() == NULL)
1022 213203 : root->Delete(rt);
1023 : else
1024 323739 : root->Notify(rt);
1025 : }
1026 :
1027 294995 : bool BgpTable::MayDelete() const {
1028 294995 : CHECK_CONCURRENCY("bgp::Config");
1029 :
1030 : // Bail if the table has listeners.
1031 294995 : if (HasListeners()) {
1032 6372 : BGP_LOG_TABLE(this, SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL,
1033 : "Paused table deletion due to pending listeners");
1034 6372 : return false;
1035 : }
1036 :
1037 : // Bail if the table has walkers.
1038 288623 : if (HasWalkers()) {
1039 0 : BGP_LOG_TABLE(this, SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL,
1040 : "Paused table deletion due to pending walkers");
1041 0 : return false;
1042 : }
1043 :
1044 : // Bail if the table is not empty.
1045 288623 : size_t size = Size();
1046 288623 : if (size > 0) {
1047 16 : BGP_LOG_TABLE(this, SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL,
1048 : "Paused table deletion due to " << size <<
1049 : " pending routes");
1050 16 : return false;
1051 : }
1052 :
1053 : // Check the base class at the end so that we add custom checks
1054 : // before this if needed and to get more informative log message.
1055 288607 : if (!DBTableBase::MayDelete())
1056 0 : return false;
1057 :
1058 288607 : return true;
1059 : }
1060 :
1061 288607 : void BgpTable::Shutdown() {
1062 288607 : CHECK_CONCURRENCY("bgp::PeerMembership", "bgp::Config");
1063 288607 : }
1064 :
1065 288607 : void BgpTable::ManagedDelete() {
1066 288607 : BGP_LOG_TABLE(this, SandeshLevel::SYS_INFO, BGP_LOG_FLAG_ALL,
1067 : "Received request for table deletion");
1068 288607 : deleter_->Delete();
1069 288607 : }
1070 :
1071 : //
1072 : // Retry deletion of the table if it is pending.
1073 : //
1074 575297 : void BgpTable::RetryDelete() {
1075 575297 : if (!deleter()->IsDeleted())
1076 256353 : return;
1077 318942 : deleter()->RetryDelete();
1078 : }
1079 :
1080 0 : PathResolver *BgpTable::CreatePathResolver() {
1081 0 : return NULL;
1082 : }
1083 :
1084 172742 : void BgpTable::LocatePathResolver() {
1085 172742 : if (path_resolver_)
1086 1102 : return;
1087 171640 : assert(!deleter()->IsDeleted());
1088 171637 : path_resolver_ = CreatePathResolver();
1089 : }
1090 :
1091 171644 : void BgpTable::DestroyPathResolver() {
1092 171644 : if (!path_resolver_)
1093 0 : return;
1094 171644 : delete path_resolver_;
1095 171644 : path_resolver_ = NULL;
1096 : }
1097 :
1098 13905 : size_t BgpTable::GetPendingRiboutsCount(size_t *markers) const {
1099 13905 : CHECK_CONCURRENCY("bgp::ShowCommand", "bgp::Config");
1100 13905 : size_t count = 0;
1101 13905 : *markers = 0;
1102 :
1103 18557 : BOOST_FOREACH(const RibOutMap::value_type &value, ribout_map_) {
1104 2326 : const RibOut *ribout = value.second;
1105 10142 : for (int idx = 0; idx < DB::PartitionCount(); ++idx) {
1106 7816 : const RibOutUpdates *updates = ribout->updates(idx);
1107 23448 : for (int qid = RibOutUpdates::QFIRST; qid < RibOutUpdates::QCOUNT;
1108 : ++qid) {
1109 15632 : count += updates->queue_size(qid);
1110 15632 : *markers += updates->queue_marker_count(qid);
1111 : }
1112 : }
1113 : }
1114 :
1115 13905 : return count;
1116 : }
1117 :
1118 2075346 : LifetimeActor *BgpTable::deleter() {
1119 2075346 : return deleter_.get();
1120 : }
1121 :
1122 291829 : const LifetimeActor *BgpTable::deleter() const {
1123 291829 : return deleter_.get();
1124 : }
1125 :
1126 1930978 : void BgpTable::UpdatePathCount(const BgpPath *path, int count) {
1127 1930978 : if (dynamic_cast<const BgpSecondaryPath *>(path)) {
1128 1157813 : secondary_path_count_ += count;
1129 : } else {
1130 773165 : primary_path_count_ += count;
1131 : }
1132 :
1133 1931784 : if (!path->IsFeasible()) {
1134 8510 : infeasible_path_count_ += count;
1135 : }
1136 :
1137 1931680 : if (path->IsStale()) {
1138 90686 : stale_path_count_ += count;
1139 : }
1140 :
1141 1931624 : if (path->IsLlgrStale()) {
1142 20118 : llgr_stale_path_count_ += count;
1143 : }
1144 1931531 : }
1145 :
1146 : // Check whether the route is aggregate route
1147 0 : bool BgpTable::IsAggregateRoute(const BgpRoute *route) const {
1148 0 : return routing_instance()->IsAggregateRoute(this, route);
1149 : }
1150 :
1151 : // Check whether the route is contributing route to aggregate route
1152 920142 : bool BgpTable::IsContributingRoute(const BgpRoute *route) const {
1153 920142 : return routing_instance()->IsContributingRoute(this, route);
1154 : }
1155 :
1156 18 : void BgpTable::FillRibOutStatisticsInfo(
1157 : vector<ShowRibOutStatistics> *sros_list) const {
1158 22 : BOOST_FOREACH(const RibOutMap::value_type &value, ribout_map_) {
1159 2 : const RibOut *ribout = value.second;
1160 2 : ribout->FillStatisticsInfo(sros_list);
1161 : }
1162 18 : }
|