Skip to content

Commit 7c966bc

Browse files
author
vedganes
committed
[inbandif] VS tests for inbandif and remote neigh in asic db
Signed-off-by: vedganes <vedavinayagam.ganesan@nokia.com> - Added tests for inband if (port type) and remote neigh programming in asic db and kernel - Fixed switch_id values in the system port config.
1 parent 67d448f commit 7c966bc

File tree

5 files changed

+318
-197
lines changed

5 files changed

+318
-197
lines changed

tests/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,7 @@ def handle_neighconn(self):
14451445
def get_chassis_instance_port_statuses(self):
14461446
instance_to_port_status_map = {}
14471447
if "neighbor_connections" not in self.virt_topo:
1448-
return instance_to_neighbor_map
1448+
return instance_to_port_status_map
14491449

14501450
working_dir = os.getcwd()
14511451
for conn, endpoints in self.virt_topo["neighbor_connections"].items():

tests/test_virtual_chassis.py

+125-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,40 @@
44
import ast
55

66
class TestVirtualChassis(object):
7+
8+
def config_inbandif_port(self, vct, ibport):
9+
"""This function configures port type inband interface in each linecard"""
10+
11+
dvss = vct.dvss
12+
for name in dvss.keys():
13+
dvs = dvss[name]
14+
# Get the config info
15+
config_db = dvs.get_config_db()
16+
metatbl = config_db.get_entry("DEVICE_METADATA", "localhost")
17+
18+
cfg_switch_type = metatbl.get("switch_type")
19+
20+
# Configure only for line cards
21+
if cfg_switch_type == "voq":
22+
dvs.runcmd(f"config interface startup {ibport}")
23+
config_db.create_entry("VOQ_INBAND_INTERFACE", f"{ibport}", {"inband_type": "port"})
24+
25+
def del_inbandif_port(self, vct, ibport):
26+
"""This function deletes existing port type inband interface"""
27+
28+
dvss = vct.dvss
29+
for name in dvss.keys():
30+
dvs = dvss[name]
31+
# Get the config info
32+
config_db = dvs.get_config_db()
33+
metatbl = config_db.get_entry("DEVICE_METADATA", "localhost")
34+
35+
cfg_switch_type = metatbl.get("switch_type")
36+
37+
# Applicable only for line cards
38+
if cfg_switch_type == "voq":
39+
config_db.delete_entry("VOQ_INBAND_INTERFACE", f"{ibport}")
40+
741
def test_connectivity(self, vct):
842
if vct is None:
943
return
@@ -155,9 +189,24 @@ def test_chassis_system_neigh(self, vct):
155189
This test validates that:
156190
(i) Local neighbor entry is created with encap index
157191
(ii) Local neighbor is synced to chassis ap db with assigned encap index
158-
TODO: (iii) Remote neighbor entry is created in ASIC_DB with received encap index
192+
(iii) Remote neighbor entry is created in ASIC_DB with received encap index
159193
"""
160194

195+
# We use Ethernet0 as inband port in each line card. In real hardware, this will be a
196+
# special port used for inband. For testing purpose, we need port record and rif record
197+
# for the inband interface and valid kernel interface. Since Ethernet0 is already
198+
# setup, the port record, rif record and kernel interface already exist. So we use it
199+
# for testing
200+
inband_port = "Ethernet0"
201+
202+
# Configure port type inband interface
203+
self.config_inbandif_port(vct, inband_port)
204+
205+
# Test neighbor on Ethernet4 since Ethernet0 is used as Inband port
206+
test_neigh_dev = "Ethernet4"
207+
test_neigh_ip = "10.8.104.3"
208+
test_neigh_mac = "00:01:02:03:04:05"
209+
161210
dvss = vct.dvss
162211
for name in dvss.keys():
163212
dvs = dvss[name]
@@ -174,7 +223,7 @@ def test_chassis_system_neigh(self, vct):
174223
if lc_switch_id == "0":
175224

176225
# Add a static neighbor
177-
_, res = dvs.runcmd(['sh', "-c", "ip neigh add 10.8.101.2 lladdr 00:01:02:03:04:05 dev Ethernet0"])
226+
_, res = dvs.runcmd(['sh', "-c", f"ip neigh add {test_neigh_ip} lladdr {test_neigh_mac} dev {test_neigh_dev}"])
178227
assert res == "", "Error configuring static neigh"
179228

180229
asic_db = dvs.get_asic_db()
@@ -185,7 +234,7 @@ def test_chassis_system_neigh(self, vct):
185234
test_neigh = ""
186235
for nkey in neighkeys:
187236
ne = ast.literal_eval(nkey)
188-
if ne['ip'] == '10.8.101.2':
237+
if ne['ip'] == test_neigh_ip:
189238
test_neigh = nkey
190239
break
191240

@@ -211,7 +260,7 @@ def test_chassis_system_neigh(self, vct):
211260
for sysnk in sysneighkeys:
212261
sysnk_tok = sysnk.split("|")
213262
assert len(sysnk_tok) == 3, "Invalid system neigh key in chassis app db"
214-
if sysnk_tok[2] == "10.8.101.2":
263+
if sysnk_tok[2] == test_neigh_ip:
215264
test_sysneigh = sysnk
216265
break
217266

@@ -224,7 +273,79 @@ def test_chassis_system_neigh(self, vct):
224273
assert encap_index == sys_neigh_encap_index, "Encap index not sync-ed correctly"
225274

226275
break
276+
277+
# Verify programming of remote neighbor in asic db and programming of static route and static
278+
# neigh in the kernel for the remote neighbor. The neighbor created in linecard 1 will be a
279+
# remote neighbor in other linecards. Verity existence of the test neighbor in linecards other
280+
# than linecard 1
281+
dvss = vct.dvss
282+
for name in dvss.keys():
283+
dvs = dvss[name]
284+
285+
config_db = dvs.get_config_db()
286+
metatbl = config_db.get_entry("DEVICE_METADATA", "localhost")
287+
288+
cfg_switch_type = metatbl.get("switch_type")
289+
290+
# Neighbor record verifiation done in line card
291+
if cfg_switch_type == "voq":
292+
lc_switch_id = metatbl.get("switch_id")
293+
assert lc_switch_id != "", "Got error in getting switch_id from CONFIG_DB DEVICE_METADATA"
294+
if lc_switch_id != "0":
295+
# Linecard other than linecard 1
296+
asic_db = dvs.get_asic_db()
297+
neighkeys = asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY")
298+
assert len(neighkeys), "No neigh entries in ASIC_DB"
299+
300+
# Check for presence of the remote neighbor in ASIC_DB
301+
remote_neigh = ""
302+
for nkey in neighkeys:
303+
ne = ast.literal_eval(nkey)
304+
if ne['ip'] == test_neigh_ip:
305+
remote_neigh = nkey
306+
break
307+
308+
assert remote_neigh != "", "Remote neigh not found in ASIC_DB"
309+
310+
# Check for kernel entries
311+
312+
_, output = dvs.runcmd("ip neigh show")
313+
assert f"{test_neigh_ip} dev {inband_port}" in output, "Kernel neigh not found for remote neighbor"
227314

315+
_, output = dvs.runcmd("ip route show")
316+
assert f"{test_neigh_ip} dev {inband_port} scope link" in output, "Kernel route not found for remote neighbor"
317+
318+
# Check for ASIC_DB entries.
319+
320+
# Check for presence of encap index, retrieve and store it for sync verification
321+
remote_neigh_entry = asic_db.get_entry("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY", remote_neigh)
322+
323+
# Validate encap index
324+
remote_encap_index = remote_neigh_entry.get("SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX")
325+
assert remote_encap_index != "", "VOQ encap index is not programmed for remote neigh in ASIC_DB"
326+
assert remote_encap_index == encap_index, "Encap index of remote neigh mismatch with allocated encap index"
327+
328+
# Validate MAC
329+
mac = remote_neigh_entry.get("SAI_NEIGHBOR_ENTRY_ATTR_DST_MAC_ADDRESS")
330+
assert mac != "", "MAC address is not programmed for remote neigh in ASIC_DB"
331+
assert mac == test_neigh_mac, "Encap index of remote neigh mismatch with allocated encap index"
332+
333+
# Check for other mandatory attributes
334+
# For remote neighbor, encap index must be imposed. So impose_index must be "true"
335+
impose_index = remote_neigh_entry.get("SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_IMPOSE_INDEX")
336+
assert impose_index != "", "Impose index attribute is not programmed for remote neigh in ASIC_DB"
337+
assert impose_index == "true", "Impose index attribute is false for remote neigh"
338+
339+
# For remote neighbors, is_local must be "false"
340+
is_local = remote_neigh_entry.get("SAI_NEIGHBOR_ENTRY_ATTR_IS_LOCAL")
341+
assert is_local != "", "is_local attribute is not programmed for remote neigh in ASIC_DB"
342+
assert is_local == "false", "is_local attribute is true for remote neigh"
343+
344+
break
345+
346+
# Cleanup
347+
self.del_inbandif_port(vct, inband_port)
348+
228349
# Add Dummy always-pass test at end as workaroud
229350
# for issue when Flaky fail on final test it invokes module tear-down before retrying
230351
def test_nonflaky_dummy():

0 commit comments

Comments
 (0)