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