Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for VNET route precedence over BGP learnt route. #15710

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 82 additions & 33 deletions tests/common/vxlan_ecmp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,29 +546,51 @@ 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" : "{}",
"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" : "{}"
}},
"OP": "{}"
}}'''.format(vnet, dest, mask, ",".join(nhs), profile, op)

return config

Expand Down Expand Up @@ -599,7 +621,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 +645,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 +917,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 +933,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
Loading