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

[202012][VxLAN]VxLAN Tunnel Counters and Rates implementation #2442

Merged
merged 3 commits into from
Sep 13, 2022
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
3 changes: 2 additions & 1 deletion orchagent/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ dist_swss_DATA = \
port_rates.lua \
watermark_queue.lua \
watermark_pg.lua \
watermark_bufferpool.lua
watermark_bufferpool.lua \
tunnel_rates.lua

bin_PROGRAMS = orchagent routeresync orchagent_restart_check

Expand Down
54 changes: 49 additions & 5 deletions orchagent/flex_counter/flex_counter_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,60 @@ const unordered_map<bool, string> FlexCounterManager::status_lookup =

const unordered_map<CounterType, string> FlexCounterManager::counter_id_field_lookup =
{
{ CounterType::PORT_DEBUG, PORT_DEBUG_COUNTER_ID_LIST },
{ CounterType::SWITCH_DEBUG, SWITCH_DEBUG_COUNTER_ID_LIST },
{ CounterType::PORT, PORT_COUNTER_ID_LIST },
{ CounterType::QUEUE, QUEUE_COUNTER_ID_LIST }
{ CounterType::PORT_DEBUG, PORT_DEBUG_COUNTER_ID_LIST },
{ CounterType::SWITCH_DEBUG, SWITCH_DEBUG_COUNTER_ID_LIST },
{ CounterType::PORT, PORT_COUNTER_ID_LIST },
{ CounterType::QUEUE, QUEUE_COUNTER_ID_LIST },
{ CounterType::TUNNEL, TUNNEL_COUNTER_ID_LIST },
};

FlexManagerDirectory g_FlexManagerDirectory;

FlexCounterManager *FlexManagerDirectory::createFlexCounterManager(const string& group_name,
const StatsMode stats_mode,
const uint polling_interval,
const bool enabled,
FieldValueTuple fv_plugin)
{
if (m_managers.find(group_name) != m_managers.end())
{
if (stats_mode != m_managers[group_name]->getStatsMode())
{
SWSS_LOG_ERROR("Stats mode mismatch with already created flex counter manager %s",
group_name.c_str());
return NULL;
}
if (polling_interval != m_managers[group_name]->getPollingInterval())
{
SWSS_LOG_ERROR("Polling interval mismatch with already created flex counter manager %s",
group_name.c_str());
return NULL;
}
if (enabled != m_managers[group_name]->getEnabled())
{
SWSS_LOG_ERROR("Enabled field mismatch with already created flex counter manager %s",
group_name.c_str());
return NULL;
}
return m_managers[group_name];
}
FlexCounterManager *fc_manager = new FlexCounterManager(group_name, stats_mode, polling_interval,
enabled, fv_plugin);
m_managers[group_name] = fc_manager;
return fc_manager;
}

FlexCounterManager::FlexCounterManager(
const string& group_name,
const StatsMode stats_mode,
const uint polling_interval,
const bool enabled) :
const bool enabled,
FieldValueTuple fv_plugin) :
group_name(group_name),
stats_mode(stats_mode),
polling_interval(polling_interval),
enabled(enabled),
fv_plugin(fv_plugin),
flex_counter_db(new DBConnector("FLEX_COUNTER_DB", 0)),
flex_counter_group_table(new ProducerTable(flex_counter_db.get(), FLEX_COUNTER_GROUP_TABLE)),
flex_counter_table(new ProducerTable(flex_counter_db.get(), FLEX_COUNTER_TABLE))
Expand Down Expand Up @@ -83,6 +122,11 @@ void FlexCounterManager::applyGroupConfiguration()
FieldValueTuple(FLEX_COUNTER_STATUS_FIELD, status_lookup.at(enabled))
};

if (!fvField(fv_plugin).empty())
{
field_values.emplace_back(fv_plugin);
}

flex_counter_group_table->set(group_name, field_values);
}

Expand Down
42 changes: 40 additions & 2 deletions orchagent/flex_counter/flex_counter_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include "dbconnector.h"
#include "producertable.h"
#include "table.h"
#include <inttypes.h>

extern "C" {
Expand All @@ -22,7 +24,8 @@ enum class CounterType
PORT,
QUEUE,
PORT_DEBUG,
SWITCH_DEBUG
SWITCH_DEBUG,
TUNNEL,
};

// FlexCounterManager allows users to manage a group of flex counters.
Expand All @@ -37,7 +40,11 @@ class FlexCounterManager
const std::string& group_name,
const StatsMode stats_mode,
const uint polling_interval,
const bool enabled);
const bool enabled,
swss::FieldValueTuple fv_plugin = std::make_pair("",""));

FlexCounterManager()
{}

FlexCounterManager(const FlexCounterManager&) = delete;
FlexCounterManager& operator=(const FlexCounterManager&) = delete;
Expand All @@ -53,6 +60,26 @@ class FlexCounterManager
const std::unordered_set<std::string>& counter_stats);
void clearCounterIdList(const sai_object_id_t object_id);

const std::string& getGroupName() const
{
return group_name;
}

const StatsMode& getStatsMode() const
{
return stats_mode;
}

const uint& getPollingInterval() const
{
return polling_interval;
}

const bool& getEnabled() const
{
return enabled;
}

protected:
void applyGroupConfiguration();

Expand All @@ -67,6 +94,7 @@ class FlexCounterManager
StatsMode stats_mode;
uint polling_interval;
bool enabled;
swss::FieldValueTuple fv_plugin;
std::unordered_set<sai_object_id_t> installed_counters;

std::shared_ptr<swss::DBConnector> flex_counter_db = nullptr;
Expand All @@ -78,4 +106,14 @@ class FlexCounterManager
static const std::unordered_map<CounterType, std::string> counter_id_field_lookup;
};

class FlexManagerDirectory
{
public:
FlexCounterManager* createFlexCounterManager(const std::string& group_name, const StatsMode stats_mode,
const uint polling_interval, const bool enabled,
swss::FieldValueTuple fv_plugin = std::make_pair("",""));
private:
std::unordered_map<std::string, FlexCounterManager*> m_managers;
};

#endif // ORCHAGENT_FLEX_COUNTER_MANAGER_H
11 changes: 10 additions & 1 deletion orchagent/flexcounterorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@
#include "bufferorch.h"
#include "flexcounterorch.h"
#include "debugcounterorch.h"
#include "directory.h"

extern sai_port_api_t *sai_port_api;

extern PortsOrch *gPortsOrch;
extern IntfsOrch *gIntfsOrch;
extern BufferOrch *gBufferOrch;
extern Directory<Orch*> gDirectory;

#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"
#define TUNNEL_KEY "TUNNEL"

unordered_map<string, string> flexCounterGroupMap =
{
Expand All @@ -35,6 +38,7 @@ unordered_map<string, string> flexCounterGroupMap =
{"RIF", RIF_STAT_COUNTER_FLEX_COUNTER_GROUP},
{"RIF_RATES", RIF_RATE_COUNTER_FLEX_COUNTER_GROUP},
{"DEBUG_COUNTER", DEBUG_COUNTER_FLEX_COUNTER_GROUP},
{"TUNNEL", TUNNEL_STAT_COUNTER_FLEX_COUNTER_GROUP},
};


Expand All @@ -56,6 +60,8 @@ void FlexCounterOrch::doTask(Consumer &consumer)
{
SWSS_LOG_ENTER();

VxlanTunnelOrch* vxlan_tunnel_orch = gDirectory.get<VxlanTunnelOrch*>();

if (!gPortsOrch->allPortsReady())
{
return;
Expand Down Expand Up @@ -129,7 +135,10 @@ void FlexCounterOrch::doTask(Consumer &consumer)
{
gBufferOrch->generateBufferPoolWatermarkCounterIdList();
}

if (vxlan_tunnel_orch && (key== TUNNEL_KEY) && (value == "enable"))
{
vxlan_tunnel_orch->generateTunnelCounterMap();
}
vector<FieldValueTuple> fieldValues;
fieldValues.emplace_back(FLEX_COUNTER_STATUS_FIELD, value);
m_flexCounterGroupTable->set(flexCounterGroupMap[key], fieldValues);
Expand Down
98 changes: 98 additions & 0 deletions orchagent/tunnel_rates.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
-- KEYS - rif IDs
-- ARGV[1] - counters db index
-- ARGV[2] - counters table name
-- ARGV[3] - poll time interval
-- return log

local logtable = {}

local function logit(msg)
logtable[#logtable+1] = tostring(msg)
end

local counters_db = ARGV[1]
local counters_table_name = ARGV[2]
local rates_table_name = "RATES"
local sec_to_ms = 1000

-- Get configuration
redis.call('SELECT', counters_db)
local smooth_interval = redis.call('HGET', rates_table_name .. ':' .. 'TUNNEL', 'TUNNEL_SMOOTH_INTERVAL')
local alpha = redis.call('HGET', rates_table_name .. ':' .. 'TUNNEL', 'TUNNEL_ALPHA')
if not alpha then
logit("Alpha is not defined")
return logtable
end
local one_minus_alpha = 1.0 - alpha
local delta = tonumber(ARGV[3])

local n = table.getn(KEYS)
for i = 1, n do
local state_table = rates_table_name .. ':' .. KEYS[i] .. ':' .. 'TUNNEL'
local initialized = redis.call('HGET', state_table, 'INIT_DONE')
logit(initialized)

-- Get new COUNTERS values
local in_octets = 0
local in_packets = 0
local out_octets = 0
local out_packets = 0

if redis.call('HEXISTS', counters_table_name .. ':' .. KEYS[i], 'SAI_TUNNEL_STAT_IN_OCTETS') == 1 then
in_octets = redis.call('HGET', counters_table_name .. ':' .. KEYS[i], 'SAI_TUNNEL_STAT_IN_OCTETS')
end
if redis.call('HEXISTS', counters_table_name .. ':' .. KEYS[i], 'SAI_TUNNEL_STAT_IN_PACKETS') == 1 then
in_packets = redis.call('HGET', counters_table_name .. ':' .. KEYS[i], 'SAI_TUNNEL_STAT_IN_PACKETS')
end
if redis.call('HEXISTS', counters_table_name .. ':' .. KEYS[i], 'SAI_TUNNEL_STAT_OUT_OCTETS') == 1 then
out_octets = redis.call('HGET', counters_table_name .. ':' .. KEYS[i], 'SAI_TUNNEL_STAT_OUT_OCTETS')
end
if redis.call('HEXISTS', counters_table_name .. ':' .. KEYS[i], 'SAI_TUNNEL_STAT_OUT_PACKETS') == 1 then
out_packets = redis.call('HGET', counters_table_name .. ':' .. KEYS[i], 'SAI_TUNNEL_STAT_OUT_PACKETS')
end

if initialized == "DONE" or initialized == "COUNTERS_LAST" then
-- Get old COUNTERS values
local in_octets_last = redis.call('HGET', rates_table_name .. ':' .. KEYS[i], 'SAI_TUNNEL_STAT_IN_OCTETS_last')
local in_packets_last = redis.call('HGET', rates_table_name .. ':' .. KEYS[i], 'SAI_TUNNEL_STAT_IN_PACKETS_last')
local out_octets_last = redis.call('HGET', rates_table_name .. ':' .. KEYS[i], 'SAI_TUNNEL_STAT_OUT_OCTETS_last')
local out_packets_last = redis.call('HGET', rates_table_name .. ':' .. KEYS[i], 'SAI_TUNNEL_STAT_OUT_PACKETS_last')

-- Calculate new rates values
local rx_bps_new = (in_octets - in_octets_last)*sec_to_ms/delta
local tx_bps_new = (out_octets - out_octets_last)*sec_to_ms/delta
local rx_pps_new = (in_packets - in_packets_last)*sec_to_ms/delta
local tx_pps_new = (out_packets - out_packets_last)*sec_to_ms/delta

if initialized == "DONE" then
-- Get old rates values
local rx_bps_old = redis.call('HGET', rates_table_name .. ':' .. KEYS[i], 'RX_BPS')
local rx_pps_old = redis.call('HGET', rates_table_name .. ':' .. KEYS[i], 'RX_PPS')
local tx_bps_old = redis.call('HGET', rates_table_name .. ':' .. KEYS[i], 'TX_BPS')
local tx_pps_old = redis.call('HGET', rates_table_name .. ':' .. KEYS[i], 'TX_PPS')

-- Smooth the rates values and store them in DB
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'RX_BPS', alpha*rx_bps_new + one_minus_alpha*rx_bps_old)
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'RX_PPS', alpha*rx_pps_new + one_minus_alpha*rx_pps_old)
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'TX_BPS', alpha*tx_bps_new + one_minus_alpha*tx_bps_old)
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'TX_PPS', alpha*tx_pps_new + one_minus_alpha*tx_pps_old)
else
-- Store unsmoothed initial rates values in DB
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'RX_BPS', rx_bps_new)
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'RX_PPS', rx_pps_new)
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'TX_BPS', tx_bps_new)
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'TX_PPS', tx_pps_new)
redis.call('HSET', state_table, 'INIT_DONE', 'DONE')
end
else
redis.call('HSET', state_table, 'INIT_DONE', 'COUNTERS_LAST')
end

-- Set old COUNTERS values
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'SAI_TUNNEL_STAT_IN_OCTETS_last', in_octets)
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'SAI_TUNNEL_STAT_IN_PACKETS_last', in_packets)
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'SAI_TUNNEL_STAT_OUT_OCTETS_last', out_octets)
redis.call('HSET', rates_table_name .. ':' .. KEYS[i], 'SAI_TUNNEL_STAT_OUT_PACKETS_last', out_packets)
end

return logtable
Loading