Skip to content

Commit

Permalink
Add the test case back
Browse files Browse the repository at this point in the history
Signed-off-by: Abhishek Dosi <[email protected]>
  • Loading branch information
abdosi committed Dec 11, 2024
1 parent 409b268 commit 7718dfa
Showing 1 changed file with 227 additions and 1 deletion.
228 changes: 227 additions & 1 deletion tests/test_nhg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1840,7 +1840,233 @@ def test_nhgorch_label_route(self, dvs, testlog):
# Remove group1
self.nhg_ps._del("group1")
self.asic_db.wait_for_n_keys(self.ASIC_NHG_STR, self.asic_nhgs_count)


def test_route_fallback_to_default_bothv4v6(self, dvs, dvs_route, testlog):
self.init_test(dvs, 6, True)
rtprefix_v6 = "2603:10b0::1/120"
defaultprefix_v6 = "::/0"
nexthop_str_v6 = "fc00::1,fc00::3,fc00::5"
default_nexthop_str_v6 = "fc00::7,fc00::9,fc00::b"
rtprefix = "3.3.3.0/24"
defaultprefix = "0.0.0.0/0"
nexthop_str = "10.0.0.1,10.0.0.3,10.0.0.5"
default_nexthop_str = "10.0.0.7,10.0.0.9,10.0.0.11"

dvs_route.check_asicdb_deleted_route_entries([rtprefix, rtprefix_v6])

try:
dvs.disable_fpmsyncd()
# Program Regular Rouute with fallback to default
fvs = swsscommon.FieldValuePairs([("nexthop",nexthop_str),
("ifname", "Ethernet0,Ethernet4,Ethernet8"),
("fallback_to_default_route", "true")])
self.rt_ps.set(rtprefix, fvs)
time.sleep(1)

fvs = swsscommon.FieldValuePairs([("nexthop",nexthop_str_v6),
("ifname", "Ethernet0,Ethernet4,Ethernet8"),
("fallback_to_default_route", "true")])
self.rt_ps.set(rtprefix_v6, fvs)
time.sleep(1)

# Program default route
fvs = swsscommon.FieldValuePairs([("nexthop", default_nexthop_str),
("ifname", "Ethernet12,Ethernet16,Ethernet20")])

self.rt_ps.set(defaultprefix, fvs)
time.sleep(1)

fvs = swsscommon.FieldValuePairs([("nexthop", default_nexthop_str_v6),
("ifname", "Ethernet12,Ethernet16,Ethernet20")])

self.rt_ps.set(defaultprefix_v6, fvs)
time.sleep(1)

# check if route was propagated to ASIC DB
rtkeys = dvs_route.check_asicdb_route_entries([rtprefix, rtprefix_v6])

# check if default route was propagated to ASIC DB
defaultrtkeys = dvs_route.check_asicdb_route_entries([defaultprefix, defaultprefix_v6])

default_nhgid = []
default_nhops = set()
default_nhgmids = set()
default_nhopsids = set()
default_parentnhgid = set()

rt_nhgid = []
rt_nhops = set()
rt_nhopsids = set()
rt_nhgmids = set()
rt_parentnhgid = set()

# assert the route points to next hop group
flat_list = []
for x in rtkeys:
flat_list.append(x)
for x in defaultrtkeys:
flat_list.append(x)
for idx, rtkey in enumerate(flat_list):
fvs = self.asic_db.get_entry(self.ASIC_RT_STR, rtkey)
if idx in [0,1]:
rt_nhgid.append(fvs["SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID"])
else:
default_nhgid.append(fvs["SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID"])

nhgid = fvs["SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID"]

fvs = self.asic_db.get_entry(self.ASIC_NHG_STR, nhgid)

assert bool(fvs)

keys = self.asic_db.get_keys(self.ASIC_NHGM_STR)

assert len(keys) == 12

for k in keys:
fvs = self.asic_db.get_entry(self.ASIC_NHGM_STR, k)
nhid = fvs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID"]
nh_fvs = self.asic_db.get_entry("ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP", nhid)

if fvs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID"] in rt_nhgid:
rt_nhopsids.add(fvs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID"])
rt_nhops.add(nh_fvs["SAI_NEXT_HOP_ATTR_IP"])
rt_nhgmids.add(k)
rt_parentnhgid.add(fvs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID"])
elif fvs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID"] in default_nhgid:
default_nhopsids.add(fvs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID"])
default_nhops.add(nh_fvs["SAI_NEXT_HOP_ATTR_IP"])
default_nhgmids.add(k)
default_parentnhgid.add(fvs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID"])

assert len(rt_parentnhgid) == 2
assert len(rt_nhopsids) == 6
assert len(rt_nhops) == 6
assert len(rt_nhgmids) == 6

assert len(default_parentnhgid) == 2
assert len(default_nhopsids) == 6
assert len(default_nhops) == 6
assert len(default_nhgmids) == 6

assert rt_nhops != default_nhops
assert rt_nhopsids != default_nhopsids
assert rt_parentnhgid != default_parentnhgid
assert rt_nhgmids != default_nhgmids

# bring links down one-by-one
for i in [0, 1, 2]:
self.flap_intf(i, 'down')
time.sleep(1)

keys = self.asic_db.get_keys(self.ASIC_NHGM_STR)

if i != 2:
assert len(keys) == 10 - (i * 2)
else:
# Last Link down so we will fallback to default eoute 3 members
assert len(keys) == 12
rt_nhops.clear()
rt_nhgmids.clear()
rt_nhopsids.clear()
for k in keys:
fvs = self.asic_db.get_entry(self.ASIC_NHGM_STR, k)
nhid = fvs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID"]
nh_fvs = self.asic_db.get_entry("ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP", nhid)

if fvs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID"] in rt_nhgid:
rt_nhopsids.add(fvs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID"])
rt_nhops.add(nh_fvs["SAI_NEXT_HOP_ATTR_IP"])
rt_nhgmids.add(k)
rt_parentnhgid.add(fvs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID"])
elif fvs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID"] in default_nhgid:
default_nhopsids.add(fvs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID"])
default_nhops.add(nh_fvs["SAI_NEXT_HOP_ATTR_IP"])
default_nhgmids.add(k)
default_parentnhgid.add(fvs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID"])

assert len(rt_parentnhgid) == 2
assert len(rt_nhopsids) == 6
assert len(rt_nhops) == 6
assert len(rt_nhgmids) == 6

assert len(default_parentnhgid) == 2
assert len(default_nhopsids) == 6
assert len(default_nhops) == 6
assert len(default_nhgmids) == 6

assert rt_nhops == default_nhops

Check warning

Code scanning / CodeQL

Redundant comparison Warning test

Test is always false, because of
this condition
.
assert rt_nhopsids == default_nhopsids

Check warning

Code scanning / CodeQL

Redundant comparison Warning test

Test is always false, because of
this condition
.
assert rt_nhgmids != default_nhgmids

Check warning

Code scanning / CodeQL

Redundant comparison Warning test

Test is always true, because of
this condition
.

# bring links up one-by-one
# Bring link up in random order to verify sequence id is as per order
for i, val in enumerate([2,1,0]):
self.flap_intf(i, 'up')
time.sleep(1)

keys = self.asic_db.get_keys(self.ASIC_NHGM_STR)

assert len(keys) == 12

for k in keys:
fvs = self.asic_db.get_entry(self.ASIC_NHGM_STR, k)
nhid = fvs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID"]
nh_fvs = self.asic_db.get_entry("ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP", nhid)

if fvs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID"] in rt_nhgid:
rt_nhopsids.add(fvs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID"])
rt_nhops.add(nh_fvs["SAI_NEXT_HOP_ATTR_IP"])
rt_nhgmids.add(k)
rt_parentnhgid.add(fvs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID"])
elif fvs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID"] in default_nhgid:
default_nhopsids.add(fvs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID"])
default_nhops.add(nh_fvs["SAI_NEXT_HOP_ATTR_IP"])
default_nhgmids.add(k)
default_parentnhgid.add(fvs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID"])

assert len(rt_parentnhgid) == 2
assert len(rt_nhopsids) == 6
assert len(rt_nhops) == 6
assert len(rt_nhgmids) == 6

assert len(default_parentnhgid) == 2
assert len(default_nhopsids) == 6
assert len(default_nhops) == 6
assert len(default_nhgmids) == 6

assert rt_nhops == default_nhops

Check warning

Code scanning / CodeQL

Redundant comparison Warning test

Test is always false, because of
this condition
.
assert rt_nhopsids == default_nhopsids

Check warning

Code scanning / CodeQL

Redundant comparison Warning test

Test is always false, because of
this condition
.
assert rt_nhgmids != default_nhgmids

Check warning

Code scanning / CodeQL

Redundant comparison Warning test

Test is always true, because of
this condition
.

# Remove route 2.2.2.0/24
self.rt_ps._del(rtprefix)
time.sleep(1)

self.rt_ps._del(rtprefix_v6)
time.sleep(1)

# Wait for route 2.2.2.0/24 to be removed
dvs_route.check_asicdb_deleted_route_entries([rtprefix, rtprefix_v6])

keys = self.asic_db.get_keys(self.ASIC_NHGM_STR)

assert len(keys) == 6

# Remove route 0.0.0.0/0
self.rt_ps._del(defaultprefix)
time.sleep(1)

self.rt_ps._del(defaultprefix_v6)
time.sleep(1)

keys = self.asic_db.get_keys(self.ASIC_NHGM_STR)

assert len(keys) == 0

finally:
dvs.start_fpmsyncd()

class TestCbfNextHopGroup(TestNextHopGroupBase):
MAX_NHG_MAP_COUNT = 512

Expand Down

0 comments on commit 7718dfa

Please sign in to comment.