OpenSDN source code
bgp_ribout_updates.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
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 //
32  : ribout_(ribout),
33  index_(index) {
34  for (int i = 0; i < QCOUNT; i++) {
35  UpdateQueue *queue = new UpdateQueue(ribout, i);
36  queue_vec_.push_back(queue);
37  }
38  monitor_.reset(new RibUpdateMonitor(ribout, &queue_vec_));
39  memset(&stats_, 0, sizeof(stats_));
40 }
41 
42 //
43 // Destructor. Get rid of all the UpdateQueues.
44 //
47 }
48 
49 //
50 // Initialize static vectors of bgp/xmpp message pointers to NULL.
51 //
53  bgp_messages_.resize(DB::PartitionCount(), NULL);
54  xmpp_messages_.resize(DB::PartitionCount(), NULL);
55 }
56 
57 //
58 // Free any memory allocated for bgp/xmpp messages.
59 //
63 }
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 //
71  if (ribout_->IsEncodingBgp()) {
72  if (!bgp_messages_[index_]) {
73  MessageBuilder *builder =
75  Message *message = builder->Create();
76  bgp_messages_[index_] = message;
77  }
78  return bgp_messages_[index_];
79  }
80  if (ribout_->IsEncodingXmpp()) {
81  if (!xmpp_messages_[index_]) {
82  MessageBuilder *builder =
84  Message *message = builder->Create();
85  xmpp_messages_[index_] = message;
86  }
87  return xmpp_messages_[index_];
88  }
89  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 void RibOutUpdates::Enqueue(DBEntryBase *db_entry, RouteUpdate *rt_update) {
104  CHECK_CONCURRENCY("db::DBTable");
105 
106  bool need_tail_dequeue = monitor_->EnqueueUpdate(db_entry, rt_update);
107  if (need_tail_dequeue) {
108  ribout_->sender()->RibOutActive(index_, ribout_, rt_update->queue_id());
109  }
110 }
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 //
132  RouteUpdate *rt_update, RibPeerSet *blocked) {
133  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  bool cache_routes = queue->marker_count() != 0;
143 
144  // Go through all UpdateInfo elements for the RouteUpdate.
145  int queue_id = rt_update->queue_id();
146  RibPeerSet rt_blocked;
147  for (UpdateInfoSList::List::iterator iter = rt_update->Updates()->begin();
148  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  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  RibPeerSet msgset;
158  msgset.BuildIntersection(uinfo->target, marker->members);
159  if (msgset.empty()) {
160  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  RibPeerSet msg_blocked;
174  stats_[queue_id].messages_built_count_++;
175  Message *message = GetMessage();
176  assert(message);
177  bool msg_built = message->Start(
178  ribout_, cache_routes, &uinfo->roattr, rt_update->route());
179  if (msg_built) {
180  UpdatePack(queue_id, message, uinfo, msgset);
181  message->Finish();
182  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  bool empty = ClearAdvertisedBits(rt_update, uinfo, msgset, msg_built);
189  if (empty) {
190  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  rt_blocked |= msg_blocked;
198  }
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  if (rt_blocked.empty()) {
205  return true;
206  } else {
207  *blocked |= rt_blocked;
208  return !UpdateMarkersOnBlocked(marker, rt_update, &rt_blocked);
209  }
210 }
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 bool RibOutUpdates::TailDequeue(int queue_id, const RibPeerSet &msync,
224  RibPeerSet *blocked, RibPeerSet *unsync) {
225  CHECK_CONCURRENCY("bgp::SendUpdate");
226 
227  stats_[queue_id].tail_dequeue_count_++;
228  UpdateQueue *queue = queue_vec_[queue_id];
229  UpdateMarker *start_marker = queue->tail_marker();
230  RouteUpdatePtr update = monitor_->GetNextUpdate(queue_id, start_marker);
231 
232  if (update.get() == NULL) {
233  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  unsync->BuildComplement(start_marker->members, msync);
241  if (*unsync == start_marker->members) {
242  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  if (!unsync->empty()) {
248  stats_[queue_id].marker_split_count_++;
249  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  RibPeerSet members = start_marker->members;
256  RouteUpdatePtr next_update;
257  for (; update.get() != NULL; update = next_update) {
258  if (!DequeueCommon(queue, start_marker, update.get(), blocked)) {
259  // Be sure to get rid of the RouteUpdate if it's empty.
260  if (update->empty()) {
261  ClearUpdate(&update);
262  }
263 
264  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  next_update = monitor_->GetNextUpdate(queue_id, update.get());
271 
272  // Be sure to get rid of the RouteUpdate if it's empty.
273  if (update->empty()) {
274  ClearUpdate(&update);
275  }
276  }
277 
278  // Request peers to flush accumulated update messages.
279  // Return false if all peers got blocked.
280  UpdateFlush(members, blocked);
281  return (members != *blocked);
282 }
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 bool RibOutUpdates::PeerDequeue(int queue_id, IPeerUpdate *peer,
298  RibPeerSet *blocked) {
299  CHECK_CONCURRENCY("bgp::SendUpdate");
300 
301  stats_[queue_id].peer_dequeue_count_++;
302  UpdateQueue *queue = queue_vec_[queue_id];
303  int peer_idx = ribout_->GetPeerIndex(peer);
304  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  assert(start_marker);
309  if (start_marker == queue->tail_marker()) {
310  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  RibPeerSet mready;
316  ribout_->BuildSendReadyBitSet(start_marker->members, &mready);
317  if (!mready.test(peer_idx)) {
318  blocked->set(peer_idx);
319  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  RibPeerSet notready;
325  notready.BuildComplement(start_marker->members, mready);
326  if (!notready.empty()) {
327  stats_[queue_id].marker_split_count_++;
328  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  monitor_->GetNextEntry(queue_id, start_marker, &upentry);
336  assert(upentry);
337 
338  // Update loop. Keep going till we reach the tail marker or till all the
339  // peers get blocked.
340  RibPeerSet members = start_marker->members;
341  RouteUpdatePtr next_update;
342  UpdateEntry *next_upentry;
343  for (; upentry != NULL; upentry = next_upentry, update = next_update) {
344  UpdateMarker *marker = NULL;
345  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  marker = static_cast<UpdateMarker *>(upentry);
349  if (marker == queue->tail_marker()) {
350  stats_[queue_id].marker_merge_count_++;
351  queue->MarkerMerge(queue->tail_marker(), start_marker,
352  start_marker->members);
353  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  if (!DequeueCommon(queue, start_marker, update.get(), blocked)) {
359  // Be sure to get rid of the RouteUpdate if it's empty.
360  if (update->empty()) {
361  ClearUpdate(&update);
362  }
363  break;
364  }
365  }
366 
367  // Iterate to the next element before we potentially delete the
368  // current one.
369  next_update =
370  monitor_->GetNextEntry(queue_id, upentry, &next_upentry);
371 
372  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  RibPeerSet mmove;
377  ribout_->BuildSendReadyBitSet(marker->members, &mmove);
378  if (!mmove.empty()) {
379  stats_[queue_id].marker_merge_count_++;
380  queue->MarkerMerge(start_marker, marker, mmove);
381  members |= mmove;
382  }
383  } else if (update->empty()) {
384  // Be sure to get rid of the RouteUpdate since it's empty.
385  ClearUpdate(&update);
386  }
387  }
388 
389  // Request peers to flush accumulated update messages.
390  // Return false if all peers got blocked.
391  UpdateFlush(members, blocked);
392  return (members != *blocked);
393 }
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 void RibOutUpdates::UpdatePack(int queue_id, Message *message,
409  UpdateInfo *start_uinfo, const RibPeerSet &msgset) {
410  CHECK_CONCURRENCY("bgp::SendUpdate");
411 
412  UpdateInfo *uinfo, *next_uinfo;
413  RouteUpdatePtr next_update;
414 
415  // Walk through all the UpdateInfo elements with the same attribute in
416  // enqueue order.
417  RouteUpdatePtr update =
418  monitor_->GetAttrNext(queue_id, start_uinfo, &uinfo);
419  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  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  if (!uinfo->target.Contains(msgset))
427  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  bool success = message->AddRoute(update->route(), &uinfo->roattr);
433  if (!success) {
434  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  bool empty = ClearAdvertisedBits(update.get(), uinfo, msgset, true);
445  if (empty && update->RemoveUpdateInfo(uinfo)) {
446  ClearUpdate(&update);
447  }
448  }
449 }
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 void RibOutUpdates::UpdateSend(int queue_id, Message *message,
459  const RibPeerSet &dst, RibPeerSet *blocked) {
460  CHECK_CONCURRENCY("bgp::SendUpdate");
461 
462  RibOut::PeerIterator iter(ribout_, dst);
463  while (iter.HasNext()) {
464  int ix_current = iter.index();
465  IPeerUpdate *peer = iter.Next();
466  size_t msgsize = 0;
467  const string *msg_str = NULL;
468  string temp;
469  const uint8_t *data = message->GetData(peer, &msgsize, &msg_str, &temp);
473  "Update size " << msgsize <<
474  " reach " << message->num_reach_routes() <<
475  " unreach " << message->num_unreach_routes());
476  }
477  stats_[queue_id].messages_sent_count_++;
478  stats_[queue_id].reach_count_ += message->num_reach_routes();
479  stats_[queue_id].unreach_count_ += message->num_unreach_routes();
480  bool more = peer->SendUpdate(data, msgsize, msg_str);
481  if (!more) {
482  blocked->set(ix_current);
483  }
484  IPeer *ipeer = dynamic_cast<IPeer *>(peer);
485  if (!ipeer) {
486  continue;
487  }
488  IPeerDebugStats *stats = ipeer->peer_stats();
489  if (stats) {
490  stats->UpdateTxReachRoute(message->num_reach_routes());
491  stats->UpdateTxUnreachRoute(message->num_unreach_routes());
492  }
493  }
494 }
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 //
506  CHECK_CONCURRENCY("bgp::SendUpdate");
507 
508  if (ribout_->IsEncodingXmpp())
509  return;
510 
511  RibOut::PeerIterator iter(ribout_, dst);
512  while (iter.HasNext()) {
513  int ix_current = iter.index();
514  IPeerUpdate *peer = iter.Next();
515  bool more = peer->FlushUpdate();
516  if (!more) {
517  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 //
528  CHECK_CONCURRENCY("bgp::SendUpdate");
529 
530  BgpRoute *route = rt_update->route();
531  RouteState *rstate = new RouteState();
532  rt_update->MoveHistory(rstate);
533  monitor_->SetEntryState(route, rstate);
534 }
535 
536 //
537 // Go through the monitor to clear the listener state for the underlying Route
538 // of the RouteUpdate.
539 //
541  CHECK_CONCURRENCY("bgp::SendUpdate");
542 
543  BgpRoute *route = rt_update->route();
544  monitor_->ClearEntryState(route);
545 }
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 //
553  CHECK_CONCURRENCY("bgp::SendUpdate");
554 
555  // Dequeue the route update.
556  RouteUpdate *rt_update = update->get();
557  monitor_->DequeueUpdate(rt_update);
558 
559  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  UpdateList *uplist = rt_update->GetUpdateList(ribout_);
563  uplist->RemoveUpdate(rt_update);
564  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  if (last_rt_update) {
570  monitor_->SetEntryState(rt_update->route(), last_rt_update);
571  update->release();
572  delete rt_update;
573  delete uplist;
574  } else {
575  update->release();
576  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  if (rt_update->IsAdvertised()) {
583  StoreHistory(rt_update);
584  } else {
585  ClearState(rt_update);
586  }
587  update->release();
588  delete rt_update;
589  }
590 }
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 //
601  UpdateInfo *uinfo, const RibPeerSet &isect, bool update_history) {
602  CHECK_CONCURRENCY("bgp::SendUpdate");
603 
604  if (update_history) {
605  rt_update->UpdateHistory(ribout_, &uinfo->roattr, isect);
606  }
607  uinfo->target.Reset(isect);
608  bool empty = uinfo->target.empty();
609  if (empty) {
610  UpdateQueue *queue = queue_vec_[rt_update->queue_id()];
611  queue->AttrDequeue(uinfo);
612  }
613  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 //
627  RouteUpdate *rt_update,
628  const RibPeerSet *blocked) {
629  CHECK_CONCURRENCY("bgp::SendUpdate");
630 
631  assert(!blocked->empty());
632  int queue_id = rt_update->queue_id();
633  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  if (marker->members == *blocked) {
638  stats_[queue_id].marker_move_count_++;
639  queue->MoveMarker(marker, rt_update);
640  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  marker->members.Reset(*blocked);
646  assert(!marker->members.empty());
647  UpdateMarker *new_marker = new UpdateMarker();
648  new_marker->members = *blocked;
649  stats_[queue_id].marker_split_count_++;
650  queue->AddMarker(new_marker, rt_update);
651 
652  return false;
653 }
654 
655 bool RibOutUpdates::Empty() const {
656  for (int i = 0; i < RibOutUpdates::QCOUNT; ++i) {
658  if (!queue->empty()) {
659  return false;
660  }
661  }
662  return true;
663 }
664 
665 size_t RibOutUpdates::queue_size(int queue_id) const {
666  const UpdateQueue *queue = queue_vec_[queue_id];
667  return queue->size();
668 }
669 
670 size_t RibOutUpdates::queue_marker_count(int queue_id) const {
671  const UpdateQueue *queue = queue_vec_[queue_id];
672  return queue->marker_count();
673 }
674 
675 bool RibOutUpdates::QueueJoin(int queue_id, int bit) {
676  UpdateQueue *queue = queue_vec_[queue_id];
677  return queue->Join(bit);
678 }
679 
680 void RibOutUpdates::QueueLeave(int queue_id, int bit) {
681  UpdateQueue *queue = queue_vec_[queue_id];
682  queue->Leave(bit);
683 }
684 
685 //
686 // Add statistics information to the provided Stats structure.
687 //
688 void RibOutUpdates::AddStatisticsInfo(int queue_id, Stats *stats) const {
691  stats->reach_count_ += stats_[queue_id].reach_count_;
692  stats->unreach_count_ += stats_[queue_id].unreach_count_;
693  stats->tail_dequeue_count_ += stats_[queue_id].tail_dequeue_count_;
694  stats->peer_dequeue_count_ += stats_[queue_id].peer_dequeue_count_;
695  stats->marker_split_count_ += stats_[queue_id].marker_split_count_;
696  stats->marker_merge_count_ += stats_[queue_id].marker_merge_count_;
697  stats->marker_move_count_ += stats_[queue_id].marker_move_count_;
698 }
#define BGP_LOG_FLAG_SYSLOG
Definition: bgp_log.h:43
#define BGP_LOG_PEER(type, peer, level, flags, dir, arg)
Definition: bgp_log.h:160
#define BGP_PEER_DIR_OUT
Definition: bgp_log.h:139
void RibOutActive(int index, RibOut *ribout, int queue_id)
void BuildComplement(const BitSet &lhs, const BitSet &rhs)
Definition: bitset.cc:487
void Reset(const BitSet &rhs)
Definition: bitset.cc:471
bool empty() const
Definition: bitset.cc:166
bool Contains(const BitSet &rhs) const
Definition: bitset.cc:537
BitSet & set(size_t pos)
Definition: bitset.cc:126
bool test(size_t pos) const
Definition: bitset.cc:147
void BuildIntersection(const BitSet &lhs, const BitSet &rhs)
Definition: bitset.cc:510
static int PartitionCount()
Definition: db.cc:32
virtual void UpdateTxReachRoute(uint64_t count)=0
virtual void UpdateTxUnreachRoute(uint64_t count)=0
virtual bool SendUpdate(const uint8_t *msg, size_t msgsize)=0
virtual bool FlushUpdate()
Definition: ipeer.h:39
Definition: ipeer.h:187
virtual IPeerDebugStats * peer_stats()=0
virtual Message * Create() const =0
static MessageBuilder * GetInstance(RibExportPolicy::Encoding encoding)
uint64_t num_unreach_routes() const
uint64_t num_reach_routes() const
virtual const uint8_t * GetData(IPeerUpdate *peer_update, size_t *lenp, const std::string **msg_str, std::string *temp)=0
virtual bool Start(const RibOut *ribout, bool cache_routes, const RibOutAttr *roattr, const BgpRoute *route)=0
virtual bool AddRoute(const BgpRoute *route, const RibOutAttr *roattr)=0
virtual void Finish()=0
void ClearUpdate(RouteUpdatePtr *update)
bool Empty() const
void Enqueue(DBEntryBase *db_entry, RouteUpdate *rt_update)
size_t queue_size(int queue_id) const
bool UpdateMarkersOnBlocked(UpdateMarker *marker, RouteUpdate *rt_update, const RibPeerSet *blocked)
Stats stats_[QCOUNT]
boost::scoped_ptr< RibUpdateMonitor > monitor_
bool ClearAdvertisedBits(RouteUpdate *rt_update, UpdateInfo *uinfo, const RibPeerSet &bits, bool update_history)
virtual bool PeerDequeue(int queue_id, IPeerUpdate *peer, RibPeerSet *blocked)
static void Initialize()
UpdateQueue * queue(int queue_id)
static void Terminate()
size_t queue_marker_count(int queue_id) const
virtual ~RibOutUpdates()
void StoreHistory(RouteUpdate *rt_update)
static std::vector< Message * > xmpp_messages_
void AddStatisticsInfo(int queue_id, Stats *stats) const
bool QueueJoin(int queue_id, int bit)
void QueueLeave(int queue_id, int bit)
void UpdateSend(int queue_id, Message *message, const RibPeerSet &dst, RibPeerSet *blocked)
bool DequeueCommon(UpdateQueue *queue, UpdateMarker *marker, RouteUpdate *rt_update, RibPeerSet *blocked)
void ClearState(RouteUpdate *rt_update)
RibOutUpdates(RibOut *ribout, int index)
void UpdatePack(int queue_id, Message *message, UpdateInfo *start_uinfo, const RibPeerSet &isect)
Message * GetMessage() const
void UpdateFlush(const RibPeerSet &dst, RibPeerSet *blocked)
virtual bool TailDequeue(int queue_id, const RibPeerSet &msync, RibPeerSet *blocked, RibPeerSet *unsync)
static std::vector< Message * > bgp_messages_
IPeerUpdate * Next()
Definition: bgp_ribout.h:273
bool HasNext() const
Definition: bgp_ribout.h:270
int index() const
Definition: bgp_ribout.h:278
bool IsEncodingBgp() const
Definition: bgp_ribout.h:333
BgpUpdateSender * sender()
Definition: bgp_ribout.h:308
int GetPeerIndex(IPeerUpdate *peer) const
Definition: bgp_ribout.cc:545
bool IsEncodingXmpp() const
Definition: bgp_ribout.h:330
void BuildSendReadyBitSet(const RibPeerSet &peerset, RibPeerSet *mready) const
Definition: bgp_ribout.cc:435
RouteUpdate * get()
int queue_id() const
Definition: bgp_update.h:230
UpdateList * GetUpdateList(RibOut *ribout)
Definition: bgp_update.cc:406
bool IsAdvertised() const
Definition: bgp_update.cc:376
void MoveHistory(RouteState *rstate)
Definition: bgp_update.cc:297
bool RemoveUpdateInfo(UpdateInfo *uinfo)
Definition: bgp_update.cc:61
BgpRoute * route()
Definition: bgp_update.h:228
UpdateInfoSList & Updates()
Definition: bgp_update.h:215
void UpdateHistory(RibOut *ribout, const RibOutAttr *roattr, const RibPeerSet &bits)
Definition: bgp_update.cc:320
bool empty() const
Definition: bgp_update.h:236
bool OnUpdateList()
Definition: bgp_update.h:221
static SandeshLevel::type LoggingLevel()
Definition: cpp/sandesh.h:224
static SandeshLevel::type LoggingUtLevel()
Definition: cpp/sandesh.h:225
bool IsMarker()
Definition: bgp_update.h:37
void RemoveUpdate(RouteUpdate *rt_update)
Definition: bgp_update.cc:468
RouteUpdate * MakeRouteUpdate()
Definition: bgp_update.cc:493
void MarkerSplit(UpdateMarker *marker, const RibPeerSet &msplit)
UpdateMarker * tail_marker()
void AddMarker(UpdateMarker *marker, RouteUpdate *rt_update)
bool Join(int bit)
void MarkerMerge(UpdateMarker *dst_marker, UpdateMarker *src_marker, const RibPeerSet &bitset)
void MoveMarker(UpdateMarker *marker, RouteUpdate *rt_update)
bool empty() const
UpdateMarker * GetMarker(int bit)
size_t marker_count() const
void Leave(int bit)
size_t size() const
void AttrDequeue(UpdateInfo *current_uinfo)
RibOutAttr roattr
Definition: bgp_update.h:101
RibPeerSet target
Definition: bgp_update.h:104
RibPeerSet members
Definition: bgp_update.h:56
#define CHECK_CONCURRENCY(...)
void STLDeleteValues(Container *container)
Definition: util.h:102