LCOV - code coverage report
Current view: top level - bgp - bgp_xmpp_peer_close.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 76 76 100.0 %
Date: 2026-06-08 02:02:55 Functions: 24 24 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #include <boost/foreach.hpp>
       6             : #include <boost/scoped_ptr.hpp>
       7             : 
       8             : #include "base/task_annotations.h"
       9             : #include "bgp/bgp_factory.h"
      10             : #include "bgp/bgp_path.h"
      11             : #include "bgp/bgp_xmpp_peer_close.h"
      12             : #include "bgp/bgp_xmpp_rtarget_manager.h"
      13             : #include "bgp/peer_close_manager.h"
      14             : #include "bgp/bgp_xmpp_channel.h"
      15             : #include "xmpp/xmpp_connection.h"
      16             : #include "xmpp/xmpp_server.h"
      17             : 
      18             : using std::string;
      19             : using std::vector;
      20             : 
      21       10045 : BgpXmppPeerClose::BgpXmppPeerClose(BgpXmppChannel *channel) :
      22       10045 :         channel_(channel) {
      23       10045 : }
      24             : 
      25       20090 : BgpXmppPeerClose::~BgpXmppPeerClose() {
      26       20090 : }
      27             : 
      28       72531 : PeerCloseManager *BgpXmppPeerClose::GetManager() const {
      29       72531 :     return channel_->close_manager();
      30             : }
      31             : 
      32       65920 : void BgpXmppPeerClose::UpdateRouteStats(Address::Family family,
      33             :                                         const BgpPath *old_path,
      34             :                                         uint32_t path_flags) const {
      35       65920 :     GetManager()->UpdateRouteStats(family, old_path, path_flags);
      36       65919 : }
      37             : 
      38         208 : bool BgpXmppPeerClose::IsReady() const {
      39         208 :     return channel_->Peer()->IsReady();
      40             : }
      41             : 
      42      831544 : IPeer *BgpXmppPeerClose::peer() const {
      43      831544 :     return channel_->Peer();
      44             : }
      45             : 
      46         195 : int BgpXmppPeerClose::GetGracefulRestartTime() const {
      47         195 :     return channel_->manager()->xmpp_server()->GetGracefulRestartTime();
      48             : }
      49             : 
      50          58 : int BgpXmppPeerClose::GetLongLivedGracefulRestartTime() const {
      51          58 :     return channel_->manager()->xmpp_server()->
      52          58 :         GetLongLivedGracefulRestartTime();
      53             : }
      54             : 
      55             : // Mark all current subscription as 'stale'
      56             : // Concurrency: Protected with a mutex from peer close manager
      57         195 : void BgpXmppPeerClose::GracefulRestartStale() {
      58         195 :     channel_->StaleCurrentSubscriptions();
      59         195 : }
      60             : 
      61             : // Mark all current subscriptions as 'llgr_stale'
      62             : // Concurrency: Protected with a mutex from peer close manager
      63          29 : void BgpXmppPeerClose::LongLivedGracefulRestartStale() {
      64          29 :     channel_->LlgrStaleCurrentSubscriptions();
      65          29 : }
      66             : 
      67             : // Delete all current subscriptions which are still stale.
      68             : // Concurrency: Protected with a mutex from peer close manager
      69          40 : void BgpXmppPeerClose::GracefulRestartSweep() {
      70          40 :     channel_->SweepCurrentSubscriptions();
      71          40 : }
      72             : 
      73        6571 : bool BgpXmppPeerClose::IsCloseGraceful() const {
      74             :     // Do not close gracefully if connection is already marked for deletion.
      75        6571 :     if (channel_->channel()->connection()->IsDeleted())
      76        1525 :         return false;
      77        5046 :     return channel_->manager()->xmpp_server()->IsPeerCloseGraceful();
      78             : }
      79             : 
      80          29 : bool BgpXmppPeerClose::IsCloseLongLivedGraceful() const {
      81          29 :     return IsCloseGraceful() && GetLongLivedGracefulRestartTime() != 0;
      82             : }
      83             : 
      84             : // EoR from xmpp is afi independent at the moment.
      85         195 : void BgpXmppPeerClose::GetGracefulRestartFamilies(Families *families) const {
      86         195 :     families->insert(Address::UNSPEC);
      87         195 : }
      88             : 
      89          29 : void BgpXmppPeerClose::GetLongLivedGracefulRestartFamilies(Families *families) const {
      90          29 :     families->insert(Address::UNSPEC);
      91          29 : }
      92             : 
      93          12 : void BgpXmppPeerClose::ReceiveEndOfRIB(Address::Family family) {
      94          12 :     channel_->ReceiveEndOfRIB(family);
      95          12 : }
      96             : 
      97             : // Process any pending subscriptions as close manager is now no longer
      98             : // using membership manager.
      99        3625 : void BgpXmppPeerClose::MembershipRequestCallbackComplete() {
     100        3625 :     CHECK_CONCURRENCY(GetTaskName());
     101        3625 :     if (channel_) {
     102         264 :         assert(!GetManager()->IsMembershipInUse());
     103         264 :         channel_->ProcessPendingSubscriptions();
     104             :     }
     105        3625 : }
     106             : 
     107      173274 : const char *BgpXmppPeerClose::GetTaskName() const {
     108      173274 :     return "bgp::Config";
     109             : }
     110             : 
     111       10045 : int BgpXmppPeerClose::GetTaskInstance() const {
     112       10045 :     return 0;
     113             : }
     114             : 
     115        6181 : void BgpXmppPeerClose::CustomClose() {
     116        6181 :     channel_->rtarget_manager()->Close();
     117        6181 :     channel_->ClearSubscriptions();
     118        6181 : }
     119             : 
     120         224 : void BgpXmppPeerClose::CloseComplete() {
     121         224 :     assert(!channel_->channel()->connection()->IsDeleted());
     122         224 :     channel_->set_peer_closed(false);
     123         224 :     channel_->channel()->UnRegisterReceive(xmps::BGP);
     124         224 : }
     125             : 
     126        6181 : void BgpXmppPeerClose::Delete() {
     127        6181 :     channel_->set_delete_in_progress(true);
     128        6181 :     channel_->set_peer_closed(true);
     129        6181 :     channel_->manager()->increment_deleting_count();
     130        6181 :     channel_->manager()->Enqueue(channel_);
     131        6181 :     channel_ = NULL;
     132        6181 : }
     133             : 
     134        6347 : void BgpXmppPeerClose::Close(bool graceful) {
     135        6347 :     if (channel_) {
     136        6347 :         assert(channel_->peer_deleted());
     137        6347 :         if (!IsCloseGraceful())
     138        6152 :             graceful = false;
     139        6347 :         GetManager()->Close(graceful);
     140             :     }
     141        6347 : }

Generated by: LCOV version 1.14