Skip to content

Commit

Permalink
Merge "Fix concurrency issues in caching string representation" into …
Browse files Browse the repository at this point in the history
…R3.1
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Oct 19, 2016
2 parents 092978e + 0737449 commit 93c8322
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 58 deletions.
38 changes: 13 additions & 25 deletions src/bgp/bgp_peer.cc
Expand Up @@ -596,6 +596,19 @@ BgpPeer::BgpPeer(BgpServer *server, RoutingInstance *instance,
total_flap_count_(0),
last_flap_(0),
inuse_authkey_type_(AuthenticationData::NIL) {
ostringstream oss1;
oss1 << peer_key_.endpoint.address();
if (peer_key_.endpoint.port() != BgpConfigManager::kDefaultPort)
oss1 << ":" << dec << peer_key_.endpoint.port();
to_str_ = oss1.str();

ostringstream oss2;
if (rtinstance_)
oss2 << rtinstance_->name() << ":";
oss2 << server_->localname() << ":";
oss2 << peer_name();
uve_key_str_ = oss2.str();

membership_req_pending_ = 0;
BGP_LOG_PEER(Event, this, SandeshLevel::SYS_INFO, BGP_LOG_FLAG_ALL,
BGP_PEER_DIR_NA, "Created");
Expand Down Expand Up @@ -2129,31 +2142,6 @@ bool BgpPeer::ReceiveMsg(BgpSession *session, const u_int8_t *msg,
return true;
}

string BgpPeer::ToString() const {
if (to_str_.empty()) {
ostringstream out;
out << peer_key_.endpoint.address();
if (peer_key_.endpoint.port() != BgpConfigManager::kDefaultPort) {
out << ":" << dec << peer_key_.endpoint.port();
}
to_str_ = out.str();
}
return to_str_;
}

string BgpPeer::ToUVEKey() const {
if (uve_key_str_.empty()) {
ostringstream out;
if (rtinstance_) {
out << rtinstance_->name() << ":";
}
out << server_->localname() << ":";
out << peer_name();
uve_key_str_ = out.str();
}
return uve_key_str_;
}

//
// Extract nexthop address from BgpMpNlri if appropriate and return updated
// BgpAttrPtr. The original attribute is returned for cases where there's no
Expand Down
4 changes: 2 additions & 2 deletions src/bgp/bgp_peer.h
Expand Up @@ -88,8 +88,8 @@ class BgpPeer : public IPeer {
// Interface methods

// thread-safe
virtual std::string ToString() const;
virtual std::string ToUVEKey() const;
virtual std::string ToString() const { return to_str_; }
virtual std::string ToUVEKey() const { return uve_key_str_; }

// thread: bgp::SendTask
// Used to send an UPDATE message on the socket.
Expand Down
10 changes: 3 additions & 7 deletions src/bgp/inet/inet_route.cc
Expand Up @@ -77,20 +77,16 @@ bool Ip4Prefix::IsMoreSpecific(const Ip4Prefix &rhs) const {
(rhs.ip4_addr().to_ulong() & mask);
}

InetRoute::InetRoute(const Ip4Prefix &prefix) : prefix_(prefix) {
InetRoute::InetRoute(const Ip4Prefix &prefix)
: prefix_(prefix),
prefix_str_(prefix.ToString()) {
}

int InetRoute::CompareTo(const Route &rhs) const {
const InetRoute &rt_other = static_cast<const InetRoute &>(rhs);
return prefix_.CompareTo(rt_other.prefix_);
}

string InetRoute::ToString() const {
if (prefix_str_.empty())
prefix_str_ = prefix_.ToString();
return prefix_str_;
}

// Check whether 'this' is more specific than rhs.
bool InetRoute::IsMoreSpecific(const string &match) const {
boost::system::error_code ec;
Expand Down
4 changes: 2 additions & 2 deletions src/bgp/inet/inet_route.h
Expand Up @@ -64,7 +64,7 @@ class InetRoute : public BgpRoute {
public:
explicit InetRoute(const Ip4Prefix &prefix);
virtual int CompareTo(const Route &rhs) const;
virtual std::string ToString() const;
virtual std::string ToString() const { return prefix_str_; }

const Ip4Prefix &GetPrefix() const { return prefix_; }

Expand All @@ -90,7 +90,7 @@ class InetRoute : public BgpRoute {

private:
Ip4Prefix prefix_;
mutable std::string prefix_str_;
std::string prefix_str_;

DISALLOW_COPY_AND_ASSIGN(InetRoute);
};
Expand Down
10 changes: 3 additions & 7 deletions src/bgp/inet6/inet6_route.cc
Expand Up @@ -91,20 +91,16 @@ Inet6Prefix Inet6Prefix::operator&(const Inet6Prefix& right) const {

// Routines for class Inet6Route

Inet6Route::Inet6Route(const Inet6Prefix &prefix) : prefix_(prefix) {
Inet6Route::Inet6Route(const Inet6Prefix &prefix)
: prefix_(prefix),
prefix_str_(prefix.ToString()) {
}

int Inet6Route::CompareTo(const Route &rhs) const {
const Inet6Route &rt_other = static_cast<const Inet6Route &>(rhs);
return prefix_.CompareTo(rt_other.prefix_);
}

string Inet6Route::ToString() const {
if (prefix_str_.empty())
prefix_str_ = prefix_.ToString();
return prefix_str_;
}

// Check whether 'this' is more specific than rhs.
bool Inet6Route::IsMoreSpecific(const string &match) const {
error_code ec;
Expand Down
4 changes: 2 additions & 2 deletions src/bgp/inet6/inet6_route.h
Expand Up @@ -73,7 +73,7 @@ class Inet6Route : public BgpRoute {
public:
explicit Inet6Route(const Inet6Prefix &prefix);
virtual int CompareTo(const Route &rhs) const;
virtual std::string ToString() const;
virtual std::string ToString() const { return prefix_str_; }

const Inet6Prefix &GetPrefix() const { return prefix_; }

Expand All @@ -100,7 +100,7 @@ class Inet6Route : public BgpRoute {

private:
Inet6Prefix prefix_;
mutable std::string prefix_str_;
std::string prefix_str_;

DISALLOW_COPY_AND_ASSIGN(Inet6Route);
};
Expand Down
15 changes: 3 additions & 12 deletions src/xmpp/xmpp_connection.cc
Expand Up @@ -58,6 +58,9 @@ XmppConnection::XmppConnection(TcpServer *server,
state_machine_(XmppObjectFactory::Create<XmppStateMachine>(
this, config->ClientOnly(), config->auth_enabled)),
mux_(XmppObjectFactory::Create<XmppChannelMux>(this)) {
ostringstream oss;
oss << FromString() << ":" << endpoint().address().to_string();
uve_key_str_ = oss.str();
}

XmppConnection::~XmppConnection() {
Expand Down Expand Up @@ -186,21 +189,9 @@ std::string XmppConnection::ToString() const {
}

std::string XmppConnection::ToUVEKey() const {
if (uve_key_str_.empty()) {
std::ostringstream out;
out << FromString() << ":" << endpoint().address().to_string();
uve_key_str_ = out.str();
}
return uve_key_str_;
}

void XmppConnection::SetFrom(const string &from) {
if (from_.size() == 0) {
from_ = from;
state_machine_->Initialize();
}
}

static void XMPPPeerInfoSend(XmppPeerInfoData &peer_info) {
XMPPPeerInfo::Send(peer_info);
}
Expand Down
1 change: 0 additions & 1 deletion src/xmpp/xmpp_connection.h
Expand Up @@ -105,7 +105,6 @@ class XmppConnection {

void set_session(XmppSession *session);
void clear_session();
void SetFrom(const std::string &);
void SetTo(const std::string &);

const XmppSession *session() const;
Expand Down

0 comments on commit 93c8322

Please sign in to comment.