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: 62 76 81.6 %
Date: 2026-11-16 02:06:09 Functions: 19 24 79.2 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14