Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply DSCP_TO_TC_MAP from PORT_QOS_MAP|global to switch level #2314

Merged
merged 5 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 12 additions & 2 deletions orchagent/qosorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ map<string, string> qos_to_ref_table_map = {
#define DSCP_MAX_VAL 63
#define EXP_MAX_VAL 7

#define DEFAULT_DSCP_TO_TC_MAP_NAME "AZURE"

task_process_status QosMapHandler::processWorkItem(Consumer& consumer, KeyOpFieldsValuesTuple &tuple)
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -148,6 +150,16 @@ task_process_status QosMapHandler::processWorkItem(Consumer& consumer, KeyOpFiel
freeAttribResources(attributes);
return task_process_status::task_failed;
}
if ((qos_map_type_name == CFG_DSCP_TO_TC_MAP_TABLE_NAME) && (qos_object_name == DEFAULT_DSCP_TO_TC_MAP_NAME))
bingwang-ms marked this conversation as resolved.
Show resolved Hide resolved
{
DscpToTcMapHandler *handler = dynamic_cast<DscpToTcMapHandler*>(this);
if (handler)
{
handler->applyDscpToTcMapToSwitch(SAI_SWITCH_ATTR_QOS_DSCP_TO_TC_MAP, sai_object);
SWSS_LOG_NOTICE("Applied DSCP_TO_TC_MAP %s to switch level", DEFAULT_DSCP_TO_TC_MAP_NAME);
}
}

(*(QosOrch::getTypeMap()[qos_map_type_name]))[qos_object_name].m_saiObjectId = sai_object;
(*(QosOrch::getTypeMap()[qos_map_type_name]))[qos_object_name].m_pendingRemove = false;
SWSS_LOG_NOTICE("Created [%s:%s]", qos_map_type_name.c_str(), qos_object_name.c_str());
Expand Down Expand Up @@ -292,8 +304,6 @@ sai_object_id_t DscpToTcMapHandler::addQosItem(const vector<sai_attribute_t> &at
}
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
2 changes: 1 addition & 1 deletion orchagent/qosorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class DscpToTcMapHandler : public QosMapHandler
bool convertFieldValuesToAttributes(KeyOpFieldsValuesTuple &tuple, vector<sai_attribute_t> &attributes) override;
sai_object_id_t addQosItem(const vector<sai_attribute_t> &attributes) override;
bool removeQosItem(sai_object_id_t sai_object);
protected:

void applyDscpToTcMapToSwitch(sai_attr_id_t attr_id, sai_object_id_t sai_dscp_to_tc_map);
};

Expand Down
3 changes: 2 additions & 1 deletion tests/mock_tests/qosorch_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,8 @@ namespace qosorch_test
entries.clear();
// Drain DSCP_TO_TC_MAP table
static_cast<Orch *>(gQosOrch)->doTask();
ASSERT_EQ((*QosOrch::getTypeMap()[CFG_DSCP_TO_TC_MAP_TABLE_NAME])["AZURE_1"].m_saiObjectId, switch_dscp_to_tc_map_id);
// As we hardcode the default map name to AZURE, pushing AZURE_1 makes no change
ASSERT_EQ((*QosOrch::getTypeMap()[CFG_DSCP_TO_TC_MAP_TABLE_NAME])["AZURE"].m_saiObjectId, switch_dscp_to_tc_map_id);

entries.push_back({"AZURE_1", "DEL", {}});
consumer->addToSync(entries);
Expand Down
55 changes: 55 additions & 0 deletions tests/test_qos_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,61 @@ def test_port_mpls_tc(self, dvs):
port_cnt = len(swsscommon.Table(self.config_db, CFG_PORT_TABLE_NAME).getKeys())
assert port_cnt == cnt

class TestDscpToTcMap(object):
ASIC_QOS_MAP_STR = "ASIC_STATE:SAI_OBJECT_TYPE_QOS_MAP"
ASIC_PORT_STR = "ASIC_STATE:SAI_OBJECT_TYPE_PORT"
ASIC_SWITCH_STR = "ASIC_STATE:SAI_OBJECT_TYPE_SWITCH"

def init_test(self, dvs):
dvs.setup_db()
self.asic_db = dvs.get_asic_db()
self.config_db = dvs.get_config_db()
self.asic_qos_map_ids = self.asic_db.get_keys(self.ASIC_QOS_MAP_STR)
self.asic_qos_map_count = len(self.asic_qos_map_ids)
self.dscp_to_tc_table = swsscommon.Table(self.config_db.db_connection, swsscommon.CFG_DSCP_TO_TC_MAP_TABLE_NAME)

def get_qos_id(self):
diff = set(self.asic_db.get_keys(self.ASIC_QOS_MAP_STR)) - set(self.asic_qos_map_ids)
assert len(diff) <= 1
return None if len(diff) == 0 else diff.pop()

def test_dscp_to_tc_map_applied_to_switch(self, dvs):
self.init_test(dvs)
dscp_to_tc_map_id = None
created_new_map = False
try:
existing_map = self.dscp_to_tc_table.getKeys()
if "AZURE" not in existing_map:
# Create a DSCP_TO_TC map
dscp_to_tc_map = [(str(i), str(i)) for i in range(0, 63)]
self.dscp_to_tc_table.set("AZURE", swsscommon.FieldValuePairs(dscp_to_tc_map))

self.asic_db.wait_for_n_keys(self.ASIC_QOS_MAP_STR, self.asic_qos_map_count + 1)

# Get the DSCP_TO_TC map ID
dscp_to_tc_map_id = self.get_qos_id()
assert(dscp_to_tc_map_id is not None)

# Assert the expected values
fvs = self.asic_db.get_entry(self.ASIC_QOS_MAP_STR, dscp_to_tc_map_id)
assert(fvs.get("SAI_QOS_MAP_ATTR_TYPE") == "SAI_QOS_MAP_TYPE_DSCP_TO_TC")
created_new_map = True
else:
for id in self.asic_qos_map_ids:
fvs = self.asic_db.get_entry(self.ASIC_QOS_MAP_STR, id)
if fvs.get("SAI_QOS_MAP_ATTR_TYPE") == "SAI_QOS_MAP_TYPE_DSCP_TO_TC":
dscp_to_tc_map_id = id
break

# Check the switch level DSCP_TO_TC_MAP is applied
switch_oid = dvs.getSwitchOid()
fvs = self.asic_db.get_entry(self.ASIC_SWITCH_STR, switch_oid)
assert(fvs.get("SAI_SWITCH_ATTR_QOS_DSCP_TO_TC_MAP") == dscp_to_tc_map_id)

finally:
if created_new_map:
self.dscp_to_tc_table._del("AZURE")


# Add Dummy always-pass test at end as workaroud
# for issue when Flaky fail on final test it invokes module tear-down before retrying
Expand Down