From e8ce795eb23df667105283ac66c0bf2411393496 Mon Sep 17 00:00:00 2001 From: Carmine Scarpitta Date: Fri, 15 Sep 2023 15:46:09 +0200 Subject: [PATCH] [tests]: Add SRv6 PT Midpoint test to test_port.py Signed-off-by: Carmine Scarpitta --- orchagent/portsorch.cpp | 2 +- tests/mock_tests/portmgr_ut.cpp | 6 +- tests/test_port.py | 127 ++++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+), 4 deletions(-) diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index baa6c57860..137d49546a 100644 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -1007,7 +1007,7 @@ bool PortsOrch::addPortBulk(const std::vector &portList) m_portPtTam[cit.key] = m_ptTam; } } - + attr.id = SAI_PORT_ATTR_PATH_TRACING_INTF; attr.value.u16 = cit.pt_intf_id.value; attrList.push_back(attr); diff --git a/tests/mock_tests/portmgr_ut.cpp b/tests/mock_tests/portmgr_ut.cpp index 60df06e915..b7b83590bd 100644 --- a/tests/mock_tests/portmgr_ut.cpp +++ b/tests/mock_tests/portmgr_ut.cpp @@ -131,7 +131,7 @@ namespace portmgr_ut Table cfg_port_table(m_config_db.get(), CFG_PORT_TABLE_NAME); // Port is not ready, verify that doTask does not handle port configuration - + cfg_port_table.set("Ethernet0", { {"speed", "100000"}, {"index", "1"}, @@ -162,14 +162,14 @@ namespace portmgr_ut ASSERT_FALSE(value_opt); } - TEST_F(PortMgrTest, ConfigurePortPTTimestampTemplate2) + TEST_F(PortMgrTest, ConfigurePortPTNonDefaultTimestampTemplate) { Table state_port_table(m_state_db.get(), STATE_PORT_TABLE_NAME); Table app_port_table(m_app_db.get(), APP_PORT_TABLE_NAME); Table cfg_port_table(m_config_db.get(), CFG_PORT_TABLE_NAME); // Port is not ready, verify that doTask does not handle port configuration - + cfg_port_table.set("Ethernet0", { {"speed", "100000"}, {"index", "1"}, diff --git a/tests/test_port.py b/tests/test_port.py index 3853a61ffe..d7bf62d2d7 100644 --- a/tests/test_port.py +++ b/tests/test_port.py @@ -305,6 +305,133 @@ def test_PortHostTxSignalSet(self, dvs, testlog): expected_fields = {"SAI_PORT_ATTR_HOST_TX_SIGNAL_ENABLE":"false"} adb.wait_for_field_match("ASIC_STATE:SAI_OBJECT_TYPE_PORT", port_oid, expected_fields) + def test_PortPathTracing(self, dvs, testlog): + pdb = swsscommon.DBConnector(0, dvs.redis_sock, 0) + adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + cdb = swsscommon.DBConnector(4, dvs.redis_sock, 0) + + ctbl = swsscommon.Table(cdb, "PORT") + ptbl = swsscommon.Table(pdb, "PORT_TABLE") + atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") + + # get the number of ports before removal + num_of_ports = len(atbl.getKeys()) + + initial_entries = set(atbl.getKeys()) + + # read port info and save it + (status, ports_info) = ctbl.get("Ethernet124") + assert status + + # remove buffer pg cfg for the port (record the buffer pgs before removing them) + pgs = dvs.get_config_db().get_keys('BUFFER_PG') + buffer_pgs = {} + for key in pgs: + if "Ethernet124" in key: + buffer_pgs[key] = dvs.get_config_db().get_entry('BUFFER_PG', key) + dvs.get_config_db().delete_entry('BUFFER_PG', key) + dvs.get_app_db().wait_for_deleted_entry("BUFFER_PG_TABLE", key) + + # remove buffer queue cfg for the port + queues = dvs.get_config_db().get_keys('BUFFER_QUEUE') + buffer_queues = {} + for key in queues: + if "Ethernet124" in key: + buffer_queues[key] = dvs.get_config_db().get_entry('BUFFER_QUEUE', key) + dvs.get_config_db().delete_entry('BUFFER_QUEUE', key) + dvs.get_app_db().wait_for_deleted_entry('BUFFER_QUEUE_TABLE', key) + + # shutdown port + dvs.port_admin_set("Ethernet124", 'down') + + # remove this port + ctbl.delete("Ethernet124") + + # verify that the port has been removed + num = dvs.get_asic_db().wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_PORT", num_of_ports - 1) + assert len(num) == num_of_ports - 1 + + # re-add the port with Path Tracing enabled + fvs = swsscommon.FieldValuePairs(ports_info + (("pt_interface_id", "129"), ("pt_timestamp_template", "template2"))) + ctbl.set("Ethernet124", fvs) + + # check application database + dvs.get_app_db().wait_for_entry('PORT_TABLE', "Ethernet124") + (status, fvs) = ptbl.get("Ethernet124") + assert status + for fv in fvs: + if fv[0] == "pt_interface_id": + assert fv[1] == "129" + if fv[0] == "pt_timestamp_template": + assert fv[1] == "template2" + + # verify that the port has been re-added + num = dvs.get_asic_db().wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_PORT", num_of_ports) + assert len(num) == num_of_ports + + # check ASIC DB + atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") + # get PT Interface ID and validate it to be 129 + entries = set(atbl.getKeys()) + new_entries = list(entries - initial_entries) + assert len(new_entries) == 1, "Wrong number of created entries." + + (status, fvs) = atbl.get(new_entries[0]) + assert status + + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_PATH_TRACING_INTF": + assert fv[1] == "129" + if fv[0] == "SAI_PORT_ATTR_PATH_TRACING_TIMESTAMP_TYPE": + assert fv[1] == "SAI_PORT_PATH_TRACING_TIMESTAMP_TYPE_12_19" + + # change Path Tracing Interface ID and Timestamp Template on the port + fvs = swsscommon.FieldValuePairs([("pt_interface_id", "130"), ("pt_timestamp_template", "template3")]) + ctbl.set("Ethernet124", fvs) + time.sleep(5) + + # check application database + (status, fvs) = ptbl.get("Ethernet124") + assert status + for fv in fvs: + if fv[0] == "pt_interface_id": + assert fv[1] == "130" + if fv[0] == "pt_timestamp_template": + assert fv[1] == "template3" + + time.sleep(5) + + # check ASIC DB + # get PT Interface ID and validate it to be 130 + (status, fvs) = atbl.get(new_entries[0]) + assert status + + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_PATH_TRACING_INTF": + assert fv[1] == "130" + if fv[0] == "SAI_PORT_ATTR_PATH_TRACING_TIMESTAMP_TYPE": + assert fv[1] == "SAI_PORT_PATH_TRACING_TIMESTAMP_TYPE_16_23" + + # shutdown port + dvs.port_admin_set("Ethernet124", 'down') + + # remove the port + ctbl.delete("Ethernet124") + + # re-add the port with the original configuration + ctbl.set("Ethernet124", ports_info) + + # verify that the port has been re-added + num = dvs.get_asic_db().wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_PORT", num_of_ports) + assert len(num) == num_of_ports + + # re-add buffer pg and queue cfg to the port + for key, pg in buffer_pgs.items(): + dvs.get_config_db().update_entry("BUFFER_PG", key, pg) + + for key, queue in buffer_queues.items(): + dvs.get_config_db().update_entry("BUFFER_QUEUE", key, queue) + # Add Dummy always-pass test at end as workaroud # for issue when Flaky fail on final test it invokes module tear-down before retrying