From 59cab5d939d8701362515fbb877a1e36dccf07fd Mon Sep 17 00:00:00 2001 From: vmittal-msft <46945843+vmittal-msft@users.noreply.github.com> Date: Mon, 22 Nov 2021 10:47:45 -0800 Subject: [PATCH] Support for setting switch level DSCP to TC QoS map (#2023) Signed-off-by: Vineet Mittal --- orchagent/qosorch.cpp | 34 +++++++++++++++++++++++++++++++++- orchagent/qosorch.h | 3 +++ orchagent/switchorch.cpp | 28 ++++++++++++++++++++++++++++ orchagent/switchorch.h | 1 + 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/orchagent/qosorch.cpp b/orchagent/qosorch.cpp index 0431b369d318..edd5db34432f 100644 --- a/orchagent/qosorch.cpp +++ b/orchagent/qosorch.cpp @@ -14,15 +14,16 @@ using namespace std; +extern sai_switch_api_t *sai_switch_api; extern sai_port_api_t *sai_port_api; extern sai_queue_api_t *sai_queue_api; extern sai_scheduler_api_t *sai_scheduler_api; extern sai_wred_api_t *sai_wred_api; extern sai_qos_map_api_t *sai_qos_map_api; extern sai_scheduler_group_api_t *sai_scheduler_group_api; -extern sai_switch_api_t *sai_switch_api; extern sai_acl_api_t* sai_acl_api; +extern SwitchOrch *gSwitchOrch; extern PortsOrch *gPortsOrch; extern sai_object_id_t gSwitchId; extern CrmOrch *gCrmOrch; @@ -217,6 +218,34 @@ bool DscpToTcMapHandler::convertFieldValuesToAttributes(KeyOpFieldsValuesTuple & return true; } +void DscpToTcMapHandler::applyDscpToTcMapToSwitch(sai_attr_id_t attr_id, sai_object_id_t map_id) +{ + SWSS_LOG_ENTER(); + bool rv = true; + + /* Query DSCP_TO_TC QoS map at switch capability */ + rv = gSwitchOrch->querySwitchDscpToTcCapability(SAI_OBJECT_TYPE_SWITCH, SAI_SWITCH_ATTR_QOS_DSCP_TO_TC_MAP); + if (rv == false) + { + SWSS_LOG_ERROR("Switch level DSCP to TC QoS map configuration is not supported"); + return; + } + + /* Apply DSCP_TO_TC QoS map at switch */ + sai_attribute_t attr; + attr.id = attr_id; + attr.value.oid = map_id; + + sai_status_t status = sai_switch_api->set_switch_attribute(gSwitchId, &attr); + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_ERROR("Failed to apply DSCP_TO_TC QoS map to switch rv:%d", status); + return; + } + + SWSS_LOG_NOTICE("Applied DSCP_TO_TC QoS map to switch successfully"); +} + sai_object_id_t DscpToTcMapHandler::addQosItem(const vector &attributes) { SWSS_LOG_ENTER(); @@ -241,6 +270,9 @@ sai_object_id_t DscpToTcMapHandler::addQosItem(const vector &at return SAI_NULL_OBJECT_ID; } SWSS_LOG_DEBUG("created QosMap object:%" PRIx64, sai_object); + + applyDscpToTcMapToSwitch(SAI_SWITCH_ATTR_QOS_DSCP_TO_TC_MAP, sai_object); + return sai_object; } diff --git a/orchagent/qosorch.h b/orchagent/qosorch.h index 69e7cef70b2e..cd265d59ece0 100644 --- a/orchagent/qosorch.h +++ b/orchagent/qosorch.h @@ -5,6 +5,7 @@ #include #include #include "orch.h" +#include "switchorch.h" #include "portsorch.h" const string dscp_to_tc_field_name = "dscp_to_tc_map"; @@ -71,6 +72,8 @@ class DscpToTcMapHandler : public QosMapHandler public: bool convertFieldValuesToAttributes(KeyOpFieldsValuesTuple &tuple, vector &attributes) override; sai_object_id_t addQosItem(const vector &attributes) override; +protected: + void applyDscpToTcMapToSwitch(sai_attr_id_t attr_id, sai_object_id_t sai_dscp_to_tc_map); }; class MplsTcToTcMapHandler : public QosMapHandler diff --git a/orchagent/switchorch.cpp b/orchagent/switchorch.cpp index 05a36ec87c05..daeace8b08a5 100644 --- a/orchagent/switchorch.cpp +++ b/orchagent/switchorch.cpp @@ -613,3 +613,31 @@ void SwitchOrch::querySwitchTpidCapability() set_switch_capability(fvVector); } } + +bool SwitchOrch::querySwitchDscpToTcCapability(sai_object_type_t sai_object, sai_attr_id_t attr_id) +{ + SWSS_LOG_ENTER(); + + /* Check if SAI is capable of handling Switch level DSCP to TC QoS map */ + vector fvVector; + sai_status_t status = SAI_STATUS_SUCCESS; + sai_attr_capability_t capability; + + status = sai_query_attribute_capability(gSwitchId, sai_object, attr_id, &capability); + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_WARN("Could not query switch level DSCP to TC map %d", status); + return false; + } + else + { + if (capability.set_implemented) + { + return true; + } + else + { + return false; + } + } +} diff --git a/orchagent/switchorch.h b/orchagent/switchorch.h index 86181e19df74..46d165bd48a4 100644 --- a/orchagent/switchorch.h +++ b/orchagent/switchorch.h @@ -28,6 +28,7 @@ class SwitchOrch : public Orch void restartCheckReply(const std::string &op, const std::string &data, std::vector &values); bool setAgingFDB(uint32_t sec); void set_switch_capability(const std::vector& values); + bool querySwitchDscpToTcCapability(sai_object_type_t sai_object, sai_attr_id_t attr_id); private: void doTask(Consumer &consumer); void doTask(swss::SelectableTimer &timer);