Skip to content

Commit

Permalink
Merge branch 'master' into fabric
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoc-do authored May 14, 2021
2 parents f054f8b + 73ffd5f commit 38ddc7a
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 244 deletions.
72 changes: 60 additions & 12 deletions orchagent/bulker.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <sairedis.h>
#include "sai.h"
#include "logger.h"
#include "sai_serialize.h"

static inline bool operator==(const sai_ip_prefix_t& a, const sai_ip_prefix_t& b)
{
Expand Down Expand Up @@ -282,8 +283,16 @@ class EntityBulker
}
size_t count = rs.size();
std::vector<sai_status_t> statuses(count);
(*remove_entries)((uint32_t)count, rs.data(), SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, statuses.data());
SWSS_LOG_INFO("EntityBulker.flush removing_entries %zu\n", removing_entries.size());
sai_status_t status = (*remove_entries)((uint32_t)count, rs.data(), SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, statuses.data());
if (status == SAI_STATUS_SUCCESS)
{
SWSS_LOG_INFO("EntityBulker.flush removing_entries %zu\n", removing_entries.size());
}
else
{
SWSS_LOG_ERROR("EntityBulker.flush remove entries failed, number of entries to remove: %zu, status: %s",
removing_entries.size(), sai_serialize_status(status).c_str());
}

for (size_t ir = 0; ir < count; ir++)
{
Expand Down Expand Up @@ -318,9 +327,17 @@ class EntityBulker
}
size_t count = rs.size();
std::vector<sai_status_t> statuses(count);
(*create_entries)((uint32_t)count, rs.data(), cs.data(), tss.data()
sai_status_t status = (*create_entries)((uint32_t)count, rs.data(), cs.data(), tss.data()
, SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, statuses.data());
SWSS_LOG_INFO("EntityBulker.flush creating_entries %zu\n", creating_entries.size());
if (status == SAI_STATUS_SUCCESS)
{
SWSS_LOG_INFO("EntityBulker.flush creating_entries %zu\n", creating_entries.size());
}
else
{
SWSS_LOG_ERROR("EntityBulker.flush create entries failed, number of entries to create: %zu, status: %s",
creating_entries.size(), sai_serialize_status(status).c_str());
}

for (size_t ir = 0; ir < count; ir++)
{
Expand Down Expand Up @@ -359,9 +376,17 @@ class EntityBulker
}
size_t count = rs.size();
std::vector<sai_status_t> statuses(count);
(*set_entries_attribute)((uint32_t)count, rs.data(), ts.data()
sai_status_t status = (*set_entries_attribute)((uint32_t)count, rs.data(), ts.data()
, SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, statuses.data());
SWSS_LOG_INFO("EntityBulker.flush setting_entries %zu, count %zu\n", setting_entries.size(), count);
if (status == SAI_STATUS_SUCCESS)
{
SWSS_LOG_INFO("EntityBulker.flush setting_entries %zu, count %zu\n", setting_entries.size(), count);
}
else
{
SWSS_LOG_ERROR("EntityBulker.flush set entry attribute failed, number of entries to set: %zu, status: %s",
setting_entries.size(), sai_serialize_status(status).c_str());
}

for (size_t ir = 0; ir < count; ir++)
{
Expand Down Expand Up @@ -544,7 +569,15 @@ class ObjectBulker
size_t count = rs.size();
std::vector<sai_status_t> statuses(count);
sai_status_t status = (*remove_entries)((uint32_t)count, rs.data(), SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR, statuses.data());
SWSS_LOG_INFO("ObjectBulker.flush removing_entries %zu rc=%d statuses[0]=%d\n", removing_entries.size(), status, statuses[0]);
if (status == SAI_STATUS_SUCCESS)
{
SWSS_LOG_INFO("ObjectBulker.flush removing_entries %zu rc=%d statuses[0]=%d\n", removing_entries.size(), status, statuses[0]);
}
else
{
SWSS_LOG_ERROR("ObjectBulker.flush remove entries failed, number of entries to remove: %zu, status: %s",
removing_entries.size(), sai_serialize_status(status).c_str());
}

for (size_t i = 0; i < count; i++)
{
Expand Down Expand Up @@ -574,9 +607,17 @@ class ObjectBulker
size_t count = creating_entries.size();
std::vector<sai_object_id_t> object_ids(count);
std::vector<sai_status_t> statuses(count);
(*create_entries)(switch_id, (uint32_t)count, cs.data(), tss.data()
sai_status_t status = (*create_entries)(switch_id, (uint32_t)count, cs.data(), tss.data()
, SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR, object_ids.data(), statuses.data());
SWSS_LOG_INFO("ObjectBulker.flush creating_entries %zu\n", creating_entries.size());
if (status == SAI_STATUS_SUCCESS)
{
SWSS_LOG_INFO("ObjectBulker.flush creating_entries %zu\n", creating_entries.size());
}
else
{
SWSS_LOG_ERROR("ObjectBulker.flush create entries failed, number of entries to create: %zu, status: %s",
creating_entries.size(), sai_serialize_status(status).c_str());
}

for (size_t i = 0; i < count; i++)
{
Expand Down Expand Up @@ -607,10 +648,17 @@ class ObjectBulker
}
size_t count = setting_entries.size();
std::vector<sai_status_t> statuses(count);
(*set_entries_attribute)((uint32_t)count, rs.data(), ts.data()
sai_status_t status = (*set_entries_attribute)((uint32_t)count, rs.data(), ts.data()
, SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR, statuses.data());
SWSS_LOG_INFO("ObjectBulker.flush setting_entries %zu\n", setting_entries.size());
if (status == SAI_STATUS_SUCCESS)
{
SWSS_LOG_INFO("ObjectBulker.flush setting_entries %zu\n", setting_entries.size());
}
else
{
SWSS_LOG_ERROR("ObjectBulker.flush set entry attribute failed, number of entries to set: %zu, status: %s",
setting_entries.size(), sai_serialize_status(status).c_str());
}
setting_entries.clear();
}
Expand Down
32 changes: 4 additions & 28 deletions orchagent/flexcounterorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ extern IntfsOrch *gIntfsOrch;
extern BufferOrch *gBufferOrch;

#define BUFFER_POOL_WATERMARK_KEY "BUFFER_POOL_WATERMARK"
#define PORT_KEY "PORT"
#define PORT_BUFFER_DROP_KEY "PORT_BUFFER_DROP"
#define QUEUE_KEY "QUEUE"
#define PG_WATERMARK_KEY "PG_WATERMARK"
#define RIF_KEY "RIF"

unordered_map<string, string> flexCounterGroupMap =
{
Expand Down Expand Up @@ -99,16 +94,6 @@ void FlexCounterOrch::doTask(Consumer &consumer)
}
else if(field == FLEX_COUNTER_STATUS_FIELD)
{
if((key == PORT_KEY) && (value == "enable"))
{
gPortsOrch->generatePortCounterMap();
m_port_counter_enabled = true;
}
if((key == PORT_BUFFER_DROP_KEY) && (value == "enable"))
{
gPortsOrch->generatePortBufferDropCounterMap();
m_port_buffer_drop_counter_enabled = true;
}
// Currently, the counters are disabled for polling by default
// The queue maps will be generated as soon as counters are enabled for polling
// Counter polling is enabled by pushing the COUNTER_ID_LIST/ATTR_ID_LIST, which contains
Expand All @@ -123,15 +108,16 @@ void FlexCounterOrch::doTask(Consumer &consumer)
// This can be because generateQueueMap() installs a fundamental list of queue stats
// that need to be polled. So my doubt here is if queue watermark stats shall be piggybacked
// into the same function as they may not be counted as fundamental
if(gPortsOrch && (key == QUEUE_KEY) && (value == "enable"))
if(gPortsOrch)
{
gPortsOrch->generateQueueMap();
gPortsOrch->generatePriorityGroupMap();
}
if(gPortsOrch && (key == PG_WATERMARK_KEY) && (value == "enable"))
if(gPortsOrch)
{
gPortsOrch->generatePriorityGroupMap();
}
if(gIntfsOrch && (key == RIF_KEY) && (value == "enable"))
if(gIntfsOrch)
{
gIntfsOrch->generateInterfaceMap();
}
Expand All @@ -158,13 +144,3 @@ void FlexCounterOrch::doTask(Consumer &consumer)
consumer.m_toSync.erase(it++);
}
}

bool FlexCounterOrch::getPortCountersState()
{
return m_port_counter_enabled;
}

bool FlexCounterOrch::getPortBufferDropCountersState()
{
return m_port_buffer_drop_counter_enabled;
}
4 changes: 0 additions & 4 deletions orchagent/flexcounterorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ class FlexCounterOrch: public Orch
void doTask(Consumer &consumer);
FlexCounterOrch(swss::DBConnector *db, std::vector<std::string> &tableNames);
virtual ~FlexCounterOrch(void);
bool getPortCountersState();
bool getPortBufferDropCountersState();

private:
std::shared_ptr<swss::DBConnector> m_flexCounterDb = nullptr;
std::shared_ptr<swss::ProducerTable> m_flexCounterGroupTable = nullptr;
bool m_port_counter_enabled = false;
bool m_port_buffer_drop_counter_enabled = false;
};

#endif
6 changes: 1 addition & 5 deletions orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,7 @@ bool OrchDaemon::init()
CFG_FLEX_COUNTER_TABLE_NAME
};

auto* flexCounterOrch = new FlexCounterOrch(m_configDb, flex_counter_tables);
m_orchList.push_back(flexCounterOrch);

gDirectory.set(flexCounterOrch);
gDirectory.set(gPortsOrch);
m_orchList.push_back(new FlexCounterOrch(m_configDb, flex_counter_tables));

vector<string> pfc_wd_tables = {
CFG_PFC_WD_TABLE_NAME
Expand Down
83 changes: 13 additions & 70 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ static char* hostif_vlan_tag[] = {
*/
PortsOrch::PortsOrch(DBConnector *db, vector<table_name_with_pri_t> &tableNames, DBConnector *chassisAppDb) :
Orch(db, tableNames),
port_stat_manager(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, false),
port_buffer_drop_stat_manager(PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_BUFFER_DROP_STAT_POLLING_INTERVAL_MS, false),
queue_stat_manager(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, QUEUE_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, false)
port_stat_manager(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true),
port_buffer_drop_stat_manager(PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_BUFFER_DROP_STAT_POLLING_INTERVAL_MS, true),
queue_stat_manager(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, QUEUE_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, true)
{
SWSS_LOG_ENTER();

Expand Down Expand Up @@ -2131,21 +2131,19 @@ bool PortsOrch::initPort(const string &alias, const int index, const set<int> &l
vector<FieldValueTuple> fields;
fields.push_back(tuple);
m_counterTable->set("", fields);

// Install a flex counter for this port to track stats
auto flex_counters_orch = gDirectory.get<FlexCounterOrch*>();
/* Delay installing the counters if they are yet enabled
If they are enabled, install the counters immediately */
if (flex_counters_orch->getPortCountersState())
std::unordered_set<std::string> counter_stats;
for (const auto& it: port_stat_ids)
{
auto port_counter_stats = generateCounterStats(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP);
port_stat_manager.setCounterIdList(p.m_port_id, CounterType::PORT, port_counter_stats);
counter_stats.emplace(sai_serialize_port_stat(it));
}
if (flex_counters_orch->getPortBufferDropCountersState())
port_stat_manager.setCounterIdList(p.m_port_id, CounterType::PORT, counter_stats);
std::unordered_set<std::string> port_buffer_drop_stats;
for (const auto& it: port_buffer_drop_stat_ids)
{
auto port_buffer_drop_stats = generateCounterStats(PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP);
port_buffer_drop_stat_manager.setCounterIdList(p.m_port_id, CounterType::PORT, port_buffer_drop_stats);
port_buffer_drop_stats.emplace(sai_serialize_port_stat(it));
}
port_buffer_drop_stat_manager.setCounterIdList(p.m_port_id, CounterType::PORT, port_buffer_drop_stats);

PortUpdate update = { p, true };
notify(SUBJECT_TYPE_PORT_CHANGE, static_cast<void *>(&update));
Expand Down Expand Up @@ -2178,11 +2176,8 @@ void PortsOrch::deInitPort(string alias, sai_object_id_t port_id)
p.m_port_id = port_id;

/* remove port from flex_counter_table for updating counters */
auto flex_counters_orch = gDirectory.get<FlexCounterOrch*>();
if ((flex_counters_orch->getPortCountersState()))
{
port_stat_manager.clearCounterIdList(p.m_port_id);
}
port_stat_manager.clearCounterIdList(p.m_port_id);

/* remove port name map from counter table */
m_counter_db->hdel(COUNTERS_PORT_NAME_MAP, alias);

Expand Down Expand Up @@ -4704,38 +4699,6 @@ void PortsOrch::generatePriorityGroupMapPerPort(const Port& port)
CounterCheckOrch::getInstance().addPort(port);
}

void PortsOrch::generatePortCounterMap()
{
if (m_isPortCounterMapGenerated)
{
return;
}

auto port_counter_stats = generateCounterStats(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP);
for (const auto& it: m_portList)
{
port_stat_manager.setCounterIdList(it.second.m_port_id, CounterType::PORT, port_counter_stats);
}

m_isPortCounterMapGenerated = true;
}

void PortsOrch::generatePortBufferDropCounterMap()
{
if (m_isPortBufferDropCounterMapGenerated)
{
return;
}

auto port_buffer_drop_stats = generateCounterStats(PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP);
for (const auto& it: m_portList)
{
port_buffer_drop_stat_manager.setCounterIdList(it.second.m_port_id, CounterType::PORT, port_buffer_drop_stats);
}

m_isPortBufferDropCounterMapGenerated = true;
}

void PortsOrch::doTask(NotificationConsumer &consumer)
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -5602,26 +5565,6 @@ bool PortsOrch::setVoqInbandIntf(string &alias, string &type)
return true;
}

std::unordered_set<std::string> PortsOrch::generateCounterStats(const string& type)
{
std::unordered_set<std::string> counter_stats;
if (type == PORT_STAT_COUNTER_FLEX_COUNTER_GROUP)
{
for (const auto& it: port_stat_ids)
{
counter_stats.emplace(sai_serialize_port_stat(it));
}
}
else if (type == PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP)
{
for (const auto& it: port_buffer_drop_stat_ids)
{
counter_stats.emplace(sai_serialize_port_stat(it));
}
}
return counter_stats;
}

void PortsOrch::voqSyncAddLag (Port &lag)
{
int32_t switch_id = lag.m_system_lag_info.switch_id;
Expand Down
9 changes: 0 additions & 9 deletions orchagent/portsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "flex_counter_manager.h"
#include "gearboxutils.h"
#include "saihelper.h"
#include "flexcounterorch.h"
#include "lagid.h"


Expand Down Expand Up @@ -126,8 +125,6 @@ class PortsOrch : public Orch, public Subject

void generateQueueMap();
void generatePriorityGroupMap();
void generatePortCounterMap();
void generatePortBufferDropCounterMap();

void refreshPortStatus();
bool removeAclTableGroup(const Port &p);
Expand Down Expand Up @@ -286,9 +283,6 @@ class PortsOrch : public Orch, public Subject
bool m_isPriorityGroupMapGenerated = false;
void generatePriorityGroupMapPerPort(const Port& port);

bool m_isPortCounterMapGenerated = false;
bool m_isPortBufferDropCounterMapGenerated = false;

bool setPortAutoNeg(sai_object_id_t id, int an);
bool setPortFecMode(sai_object_id_t id, int fec);

Expand All @@ -313,9 +307,6 @@ class PortsOrch : public Orch, public Subject
sai_uint32_t m_systemPortCount;
bool getSystemPorts();
bool addSystemPorts();

std::unordered_set<std::string> generateCounterStats(const string& type);

unique_ptr<Table> m_tableVoqSystemLagTable;
unique_ptr<Table> m_tableVoqSystemLagMemberTable;
void voqSyncAddLag(Port &lag);
Expand Down
3 changes: 0 additions & 3 deletions tests/mock_tests/mock_orchagent_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#include "vxlanorch.h"
#include "policerorch.h"
#include "fgnhgorch.h"
#include "flexcounterorch.h"
#include "directory.h"

extern int gBatchSize;
extern bool gSwssRecord;
Expand Down Expand Up @@ -44,7 +42,6 @@ extern FdbOrch *gFdbOrch;
extern MirrorOrch *gMirrorOrch;
extern BufferOrch *gBufferOrch;
extern VRFOrch *gVrfOrch;
extern Directory<Orch*> gDirectory;

extern sai_acl_api_t *sai_acl_api;
extern sai_switch_api_t *sai_switch_api;
Expand Down
Loading

0 comments on commit 38ddc7a

Please sign in to comment.