Skip to content

Commit 97062de

Browse files
committed
Support for setting switch level DSCP to TC QoS map
Signed-off-by: Vineet Mittal <[email protected]>
1 parent 5f8ebfa commit 97062de

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

orchagent/qosorch.cpp

+40
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
using namespace std;
1414

15+
extern sai_switch_api_t *sai_switch_api;
1516
extern sai_port_api_t *sai_port_api;
1617
extern sai_queue_api_t *sai_queue_api;
1718
extern sai_scheduler_api_t *sai_scheduler_api;
@@ -20,7 +21,9 @@ extern sai_qos_map_api_t *sai_qos_map_api;
2021
extern sai_scheduler_group_api_t *sai_scheduler_group_api;
2122
extern sai_switch_api_t *sai_switch_api;
2223
extern sai_acl_api_t* sai_acl_api;
24+
extern bool querySwitchDscpToTcCapability(sai_object_type_t, sai_attr_id_t);
2325

26+
extern SwitchOrch *gSwitchOrch;
2427
extern PortsOrch *gPortsOrch;
2528
extern sai_object_id_t gSwitchId;
2629
extern CrmOrch *gCrmOrch;
@@ -207,12 +210,41 @@ bool DscpToTcMapHandler::convertFieldValuesToAttributes(KeyOpFieldsValuesTuple &
207210
return true;
208211
}
209212

213+
bool DscpToTcMapHandler::applyDscpToTcMapToSwitch(sai_attr_id_t attr_id, sai_object_id_t map_id)
214+
{
215+
SWSS_LOG_ENTER();
216+
217+
/* Apply DSCP_TO_TC QoS map at switch */
218+
sai_attribute_t attr;
219+
attr.id = attr_id;
220+
attr.value.oid = map_id;
221+
222+
sai_status_t status = sai_switch_api->set_switch_attribute(gSwitchId, &attr);
223+
if (status != SAI_STATUS_SUCCESS)
224+
{
225+
SWSS_LOG_ERROR("Failed to apply DSCP_TO_TC QoS map to switch rv:%d", status);
226+
return false;
227+
}
228+
229+
SWSS_LOG_NOTICE("Applied DSCP_TO_TC QoS map to switch successfully");
230+
return true;
231+
}
232+
210233
sai_object_id_t DscpToTcMapHandler::addQosItem(const vector<sai_attribute_t> &attributes)
211234
{
212235
SWSS_LOG_ENTER();
213236
sai_status_t sai_status;
214237
sai_object_id_t sai_object;
215238
vector<sai_attribute_t> qos_map_attrs;
239+
bool rv;
240+
241+
/* Query DSCP_TO_TC QoS map at switch capability */
242+
rv = gSwitchOrch->querySwitchDscpToTcCapability(SAI_OBJECT_TYPE_SWITCH, SAI_SWITCH_ATTR_QOS_DSCP_TO_TC_MAP);
243+
if (rv == false)
244+
{
245+
SWSS_LOG_ERROR("Switch level DSCP to TC QoS map configuration is not supported");
246+
return false;
247+
}
216248

217249
sai_attribute_t qos_map_attr;
218250
qos_map_attr.id = SAI_QOS_MAP_ATTR_TYPE;
@@ -231,6 +263,14 @@ sai_object_id_t DscpToTcMapHandler::addQosItem(const vector<sai_attribute_t> &at
231263
return SAI_NULL_OBJECT_ID;
232264
}
233265
SWSS_LOG_DEBUG("created QosMap object:%" PRIx64, sai_object);
266+
267+
rv = applyDscpToTcMapToSwitch(SAI_SWITCH_ATTR_QOS_DSCP_TO_TC_MAP, sai_object);
268+
if (rv == false)
269+
{
270+
SWSS_LOG_ERROR("Failed to apply dscp_to_tc map at switch");
271+
return SAI_NULL_OBJECT_ID;
272+
}
273+
234274
return sai_object;
235275
}
236276

orchagent/qosorch.h

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <unordered_map>
66
#include <unordered_set>
77
#include "orch.h"
8+
#include "switchorch.h"
89
#include "portsorch.h"
910

1011
const string dscp_to_tc_field_name = "dscp_to_tc_map";
@@ -69,6 +70,8 @@ class DscpToTcMapHandler : public QosMapHandler
6970
public:
7071
bool convertFieldValuesToAttributes(KeyOpFieldsValuesTuple &tuple, vector<sai_attribute_t> &attributes) override;
7172
sai_object_id_t addQosItem(const vector<sai_attribute_t> &attributes) override;
73+
protected:
74+
bool applyDscpToTcMapToSwitch(sai_attr_id_t attr_id, sai_object_id_t sai_dscp_to_tc_map);
7275
};
7376

7477
class MplsTcToTcMapHandler : public QosMapHandler

orchagent/switchorch.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -613,3 +613,22 @@ void SwitchOrch::querySwitchTpidCapability()
613613
set_switch_capability(fvVector);
614614
}
615615
}
616+
617+
bool SwitchOrch::querySwitchDscpToTcCapability(sai_object_type_t sai_object, sai_attr_id_t attr_id)
618+
{
619+
SWSS_LOG_ENTER();
620+
621+
/* Check if SAI is capable of handling Switch level DSCP to TC QoS map */
622+
vector<FieldValueTuple> fvVector;
623+
sai_status_t status = SAI_STATUS_SUCCESS;
624+
sai_attr_capability_t capability;
625+
626+
status = sai_query_attribute_capability(gSwitchId, sai_object, attr_id, &capability);
627+
if (status != SAI_STATUS_SUCCESS)
628+
{
629+
SWSS_LOG_WARN("Could not query switch level DSCP to TC map %d", status);
630+
return false;
631+
}
632+
633+
return true;
634+
}

orchagent/switchorch.h

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class SwitchOrch : public Orch
2828
void restartCheckReply(const std::string &op, const std::string &data, std::vector<swss::FieldValueTuple> &values);
2929
bool setAgingFDB(uint32_t sec);
3030
void set_switch_capability(const std::vector<swss::FieldValueTuple>& values);
31+
bool querySwitchDscpToTcCapability(sai_object_type_t sai_object, sai_attr_id_t attr_id);
3132
private:
3233
void doTask(Consumer &consumer);
3334
void doTask(swss::SelectableTimer &timer);

0 commit comments

Comments
 (0)