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: 35 76 46.1 %
Date: 2026-10-26 01:57:03 Functions: 11 24 45.8 %
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        1286 : BgpXmppPeerClose::BgpXmppPeerClose(BgpXmppChannel *channel) :
      22        1286 :         channel_(channel) {
      23        1286 : }
      24             : 
      25        2572 : BgpXmppPeerClose::~BgpXmppPeerClose() {
      26        2572 : }
      27             : 
      28        1286 : PeerCloseManager *BgpXmppPeerClose::GetManager() const {
      29        1286 :     return channel_->close_manager();
      30             : }
      31             : 
      32           0 : void BgpXmppPeerClose::UpdateRouteStats(Address::Family family,
      33             :                                         const BgpPath *old_path,
      34             :                                         uint32_t path_flags) const {
      35           0 :     GetManager()->UpdateRouteStats(family, old_path, path_flags);
      36           0 : }
      37             : 
      38           0 : bool BgpXmppPeerClose::IsReady() const {
      39           0 :     return channel_->Peer()->IsReady();
      40             : }
      41             : 
      42        7716 : IPeer *BgpXmppPeerClose::peer() const {
      43        7716 :     return channel_->Peer();
      44             : }
      45             : 
      46           0 : int BgpXmppPeerClose::GetGracefulRestartTime() const {
      47           0 :     return channel_->manager()->xmpp_server()->GetGracefulRestartTime();
      48             : }
      49             : 
      50           0 : int BgpXmppPeerClose::GetLongLivedGracefulRestartTime() const {
      51           0 :     return channel_->manager()->xmpp_server()->
      52           0 :         GetLongLivedGracefulRestartTime();
      53             : }
      54             : 
      55             : // Mark all current subscription as 'stale'
      56             : // Concurrency: Protected with a mutex from peer close manager
      57           0 : void BgpXmppPeerClose::GracefulRestartStale() {
      58           0 :     channel_->StaleCurrentSubscriptions();
      59           0 : }
      60             : 
      61             : // Mark all current subscriptions as 'llgr_stale'
      62             : // Concurrency: Protected with a mutex from peer close manager
      63           0 : void BgpXmppPeerClose::LongLivedGracefulRestartStale() {
      64           0 :     channel_->LlgrStaleCurrentSubscriptions();
      65           0 : }
      66             : 
      67             : // Delete all current subscriptions which are still stale.
      68             : // Concurrency: Protected with a mutex from peer close manager
      69           0 : void BgpXmppPeerClose::GracefulRestartSweep() {
      70           0 :     channel_->SweepCurrentSubscriptions();
      71           0 : }
      72             : 
      73        1286 : bool BgpXmppPeerClose::IsCloseGraceful() const {
      74             :     // Do not close gracefully if connection is already marked for deletion.
      75        1286 :     if (channel_->channel()->connection()->IsDeleted())
      76          24 :         return false;
      77        1262 :     return channel_->manager()->xmpp_server()->IsPeerCloseGraceful();
      78             : }
      79             : 
      80           0 : bool BgpXmppPeerClose::IsCloseLongLivedGraceful() const {
      81           0 :     return IsCloseGraceful() && GetLongLivedGracefulRestartTime() != 0;
      82             : }
      83             : 
      84             : // EoR from xmpp is afi independent at the moment.
      85           0 : void BgpXmppPeerClose::GetGracefulRestartFamilies(Families *families) const {
      86           0 :     families->insert(Address::UNSPEC);
      87           0 : }
      88             : 
      89           0 : void BgpXmppPeerClose::GetLongLivedGracefulRestartFamilies(Families *families) const {
      90           0 :     families->insert(Address::UNSPEC);
      91           0 : }
      92             : 
      93           0 : void BgpXmppPeerClose::ReceiveEndOfRIB(Address::Family family) {
      94           0 :     channel_->ReceiveEndOfRIB(family);
      95           0 : }
      96             : 
      97             : // Process any pending subscriptions as close manager is now no longer
      98             : // using membership manager.
      99           0 : void BgpXmppPeerClose::MembershipRequestCallbackComplete() {
     100           0 :     CHECK_CONCURRENCY(GetTaskName());
     101           0 :     if (channel_) {
     102           0 :         assert(!GetManager()->IsMembershipInUse());
     103           0 :         channel_->ProcessPendingSubscriptions();
     104             :     }
     105           0 : }
     106             : 
     107        6430 : const char *BgpXmppPeerClose::GetTaskName() const {
     108        6430 :     return "bgp::Config";
     109             : }
     110             : 
     111        1286 : int BgpXmppPeerClose::GetTaskInstance() const {
     112        1286 :     return 0;
     113             : }
     114             : 
     115        1286 : void BgpXmppPeerClose::CustomClose() {
     116        1286 :     channel_->rtarget_manager()->Close();
     117        1286 :     channel_->ClearSubscriptions();
     118        1286 : }
     119             : 
     120           0 : void BgpXmppPeerClose::CloseComplete() {
     121           0 :     assert(!channel_->channel()->connection()->IsDeleted());
     122           0 :     channel_->set_peer_closed(false);
     123           0 :     channel_->channel()->UnRegisterReceive(xmps::BGP);
     124           0 : }
     125             : 
     126        1286 : void BgpXmppPeerClose::Delete() {
     127        1286 :     channel_->set_delete_in_progress(true);
     128        1286 :     channel_->set_peer_closed(true);
     129        1286 :     channel_->manager()->increment_deleting_count();
     130        1286 :     channel_->manager()->Enqueue(channel_);
     131        1286 :     channel_ = NULL;
     132        1286 : }
     133             : 
     134        1286 : void BgpXmppPeerClose::Close(bool graceful) {
     135        1286 :     if (channel_) {
     136        1286 :         assert(channel_->peer_deleted());
     137        1286 :         if (!IsCloseGraceful())
     138        1286 :             graceful = false;
     139        1286 :         GetManager()->Close(graceful);
     140             :     }
     141        1286 : }

Generated by: LCOV version 1.14