From c7526418d9322156194b9abefff575a0d2384409 Mon Sep 17 00:00:00 2001 From: Ananth Suryanarayana Date: Tue, 19 Jul 2016 13:07:07 -0700 Subject: [PATCH] Add ability to selectively skip sending xmpp updates In scaled setups, we want to minimuze cpu consumed by actual data send over tcp. Instead of sending and dropping right after read at the receiver end, we can have an option not send data at all. This was there, but limited as a binary option. With this change, one can filter destinations to which the updates send must be skipped, based on regex pattern match as specified in the environment variable XMPP_SKIP_UPDATE_SEND Change-Id: I078887186e6df2fb7be5b7a6b6b44d7c40a7e6e8 Partial-Bug: 1464016 --- src/bgp/bgp_xmpp_channel.cc | 27 ++++++++++++++++----------- src/bgp/bgp_xmpp_channel.h | 1 + 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/bgp/bgp_xmpp_channel.cc b/src/bgp/bgp_xmpp_channel.cc index 4417bb2cfe3..def8c17b64a 100644 --- a/src/bgp/bgp_xmpp_channel.cc +++ b/src/bgp/bgp_xmpp_channel.cc @@ -5,10 +5,11 @@ #include "bgp/bgp_xmpp_channel.h" #include +#include #include -#include #include +#include #include "base/task_annotations.h" #include "bgp/bgp_config.h" @@ -52,6 +53,9 @@ using autogen::SecurityGroupListType; using autogen::CommunityTagListType; using autogen::TunnelEncapsulationListType; +using boost::regex; +using boost::regex_search; +using boost::smatch; using boost::system::error_code; using pugi::xml_node; using std::auto_ptr; @@ -536,23 +540,24 @@ class BgpXmppChannel::XmppPeer : public IPeer { uint64_t closed_at_; }; -static bool SkipUpdateSend() { - static bool init_; - static bool skip_; - - if (init_) return skip_; - - skip_ = getenv("XMPP_SKIP_UPDATE_SEND") != NULL; - init_ = true; +// Skip sending updates if the destinatin matches against the pattern. +// XX Used in test environments only +bool BgpXmppChannel::SkipUpdateSend() const { + static char *skip_env_ = getenv("XMPP_SKIP_UPDATE_SEND"); + if (!skip_env_) + return false; - return skip_; + // Use XMPP_SKIP_UPDATE_SEND as a regex pattern to match against destination + smatch matches; + return regex_search(ToString(), matches, regex(skip_env_)); } bool BgpXmppChannel::XmppPeer::SendUpdate(const uint8_t *msg, size_t msgsize) { XmppChannel *channel = parent_->channel_; if (channel->GetPeerState() == xmps::READY) { parent_->stats_[TX].rt_updates++; - if (SkipUpdateSend()) return true; + if (parent_->SkipUpdateSend()) + return true; send_ready_ = channel->Send(msg, msgsize, xmps::BGP, boost::bind(&BgpXmppChannel::XmppPeer::WriteReadyCb, this, _1)); if (!send_ready_) { diff --git a/src/bgp/bgp_xmpp_channel.h b/src/bgp/bgp_xmpp_channel.h index ea98bfc171f..2eb76a94c35 100644 --- a/src/bgp/bgp_xmpp_channel.h +++ b/src/bgp/bgp_xmpp_channel.h @@ -131,6 +131,7 @@ class BgpXmppChannel { uint64_t get_tx_route_reach() const { return stats_[TX].reach; } uint64_t get_tx_route_unreach() const { return stats_[TX].unreach; } uint64_t get_tx_update() const { return stats_[TX].rt_updates; } + bool SkipUpdateSend() const; protected: XmppChannel *channel_;