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_ribout_updates.h"
7 :
8 : #include <string>
9 :
10 : #include "sandesh/sandesh_trace.h"
11 : #include "base/task_annotations.h"
12 : #include "bgp/bgp_log.h"
13 : #include "bgp/bgp_peer_types.h"
14 : #include "bgp/bgp_ribout.h"
15 : #include "bgp/bgp_route.h"
16 : #include "bgp/bgp_update_queue.h"
17 : #include "bgp/bgp_update_monitor.h"
18 : #include "bgp/bgp_update_sender.h"
19 : #include "bgp/message_builder.h"
20 :
21 : using std::unique_ptr;
22 : using std::vector;
23 :
24 : vector<Message *> RibOutUpdates::bgp_messages_;
25 : vector<Message *> RibOutUpdates::xmpp_messages_;
26 :
27 : //
28 : // Create a new RibOutUpdates. Also create the necessary UpdateQueue and
29 : // add them to the vector.
30 : //
31 3216 : RibOutUpdates::RibOutUpdates(RibOut *ribout, int index)
32 3216 : : ribout_(ribout),
33 3216 : index_(index) {
34 9648 : for (int i = 0; i < QCOUNT; i++) {
35 6432 : UpdateQueue *queue = new UpdateQueue(ribout, i);
36 6432 : queue_vec_.push_back(queue);
37 : }
38 3216 : monitor_.reset(new RibUpdateMonitor(ribout, &queue_vec_));
39 3216 : memset(&stats_, 0, sizeof(stats_));
40 3216 : }
41 :
42 : //
43 : // Destructor. Get rid of all the UpdateQueues.
44 : //
45 6432 : RibOutUpdates::~RibOutUpdates() {
46 3216 : STLDeleteValues(&queue_vec_);
47 6432 : }
48 :
49 : //
50 : // Initialize static vectors of bgp/xmpp message pointers to NULL.
51 : //
52 2 : void RibOutUpdates::Initialize() {
53 2 : bgp_messages_.resize(DB::PartitionCount(), NULL);
54 2 : xmpp_messages_.resize(DB::PartitionCount(), NULL);
55 2 : }
56 :
57 : //
58 : // Free any memory allocated for bgp/xmpp messages.
59 : //
60 1 : void RibOutUpdates::Terminate() {
61 1 : STLDeleteValues(&bgp_messages_);
62 1 : STLDeleteValues(&xmpp_messages_);
63 1 : }
64 :
65 : //
66 : // Create if needed, and return the bgp/xmpp message for this RibOutUpdates.
67 : // Note that we use static vectors of bgp/xmpp messages, one per partition,
68 : // so that we don't need to allocate and free messages repeatedly.
69 : //
70 42568 : Message *RibOutUpdates::GetMessage() const {
71 42568 : if (ribout_->IsEncodingBgp()) {
72 10379 : if (!bgp_messages_[index_]) {
73 : MessageBuilder *builder =
74 4 : MessageBuilder::GetInstance(RibExportPolicy::BGP);
75 4 : Message *message = builder->Create();
76 4 : bgp_messages_[index_] = message;
77 : }
78 10379 : return bgp_messages_[index_];
79 : }
80 32187 : if (ribout_->IsEncodingXmpp()) {
81 32205 : if (!xmpp_messages_[index_]) {
82 : MessageBuilder *builder =
83 4 : MessageBuilder::GetInstance(RibExportPolicy::XMPP);
84 4 : Message *message = builder->Create();
85 4 : xmpp_messages_[index_] = message;
86 : }
87 32204 : return xmpp_messages_[index_];
88 : }
89 0 : return NULL;
90 : }
91 :
92 : //
93 : // Concurrency: Called in the context of the routing table partition task.
94 : //
95 : // Enqueue the RouteUpdate corresponding to the DBEntryBase into the queue.
96 : // This is called in the context of the routing table partition task. All
97 : // the concurrency issues are handled by going through the monitor.
98 : //
99 : // If the UpdateQueue corresponding to the RouteUpdate previously had no
100 : // updates after the tail marker, we kick the BgpUpdateSender to perform
101 : // a tail dequeue for the RibOut.
102 : //
103 60878 : void RibOutUpdates::Enqueue(DBEntryBase *db_entry, RouteUpdate *rt_update) {
104 60878 : CHECK_CONCURRENCY("db::DBTable");
105 :
106 60771 : bool need_tail_dequeue = monitor_->EnqueueUpdate(db_entry, rt_update);
107 60960 : if (need_tail_dequeue) {
108 39339 : ribout_->sender()->RibOutActive(index_, ribout_, rt_update->queue_id());
109 : }
110 60895 : }
111 :
112 : //
113 : // Concurrency: Called in the context of the bgp::SendUpdate task.
114 : //
115 : // Common dequeue routine invoked by tail dequeue and peer dequeue. It builds
116 : // and sends updates for each UpdateInfo element in the list hanging off the
117 : // RouteUpdate. For each update that it builds, it also includes prefixes for
118 : // other UpdateInfo elements that share the same attributes, provided that
119 : // the associated RouteUpdate was enqueued after the original one.
120 :
121 : // Each update is targeted at the peers in the RibPeerSet of the UpdateMarker
122 : // passed in to us. This set of peers is subsequently culled based on the
123 : // RibPeerSet in each UpdateInfo. IOW, the update is sent only to the set
124 : // of peers in the intersection of the UpdateMarker and the UpdateInfo. Note
125 : // that the UpdateMarker could specify a single peer if we are called from
126 : // peer dequeue.
127 : //
128 : // Return false if all the peers in the marker get blocked. In any case, the
129 : // blocked parameter is populated with the set of peers that are send blocked.
130 : //
131 42544 : bool RibOutUpdates::DequeueCommon(UpdateQueue *queue, UpdateMarker *marker,
132 : RouteUpdate *rt_update, RibPeerSet *blocked) {
133 42544 : CHECK_CONCURRENCY("bgp::SendUpdate");
134 :
135 : // Pass a hint to the Message telling it whether it needs to cache the
136 : // formatted version of each route. This is used only for xmpp messages.
137 : // Heuristic is to cache if there's markers other than the tail marker.
138 : // The reasoning is that the cached version can be used later when the
139 : // markers in question are being processed. Put another way - there's
140 : // no need to cache if route is not going to be advertised to any peers
141 : // other than the ones in the given UpdateMarker.
142 42574 : bool cache_routes = queue->marker_count() != 0;
143 :
144 : // Go through all UpdateInfo elements for the RouteUpdate.
145 42574 : int queue_id = rt_update->queue_id();
146 42573 : RibPeerSet rt_blocked;
147 42575 : for (UpdateInfoSList::List::iterator iter = rt_update->Updates()->begin();
148 171083 : iter != rt_update->Updates()->end();) {
149 : // Get the UpdateInfo and move the iterator to next one before doing
150 : // any processing, since we may delete the UpdateInfo further down.
151 42945 : UpdateInfo *uinfo = iter.operator->();
152 : ++iter;
153 :
154 : // Skip if there's no overlap between the UpdateMarker and the targets
155 : // for the UpdateInfo. The intersection is the set of peers to which
156 : // the message we are about to build will be sent.
157 42945 : RibPeerSet msgset;
158 42957 : msgset.BuildIntersection(uinfo->target, marker->members);
159 42922 : if (msgset.empty()) {
160 352 : continue;
161 : }
162 :
163 : // Generate the update, merge additional updates into that message and
164 : // send it message to the target RibPeerSet.
165 : //
166 : // In the rare case that the first route and it's attributes don't fit
167 : // into the message, clear the target bits in the UpdateInfo to ensure
168 : // that the UpdateQueue doesn't get wedged. However, don't update the
169 : // history bits in the RouteUpdate since the message did not get sent.
170 : //
171 : // The Create routine has the responsibility of logging an error and
172 : // incrementing any counters.
173 42569 : RibPeerSet msg_blocked;
174 42570 : stats_[queue_id].messages_built_count_++;
175 42570 : Message *message = GetMessage();
176 42565 : assert(message);
177 127741 : bool msg_built = message->Start(
178 42565 : ribout_, cache_routes, &uinfo->roattr, rt_update->route());
179 42613 : if (msg_built) {
180 42618 : UpdatePack(queue_id, message, uinfo, msgset);
181 42624 : message->Finish();
182 42621 : UpdateSend(queue_id, message, msgset, &msg_blocked);
183 : }
184 :
185 : // Reset bits in the UpdateInfo. Note that this has already been done
186 : // via UpdatePack for all the other UpdateInfo elements that we packed
187 : // into this message.
188 42643 : bool empty = ClearAdvertisedBits(rt_update, uinfo, msgset, msg_built);
189 42641 : if (empty) {
190 42642 : rt_update->RemoveUpdateInfo(uinfo);
191 : }
192 :
193 : // Update RibPeerSet of peers that got blocked while processing this
194 : // RouteUpdate. Since there's no overlap of peers between UpdateInfos
195 : // for the same RouteUpdate, we can update the markers for all blocked
196 : // peers in one shot i.e. outside this loop.
197 42640 : rt_blocked |= msg_blocked;
198 42986 : }
199 :
200 : // Update the markers for any peers that got blocked while processing this
201 : // RouteUpdate. If all peers in the UpdateMarker got blocked, we shouldn't
202 : // build any more update messages. Return false to let the callers know
203 : // that this has happened.
204 42581 : if (rt_blocked.empty()) {
205 42520 : return true;
206 : } else {
207 80 : *blocked |= rt_blocked;
208 80 : return !UpdateMarkersOnBlocked(marker, rt_update, &rt_blocked);
209 : }
210 42600 : }
211 :
212 : //
213 : // Concurrency: Called in the context of the bgp::SendUpdate task.
214 : //
215 : // Dequeue and build updates for the in-sync peers in the RibPeerSet of the
216 : // tail marker for the given queue id.
217 : //
218 : // Return false if all the peers in the marker get blocked. In any case, the
219 : // blocked parameter is populated with the set of peers that are send blocked
220 : // and the unsync parameter is populated with the set of peers from the tail
221 : // marker that are not in the msync set passed in to the method.
222 : //
223 42326 : bool RibOutUpdates::TailDequeue(int queue_id, const RibPeerSet &msync,
224 : RibPeerSet *blocked, RibPeerSet *unsync) {
225 42326 : CHECK_CONCURRENCY("bgp::SendUpdate");
226 :
227 42323 : stats_[queue_id].tail_dequeue_count_++;
228 42323 : UpdateQueue *queue = queue_vec_[queue_id];
229 42323 : UpdateMarker *start_marker = queue->tail_marker();
230 42323 : RouteUpdatePtr update = monitor_->GetNextUpdate(queue_id, start_marker);
231 :
232 42359 : if (update.get() == NULL) {
233 2 : return true;
234 : }
235 :
236 : // Intersect marker membership and in-sync peers to come up with the
237 : // unsync peers. If all the peers are unsync return right away. The
238 : // BgpUpdateSender will take care of triggering a TailDequeue again
239 : // when at least one peer becomes in-sync.
240 42357 : unsync->BuildComplement(start_marker->members, msync);
241 42325 : if (*unsync == start_marker->members) {
242 332 : return false;
243 : }
244 :
245 : // Split the unsync peers from the tail marker. Note that this updates
246 : // the RibPeerSet in the tail marker.
247 41991 : if (!unsync->empty()) {
248 204 : stats_[queue_id].marker_split_count_++;
249 204 : queue->MarkerSplit(start_marker, *unsync);
250 : }
251 :
252 : // Update send loop. Select next update to send, format a message.
253 : // Add other updates with the same attributes and replicate the
254 : // packet.
255 41989 : RibPeerSet members = start_marker->members;
256 41991 : RouteUpdatePtr next_update;
257 84518 : for (; update.get() != NULL; update = next_update) {
258 42541 : if (!DequeueCommon(queue, start_marker, update.get(), blocked)) {
259 : // Be sure to get rid of the RouteUpdate if it's empty.
260 48 : if (update->empty()) {
261 48 : ClearUpdate(&update);
262 : }
263 :
264 48 : return false;
265 : }
266 :
267 : // Iterate to the next update before we potentially delete the
268 : // current one. If there are no more updates in the queue, the
269 : // marker will get moved so that it's after the current update.
270 42546 : next_update = monitor_->GetNextUpdate(queue_id, update.get());
271 :
272 : // Be sure to get rid of the RouteUpdate if it's empty.
273 42539 : if (update->empty()) {
274 42184 : ClearUpdate(&update);
275 : }
276 : }
277 :
278 : // Request peers to flush accumulated update messages.
279 : // Return false if all peers got blocked.
280 41963 : UpdateFlush(members, blocked);
281 41979 : return (members != *blocked);
282 42365 : }
283 :
284 : //
285 : // Concurrency: Called in the context of the bgp::SendUpdate task.
286 : //
287 : // Dequeue and build updates for all the peers that share the same marker as
288 : // the specified peer. This routine has some extra intelligence beyond the
289 : // TailDequeue. As it encounters update markers, it merges in any send ready
290 : // peers from those with the marker being processed for dequeue. This is done
291 : // to reduce the number of times we build an update message containing the
292 : // the same information.
293 : //
294 : // Return false if all the peers in the marker get blocked. In any case, the
295 : // blocked parameter is populated with the set of peers that are send blocked.
296 : //
297 0 : bool RibOutUpdates::PeerDequeue(int queue_id, IPeerUpdate *peer,
298 : RibPeerSet *blocked) {
299 0 : CHECK_CONCURRENCY("bgp::SendUpdate");
300 :
301 0 : stats_[queue_id].peer_dequeue_count_++;
302 0 : UpdateQueue *queue = queue_vec_[queue_id];
303 0 : int peer_idx = ribout_->GetPeerIndex(peer);
304 0 : UpdateMarker *start_marker = queue->GetMarker(peer_idx);
305 :
306 : // We're done if this is the same as the tail marker. Updates will be
307 : // built subsequently via TailDequeue.
308 0 : assert(start_marker);
309 0 : if (start_marker == queue->tail_marker()) {
310 0 : return true;
311 : }
312 :
313 : // We're done if the lead peer is not send ready. This can happen if
314 : // the peer got blocked when processing updates in another partition.
315 0 : RibPeerSet mready;
316 0 : ribout_->BuildSendReadyBitSet(start_marker->members, &mready);
317 0 : if (!mready.test(peer_idx)) {
318 0 : blocked->set(peer_idx);
319 0 : return false;
320 : }
321 :
322 : // Split out any peers from the marker that are not send ready. Note that
323 : // this updates the RibPeerSet in the marker.
324 0 : RibPeerSet notready;
325 0 : notready.BuildComplement(start_marker->members, mready);
326 0 : if (!notready.empty()) {
327 0 : stats_[queue_id].marker_split_count_++;
328 0 : queue->MarkerSplit(start_marker, notready);
329 : }
330 :
331 : // Get the encapsulator for the first RouteUpdate. Even if there's no
332 : // RouteUpdate, we should find another marker or the tail marker.
333 : UpdateEntry *upentry;
334 : RouteUpdatePtr update =
335 0 : monitor_->GetNextEntry(queue_id, start_marker, &upentry);
336 0 : assert(upentry);
337 :
338 : // Update loop. Keep going till we reach the tail marker or till all the
339 : // peers get blocked.
340 0 : RibPeerSet members = start_marker->members;
341 0 : RouteUpdatePtr next_update;
342 : UpdateEntry *next_upentry;
343 0 : for (; upentry != NULL; upentry = next_upentry, update = next_update) {
344 0 : UpdateMarker *marker = NULL;
345 0 : if (upentry->IsMarker()) {
346 : // The queue entry is a marker. We're done if we've reached the
347 : // tail marker. Updates will be built later via TailDequeue.
348 0 : marker = static_cast<UpdateMarker *>(upentry);
349 0 : if (marker == queue->tail_marker()) {
350 0 : stats_[queue_id].marker_merge_count_++;
351 0 : queue->MarkerMerge(queue->tail_marker(), start_marker,
352 0 : start_marker->members);
353 0 : break;
354 : }
355 : } else {
356 : // The queue entry is a RouteUpdate. Go ahead and build an update
357 : // message. Bail if all the peers in the marker get blocked.
358 0 : if (!DequeueCommon(queue, start_marker, update.get(), blocked)) {
359 : // Be sure to get rid of the RouteUpdate if it's empty.
360 0 : if (update->empty()) {
361 0 : ClearUpdate(&update);
362 : }
363 0 : break;
364 : }
365 : }
366 :
367 : // Iterate to the next element before we potentially delete the
368 : // current one.
369 : next_update =
370 0 : monitor_->GetNextEntry(queue_id, upentry, &next_upentry);
371 :
372 0 : if (upentry->IsMarker()) {
373 : // As the entry is a marker, merge send-ready peers from it
374 : // with the marker that is being processed for dequeue. Note
375 : // that this updates the RibPeerSet in the marker.
376 0 : RibPeerSet mmove;
377 0 : ribout_->BuildSendReadyBitSet(marker->members, &mmove);
378 0 : if (!mmove.empty()) {
379 0 : stats_[queue_id].marker_merge_count_++;
380 0 : queue->MarkerMerge(start_marker, marker, mmove);
381 0 : members |= mmove;
382 : }
383 0 : } else if (update->empty()) {
384 : // Be sure to get rid of the RouteUpdate since it's empty.
385 0 : ClearUpdate(&update);
386 : }
387 : }
388 :
389 : // Request peers to flush accumulated update messages.
390 : // Return false if all peers got blocked.
391 0 : UpdateFlush(members, blocked);
392 0 : return (members != *blocked);
393 0 : }
394 :
395 : //
396 : // Concurrency: Called in the context of the bgp::SendUpdate task.
397 : //
398 : // Go through all the UpdateInfo elements that have the same attribute as
399 : // the start parameter and pack the corresponding prefixes into the Message.
400 : // The attributes and the prefix associated with start are already in the
401 : // Message when this method is invoked.
402 : //
403 : // The set of peers for which this update is being built is represented by
404 : // the msgset parameter. As the msgset has already been determined by the
405 : // caller, we should only add prefixes that need to go to all the peers in
406 : // the msgset.
407 : //
408 42611 : void RibOutUpdates::UpdatePack(int queue_id, Message *message,
409 : UpdateInfo *start_uinfo, const RibPeerSet &msgset) {
410 42611 : CHECK_CONCURRENCY("bgp::SendUpdate");
411 :
412 : UpdateInfo *uinfo, *next_uinfo;
413 42554 : RouteUpdatePtr next_update;
414 :
415 : // Walk through all the UpdateInfo elements with the same attribute in
416 : // enqueue order.
417 : RouteUpdatePtr update =
418 42552 : monitor_->GetAttrNext(queue_id, start_uinfo, &uinfo);
419 61453 : for (; update.get() != NULL; update = next_update, uinfo = next_uinfo) {
420 : // Iterate to the next element before we potentially delete the
421 : // current one.
422 18830 : next_update = monitor_->GetAttrNext(queue_id, uinfo, &next_uinfo);
423 :
424 : // Skip if the msgset RibPeerSet is not a subset of the target in
425 : // UpdateInfo.
426 18825 : if (!uinfo->target.Contains(msgset))
427 0 : continue;
428 :
429 : // Go ahead and add the route to the message. Terminate the loop
430 : // if the message doesn't have room for the route. The route will
431 : // get included in another update message.
432 18820 : bool success = message->AddRoute(update->route(), &uinfo->roattr);
433 18821 : if (!success) {
434 0 : break;
435 : }
436 :
437 : // First clear the advertised bits as represented by msgset from
438 : // the target RibPeerSet in the UpdateInfo. If the target is now
439 : // empty, remove the UpdateInfo from the list container in the
440 : // underlying RouteUpdate.
441 : //
442 : // If the RouteUpdate itself is now empty i.e. there are no more
443 : // UpdateInfo elements associated with it, we can get rid of it.
444 18821 : bool empty = ClearAdvertisedBits(update.get(), uinfo, msgset, true);
445 18816 : if (empty && update->RemoveUpdateInfo(uinfo)) {
446 18835 : ClearUpdate(&update);
447 : }
448 : }
449 42610 : }
450 :
451 : //
452 : // Concurrency: Called in the context of the bgp::SendUpdate task.
453 : //
454 : // Go through all the peers in the specified RibPeerSet and send the given
455 : // message to each of them. Update the blocked RibPeerSet with peers that
456 : // become blocked after sending the message.
457 : //
458 42617 : void RibOutUpdates::UpdateSend(int queue_id, Message *message,
459 : const RibPeerSet &dst, RibPeerSet *blocked) {
460 42617 : CHECK_CONCURRENCY("bgp::SendUpdate");
461 :
462 42575 : RibOut::PeerIterator iter(ribout_, dst);
463 173216 : while (iter.HasNext()) {
464 130548 : int ix_current = iter.index();
465 130541 : IPeerUpdate *peer = iter.Next();
466 130437 : size_t msgsize = 0;
467 130437 : const string *msg_str = NULL;
468 130437 : string temp;
469 130432 : const uint8_t *data = message->GetData(peer, &msgsize, &msg_str, &temp);
470 130443 : if (Sandesh::LoggingLevel() >= Sandesh::LoggingUtLevel()) {
471 155714 : BGP_LOG_PEER(Message, peer, Sandesh::LoggingUtLevel(),
472 : BGP_LOG_FLAG_SYSLOG, BGP_PEER_DIR_OUT,
473 : "Update size " << msgsize <<
474 : " reach " << message->num_reach_routes() <<
475 : " unreach " << message->num_unreach_routes());
476 : }
477 130621 : stats_[queue_id].messages_sent_count_++;
478 130621 : stats_[queue_id].reach_count_ += message->num_reach_routes();
479 130607 : stats_[queue_id].unreach_count_ += message->num_unreach_routes();
480 130608 : bool more = peer->SendUpdate(data, msgsize, msg_str);
481 130597 : if (!more) {
482 192 : blocked->set(ix_current);
483 : }
484 130619 : IPeer *ipeer = dynamic_cast<IPeer *>(peer);
485 130619 : if (!ipeer) {
486 0 : continue;
487 : }
488 130619 : IPeerDebugStats *stats = ipeer->peer_stats();
489 130614 : if (stats) {
490 130617 : stats->UpdateTxReachRoute(message->num_reach_routes());
491 130650 : stats->UpdateTxUnreachRoute(message->num_unreach_routes());
492 : }
493 130653 : }
494 42617 : }
495 :
496 : //
497 : // Concurrency: Called in the context of the bgp::SendUpdate task.
498 : //
499 : // Go through all the peers in the specified RibPeerSet and ask them to flush
500 : // i.e. send immediately, any accumulated updates. Update blocked RibPeerSet
501 : // with peers that become blocked after flushing.
502 : //
503 : // Skip if the RibOut is XMPP.
504 : //
505 41973 : void RibOutUpdates::UpdateFlush(const RibPeerSet &dst, RibPeerSet *blocked) {
506 41973 : CHECK_CONCURRENCY("bgp::SendUpdate");
507 :
508 41964 : if (ribout_->IsEncodingXmpp())
509 32139 : return;
510 :
511 9822 : RibOut::PeerIterator iter(ribout_, dst);
512 19668 : while (iter.HasNext()) {
513 9829 : int ix_current = iter.index();
514 9829 : IPeerUpdate *peer = iter.Next();
515 9830 : bool more = peer->FlushUpdate();
516 9839 : if (!more) {
517 0 : blocked->set(ix_current);
518 : }
519 : }
520 : }
521 :
522 : //
523 : // Take the AdvertisedInfo history in the RouteUpdate and move it to a new
524 : // RouteState. Go through the monitor to associate the new RouteState as the
525 : // listener state for the Route.
526 : //
527 37140 : void RibOutUpdates::StoreHistory(RouteUpdate *rt_update) {
528 37140 : CHECK_CONCURRENCY("bgp::SendUpdate");
529 :
530 37142 : BgpRoute *route = rt_update->route();
531 37142 : RouteState *rstate = new RouteState();
532 37142 : rt_update->MoveHistory(rstate);
533 37154 : monitor_->SetEntryState(route, rstate);
534 37172 : }
535 :
536 : //
537 : // Go through the monitor to clear the listener state for the underlying Route
538 : // of the RouteUpdate.
539 : //
540 23864 : void RibOutUpdates::ClearState(RouteUpdate *rt_update) {
541 23864 : CHECK_CONCURRENCY("bgp::SendUpdate");
542 :
543 23867 : BgpRoute *route = rt_update->route();
544 23867 : monitor_->ClearEntryState(route);
545 23908 : }
546 :
547 : //
548 : // Called when the RouteUpdate encapsulated by the RouteUpdatePtr has no more
549 : // UpdateInfo elements. Releases ownership of the RouteUpdate and deletes the
550 : // RouteUpdate, as well as any associated UpdateList if appropriate.
551 : //
552 61062 : void RibOutUpdates::ClearUpdate(RouteUpdatePtr *update) {
553 61062 : CHECK_CONCURRENCY("bgp::SendUpdate");
554 :
555 : // Dequeue the route update.
556 61020 : RouteUpdate *rt_update = update->get();
557 61015 : monitor_->DequeueUpdate(rt_update);
558 :
559 61011 : if (rt_update->OnUpdateList()) {
560 : // Remove the route update from the update list and check if the list
561 : // can now be downgraded back to a route update.
562 0 : UpdateList *uplist = rt_update->GetUpdateList(ribout_);
563 0 : uplist->RemoveUpdate(rt_update);
564 0 : RouteUpdate *last_rt_update = uplist->MakeRouteUpdate();
565 :
566 : // If we were able to downgrade, set the DBEntry to point to the last
567 : // remaining route update and get rid of the current route update and
568 : // the update list. Otherwise, just get rid of the route update.
569 0 : if (last_rt_update) {
570 0 : monitor_->SetEntryState(rt_update->route(), last_rt_update);
571 0 : update->release();
572 0 : delete rt_update;
573 0 : delete uplist;
574 : } else {
575 0 : update->release();
576 0 : delete rt_update;
577 : }
578 : } else {
579 : // Store the history from the route update or clear the state for the
580 : // DBEntry depending on whether we advertised the route. In either
581 : // case, get rid of the route update.
582 61014 : if (rt_update->IsAdvertised()) {
583 37140 : StoreHistory(rt_update);
584 : } else {
585 23862 : ClearState(rt_update);
586 : }
587 61073 : update->release();
588 61057 : delete rt_update;
589 : }
590 61033 : }
591 :
592 : //
593 : // Clear the advertised bits specified by isect from the target RibPeerSet in
594 : // the UpdateInfo. If the target is now empty, remove the UpdateInfo from the
595 : // set container in the UpdateQueue. Note that the UpdateInfo will still be
596 : // on the SList in the RouteUpdate.
597 : //
598 : // Return true if the UpdateInfo was removed from the set container.
599 : //
600 61467 : bool RibOutUpdates::ClearAdvertisedBits(RouteUpdate *rt_update,
601 : UpdateInfo *uinfo, const RibPeerSet &isect, bool update_history) {
602 61467 : CHECK_CONCURRENCY("bgp::SendUpdate");
603 :
604 61398 : if (update_history) {
605 61398 : rt_update->UpdateHistory(ribout_, &uinfo->roattr, isect);
606 : }
607 61422 : uinfo->target.Reset(isect);
608 61419 : bool empty = uinfo->target.empty();
609 61416 : if (empty) {
610 61415 : UpdateQueue *queue = queue_vec_[rt_update->queue_id()];
611 61411 : queue->AttrDequeue(uinfo);
612 : }
613 61446 : return empty;
614 : }
615 :
616 : //
617 : // Concurrency: Called in the context of the bgp::SendUpdate task.
618 : //
619 : // Update the markers for all the peers in the blocked RibPeerSet. In the
620 : // general case we clear the blocked RibPeerSet from the UpdateMarker and
621 : // create a new UpdateMarker for the blocked peers.
622 : //
623 : // Return true in the special case where all peers in the UpdateMarker have
624 : // become blocked.
625 : //
626 80 : bool RibOutUpdates::UpdateMarkersOnBlocked(UpdateMarker *marker,
627 : RouteUpdate *rt_update,
628 : const RibPeerSet *blocked) {
629 80 : CHECK_CONCURRENCY("bgp::SendUpdate");
630 :
631 80 : assert(!blocked->empty());
632 80 : int queue_id = rt_update->queue_id();
633 80 : UpdateQueue *queue = queue_vec_[queue_id];
634 :
635 : // If all the peers in the UpdateMarker are blocked, we simply move the
636 : // marker after the RouteUpdate.
637 80 : if (marker->members == *blocked) {
638 48 : stats_[queue_id].marker_move_count_++;
639 48 : queue->MoveMarker(marker, rt_update);
640 48 : return true;
641 : }
642 :
643 : // Reset bits in the specified UpdateMarker, create a new one for the
644 : // blocked peers and insert the new one after the RouteUpdate.
645 32 : marker->members.Reset(*blocked);
646 32 : assert(!marker->members.empty());
647 32 : UpdateMarker *new_marker = new UpdateMarker();
648 32 : new_marker->members = *blocked;
649 32 : stats_[queue_id].marker_split_count_++;
650 32 : queue->AddMarker(new_marker, rt_update);
651 :
652 32 : return false;
653 : }
654 :
655 0 : bool RibOutUpdates::Empty() const {
656 0 : for (int i = 0; i < RibOutUpdates::QCOUNT; ++i) {
657 0 : UpdateQueue *queue = queue_vec_[i];
658 0 : if (!queue->empty()) {
659 0 : return false;
660 : }
661 : }
662 0 : return true;
663 : }
664 :
665 0 : size_t RibOutUpdates::queue_size(int queue_id) const {
666 0 : const UpdateQueue *queue = queue_vec_[queue_id];
667 0 : return queue->size();
668 : }
669 :
670 0 : size_t RibOutUpdates::queue_marker_count(int queue_id) const {
671 0 : const UpdateQueue *queue = queue_vec_[queue_id];
672 0 : return queue->marker_count();
673 : }
674 :
675 17472 : bool RibOutUpdates::QueueJoin(int queue_id, int bit) {
676 17472 : UpdateQueue *queue = queue_vec_[queue_id];
677 17472 : return queue->Join(bit);
678 : }
679 :
680 17472 : void RibOutUpdates::QueueLeave(int queue_id, int bit) {
681 17472 : UpdateQueue *queue = queue_vec_[queue_id];
682 17472 : queue->Leave(bit);
683 17472 : }
684 :
685 : //
686 : // Add statistics information to the provided Stats structure.
687 : //
688 0 : void RibOutUpdates::AddStatisticsInfo(int queue_id, Stats *stats) const {
689 0 : stats->messages_built_count_ += stats_[queue_id].messages_built_count_;
690 0 : stats->messages_sent_count_ += stats_[queue_id].messages_sent_count_;
691 0 : stats->reach_count_ += stats_[queue_id].reach_count_;
692 0 : stats->unreach_count_ += stats_[queue_id].unreach_count_;
693 0 : stats->tail_dequeue_count_ += stats_[queue_id].tail_dequeue_count_;
694 0 : stats->peer_dequeue_count_ += stats_[queue_id].peer_dequeue_count_;
695 0 : stats->marker_split_count_ += stats_[queue_id].marker_split_count_;
696 0 : stats->marker_merge_count_ += stats_[queue_id].marker_merge_count_;
697 0 : stats->marker_move_count_ += stats_[queue_id].marker_move_count_;
698 0 : }
|