Skip to content

Commit

Permalink
Merge "Add ability to selectively skip sending xmpp updates"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Jul 20, 2016
2 parents cc1fd33 + c752641 commit 32db0ff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/bgp/bgp_xmpp_channel.cc
Expand Up @@ -5,10 +5,11 @@
#include "bgp/bgp_xmpp_channel.h"

#include <boost/foreach.hpp>
#include <boost/regex.hpp>

#include <limits>
#include <vector>
#include <sstream>
#include <vector>

#include "base/task_annotations.h"
#include "bgp/bgp_config.h"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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_) {
Expand Down
1 change: 1 addition & 0 deletions src/bgp/bgp_xmpp_channel.h
Expand Up @@ -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_;
Expand Down

0 comments on commit 32db0ff

Please sign in to comment.