Skip to content

Commit 67232b6

Browse files
authored
Revert "dualtor_neighbor_check.py changed (#3931)" (#4136)
Reverts #3931 Reverting for backward compatibility issues.
1 parent 3acd2d1 commit 67232b6

File tree

2 files changed

+45
-319
lines changed

2 files changed

+45
-319
lines changed

scripts/dualtor_neighbor_check.py

Lines changed: 13 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
-- - HW_MUX_CABLE_TABLE
3636
-- - NEIGH_TABLE
3737
-- ASIC_DB:
38-
-- - ASIC_STATE (route entries, neighbor entries, nexthop entries)
38+
-- - ASIC_STATE
3939
--
4040
-- KEYS - None
4141
-- ARGV[1] - APPL_DB db index
@@ -76,7 +76,6 @@
7676
local asic_fdb = {}
7777
local asic_route_table = {}
7878
local asic_neighbor_table = {}
79-
local asic_nexthop_table = {}
8079
8180
-- read from APPL_DB
8281
redis.call('SELECT', APPL_DB)
@@ -127,16 +126,12 @@
127126
asic_fdb[mac] = bridge_port_id
128127
end
129128
130-
-- read ASIC route table with nexthop information
129+
-- read ASIC route table
131130
local route_prefix = asic_state_table_name .. ASIC_DB_SEPARATOR .. asic_route_key_prefix
132131
local route_entries = redis.call('KEYS', route_prefix .. '*')
133132
for i, route_entry in ipairs(route_entries) do
134133
local route_details = string.sub(route_entry, string.len(route_prefix) + 2)
135-
local nexthop_id = redis.call('HGET', route_entry, 'SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID')
136-
local route_info = {}
137-
route_info['route_details'] = route_details
138-
route_info['nexthop_id'] = nexthop_id
139-
table.insert(asic_route_table, route_info)
134+
table.insert(asic_route_table, route_details)
140135
end
141136
142137
-- read ASIC neigh table
@@ -147,40 +142,20 @@
147142
table.insert(asic_neighbor_table, neighbor_details)
148143
end
149144
150-
-- read ASIC nexthop table
151-
local nexthop_prefix = asic_state_table_name .. ASIC_DB_SEPARATOR .. 'SAI_OBJECT_TYPE_NEXT_HOP:'
152-
local nexthop_entries = redis.call('KEYS', nexthop_prefix .. '*')
153-
for i, nexthop_entry in ipairs(nexthop_entries) do
154-
local nexthop_id = string.sub(nexthop_entry, string.len(nexthop_prefix) + 1)
155-
local nexthop_type = redis.call('HGET', nexthop_entry, 'SAI_NEXT_HOP_ATTR_TYPE')
156-
local nexthop_info = {}
157-
nexthop_info['nexthop_id'] = nexthop_id
158-
nexthop_info['nexthop_type'] = nexthop_type
159-
160-
-- Get tunnel ID if it's a tunnel nexthop
161-
if nexthop_type == 'SAI_NEXT_HOP_TYPE_TUNNEL_ENCAP' then
162-
nexthop_info['tunnel_id'] = redis.call('HGET', nexthop_entry, 'SAI_NEXT_HOP_ATTR_TUNNEL_ID')
163-
end
164-
165-
asic_nexthop_table[nexthop_id] = nexthop_info
166-
end
167-
168145
local result = {}
169146
result['neighbors'] = neighbors
170147
result['mux_states'] = mux_states
171148
result['hw_mux_states'] = hw_mux_states
172149
result['asic_fdb'] = asic_fdb
173150
result['asic_route_table'] = asic_route_table
174151
result['asic_neigh_table'] = asic_neighbor_table
175-
result['asic_nexthop_table'] = asic_nexthop_table
176152
177153
return redis.status_reply(cjson.encode(result))
178154
"""
179155

180156
DB_READ_SCRIPT_CONFIG_DB_KEY = "_DUALTOR_NEIGHBOR_CHECK_SCRIPT_SHA1"
181157
ZERO_MAC = "00:00:00:00:00:00"
182-
NEIGHBOR_ATTRIBUTES = ["NEIGHBOR", "MAC", "PORT", "MUX_STATE", "IN_MUX_TOGGLE", "NEIGHBOR_IN_ASIC", "PREFIX_ROUTE",
183-
"NEXTHOP_TYPE", "HWSTATUS"]
158+
NEIGHBOR_ATTRIBUTES = ["NEIGHBOR", "MAC", "PORT", "MUX_STATE", "IN_MUX_TOGGLE", "NEIGHBOR_IN_ASIC", "TUNNEL_IN_ASIC", "HWSTATUS"]
184159
NOT_AVAILABLE = "N/A"
185160

186161

@@ -355,15 +330,13 @@ def _is_script_existed(script_sha1):
355330
asic_fdb = {k: v.lstrip("oid:0x") for k, v in tables["asic_fdb"].items()}
356331
asic_route_table = tables["asic_route_table"]
357332
asic_neigh_table = tables["asic_neigh_table"]
358-
asic_nexthop_table = tables["asic_nexthop_table"]
359333
WRITE_LOG_DEBUG("neighbors: %s", json.dumps(neighbors, indent=4))
360334
WRITE_LOG_DEBUG("mux states: %s", json.dumps(mux_states, indent=4))
361335
WRITE_LOG_DEBUG("hw mux states: %s", json.dumps(hw_mux_states, indent=4))
362336
WRITE_LOG_DEBUG("ASIC FDB: %s", json.dumps(asic_fdb, indent=4))
363337
WRITE_LOG_DEBUG("ASIC route table: %s", json.dumps(asic_route_table, indent=4))
364338
WRITE_LOG_DEBUG("ASIC neigh table: %s", json.dumps(asic_neigh_table, indent=4))
365-
WRITE_LOG_DEBUG("ASIC nexthop table: %s", json.dumps(asic_nexthop_table, indent=4))
366-
return neighbors, mux_states, hw_mux_states, asic_fdb, asic_route_table, asic_neigh_table, asic_nexthop_table
339+
return neighbors, mux_states, hw_mux_states, asic_fdb, asic_route_table, asic_neigh_table
367340

368341

369342
def get_if_br_oid_to_port_name_map():
@@ -417,33 +390,10 @@ def get_mac_to_port_name_map(asic_fdb, if_oid_to_port_name_map):
417390

418391

419392
def check_neighbor_consistency(neighbors, mux_states, hw_mux_states, mac_to_port_name_map,
420-
asic_route_table, asic_neigh_table, asic_nexthop_table,
421-
mux_server_to_port_map):
393+
asic_route_table, asic_neigh_table, mux_server_to_port_map):
422394
"""Checks if neighbors are consistent with mux states."""
423395

424-
# Parse route table to get route destinations and their nexthop types
425-
route_to_nexthop_map = {}
426-
asic_route_destinations = set()
427-
428-
for route_info in asic_route_table:
429-
route_details = json.loads(route_info["route_details"])
430-
route_dest = route_details["dest"].split("/")[0]
431-
asic_route_destinations.add(route_dest)
432-
433-
nexthop_id = route_info["nexthop_id"]
434-
435-
nexthop_type = NOT_AVAILABLE
436-
if nexthop_id in asic_nexthop_table:
437-
nexthop_info = asic_nexthop_table[nexthop_id]
438-
if nexthop_info["nexthop_type"] == "SAI_NEXT_HOP_TYPE_TUNNEL_ENCAP":
439-
nexthop_type = "TUNNEL"
440-
elif nexthop_info["nexthop_type"] == "SAI_NEXT_HOP_TYPE_IP":
441-
nexthop_type = "NEIGHBOR"
442-
else:
443-
nexthop_type = nexthop_info["nexthop_type"]
444-
445-
route_to_nexthop_map[route_dest] = nexthop_type
446-
396+
asic_route_destinations = set(json.loads(_)["dest"].split("/")[0] for _ in asic_route_table)
447397
asic_neighs = set(json.loads(_)["ip"] for _ in asic_neigh_table)
448398

449399
check_results = []
@@ -459,14 +409,12 @@ def check_neighbor_consistency(neighbors, mux_states, hw_mux_states, mac_to_port
459409
continue
460410

461411
check_result["NEIGHBOR_IN_ASIC"] = neighbor_ip in asic_neighs
462-
check_result["PREFIX_ROUTE"] = neighbor_ip in asic_route_destinations
463-
check_result["NEXTHOP_TYPE"] = route_to_nexthop_map.get(neighbor_ip, NOT_AVAILABLE)
464-
412+
check_result["TUNNEL_IN_ASIC"] = neighbor_ip in asic_route_destinations
465413
if is_zero_mac:
466414
# NOTE: for zero-mac neighbors, two situations:
467415
# 1. new neighbor just learnt, no neighbor entry in ASIC, tunnel route present in ASIC.
468416
# 2. neighbor expired, neighbor entry still present in ASIC, no tunnel route in ASIC.
469-
check_result["HWSTATUS"] = check_result["NEIGHBOR_IN_ASIC"] or check_result["PREFIX_ROUTE"]
417+
check_result["HWSTATUS"] = check_result["NEIGHBOR_IN_ASIC"] or check_result["TUNNEL_IN_ASIC"]
470418
else:
471419
port_name = mac_to_port_name_map[mac]
472420
# NOTE: mux server ips are always fixed to the mux port
@@ -479,16 +427,9 @@ def check_neighbor_consistency(neighbors, mux_states, hw_mux_states, mac_to_port
479427
check_result["IN_MUX_TOGGLE"] = mux_state != hw_mux_state
480428

481429
if mux_state == "active":
482-
# For active mux state, neighbor should be in ASIC and route should point to neighbor nexthop
483-
expected_nexthop = "NEIGHBOR"
484-
check_result["HWSTATUS"] = (check_result["NEIGHBOR_IN_ASIC"] and
485-
check_result["PREFIX_ROUTE"] and
486-
check_result["NEXTHOP_TYPE"] == expected_nexthop)
430+
check_result["HWSTATUS"] = (check_result["NEIGHBOR_IN_ASIC"] and (not check_result["TUNNEL_IN_ASIC"]))
487431
elif mux_state == "standby":
488-
# For standby mux state, route should point to tunnel nexthop
489-
expected_nexthop = "TUNNEL"
490-
check_result["HWSTATUS"] = (check_result["PREFIX_ROUTE"] and
491-
check_result["NEXTHOP_TYPE"] == expected_nexthop)
432+
check_result["HWSTATUS"] = ((not check_result["NEIGHBOR_IN_ASIC"]) and check_result["TUNNEL_IN_ASIC"])
492433
else:
493434
# skip as unknown mux state
494435
continue
@@ -513,7 +454,7 @@ def parse_check_results(check_results):
513454
if not is_zero_mac:
514455
check_result["IN_MUX_TOGGLE"] = bool_to_yes_no[in_toggle]
515456
check_result["NEIGHBOR_IN_ASIC"] = bool_to_yes_no[check_result["NEIGHBOR_IN_ASIC"]]
516-
check_result["PREFIX_ROUTE"] = bool_to_yes_no[check_result["PREFIX_ROUTE"]]
457+
check_result["TUNNEL_IN_ASIC"] = bool_to_yes_no[check_result["TUNNEL_IN_ASIC"]]
517458
check_result["HWSTATUS"] = bool_to_consistency[hwstatus]
518459
if (not hwstatus):
519460
if is_zero_mac:
@@ -558,8 +499,7 @@ def parse_check_results(check_results):
558499

559500
mux_server_to_port_map = get_mux_server_to_port_map(mux_cables)
560501
if_oid_to_port_name_map = get_if_br_oid_to_port_name_map()
561-
neighbors, mux_states, hw_mux_states, asic_fdb, asic_route_table, asic_neigh_table, \
562-
asic_nexthop_table = read_tables_from_db(appl_db)
502+
neighbors, mux_states, hw_mux_states, asic_fdb, asic_route_table, asic_neigh_table = read_tables_from_db(appl_db)
563503
mac_to_port_name_map = get_mac_to_port_name_map(asic_fdb, if_oid_to_port_name_map)
564504

565505
check_results = check_neighbor_consistency(
@@ -569,7 +509,6 @@ def parse_check_results(check_results):
569509
mac_to_port_name_map,
570510
asic_route_table,
571511
asic_neigh_table,
572-
asic_nexthop_table,
573512
mux_server_to_port_map
574513
)
575514
res = parse_check_results(check_results)

0 commit comments

Comments
 (0)