Skip to content
Closed
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
321 changes: 301 additions & 20 deletions orchagent/crmorch.cpp

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions orchagent/crmorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ enum class CrmResourceType
CRM_SRV6_MY_SID_ENTRY,
CRM_SRV6_NEXTHOP,
CRM_NEXTHOP_GROUP_MAP,
CRM_DASH_VNET,
CRM_DASH_ENI,
CRM_DASH_ENI_ETHER_ADDRESS_MAP,
CRM_DASH_IPV4_INBOUND_ROUTING,
CRM_DASH_IPV6_INBOUND_ROUTING,
CRM_DASH_IPV4_OUTBOUND_ROUTING,
CRM_DASH_IPV6_OUTBOUND_ROUTING,
CRM_DASH_IPV4_PA_VALIDATION,
CRM_DASH_IPV6_PA_VALIDATION,
CRM_DASH_IPV4_OUTBOUND_CA_TO_PA,
CRM_DASH_IPV6_OUTBOUND_CA_TO_PA,
CRM_DASH_IPV4_ACL_GROUP,
CRM_DASH_IPV6_ACL_GROUP,
CRM_DASH_IPV4_ACL_RULE,
CRM_DASH_IPV6_ACL_RULE
};

enum class CrmThresholdType
Expand Down Expand Up @@ -63,6 +78,10 @@ class CrmOrch : public Orch
void incCrmAclTableUsedCounter(CrmResourceType resource, sai_object_id_t tableId);
// Decrement "used" counter for the per ACL table CRM resources (ACL entry/counter)
void decCrmAclTableUsedCounter(CrmResourceType resource, sai_object_id_t tableId);
// Increment "used" counter for the per DASH ACL CRM resources (ACL group/rule)
void incCrmDashAclUsedCounter(CrmResourceType resource, sai_object_id_t groupId);
// Decrement "used" counter for the per DASH ACL CRM resources (ACL group/rule)
void decCrmDashAclGroupUsedCounter(CrmResourceType resource, sai_object_id_t groupId);

private:
std::shared_ptr<swss::DBConnector> m_countersDb = nullptr;
Expand Down Expand Up @@ -100,9 +119,11 @@ class CrmOrch : public Orch
void handleSetCommand(const std::string& key, const std::vector<swss::FieldValueTuple>& data);
void doTask(swss::SelectableTimer &timer);
bool getResAvailability(CrmResourceType type, CrmResourceEntry &res);
bool getDashAclGroupResAvailability(CrmResourceType type, CrmResourceEntry &res);
void getResAvailableCounters();
void updateCrmCountersTable();
void checkCrmThresholds();
std::string getCrmAclKey(sai_acl_stage_t stage, sai_acl_bind_point_type_t bindPoint);
std::string getCrmAclTableKey(sai_object_id_t id);
std::string getCrmDashAclGroupKey(sai_object_id_t id);
};
25 changes: 24 additions & 1 deletion orchagent/dash/dashaclorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <swssnet.h>

#include "crmorch.h"
#include "dashaclorch.h"

using namespace std;
Expand All @@ -14,6 +15,7 @@ using namespace swss;
extern sai_dash_acl_api_t* sai_dash_acl_api;
extern sai_dash_eni_api_t* sai_dash_eni_api;
extern sai_object_id_t gSwitchId;
extern CrmOrch *gCrmOrch;

template <typename T, typename... Args>
static bool extractVariables(const string &input, char delimiter, T &output, Args &... args)
Expand Down Expand Up @@ -443,6 +445,11 @@ task_process_status DashAclOrch::taskUpdateDashAclGroup(
return task_failed;
}
acl_group.m_rule_count = 0;

CrmResourceType crm_rtype = acl_group.m_ip_version == SAI_IP_ADDR_FAMILY_IPV4 ?
CrmResourceType::CRM_DASH_IPV4_ACL_GROUP : CrmResourceType::CRM_DASH_IPV6_ACL_GROUP;
gCrmOrch->incCrmDashAclUsedCounter(crm_rtype, acl_group.m_dash_acl_group_id);

SWSS_LOG_NOTICE("Created ACL group %s", key.c_str());
}
else
Expand Down Expand Up @@ -491,6 +498,10 @@ task_process_status DashAclOrch::taskRemoveDashAclGroup(
SWSS_LOG_ERROR("Failed to remove ACL group %s, rv: %s", key.c_str(), sai_serialize_status(status).c_str());
return task_failed;
}
CrmResourceType crm_rtype = acl_group->m_ip_version == SAI_IP_ADDR_FAMILY_IPV4 ?
CrmResourceType::CRM_DASH_IPV4_ACL_GROUP : CrmResourceType::CRM_DASH_IPV6_ACL_GROUP;
gCrmOrch->decCrmDashAclGroupUsedCounter(crm_rtype, acl_group->m_dash_acl_group_id);

m_dash_acl_group_table.erase(key);
SWSS_LOG_NOTICE("Removed ACL group %s", key.c_str());

Expand Down Expand Up @@ -644,6 +655,11 @@ task_process_status DashAclOrch::taskUpdateDashAclRule(
return task_failed;
}
acl_group->m_rule_count++;

CrmResourceType crm_rtype = acl_group->m_ip_version == SAI_IP_ADDR_FAMILY_IPV4 ?
CrmResourceType::CRM_DASH_IPV4_ACL_RULE : CrmResourceType::CRM_DASH_IPV6_ACL_RULE;
gCrmOrch->incCrmDashAclUsedCounter(crm_rtype, acl_group->m_dash_acl_group_id);

SWSS_LOG_NOTICE("Created ACL rule %s", key.c_str());
}
else
Expand Down Expand Up @@ -677,6 +693,8 @@ task_process_status DashAclOrch::taskRemoveDashAclRule(
return task_failed;
}

auto &acl_group = m_dash_acl_group_table[group_id];

auto itr = m_dash_acl_rule_table.find(key);

if (itr == m_dash_acl_rule_table.end())
Expand All @@ -703,7 +721,12 @@ task_process_status DashAclOrch::taskRemoveDashAclRule(
return task_failed;
}
m_dash_acl_rule_table.erase(itr);
m_dash_acl_group_table[group_id].m_rule_count--;
--acl_group.m_rule_count;

CrmResourceType crm_resource = acl_group.m_ip_version == SAI_IP_ADDR_FAMILY_IPV4 ?
CrmResourceType::CRM_DASH_IPV4_ACL_RULE : CrmResourceType::CRM_DASH_IPV6_ACL_RULE;
gCrmOrch->decCrmDashAclGroupUsedCounter(crm_resource, acl_group.m_dash_acl_group_id);

SWSS_LOG_NOTICE("Removed ACL rule %s", key.c_str());

return task_success;
Expand Down
14 changes: 14 additions & 0 deletions orchagent/dash/dashorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "saiextensions.h"
#include "swssnet.h"
#include "tokenize.h"
#include "crmorch.h"

using namespace std;
using namespace swss;
Expand All @@ -25,6 +26,7 @@ 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;

DashOrch::DashOrch(DBConnector *db, vector<string> &tableName) : Orch(db, tableName)
{
Expand Down Expand Up @@ -343,6 +345,9 @@ bool DashOrch::addEniObject(const string& eni, EniEntry& entry)
return parseHandleSaiStatusFailure(handle_status);
}
}

gCrmOrch->incCrmResUsedCounter(CrmResourceType::CRM_DASH_ENI);

SWSS_LOG_NOTICE("Created ENI object for %s", eni.c_str());

return true;
Expand Down Expand Up @@ -373,6 +378,9 @@ bool DashOrch::addEniAddrMapEntry(const string& eni, const EniEntry& entry)
return parseHandleSaiStatusFailure(handle_status);
}
}

gCrmOrch->incCrmResUsedCounter(CrmResourceType::CRM_DASH_ENI_ETHER_ADDRESS_MAP);

SWSS_LOG_NOTICE("Created ENI ether address map entry for %s", eni.c_str());

return true;
Expand Down Expand Up @@ -430,6 +438,9 @@ bool DashOrch::removeEniObject(const string& eni)
return parseHandleSaiStatusFailure(handle_status);
}
}

gCrmOrch->decCrmResUsedCounter(CrmResourceType::CRM_DASH_ENI);

SWSS_LOG_NOTICE("Removed ENI object for %s", eni.c_str());

return true;
Expand Down Expand Up @@ -460,6 +471,9 @@ bool DashOrch::removeEniAddrMapEntry(const string& eni)
return parseHandleSaiStatusFailure(handle_status);
}
}

gCrmOrch->decCrmResUsedCounter(CrmResourceType::CRM_DASH_ENI_ETHER_ADDRESS_MAP);

SWSS_LOG_NOTICE("Removed ENI ether address map entry for %s", eni.c_str());

return true;
Expand Down
11 changes: 11 additions & 0 deletions orchagent/dash/dashrouteorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "swssnet.h"
#include "tokenize.h"
#include "dashorch.h"
#include "crmorch.h"

using namespace std;
using namespace swss;
Expand All @@ -26,6 +27,7 @@ extern sai_dash_outbound_routing_api_t* sai_dash_outbound_routing_api;
extern sai_dash_inbound_routing_api_t* sai_dash_inbound_routing_api;
extern sai_object_id_t gSwitchId;
extern size_t gMaxBulkSize;
extern CrmOrch *gCrmOrch;

static std::unordered_map<std::string, sai_outbound_routing_entry_action_t> sOutboundAction =
{
Expand Down Expand Up @@ -128,6 +130,9 @@ bool DashRouteOrch::addOutboundRoutingPost(const string& key, const OutboundRout

OutboundRoutingEntry entry = { dash_orch_->getEni(ctxt.eni)->eni_id, ctxt.destination, ctxt.action_type, ctxt.vnet, ctxt.overlay_ip };
routing_entries_[key] = entry;

gCrmOrch->incCrmResUsedCounter(ctxt.destination.isV4() ? CrmResourceType::CRM_DASH_IPV4_OUTBOUND_ROUTING : CrmResourceType::CRM_DASH_IPV6_OUTBOUND_ROUTING);

SWSS_LOG_NOTICE("Outbound routing entry for %s added", key.c_str());

return true;
Expand Down Expand Up @@ -183,6 +188,8 @@ bool DashRouteOrch::removeOutboundRoutingPost(const string& key, const OutboundR
}
}

gCrmOrch->decCrmResUsedCounter(ctxt.destination.isV4() ? CrmResourceType::CRM_DASH_IPV4_OUTBOUND_ROUTING : CrmResourceType::CRM_DASH_IPV6_OUTBOUND_ROUTING);

routing_entries_.erase(key);
SWSS_LOG_NOTICE("Outbound routing entry for %s removed", key.c_str());

Expand Down Expand Up @@ -404,6 +411,9 @@ bool DashRouteOrch::addInboundRoutingPost(const string& key, const InboundRoutin

InboundRoutingEntry entry = { dash_orch_->getEni(ctxt.eni)->eni_id, ctxt.vni, ctxt.sip, ctxt.sip_mask, ctxt.action_type, ctxt.vnet, ctxt.pa_validation, ctxt.priority };
routing_rule_entries_[key] = entry;

gCrmOrch->incCrmResUsedCounter(ctxt.sip.isV4() ? CrmResourceType::CRM_DASH_IPV4_INBOUND_ROUTING : CrmResourceType::CRM_DASH_IPV6_INBOUND_ROUTING);

SWSS_LOG_NOTICE("Inbound routing entry for %s added", key.c_str());

return true;
Expand Down Expand Up @@ -462,6 +472,7 @@ bool DashRouteOrch::removeInboundRoutingPost(const string& key, const InboundRou
}
}

gCrmOrch->decCrmResUsedCounter(ctxt.sip.isV4() ? CrmResourceType::CRM_DASH_IPV4_INBOUND_ROUTING : CrmResourceType::CRM_DASH_IPV6_INBOUND_ROUTING);

routing_rule_entries_.erase(key);
SWSS_LOG_NOTICE("Inbound routing entry for %s removed", key.c_str());
Expand Down
20 changes: 20 additions & 0 deletions orchagent/dash/dashvnetorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "swssnet.h"
#include "tokenize.h"
#include "dashorch.h"
#include "crmorch.h"

using namespace std;
using namespace swss;
Expand All @@ -28,6 +29,7 @@ extern sai_dash_outbound_ca_to_pa_api_t* sai_dash_outbound_ca_to_pa_api;
extern sai_dash_pa_validation_api_t* sai_dash_pa_validation_api;
extern sai_object_id_t gSwitchId;
extern size_t gMaxBulkSize;
extern CrmOrch *gCrmOrch;

DashVnetOrch::DashVnetOrch(DBConnector *db, vector<string> &tables) :
vnet_bulker_(sai_dash_vnet_api, gSwitchId, gMaxBulkSize),
Expand Down Expand Up @@ -81,6 +83,9 @@ bool DashVnetOrch::addVnetPost(const string& vnet_name, const DashVnetBulkContex
VnetEntry entry = { id, ctxt.guid };
vnet_table_[vnet_name] = entry;
gVnetNameToId[vnet_name] = id;

gCrmOrch->incCrmResUsedCounter(CrmResourceType::CRM_DASH_VNET);

SWSS_LOG_NOTICE("Vnet entry added for %s", vnet_name.c_str());

return true;
Expand Down Expand Up @@ -134,6 +139,9 @@ bool DashVnetOrch::removeVnetPost(const string& vnet_name, const DashVnetBulkCon
return parseHandleSaiStatusFailure(handle_status);
}
}

gCrmOrch->decCrmResUsedCounter(CrmResourceType::CRM_DASH_VNET);

vnet_table_.erase(vnet_name);
gVnetNameToId.erase(vnet_name);
SWSS_LOG_NOTICE("Vnet entry removed for %s", vnet_name.c_str());
Expand Down Expand Up @@ -372,6 +380,9 @@ bool DashVnetOrch::addOutboundCaToPaPost(const string& key, const VnetMapBulkCon
return parseHandleSaiStatusFailure(handle_status);
}
}

gCrmOrch->incCrmResUsedCounter(ctxt.dip.isV4() ? CrmResourceType::CRM_DASH_IPV4_OUTBOUND_CA_TO_PA : CrmResourceType::CRM_DASH_IPV6_OUTBOUND_CA_TO_PA);

SWSS_LOG_NOTICE("Outbound CA to PA map entry for %s added", key.c_str());

return true;
Expand Down Expand Up @@ -404,6 +415,9 @@ bool DashVnetOrch::addPaValidationPost(const string& key, const VnetMapBulkConte
return parseHandleSaiStatusFailure(handle_status);
}
}

gCrmOrch->incCrmResUsedCounter(ctxt.underlay_ip.isV4() ? CrmResourceType::CRM_DASH_IPV4_PA_VALIDATION : CrmResourceType::CRM_DASH_IPV6_PA_VALIDATION);

SWSS_LOG_NOTICE("PA validation entry for %s added", key.c_str());

return true;
Expand Down Expand Up @@ -501,6 +515,9 @@ bool DashVnetOrch::removeOutboundCaToPaPost(const string& key, const VnetMapBulk
return parseHandleSaiStatusFailure(handle_status);
}
}

gCrmOrch->decCrmResUsedCounter(vnet_map_table_[key].dip.isV4() ? CrmResourceType::CRM_DASH_IPV4_OUTBOUND_CA_TO_PA : CrmResourceType::CRM_DASH_IPV6_OUTBOUND_CA_TO_PA);

SWSS_LOG_NOTICE("Outbound CA to PA map entry for %s removed", key.c_str());

return true;
Expand Down Expand Up @@ -533,6 +550,9 @@ bool DashVnetOrch::removePaValidationPost(const string& key, const VnetMapBulkCo
return parseHandleSaiStatusFailure(handle_status);
}
}

gCrmOrch->decCrmResUsedCounter(vnet_map_table_[key].underlay_ip.isV4() ? CrmResourceType::CRM_DASH_IPV4_PA_VALIDATION : CrmResourceType::CRM_DASH_IPV6_PA_VALIDATION);

SWSS_LOG_NOTICE("PA validation entry for %s removed", key.c_str());

return true;
Expand Down
7 changes: 5 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1755,8 +1755,6 @@ def manage_dvs(request) -> str:
buffer_model = request.config.getoption("--buffer_model")
force_recreate = request.config.getoption("--force-recreate-dvs")
graceful_stop = request.config.getoption("--graceful-stop")
global NUM_PORTS
NUM_PORTS = request.config.getoption("--num-ports")

dvs = None
curr_dvs_env = [] # lgtm[py/unused-local-variable]
Expand Down Expand Up @@ -1819,6 +1817,11 @@ def update_dvs(log_path, new_dvs_env=[]):
@pytest.fixture(scope="module")
def dvs(request, manage_dvs) -> DockerVirtualSwitch:
dvs_env = getattr(request.module, "DVS_ENV", [])
global NUM_PORTS
if getattr(request.module, "NUM_PORTS", None):
NUM_PORTS = getattr(request.module, "NUM_PORTS")
else:
NUM_PORTS = request.config.getoption("--num-ports")
name = request.config.getoption("--dvsname")
log_path = name if name else request.module.__name__

Expand Down
Loading