Skip to content

Commit

Permalink
[tests]: Add SRv6 PT Midpoint test to test_port.py
Browse files Browse the repository at this point in the history
Signed-off-by: Carmine Scarpitta <cscarpit@cisco.com>
  • Loading branch information
cscarpitta committed May 22, 2024
1 parent 7b3c808 commit 3e5bb9e
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 4 deletions.
2 changes: 1 addition & 1 deletion orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ bool PortsOrch::addPortBulk(const std::vector<PortConfig> &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);
Expand Down
6 changes: 3 additions & 3 deletions tests/mock_tests/portmgr_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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"},
Expand Down
127 changes: 127 additions & 0 deletions tests/test_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3e5bb9e

Please sign in to comment.