From 00742979161240fad9c980f9ceccfbdd7e35b8e4 Mon Sep 17 00:00:00 2001 From: Kuldeep Kashyap Date: Tue, 27 Sep 2022 08:57:02 +0530 Subject: [PATCH] tests: Add lib changes to support bgp local asn feature Added lib changes to support bgp local asn feature config changes Signed-off-by: Kuldeep Kashyap --- tests/topotests/lib/bgp.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/tests/topotests/lib/bgp.py b/tests/topotests/lib/bgp.py index 7ab36c4fcd..218f2dbe2b 100644 --- a/tests/topotests/lib/bgp.py +++ b/tests/topotests/lib/bgp.py @@ -830,22 +830,36 @@ def __create_bgp_neighbor(topo, input_dict, router, addr_type, add_neigh=True): global_connect = input_dict.get("connecttimer", 5) for name, peer_dict in neigh_data.items(): + remote_as = 0 for dest_link, peer in peer_dict["dest_link"].items(): + local_asn = peer.setdefault("local_asn", {}) + if local_asn: + local_as = local_asn.setdefault("local_as", 0) + remote_as = local_asn.setdefault("remote_as", 0) + no_prepend = local_asn.setdefault("no_prepend", False) + replace_as = local_asn.setdefault("replace_as", False) + if local_as == remote_as: + assert False is True, ( + " Configuration Error : Router must not have " + "same AS-NUMBER as Local AS NUMBER" + ) nh_details = topo[name] if "vrfs" in topo[router] or type(nh_details["bgp"]) is list: for vrf_data in nh_details["bgp"]: if "vrf" in nh_details["links"][dest_link] and "vrf" in vrf_data: if nh_details["links"][dest_link]["vrf"] == vrf_data["vrf"]: - remote_as = vrf_data["local_as"] + if not remote_as: + remote_as = vrf_data["local_as"] break else: if "vrf" not in vrf_data: - remote_as = vrf_data["local_as"] - break - + if not remote_as: + remote_as = vrf_data["local_as"] + break else: - remote_as = nh_details["bgp"]["local_as"] + if not remote_as: + remote_as = nh_details["bgp"]["local_as"] update_source = None @@ -890,6 +904,14 @@ def __create_bgp_neighbor(topo, input_dict, router, addr_type, add_neigh=True): elif add_neigh: config_data.append("{} remote-as {}".format(neigh_cxt, remote_as)) + if local_asn and local_as: + cmd = "{} local-as {}".format(neigh_cxt, local_as) + if no_prepend: + cmd = "{} no-prepend".format(cmd) + if replace_as: + cmd = "{} replace-as".format(cmd) + config_data.append("{}".format(cmd)) + if addr_type == "ipv6": config_data.append("address-family ipv6 unicast") config_data.append("{} activate".format(neigh_cxt)) -- 2.39.5