Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v6erspan' into v6erspan
Browse files Browse the repository at this point in the history
  • Loading branch information
mramezani95 committed Nov 8, 2024
2 parents 343f21e + 483e651 commit f09153f
Show file tree
Hide file tree
Showing 33 changed files with 2,014 additions and 1,394 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ if test "x$asan_enabled" = "xtrue"; then
CFLAGS_ASAN+=" -Wno-maybe-uninitialized"
AC_SUBST(CFLAGS_ASAN)

LDFLAGS_ASAN+=" -lasan"
LDFLAGS_ASAN+=" -fsanitize=address"
AC_SUBST(LDFLAGS_ASAN)
fi

Expand Down
6 changes: 3 additions & 3 deletions fdbsyncd/fdbsyncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ int main(int argc, char **argv)
{
Logger::linkToDbNative("fdbsyncd");

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 config_db(CONFIG_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector stateDb("STATE_DB", 0);
DBConnector config_db("CONFIG_DB", 0);

FdbSync sync(&pipelineAppDB, &stateDb, &config_db);

Expand Down
2 changes: 1 addition & 1 deletion gearsyncd/gearparserbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ GearParserBase::init()
{
m_writeToDb = false;
m_rootInit = false;
m_applDb = std::unique_ptr<swss::DBConnector>{new swss::DBConnector(APPL_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0)};
m_applDb = std::unique_ptr<swss::DBConnector>{new swss::DBConnector("APPL_DB", 0)};
m_producerStateTable = std::unique_ptr<swss::ProducerStateTable>{new swss::ProducerStateTable(m_applDb.get(), APP_GEARBOX_TABLE_NAME)};
}

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

DBConnector cfgDb(CONFIG_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector applDb(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector cfgDb("CONFIG_DB", 0);
DBConnector applDb("APPL_DB", 0);
ProducerStateTable producerStateTable(&applDb, APP_GEARBOX_TABLE_NAME);

WarmStart::initialize("gearsyncd", "swss");
Expand Down
2 changes: 0 additions & 2 deletions orchagent/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ INCLUDES = -I $(top_srcdir)/lib \
-I pbh \
-I nhg

if GCOV_ENABLED
SUBDIRS = p4orch/tests
endif

CFLAGS_SAI = -I /usr/include/sai

Expand Down
175 changes: 165 additions & 10 deletions orchagent/dash/dashorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "crmorch.h"
#include "saihelper.h"
#include "directory.h"
#include "flex_counter_manager.h"

#include "taskworker.h"
#include "pbutils.h"
Expand All @@ -28,16 +29,45 @@ using namespace swss;

extern Directory<Orch*> gDirectory;
extern std::unordered_map<std::string, sai_object_id_t> gVnetNameToId;
extern sai_dash_appliance_api_t* sai_dash_appliance_api;
extern sai_dash_vip_api_t* sai_dash_vip_api;
extern sai_dash_direction_lookup_api_t* sai_dash_direction_lookup_api;
extern sai_dash_eni_api_t* sai_dash_eni_api;
extern sai_object_id_t gSwitchId;
extern size_t gMaxBulkSize;
extern CrmOrch *gCrmOrch;
extern bool gTraditionalFlexCounter;

DashOrch::DashOrch(DBConnector *db, vector<string> &tableName, ZmqServer *zmqServer) : ZmqOrch(db, tableName, zmqServer)
#define FLEX_COUNTER_UPD_INTERVAL 1

DashOrch::DashOrch(DBConnector *db, vector<string> &tableName, ZmqServer *zmqServer) :
ZmqOrch(db, tableName, zmqServer),
m_eni_stat_manager(ENI_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, ENI_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, false)
{
SWSS_LOG_ENTER();

m_asic_db = std::shared_ptr<DBConnector>(new DBConnector("ASIC_DB", 0));
m_counter_db = std::shared_ptr<DBConnector>(new DBConnector("COUNTERS_DB", 0));
m_eni_name_table = std::unique_ptr<Table>(new Table(m_counter_db.get(), COUNTERS_ENI_NAME_MAP));

if (gTraditionalFlexCounter)
{
m_vid_to_rid_table = std::make_unique<Table>(m_asic_db.get(), "VIDTORID");
}

auto intervT = timespec { .tv_sec = FLEX_COUNTER_UPD_INTERVAL , .tv_nsec = 0 };
m_fc_update_timer = new SelectableTimer(intervT);
auto executorT = new ExecutableTimer(m_fc_update_timer, this, "FLEX_COUNTER_UPD_TIMER");
Orch::addExecutor(executorT);

/* Fetch the available counter Ids */
m_counter_stats.clear();
auto stat_enum_list = queryAvailableCounterStats((sai_object_type_t)SAI_OBJECT_TYPE_ENI);
for (auto &stat_enum: stat_enum_list)
{
auto counter_id = static_cast<sai_eni_stat_t>(stat_enum);
m_counter_stats.insert(sai_serialize_eni_stat(counter_id));
}
}

bool DashOrch::getRouteTypeActions(dash::route_type::RoutingType routing_type, dash::route_type::RouteType& route_type)
Expand Down Expand Up @@ -66,15 +96,31 @@ bool DashOrch::addApplianceEntry(const string& appliance_id, const dash::applian
}

uint32_t attr_count = 1;
sai_attribute_t appliance_attr;
sai_status_t status;

// NOTE: DASH Appliance object should be the first object pushed to SAI
sai_object_id_t sai_appliance_id = 0UL;
appliance_attr.id = SAI_DASH_APPLIANCE_ATTR_LOCAL_REGION_ID;
appliance_attr.value.u32 = entry.local_region_id();
status = sai_dash_appliance_api->create_dash_appliance(&sai_appliance_id, gSwitchId,
attr_count, &appliance_attr);
if (status != SAI_STATUS_SUCCESS && status != SAI_STATUS_NOT_IMPLEMENTED)
{
SWSS_LOG_ERROR("Failed to create dash appliance object in SAI for %s", appliance_id.c_str());
task_process_status handle_status = handleSaiCreateStatus((sai_api_t) SAI_API_DASH_APPLIANCE, status);
if (handle_status != task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}
}

sai_vip_entry_t vip_entry;
vip_entry.switch_id = gSwitchId;
if (!to_sai(entry.sip(), vip_entry.vip))
{
return false;
}
sai_attribute_t appliance_attr;
vector<sai_attribute_t> appliance_attrs;
sai_status_t status;
appliance_attr.id = SAI_VIP_ENTRY_ATTR_ACTION;
appliance_attr.value.u32 = SAI_VIP_ENTRY_ACTION_ACCEPT;
status = sai_dash_vip_api->create_vip_entry(&vip_entry, attr_count, &appliance_attr);
Expand Down Expand Up @@ -103,8 +149,8 @@ bool DashOrch::addApplianceEntry(const string& appliance_id, const dash::applian
return parseHandleSaiStatusFailure(handle_status);
}
}
appliance_entries_[appliance_id] = entry;
SWSS_LOG_NOTICE("Created vip and direction lookup entries for %s", appliance_id.c_str());
appliance_entries_[appliance_id] = ApplianceEntry { sai_appliance_id, entry };
SWSS_LOG_NOTICE("Created appliance, vip and direction lookup entries for %s", appliance_id.c_str());

return true;
}
Expand All @@ -114,15 +160,14 @@ bool DashOrch::removeApplianceEntry(const string& appliance_id)
SWSS_LOG_ENTER();

sai_status_t status;
dash::appliance::Appliance entry;

if (appliance_entries_.find(appliance_id) == appliance_entries_.end())
{
SWSS_LOG_WARN("Appliance id does not exist: %s", appliance_id.c_str());
return true;
}

entry = appliance_entries_[appliance_id];
const auto& entry = appliance_entries_[appliance_id].metadata;
sai_vip_entry_t vip_entry;
vip_entry.switch_id = gSwitchId;
if (!to_sai(entry.sip(), vip_entry.vip))
Expand Down Expand Up @@ -153,8 +198,23 @@ bool DashOrch::removeApplianceEntry(const string& appliance_id)
return parseHandleSaiStatusFailure(handle_status);
}
}

auto sai_appliance_id = appliance_entries_[appliance_id].appliance_id;
if (sai_appliance_id != 0UL)
{
status = sai_dash_appliance_api->remove_dash_appliance(sai_appliance_id);
if (status != SAI_STATUS_SUCCESS && status != SAI_STATUS_NOT_IMPLEMENTED)
{
SWSS_LOG_ERROR("Failed to remove dash appliance object in SAI for %s", appliance_id.c_str());
task_process_status handle_status = handleSaiRemoveStatus((sai_api_t) SAI_API_DASH_APPLIANCE, status);
if (handle_status != task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}
}
}
appliance_entries_.erase(appliance_id);
SWSS_LOG_NOTICE("Removed vip and direction lookup entries for %s", appliance_id.c_str());
SWSS_LOG_NOTICE("Removed appliance, vip and direction lookup entries for %s", appliance_id.c_str());

return true;
}
Expand Down Expand Up @@ -383,7 +443,7 @@ bool DashOrch::addEniObject(const string& eni, EniEntry& entry)
eni_attrs.push_back(eni_attr);

eni_attr.id = SAI_ENI_ATTR_VM_VNI;
auto app_entry = appliance_entries_.begin()->second;
auto& app_entry = appliance_entries_.begin()->second.metadata;
eni_attr.value.u32 = app_entry.vm_vni();
eni_attrs.push_back(eni_attr);

Expand Down Expand Up @@ -417,6 +477,8 @@ bool DashOrch::addEniObject(const string& eni, EniEntry& entry)
}
}

addEniToFC(eni_id, eni);

gCrmOrch->incCrmResUsedCounter(CrmResourceType::CRM_DASH_ENI);

SWSS_LOG_NOTICE("Created ENI object for %s", eni.c_str());
Expand Down Expand Up @@ -499,6 +561,9 @@ bool DashOrch::removeEniObject(const string& eni)
SWSS_LOG_ENTER();

EniEntry entry = eni_entries_[eni];

removeEniFromFC(entry.eni_id, eni);

sai_status_t status = sai_dash_eni_api->remove_eni(entry.eni_id);
if (status != SAI_STATUS_SUCCESS)
{
Expand Down Expand Up @@ -881,3 +946,93 @@ void DashOrch::doTask(ConsumerBase& consumer)
SWSS_LOG_ERROR("Unknown table: %s", tn.c_str());
}
}

void DashOrch::removeEniFromFC(sai_object_id_t oid, const string &name)
{
SWSS_LOG_ENTER();

if (oid == SAI_NULL_OBJECT_ID)
{
SWSS_LOG_WARN("Cannot remove counter on NULL OID for eni %s", name.c_str());
return;
}

if (m_eni_stat_work_queue.find(oid) != m_eni_stat_work_queue.end())
{
m_eni_stat_work_queue.erase(oid);
return;
}

m_eni_name_table->hdel("", name);
m_eni_stat_manager.clearCounterIdList(oid);
SWSS_LOG_DEBUG("Unregistered eni %s to Flex counter", name.c_str());
}

void DashOrch::clearEniFCStats()
{
for (auto it = eni_entries_.begin(); it != eni_entries_.end(); it++)
{
removeEniFromFC(it->second.eni_id, it->first);
}
}

void DashOrch::handleFCStatusUpdate(bool enabled)
{
if (!enabled && m_eni_fc_status)
{
m_fc_update_timer->stop();
clearEniFCStats();
}
else if (enabled && !m_eni_fc_status)
{
m_fc_update_timer->start();
}
m_eni_fc_status = enabled;
}

void DashOrch::addEniToFC(sai_object_id_t oid, const string &name)
{
auto was_empty = m_eni_stat_work_queue.empty();
m_eni_stat_work_queue[oid] = name;
if (was_empty)
{
m_fc_update_timer->start();
}
}

void DashOrch::doTask(SelectableTimer &timer)
{
SWSS_LOG_ENTER();

if (!m_eni_fc_status)
{
m_fc_update_timer->stop();
return ;
}

for (auto it = m_eni_stat_work_queue.begin(); it != m_eni_stat_work_queue.end(); )
{
string value;
const auto id = sai_serialize_object_id(it->first);

if (!gTraditionalFlexCounter || m_vid_to_rid_table->hget("", id, value))
{
SWSS_LOG_INFO("Registering %s, id %s", it->second.c_str(), id.c_str());
std::vector<FieldValueTuple> eniNameFvs;
eniNameFvs.emplace_back(it->second, id);
m_eni_name_table->set("", eniNameFvs);

m_eni_stat_manager.setCounterIdList(it->first, CounterType::ENI, m_counter_stats);
it = m_eni_stat_work_queue.erase(it);
}
else
{
++it;
}
}

if (m_eni_stat_work_queue.empty())
{
m_fc_update_timer->stop();
}
}
29 changes: 28 additions & 1 deletion orchagent/dash/dashorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,30 @@
#include "timer.h"
#include "zmqorch.h"
#include "zmqserver.h"
#include "flex_counter_manager.h"

#include "dash_api/appliance.pb.h"
#include "dash_api/route_type.pb.h"
#include "dash_api/eni.pb.h"
#include "dash_api/qos.pb.h"
#include "dash_api/eni_route.pb.h"

#define ENI_STAT_COUNTER_FLEX_COUNTER_GROUP "ENI_STAT_COUNTER"
#define ENI_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS 10000

struct EniEntry
{
sai_object_id_t eni_id;
dash::eni::Eni metadata;
};

typedef std::map<std::string, dash::appliance::Appliance> ApplianceTable;
struct ApplianceEntry
{
sai_object_id_t appliance_id;
dash::appliance::Appliance metadata;
};

typedef std::map<std::string, ApplianceEntry> ApplianceTable;
typedef std::map<dash::route_type::RoutingType, dash::route_type::RouteType> RoutingTypeTable;
typedef std::map<std::string, EniEntry> EniTable;
typedef std::map<std::string, dash::qos::Qos> QosTable;
Expand All @@ -42,6 +52,7 @@ class DashOrch : public ZmqOrch
DashOrch(swss::DBConnector *db, std::vector<std::string> &tables, swss::ZmqServer *zmqServer);
const EniEntry *getEni(const std::string &eni) const;
bool getRouteTypeActions(dash::route_type::RoutingType routing_type, dash::route_type::RouteType& route_type);
void handleFCStatusUpdate(bool is_enabled);

private:
ApplianceTable appliance_entries_;
Expand Down Expand Up @@ -71,4 +82,20 @@ class DashOrch : public ZmqOrch
bool removeQosEntry(const std::string& qos_name);
bool setEniRoute(const std::string& eni, const dash::eni_route::EniRoute& entry);
bool removeEniRoute(const std::string& eni);

private:
std::map<sai_object_id_t, std::string> m_eni_stat_work_queue;
FlexCounterManager m_eni_stat_manager;
bool m_eni_fc_status = false;
std::unordered_set<std::string> m_counter_stats;
std::unique_ptr<swss::Table> m_eni_name_table;
std::unique_ptr<swss::Table> m_vid_to_rid_table;
std::shared_ptr<swss::DBConnector> m_counter_db;
std::shared_ptr<swss::DBConnector> m_asic_db;
swss::SelectableTimer* m_fc_update_timer = nullptr;

void doTask(swss::SelectableTimer&);
void addEniToFC(sai_object_id_t oid, const std::string& name);
void removeEniFromFC(sai_object_id_t oid, const std::string& name);
void clearEniFCStats();
};
1 change: 1 addition & 0 deletions orchagent/flex_counter/flex_counter_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const unordered_map<CounterType, string> FlexCounterManager::counter_id_field_lo
{ CounterType::TUNNEL, TUNNEL_COUNTER_ID_LIST },
{ CounterType::HOSTIF_TRAP, FLOW_COUNTER_ID_LIST },
{ CounterType::ROUTE, FLOW_COUNTER_ID_LIST },
{ CounterType::ENI, ENI_COUNTER_ID_LIST },
};

FlexManagerDirectory g_FlexManagerDirectory;
Expand Down
1 change: 1 addition & 0 deletions orchagent/flex_counter/flex_counter_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum class CounterType
TUNNEL,
HOSTIF_TRAP,
ROUTE,
ENI
};

// FlexCounterManager allows users to manage a group of flex counters.
Expand Down
Loading

0 comments on commit f09153f

Please sign in to comment.