Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 83a186a

Browse files
authoredSep 1, 2022
Change the log messages in addKernelNeigh/Route from ERROR to INFO (sonic-net#2437)
* Change the log messages from ERROR to INFO. * Update the test_chassis_system_neigh test to check the mac address change of a neighbor.
1 parent 9c23389 commit 83a186a

File tree

2 files changed

+147
-127
lines changed

2 files changed

+147
-127
lines changed
 

‎cfgmgr/nbrmgr.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ void NbrMgr::doStateSystemNeighTask(Consumer &consumer)
397397

398398
if (!addKernelNeigh(nbr_odev, ip_address, mac_address))
399399
{
400-
SWSS_LOG_ERROR("Neigh entry add on dev %s failed for '%s'", nbr_odev.c_str(), kfvKey(t).c_str());
400+
SWSS_LOG_INFO("Neigh entry add on dev %s failed for '%s'", nbr_odev.c_str(), kfvKey(t).c_str());
401401
// Delete neigh to take care of deletion of exiting nbr for mac change. This makes sure that
402402
// re-try will be successful and route addtion (below) will be attempted and be successful
403403
delKernelNeigh(nbr_odev, ip_address);
@@ -411,7 +411,7 @@ void NbrMgr::doStateSystemNeighTask(Consumer &consumer)
411411

412412
if (!addKernelRoute(nbr_odev, ip_address))
413413
{
414-
SWSS_LOG_ERROR("Route entry add on dev %s failed for '%s'", nbr_odev.c_str(), kfvKey(t).c_str());
414+
SWSS_LOG_INFO("Route entry add on dev %s failed for '%s'", nbr_odev.c_str(), kfvKey(t).c_str());
415415
delKernelNeigh(nbr_odev, ip_address);
416416
// Delete route to take care of deletion of exiting route of nbr for mac change.
417417
delKernelRoute(ip_address);
@@ -522,8 +522,8 @@ bool NbrMgr::addKernelRoute(string odev, IpAddress ip_addr)
522522

523523
if(ret)
524524
{
525-
/* Just log error and return */
526-
SWSS_LOG_ERROR("Failed to add route for %s, error: %d", ip_str.c_str(), ret);
525+
/* This failure the caller expects is due to mac move */
526+
SWSS_LOG_INFO("Failed to add route for %s, error: %d", ip_str.c_str(), ret);
527527
return false;
528528
}
529529

@@ -586,8 +586,8 @@ bool NbrMgr::addKernelNeigh(string odev, IpAddress ip_addr, MacAddress mac_addr)
586586

587587
if(ret)
588588
{
589-
/* Just log error and return */
590-
SWSS_LOG_ERROR("Failed to add Nbr for %s, error: %d", ip_str.c_str(), ret);
589+
/* This failure the caller expects is due to mac move */
590+
SWSS_LOG_INFO("Failed to add Nbr for %s, error: %d", ip_str.c_str(), ret);
591591
return false;
592592
}
593593

‎tests/test_virtual_chassis.py

+141-121
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from swsscommon import swsscommon
22
from dvslib.dvs_database import DVSDatabase
33
import ast
4+
import time
45

56
class TestVirtualChassis(object):
67

@@ -239,156 +240,175 @@ def test_chassis_system_neigh(self, vct):
239240
# Test neighbor on Ethernet4 since Ethernet0 is used as Inband port
240241
test_neigh_dev = "Ethernet4"
241242
test_neigh_ip = "10.8.104.3"
242-
test_neigh_mac = "00:01:02:03:04:05"
243243

244-
dvss = vct.dvss
245-
print("name {}".format(dvss.keys()))
246-
for name in dvss.keys():
247-
dvs = dvss[name]
248-
249-
config_db = dvs.get_config_db()
250-
metatbl = config_db.get_entry("DEVICE_METADATA", "localhost")
251-
252-
cfg_switch_type = metatbl.get("switch_type")
253-
254-
# Neighbor record verifiation done in line card
255-
if cfg_switch_type == "voq":
256-
lc_switch_id = metatbl.get("switch_id")
257-
assert lc_switch_id != "", "Got error in getting switch_id from CONFIG_DB DEVICE_METADATA"
258-
if lc_switch_id == "0":
259-
260-
# Add a static neighbor
261-
_, res = dvs.runcmd(['sh', "-c", "ip neigh show"])
262-
_, res = dvs.runcmd(['sh', "-c", f"ip neigh add {test_neigh_ip} lladdr {test_neigh_mac} dev {test_neigh_dev}"])
263-
assert res == "", "Error configuring static neigh"
244+
# Grouping together the checks done during neighbor entry create into a function chassis_system_neigh_create()
245+
# if action is "add" it creates a new neighbor entry in local asic
246+
# if action is "change" it updates an existing neighbor entry with the mac_address
247+
def chassis_system_neigh_create():
248+
dvss = vct.dvss
249+
print("name {}".format(dvss.keys()))
250+
for name in dvss.keys():
251+
dvs = dvss[name]
264252

265-
asic_db = dvs.get_asic_db()
266-
asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY", 1)
267-
neighkeys = asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY")
268-
assert len(neighkeys), "No neigh entries in ASIC_DB"
269-
270-
# Check for presence of the neighbor in ASIC_DB
271-
test_neigh = ""
272-
for nkey in neighkeys:
273-
ne = ast.literal_eval(nkey)
274-
if ne['ip'] == test_neigh_ip:
275-
test_neigh = nkey
276-
break
253+
config_db = dvs.get_config_db()
254+
metatbl = config_db.get_entry("DEVICE_METADATA", "localhost")
255+
256+
cfg_switch_type = metatbl.get("switch_type")
257+
258+
# Neighbor record verifiation done in line card
259+
if cfg_switch_type == "voq":
260+
lc_switch_id = metatbl.get("switch_id")
261+
assert lc_switch_id != "", "Got error in getting switch_id from CONFIG_DB DEVICE_METADATA"
262+
if lc_switch_id == "0":
263+
264+
# Add a static neighbor
265+
_, res = dvs.runcmd(['sh', "-c", "ip neigh show"])
266+
_, res = dvs.runcmd(['sh', "-c", f"ip neigh {action} {test_neigh_ip} lladdr {mac_address} dev {test_neigh_dev}"])
267+
assert res == "", "Error configuring static neigh"
268+
269+
asic_db = dvs.get_asic_db()
270+
asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY", 1)
271+
neighkeys = asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY")
272+
assert len(neighkeys), "No neigh entries in ASIC_DB"
273+
274+
# Check for presence of the neighbor in ASIC_DB
275+
test_neigh = ""
276+
for nkey in neighkeys:
277+
ne = ast.literal_eval(nkey)
278+
if ne['ip'] == test_neigh_ip:
279+
test_neigh = nkey
280+
break
277281

278-
assert test_neigh != "", "Neigh not found in ASIC_DB"
282+
assert test_neigh != "", "Neigh not found in ASIC_DB"
279283

280-
# Preserve test neigh asic db key for delete verification later
281-
test_neigh_asic_db_key = test_neigh
284+
# Preserve test neigh asic db key for delete verification later
285+
test_neigh_asic_db_key = test_neigh
282286

283-
# Check for presence of encap index, retrieve and store it for sync verification
284-
test_neigh_entry = asic_db.wait_for_entry("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY", test_neigh)
285-
test_neigh_entry_attrs = asic_db.wait_for_fields("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY", test_neigh, ["SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX"])
286-
print(test_neigh)
287-
print(test_neigh_entry)
288-
print(test_neigh_entry_attrs)
289-
encap_index = test_neigh_entry_attrs["SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX"]
290-
assert encap_index != "" and encap_index != None, "VOQ encap index is not programmed in ASIC_DB"
287+
# Check for presence of encap index, retrieve and store it for sync verification
288+
test_neigh_entry = asic_db.wait_for_entry("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY", test_neigh)
289+
test_neigh_entry_attrs = asic_db.wait_for_fields("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY", test_neigh, ["SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX"])
290+
print(test_neigh)
291+
print(test_neigh_entry)
292+
print(test_neigh_entry_attrs)
293+
encap_index = test_neigh_entry_attrs["SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX"]
294+
assert encap_index != "" and encap_index != None, "VOQ encap index is not programmed in ASIC_DB"
291295

292-
break
293-
294-
# Verify neighbor record syncing with encap index
295-
for name in dvss.keys():
296-
if name.startswith("supervisor"):
297-
dvs = dvss[name]
298-
chassis_app_db = DVSDatabase(swsscommon.CHASSIS_APP_DB, dvs.redis_chassis_sock)
299-
chassis_app_db.wait_for_n_keys("SYSTEM_NEIGH", 1)
300-
sysneighkeys = chassis_app_db.get_keys("SYSTEM_NEIGH")
301-
302-
print(sysneighkeys)
303-
test_sysneigh = ""
304-
for sysnk in sysneighkeys:
305-
sysnk_tok = sysnk.split("|")
306-
assert len(sysnk_tok) == 3, "Invalid system neigh key in chassis app db"
307-
if sysnk_tok[2] == test_neigh_ip:
308-
test_sysneigh = sysnk
309296
break
310297

311-
assert test_sysneigh != "", "Neigh is not sync-ed to chassis app db"
298+
# Verify neighbor record syncing with encap index
299+
for name in dvss.keys():
300+
if name.startswith("supervisor"):
301+
dvs = dvss[name]
302+
chassis_app_db = DVSDatabase(swsscommon.CHASSIS_APP_DB, dvs.redis_chassis_sock)
303+
chassis_app_db.wait_for_n_keys("SYSTEM_NEIGH", 1)
304+
sysneighkeys = chassis_app_db.get_keys("SYSTEM_NEIGH")
305+
306+
print(sysneighkeys)
307+
test_sysneigh = ""
308+
for sysnk in sysneighkeys:
309+
sysnk_tok = sysnk.split("|")
310+
assert len(sysnk_tok) == 3, "Invalid system neigh key in chassis app db"
311+
if sysnk_tok[2] == test_neigh_ip:
312+
test_sysneigh = sysnk
313+
break
312314

313-
# Preserve test sys neigh chassis app db key for delete verification later
314-
test_sysneigh_chassis_app_db_key = test_sysneigh
315+
assert test_sysneigh != "", "Neigh is not sync-ed to chassis app db"
315316

316-
test_sysneigh_entry = chassis_app_db.get_entry("SYSTEM_NEIGH", test_sysneigh)
317-
sys_neigh_encap_index = test_sysneigh_entry.get("encap_index")
318-
assert sys_neigh_encap_index != "", "System neigh in chassis app db does not have encap index"
317+
# Preserve test sys neigh chassis app db key for delete verification later
318+
test_sysneigh_chassis_app_db_key = test_sysneigh
319319

320-
assert encap_index == sys_neigh_encap_index, "Encap index not sync-ed correctly"
320+
test_sysneigh_entry = chassis_app_db.get_entry("SYSTEM_NEIGH", test_sysneigh)
321+
sys_neigh_encap_index = test_sysneigh_entry.get("encap_index")
322+
assert sys_neigh_encap_index != "", "System neigh in chassis app db does not have encap index"
321323

322-
break
324+
assert encap_index == sys_neigh_encap_index, "Encap index not sync-ed correctly"
323325

324-
# Verify programming of remote neighbor in asic db and programming of static route and static
325-
# neigh in the kernel for the remote neighbor. The neighbor created in linecard 1 will be a
326-
# remote neighbor in other linecards. Verity existence of the test neighbor in linecards other
327-
# than linecard 1
328-
for name in dvss.keys():
329-
dvs = dvss[name]
326+
break
330327

331-
config_db = dvs.get_config_db()
332-
metatbl = config_db.get_entry("DEVICE_METADATA", "localhost")
328+
# Add a delay for the programming of neighbor in remote LC
329+
time.sleep(10)
333330

334-
cfg_switch_type = metatbl.get("switch_type")
331+
# Verify programming of remote neighbor in asic db and programming of static route and static
332+
# neigh in the kernel for the remote neighbor. The neighbor created in linecard 1 will be a
333+
# remote neighbor in other linecards. Verity existence of the test neighbor in linecards other
334+
# than linecard 1
335+
for name in dvss.keys():
336+
dvs = dvss[name]
335337

336-
# Neighbor record verifiation done in line card
337-
if cfg_switch_type == "voq":
338-
lc_switch_id = metatbl.get("switch_id")
339-
assert lc_switch_id != "", "Got error in getting switch_id from CONFIG_DB DEVICE_METADATA"
340-
if lc_switch_id != "0":
341-
# Linecard other than linecard 1
342-
asic_db = dvs.get_asic_db()
343-
asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY", 1)
344-
neighkeys = asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY")
345-
assert len(neighkeys), "No neigh entries in ASIC_DB"
346-
347-
# Check for presence of the remote neighbor in ASIC_DB
348-
remote_neigh = ""
349-
for nkey in neighkeys:
350-
ne = ast.literal_eval(nkey)
351-
if ne['ip'] == test_neigh_ip:
352-
remote_neigh = nkey
353-
break
338+
config_db = dvs.get_config_db()
339+
metatbl = config_db.get_entry("DEVICE_METADATA", "localhost")
340+
341+
cfg_switch_type = metatbl.get("switch_type")
342+
343+
# Neighbor record verifiation done in line card
344+
if cfg_switch_type == "voq":
345+
lc_switch_id = metatbl.get("switch_id")
346+
assert lc_switch_id != "", "Got error in getting switch_id from CONFIG_DB DEVICE_METADATA"
347+
if lc_switch_id != "0":
348+
# Linecard other than linecard 1
349+
asic_db = dvs.get_asic_db()
350+
asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY", 1)
351+
neighkeys = asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY")
352+
assert len(neighkeys), "No neigh entries in ASIC_DB"
353+
354+
# Check for presence of the remote neighbor in ASIC_DB
355+
remote_neigh = ""
356+
for nkey in neighkeys:
357+
ne = ast.literal_eval(nkey)
358+
if ne['ip'] == test_neigh_ip:
359+
remote_neigh = nkey
360+
break
354361

355-
assert remote_neigh != "", "Remote neigh not found in ASIC_DB"
362+
assert remote_neigh != "", "Remote neigh not found in ASIC_DB"
356363

357-
# Preserve remote neigh asic db neigh key for delete verification later
358-
test_remote_neigh_asic_db_key = remote_neigh
364+
# Preserve remote neigh asic db neigh key for delete verification later
365+
test_remote_neigh_asic_db_key = remote_neigh
359366

360-
# Check for kernel entries
367+
# Check for kernel entries
361368

362-
_, output = dvs.runcmd("ip neigh show")
363-
assert f"{test_neigh_ip} dev {inband_port}" in output, "Kernel neigh not found for remote neighbor"
369+
_, output = dvs.runcmd("ip neigh show")
370+
assert f"{test_neigh_ip} dev {inband_port}" in output, "Kernel neigh not found for remote neighbor"
364371

365-
_, output = dvs.runcmd("ip route show")
366-
assert f"{test_neigh_ip} dev {inband_port} scope link" in output, "Kernel route not found for remote neighbor"
372+
_, output = dvs.runcmd("ip route show")
373+
assert f"{test_neigh_ip} dev {inband_port} scope link" in output, "Kernel route not found for remote neighbor"
367374

368-
# Check for ASIC_DB entries.
375+
# Check for ASIC_DB entries.
369376

370-
# Check for presence of encap index, retrieve and store it for sync verification
371-
remote_neigh_entry = asic_db.get_entry("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY", remote_neigh)
377+
# Check for presence of encap index, retrieve and store it for sync verification
378+
remote_neigh_entry = asic_db.get_entry("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY", remote_neigh)
372379

373-
# Validate encap index
374-
remote_encap_index = remote_neigh_entry.get("SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX")
375-
assert remote_encap_index != "", "VOQ encap index is not programmed for remote neigh in ASIC_DB"
376-
assert remote_encap_index == encap_index, "Encap index of remote neigh mismatch with allocated encap index"
380+
# Validate encap index
381+
remote_encap_index = remote_neigh_entry.get("SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX")
382+
assert remote_encap_index != "", "VOQ encap index is not programmed for remote neigh in ASIC_DB"
383+
assert remote_encap_index == encap_index, "Encap index of remote neigh mismatch with allocated encap index"
377384

378-
# Validate MAC
379-
mac = remote_neigh_entry.get("SAI_NEIGHBOR_ENTRY_ATTR_DST_MAC_ADDRESS")
380-
assert mac != "", "MAC address is not programmed for remote neigh in ASIC_DB"
381-
assert mac == test_neigh_mac, "Encap index of remote neigh mismatch with allocated encap index"
385+
# Validate MAC
386+
mac = remote_neigh_entry.get("SAI_NEIGHBOR_ENTRY_ATTR_DST_MAC_ADDRESS")
387+
assert mac != "", "MAC address is not programmed for remote neigh in ASIC_DB"
388+
assert mac == mac_address, "Encap index of remote neigh mismatch with allocated encap index"
382389

383-
# Check for other mandatory attributes
384-
# For remote neighbors, is_local must be "false"
385-
is_local = remote_neigh_entry.get("SAI_NEIGHBOR_ENTRY_ATTR_IS_LOCAL")
386-
assert is_local != "", "is_local attribute is not programmed for remote neigh in ASIC_DB"
387-
assert is_local == "false", "is_local attribute is true for remote neigh"
390+
# Check for other mandatory attributes
391+
# For remote neighbors, is_local must be "false"
392+
is_local = remote_neigh_entry.get("SAI_NEIGHBOR_ENTRY_ATTR_IS_LOCAL")
393+
assert is_local != "", "is_local attribute is not programmed for remote neigh in ASIC_DB"
394+
assert is_local == "false", "is_local attribute is true for remote neigh"
388395

389-
break
396+
break
397+
398+
return test_neigh_asic_db_key, test_sysneigh_chassis_app_db_key, test_remote_neigh_asic_db_key
399+
400+
# First step is to add a new neighbor and check local/chassis_db/remote entry creation
401+
mac_address = "00:01:02:03:04:77"
402+
action = "add"
403+
chassis_system_neigh_create()
404+
405+
# Second step to update the mac address and check local/chassis_db/remote entry creation
406+
mac_address = "00:01:02:03:04:05"
407+
action = "change"
408+
test_neigh_asic_db_key, test_sysneigh_chassis_app_db_key, test_remote_neigh_asic_db_key = chassis_system_neigh_create()
390409

391410
# Verify system neighbor delete and clearing
411+
dvss = vct.dvss
392412
for name in dvss.keys():
393413
dvs = dvss[name]
394414

0 commit comments

Comments
 (0)
Please sign in to comment.