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 10044 : BgpXmppPeerClose::BgpXmppPeerClose(BgpXmppChannel *channel) : 22 10044 : channel_(channel) { 23 10044 : } 24 : 25 20088 : BgpXmppPeerClose::~BgpXmppPeerClose() { 26 20088 : } 27 : 28 72512 : PeerCloseManager *BgpXmppPeerClose::GetManager() const { 29 72512 : return channel_->close_manager(); 30 : } 31 : 32 65902 : void BgpXmppPeerClose::UpdateRouteStats(Address::Family family, 33 : const BgpPath *old_path, 34 : uint32_t path_flags) const { 35 65902 : GetManager()->UpdateRouteStats(family, old_path, path_flags); 36 65902 : } 37 : 38 208 : bool BgpXmppPeerClose::IsReady() const { 39 208 : return channel_->Peer()->IsReady(); 40 : } 41 : 42 831658 : IPeer *BgpXmppPeerClose::peer() const { 43 831658 : 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 6570 : bool BgpXmppPeerClose::IsCloseGraceful() const { 74 : // Do not close gracefully if connection is already marked for deletion. 75 6570 : if (channel_->channel()->connection()->IsDeleted()) 76 1527 : return false; 77 5043 : 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 3629 : void BgpXmppPeerClose::MembershipRequestCallbackComplete() { 100 3629 : CHECK_CONCURRENCY(GetTaskName()); 101 3629 : if (channel_) { 102 264 : assert(!GetManager()->IsMembershipInUse()); 103 264 : channel_->ProcessPendingSubscriptions(); 104 : } 105 3629 : } 106 : 107 173300 : const char *BgpXmppPeerClose::GetTaskName() const { 108 173300 : return "bgp::Config"; 109 : } 110 : 111 10044 : int BgpXmppPeerClose::GetTaskInstance() const { 112 10044 : return 0; 113 : } 114 : 115 6180 : void BgpXmppPeerClose::CustomClose() { 116 6180 : channel_->rtarget_manager()->Close(); 117 6180 : channel_->ClearSubscriptions(); 118 6180 : } 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 6180 : void BgpXmppPeerClose::Delete() { 127 6180 : channel_->set_delete_in_progress(true); 128 6180 : channel_->set_peer_closed(true); 129 6180 : channel_->manager()->increment_deleting_count(); 130 6180 : channel_->manager()->Enqueue(channel_); 131 6180 : channel_ = NULL; 132 6180 : } 133 : 134 6346 : void BgpXmppPeerClose::Close(bool graceful) { 135 6346 : if (channel_) { 136 6346 : assert(channel_->peer_deleted()); 137 6346 : if (!IsCloseGraceful()) 138 6151 : graceful = false; 139 6346 : GetManager()->Close(graceful); 140 : } 141 6346 : }