Skip to content

Commit

Permalink
Support for setting switch level DSCP to TC QoS map (#2023)
Browse files Browse the repository at this point in the history
Signed-off-by: Vineet Mittal <vineetmittal@microsoft.com>
  • Loading branch information
vmittal-msft authored Nov 22, 2021
1 parent da21172 commit 59cab5d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
34 changes: 33 additions & 1 deletion orchagent/qosorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<sai_attribute_t> &attributes)
{
SWSS_LOG_ENTER();
Expand All @@ -241,6 +270,9 @@ sai_object_id_t DscpToTcMapHandler::addQosItem(const vector<sai_attribute_t> &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;
}

Expand Down
3 changes: 3 additions & 0 deletions orchagent/qosorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <unordered_map>
#include <unordered_set>
#include "orch.h"
#include "switchorch.h"
#include "portsorch.h"

const string dscp_to_tc_field_name = "dscp_to_tc_map";
Expand Down Expand Up @@ -71,6 +72,8 @@ class DscpToTcMapHandler : public QosMapHandler
public:
bool convertFieldValuesToAttributes(KeyOpFieldsValuesTuple &tuple, vector<sai_attribute_t> &attributes) override;
sai_object_id_t addQosItem(const vector<sai_attribute_t> &attributes) override;
protected:
void applyDscpToTcMapToSwitch(sai_attr_id_t attr_id, sai_object_id_t sai_dscp_to_tc_map);
};

class MplsTcToTcMapHandler : public QosMapHandler
Expand Down
28 changes: 28 additions & 0 deletions orchagent/switchorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FieldValueTuple> 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;
}
}
}
1 change: 1 addition & 0 deletions orchagent/switchorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class SwitchOrch : public Orch
void restartCheckReply(const std::string &op, const std::string &data, std::vector<swss::FieldValueTuple> &values);
bool setAgingFDB(uint32_t sec);
void set_switch_capability(const std::vector<swss::FieldValueTuple>& 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);
Expand Down

0 comments on commit 59cab5d

Please sign in to comment.