8 #include <boost/foreach.hpp>
9 #include <boost/tuple/tuple.hpp>
19 #include "sandesh/request_pipeline.h"
20 #include "sandesh/common/vns_types.h"
21 #include "sandesh/common/vns_constants.h"
22 #include "sandesh/xmpp_server_types.h"
23 #include "sandesh/xmpp_trace_sandesh_types.h"
24 #include "sandesh/xmpp_client_server_sandesh_types.h"
27 using namespace boost::asio;
30 #define DEFAULT_XMPP_HOLD_TIME 90
34 :
LifetimeActor(server->lifetime_manager()), server_(server) {
38 return server_->MayDelete();
42 server_->SessionShutdown();
57 evm, ssl::context::sslv23_server, config->auth_enabled, true),
62 server_addr_(server_addr),
64 auth_enabled_(config->auth_enabled),
65 tcp_hold_time_(config->tcp_hold_time),
66 gr_helper_disable_(config->gr_helper_disable),
68 connection_queue_(
TaskScheduler::GetInstance()->GetTaskId(
"bgp::Config"),
74 boost::asio::ssl::context *ctx =
context();
75 boost::system::error_code ec;
78 ctx->set_options(ssl::context::default_workarounds |
79 ssl::context::no_sslv3 | ssl::context::no_sslv2, ec);
80 if (ec.value() != 0) {
81 LOG(ERROR,
"Error : " << ec.message() <<
", setting ssl options");
88 if (!ca_cert_filename.empty()) {
91 ctx->set_verify_mode(boost::asio::ssl::verify_peer, ec);
92 if (ec.value() != 0) {
93 LOG(ERROR,
"Error : " << ec.message()
94 <<
", while setting ssl verification mode");
99 if (ec.value() != 0) {
100 LOG(ERROR,
"Error : " << ec.message()
101 <<
", while using cacert file : "
109 boost::asio::ssl::context::pem, ec);
110 if (ec.value() != 0) {
111 LOG(ERROR,
"Error : " << ec.message()
112 <<
", while using server cert file : "
119 boost::asio::ssl::context::pem, ec);
120 if (ec.value() != 0) {
121 LOG(ERROR,
"Error : " << ec.message()
122 <<
", while using privkey file : "
147 if (server_->subcluster_name() != protocol_config->
subcluster_name()) {
149 server_->ClearAllConnections();
156 bool clear_peers = config_.gr_enable() || system->
gr_enable();
157 bool update_peers =
false;
158 config_.set_gr_enable(system->
gr_enable());
159 config_.set_gr_time(system->
gr_time());
160 config_.set_llgr_time(system->
llgr_time());
165 if (config_.fc_enabled() != system->
fc_enabled() ||
182 server_->ClearAllConnections();
183 else if (update_peers)
184 server_->UpdateAllConnections(config_.xmpp_hold_time());
189 server_->set_subcluster_name(name);
194 config_.set_xmpp_hold_time(hold_time);
227 auth_enabled_(false),
229 gr_helper_disable_(false),
231 connection_queue_(
TaskScheduler::GetInstance()->GetTaskId(
"bgp::Config"),
367 SOL_SOCKET, SO_REUSEADDR> reuse_addr_t;
371 boost::system::error_code err;
372 socket->open(ip::tcp::v4(), err);
377 socket->set_option(reuse_addr_t(
true), err);
422 if (value.second->ToString() == address)
431 if (value.second->GetComputeHostName() == hostname) {
432 value.second->Clear();
442 value.second->UpdateKeepAliveTimer(time_out);
449 value.second->Clear();
475 boost::system::error_code err;
533 ConnectionMap::iterator loc1 =
536 ConnectionMap::iterator loc2 =
539 swap(loc1->second, loc2->second);
540 swap(loc1->second->endpoint(), loc2->second->endpoint());
552 ConnectionMap::iterator loc;
555 tie(loc, result) =
connection_map_.insert(make_pair(endpoint, connection));
580 connection = XmppStaticObjectFactory::Create<XmppServerConnection>
621 if (old_connection) {
623 "Close duplicate connection " + session->
ToString());
657 ConnectionSet::iterator it;
677 const string &endpoint_name) {
679 ConnectionEndpointMap::const_iterator loc =
692 ConnectionEndpointMap::const_iterator loc =
697 conn_endpoint = loc->second;
703 return conn_endpoint;
710 make_pair(connection->
ToString(), conn_endpoint));
714 return conn_endpoint;
733 vector<ShowXmppConnection> *show_connection_list)
const {
737 ShowXmppConnection show_connection;
739 show_connection_list->push_back(show_connection);
742 ShowXmppConnection show_connection;
743 connection->FillShowInfo(&show_connection);
744 show_connection_list->push_back(show_connection);
749 SocketIOStats peer_socket_stats;
751 resp->set_rx_socket_stats(peer_socket_stats);
753 resp->set_tx_socket_stats(peer_socket_stats);
763 const ShowXmppConnectionReq *req =
764 static_cast<const ShowXmppConnectionReq *
>(ps.
snhRequest_.get());
768 ShowXmppConnectionResp *resp =
new ShowXmppConnectionResp;
769 vector<ShowXmppConnection> connections;
772 resp->set_connections(connections);
773 resp->set_context(req->context());
779 void ShowXmppConnectionReq::HandleRequest()
const {
789 ps.stages_.push_back(s1);
799 const ClearXmppConnectionReq *req =
800 static_cast<const ClearXmppConnectionReq *
>(ps.
snhRequest_.get());
804 ClearXmppConnectionResp *resp =
new ClearXmppConnectionResp;
806 resp->set_success(
false);
807 }
else if (req->get_hostname_or_all() !=
"all") {
809 resp->set_success(
true);
811 resp->set_success(
false);
816 resp->set_success(
true);
818 resp->set_success(
false);
822 resp->set_context(req->context());
828 void ClearXmppConnectionReq::HandleRequest()
const {
838 ps.stages_.push_back(s1);
847 const ShowXmppServerReq *req =
848 static_cast<const ShowXmppServerReq *
>(ps.
snhRequest_.get());
852 ShowXmppServerResp *resp =
new ShowXmppServerResp;
855 resp->set_context(req->context());
861 void ShowXmppServerReq::HandleRequest()
const {
868 ps.stages_.push_back(s1);
boost::asio::ip::address IpAddress
void RegisterObservers(const Observers &obs)
uint16_t end_of_rib_timeout() const
uint16_t rd_cluster_seed() const
uint32_t llgr_time() const
static const int kEndOfRibTime
uint8_t xmpp_hold_time() const
bool gr_xmpp_helper() const
const std::string & subcluster_name() const
static bool CallbackS1(const Sandesh *sr, const RequestPipeline::PipeSpec ps, int stage, int instNum, RequestPipeline::InstData *data)
static bool CallbackS1(const Sandesh *sr, const RequestPipeline::PipeSpec ps, int stage, int instNum, RequestPipeline::InstData *data)
static bool CallbackS1(const Sandesh *sr, const RequestPipeline::PipeSpec ps, int stage, int instNum, RequestPipeline::InstData *data)
boost::asio::ssl::stream< boost::asio::ip::tcp::socket > SslSocket
boost::asio::ssl::context * context()
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
int GetTaskId(const std::string &name)
static TaskScheduler * GetInstance()
Endpoint LocalEndpoint() const
void GetRxSocketStats(SocketIOStats *socket_stats) const
virtual bool Initialize(unsigned short port)
virtual TcpSession * CreateSession()
virtual void DeleteSession(TcpSession *session)
boost::asio::ip::tcp::socket Socket
void GetTxSocketStats(SocketIOStats *socket_stats) const
const std::string & ToUVEKey() const
virtual Socket * socket() const
virtual std::string ToString() const
void set_read_on_connect(bool read)
void set_observer(EventObserver observer)
Endpoint remote_endpoint() const
Endpoint local_endpoint() const
bool Enqueue(QueueEntryT entry)
void set_disable(bool disabled)
void Shutdown(bool delete_entries=true)
boost::asio::ip::tcp::endpoint local_endpoint
boost::asio::ip::tcp::endpoint endpoint
std::string path_to_ca_cert
std::string path_to_server_cert
std::string path_to_server_priv_key
void set_xmpp_hold_time(int hold_time)
const string subcluster_name() const
uint8_t xmpp_hold_time() const
BgpGlobalSystemConfig config_
void ProcessGlobalSystemConfig(const BgpGlobalSystemConfig *system, BgpConfigManager::EventType event)
XmppConfigUpdater(XmppServer *server, BgpConfigManager *config_manager)
void ProcessProtocolConfig(const BgpProtocolConfig *protocol_config, BgpConfigManager::EventType event)
const BgpGlobalSystemConfig & config() const
void set_subcluster_name(const string &name)
void set_connection(XmppConnection *connection)
XmppConnection * connection()
size_t GetSessionQueueSize() const
const XmppSession * session() const
virtual boost::asio::ip::tcp::endpoint endpoint() const
virtual bool AcceptSession(XmppSession *session)
int SetDscpValue(uint8_t value)
XmppStateMachine * state_machine()
const std::string & ToString() const
void set_session(XmppSession *session)
virtual void ManagedDelete()
XmppConnectionEndpoint * conn_endpoint()
void clear_on_work_queue()
void set_conn_endpoint(XmppConnectionEndpoint *conn_endpoint)
virtual void RetryDelete()
void FillShowInfo(ShowXmppConnection *show_connection) const
DeleteActor(XmppServer *server)
virtual bool MayDelete() const
uint32_t GetLongLivedGracefulRestartTime() const
virtual bool IsPeerCloseGraceful() const
void ClearAllConnections()
XmppServer(EventManager *evm, const std::string &server_addr, const XmppChannelConfig *config)
void SetDscpValue(uint8_t value)
LifetimeManager * lifetime_manager()
std::mutex deletion_mutex_
XmppConnectionEndpoint * FindConnectionEndpoint(const std::string &endpoint_name)
size_t ConnectionEventCount() const
virtual XmppServerConnection * CreateConnection(XmppSession *session)
virtual void RemoveDeletedConnection(XmppServerConnection *connection)
std::mutex endpoint_map_mutex_
virtual SslSession * AllocSession(SslSocket *socket)
size_t ConnectionCount() const
void FillShowConnections(std::vector< ShowXmppConnection > *show_connection_list) const
std::shared_mutex connection_map_mutex_
boost::function< void(XmppChannelMux *, xmps::PeerState)> ConnectionEventCb
virtual void RemoveConnection(XmppServerConnection *connection)
ConnectionEventCbMap connection_event_map_
std::shared_lock< std::shared_mutex > ReadLock
ConnectionSet deleted_connection_set_
virtual void InsertConnection(XmppServerConnection *connection)
virtual bool AcceptSession(TcpSession *session)
bool ClearConnection(const std::string &hostname)
void UnRegisterConnectionEvent(xmps::PeerId)
void SwapXmppConnectionMapEntries(XmppConnection *connection1, XmppConnection *connection2)
void CreateConfigUpdater(BgpConfigManager *config_manager)
ConnectionMap connection_map_
virtual TcpSession * CreateSession()
boost::scoped_ptr< DeleteActor > deleter_
void SetConnectionQueueDisable(bool disabled)
virtual bool Initialize(short port)
void ReleaseConnectionEndpoint(XmppServerConnection *connection)
bool IsGRHelperModeEnabled() const
WorkQueue< XmppServerConnection * > connection_queue_
bool DequeueConnection(XmppServerConnection *connection)
uint16_t GetGracefulRestartTime() const
XmppConnectionEndpoint * LocateConnectionEndpoint(XmppServerConnection *connection, bool &created)
size_t ConnectionMapSize() const
void RegisterConnectionEvent(xmps::PeerId, ConnectionEventCb)
virtual XmppServerConnection * FindConnection(Endpoint remote_endpoint)
boost::asio::ip::tcp::endpoint Endpoint
size_t GetConnectionQueueSize() const
boost::scoped_ptr< XmppConfigUpdater > xmpp_config_updater_
boost::scoped_ptr< LifetimeManager > lifetime_manager_
virtual LifetimeActor * deleter()
virtual void InsertDeletedConnection(XmppServerConnection *connection)
void NotifyConnectionEvent(XmppChannelMux *, xmps::PeerState)
uint32_t GetEndOfRibSendTime() const
void UpdateAllConnections(uint8_t time_out)
ConnectionEndpointMap connection_endpoint_map_
void FillShowServer(ShowXmppServerResp *resp) const
uint32_t GetEndOfRibReceiveTime() const
std::unique_lock< std::shared_mutex > WriteLock
boost::system::error_code EnableTcpKeepalive(int tcp_hold_time)
void set_hold_time(int hold_time)
void set_session(TcpSession *session)
virtual void OnSessionEvent(TcpSession *session, TcpSession::Event event)
#define LOG(_Level, _Msg)
BgpGlobalSystemConfigObserver system
BgpProtocolObserver protocol
boost::shared_ptr< const SandeshRequest > snhRequest_
std::vector< int > instances_
#define CHECK_CONCURRENCY(...)
void STLDeleteElements(Container *container)
#define XMPP_PEER_DIR_OUT
#define XMPP_WARNING(obj,...)
#define XMPP_DEBUG(obj,...)
#define DEFAULT_XMPP_HOLD_TIME