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

[orchagent] Adds swss support for drop counters #1075

Merged
merged 30 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f298f1f
[orchagent] Adds swss support for drop counters
daall Aug 30, 2019
0787c6e
Fix build issues
daall Oct 1, 2019
11e540b
Fix log levels
daall Oct 1, 2019
b3e84eb
Cast drop reasons before serializing
daall Oct 2, 2019
59f3f6b
Fix testing issues
daall Oct 5, 2019
878f107
Clean up flex counter utilities
daall Oct 7, 2019
2983801
Expose switch ids in redis
daall Oct 7, 2019
550376a
Clean-up comments and namespace usage
daall Oct 7, 2019
577f7fc
Add basic drop counter vswitch tests
daall Oct 7, 2019
64a87d4
Add drop reasons
daall Oct 9, 2019
ba35f31
Fix rebase merge conflicts
daall Oct 12, 2019
9f05dce
Move flex counter and switch related work to different PRs
daall Oct 12, 2019
ec9a86d
Fix first round of feedback comments
daall Oct 29, 2019
21dcf97
Fix free counters review comments
daall Oct 29, 2019
8cfb456
Reorganize helper classes
daall Oct 29, 2019
8eb4b2e
Delete extra makefile
daall Oct 30, 2019
609da17
Only put useful capabilities in STATE DB
daall Oct 31, 2019
00d11e7
Use new flex counter manager naming
daall Nov 12, 2019
682ff59
Merge branch 'master' of https://github.com/azure/sonic-swss into dro…
daall Nov 12, 2019
7f260ac
Merge branch 'master' into drop_counters
daall Nov 13, 2019
1af858b
Update mock tests to build with debug counter orch
daall Nov 14, 2019
95f8c51
Add remaining ingress drop reasons
daall Nov 14, 2019
6503663
Fix reference style issue
daall Nov 14, 2019
e5503e0
Update tests to match virtual switch implementation
daall Nov 14, 2019
efea942
Respond to C++ style issues
daall Nov 16, 2019
f3044b2
Improve documentation for vs tests
daall Nov 16, 2019
bf0a3cc
Add test case for removing all drop reasons from a counter
daall Nov 16, 2019
130c70d
Specify exception type being caught
daall Nov 16, 2019
ba34ca6
Add range check for drop counter indices
daall Nov 18, 2019
4d0876b
Undo range check
daall Nov 19, 2019
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
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
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