From 499797aa4d1feb198bd2b98fbeeec1949c43608e Mon Sep 17 00:00:00 2001 From: Bhavanaashok33 Date: Thu, 28 May 2020 22:30:13 -0700 Subject: [PATCH] changed uri to const ref and fixed indentations --- agent-ovs/lib/PrometheusManager.cpp | 2 +- libopflex/engine/OpflexPEHandler.cpp | 11 +++++++--- libopflex/engine/OpflexPool.cpp | 22 +++++++++---------- .../opflex/engine/internal/OpflexPool.h | 6 ++--- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/agent-ovs/lib/PrometheusManager.cpp b/agent-ovs/lib/PrometheusManager.cpp index 7a5307c04..24becdd5b 100644 --- a/agent-ovs/lib/PrometheusManager.cpp +++ b/agent-ovs/lib/PrometheusManager.cpp @@ -159,7 +159,7 @@ static string ofpeer_family_help[] = "number of state reports sent to opflex peer", "number of state reports responses received from opflex peer", "number of state reports error repsonses from opflex peer", - "number of policies requested by the client which is not yet received" + "number of policies requested by the agent which is not yet resolved by opflex peer" }; static string remote_ep_family_names[] = diff --git a/libopflex/engine/OpflexPEHandler.cpp b/libopflex/engine/OpflexPEHandler.cpp index e9f26b3dc..d083ebd70 100644 --- a/libopflex/engine/OpflexPEHandler.cpp +++ b/libopflex/engine/OpflexPEHandler.cpp @@ -369,9 +369,14 @@ void OpflexPEHandler::handlePolicyResolveRes(uint64_t reqId, for (it = policy.Begin(); it != policy.End(); ++it) { const Value& mo = *it; serializer.deserialize(mo, *client, true, ¬ifs); - const Value& uriv = mo["uri"]; - OpflexPool& pool = getProcessor()->getPool(); - pool.removePendingItem(conn, uriv.GetString()); + if (!mo.HasMember("uri")) { + LOG(ERROR) << "uri member doesn't exist in the JSON value" ; + } + else { + const Value& uriv = mo["uri"]; + OpflexPool& pool = getProcessor()->getPool(); + pool.removePendingItem(conn, uriv.GetString()); + } } } client->deliverNotifications(notifs); diff --git a/libopflex/engine/OpflexPool.cpp b/libopflex/engine/OpflexPool.cpp index 7a84bd293..2b565abb1 100644 --- a/libopflex/engine/OpflexPool.cpp +++ b/libopflex/engine/OpflexPool.cpp @@ -50,22 +50,22 @@ OpflexPool::~OpflexPool() { uv_mutex_destroy(&conn_mutex); } -void OpflexPool::addPendingItem(OpflexClientConnection* conn, std::string uri) { +void OpflexPool::addPendingItem(OpflexClientConnection* conn, const std::string& uri) { std::string hostName = conn->getHostname(); std::unique_lock lock(modify_uri_mutex); if(pendingResolution[hostName].insert(uri).second == true) { - conn->getOpflexStats()->incrPolUnresolvedCount(); + conn->getOpflexStats()->incrPolUnresolvedCount(); } } -void OpflexPool::removePendingItem(OpflexClientConnection* conn, std::string uri) { - std::string hostName = conn->getHostname(); - std::unique_lock lock(modify_uri_mutex); - std::set::iterator rem = pendingResolution[hostName].find(uri); - if (rem != pendingResolution[hostName].end()) { - pendingResolution[hostName].erase(rem); - conn->getOpflexStats()->decrPolUnresolvedCount(); - } +void OpflexPool::removePendingItem(OpflexClientConnection* conn, const std::string& uri) { + std::string hostName = conn->getHostname(); + std::unique_lock lock(modify_uri_mutex); + std::set::iterator rem = pendingResolution[hostName].find(uri); + if (rem != pendingResolution[hostName].end()) { + pendingResolution[hostName].erase(rem); + conn->getOpflexStats()->decrPolUnresolvedCount(); + } } boost::optional OpflexPool::getLocation() { @@ -413,7 +413,7 @@ void incrementMsgCounter(OpflexClientConnection* conn, OpflexMessage* msg) size_t OpflexPool::sendToRole(OpflexMessage* message, OFConstants::OpflexRole role, - bool sync, std::string uri) { + bool sync, const std::string& uri) { #ifdef HAVE_CXX11 std::unique_ptr messagep(message); #else diff --git a/libopflex/engine/include/opflex/engine/internal/OpflexPool.h b/libopflex/engine/include/opflex/engine/internal/OpflexPool.h index df1e52379..9dbb81495 100644 --- a/libopflex/engine/include/opflex/engine/internal/OpflexPool.h +++ b/libopflex/engine/include/opflex/engine/internal/OpflexPool.h @@ -212,12 +212,12 @@ class OpflexPool : private boost::noncopyable { /** * Add the number of policies requested by the client */ - void addPendingItem(OpflexClientConnection* conn, std::string uri); + void addPendingItem(OpflexClientConnection* conn, const std::string& uri); /** * Remove the policies recieved from the peer */ - void removePendingItem(OpflexClientConnection* conn, std::string uri); + void removePendingItem(OpflexClientConnection* conn, const std::string& uri); /** * Register the given peer status listener to get updates on the @@ -257,7 +257,7 @@ class OpflexPool : private boost::noncopyable { */ size_t sendToRole(OpflexMessage* message, ofcore::OFConstants::OpflexRole role, - bool sync = false, std::string uri = ""); + bool sync = false, const std::string& uri = ""); /** * Get the number of connections in a particular role