Skip to content

Commit

Permalink
Tests for VNET route precedence over BGP learnt route. (#15710)
Browse files Browse the repository at this point in the history
What is the motivation for this PR?
Currently if a route is learnt via BGP and added into the hardware, adding a VNET route results in failure. In addition due to a bug in VnetOrch, we start advertising the failed route, This prompts the BGP to remove the learnt route in favor of the local route. Since the Vnet Orch doesn't retry adding the Vnet route, This results in no route being present in the Hardware.

How I verified it
The fix is in PR sonic-net/sonic-swss#3345
These tests cover various scenario in which VNET and BGP routes are added and removed in different order

How did you do it?
How did you verify/test it?
Any platform specific information?
Cisco-8000 and mlnx.

Supported testbed topology if it's a new test case?
Documentation
There are 5 differnet scenarios which are checked. Each scenario is tested with with the following options.
Encap types [v4_inv4, v6_inV4]
Monitor Type [BFD, Custom]
Init NH state( BFD/monitor sessions for nexthops are initially up or not.)

test_vnet_route_after_bgp
ADD BGP ROUTE on TOR
Add VNET route
Configure monitor (BFD or custom) with nexthop state (UP)
Test with traffic
Remove VNET route
Remove BGP route
test_vnet_route_before_bgp_after_ep_up
Add VNET route
Configure monitor (BFD or custom) with nexthop state (UP)
Add BGP ROUTE on TOR
Test with traffic
Remove VNET ROUTE
Remove BGP route
test_vnet_route_bgp_removal_before_ep
ADD BGP ROUTE on TOR
Add VNET route
Remove BGP route
Configure monitor (BFD or custom) with nexthop state (UP)
Test with traffic
Remove VNET route
test_vnet_route_after_bgp_with_early_bgp_removal
Add VNET route
Add BGP ROUTE on TOR
Configure monitor (BFD or custom) with nexthop state (UP)
Test with traffic
Remove BGP route
Test with traffic
Remove VNET route
test_vnet_route_after_bgp_multi_flap
ADD BGP ROUTE on TOR
Add VNET route
Configure monitor (BFD or custom) with nexthop state (UP)
Test with traffic
flap the bfd/monitor sessions.
Test with traffic
Remove VNET route
Remove BGP route
  • Loading branch information
siqbal1986 authored Dec 19, 2024
1 parent 86a132e commit 071bdfe
Show file tree
Hide file tree
Showing 3 changed files with 1,305 additions and 33 deletions.
114 changes: 81 additions & 33 deletions tests/common/vxlan_ecmp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,29 +546,50 @@ def create_and_apply_config(self,
self.apply_config_in_swss(duthost, str_config, op + "_vnet_route")

@classmethod
def create_single_route(cls, vnet, dest, mask, nhs, op, bfd=False, profile=""):
def create_single_route(cls, vnet, dest, mask, nhs, op, bfd=False, profile="", adv_pfx="", adv_pfx_mask=""):
'''
Create a single route entry for vnet, for the given dest, through
the endpoints:nhs, op:SET/DEL
'''
if bfd:
config = '''{{
"VNET_ROUTE_TUNNEL_TABLE:{}:{}/{}": {{
"endpoint": "{}",
"endpoint_monitor": "{}",
"profile" : "{}"
}},
"OP": "{}"
}}'''.format(vnet, dest, mask, ",".join(nhs), ",".join(nhs), profile, op)

if adv_pfx != "" and adv_pfx_mask != "":
if bfd:
config = '''{{
"VNET_ROUTE_TUNNEL_TABLE:{}:{}/{}": {{
"endpoint": "{}",
"endpoint_monitor": "{}",
"profile" : "{}",
"adv_prefix" : "{}/{}"
}},
"OP": "{}"
}}'''.format(vnet, dest, mask, ",".join(nhs), ",".join(nhs), profile, adv_pfx, adv_pfx_mask, op)
else:
config = '''{{
"VNET_ROUTE_TUNNEL_TABLE:{}:{}/{}": {{
"endpoint": "{}",
"profile" : "{}",
"adv_prefix" : "{}/{}"
}},
"OP": "{}"
}}'''.format(vnet, dest, mask, ",".join(nhs), profile, adv_pfx, adv_pfx_mask, op)
else:
config = '''{{
"VNET_ROUTE_TUNNEL_TABLE:{}:{}/{}": {{
"endpoint": "{}",
"profile" : "{}"
}},
"OP": "{}"
}}'''.format(vnet, dest, mask, ",".join(nhs), profile, op)
if bfd:
config = '''{{
"VNET_ROUTE_TUNNEL_TABLE:{}:{}/{}": {{
"endpoint": "{}",
"endpoint_monitor": "{}",
"profile" : "{}"
}},
"OP": "{}"
}}'''.format(vnet, dest, mask, ",".join(nhs), ",".join(nhs), profile, op)

else:
config = '''{{
"VNET_ROUTE_TUNNEL_TABLE:{}:{}/{}": {{
"endpoint": "{}",
"profile" : "{}"
}},
"OP": "{}"
}}'''.format(vnet, dest, mask, ",".join(nhs), profile, op)

return config

Expand Down Expand Up @@ -599,7 +620,9 @@ def set_routes_in_dut(self,
op,
bfd=False,
mask="",
profile=""):
profile="",
adv_pfx="",
adv_pfx_mask=""):
'''
Configure Vnet routes in the DUT.
duthost : AnsibleHost structure for the DUT.
Expand All @@ -621,7 +644,9 @@ def set_routes_in_dut(self,
dest_to_nh_map[vnet][dest],
op,
bfd=bfd,
profile=profile))
profile=profile,
adv_pfx=adv_pfx,
adv_pfx_mask=adv_pfx_mask))

full_config = '[' + "\n,".join(config_list) + '\n]'
self.apply_config_in_swss(duthost, full_config, op+"_routes")
Expand Down Expand Up @@ -891,7 +916,10 @@ def create_and_apply_priority_config(self,
mask,
nhs,
primary,
op):
op,
profile="",
adv_pfx="",
adv_pfx_mask=""):
'''
Create a single destinatoin->endpoint list mapping, and configure
it in the DUT.
Expand All @@ -904,26 +932,46 @@ def create_and_apply_priority_config(self,
op : Operation to be done : SET or DEL.
'''
config = self.create_single_priority_route(vnet, dest, mask, nhs, primary, op)
config = self.create_single_priority_route(vnet, dest, mask, nhs, primary, op, profile, adv_pfx, adv_pfx_mask)
str_config = '[\n' + config + '\n]'
self.apply_config_in_swss(duthost, str_config, op + "_vnet_route")

@classmethod
def create_single_priority_route(cls, vnet, dest, mask, nhs, primary, op):
def create_single_priority_route(cls, vnet, dest, mask, nhs, primary, op, profile="", adv_pfx="", adv_pfx_mask=""):
'''
Create a single route entry for vnet, for the given dest, through
the endpoints:nhs, op:SET/DEL
'''
config = '''{{
"VNET_ROUTE_TUNNEL_TABLE:{}:{}/{}": {{
"endpoint": "{}",
"endpoint_monitor": "{}",
"primary" : "{}",
"monitoring" : "custom",
"adv_prefix" : "{}/{}"
}},
"OP": "{}"
}}'''.format(vnet, dest, mask, ",".join(nhs), ",".join(nhs), ",".join(primary), dest, mask, op)
if profile == "":
config = '''{{
"VNET_ROUTE_TUNNEL_TABLE:{}:{}/{}": {{
"endpoint": "{}",
"endpoint_monitor": "{}",
"primary" : "{}",
"monitoring" : "custom",
"adv_prefix" : "{}/{}"
}},
"OP": "{}"
}}'''.format(vnet, dest, mask, ",".join(nhs), ",".join(nhs), ",".join(primary),
dest if adv_pfx == "" else adv_pfx,
mask if adv_pfx_mask == "" else adv_pfx_mask,
op)
else:
config = '''{{
"VNET_ROUTE_TUNNEL_TABLE:{}:{}/{}": {{
"endpoint": "{}",
"endpoint_monitor": "{}",
"primary" : "{}",
"monitoring" : "custom",
"adv_prefix" : "{}/{}",
"profile" : "{}"
}},
"OP": "{}"
}}'''.format(vnet, dest, mask, ",".join(nhs), ",".join(nhs), ",".join(primary),
dest if adv_pfx == "" else adv_pfx,
mask if adv_pfx_mask == "" else adv_pfx_mask,
profile,
op)
return config

def set_vnet_monitor_state(self, duthost, dest, mask, nh, state):
Expand Down
63 changes: 63 additions & 0 deletions tests/vxlan/bfd_notifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

'''
# Description: This script is used to force notify the BFD state change to Orchagent.
This script can be called as
>>python script.py
{'363:1d0:e:88d::64c:ed8': 'oid:0x45000000000ae7', '203:1d0:e:288::64c:e18': 'oid:0x45000000000adc'}
>>python script.py --set "oid:0x45000000000ae7, oid:0x45000000000adc" "Up"
>>python script.py --set "oid:0x45000000000ae7, oid:0x45000000000adc" "Down"
>>python script.py --set "oid:0x45000000000ae7, oid:0x45000000000adc" "Init"
>>python script.py --set "oid:0x45000000000ae7, oid:0x45000000000adc" "Admin_Down"
'''
import swsscommon.swsscommon as swsscommon
import argparse


def main():
parser = argparse.ArgumentParser(description="BFD Notifier Script")
parser.add_argument("--set", nargs=2, metavar=('KEYLIST', 'STATE'), help="Comma separated key list and state")
args = parser.parse_args()

notifier = BFDNotifier()
if args.set:
key_list_str, state = args.set
key_list = key_list_str.split(',')
key_list = [key.strip() for key in key_list]
notifier.update_bfds_state(key_list, state)
else:
result = notifier.get_asic_db_bfd_session_id()
print(result)


class BFDNotifier:
def get_asic_db_bfd_session_id(self):
asic_db = swsscommon.DBConnector("ASIC_DB", 0, True)
tbl = swsscommon.Table(asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_BFD_SESSION")
entries = set(tbl.getKeys())
result = {}
for entry in entries:
status, fvs = tbl.get(entry)
fvs = dict(fvs)
assert status, "Got an error when get a key"
result[fvs["SAI_BFD_SESSION_ATTR_DST_IP_ADDRESS"]] = entry
return result

def update_bfds_state(self, bfd_ids, state):
bfd_sai_state = {
"Admin_Down": "SAI_BFD_SESSION_STATE_ADMIN_DOWN",
"Down": "SAI_BFD_SESSION_STATE_DOWN",
"Init": "SAI_BFD_SESSION_STATE_INIT",
"Up": "SAI_BFD_SESSION_STATE_UP"
}

asic_db = swsscommon.DBConnector("ASIC_DB", 0, True)
ntf = swsscommon.NotificationProducer(asic_db, "NOTIFICATIONS")
fvp = swsscommon.FieldValuePairs()
for bfd_id in bfd_ids:
ntf_data = "[{\"bfd_session_id\":\""+bfd_id+"\",\"session_state\":\""+bfd_sai_state[state]+"\"}]"
ntf.send("bfd_session_state_change", ntf_data, fvp)


if __name__ == "__main__":
main()
Loading

0 comments on commit 071bdfe

Please sign in to comment.