Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge master branch #4

Merged
merged 6 commits into from
Nov 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cfgmgr/buffermgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ int main(int argc, char **argv)
CFG_PORT_CABLE_LEN_TABLE_NAME,
};

DBConnector cfgDb(CONFIG_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector stateDb(STATE_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector cfgDb("CONFIG_DB", 0);
DBConnector stateDb("STATE_DB", 0);

BufferMgr buffmgr(&cfgDb, &stateDb, pg_lookup_file, cfg_buffer_tables);

Expand Down
6 changes: 3 additions & 3 deletions cfgmgr/intfmgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ int main(int argc, char **argv)
CFG_VLAN_SUB_INTF_TABLE_NAME,
};

DBConnector cfgDb(CONFIG_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector appDb(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector stateDb(STATE_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector cfgDb("CONFIG_DB", 0);
DBConnector appDb("APPL_DB", 0);
DBConnector stateDb("STATE_DB", 0);

IntfMgr intfmgr(&cfgDb, &appDb, &stateDb, cfg_intf_tables);

Expand Down
6 changes: 3 additions & 3 deletions cfgmgr/nbrmgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ int main(int argc, char **argv)
CFG_NEIGH_TABLE_NAME,
};

DBConnector cfgDb(CONFIG_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector appDb(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector stateDb(STATE_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector cfgDb("CONFIG_DB", 0);
DBConnector appDb("APPL_DB", 0);
DBConnector stateDb("STATE_DB", 0);

NbrMgr nbrmgr(&cfgDb, &appDb, &stateDb, cfg_nbr_tables);

Expand Down
6 changes: 3 additions & 3 deletions cfgmgr/portmgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ int main(int argc, char **argv)
CFG_PORT_TABLE_NAME,
};

DBConnector cfgDb(CONFIG_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector appDb(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector stateDb(STATE_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector cfgDb("CONFIG_DB", 0);
DBConnector appDb("APPL_DB", 0);
DBConnector stateDb("STATE_DB", 0);

PortMgr portmgr(&cfgDb, &appDb, &stateDb, cfg_port_tables);

Expand Down
4 changes: 2 additions & 2 deletions cfgmgr/sflowmgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ int main(int argc, char **argv)
CFG_PORT_TABLE_NAME
};

DBConnector cfgDb(CONFIG_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector appDb(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector cfgDb("CONFIG_DB", 0);
DBConnector appDb("APPL_DB", 0);

SflowMgr sflowmgr(&cfgDb, &appDb, cfg_sflow_tables);

Expand Down
6 changes: 3 additions & 3 deletions cfgmgr/teammgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ int main(int argc, char **argv)

try
{
DBConnector conf_db(CONFIG_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector app_db(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector state_db(STATE_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector conf_db("CONFIG_DB", 0);
DBConnector app_db("APPL_DB", 0);
DBConnector state_db("STATE_DB", 0);

WarmStart::initialize("teammgrd", "teamd");
WarmStart::checkWarmStart("teammgrd", "teamd");
Expand Down
6 changes: 3 additions & 3 deletions cfgmgr/vlanmgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ int main(int argc, char **argv)
CFG_VLAN_MEMBER_TABLE_NAME,
};

DBConnector cfgDb(CONFIG_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector appDb(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector stateDb(STATE_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector cfgDb("CONFIG_DB", 0);
DBConnector appDb("APPL_DB", 0);
DBConnector stateDb("STATE_DB", 0);

WarmStart::initialize("vlanmgrd", "swss");
WarmStart::checkWarmStart("vlanmgrd", "swss");
Expand Down
6 changes: 3 additions & 3 deletions cfgmgr/vrfmgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ int main(int argc, char **argv)
CFG_VNET_TABLE_NAME,
};

DBConnector cfgDb(CONFIG_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector appDb(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector stateDb(STATE_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector cfgDb("CONFIG_DB", 0);
DBConnector appDb("APPL_DB", 0);
DBConnector stateDb("STATE_DB", 0);

VrfMgr vrfmgr(&cfgDb, &appDb, &stateDb, cfg_vrf_tables);

Expand Down
6 changes: 3 additions & 3 deletions cfgmgr/vxlanmgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ int main(int argc, char **argv)
try
{

DBConnector cfgDb(CONFIG_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector appDb(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector stateDb(STATE_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector cfgDb("CONFIG_DB", 0);
DBConnector appDb("APPL_DB", 0);
DBConnector stateDb("STATE_DB", 0);

vector<std::string> cfg_vnet_tables = {
CFG_VNET_TABLE_NAME,
Expand Down
4 changes: 0 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ AM_CONDITIONAL(DEBUG, test x$debug = xtrue)

CFLAGS_COMMON="-std=c++14 -Wall -fPIC -Wno-write-strings -I/usr/include/libnl3 -I/usr/include/swss"

AM_CONDITIONAL(sonic_asic_platform_barefoot, test x$CONFIGURED_PLATFORM = xbarefoot)
AM_COND_IF([sonic_asic_platform_barefoot],
[CFLAGS_COMMON+=" -I/opt/bfn/install/include/switchsai"])

CFLAGS_COMMON+=" -Werror"
CFLAGS_COMMON+=" -Wno-reorder"
CFLAGS_COMMON+=" -Wcast-align"
Expand Down
4 changes: 2 additions & 2 deletions fpmsyncd/fpmsyncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ static bool eoiuFlagsSet(Table &bgpStateTable)
int main(int argc, char **argv)
{
swss::Logger::linkToDbNative("fpmsyncd");
DBConnector db(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector db("APPL_DB", 0);
RedisPipeline pipeline(&db);
RouteSync sync(&pipeline);

DBConnector stateDb(STATE_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector stateDb("STATE_DB", 0);
Table bgpStateTable(&stateDb, STATE_BGP_TABLE_NAME);

NetDispatcher::getInstance().registerMessageHandler(RTM_NEWROUTE, &sync);
Expand Down
4 changes: 2 additions & 2 deletions neighsyncd/neighsyncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ int main(int argc, char **argv)
{
Logger::linkToDbNative("neighsyncd");

DBConnector appDb(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector appDb("APPL_DB", 0);
RedisPipeline pipelineAppDB(&appDb);
DBConnector stateDb(STATE_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector stateDb("STATE_DB", 0);

NeighSync sync(&pipelineAppDB, &stateDb);

Expand Down
6 changes: 4 additions & 2 deletions orchagent/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
INCLUDES = -I $(top_srcdir) -I $(top_srcdir)/warmrestart -I flex_counter
INCLUDES = -I $(top_srcdir) -I $(top_srcdir)/warmrestart -I flex_counter -I debug_counter

CFLAGS_SAI = -I /usr/include/sai

Expand Down Expand Up @@ -54,9 +54,11 @@ orchagent_SOURCES = \
watermarkorch.cpp \
policerorch.cpp \
sfloworch.cpp \
chassisorch.cpp
chassisorch.cpp \
debugcounterorch.cpp

orchagent_SOURCES += flex_counter/flex_counter_manager.cpp flex_counter/flex_counter_stat_manager.cpp
orchagent_SOURCES += debug_counter/debug_counter.cpp debug_counter/drop_counter.cpp

orchagent_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
orchagent_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
Expand Down
4 changes: 2 additions & 2 deletions orchagent/aclorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ bool AclOrch::m_bCollectCounters = true;
sai_uint32_t AclRule::m_minPriority = 0;
sai_uint32_t AclRule::m_maxPriority = 0;

swss::DBConnector AclOrch::m_db(COUNTERS_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
swss::DBConnector AclOrch::m_db("COUNTERS_DB", 0);
swss::Table AclOrch::m_countersTable(&m_db, "COUNTERS");

extern sai_acl_api_t* sai_acl_api;
Expand Down Expand Up @@ -559,7 +559,7 @@ bool AclRule::isActionSupported(sai_acl_entry_attr_t action) const
const auto* pTable = m_pAclOrch->getTableByOid(m_tableOid);
if (pTable == nullptr)
{
SWSS_LOG_THROW("ACL table does not exist for oid %lu", m_tableOid);
SWSS_LOG_THROW("ACL table does not exist for oid %" PRIu64, m_tableOid);
}
return m_pAclOrch->isAclActionSupported(pTable->stage, action_type);
}
Expand Down
4 changes: 2 additions & 2 deletions orchagent/bufferorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ type_map BufferOrch::m_buffer_type_maps = {

BufferOrch::BufferOrch(DBConnector *db, vector<string> &tableNames) :
Orch(db, tableNames),
m_flexCounterDb(new DBConnector(FLEX_COUNTER_DB, DBConnector::DEFAULT_UNIXSOCKET, 0)),
m_flexCounterDb(new DBConnector("FLEX_COUNTER_DB", 0)),
m_flexCounterTable(new ProducerTable(m_flexCounterDb.get(), FLEX_COUNTER_TABLE)),
m_flexCounterGroupTable(new ProducerTable(m_flexCounterDb.get(), FLEX_COUNTER_GROUP_TABLE)),
m_countersDb(new DBConnector(COUNTERS_DB, DBConnector::DEFAULT_UNIXSOCKET, 0)),
m_countersDb(new DBConnector("COUNTERS_DB", 0)),
m_countersDbRedisClient(m_countersDb.get())
{
SWSS_LOG_ENTER();
Expand Down
2 changes: 1 addition & 1 deletion orchagent/countercheckorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CounterCheckOrch& CounterCheckOrch::getInstance(DBConnector *db)

CounterCheckOrch::CounterCheckOrch(DBConnector *db, vector<string> &tableNames):
Orch(db, tableNames),
m_countersDb(new DBConnector(COUNTERS_DB, DBConnector::DEFAULT_UNIXSOCKET, 0)),
m_countersDb(new DBConnector("COUNTERS_DB", 0)),
m_countersTable(new Table(m_countersDb.get(), COUNTERS_TABLE))
{
SWSS_LOG_ENTER();
Expand Down
2 changes: 1 addition & 1 deletion orchagent/crmorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const map<string, CrmResourceType> crmUsedCntsTableMap =

CrmOrch::CrmOrch(DBConnector *db, string tableName):
Orch(db, tableName),
m_countersDb(new DBConnector(COUNTERS_DB, DBConnector::DEFAULT_UNIXSOCKET, 0)),
m_countersDb(new DBConnector("COUNTERS_DB", 0)),
m_countersCrmTable(new Table(m_countersDb.get(), COUNTERS_CRM_TABLE)),
m_timer(new SelectableTimer(timespec { .tv_sec = CRM_POLLING_INTERVAL_DEFAULT, .tv_nsec = 0 }))
{
Expand Down
112 changes: 112 additions & 0 deletions orchagent/debug_counter/debug_counter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#include "debug_counter.h"
#include "drop_counter.h"

#include <unordered_set>
#include <unordered_map>
#include <string>
#include <memory>
#include <vector>
#include "rediscommand.h"
#include <exception>
#include "logger.h"

using std::runtime_error;
using std::string;
using std::unique_ptr;
using std::unordered_map;
using std::unordered_set;
using std::vector;
using swss::FieldValueTuple;

extern sai_object_id_t gSwitchId;
extern sai_debug_counter_api_t *sai_debug_counter_api;

// Set of supported attributes to support easy look-up.
const unordered_set<string> DebugCounter::supported_debug_counter_attributes =
{
COUNTER_ALIAS,
COUNTER_TYPE,
COUNTER_DESCRIPTION,
COUNTER_GROUP
};

const std::unordered_map<std::string, sai_debug_counter_type_t> DebugCounter::debug_counter_type_lookup =
{
{ PORT_INGRESS_DROPS, SAI_DEBUG_COUNTER_TYPE_PORT_IN_DROP_REASONS },
{ PORT_EGRESS_DROPS, SAI_DEBUG_COUNTER_TYPE_PORT_OUT_DROP_REASONS },
{ SWITCH_INGRESS_DROPS, SAI_DEBUG_COUNTER_TYPE_SWITCH_IN_DROP_REASONS },
{ SWITCH_EGRESS_DROPS, SAI_DEBUG_COUNTER_TYPE_SWITCH_OUT_DROP_REASONS }
};

// It is expected that derived types populate any relevant fields and
// initialize the counter in the SAI.
//
// If counter_type is not a member of debug_counter_type_lookup then this
// constructor will throw a runtime error.
DebugCounter::DebugCounter(
const string& counter_name,
const string& counter_type)
: name(counter_name)
{
SWSS_LOG_ENTER();

auto counter_type_it = debug_counter_type_lookup.find(counter_type);
if (counter_type_it == debug_counter_type_lookup.end()) {
SWSS_LOG_ERROR("Failed to initialize debug counter of type '%s'",
counter_type.c_str());
throw runtime_error("Failed to initialize debug counter");
}
type = counter_type_it->first;
}

// It is expected that derived types delete the counter from the SAI.
DebugCounter::~DebugCounter()
{
SWSS_LOG_ENTER();
}

void DebugCounter::serializeDebugCounterType(sai_attribute_t& type_attribute)
{
SWSS_LOG_ENTER();

sai_debug_counter_type_t sai_counter_type = debug_counter_type_lookup.at(type);
type_attribute.id = SAI_DEBUG_COUNTER_ATTR_TYPE;
type_attribute.value.s32 = sai_counter_type;

SWSS_LOG_DEBUG("Serializing debug counter of type '%s'", type.c_str());
}

// addDebugCounterToSAI creates a new debug counter object in the SAI given a list of debug counter attributes.
//
// If the SAI returns an error then this method will throw a runtime error.
//
// Behavior is undefined if num_attributes is not equal to the number of
// attributes in debug_counter_attributes.
void DebugCounter::addDebugCounterToSAI(const int num_attributes, const sai_attribute_t *debug_counter_attributes)
{
SWSS_LOG_ENTER();

SWSS_LOG_DEBUG("Adding debug counter '%s' to SAI", name.c_str());
sai_object_id_t debug_counter_id;
if (sai_debug_counter_api->create_debug_counter(&debug_counter_id,
gSwitchId,
num_attributes,
debug_counter_attributes) != SAI_STATUS_SUCCESS) {
SWSS_LOG_ERROR("Failed to create debug counter '%s'", name.c_str());
throw std::runtime_error("Failed to create debug counter");
}

SWSS_LOG_DEBUG("Created debug counter '%s' with OID=%lu", name.c_str(), debug_counter_id);
counter_id = debug_counter_id;
}

void DebugCounter::removeDebugCounterFromSAI()
{
SWSS_LOG_ENTER();

SWSS_LOG_DEBUG("Removing debug counter '%s' from SAI", name.c_str());
if (sai_debug_counter_api->remove_debug_counter(counter_id) != SAI_STATUS_SUCCESS) {
SWSS_LOG_ERROR("Failed to remove debug counter '%s'", name.c_str());
throw std::runtime_error("Failed to remove debug counter");
}
}
64 changes: 64 additions & 0 deletions orchagent/debug_counter/debug_counter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#ifndef SWSS_UTIL_DEBUG_COUNTER_H_
#define SWSS_UTIL_DEBUG_COUNTER_H_

#include <string>
#include <unordered_map>
#include <unordered_set>

extern "C" {
#include "sai.h"
}

// Supported debug counter attributes.
#define COUNTER_ALIAS "alias"
#define COUNTER_TYPE "type"
#define COUNTER_DESCRIPTION "desc"
#define COUNTER_GROUP "group"

// Supported debug counter types.
#define PORT_INGRESS_DROPS "PORT_INGRESS_DROPS"
#define PORT_EGRESS_DROPS "PORT_EGRESS_DROPS"
#define SWITCH_INGRESS_DROPS "SWITCH_INGRESS_DROPS"
#define SWITCH_EGRESS_DROPS "SWITCH_EGRESS_DROPS"

// DebugCounter represents a SAI debug counter object.
class DebugCounter
{
public:
DebugCounter(const std::string& counter_name, const std::string& counter_type) noexcept(false);
DebugCounter(const DebugCounter&) = delete;
DebugCounter& operator=(const DebugCounter&) = delete;
virtual ~DebugCounter();

std::string getCounterName() const { return name; }
std::string getCounterType() const { return type; }

virtual std::string getDebugCounterSAIStat() const noexcept(false) = 0;

static const std::unordered_set<std::string>& getSupportedDebugCounterAttributes()
{
return supported_debug_counter_attributes;
}

// TODO: We should try to neatly abstract this like we've done for the isValid methods in DropCounter.
static const std::unordered_map<std::string, sai_debug_counter_type_t>& getDebugCounterTypeLookup()
{
return debug_counter_type_lookup;
}

protected:
// These methods are intended to help with initialization. Dervied types will most likely
// need to define additional helper methods to serialize additional fields (see DropCounter for example).
void serializeDebugCounterType(sai_attribute_t& type_attribute);
void addDebugCounterToSAI(int num_attrs, const sai_attribute_t *counter_attrs) noexcept(false);
void removeDebugCounterFromSAI() noexcept(false);

std::string name;
std::string type;
sai_object_id_t counter_id = 0;

static const std::unordered_set<std::string> supported_debug_counter_attributes;
static const std::unordered_map<std::string, sai_debug_counter_type_t> debug_counter_type_lookup;
};

#endif // _SWSS_UTIL_DEBUG_COUNTER_H_
Loading