7 #include <boost/foreach.hpp>
8 #include <boost/tuple/tuple.hpp>
18 #include "sandesh/request_pipeline.h"
19 #include "sandesh/common/vns_types.h"
20 #include "sandesh/common/vns_constants.h"
21 #include "sandesh/xmpp_server_types.h"
22 #include "sandesh/xmpp_trace_sandesh_types.h"
23 #include "sandesh/xmpp_client_server_sandesh_types.h"
26 using namespace boost::asio;
29 #define DEFAULT_XMPP_HOLD_TIME 90
33 :
LifetimeActor(server->lifetime_manager()), server_(server) {
37 return server_->MayDelete();
41 server_->SessionShutdown();
56 evm, ssl::context::sslv23_server, config->auth_enabled, true),
61 server_addr_(server_addr),
63 auth_enabled_(config->auth_enabled),
64 tcp_hold_time_(config->tcp_hold_time),
65 gr_helper_disable_(config->gr_helper_disable),
67 connection_queue_(
TaskScheduler::GetInstance()->GetTaskId(
"bgp::Config"),
73 boost::asio::ssl::context *ctx =
context();
74 boost::system::error_code ec;
77 ctx->set_options(ssl::context::default_workarounds |
78 ssl::context::no_sslv3 | ssl::context::no_sslv2, ec);
79 if (ec.value() != 0) {
80 LOG(ERROR,
"Error : " << ec.message() <<
", setting ssl options");
87 if (!ca_cert_filename.empty()) {
90 ctx->set_verify_mode(boost::asio::ssl::verify_peer, ec);
91 if (ec.value() != 0) {
92 LOG(ERROR,
"Error : " << ec.message()
93 <<
", while setting ssl verification mode");
98 if (ec.value() != 0) {
99 LOG(ERROR,
"Error : " << ec.message()
100 <<
", while using cacert file : "
108 boost::asio::ssl::context::pem, ec);
109 if (ec.value() != 0) {
110 LOG(ERROR,
"Error : " << ec.message()
111 <<
", while using server cert file : "
118 boost::asio::ssl::context::pem, ec);
119 if (ec.value() != 0) {
120 LOG(ERROR,
"Error : " << ec.message()
121 <<
", while using privkey file : "
146 if (server_->subcluster_name() != protocol_config->
subcluster_name()) {
148 server_->ClearAllConnections();
155 bool clear_peers = config_.gr_enable() || system->
gr_enable();
156 bool update_peers =
false;
157 config_.set_gr_enable(system->
gr_enable());
158 config_.set_gr_time(system->
gr_time());
159 config_.set_llgr_time(system->
llgr_time());
164 if (config_.fc_enabled() != system->
fc_enabled() ||
181 server_->ClearAllConnections();
182 else if (update_peers)
183 server_->UpdateAllConnections(config_.xmpp_hold_time());
188 server_->set_subcluster_name(name);
193 config_.set_xmpp_hold_time(hold_time);
226 auth_enabled_(false),
228 gr_helper_disable_(false),
230 connection_queue_(
TaskScheduler::GetInstance()->GetTaskId(
"bgp::Config"),
366 SOL_SOCKET, SO_REUSEADDR> reuse_addr_t;
370 boost::system::error_code err;
371 socket->open(ip::tcp::v4(), err);
376 socket->set_option(reuse_addr_t(
true), err);
421 if (value.second->ToString() == address)
430 if (value.second->GetComputeHostName() == hostname) {
431 value.second->Clear();
441 value.second->UpdateKeepAliveTimer(time_out);
448 value.second->Clear();
474 boost::system::error_code err;
532 ConnectionMap::iterator loc1 =
535 ConnectionMap::iterator loc2 =
538 swap(loc1->second, loc2->second);
539 swap(loc1->second->endpoint(), loc2->second->endpoint());
551 ConnectionMap::iterator loc;
554 tie(loc, result) =
connection_map_.insert(make_pair(endpoint, connection));
579 connection = XmppStaticObjectFactory::Create<XmppServerConnection>
620 if (old_connection) {
622 "Close duplicate connection " + session->
ToString());
656 ConnectionSet::iterator it;
676 const string &endpoint_name) {
678 ConnectionEndpointMap::const_iterator loc =
691 ConnectionEndpointMap::const_iterator loc =
696 conn_endpoint = loc->second;
702 return conn_endpoint;
709 make_pair(connection->
ToString(), conn_endpoint));
713 return conn_endpoint;
732 vector<ShowXmppConnection> *show_connection_list)
const {
736 ShowXmppConnection show_connection;
738 show_connection_list->push_back(show_connection);
741 ShowXmppConnection show_connection;
742 connection->FillShowInfo(&show_connection);
743 show_connection_list->push_back(show_connection);
748 SocketIOStats peer_socket_stats;
750 resp->set_rx_socket_stats(peer_socket_stats);
752 resp->set_tx_socket_stats(peer_socket_stats);
762 const ShowXmppConnectionReq *req =
763 static_cast<const ShowXmppConnectionReq *
>(ps.
snhRequest_.get());
767 ShowXmppConnectionResp *resp =
new ShowXmppConnectionResp;
768 vector<ShowXmppConnection> connections;
771 resp->set_connections(connections);
772 resp->set_context(req->context());
778 void ShowXmppConnectionReq::HandleRequest()
const {
788 ps.stages_.push_back(s1);
798 const ClearXmppConnectionReq *req =
799 static_cast<const ClearXmppConnectionReq *
>(ps.
snhRequest_.get());
803 ClearXmppConnectionResp *resp =
new ClearXmppConnectionResp;
805 resp->set_success(
false);
806 }
else if (req->get_hostname_or_all() !=
"all") {
808 resp->set_success(
true);
810 resp->set_success(
false);
815 resp->set_success(
true);
817 resp->set_success(
false);
821 resp->set_context(req->context());
827 void ClearXmppConnectionReq::HandleRequest()
const {
837 ps.stages_.push_back(s1);
846 const ShowXmppServerReq *req =
847 static_cast<const ShowXmppServerReq *
>(ps.
snhRequest_.get());
851 ShowXmppServerResp *resp =
new ShowXmppServerResp;
854 resp->set_context(req->context());
860 void ShowXmppServerReq::HandleRequest()
const {
867 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()
tbb::mutex endpoint_map_mutex_
XmppConnectionEndpoint * FindConnectionEndpoint(const std::string &endpoint_name)
size_t ConnectionEventCount() const
virtual XmppServerConnection * CreateConnection(XmppSession *session)
virtual void RemoveDeletedConnection(XmppServerConnection *connection)
virtual SslSession * AllocSession(SslSocket *socket)
tbb::mutex deletion_mutex_
size_t ConnectionCount() const
tbb::reader_writer_lock connection_map_mutex_
void FillShowConnections(std::vector< ShowXmppConnection > *show_connection_list) const
boost::function< void(XmppChannelMux *, xmps::PeerState)> ConnectionEventCb
virtual void RemoveConnection(XmppServerConnection *connection)
ConnectionEventCbMap connection_event_map_
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
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