tests: Apply black formatting for all tests/topotests

It's just annoying when the linter tells to apply the formatting for the code
you didn't touch.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
This commit is contained in:
Donatas Abraitis 2024-04-27 23:19:32 +03:00
parent 086df4bfaa
commit 1a1c2a9f84
77 changed files with 4877 additions and 2963 deletions

View file

@ -130,13 +130,15 @@ def test_bfd_loss_intermediate():
pytest.skip(tgen.errors)
r1 = tgen.gears["r1"]
expected = { "as":101, "peers":{ "2001:db8:4::1": { "state":"Established" } } }
test_func = partial(topotest.router_json_cmp, r1, "show bgp ipv6 uni summ json", expected)
expected = {"as": 101, "peers": {"2001:db8:4::1": {"state": "Established"}}}
test_func = partial(
topotest.router_json_cmp, r1, "show bgp ipv6 uni summ json", expected
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg ='"r1" has not established bgp peering yet'
assertmsg = '"r1" has not established bgp peering yet'
assert result is None, assertmsg
#assert False
# assert False
logger.info("removing IPv6 address from r2 to simulate loss of connectivity")
# Disable r2-eth0 ipv6 address
cmd = 'vtysh -c "configure terminal" -c "interface r2-eth1" -c "no ipv6 address 2001:db8:4::2/64"'

View file

@ -81,8 +81,7 @@ def setup_module(mod):
for rname, router in router_list.items():
router.load_config(
TopoRouter.RD_ZEBRA,
os.path.join(CWD, "{}/zebra.conf".format(rname))
TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
)
router.load_config(
TopoRouter.RD_BFD, os.path.join(CWD, "{}/bfdd.conf".format(rname))
@ -114,8 +113,8 @@ def test_bfd_connection():
if tgen.routers_have_failure():
pytest.skip(tgen.errors)
logger.info("waiting for bfd peers to go up")
router = tgen.gears['r1']
json_file = "{}/{}/bfd_peers_status.json".format(CWD, 'r1')
router = tgen.gears["r1"]
json_file = "{}/{}/bfd_peers_status.json".format(CWD, "r1")
expected = json.loads(open(json_file).read())
test_func = partial(

View file

@ -117,7 +117,9 @@ def test_bgp_color_extended_communities():
test_func = functools.partial(_bgp_check_route, r2, True)
_, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
assert result is None, "10.10.10.0/24 ext community is correctly not installed, but SHOULD be"
assert (
result is None
), "10.10.10.0/24 ext community is correctly not installed, but SHOULD be"
if __name__ == "__main__":

View file

@ -32,7 +32,7 @@ pytestmark = [pytest.mark.bgpd]
def build_topo(tgen):
for routern in range(1, 5):
for routern in range(1, 5):
tgen.add_router("r{}".format(routern))
switch = tgen.add_switch("s1")
@ -47,6 +47,7 @@ def build_topo(tgen):
switch.add_link(tgen.gears["r2"])
switch.add_link(tgen.gears["r3"])
def setup_module(mod):
tgen = Topogen(build_topo, mod.__name__)
@ -67,6 +68,7 @@ def setup_module(mod):
# Initialize all routers.
tgen.start_router()
def teardown_module(_mod):
"Teardown the pytest environment"
tgen = get_topogen()

View file

@ -325,12 +325,14 @@ def teardown_module():
)
logger.info("=" * 40)
#####################################################
#
# Testcases
#
#####################################################
def test_verify_bgp_default_originate_in_IBGP_p0(request):
"""
Verify BGP default-originate route with IBGP peer
@ -396,7 +398,9 @@ def test_verify_bgp_default_originate_in_IBGP_p0(request):
step("After changing the BGP AS Path Verify the BGP Convergence")
BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
assert BGP_CONVERGENCE is True, " Complete Convergence is expected after changing the ASN but failed to converge --> :Failed \n Error: {}".format(
assert (
BGP_CONVERGENCE is True
), " Complete Convergence is expected after changing the ASN but failed to converge --> :Failed \n Error: {}".format(
BGP_CONVERGENCE
)
@ -413,8 +417,10 @@ def test_verify_bgp_default_originate_in_IBGP_p0(request):
}
}
result = create_static_routes(tgen, static_routes_input)
assert result is True, "Testcase {} : Failed to configure the static routes {} on router R1 \n Error: {}".format(
tc_name,static_routes_input, result
assert (
result is True
), "Testcase {} : Failed to configure the static routes {} on router R1 \n Error: {}".format(
tc_name, static_routes_input, result
)
step("verify IPv4 and IPv6 static route are configured and up on R1")
for addr_type in ADDR_TYPES:
@ -429,8 +435,10 @@ def test_verify_bgp_default_originate_in_IBGP_p0(request):
}
}
result = verify_fib_routes(tgen, addr_type, "r1", static_routes_input)
assert result is True, "Testcase {} : Failed \n After configuring the static routes {} , the routes are not found in FIB \n Error: {}".format(
tc_name,static_routes_input, result
assert (
result is True
), "Testcase {} : Failed \n After configuring the static routes {} , the routes are not found in FIB \n Error: {}".format(
tc_name, static_routes_input, result
)
step(
@ -483,7 +491,11 @@ def test_verify_bgp_default_originate_in_IBGP_p0(request):
},
}
result = create_router_bgp(tgen, topo, redistribute_static)
assert result is True, "Testcase {} : Failed to configure the redistribute static configuration \n Error: {}".format(tc_name, result)
assert (
result is True
), "Testcase {} : Failed to configure the redistribute static configuration \n Error: {}".format(
tc_name, result
)
step(
"After configuring redistribute command , verify static and connected routes ( loopback connected routes) are advertised on R2"
@ -517,13 +529,17 @@ def test_verify_bgp_default_originate_in_IBGP_p0(request):
}
}
result = verify_fib_routes(tgen, addr_type, "r2", static_routes_input)
assert result is True, "Testcase {} : After redistributing static routes the routes {} expected in FIB but NOT FOUND ......! \n Error: {}".format(
tc_name, static_routes_input,result
assert (
result is True
), "Testcase {} : After redistributing static routes the routes {} expected in FIB but NOT FOUND ......! \n Error: {}".format(
tc_name, static_routes_input, result
)
result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input)
assert result is True, "Testcase {} : After redistributing static routes the routes {} expected in RIB but NOT FOUND ......! \n Error: {}".format(
tc_name, static_routes_input , result
assert (
result is True
), "Testcase {} : After redistributing static routes the routes {} expected in RIB but NOT FOUND ......! \n Error: {}".format(
tc_name, static_routes_input, result
)
step(
@ -547,7 +563,11 @@ def test_verify_bgp_default_originate_in_IBGP_p0(request):
}
}
result = create_router_bgp(tgen, topo, default_originate_config)
assert result is True, "Testcase {} : Failed Configuring default originate configuration. \n Error: {}".format(tc_name, result)
assert (
result is True
), "Testcase {} : Failed Configuring default originate configuration. \n Error: {}".format(
tc_name, result
)
step(
"After configuring default-originate command , verify default routes are advertised on R2 "
@ -574,12 +594,16 @@ def test_verify_bgp_default_originate_in_IBGP_p0(request):
}
result = verify_fib_routes(tgen, addr_type, "r2", static_routes_input)
assert result is True, "Testcase {} : post configuring the BGP Default originate configuration static and connected routes should not be effected but impacted on FIB .......! FAILED \n Error: {}".format(
assert (
result is True
), "Testcase {} : post configuring the BGP Default originate configuration static and connected routes should not be effected but impacted on FIB .......! FAILED \n Error: {}".format(
tc_name, result
)
result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input)
assert result is True, "Testcase {} : Failedpost configuring the BGP Default originate configuration static and connected routes should not be effected but impacted on RIB......! FAILED \n Error: {}".format(
assert (
result is True
), "Testcase {} : Failedpost configuring the BGP Default originate configuration static and connected routes should not be effected but impacted on RIB......! FAILED \n Error: {}".format(
tc_name, result
)
step(
@ -686,7 +710,9 @@ def test_verify_bgp_default_originate_in_EBGP_p0(request):
step("After changing the BGP AS Path Verify the BGP Convergence")
BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
assert BGP_CONVERGENCE is True, "Complete convergence is expeceted after changing the ASN os the routes ..! :Failed \n Error: {}".format(
assert (
BGP_CONVERGENCE is True
), "Complete convergence is expeceted after changing the ASN os the routes ..! :Failed \n Error: {}".format(
BGP_CONVERGENCE
)
@ -703,7 +729,9 @@ def test_verify_bgp_default_originate_in_EBGP_p0(request):
}
}
result = create_static_routes(tgen, static_routes_input)
assert result is True, "Testcase {} : Failed to configure the static routes ....! Failed \n Error: {}".format(
assert (
result is True
), "Testcase {} : Failed to configure the static routes ....! Failed \n Error: {}".format(
tc_name, result
)
step("verify IPv4 and IPv6 static route are configured and up on R1")
@ -719,8 +747,10 @@ def test_verify_bgp_default_originate_in_EBGP_p0(request):
}
}
result = verify_fib_routes(tgen, addr_type, "r3", static_routes_input)
assert result is True, "Testcase {} : Route is not found in {} in FIB ......! Failed \n Error: {}".format(
tc_name, static_routes_input,result
assert (
result is True
), "Testcase {} : Route is not found in {} in FIB ......! Failed \n Error: {}".format(
tc_name, static_routes_input, result
)
step(
@ -773,7 +803,11 @@ def test_verify_bgp_default_originate_in_EBGP_p0(request):
},
}
result = create_router_bgp(tgen, topo, redistribute_static)
assert result is True, "Testcase {} : Failed to configure redistribute configuratin \n Error: {}".format(tc_name, result)
assert (
result is True
), "Testcase {} : Failed to configure redistribute configuratin \n Error: {}".format(
tc_name, result
)
step(
"After configuring redistribute command , verify static and connected routes ( loopback connected routes) are advertised on R2"
@ -806,11 +840,15 @@ def test_verify_bgp_default_originate_in_EBGP_p0(request):
}
}
result = verify_fib_routes(tgen, addr_type, "r2", static_routes_input)
assert result is True, "Testcase {} : static & and connected routes are expected but not found in FIB .... ! \n Error: {}".format(
assert (
result is True
), "Testcase {} : static & and connected routes are expected but not found in FIB .... ! \n Error: {}".format(
tc_name, result
)
result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input)
assert result is True, "Testcase {} : static & and connected routes are expected but not found in RIB .... ! \n Error: {}".format(
assert (
result is True
), "Testcase {} : static & and connected routes are expected but not found in RIB .... ! \n Error: {}".format(
tc_name, result
)
snapshot1 = get_prefix_count_route(tgen, topo, dut="r2", peer="r3")
@ -830,7 +868,11 @@ def test_verify_bgp_default_originate_in_EBGP_p0(request):
}
}
result = create_router_bgp(tgen, topo, default_originate_config)
assert result is True, "Testcase {} : Failed to configure the default originate configuration \n Error: {}".format(tc_name, result)
assert (
result is True
), "Testcase {} : Failed to configure the default originate configuration \n Error: {}".format(
tc_name, result
)
step(
"After configuring default-originate command , verify default routes are advertised on R2 on both BGP RIB and FIB"
@ -853,13 +895,17 @@ def test_verify_bgp_default_originate_in_EBGP_p0(request):
}
result = verify_fib_routes(tgen, addr_type, "r2", static_routes_input)
assert result is True, "Testcase {} : static route from R1 {} and default route from R3 is expected in R2 FIB .....! NOT FOUND \n Error: {}".format(
tc_name, NETWORK1_1,result
assert (
result is True
), "Testcase {} : static route from R1 {} and default route from R3 is expected in R2 FIB .....! NOT FOUND \n Error: {}".format(
tc_name, NETWORK1_1, result
)
result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input)
assert result is True, "Testcase {} : static route from R1 {} and default route from R3 is expected in R2 RIB .....! NOT FOUND \n Error: {}".format(
tc_name,NETWORK1_1, result
assert (
result is True
), "Testcase {} : static route from R1 {} and default route from R3 is expected in R2 RIB .....! NOT FOUND \n Error: {}".format(
tc_name, NETWORK1_1, result
)
step(
@ -875,7 +921,11 @@ def test_verify_bgp_default_originate_in_EBGP_p0(request):
metric=0,
expected_aspath="4000",
)
assert result is True, "Testcase {} : Default route from R3 is expected with attributes in R2 RIB .....! NOT FOUND Error: {}".format(tc_name, result)
assert (
result is True
), "Testcase {} : Default route from R3 is expected with attributes in R2 RIB .....! NOT FOUND Error: {}".format(
tc_name, result
)
step(
"Taking the snapshot2 of the prefix count after configuring the default originate"
@ -968,7 +1018,9 @@ def test_verify_bgp_default_originate_in_IBGP_with_route_map_p0(request):
step("After changing the BGP AS Path Verify the BGP Convergence")
BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
assert BGP_CONVERGENCE is True, "Complete convergence is expected after changing ASN ....! ERROR :Failed \n Error: {}".format(
assert (
BGP_CONVERGENCE is True
), "Complete convergence is expected after changing ASN ....! ERROR :Failed \n Error: {}".format(
BGP_CONVERGENCE
)
@ -989,7 +1041,9 @@ def test_verify_bgp_default_originate_in_IBGP_with_route_map_p0(request):
}
}
result = create_static_routes(tgen, static_routes_input)
assert result is True, "Testcase {} : Static Configuration is Failed \n Error: {}".format(
assert (
result is True
), "Testcase {} : Static Configuration is Failed \n Error: {}".format(
tc_name, result
)
@ -1010,8 +1064,10 @@ def test_verify_bgp_default_originate_in_IBGP_with_route_map_p0(request):
}
}
result = verify_fib_routes(tgen, addr_type, "r0", static_routes_input)
assert result is True, "Testcase {} : routes {} unable is not found in R0 FIB \n Error: {}".format(
tc_name, static_routes_input,result
assert (
result is True
), "Testcase {} : routes {} unable is not found in R0 FIB \n Error: {}".format(
tc_name, static_routes_input, result
)
step(
@ -1028,7 +1084,11 @@ def test_verify_bgp_default_originate_in_IBGP_with_route_map_p0(request):
}
}
result = create_router_bgp(tgen, topo, redistribute_static)
assert result is True, "Testcase {} : Failed to configure redistribute static configuration....! \n Error: {}".format(tc_name, result)
assert (
result is True
), "Testcase {} : Failed to configure redistribute static configuration....! \n Error: {}".format(
tc_name, result
)
step("verify IPv4 and IPv6 static route are configured and up on R1")
for addr_type in ADDR_TYPES:
@ -1047,13 +1107,17 @@ def test_verify_bgp_default_originate_in_IBGP_with_route_map_p0(request):
}
}
result = verify_fib_routes(tgen, addr_type, "r1", static_routes_input)
assert result is True, "Testcase {} : Failed... Routes {} expected in r0 FIB after configuring the redistribute config \n Error: {}".format(
tc_name,static_routes_input, result
assert (
result is True
), "Testcase {} : Failed... Routes {} expected in r0 FIB after configuring the redistribute config \n Error: {}".format(
tc_name, static_routes_input, result
)
result = verify_bgp_rib(tgen, addr_type, "r1", static_routes_input)
assert result is True, "Testcase {} : Failed... Routes {} expected in r0 RIB after configuring the redistribute config \n Error: {}".format(
tc_name, static_routes_input,result
assert (
result is True
), "Testcase {} : Failed... Routes {} expected in r0 RIB after configuring the redistribute config \n Error: {}".format(
tc_name, static_routes_input, result
)
step(
@ -1094,7 +1158,11 @@ def test_verify_bgp_default_originate_in_IBGP_with_route_map_p0(request):
}
}
result = create_prefix_lists(tgen, input_dict_3)
assert result is True, "Testcase {} : Failed to configure the prefix list \n Error: {}".format(tc_name, result)
assert (
result is True
), "Testcase {} : Failed to configure the prefix list \n Error: {}".format(
tc_name, result
)
step(
"Configure IPV4 and IPv6 route-map (RMv4 and RMv6 ) matching prefix-list (Pv4 and Pv6) respectively on R1"
@ -1120,7 +1188,11 @@ def test_verify_bgp_default_originate_in_IBGP_with_route_map_p0(request):
}
}
result = create_route_maps(tgen, input_dict_3)
assert result is True, "Testcase {} : Failed to configure the route map \n Error: {}".format(tc_name, result)
assert (
result is True
), "Testcase {} : Failed to configure the route map \n Error: {}".format(
tc_name, result
)
step(
"Configure default-originate with route-map (RMv4 and RMv6) on R1, on BGP IPv4 and IPv6 address family "
@ -1142,7 +1214,11 @@ def test_verify_bgp_default_originate_in_IBGP_with_route_map_p0(request):
}
}
result = create_router_bgp(tgen, topo, default_originate_config)
assert result is True, "Testcase {} : Failed to configure the default originate \n Error: {}".format(tc_name, result)
assert (
result is True
), "Testcase {} : Failed to configure the default originate \n Error: {}".format(
tc_name, result
)
step("Verify the default route is received in BGP RIB and FIB")
step(
@ -1167,7 +1243,9 @@ def test_verify_bgp_default_originate_in_IBGP_with_route_map_p0(request):
static_routes_input,
next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type],
)
assert result is True, "Testcase {} : Failed...! Expected default route from R1 not found in FIB \n Error: {}".format(
assert (
result is True
), "Testcase {} : Failed...! Expected default route from R1 not found in FIB \n Error: {}".format(
tc_name, result
)
@ -1178,7 +1256,9 @@ def test_verify_bgp_default_originate_in_IBGP_with_route_map_p0(request):
static_routes_input,
next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type],
)
assert result is True, "Testcase {} : Failed...! Expected default route from R1 not found in RIB \n Error: {}".format(
assert (
result is True
), "Testcase {} : Failed...! Expected default route from R1 not found in RIB \n Error: {}".format(
tc_name, result
)
step("Remove route-map RMv4 and RMv6 from default-originate command in R1")
@ -1196,7 +1276,11 @@ def test_verify_bgp_default_originate_in_IBGP_with_route_map_p0(request):
}
}
result = create_router_bgp(tgen, topo, default_originate_config)
assert result is True, "Testcase {} : Failed to remove the default originate conditional route-map \n Error: {}".format(tc_name, result)
assert (
result is True
), "Testcase {} : Failed to remove the default originate conditional route-map \n Error: {}".format(
tc_name, result
)
step(
"Verify BGP RIB and FIB After removing route-map , default route still present on R2"
@ -1221,7 +1305,9 @@ def test_verify_bgp_default_originate_in_IBGP_with_route_map_p0(request):
static_routes_input,
next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type],
)
assert result is True, "Testcase {} : Failed Default route from R1 is not found in FIB \n Error: {}".format(
assert (
result is True
), "Testcase {} : Failed Default route from R1 is not found in FIB \n Error: {}".format(
tc_name, result
)
@ -1232,7 +1318,9 @@ def test_verify_bgp_default_originate_in_IBGP_with_route_map_p0(request):
static_routes_input,
next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type],
)
assert result is True, "Testcase {} : Failed Default route from R1 is not found in RIB \n Error: {}".format(
assert (
result is True
), "Testcase {} : Failed Default route from R1 is not found in RIB \n Error: {}".format(
tc_name, result
)
@ -1266,7 +1354,11 @@ def test_verify_bgp_default_originate_in_IBGP_with_route_map_p0(request):
}
}
result = create_router_bgp(tgen, topo, default_originate_config)
assert result is True, "Testcase {} : Failed to configure the Default originate route-map \n Error: {}".format(tc_name, result)
assert (
result is True
), "Testcase {} : Failed to configure the Default originate route-map \n Error: {}".format(
tc_name, result
)
step(
"After configuring default-originate command , verify default routes are advertised on R2 "
@ -1290,7 +1382,9 @@ def test_verify_bgp_default_originate_in_IBGP_with_route_map_p0(request):
static_routes_input,
next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type],
)
assert result is True, "Testcase {} : Failed Default Route from R1 is not found in FIB \n Error: {}".format(
assert (
result is True
), "Testcase {} : Failed Default Route from R1 is not found in FIB \n Error: {}".format(
tc_name, result
)
@ -1301,7 +1395,9 @@ def test_verify_bgp_default_originate_in_IBGP_with_route_map_p0(request):
static_routes_input,
next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type],
)
assert result is True, "Testcase {} : Failed Default Route from R1 is not found in RIB \n Error: {}".format(
assert (
result is True
), "Testcase {} : Failed Default Route from R1 is not found in RIB \n Error: {}".format(
tc_name, result
)
@ -1345,7 +1441,11 @@ def test_verify_bgp_default_originate_in_IBGP_with_route_map_p0(request):
}
}
result = create_prefix_lists(tgen, input_dict_3)
assert result is True, "Testcase {} : Failed to delete the prefix list Error: {}".format(tc_name, result)
assert (
result is True
), "Testcase {} : Failed to delete the prefix list Error: {}".format(
tc_name, result
)
step(
"Verify BGP RIB and FIB After deleting prefix-list , verify IPv4 and IPv6 default route got removed from DUT "
@ -1426,7 +1526,11 @@ def test_verify_bgp_default_originate_in_IBGP_with_route_map_p0(request):
}
}
result = create_prefix_lists(tgen, input_dict_3)
assert result is True, "Testcase {} : Failed to configure the prefix lists Error: {}".format(tc_name, result)
assert (
result is True
), "Testcase {} : Failed to configure the prefix lists Error: {}".format(
tc_name, result
)
step(
"After configuring the Prefixlist cross checking the BGP Default route is configured again , before deleting the route map"
@ -1452,7 +1556,9 @@ def test_verify_bgp_default_originate_in_IBGP_with_route_map_p0(request):
next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type],
expected=True,
)
assert result is True, "Testcase {} : Failed Default route from R1 is expected in FIB but not found \n Error: {}".format(
assert (
result is True
), "Testcase {} : Failed Default route from R1 is expected in FIB but not found \n Error: {}".format(
tc_name, result
)
@ -1464,14 +1570,20 @@ def test_verify_bgp_default_originate_in_IBGP_with_route_map_p0(request):
next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type],
expected=True,
)
assert result is True, "Testcase {} : Failed Default route from R1 is expected in RIB but not found \n Error: {}".format(
assert (
result is True
), "Testcase {} : Failed Default route from R1 is expected in RIB but not found \n Error: {}".format(
tc_name, result
)
step("Deleting the routemap")
input_dict = {"r1": {"route_maps": ["RMv4", "RMv6"]}}
result = delete_route_maps(tgen, input_dict)
assert result is True, "Testcase {} : Failed to delete the Route-map \n Error: {}".format(tc_name, result)
assert (
result is True
), "Testcase {} : Failed to delete the Route-map \n Error: {}".format(
tc_name, result
)
step(
"Verify BGP RIB and FIB ,After deleting route-map , verify IPv4 and IPv6 default route got removed from DUT"
@ -1605,7 +1717,9 @@ def test_verify_bgp_default_originate_in_EBGP_with_route_map_p0(request):
}
}
result = create_static_routes(tgen, static_routes_input)
assert result is True, "Testcase {} : Failed to configure the static routes \n Error: {}".format(
assert (
result is True
), "Testcase {} : Failed to configure the static routes \n Error: {}".format(
tc_name, result
)
step("verify IPv4 and IPv6 static route are configured and up on R4")
@ -1625,8 +1739,10 @@ def test_verify_bgp_default_originate_in_EBGP_with_route_map_p0(request):
}
}
result = verify_fib_routes(tgen, addr_type, "r4", static_routes_input)
assert result is True, "Testcase {} : Failed Static route {} is not found in R4 FIB \n Error: {}".format(
tc_name, static_routes_input,result
assert (
result is True
), "Testcase {} : Failed Static route {} is not found in R4 FIB \n Error: {}".format(
tc_name, static_routes_input, result
)
step(
@ -1643,7 +1759,11 @@ def test_verify_bgp_default_originate_in_EBGP_with_route_map_p0(request):
}
}
result = create_router_bgp(tgen, topo, redistribute_static)
assert result is True, "Testcase {} : Failed to configure the redistribute static \n Error: {}".format(tc_name, result)
assert (
result is True
), "Testcase {} : Failed to configure the redistribute static \n Error: {}".format(
tc_name, result
)
step("verify IPv4 and IPv6 static route are configured and up on R3")
for addr_type in ADDR_TYPES:
@ -1662,11 +1782,15 @@ def test_verify_bgp_default_originate_in_EBGP_with_route_map_p0(request):
}
}
result = verify_fib_routes(tgen, addr_type, "r3", static_routes_input)
assert result is True, "Testcase {} : Failed static routes from R1 and R3 is not found in FIB \n Error: {}".format(
assert (
result is True
), "Testcase {} : Failed static routes from R1 and R3 is not found in FIB \n Error: {}".format(
tc_name, result
)
result = verify_bgp_rib(tgen, addr_type, "r3", static_routes_input)
assert result is True, "Testcase {} : Failed static routes from R1 and R3 is not found in RIB \n Error: {}".format(
assert (
result is True
), "Testcase {} : Failed static routes from R1 and R3 is not found in RIB \n Error: {}".format(
tc_name, result
)
@ -1698,12 +1822,20 @@ def test_verify_bgp_default_originate_in_EBGP_with_route_map_p0(request):
}
}
result = create_prefix_lists(tgen, input_dict_3)
assert result is True, "Testcase {} : Failed to configure the prefix lists \n Error: {}".format(tc_name, result)
assert (
result is True
), "Testcase {} : Failed to configure the prefix lists \n Error: {}".format(
tc_name, result
)
step("verify IPv4 and IPv6 Prefix list got configured on R3")
input_dict = {"r3": {"prefix_lists": ["Pv4", "Pv6"]}}
result = verify_prefix_lists(tgen, input_dict)
assert result is True, "Testcase {} : Failed ..! configured prefix lists {} are not found \n Error: {}".format(tc_name,input_dict, result)
assert (
result is True
), "Testcase {} : Failed ..! configured prefix lists {} are not found \n Error: {}".format(
tc_name, input_dict, result
)
step(
"Configure IPv4 and IPv6 route-map ( RMv4 and RMv6 ) matching prefix-list (Pv4 and Pv6 ) respectively on R3"
@ -1729,7 +1861,11 @@ def test_verify_bgp_default_originate_in_EBGP_with_route_map_p0(request):
}
}
result = create_route_maps(tgen, input_dict_3)
assert result is True, "Testcase {} : Failed to configure the route-map \n Error: {}".format(tc_name, result)
assert (
result is True
), "Testcase {} : Failed to configure the route-map \n Error: {}".format(
tc_name, result
)
step(
"Taking the snapshot of the prefix count before configuring the default originate"
)
@ -1754,7 +1890,11 @@ def test_verify_bgp_default_originate_in_EBGP_with_route_map_p0(request):
}
}
result = create_router_bgp(tgen, topo, default_originate_config)
assert result is True, "Testcase {} : Failed to configure default-originate \n Error: {}".format(tc_name, result)
assert (
result is True
), "Testcase {} : Failed to configure default-originate \n Error: {}".format(
tc_name, result
)
step("Verify the default route is NOT received in BGP RIB and FIB on R2 ")
step(
@ -1836,7 +1976,11 @@ def test_verify_bgp_default_originate_in_EBGP_with_route_map_p0(request):
}
}
result = create_prefix_lists(tgen, input_dict_3)
assert result is True, "Testcase {} : Failed to configure the prefix lists Error: {}".format(tc_name, result)
assert (
result is True
), "Testcase {} : Failed to configure the prefix lists Error: {}".format(
tc_name, result
)
step("Verify BGP default route for IPv4 and IPv6 is received on R2")
@ -1859,7 +2003,9 @@ def test_verify_bgp_default_originate_in_EBGP_with_route_map_p0(request):
static_routes_input,
next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type],
)
assert result is True, "Testcase {} : Failed Default routes are expected in R2 FIB from R3 but not found ....! \n Error: {}".format(
assert (
result is True
), "Testcase {} : Failed Default routes are expected in R2 FIB from R3 but not found ....! \n Error: {}".format(
tc_name, result
)
@ -1870,7 +2016,9 @@ def test_verify_bgp_default_originate_in_EBGP_with_route_map_p0(request):
static_routes_input,
next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type],
)
assert result is True, "Testcase {} : Failed Default routes are expected in R2 RIB from R3 but not found ....! \n Error: {}".format(
assert (
result is True
), "Testcase {} : Failed Default routes are expected in R2 RIB from R3 but not found ....! \n Error: {}".format(
tc_name, result
)
@ -1914,7 +2062,11 @@ def test_verify_bgp_default_originate_in_EBGP_with_route_map_p0(request):
}
}
result = create_prefix_lists(tgen, input_dict_3)
assert result is True, "Testcase {} : Failed to remove prefix-lists from R3 Error: {}".format(tc_name, result)
assert (
result is True
), "Testcase {} : Failed to remove prefix-lists from R3 Error: {}".format(
tc_name, result
)
step(
"After Removing route BGP default route for IPv4 and IPv6 is NOT received on R2"

View file

@ -955,6 +955,7 @@ def test_verify_bgp_default_originate_route_map_in_OUT_p1(request):
write_test_footer(tc_name)
def test_verify_bgp_default_originate_route_map_in_IN_p1(request):
"""Verify BGP default originate route-map with IN route-map"""
tgen = get_topogen()
@ -1472,6 +1473,7 @@ def test_verify_bgp_default_originate_route_map_in_IN_p1(request):
)
write_test_footer(tc_name)
def test_verify_default_originate_after_removing_default_originate_p1(request):
"""Verify BGP default route after removing default-originate"""
@ -2232,9 +2234,9 @@ def test_verify_default_originate_after_removing_default_originate_p1(request):
)
write_test_footer(tc_name)
def test_verify_default_originate_route_with_GR_p1(request):
""" "Verify default-originate route with GR "
"""
""" "Verify default-originate route with GR " """
tgen = get_topogen()
global BGP_CONVERGENCE
global topo
@ -2250,14 +2252,13 @@ def test_verify_default_originate_route_with_GR_p1(request):
if BGP_CONVERGENCE != True:
pytest.skip("skipped because of BGP Convergence failure")
step("Configure IPV4 and IPV6 IBGP between R1 and R2 ")
step("Configure IPV4 and IPV6 EBGP between R2 to R3 ")
r0_local_as = topo['routers']['r0']['bgp']['local_as']
r1_local_as = topo['routers']['r1']['bgp']['local_as']
r2_local_as = topo['routers']['r2']['bgp']['local_as']
r3_local_as = topo['routers']['r3']['bgp']['local_as']
r4_local_as = topo['routers']['r4']['bgp']['local_as']
r0_local_as = topo["routers"]["r0"]["bgp"]["local_as"]
r1_local_as = topo["routers"]["r1"]["bgp"]["local_as"]
r2_local_as = topo["routers"]["r2"]["bgp"]["local_as"]
r3_local_as = topo["routers"]["r3"]["bgp"]["local_as"]
r4_local_as = topo["routers"]["r4"]["bgp"]["local_as"]
input_dict = {
"r0": {
"bgp": {
@ -2336,33 +2337,14 @@ def test_verify_default_originate_route_with_GR_p1(request):
"bgp": {
"local_as": local_as,
"address_family": {
"ipv4": {
"unicast": {
"default_originate":{
"r2":{
}
}
}
}, "ipv6": {
"unicast": {
"default_originate":{
"r2":{
}
}
}
}
}
"ipv4": {"unicast": {"default_originate": {"r2": {}}}},
"ipv6": {"unicast": {"default_originate": {"r2": {}}}},
},
}
}
}
result = create_router_bgp(tgen, topo, default_originate_config)
assert result is True, "Testcase {} : Failed \n Error: {}".format(
tc_name, result)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
step(
"R2 received default-originate routes and advertised it to R3 , verify on R2 and R3"
@ -2383,17 +2365,28 @@ def test_verify_default_originate_route_with_GR_p1(request):
}
}
result = verify_fib_routes(tgen, addr_type, "r2", static_routes_input,next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type])
result = verify_fib_routes(
tgen,
addr_type,
"r2",
static_routes_input,
next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type],
)
assert result is True, "Testcase {} : Failed \n Error: {}".format(
tc_name, result
)
result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input,next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type])
result = verify_bgp_rib(
tgen,
addr_type,
"r2",
static_routes_input,
next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type],
)
assert result is True, "Testcase {} : Failed \n Error: {}".format(
tc_name, result
)
step(" Kill BGPd session on R2")
kill_router_daemons(tgen, "r2", ["bgpd"])
start_router_daemons(tgen, "r2", ["bgpd"])
@ -2411,17 +2404,30 @@ def test_verify_default_originate_route_with_GR_p1(request):
}
}
result = verify_fib_routes(tgen, addr_type, "r2", static_routes_input,next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type])
result = verify_fib_routes(
tgen,
addr_type,
"r2",
static_routes_input,
next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type],
)
assert result is True, "Testcase {} : Failed \n Error: {}".format(
tc_name, result
)
result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input,next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type])
result = verify_bgp_rib(
tgen,
addr_type,
"r2",
static_routes_input,
next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type],
)
assert result is True, "Testcase {} : Failed \n Error: {}".format(
tc_name, result
)
write_test_footer(tc_name)
if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]
sys.exit(pytest.main(args))

View file

@ -75,6 +75,7 @@ NETWORK1_1 = {"ipv4": "198.51.1.1/32", "ipv6": "2001:DB8::1:1/128"}
DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
NEXT_HOP_IP = {"ipv4": "Null0", "ipv6": "Null0"}
def setup_module(mod):
"""
Sets up the pytest environment
@ -818,11 +819,11 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
step("Configure IPv4 and IPv6 , EBGP neighbor between R3 and R2")
step("Configure IPv4 and IPv6 IBGP neighbor between R3 and R4")
r0_local_as = topo['routers']['r0']['bgp']['local_as']
r1_local_as = topo['routers']['r1']['bgp']['local_as']
r2_local_as = topo['routers']['r2']['bgp']['local_as']
r3_local_as = topo['routers']['r3']['bgp']['local_as']
r4_local_as = topo['routers']['r4']['bgp']['local_as']
r0_local_as = topo["routers"]["r0"]["bgp"]["local_as"]
r1_local_as = topo["routers"]["r1"]["bgp"]["local_as"]
r2_local_as = topo["routers"]["r2"]["bgp"]["local_as"]
r3_local_as = topo["routers"]["r3"]["bgp"]["local_as"]
r4_local_as = topo["routers"]["r4"]["bgp"]["local_as"]
input_dict = {
"r0": {
"bgp": {
@ -1026,22 +1027,21 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
"action": "permit",
"seq_id": "1",
"set": {
"path": {
"as_num": "200",
"as_action": "prepend",
}
"path": {
"as_num": "200",
"as_action": "prepend",
}
},
},
{
"action": "permit",
"seq_id": "2",
"set": {
"path": {
"as_num": "300",
"as_action": "prepend",
}
"path": {
"as_num": "300",
"as_action": "prepend",
}
},
},
],
"RMv6": [
@ -1049,21 +1049,21 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
"action": "permit",
"seq_id": "1",
"set": {
"path": {
"as_num": "200",
"as_action": "prepend",
}
"path": {
"as_num": "200",
"as_action": "prepend",
}
},
},
{
"action": "permit",
"seq_id": "2",
"set": {
"path": {
"as_num": "300",
"as_action": "prepend",
}
"path": {
"as_num": "300",
"as_action": "prepend",
}
},
},
],
}
@ -1122,22 +1122,21 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
"action": "permit",
"seq_id": "1",
"set": {
"path": {
"as_num": "500",
"as_action": "prepend",
}
"path": {
"as_num": "500",
"as_action": "prepend",
}
},
},
{
"action": "permit",
"seq_id": "2",
"set": {
"path": {
"as_num": "600",
"as_action": "prepend",
}
"path": {
"as_num": "600",
"as_action": "prepend",
}
},
},
],
"RMv6": [
@ -1145,21 +1144,21 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
"action": "permit",
"seq_id": "1",
"set": {
"path": {
"as_num": "500",
"as_action": "prepend",
}
"path": {
"as_num": "500",
"as_action": "prepend",
}
},
},
{
"action": "permit",
"seq_id": "2",
"set": {
"path": {
"as_num": "600",
"as_action": "prepend",
}
"path": {
"as_num": "600",
"as_action": "prepend",
}
},
},
],
}
@ -1170,7 +1169,6 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result)
assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
step("As path 500 added to IPv4 and IPv6 default -originate route received on R2")
result = verify_rib_default_route(
tgen,
@ -1232,7 +1230,6 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
"Verify Configured metric value received on R2 along with as-path for IPv4 and IPv6 default routes "
)
DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "::/0"}
result = verify_rib_default_route(
tgen,
@ -1244,7 +1241,6 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
expected_aspath="4000 500",
)
step(
"Modify route-map seq1 configure metric 50 and route-map seq2 configure metric 100 IPv4 and IPv6 route-map "
)
@ -1294,7 +1290,6 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
"Verify Configured metric value received on R2 along with as-path for IPv4 and IPv6 default routes "
)
result = verify_rib_default_route(
tgen,
topo,
@ -1314,7 +1309,6 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
{
"action": "permit",
"seq_id": "1",
"set": {
"path": {
"as_num": "500",
@ -1374,9 +1368,6 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
"Verify AS-prepend is deleted from default originate route and metric value only present on R2 for IPv4 and IPv6 default routes "
)
result = verify_rib_default_route(
tgen,
topo,
@ -1388,7 +1379,6 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
)
assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
step("Delete metric value from IP4 and IPv6 route-map configured on R3 ")
route_map = {
"r3": {
@ -1428,8 +1418,6 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
"Verify Metric value deleted from IPv4 and IPv6 default route on R2 ,verify default routes "
)
result = verify_rib_default_route(
tgen,
topo,
@ -1443,11 +1431,11 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
step("Change IPv4 and IPv6 , EBGP to IBGP neighbor between R3 and R2")
step("Change IPv4 and IPv6 IBGP to EBGP neighbor between R3 and R4")
r0_local_as = topo['routers']['r0']['bgp']['local_as']
r1_local_as = topo['routers']['r1']['bgp']['local_as']
r2_local_as = topo['routers']['r2']['bgp']['local_as']
r3_local_as = topo['routers']['r3']['bgp']['local_as']
r4_local_as = topo['routers']['r4']['bgp']['local_as']
r0_local_as = topo["routers"]["r0"]["bgp"]["local_as"]
r1_local_as = topo["routers"]["r1"]["bgp"]["local_as"]
r2_local_as = topo["routers"]["r2"]["bgp"]["local_as"]
r3_local_as = topo["routers"]["r3"]["bgp"]["local_as"]
r4_local_as = topo["routers"]["r4"]["bgp"]["local_as"]
input_dict = {
"r0": {
"bgp": {
@ -1459,7 +1447,6 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
"local_as": r1_local_as,
}
},
"r2": {
"bgp": {
"local_as": 1111,
@ -1645,8 +1632,6 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
"Verify Configured metric value received on R2 along with as-path for IPv4 and IPv6 default routes "
)
result = verify_rib_default_route(
tgen,
topo,
@ -1656,7 +1641,6 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
locPrf=50,
)
assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
step(
@ -1708,9 +1692,6 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
"Verify Modified local-preference value received on R2 for IPv4 and IPv6 default routes "
)
DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "::/0"}
result = verify_rib_default_route(
tgen,
@ -1724,13 +1705,15 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
# updating the topology with the updated AS-Number to avoid conflict in con configuring the AS
updated_topo = topo
updated_topo['routers']['r0']['bgp']['local_as']=get_dut_as_number(tgen,"r0")
updated_topo['routers']['r1']['bgp']['local_as']=get_dut_as_number(tgen,"r1")
updated_topo['routers']['r2']['bgp']['local_as']=get_dut_as_number(tgen,"r2")
updated_topo['routers']['r3']['bgp']['local_as']=get_dut_as_number(tgen,"r3")
updated_topo['routers']['r4']['bgp']['local_as']=get_dut_as_number(tgen,"r4")
updated_topo["routers"]["r0"]["bgp"]["local_as"] = get_dut_as_number(tgen, "r0")
updated_topo["routers"]["r1"]["bgp"]["local_as"] = get_dut_as_number(tgen, "r1")
updated_topo["routers"]["r2"]["bgp"]["local_as"] = get_dut_as_number(tgen, "r2")
updated_topo["routers"]["r3"]["bgp"]["local_as"] = get_dut_as_number(tgen, "r3")
updated_topo["routers"]["r4"]["bgp"]["local_as"] = get_dut_as_number(tgen, "r4")
step("Shut IPv4/IPv6 BGP neighbor from R4 ( R4-R3) using 'neighbor x.x.x.x shut' command ")
step(
"Shut IPv4/IPv6 BGP neighbor from R4 ( R4-R3) using 'neighbor x.x.x.x shut' command "
)
local_as = get_dut_as_number(tgen, dut="r4")
shut_neighbor = {
"r4": {
@ -1740,46 +1723,41 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
"ipv4": {
"unicast": {
"neighbor": {
"r3": {
"dest_link": {
"r4": {"shutdown":True}
}
}
"r3": {"dest_link": {"r4": {"shutdown": True}}}
}
}
},
"ipv6": {
"unicast": {
"neighbor": {
"r3": {
"dest_link": {
"r4": {"shutdown":True}
}
}
"r3": {"dest_link": {"r4": {"shutdown": True}}}
}
}
}
}
},
},
}
}
}
result = create_router_bgp(tgen, updated_topo, shut_neighbor)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
interface = topo['routers']['r3']['links']['r4']['interface']
input_dict = {
"r1": {
"interface_list": [interface],
"status": "down"
}
}
interface = topo["routers"]["r3"]["links"]["r4"]["interface"]
input_dict = {"r1": {"interface_list": [interface], "status": "down"}}
result = interface_status(tgen, topo, input_dict)
assert result is True, "Testcase {} : Shut down the interface failed ! \n Error: {}".format(tc_name, result)
assert (
result is True
), "Testcase {} : Shut down the interface failed ! \n Error: {}".format(
tc_name, result
)
step("After shutting the interface verify the BGP convergence")
result = verify_bgp_convergence(tgen,topo,expected=False)
assert result is not True, "Testcase {} : Failed \n After shutting Down BGP convergence should Fail and return False \n Error: {}".format(tc_name, result)
result = verify_bgp_convergence(tgen, topo, expected=False)
assert (
result is not True
), "Testcase {} : Failed \n After shutting Down BGP convergence should Fail and return False \n Error: {}".format(
tc_name, result
)
step("verify default route deleted from R2 ")
result = verify_rib_default_route(
@ -1788,8 +1766,13 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
dut="r2",
routes=DEFAULT_ROUTES,
expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
expected=False)
assert result is not True, "Testcase {} : Failed \n Error: After Shut down interface the default route is NOT expected but found in RIB -> {}".format( tc_name, result)
expected=False,
)
assert (
result is not True
), "Testcase {} : Failed \n Error: After Shut down interface the default route is NOT expected but found in RIB -> {}".format(
tc_name, result
)
result = verify_fib_default_route(
tgen,
@ -1797,11 +1780,17 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
dut="r2",
routes=DEFAULT_ROUTES,
expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
expected=False)
assert result is not True, "Testcase {} : Failed \n Error: After Shut down interface the default route is NOT expected but found in FIB -> {}".format( tc_name, result)
expected=False,
)
assert (
result is not True
), "Testcase {} : Failed \n Error: After Shut down interface the default route is NOT expected but found in FIB -> {}".format(
tc_name, result
)
step("no Shut IPv4/IPv6 BGP neighbor from R4 ( R4-R3) using 'neighbor x.x.x.x shut' command ")
step(
"no Shut IPv4/IPv6 BGP neighbor from R4 ( R4-R3) using 'neighbor x.x.x.x shut' command "
)
local_as = get_dut_as_number(tgen, dut="r4")
shut_neighbor = {
"r4": {
@ -1811,46 +1800,39 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
"ipv4": {
"unicast": {
"neighbor": {
"r3": {
"dest_link": {
"r4": {"shutdown":False}
}
}
"r3": {"dest_link": {"r4": {"shutdown": False}}}
}
}
},
"ipv6": {
"unicast": {
"neighbor": {
"r3": {
"dest_link": {
"r4": {"shutdown":False}
}
}
"r3": {"dest_link": {"r4": {"shutdown": False}}}
}
}
}
}
},
},
}
}
}
result = create_router_bgp(tgen, updated_topo, shut_neighbor)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
interface = topo['routers']['r3']['links']['r4']['interface']
input_dict = {
"r1": {
"interface_list": [interface],
"status": "up"
}
}
interface = topo["routers"]["r3"]["links"]["r4"]["interface"]
input_dict = {"r1": {"interface_list": [interface], "status": "up"}}
result = interface_status(tgen, topo, input_dict)
assert result is True, "Testcase {} : Bring up interface failed ! \n Error: {}".format(tc_name, result)
assert (
result is True
), "Testcase {} : Bring up interface failed ! \n Error: {}".format(tc_name, result)
step("After no shutting the interface verify the BGP convergence")
result = verify_bgp_convergence(tgen,topo,expected=True)
assert result is True, "Testcase {} : Failed \n After shutting Down BGP convergence should Fail and return False \n Error: {}".format(tc_name, result)
result = verify_bgp_convergence(tgen, topo, expected=True)
assert (
result is True
), "Testcase {} : Failed \n After shutting Down BGP convergence should Fail and return False \n Error: {}".format(
tc_name, result
)
step("After no shut neighbor , verify default route relearn on R2")
result = verify_rib_default_route(
@ -1859,8 +1841,13 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
dut="r2",
routes=DEFAULT_ROUTES,
expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
expected=True)
assert result is True, "Testcase {} : Failed \n Error: After no Shut down interface the default route is expected but found in RIB -> {}".format( tc_name, result)
expected=True,
)
assert (
result is True
), "Testcase {} : Failed \n Error: After no Shut down interface the default route is expected but found in RIB -> {}".format(
tc_name, result
)
result = verify_fib_default_route(
tgen,
@ -1868,10 +1855,13 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
dut="r2",
routes=DEFAULT_ROUTES,
expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
expected=True)
assert result is True, "Testcase {} : Failed \n Error: After Shut down interface the default route is expected but found in FIB -> {}".format( tc_name, result)
expected=True,
)
assert (
result is True
), "Testcase {} : Failed \n Error: After Shut down interface the default route is expected but found in FIB -> {}".format(
tc_name, result
)
step("Remove IPv4/IPv6 static route configure on R4")
for addr_type in ADDR_TYPES:
@ -1881,7 +1871,7 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
{
"network": [NETWORK1_1[addr_type]],
"next_hop": NEXT_HOP_IP[addr_type],
"delete": True
"delete": True,
}
]
}
@ -1902,12 +1892,16 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
]
}
}
result = verify_fib_routes(tgen, addr_type, "r4", static_routes_input, expected=False)
assert result is not True, "Testcase {} : Failed \n Error: {}".format(
result = verify_fib_routes(
tgen, addr_type, "r4", static_routes_input, expected=False
)
assert result is not True, "Testcase {} : Failed \n Error: {}".format(
tc_name, result
)
result = verify_bgp_rib(tgen, addr_type, "r4", static_routes_input, expected=False)
assert result is not True, "Testcase {} : Failed \n Error: {}".format(
result = verify_bgp_rib(
tgen, addr_type, "r4", static_routes_input, expected=False
)
assert result is not True, "Testcase {} : Failed \n Error: {}".format(
tc_name, result
)
@ -1918,8 +1912,13 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
dut="r2",
routes=DEFAULT_ROUTES,
expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
expected= False)
assert result is not True, "Testcase {} : Failed \n Error: After removing static the default route is NOT expected but found in RIB -> {}".format( tc_name, result)
expected=False,
)
assert (
result is not True
), "Testcase {} : Failed \n Error: After removing static the default route is NOT expected but found in RIB -> {}".format(
tc_name, result
)
result = verify_fib_default_route(
tgen,
@ -1927,9 +1926,13 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
dut="r2",
routes=DEFAULT_ROUTES,
expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
expected= False)
assert result is not True, "Testcase {} : Failed \n Error: After removing static the default route is NOT expected but found in FIB -> {}".format( tc_name, result)
expected=False,
)
assert (
result is not True
), "Testcase {} : Failed \n Error: After removing static the default route is NOT expected but found in FIB -> {}".format(
tc_name, result
)
step("Configuring the static route back in r4")
for addr_type in ADDR_TYPES:
@ -1959,12 +1962,16 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
]
}
}
result = verify_fib_routes(tgen, addr_type, "r4", static_routes_input, expected=True)
assert result is True, "Testcase {} : Failed \n Error: {}".format(
result = verify_fib_routes(
tgen, addr_type, "r4", static_routes_input, expected=True
)
assert result is True, "Testcase {} : Failed \n Error: {}".format(
tc_name, result
)
result = verify_bgp_rib(tgen, addr_type, "r4", static_routes_input, expected=True)
assert result is True, "Testcase {} : Failed \n Error: {}".format(
result = verify_bgp_rib(
tgen, addr_type, "r4", static_routes_input, expected=True
)
assert result is True, "Testcase {} : Failed \n Error: {}".format(
tc_name, result
)
@ -1975,8 +1982,13 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
dut="r2",
routes=DEFAULT_ROUTES,
expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
expected= True)
assert result is True, "Testcase {} : Failed \n Error: After removing static the default route is expected but found in RIB -> {}".format( tc_name, result)
expected=True,
)
assert (
result is True
), "Testcase {} : Failed \n Error: After removing static the default route is expected but found in RIB -> {}".format(
tc_name, result
)
result = verify_fib_default_route(
tgen,
@ -1984,8 +1996,13 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
dut="r2",
routes=DEFAULT_ROUTES,
expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
expected= True)
assert result is True, "Testcase {} : Failed \n Error: After removing static the default route is expected but found in FIB -> {}".format( tc_name, result)
expected=True,
)
assert (
result is True
), "Testcase {} : Failed \n Error: After removing static the default route is expected but found in FIB -> {}".format(
tc_name, result
)
step("Deactivate IPv4 and IPv6 neighbor configured from R4 ( R4-R3)")
@ -1999,15 +2016,14 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
"r3": {"dest_link": {"r4": {"deactivate": "ipv4"}}}
}
},
},"ipv6": {
},
"ipv6": {
"unicast": {
"neighbor": {
"r3": {"dest_link": {"r4": {"deactivate": "ipv6"}}}
}
},
}
},
}
}
}
@ -2022,8 +2038,13 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
dut="r2",
routes=DEFAULT_ROUTES,
expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
expected= False)
assert result is not True, "Testcase {} : Failed \n Error: After Deactivating the BGP neighbor the default route is NOT expected but found in RIB -> {}".format( tc_name, result)
expected=False,
)
assert (
result is not True
), "Testcase {} : Failed \n Error: After Deactivating the BGP neighbor the default route is NOT expected but found in RIB -> {}".format(
tc_name, result
)
result = verify_fib_default_route(
tgen,
@ -2031,8 +2052,13 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
dut="r2",
routes=DEFAULT_ROUTES,
expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
expected= False)
assert result is not True, "Testcase {} : Failed \n Error: After Deactivating the BGP neighbor the default route is NOT expected but found in FIB -> {}".format( tc_name, result)
expected=False,
)
assert (
result is not True
), "Testcase {} : Failed \n Error: After Deactivating the BGP neighbor the default route is NOT expected but found in FIB -> {}".format(
tc_name, result
)
step("Activate IPv4 and IPv6 neighbor configured from R4 ( R4-R3)")
@ -2046,15 +2072,14 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
"r3": {"dest_link": {"r4": {"activate": "ipv4"}}}
}
},
},"ipv6": {
},
"ipv6": {
"unicast": {
"neighbor": {
"r3": {"dest_link": {"r4": {"activate": "ipv6"}}}
}
},
}
},
}
}
}
@ -2064,7 +2089,7 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
step("Verify bgp convergence.")
bgp_convergence = verify_bgp_convergence(tgen, updated_topo)
assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format(
assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format(
tc_name, bgp_convergence
)
step("After Activating the BGP neighbor , verify default route learned on R2")
@ -2074,8 +2099,13 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
dut="r2",
routes=DEFAULT_ROUTES,
expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
expected= True)
assert result is True, "Testcase {} : Failed \n Error: After Deactivating the BGP neighbor the default route is expected but found in RIB -> {}".format( tc_name, result)
expected=True,
)
assert (
result is True
), "Testcase {} : Failed \n Error: After Deactivating the BGP neighbor the default route is expected but found in RIB -> {}".format(
tc_name, result
)
result = verify_fib_default_route(
tgen,
@ -2083,10 +2113,16 @@ def test_verify_default_originate_after_BGP_attributes_p1(request):
dut="r2",
routes=DEFAULT_ROUTES,
expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
expected= True)
assert result is True, "Testcase {} : Failed \n Error: After Deactivating the BGP neighbor the default route is expected but found in FIB -> {}".format( tc_name, result)
expected=True,
)
assert (
result is True
), "Testcase {} : Failed \n Error: After Deactivating the BGP neighbor the default route is expected but found in FIB -> {}".format(
tc_name, result
)
write_test_footer(tc_name)
if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]
sys.exit(pytest.main(args))

View file

@ -192,6 +192,7 @@ def test_bgp_check_fqdn():
_, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
assert result is None, "FQDN capability disabled, but we still have a hostname"
if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]
sys.exit(pytest.main(args))

View file

@ -179,7 +179,7 @@ def setup_module(mod):
pe.cmd_raises("sysctl -w net.ipv4.tcp_l3mdev_accept={}".format(l3mdev_accept))
# For all registered routers, load the zebra configuration file
for (name, router) in tgen.routers().items():
for name, router in tgen.routers().items():
router.load_config(
TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(name))
)
@ -230,11 +230,11 @@ def evpn_gateway_ip_show_op_check(trigger=" "):
"zebra_vrf_ipv6": "show ipv6 route vrf vrf-blue json",
}
for (name, pe) in tgen.gears.items():
for name, pe in tgen.gears.items():
if name not in PES:
continue
for (cmd_key, command) in show_commands.items():
for cmd_key, command in show_commands.items():
expected_op_file = "{0}/{1}/{2}_{3}.json".format(
CWD, name, cmd_key, trigger
)

View file

@ -124,7 +124,8 @@ def test_rt_extcomm_list_delete():
# check for the deletion of the extended community
test_func = functools.partial(
_bgp_extcomm_list_del_check, r2, "10.10.10.1/32", r"1.1.1.1:1")
_bgp_extcomm_list_del_check, r2, "10.10.10.1/32", r"1.1.1.1:1"
)
_, result = topotest.run_and_expect(test_func, True, count=60, wait=0.5)
assert result, "RT extended community 1.1.1.1:1 was not stripped."
@ -138,7 +139,8 @@ def test_soo_extcomm_list_delete():
# check for the deletion of the extended community
test_func = functools.partial(
_bgp_extcomm_list_del_check, r2, "10.10.10.2/32", r"2.2.2.2:2")
_bgp_extcomm_list_del_check, r2, "10.10.10.2/32", r"2.2.2.2:2"
)
_, result = topotest.run_and_expect(test_func, True, count=60, wait=0.5)
assert result, "SoO extended community 2.2.2.2:2 was not stripped."
@ -152,7 +154,8 @@ def test_nt_extcomm_list_delete():
# check for the deletion of the extended community
test_func = functools.partial(
_bgp_extcomm_list_del_check, r2, "10.10.10.3/32", r"3.3.3.3")
_bgp_extcomm_list_del_check, r2, "10.10.10.3/32", r"3.3.3.3"
)
_, result = topotest.run_and_expect(test_func, True, count=60, wait=0.5)
assert result, "NT extended community 3.3.3.3:0 was not stripped."

View file

@ -83,8 +83,10 @@ def test_bgp_gr_restart_retain_routes():
return topotest.json_cmp(output, expected)
def _bgp_check_kernel_retained_routes():
output = json.loads(r2.cmd("ip -j route show 172.16.255.1/32 proto bgp dev r2-eth0"))
expected = [{"dst":"172.16.255.1","gateway":"192.168.255.1","metric":20}]
output = json.loads(
r2.cmd("ip -j route show 172.16.255.1/32 proto bgp dev r2-eth0")
)
expected = [{"dst": "172.16.255.1", "gateway": "192.168.255.1", "metric": 20}]
return topotest.json_cmp(output, expected)
step("Initial BGP converge")
@ -101,7 +103,9 @@ def test_bgp_gr_restart_retain_routes():
assert result is None, "Failed to see BGP retained routes on R2"
step("Check if routes (Kernel) are retained at R2")
assert _bgp_check_kernel_retained_routes() is None, "Failed to retain BGP routes in kernel on R2"
assert (
_bgp_check_kernel_retained_routes() is None
), "Failed to retain BGP routes in kernel on R2"
if __name__ == "__main__":

View file

@ -7,18 +7,36 @@ luCommand("ce1", 'vtysh -c "show bgp summary"', " 00:0", "wait", "Adjacencies up
luCommand("ce2", 'vtysh -c "show bgp summary"', " 00:0", "wait", "Adjacencies up", 180)
luCommand("ce3", 'vtysh -c "show bgp summary"', " 00:0", "wait", "Adjacencies up", 180)
luCommand(
"r1", 'vtysh -c "show ip route ospf"', "2.2.2.2", "wait", "OSPF Route has Arrived", 60)
"r1",
'vtysh -c "show ip route ospf"',
"2.2.2.2",
"wait",
"OSPF Route has Arrived",
60,
)
luCommand(
"r1", "ping 2.2.2.2 -c 1", " 0. packet loss", "wait", "PE->P2 (loopback) ping", 60
)
luCommand(
"r3", 'vtysh -c "show ip route ospf"', "2.2.2.2", "wait", "OSPF Route has Arrived", 60)
"r3",
'vtysh -c "show ip route ospf"',
"2.2.2.2",
"wait",
"OSPF Route has Arrived",
60,
)
luCommand(
"r3", "ping 2.2.2.2 -c 1", " 0. packet loss", "wait", "PE->P2 (loopback) ping", 60
)
luCommand(
"r4", 'vtysh -c "show ip route ospf"', "2.2.2.2", "wait", "OSPF Route has Arrived", 60)
"r4",
'vtysh -c "show ip route ospf"',
"2.2.2.2",
"wait",
"OSPF Route has Arrived",
60,
)
luCommand(
"r4", "ping 2.2.2.2 -c 1", " 0. packet loss", "wait", "PE->P2 (loopback) ping", 60
)

View file

@ -70,7 +70,7 @@ else:
"See all sharp routes in rib on ce1",
wait,
wait_time=10,
)
)
luCommand(
"ce2",
'vtysh -c "show ip route summ" | grep "sharp" | cut -d " " -f 33',
@ -79,7 +79,7 @@ else:
"See all sharp routes in rib on ce2",
wait,
wait_time=10,
)
)
rtrs = ["ce1", "ce2", "ce3"]
for rtr in rtrs:

View file

@ -137,7 +137,9 @@ def test_bgp_large_comm_list_match_any():
step("BGP filtering check with large-community-list on R3")
test_func = functools.partial(_bgp_converge)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
assert result is None, "Failed to filter BGP UPDATES with large-community-list on R3"
assert (
result is None
), "Failed to filter BGP UPDATES with large-community-list on R3"
if __name__ == "__main__":

View file

@ -35,7 +35,7 @@ from lib.common_config import (
verify_rib,
step,
check_address_types,
check_router_status
check_router_status,
)
from lib.topolog import logger

View file

@ -48,7 +48,7 @@ from lib.common_config import (
verify_rib,
step,
check_address_types,
check_router_status
check_router_status,
)
from lib.topolog import logger
@ -163,7 +163,9 @@ def test_verify_bgp_local_as_agg_in_EBGP_p0(request):
"neighbor": {
neighbor: {
"dest_link": {
"r3": {"local_asn": {"local_as": "1.110"}}
"r3": {
"local_asn": {"local_as": "1.110"}
}
}
}
}
@ -190,7 +192,9 @@ def test_verify_bgp_local_as_agg_in_EBGP_p0(request):
"neighbor": {
neighbor: {
"dest_link": {
dut: {"local_asn": {"remote_as": "1.110"}}
dut: {
"local_asn": {"remote_as": "1.110"}
}
}
}
}

View file

@ -229,7 +229,9 @@ def test_verify_bgp_local_as_in_EBGP_p0(request):
"neighbor": {
neighbor: {
"dest_link": {
"r3": {"local_asn": {"local_as": "1.110"}}
"r3": {
"local_asn": {"local_as": "1.110"}
}
}
}
}
@ -256,7 +258,9 @@ def test_verify_bgp_local_as_in_EBGP_p0(request):
"neighbor": {
neighbor: {
"dest_link": {
dut: {"local_asn": {"remote_as": "1.110"}}
dut: {
"local_asn": {"remote_as": "1.110"}
}
}
}
}
@ -832,7 +836,9 @@ def test_verify_bgp_local_as_GR_EBGP_p0(request):
"neighbor": {
"r2": {
"dest_link": {
"r3": {"local_asn": {"local_as": "1.110"}}
"r3": {
"local_asn": {"local_as": "1.110"}
}
}
}
}
@ -861,7 +867,9 @@ def test_verify_bgp_local_as_GR_EBGP_p0(request):
"neighbor": {
"r4": {
"dest_link": {
"r3": {"local_asn": {"local_as": "1.110"}}
"r3": {
"local_asn": {"local_as": "1.110"}
}
}
}
}
@ -1395,7 +1403,9 @@ def test_verify_bgp_local_as_in_EBGP_aspath_p0(request):
"neighbor": {
neighbor: {
"dest_link": {
"r3": {"local_asn": {"local_as": "1.110"}}
"r3": {
"local_asn": {"local_as": "1.110"}
}
}
}
}
@ -1422,7 +1432,9 @@ def test_verify_bgp_local_as_in_EBGP_aspath_p0(request):
"neighbor": {
neighbor: {
"dest_link": {
dut: {"local_asn": {"remote_as": "1.110"}}
dut: {
"local_asn": {"remote_as": "1.110"}
}
}
}
}
@ -1593,7 +1605,10 @@ def test_verify_bgp_local_as_in_EBGP_aspath_p0(request):
{
"action": "permit",
"set": {
"path": {"as_num": "1.1000 1.1000", "as_action": "prepend"}
"path": {
"as_num": "1.1000 1.1000",
"as_action": "prepend",
}
},
}
]
@ -1778,7 +1793,9 @@ def test_verify_bgp_local_as_in_iBGP_p0(request):
"neighbor": {
"r4": {
"dest_link": {
"r3": {"local_asn": {"local_as": "1.110"}}
"r3": {
"local_asn": {"local_as": "1.110"}
}
}
}
}
@ -2137,7 +2154,9 @@ def test_verify_bgp_local_as_allow_as_in_iBGP_p0(request):
"neighbor": {
"r2": {
"dest_link": {
"r3": {"local_asn": {"local_as": "1.110"}}
"r3": {
"local_asn": {"local_as": "1.110"}
}
}
}
}
@ -2166,7 +2185,9 @@ def test_verify_bgp_local_as_allow_as_in_iBGP_p0(request):
"neighbor": {
"r4": {
"dest_link": {
"r3": {"local_asn": {"local_as": "1.110"}}
"r3": {
"local_asn": {"local_as": "1.110"}
}
}
}
}
@ -2484,7 +2505,9 @@ def test_verify_bgp_local_as_in_EBGP_port_reset_p0(request):
"neighbor": {
neighbor: {
"dest_link": {
"r3": {"local_asn": {"local_as": "1.110"}}
"r3": {
"local_asn": {"local_as": "1.110"}
}
}
}
}
@ -2511,7 +2534,9 @@ def test_verify_bgp_local_as_in_EBGP_port_reset_p0(request):
"neighbor": {
neighbor: {
"dest_link": {
dut: {"local_asn": {"remote_as": "1.110"}}
dut: {
"local_asn": {"remote_as": "1.110"}
}
}
}
}
@ -2824,7 +2849,9 @@ def test_verify_bgp_local_as_in_EBGP_negative2_p0(request):
"neighbor": {
neighbor: {
"dest_link": {
"r3": {"local_asn": {"local_as": "1.110"}}
"r3": {
"local_asn": {"local_as": "1.110"}
}
}
}
}
@ -2851,7 +2878,9 @@ def test_verify_bgp_local_as_in_EBGP_negative2_p0(request):
"neighbor": {
neighbor: {
"dest_link": {
dut: {"local_asn": {"remote_as": "1.110"}}
dut: {
"local_asn": {"remote_as": "1.110"}
}
}
}
}
@ -3164,7 +3193,9 @@ def test_verify_bgp_local_as_in_EBGP_negative3_p0(request):
"neighbor": {
neighbor: {
"dest_link": {
"r3": {"local_asn": {"local_as": "1.110"}}
"r3": {
"local_asn": {"local_as": "1.110"}
}
}
}
}
@ -3191,7 +3222,9 @@ def test_verify_bgp_local_as_in_EBGP_negative3_p0(request):
"neighbor": {
neighbor: {
"dest_link": {
dut: {"local_asn": {"remote_as": "1.110"}}
dut: {
"local_asn": {"remote_as": "1.110"}
}
}
}
}
@ -3354,7 +3387,9 @@ def test_verify_bgp_local_as_in_EBGP_restart_daemons_p0(request):
"neighbor": {
neighbor: {
"dest_link": {
"r3": {"local_asn": {"local_as": "1.110"}}
"r3": {
"local_asn": {"local_as": "1.110"}
}
}
}
}
@ -3381,7 +3416,9 @@ def test_verify_bgp_local_as_in_EBGP_restart_daemons_p0(request):
"neighbor": {
neighbor: {
"dest_link": {
dut: {"local_asn": {"remote_as": "1.110"}}
dut: {
"local_asn": {"remote_as": "1.110"}
}
}
}
}

View file

@ -78,6 +78,7 @@ pytestmark = [pytest.mark.bgpd, pytest.mark.staticd]
# Address read from env variables
ADDR_TYPES = check_address_types()
####
def setup_module(mod):
"""

View file

@ -49,7 +49,11 @@ def setup_module(mod):
for routern in range(1, 4):
tgen.gears["r{}".format(routern)].cmd("ip link add vrf1 type vrf table 10")
tgen.gears["r{}".format(routern)].cmd("ip link set vrf1 up")
tgen.gears["r{}".format(routern)].cmd("ip address add dev vrf1 {}.{}.{}.{}/32".format(routern, routern, routern,routern))
tgen.gears["r{}".format(routern)].cmd(
"ip address add dev vrf1 {}.{}.{}.{}/32".format(
routern, routern, routern, routern
)
)
tgen.gears["r2"].cmd("ip address add dev vrf1 192.0.2.8/32")
tgen.gears["r3"].cmd("ip address add dev vrf1 192.0.2.8/32")
@ -74,6 +78,7 @@ def teardown_module(mod):
tgen = get_topogen()
tgen.stop_topology()
def test_bgp_path_selection_ecmp():
tgen = get_topogen()
@ -97,7 +102,7 @@ def test_bgp_path_selection_ecmp():
"aspath": {"string": "65002"},
"multipath": True,
"nexthops": [{"ip": "192.0.2.3", "metric": 20}],
}
},
]
}
@ -117,7 +122,9 @@ def test_bgp_path_selection_vpn_ecmp():
def _bgp_check_path_selection_vpn_ecmp():
output = json.loads(
tgen.gears["r1"].vtysh_cmd("show bgp vrf vrf1 ipv4 unicast 192.0.2.8/32 json")
tgen.gears["r1"].vtysh_cmd(
"show bgp vrf vrf1 ipv4 unicast 192.0.2.8/32 json"
)
)
expected = {
"paths": [
@ -132,7 +139,7 @@ def test_bgp_path_selection_vpn_ecmp():
"aspath": {"string": "65002"},
"multipath": True,
"nexthops": [{"ip": "192.0.2.3", "metric": 20}],
}
},
]
}
@ -160,13 +167,13 @@ def test_bgp_path_selection_metric():
"valid": True,
"aspath": {"string": "65002"},
"nexthops": [{"ip": "192.0.2.2", "metric": 10}],
"bestpath":{ "selectionReason":"IGP Metric"},
"bestpath": {"selectionReason": "IGP Metric"},
},
{
"valid": True,
"aspath": {"string": "65002"},
"nexthops": [{"ip": "192.0.2.3", "metric": 20}],
}
},
]
}
@ -189,7 +196,9 @@ def test_bgp_path_selection_vpn_metric():
def _bgp_check_path_selection_vpn_metric():
output = json.loads(
tgen.gears["r1"].vtysh_cmd("show bgp vrf vrf1 ipv4 unicast 192.0.2.8/32 json")
tgen.gears["r1"].vtysh_cmd(
"show bgp vrf vrf1 ipv4 unicast 192.0.2.8/32 json"
)
)
expected = {
"paths": [
@ -197,13 +206,13 @@ def test_bgp_path_selection_vpn_metric():
"valid": True,
"aspath": {"string": "65002"},
"nexthops": [{"ip": "192.0.2.2", "metric": 10}],
"bestpath":{ "selectionReason":"IGP Metric"},
"bestpath": {"selectionReason": "IGP Metric"},
},
{
"valid": True,
"aspath": {"string": "65002"},
"nexthops": [{"ip": "192.0.2.3", "metric": 20}],
}
},
]
}

View file

@ -815,7 +815,11 @@ def test_route_summarisation_with_as_set_p1(request):
)
for addr_type in ADDR_TYPES:
for pfx, seq_id, network, in zip(
for (
pfx,
seq_id,
network,
) in zip(
[1, 2, 3, 4, 5],
[10, 20, 30, 40, 50],
[NETWORK_1_1, NETWORK_1_2, NETWORK_1_3, NETWORK_1_4, NETWORK_1_5],

View file

@ -37,10 +37,12 @@ def setup_module(mod):
tgen.start_topology()
for rname, router in tgen.routers().items():
router.load_config(TopoRouter.RD_ZEBRA,
os.path.join(CWD, '{}/zebra.conf'.format(rname)))
router.load_config(TopoRouter.RD_BGP,
os.path.join(CWD, '{}/bgpd.conf'.format(rname)))
router.load_config(
TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
)
router.load_config(
TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
)
tgen.gears["pe1"].run("ip link add vrf10 type vrf table 10")
tgen.gears["pe1"].run("ip link set vrf10 up")
@ -62,7 +64,7 @@ def open_json_file(path):
return json.load(f)
except IOError:
assert False, "Could not read file {}".format(path)
def check(name, command, checker):
tgen = get_topogen()
@ -80,25 +82,25 @@ def check(name, command, checker):
def check_vrf10_bgp_rib(output):
expected = open_json_file("%s/pe1/results/vrf10_ipv4_unicast.json" % CWD)
expected = open_json_file("%s/pe1/results/vrf10_ipv4_unicast.json" % CWD)
actual = json.loads(output)
return topotest.json_cmp(actual, expected)
def check_default_bgp_vpn_rib(output):
expected = open_json_file("%s/pe1/results/default_ipv4_vpn.json" % CWD)
expected = open_json_file("%s/pe1/results/default_ipv4_vpn.json" % CWD)
actual = json.loads(output)
return topotest.json_cmp(actual, expected)
def check_vrf20_bgp_rib(output):
expected = open_json_file("%s/pe1/results/vrf20_ipv4_unicast.json" % CWD)
expected = open_json_file("%s/pe1/results/vrf20_ipv4_unicast.json" % CWD)
actual = json.loads(output)
return topotest.json_cmp(actual, expected)
def check_vrf20_rib(output):
expected = open_json_file("%s/pe1/results/vrf20_ipv4.json" % CWD)
expected = open_json_file("%s/pe1/results/vrf20_ipv4.json" % CWD)
actual = json.loads(output)
return topotest.json_cmp(actual, expected)

View file

@ -217,6 +217,7 @@ def test_bgp_allow_as_in():
assertmsg = '"r2" 192.168.1.1/32 route should be gone'
assert result is None, assertmsg
def test_local_vs_non_local():
tgen = get_topogen()
@ -229,7 +230,7 @@ def test_local_vs_non_local():
paths = output["paths"]
for i in range(len(paths)):
if "fibPending" in paths[i]:
assert(False), "Route 60.0.0.0/24 should not have fibPending"
assert False, "Route 60.0.0.0/24 should not have fibPending"
if __name__ == "__main__":

View file

@ -46,7 +46,7 @@ from lib.bgp import (
verify_bgp_rib,
verify_bgp_timers_and_functionality,
verify_router_id,
verify_tcp_mss
verify_tcp_mss,
)
from lib.common_config import (
kill_router_daemons,
@ -66,7 +66,7 @@ from lib.common_config import (
verify_fib_routes,
verify_rib,
write_test_footer,
write_test_header
write_test_header,
)
# Global variables
@ -84,7 +84,8 @@ NETWORK5_2 = {"ipv4": "5.1.1.2/32", "ipv6": "5::2/128"}
NEXT_HOP_IP = {"ipv4": "Null0", "ipv6": "Null0"}
## File name
TCPDUMP_FILE="test_tcp_packet_test.txt"
TCPDUMP_FILE = "test_tcp_packet_test.txt"
def setup_module(mod):
"""
@ -92,7 +93,7 @@ def setup_module(mod):
* `mod`: module name
"""
global topo,TCPDUMP_FILE
global topo, TCPDUMP_FILE
# Required linux kernel version for this suite to run.
result = required_linux_kernel_version("4.15")
@ -127,6 +128,7 @@ def setup_module(mod):
step("Running setup_module() done")
def teardown_module():
"""Teardown the pytest environment"""
@ -137,9 +139,7 @@ def teardown_module():
# Stop toplogy and Remove tmp files
tgen.stop_topology()
step(
"Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
)
step("Testsuite end time: {}".format(time.asctime(time.localtime(time.time()))))
step("=" * 40)
@ -149,6 +149,7 @@ def teardown_module():
#
#####################################################
def test_bgp_vrf_tcp_mss(request):
tgen = get_topogen()
tc_name = request.node.name
@ -279,34 +280,34 @@ def test_bgp_vrf_tcp_mss(request):
step("Verify the static Routes in R2 on RED VRF")
for addr_type in ADDR_TYPES:
static_routes_input = {
"r3": {
"static_routes": [
{
"network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
"next_hop": NEXT_HOP_IP[addr_type],
"vrf": "RED",
},
{
"network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
"next_hop": NEXT_HOP_IP[addr_type],
"vrf": "RED",
},
{
"network": [NETWORK3_1[addr_type]] + [NETWORK3_2[addr_type]],
"next_hop": NEXT_HOP_IP[addr_type],
"vrf": "RED",
},
{
"network": [NETWORK4_1[addr_type]] + [NETWORK4_2[addr_type]],
"next_hop": NEXT_HOP_IP[addr_type],
"vrf": "RED",
},
{
"network": [NETWORK5_1[addr_type]] + [NETWORK5_2[addr_type]],
"next_hop": NEXT_HOP_IP[addr_type],
"vrf": "RED",
},
]
"r3": {
"static_routes": [
{
"network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
"next_hop": NEXT_HOP_IP[addr_type],
"vrf": "RED",
},
{
"network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
"next_hop": NEXT_HOP_IP[addr_type],
"vrf": "RED",
},
{
"network": [NETWORK3_1[addr_type]] + [NETWORK3_2[addr_type]],
"next_hop": NEXT_HOP_IP[addr_type],
"vrf": "RED",
},
{
"network": [NETWORK4_1[addr_type]] + [NETWORK4_2[addr_type]],
"next_hop": NEXT_HOP_IP[addr_type],
"vrf": "RED",
},
{
"network": [NETWORK5_1[addr_type]] + [NETWORK5_2[addr_type]],
"next_hop": NEXT_HOP_IP[addr_type],
"vrf": "RED",
},
]
}
}
dut = "r2"
@ -316,34 +317,34 @@ def test_bgp_vrf_tcp_mss(request):
step("Verify the static Routes in R1 on RED VRF")
for addr_type in ADDR_TYPES:
static_routes_input = {
"r3": {
"static_routes": [
{
"network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
"next_hop": NEXT_HOP_IP[addr_type],
"vrf": "RED",
},
{
"network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
"next_hop": NEXT_HOP_IP[addr_type],
"vrf": "RED",
},
{
"network": [NETWORK3_1[addr_type]] + [NETWORK3_2[addr_type]],
"next_hop": NEXT_HOP_IP[addr_type],
"vrf": "RED",
},
{
"network": [NETWORK4_1[addr_type]] + [NETWORK4_2[addr_type]],
"next_hop": NEXT_HOP_IP[addr_type],
"vrf": "RED",
},
{
"network": [NETWORK5_1[addr_type]] + [NETWORK5_2[addr_type]],
"next_hop": NEXT_HOP_IP[addr_type],
"vrf": "RED",
},
]
"r3": {
"static_routes": [
{
"network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
"next_hop": NEXT_HOP_IP[addr_type],
"vrf": "RED",
},
{
"network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
"next_hop": NEXT_HOP_IP[addr_type],
"vrf": "RED",
},
{
"network": [NETWORK3_1[addr_type]] + [NETWORK3_2[addr_type]],
"next_hop": NEXT_HOP_IP[addr_type],
"vrf": "RED",
},
{
"network": [NETWORK4_1[addr_type]] + [NETWORK4_2[addr_type]],
"next_hop": NEXT_HOP_IP[addr_type],
"vrf": "RED",
},
{
"network": [NETWORK5_1[addr_type]] + [NETWORK5_2[addr_type]],
"next_hop": NEXT_HOP_IP[addr_type],
"vrf": "RED",
},
]
}
}
dut = "r1"
@ -403,9 +404,6 @@ def test_bgp_vrf_tcp_mss(request):
tcp_mss_result
)
step("Enabling tcp-mss 500 between R2 and R3 of VRF Default")
TCP_MSS = 500
raw_config = {
@ -439,8 +437,6 @@ def test_bgp_vrf_tcp_mss(request):
result = apply_raw_config(tgen, raw_config)
assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
step("Clear BGP at router R2 and R3")
for addr_type in ADDR_TYPES:
clear_bgp(tgen, topo, "r2", addr_type)
@ -549,7 +545,6 @@ def test_bgp_vrf_tcp_mss(request):
tcp_mss_result is not True
), " TCP-MSS mismatch :Failed \n Error: {}".format(tcp_mss_result)
step("Removing tcp-mss 500 between R2 and R3 of VRF Default ")
TCP_MSS = 500
raw_config = {

View file

@ -52,30 +52,32 @@ def build_topo(tgen):
switch = tgen.add_switch("s3")
switch.add_link(tgen.gears["r2"])
def _populate_iface():
tgen = get_topogen()
cmds_list = [
'ip link add vrf1 type vrf table 10',
'echo 10 > /proc/sys/net/mpls/platform_labels',
'ip link set dev vrf1 up',
'ip link set dev {0}-eth1 master vrf1',
'echo 1 > /proc/sys/net/mpls/conf/{0}-eth0/input',
'ip tunnel add {0}-gre0 mode gre ttl 64 dev {0}-eth0 local 10.125.0.{1} remote 10.125.0.{2}',
'ip link set dev {0}-gre0 up',
'echo 1 > /proc/sys/net/mpls/conf/{0}-gre0/input',
"ip link add vrf1 type vrf table 10",
"echo 10 > /proc/sys/net/mpls/platform_labels",
"ip link set dev vrf1 up",
"ip link set dev {0}-eth1 master vrf1",
"echo 1 > /proc/sys/net/mpls/conf/{0}-eth0/input",
"ip tunnel add {0}-gre0 mode gre ttl 64 dev {0}-eth0 local 10.125.0.{1} remote 10.125.0.{2}",
"ip link set dev {0}-gre0 up",
"echo 1 > /proc/sys/net/mpls/conf/{0}-gre0/input",
]
for cmd in cmds_list:
input = cmd.format('r1', '1', '2')
logger.info('input: ' + cmd)
output = tgen.net['r1'].cmd(cmd.format('r1', '1', '2'))
logger.info('output: ' + output)
input = cmd.format("r1", "1", "2")
logger.info("input: " + cmd)
output = tgen.net["r1"].cmd(cmd.format("r1", "1", "2"))
logger.info("output: " + output)
for cmd in cmds_list:
input = cmd.format('r2', '2', '1')
logger.info('input: ' + cmd)
output = tgen.net['r2'].cmd(cmd.format('r2', '2', '1'))
logger.info('output: ' + output)
input = cmd.format("r2", "2", "1")
logger.info("input: " + cmd)
output = tgen.net["r2"].cmd(cmd.format("r2", "2", "1"))
logger.info("output: " + output)
def setup_module(mod):
"Sets up the pytest environment"
@ -113,13 +115,13 @@ def test_protocols_convergence():
if tgen.routers_have_failure():
pytest.skip(tgen.errors)
router = tgen.gears['r1']
router = tgen.gears["r1"]
logger.info("Dump some context for r1")
router.vtysh_cmd("show bgp ipv4 vpn")
router.vtysh_cmd("show bgp summary")
router.vtysh_cmd("show bgp vrf vrf1 ipv4")
router.vtysh_cmd("show running-config")
router = tgen.gears['r2']
router = tgen.gears["r2"]
logger.info("Dump some context for r2")
router.vtysh_cmd("show bgp ipv4 vpn")
router.vtysh_cmd("show bgp summary")
@ -128,11 +130,11 @@ def test_protocols_convergence():
# Check IPv4 routing tables on r1
logger.info("Checking IPv4 routes for convergence on r1")
router = tgen.gears['r1']
router = tgen.gears["r1"]
json_file = "{}/{}/ipv4_routes.json".format(CWD, router.name)
if not os.path.isfile(json_file):
logger.info("skipping file {}".format(json_file))
assert 0, 'ipv4_routes.json file not found'
assert 0, "ipv4_routes.json file not found"
return
expected = json.loads(open(json_file).read())
@ -148,10 +150,10 @@ def test_protocols_convergence():
# Check BGP IPv4 routing tables on r2 not installed
logger.info("Checking BGP IPv4 routes for convergence on r2")
router = tgen.gears['r2']
router = tgen.gears["r2"]
json_file = "{}/{}/bgp_ipv4_routes.json".format(CWD, router.name)
if not os.path.isfile(json_file):
assert 0, 'bgp_ipv4_routes.json file not found'
assert 0, "bgp_ipv4_routes.json file not found"
expected = json.loads(open(json_file).read())
test_func = partial(
@ -163,7 +165,8 @@ def test_protocols_convergence():
_, result = topotest.run_and_expect(test_func, None, count=40, wait=2)
assertmsg = '"{}" JSON output mismatches'.format(router.name)
assert result is None, assertmsg
def test_memory_leak():
"Run the memory leak test and report results."
tgen = get_topogen()

View file

@ -851,23 +851,25 @@ def test_dynamic_imported_matching_prefix_based_on_community_list_p0(request):
result = verify_bgp_rib(
tgen, addr_type, "r3", static_routes, expected=False
)
assert (
result is not True
), "Testcase {} : Failed \nError {}\n" "Routes {} still in BGP table".format(
tc_name,
result,
static_routes["r3"]["static_routes"][0]["network"],
assert result is not True, (
"Testcase {} : Failed \nError {}\n"
"Routes {} still in BGP table".format(
tc_name,
result,
static_routes["r3"]["static_routes"][0]["network"],
)
)
result = verify_rib(
tgen, addr_type, "r3", static_routes, expected=False
)
assert (
result is not True
), "Testcase {} : Failed Error {}" "Routes {} still in Route table".format(
tc_name,
result,
static_routes["r3"]["static_routes"][0]["network"],
assert result is not True, (
"Testcase {} : Failed Error {}"
"Routes {} still in Route table".format(
tc_name,
result,
static_routes["r3"]["static_routes"][0]["network"],
)
)
else:
result = verify_bgp_rib(tgen, addr_type, "r3", static_routes)
@ -924,23 +926,25 @@ def test_dynamic_imported_matching_prefix_based_on_community_list_p0(request):
result = verify_bgp_rib(
tgen, addr_type, "r3", static_routes, expected=False
)
assert (
result is not True
), "Testcase {} : Failed \nError {}\n" "Routes {} still in BGP table".format(
tc_name,
result,
static_routes["r3"]["static_routes"][0]["network"],
assert result is not True, (
"Testcase {} : Failed \nError {}\n"
"Routes {} still in BGP table".format(
tc_name,
result,
static_routes["r3"]["static_routes"][0]["network"],
)
)
result = verify_rib(
tgen, addr_type, "r3", static_routes, expected=False
)
assert (
result is not True
), "Testcase {} : Failed Error {}" "Routes {} still in Route table".format(
tc_name,
result,
static_routes["r3"]["static_routes"][0]["network"],
assert result is not True, (
"Testcase {} : Failed Error {}"
"Routes {} still in Route table".format(
tc_name,
result,
static_routes["r3"]["static_routes"][0]["network"],
)
)
else:
result = verify_bgp_rib(tgen, addr_type, "r3", static_routes)
@ -1153,23 +1157,25 @@ def test_dynamic_import_routes_delete_static_route_p1(request):
result = verify_bgp_rib(
tgen, addr_type, "r2", static_routes, expected=False
)
assert (
result is not True
), "Testcase {} : Failed \nError {}\n" "Routes {} still in BGP table".format(
tc_name,
result,
static_routes["r2"]["static_routes"][0]["network"],
assert result is not True, (
"Testcase {} : Failed \nError {}\n"
"Routes {} still in BGP table".format(
tc_name,
result,
static_routes["r2"]["static_routes"][0]["network"],
)
)
result = verify_rib(
tgen, addr_type, "r2", static_routes, expected=False
)
assert (
result is not True
), "Testcase {} : Failed Error {}" "Routes {} still in Route table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
assert result is not True, (
"Testcase {} : Failed Error {}"
"Routes {} still in Route table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
)
)
step("Delete static routes from vrf BLUE")
@ -1209,21 +1215,23 @@ def test_dynamic_import_routes_delete_static_route_p1(request):
result = verify_bgp_rib(
tgen, addr_type, dut, static_routes, expected=False
)
assert (
result is not True
), "Testcase {} : Failed \nError {}\n" "Routes {} still in BGP table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
assert result is not True, (
"Testcase {} : Failed \nError {}\n"
"Routes {} still in BGP table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
)
)
result = verify_rib(tgen, addr_type, dut, static_routes, expected=False)
assert (
result is not True
), "Testcase {} : Failed Error {}" "Routes {} still in Route table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
assert result is not True, (
"Testcase {} : Failed Error {}"
"Routes {} still in Route table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
)
)
step("Delete static routes from vrf default")

View file

@ -357,23 +357,25 @@ def test_dynamic_import_recursive_import_tenant_vrf_p1(request):
result = verify_bgp_rib(
tgen, addr_type, "r4", static_routes, expected=False
)
assert (
result is not True
), "Testcase {} : Failed \nError {}\n" "Routes {} still in BGP table".format(
tc_name,
result,
static_routes["r4"]["static_routes"][0]["network"],
assert result is not True, (
"Testcase {} : Failed \nError {}\n"
"Routes {} still in BGP table".format(
tc_name,
result,
static_routes["r4"]["static_routes"][0]["network"],
)
)
result = verify_rib(
tgen, addr_type, "r4", static_routes, expected=False
)
assert (
result is not True
), "Testcase {} : Failed Error {}" "Routes {} still in Route table".format(
tc_name,
result,
static_routes["r4"]["static_routes"][0]["network"],
assert result is not True, (
"Testcase {} : Failed Error {}"
"Routes {} still in Route table".format(
tc_name,
result,
static_routes["r4"]["static_routes"][0]["network"],
)
)
else:
result = verify_bgp_rib(tgen, addr_type, "r4", static_routes)

View file

@ -495,23 +495,25 @@ def test_dynamic_import_routes_between_two_tenant_vrf_p0(request):
result = verify_bgp_rib(
tgen, addr_type, dut, static_routes, expected=False
)
assert (
result is not True
), "Testcase {} : Failed \nError {}\n" "Routes {} still in BGP table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
assert result is not True, (
"Testcase {} : Failed \nError {}\n"
"Routes {} still in BGP table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
)
)
result = verify_rib(
tgen, addr_type, dut, static_routes, expected=False
)
assert (
result is not True
), "Testcase {} : Failed \nError {}\n" "Routes {} still in Route table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
assert result is not True, (
"Testcase {} : Failed \nError {}\n"
"Routes {} still in Route table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
)
)
else:
result = verify_bgp_rib(tgen, addr_type, dut, static_routes)
@ -882,23 +884,25 @@ def test_dynamic_import_routes_between_two_tenant_vrf_p0(request):
result = verify_bgp_rib(
tgen, addr_type, dut, static_routes, expected=False
)
assert (
result is not True
), "Testcase {} : Failed \nError {}\n" "Routes {} still in BGP table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
assert result is not True, (
"Testcase {} : Failed \nError {}\n"
"Routes {} still in BGP table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
)
)
result = verify_rib(
tgen, addr_type, dut, static_routes, expected=False
)
assert (
result is not True
), "Testcase {} : Failed Error {}" "Routes {} still in Route table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
assert result is not True, (
"Testcase {} : Failed Error {}"
"Routes {} still in Route table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
)
)
else:
result = verify_bgp_rib(tgen, addr_type, dut, static_routes)

View file

@ -356,23 +356,25 @@ def test_dynamic_import_routes_between_tenant_to_default_vrf_p0(request):
result = verify_bgp_rib(
tgen, addr_type, dut, static_routes, expected=False
)
assert (
result is not True
), "Testcase {} : Failed \nError {}\n" "Routes {} still in BGP table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
assert result is not True, (
"Testcase {} : Failed \nError {}\n"
"Routes {} still in BGP table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
)
)
result = verify_rib(
tgen, addr_type, dut, static_routes, expected=False
)
assert (
result is not True
), "Testcase {} : Failed \nError {}\n" "Routes {} still in BGP table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
assert result is not True, (
"Testcase {} : Failed \nError {}\n"
"Routes {} still in BGP table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
)
)
else:
result = verify_bgp_rib(tgen, addr_type, dut, static_routes)
@ -503,23 +505,25 @@ def test_dynamic_import_routes_between_tenant_to_default_vrf_p0(request):
result = verify_bgp_rib(
tgen, addr_type, dut, static_routes, expected=False
)
assert (
result is not True
), "Testcase {} : Failed \nError {}\n" "Routes {} still in BGP table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
assert result is not True, (
"Testcase {} : Failed \nError {}\n"
"Routes {} still in BGP table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
)
)
result = verify_rib(
tgen, addr_type, dut, static_routes, expected=False
)
assert (
result is not True
), "Testcase {} : Failed Error {}" "Routes {} still in Route table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
assert result is not True, (
"Testcase {} : Failed Error {}"
"Routes {} still in Route table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
)
)
else:
result = verify_bgp_rib(tgen, addr_type, dut, static_routes)
@ -882,23 +886,25 @@ def test_dynamic_import_routes_between_tenant_to_default_vrf_p0(request):
result = verify_bgp_rib(
tgen, addr_type, dut, static_routes, expected=False
)
assert (
result is not True
), "Testcase {} : Failed \nError {}\n" "Routes {} still in BGP table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
assert result is not True, (
"Testcase {} : Failed \nError {}\n"
"Routes {} still in BGP table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
)
)
result = verify_rib(
tgen, addr_type, dut, static_routes, expected=False
)
assert (
result is not True
), "Testcase {} : Failed Error {}" "Routes {} still in Route table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
assert result is not True, (
"Testcase {} : Failed Error {}"
"Routes {} still in Route table".format(
tc_name,
result,
static_routes[dut]["static_routes"][0]["network"],
)
)
else:
result = verify_bgp_rib(tgen, addr_type, dut, static_routes)

View file

@ -37,10 +37,12 @@ def setup_module(mod):
tgen.start_topology()
for rname, router in tgen.routers().items():
router.load_config(TopoRouter.RD_ZEBRA,
os.path.join(CWD, '{}/zebra.conf'.format(rname)))
router.load_config(TopoRouter.RD_BGP,
os.path.join(CWD, '{}/bgpd.conf'.format(rname)))
router.load_config(
TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
)
router.load_config(
TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
)
tgen.gears["pe1"].run("ip link add vrf10 type vrf table 10")
tgen.gears["pe1"].run("ip link set vrf10 up")
@ -62,22 +64,22 @@ def open_json_file(path):
return json.load(f)
except IOError:
assert False, "Could not read file {}".format(path)
def check_vrf10_rib(output):
expected = open_json_file("%s/pe1/results/vrf10_ipv4_unicast.json" % CWD)
expected = open_json_file("%s/pe1/results/vrf10_ipv4_unicast.json" % CWD)
actual = json.loads(output)
return topotest.json_cmp(actual, expected)
def check_default_vpn_rib(output):
expected = open_json_file("%s/pe1/results/default_ipv4_vpn.json" % CWD)
expected = open_json_file("%s/pe1/results/default_ipv4_vpn.json" % CWD)
actual = json.loads(output)
return topotest.json_cmp(actual, expected)
def check_vrf20_rib(output):
expected = open_json_file("%s/pe1/results/vrf20_ipv4_unicast.json" % CWD)
expected = open_json_file("%s/pe1/results/vrf20_ipv4_unicast.json" % CWD)
actual = json.loads(output)
return topotest.json_cmp(actual, expected)

View file

@ -43,7 +43,7 @@ from lib.common_config import (
step,
create_static_routes,
check_router_status,
apply_raw_config
apply_raw_config,
)
from lib.topolog import logger
@ -51,7 +51,7 @@ from lib.bgp import (
verify_bgp_convergence,
create_router_bgp,
verify_bgp_rib,
verify_bgp_bestpath
verify_bgp_bestpath,
)
from lib.topojson import build_config_from_json
@ -84,10 +84,8 @@ VRF_LIST = ["RED", "BLUE", "GREEN"]
COMM_VAL_1 = "100:100"
COMM_VAL_2 = "500:500"
COMM_VAL_3 = "600:600"
BESTPATH = {
"ipv4": "0.0.0.0",
"ipv6": "::"
}
BESTPATH = {"ipv4": "0.0.0.0", "ipv6": "::"}
def setup_module(mod):
"""
@ -158,6 +156,7 @@ def teardown_module():
#
#####################################################
def test_dynamic_import_ecmp_imported_routed_diffrent_vrfs_p0(request):
"""
Verify ECMP for imported routes from different VRFs.
@ -170,136 +169,130 @@ def test_dynamic_import_ecmp_imported_routed_diffrent_vrfs_p0(request):
check_router_status(tgen)
reset_config_on_routers(tgen)
step("Configure same static routes in tenant vrfs RED and GREEN on router "
"R3 and redistribute in respective BGP process")
step(
"Configure same static routes in tenant vrfs RED and GREEN on router "
"R3 and redistribute in respective BGP process"
)
for vrf_name in ["RED", "GREEN"]:
for addr_type in ADDR_TYPES:
if vrf_name == "GREEN":
next_hop_vrf = topo["routers"]["r1"]["links"][
"r3-link3"][addr_type].split("/")[0]
next_hop_vrf = topo["routers"]["r1"]["links"]["r3-link3"][
addr_type
].split("/")[0]
else:
next_hop_vrf = topo["routers"]["r2"]["links"][
"r3-link1"][addr_type].split("/")[0]
next_hop_vrf = topo["routers"]["r2"]["links"]["r3-link1"][
addr_type
].split("/")[0]
static_routes = {
"r3": {
"static_routes": [
{
"network": [NETWORK1_1[addr_type]],
"next_hop": next_hop_vrf,
"vrf": vrf_name
"vrf": vrf_name,
}
]
}
}
result = create_static_routes(tgen, static_routes)
assert result is True, "Testcase {} :Failed \n Error: {}". \
format(tc_name, result)
assert result is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, result
)
step("Redistribute static route on BGP VRF : {}".format(vrf_name))
temp = {}
for addr_type in ADDR_TYPES:
temp.update({
addr_type: {
"unicast": {
"redistribute": [{
"redist_type": "static"
}]
}
}
})
temp.update(
{addr_type: {"unicast": {"redistribute": [{"redist_type": "static"}]}}}
)
redist_dict = {"r3": {"bgp": [{
"vrf": vrf_name, "local_as": 3, "address_family": temp
}]}}
redist_dict = {
"r3": {"bgp": [{"vrf": vrf_name, "local_as": 3, "address_family": temp}]}
}
result = create_router_bgp(tgen, topo, redist_dict)
assert result is True, "Testcase {} :Failed \n Error: {}". \
format(tc_name, result)
assert result is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, result
)
step("Verify that configured static routes are installed in respective "
"BGP table for vrf RED & GREEN")
step(
"Verify that configured static routes are installed in respective "
"BGP table for vrf RED & GREEN"
)
for vrf_name in ["RED", "GREEN"]:
for addr_type in ADDR_TYPES:
if vrf_name == "GREEN":
next_hop_vrf = topo["routers"]["r1"]["links"][
"r3-link3"][addr_type].split("/")[0]
next_hop_vrf = topo["routers"]["r1"]["links"]["r3-link3"][
addr_type
].split("/")[0]
else:
next_hop_vrf = topo["routers"]["r2"]["links"][
"r3-link1"][addr_type].split("/")[0]
next_hop_vrf = topo["routers"]["r2"]["links"]["r3-link1"][
addr_type
].split("/")[0]
static_routes = {
"r3": {
"static_routes": [
{
"network": [NETWORK1_1[addr_type]],
"vrf": vrf_name
}
{"network": [NETWORK1_1[addr_type]], "vrf": vrf_name}
]
}
}
result = verify_bgp_rib(tgen, addr_type, "r3", static_routes,
next_hop=next_hop_vrf)
assert result is True, "Testcase {} : Failed \n Error {}". \
format(tc_name, result)
result = verify_bgp_rib(
tgen, addr_type, "r3", static_routes, next_hop=next_hop_vrf
)
assert result is True, "Testcase {} : Failed \n Error {}".format(
tc_name, result
)
result = verify_rib(tgen, addr_type, "r3", static_routes,
next_hop=next_hop_vrf)
assert result is True, "Testcase {} : Failed \n Error {}". \
format(tc_name, result)
result = verify_rib(
tgen, addr_type, "r3", static_routes, next_hop=next_hop_vrf
)
assert result is True, "Testcase {} : Failed \n Error {}".format(
tc_name, result
)
step("Import vrf RED and GREEN into default vrf and Configure ECMP")
bgp_val = []
for vrf_name in ["RED", "GREEN"]:
temp = {}
for addr_type in ADDR_TYPES:
temp.update({
addr_type: {
"unicast": {
"import": {
"vrf": vrf_name
},
"maximum_paths": {
"ebgp": 2
temp.update(
{
addr_type: {
"unicast": {
"import": {"vrf": vrf_name},
"maximum_paths": {"ebgp": 2},
}
}
}
})
)
bgp_val.append({
"local_as": 3, "address_family": temp
})
bgp_val.append({"local_as": 3, "address_family": temp})
import_dict = {"r3": {"bgp": bgp_val}}
result = create_router_bgp(tgen, topo, import_dict)
assert result is True, "Testcase {} :Failed \n Error: {}". \
format(tc_name, result)
assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
step("Configure bgp bestpath on router r3")
r3_raw_config = {
"r3": {
"raw_config": [
"router bgp 3",
"bgp bestpath as-path multipath-relax"
]
}
"r3": {"raw_config": ["router bgp 3", "bgp bestpath as-path multipath-relax"]}
}
result = apply_raw_config(tgen, r3_raw_config)
assert result is True, "Testcase {} :Failed \n Error: {}". \
format(tc_name, result)
assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
step("Verify that routes are imported with two different next-hop vrfs "
"and IPs. Additionally R3 must do ECMP for both the routes.")
step(
"Verify that routes are imported with two different next-hop vrfs "
"and IPs. Additionally R3 must do ECMP for both the routes."
)
for addr_type in ADDR_TYPES:
next_hop_vrf = [
topo["routers"]["r2"]["links"]["r3-link1"][addr_type]. \
split("/")[0],
topo["routers"]["r1"]["links"]["r3-link3"][addr_type]. \
split("/")[0]
]
topo["routers"]["r2"]["links"]["r3-link1"][addr_type].split("/")[0],
topo["routers"]["r1"]["links"]["r3-link3"][addr_type].split("/")[0],
]
static_routes = {
"r3": {
"static_routes": [
@ -310,54 +303,61 @@ def test_dynamic_import_ecmp_imported_routed_diffrent_vrfs_p0(request):
}
}
result = verify_bgp_rib(tgen, addr_type, "r3", static_routes,
next_hop=next_hop_vrf)
assert result is True, "Testcase {} : Failed \n Error {}". \
format(tc_name, result)
result = verify_bgp_rib(
tgen, addr_type, "r3", static_routes, next_hop=next_hop_vrf
)
assert result is True, "Testcase {} : Failed \n Error {}".format(
tc_name, result
)
result = verify_rib(tgen, addr_type, "r3", static_routes,
next_hop=next_hop_vrf)
assert result is True, "Testcase {} : Failed \n Error {}". \
format(tc_name, result)
result = verify_rib(tgen, addr_type, "r3", static_routes, next_hop=next_hop_vrf)
assert result is True, "Testcase {} : Failed \n Error {}".format(
tc_name, result
)
step("Now change the next-hop of static routes in vrf RED and GREEN to "
"same IP address")
step(
"Now change the next-hop of static routes in vrf RED and GREEN to "
"same IP address"
)
for addr_type in ADDR_TYPES:
next_hop_vrf = topo["routers"]["r1"]["links"][
"r3-link3"][addr_type].split("/")[0]
next_hop_vrf = topo["routers"]["r1"]["links"]["r3-link3"][addr_type].split("/")[
0
]
static_routes = {
"r3": {
"static_routes": [
{
"network": [NETWORK1_1[addr_type]],
"next_hop": next_hop_vrf,
"vrf": "RED"
"vrf": "RED",
},
{
"network": [NETWORK1_1[addr_type]],
"next_hop": topo["routers"]["r2"]["links"][
"r3-link1"][addr_type].split("/")[0],
"next_hop": topo["routers"]["r2"]["links"]["r3-link1"][
addr_type
].split("/")[0],
"vrf": "RED",
"delete": True
}
"delete": True,
},
]
}
}
result = create_static_routes(tgen, static_routes)
assert result is True, "Testcase {} :Failed \n Error: {}". \
format(tc_name, result)
assert result is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, result
)
step("Verify that now routes are imported with two different next-hop "
"vrfs but same IPs. Additionally R3 must do ECMP for both the routes")
step(
"Verify that now routes are imported with two different next-hop "
"vrfs but same IPs. Additionally R3 must do ECMP for both the routes"
)
for addr_type in ADDR_TYPES:
next_hop_vrf = [
topo["routers"]["r1"]["links"]["r3-link3"][addr_type].\
split("/")[0],
topo["routers"]["r1"]["links"]["r3-link3"][addr_type]. \
split("/")[0]
]
topo["routers"]["r1"]["links"]["r3-link3"][addr_type].split("/")[0],
topo["routers"]["r1"]["links"]["r3-link3"][addr_type].split("/")[0],
]
static_routes = {
"r3": {
"static_routes": [
@ -368,20 +368,24 @@ def test_dynamic_import_ecmp_imported_routed_diffrent_vrfs_p0(request):
}
}
result = verify_bgp_rib(tgen, addr_type, "r3", static_routes,
next_hop=next_hop_vrf)
assert result is True, "Testcase {} : Failed \n Error {}". \
format(tc_name, result)
result = verify_bgp_rib(
tgen, addr_type, "r3", static_routes, next_hop=next_hop_vrf
)
assert result is True, "Testcase {} : Failed \n Error {}".format(
tc_name, result
)
result = verify_rib(tgen, addr_type, "r3", static_routes,
next_hop=next_hop_vrf)
assert result is True, "Testcase {} : Failed \n Error {}". \
format(tc_name, result)
result = verify_rib(tgen, addr_type, "r3", static_routes, next_hop=next_hop_vrf)
assert result is True, "Testcase {} : Failed \n Error {}".format(
tc_name, result
)
write_test_footer(tc_name)
def test_locally_imported_routes_selected_as_bestpath_over_ebgp_imported_routes_p0(request):
def test_locally_imported_routes_selected_as_bestpath_over_ebgp_imported_routes_p0(
request,
):
"""
Verify ECMP for imported routes from different VRFs.
"""
@ -393,13 +397,15 @@ def test_locally_imported_routes_selected_as_bestpath_over_ebgp_imported_routes_
check_router_status(tgen)
reset_config_on_routers(tgen)
step("Configure same static routes on R2 and R3 vrfs and redistribute in BGP "
"for GREEN and RED vrf instances")
for dut, network in zip(["r2", "r3"], [
[NETWORK1_1, NETWORK1_2], [NETWORK1_1, NETWORK1_2]]):
step(
"Configure same static routes on R2 and R3 vrfs and redistribute in BGP "
"for GREEN and RED vrf instances"
)
for dut, network in zip(
["r2", "r3"], [[NETWORK1_1, NETWORK1_2], [NETWORK1_1, NETWORK1_2]]
):
for vrf_name, network_vrf in zip(["RED", "GREEN"], network):
step("Configure static route for VRF : {} on {}".format(vrf_name,
dut))
step("Configure static route for VRF : {} on {}".format(vrf_name, dut))
for addr_type in ADDR_TYPES:
static_routes = {
dut: {
@ -407,44 +413,50 @@ def test_locally_imported_routes_selected_as_bestpath_over_ebgp_imported_routes_
{
"network": [network_vrf[addr_type]],
"next_hop": "blackhole",
"vrf": vrf_name
"vrf": vrf_name,
}
]
}
}
result = create_static_routes(tgen, static_routes)
assert result is True, "Testcase {} :Failed \n Error: {}". \
format(tc_name, result)
assert result is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, result
)
for dut, as_num in zip(["r2", "r3"], ["2", "3"]):
for vrf_name in ["RED", "GREEN"]:
step("Redistribute static route on BGP VRF : {}".format(vrf_name))
temp = {}
for addr_type in ADDR_TYPES:
temp.update({
addr_type: {
"unicast": {
"redistribute": [{
"redist_type": "static"
}]
temp.update(
{
addr_type: {
"unicast": {"redistribute": [{"redist_type": "static"}]}
}
}
})
)
redist_dict = {dut: {"bgp": [{
"vrf": vrf_name, "local_as": as_num, "address_family": temp
}]}}
redist_dict = {
dut: {
"bgp": [
{"vrf": vrf_name, "local_as": as_num, "address_family": temp}
]
}
}
result = create_router_bgp(tgen, topo, redist_dict)
assert result is True, "Testcase {} :Failed \n Error: {}". \
format(tc_name, result)
assert result is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, result
)
step("Verify that R2 and R3 has installed redistributed routes in default "
"and RED vrfs and GREEN respectively:")
for dut, network in zip(["r2", "r3"],
[[NETWORK1_1, NETWORK1_2],
[NETWORK1_1, NETWORK1_2]]):
step(
"Verify that R2 and R3 has installed redistributed routes in default "
"and RED vrfs and GREEN respectively:"
)
for dut, network in zip(
["r2", "r3"], [[NETWORK1_1, NETWORK1_2], [NETWORK1_1, NETWORK1_2]]
):
for vrf_name, network_vrf in zip(["RED", "GREEN"], network):
for addr_type in ADDR_TYPES:
static_routes = {
@ -453,38 +465,32 @@ def test_locally_imported_routes_selected_as_bestpath_over_ebgp_imported_routes_
{
"network": [network_vrf[addr_type]],
"next_hop": "blackhole",
"vrf": vrf_name
"vrf": vrf_name,
}
]
}
}
result = verify_bgp_rib(tgen, addr_type, dut, static_routes)
assert result is True, "Testcase {} : Failed \n Error {}". \
format(tc_name, result)
assert result is True, "Testcase {} : Failed \n Error {}".format(
tc_name, result
)
step("Import vrf RED's route in vrf GREEN on R3")
temp = {}
for addr_type in ADDR_TYPES:
temp.update({
addr_type: {
"unicast": {
"import": {
"vrf": "RED"
}
}
}
})
temp.update({addr_type: {"unicast": {"import": {"vrf": "RED"}}}})
import_dict = {"r3": {"bgp": [{
"vrf": "GREEN", "local_as": 3, "address_family": temp
}]}}
import_dict = {
"r3": {"bgp": [{"vrf": "GREEN", "local_as": 3, "address_family": temp}]}
}
result = create_router_bgp(tgen, topo, import_dict)
assert result is True, "Testcase {} :Failed \n Error: {}". \
format(tc_name, result)
assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
step("Verify that locally imported routes are installed over eBGP imported"
" routes from VRF RED into VRF GREEN")
step(
"Verify that locally imported routes are installed over eBGP imported"
" routes from VRF RED into VRF GREEN"
)
for addr_type in ADDR_TYPES:
static_routes = {
"r3": {
@ -492,7 +498,7 @@ def test_locally_imported_routes_selected_as_bestpath_over_ebgp_imported_routes_
{
"network": [NETWORK1_2[addr_type]],
"next_hop": "blackhole",
"vrf": "GREEN"
"vrf": "GREEN",
}
]
}
@ -504,19 +510,21 @@ def test_locally_imported_routes_selected_as_bestpath_over_ebgp_imported_routes_
{
"network": NETWORK1_2[addr_type],
"bestpath": BESTPATH[addr_type],
"vrf": "GREEN"
"vrf": "GREEN",
}
]
}
}
result = verify_bgp_bestpath(tgen, addr_type, input_routes)
assert result is True, "Testcase {} : Failed \n Error {}". \
format(tc_name, result)
assert result is True, "Testcase {} : Failed \n Error {}".format(
tc_name, result
)
result = verify_rib(tgen, addr_type, "r3", static_routes)
assert result is True, "Testcase {} : Failed \n Error {}". \
format(tc_name, result)
assert result is True, "Testcase {} : Failed \n Error {}".format(
tc_name, result
)
write_test_footer(tc_name)

View file

@ -97,8 +97,8 @@ def test_static_timing():
optype = "adding" if add else "removing"
iptype = "IPv6" if do_ipv6 else "IPv4"
if super_prefix is None:
super_prefix = u"2001::/48" if do_ipv6 else u"10.0.0.0/8"
via = u"lo"
super_prefix = "2001::/48" if do_ipv6 else "10.0.0.0/8"
via = "lo"
optyped = "added" if add else "removed"
for rname, router in router_list.items():
@ -161,8 +161,8 @@ def test_static_timing():
prefix_count = 50
prefix_base = [
[u"10.0.0.0/8", u"11.0.0.0/8"],
[u"2100:1111:2220::/44", u"2100:3333:4440::/44"],
["10.0.0.0/8", "11.0.0.0/8"],
["2100:1111:2220::/44", "2100:3333:4440::/44"],
]
# This apparently needed to allow for various mgmtd/staticd/zebra connections to form

View file

@ -193,6 +193,7 @@ if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]
sys.exit(pytest.main(args))
#
# Auxiliary Functions
#

View file

@ -41,6 +41,7 @@ pytestmark = [
# pytest.mark.vrrpd,
]
# Function we pass to Topogen to create the topology
def build_topo(tgen):
"Build function"

View file

@ -65,7 +65,8 @@ def setup_module(module):
TopoRouter.RD_SHARP, os.path.join(CWD, "{}/sharpd.conf".format(rname))
)
router.load_config(
TopoRouter.RD_FPM_LISTENER, os.path.join(CWD, "{}/fpm_stub.conf".format(rname))
TopoRouter.RD_FPM_LISTENER,
os.path.join(CWD, "{}/fpm_stub.conf".format(rname)),
)
tgen.start_router()

View file

@ -118,11 +118,19 @@ def setup_module(mod):
# For all registered routers, load the zebra configuration file
for rname, router in router_list.items():
router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)))
router.load_config( TopoRouter.RD_ISIS, os.path.join(CWD, "{}/isisd.conf".format(rname)))
router.load_config(
TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
)
router.load_config(
TopoRouter.RD_ISIS, os.path.join(CWD, "{}/isisd.conf".format(rname))
)
if rname in ["rt0", "rt9"]:
router.load_config( TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)))
router.load_config( TopoRouter.RD_PATH, os.path.join(CWD, "{}/pathd.conf".format(rname)))
router.load_config(
TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
)
router.load_config(
TopoRouter.RD_PATH, os.path.join(CWD, "{}/pathd.conf".format(rname))
)
router.run("ip link add dum0 type dummy")
router.run("ip link set dum0 up")
if rname == "rt0":
@ -145,6 +153,7 @@ def setup_testcase(msg):
pytest.skip(tgen.errors)
return tgen
def open_json_file(filename):
try:
with open(filename, "r") as f:
@ -162,7 +171,7 @@ def check_rib(name, cmd, expected_file):
expected = open_json_file("{}/{}".format(CWD, expected_file))
return topotest.json_cmp(output, expected)
logger.info("[+] check {} \"{}\" {}".format(name, cmd, expected_file))
logger.info('[+] check {} "{}" {}'.format(name, cmd, expected_file))
tgen = get_topogen()
func = partial(_check, name, cmd, expected_file)
success, result = topotest.run_and_expect(func, None, count=120, wait=0.5)

View file

@ -197,13 +197,16 @@ def setup_module(mod):
# For all registered routers, load the zebra and isis configuration files
for rname, router in tgen.routers().items():
router.load_config(TopoRouter.RD_ZEBRA,
os.path.join(CWD, '{}/zebra.conf'.format(rname)))
router.load_config(TopoRouter.RD_ISIS,
os.path.join(CWD, '{}/isisd.conf'.format(rname)))
if (os.path.exists('{}/sharpd.conf'.format(rname))):
router.load_config(TopoRouter.RD_SHARP,
os.path.join(CWD, '{}/sharpd.conf'.format(rname)))
router.load_config(
TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
)
router.load_config(
TopoRouter.RD_ISIS, os.path.join(CWD, "{}/isisd.conf".format(rname))
)
if os.path.exists("{}/sharpd.conf".format(rname)):
router.load_config(
TopoRouter.RD_SHARP, os.path.join(CWD, "{}/sharpd.conf".format(rname))
)
# Start routers
tgen.start_router()
@ -227,7 +230,9 @@ def router_compare_json_output(rname, command, reference):
expected = json.loads(open(filename).read())
# Run test function until we get an result. Wait at most 60 seconds.
test_func = functools.partial(topotest.router_json_cmp, tgen.gears[rname], command, expected)
test_func = functools.partial(
topotest.router_json_cmp, tgen.gears[rname], command, expected
)
_, diff = topotest.run_and_expect(test_func, None, count=120, wait=0.5)
assertmsg = '"{}" JSON output mismatches the expected result'.format(rname)
assert diff is None, assertmsg
@ -308,8 +313,10 @@ def test_srv6_locator_step1():
for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
router_compare_json_output(
rname, "show segment-routing srv6 locator json", "step1/show_srv6_locator_table.ref"
)
rname,
"show segment-routing srv6 locator json",
"step1/show_srv6_locator_table.ref",
)
def test_ping_step1():
@ -326,10 +333,16 @@ def test_ping_step1():
pytest.skip(tgen.errors)
# Setup encap route on rt1, decap route on rt2
tgen.gears["rt1"].vtysh_cmd("sharp install seg6-routes fc00:0:9::1 nexthop-seg6 2001:db8:1::2 encap fc00:0:1:2:6:f00d:: 1")
tgen.gears["rt6"].vtysh_cmd("sharp install seg6local-routes fc00:0:f00d:: nexthop-seg6local eth-dst End_DT6 254 1")
tgen.gears["dst"].vtysh_cmd("sharp install route 2001:db8:1::1 nexthop 2001:db8:10::1 1")
tgen.gears["rt1"].vtysh_cmd(
"sharp install seg6-routes fc00:0:9::1 nexthop-seg6 2001:db8:1::2 encap fc00:0:1:2:6:f00d:: 1"
)
tgen.gears["rt6"].vtysh_cmd(
"sharp install seg6local-routes fc00:0:f00d:: nexthop-seg6local eth-dst End_DT6 254 1"
)
tgen.gears["dst"].vtysh_cmd(
"sharp install route 2001:db8:1::1 nexthop 2001:db8:10::1 1"
)
# Try to ping dst from rt1
check_ping6("rt1", "fc00:0:9::1", True)
@ -412,8 +425,10 @@ def test_srv6_locator_step2():
for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
router_compare_json_output(
rname, "show segment-routing srv6 locator json", "step2/show_srv6_locator_table.ref"
)
rname,
"show segment-routing srv6 locator json",
"step2/show_srv6_locator_table.ref",
)
def test_ping_step2():
@ -428,7 +443,7 @@ def test_ping_step2():
# Skip if previous fatal error condition is raised
if tgen.routers_have_failure():
pytest.skip(tgen.errors)
check_ping6("rt1", "fc00:0:9::1", False)
@ -512,8 +527,10 @@ def test_srv6_locator_step3():
for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
router_compare_json_output(
rname, "show segment-routing srv6 locator json", "step3/show_srv6_locator_table.ref"
)
rname,
"show segment-routing srv6 locator json",
"step3/show_srv6_locator_table.ref",
)
def test_ping_step3():
@ -528,7 +545,7 @@ def test_ping_step3():
# Skip if previous fatal error condition is raised
if tgen.routers_have_failure():
pytest.skip(tgen.errors)
check_ping6("rt1", "fc00:0:9::1", True)
@ -608,8 +625,10 @@ def test_srv6_locator_step4():
for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
router_compare_json_output(
rname, "show segment-routing srv6 locator json", "step4/show_srv6_locator_table.ref"
)
rname,
"show segment-routing srv6 locator json",
"step4/show_srv6_locator_table.ref",
)
def test_ping_step4():
@ -624,7 +643,7 @@ def test_ping_step4():
# Skip if previous fatal error condition is raised
if tgen.routers_have_failure():
pytest.skip(tgen.errors)
check_ping6("rt1", "fc00:0:9::1", False)
@ -704,8 +723,10 @@ def test_srv6_locator_step5():
for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
router_compare_json_output(
rname, "show segment-routing srv6 locator json", "step5/show_srv6_locator_table.ref"
)
rname,
"show segment-routing srv6 locator json",
"step5/show_srv6_locator_table.ref",
)
def test_ping_step5():
@ -720,7 +741,7 @@ def test_ping_step5():
# Skip if previous fatal error condition is raised
if tgen.routers_have_failure():
pytest.skip(tgen.errors)
check_ping6("rt1", "fc00:0:9::1", True)
@ -799,8 +820,10 @@ def test_srv6_locator_step6():
for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
router_compare_json_output(
rname, "show segment-routing srv6 locator json", "step6/show_srv6_locator_table.ref"
)
rname,
"show segment-routing srv6 locator json",
"step6/show_srv6_locator_table.ref",
)
def test_ping_step6():
@ -815,7 +838,7 @@ def test_ping_step6():
# Skip if previous fatal error condition is raised
if tgen.routers_have_failure():
pytest.skip(tgen.errors)
check_ping6("rt1", "fc00:0:9::1", False)
@ -895,8 +918,10 @@ def test_srv6_locator_step7():
for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
router_compare_json_output(
rname, "show segment-routing srv6 locator json", "step7/show_srv6_locator_table.ref"
)
rname,
"show segment-routing srv6 locator json",
"step7/show_srv6_locator_table.ref",
)
def test_ping_step7():
@ -911,7 +936,7 @@ def test_ping_step7():
# Skip if previous fatal error condition is raised
if tgen.routers_have_failure():
pytest.skip(tgen.errors)
check_ping6("rt1", "fc00:0:9::1", True)
@ -990,8 +1015,10 @@ def test_srv6_locator_step8():
for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
router_compare_json_output(
rname, "show segment-routing srv6 locator json", "step8/show_srv6_locator_table.ref"
)
rname,
"show segment-routing srv6 locator json",
"step8/show_srv6_locator_table.ref",
)
def test_ping_step8():
@ -1006,7 +1033,7 @@ def test_ping_step8():
# Skip if previous fatal error condition is raised
if tgen.routers_have_failure():
pytest.skip(tgen.errors)
check_ping6("rt1", "fc00:0:9::1", False)
@ -1089,8 +1116,10 @@ def test_srv6_locator_step9():
for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
router_compare_json_output(
rname, "show segment-routing srv6 locator json", "step9/show_srv6_locator_table.ref"
)
rname,
"show segment-routing srv6 locator json",
"step9/show_srv6_locator_table.ref",
)
def test_ping_step9():
@ -1105,7 +1134,7 @@ def test_ping_step9():
# Skip if previous fatal error condition is raised
if tgen.routers_have_failure():
pytest.skip(tgen.errors)
check_ping6("rt1", "fc00:0:9::1", True)

View file

@ -189,10 +189,18 @@ def test_step3():
tgen = setup_testcase("Step3: Add IPv6 on r1 and r2 interfaces")
tgen.net["r1"].cmd('vtysh -c "conf t" -c "interface r1-eth0" -c "ipv6 address 2001:db8:0::1/64"')
tgen.net["r1"].cmd('vtysh -c "conf t" -c "interface r1-eth0" -c "ipv6 router isis TE"')
tgen.net["r2"].cmd('vtysh -c "conf t" -c "interface r2-eth0" -c "ipv6 address 2001:db8:0::2/64"')
tgen.net["r2"].cmd('vtysh -c "conf t" -c "interface r2-eth0" -c "ipv6 router isis TE"')
tgen.net["r1"].cmd(
'vtysh -c "conf t" -c "interface r1-eth0" -c "ipv6 address 2001:db8:0::1/64"'
)
tgen.net["r1"].cmd(
'vtysh -c "conf t" -c "interface r1-eth0" -c "ipv6 router isis TE"'
)
tgen.net["r2"].cmd(
'vtysh -c "conf t" -c "interface r2-eth0" -c "ipv6 address 2001:db8:0::2/64"'
)
tgen.net["r2"].cmd(
'vtysh -c "conf t" -c "interface r2-eth0" -c "ipv6 router isis TE"'
)
for rname in ["r1", "r2", "r3", "r4"]:
compare_ted_json_output(tgen, rname, "ted_step3.json")
@ -202,8 +210,12 @@ def test_step4():
tgen = setup_testcase("Step4: Modify Prefix SID on router r4")
tgen.net["r4"].cmd('vtysh -c "conf t" -c "router isis TE" -c "segment-routing prefix 10.0.255.4/32 index 40"')
tgen.net["r4"].cmd('vtysh -c "conf t" -c "router isis TE" -c "segment-routing prefix 2001:db8:ffff::4/128 index 1040"')
tgen.net["r4"].cmd(
'vtysh -c "conf t" -c "router isis TE" -c "segment-routing prefix 10.0.255.4/32 index 40"'
)
tgen.net["r4"].cmd(
'vtysh -c "conf t" -c "router isis TE" -c "segment-routing prefix 2001:db8:ffff::4/128 index 1040"'
)
for rname in ["r1", "r2", "r3", "r4"]:
compare_ted_json_output(tgen, rname, "ted_step4.json")
@ -229,9 +241,15 @@ def test_step6():
tgen = setup_testcase("Step6: Modify link parameters on r2 & r4")
tgen.net["r2"].cmd('vtysh -c "conf t" -c "interface r2-eth3" -c "link-params" -c "no use-bw"')
tgen.net["r4"].cmd('vtysh -c "conf t" -c "interface r4-eth0" -c "link-params" -c "delay 20000"')
tgen.net["r4"].cmd('vtysh -c "conf t" -c "interface r4-eth0" -c "link-params" -c "delay-variation 10000"')
tgen.net["r2"].cmd(
'vtysh -c "conf t" -c "interface r2-eth3" -c "link-params" -c "no use-bw"'
)
tgen.net["r4"].cmd(
'vtysh -c "conf t" -c "interface r4-eth0" -c "link-params" -c "delay 20000"'
)
tgen.net["r4"].cmd(
'vtysh -c "conf t" -c "interface r4-eth0" -c "link-params" -c "delay-variation 10000"'
)
for rname in ["r1", "r2", "r3", "r4"]:
compare_ted_json_output(tgen, rname, "ted_step6.json")

View file

@ -8,27 +8,29 @@ import struct
class BGPOpen:
UNPACK_STR = '!16sHBBHH4sB'
UNPACK_STR = "!16sHBBHH4sB"
@classmethod
def dissect(cls, data):
(marker,
length,
open_type,
version,
my_as,
hold_time,
bgp_id,
optional_params_len) = struct.unpack_from(cls.UNPACK_STR, data)
(
marker,
length,
open_type,
version,
my_as,
hold_time,
bgp_id,
optional_params_len,
) = struct.unpack_from(cls.UNPACK_STR, data)
data = data[struct.calcsize(cls.UNPACK_STR) + optional_params_len:]
data = data[struct.calcsize(cls.UNPACK_STR) + optional_params_len :]
# XXX: parse optional parameters
return data, {
'version': version,
'my_as': my_as,
'hold_time': hold_time,
'bgp_id': ipaddress.ip_address(bgp_id),
'optional_params_len': optional_params_len,
"version": version,
"my_as": my_as,
"hold_time": hold_time,
"bgp_id": ipaddress.ip_address(bgp_id),
"optional_params_len": optional_params_len,
}

View file

@ -10,45 +10,47 @@ from .nlri import NlriIPv4Unicast
from .path_attributes import PathAttribute
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class BGPUpdate:
UNPACK_STR = '!16sHBH'
UNPACK_STR = "!16sHBH"
STATIC_SIZE = 23
@classmethod
def dissect(cls, data):
msg = {'bmp_log_type': 'update'}
msg = {"bmp_log_type": "update"}
common_size = struct.calcsize(cls.UNPACK_STR)
(marker,
length,
update_type,
withdrawn_routes_len) = struct.unpack_from(cls.UNPACK_STR, data)
(marker, length, update_type, withdrawn_routes_len) = struct.unpack_from(
cls.UNPACK_STR, data
)
# get withdrawn routes
withdrawn_routes = ''
withdrawn_routes = ""
if withdrawn_routes_len:
withdrawn_routes = NlriIPv4Unicast.parse(
data[common_size:common_size + withdrawn_routes_len]
data[common_size : common_size + withdrawn_routes_len]
)
msg['bmp_log_type'] = 'withdraw'
msg["bmp_log_type"] = "withdraw"
msg.update(withdrawn_routes)
# get path attributes
(total_path_attrs_len,) = struct.unpack_from(
'!H', data[common_size+withdrawn_routes_len:])
"!H", data[common_size + withdrawn_routes_len :]
)
if total_path_attrs_len:
offset = cls.STATIC_SIZE + withdrawn_routes_len
path_attrs_data = data[offset:offset + total_path_attrs_len]
path_attrs_data = data[offset : offset + total_path_attrs_len]
while path_attrs_data:
path_attrs_data, pattr = PathAttribute.dissect(path_attrs_data)
if pattr:
msg = {**msg, **pattr}
# get nlri
nlri_len = length - cls.STATIC_SIZE - withdrawn_routes_len - total_path_attrs_len
nlri_len = (
length - cls.STATIC_SIZE - withdrawn_routes_len - total_path_attrs_len
)
if nlri_len > 0:
nlri = NlriIPv4Unicast.parse(data[length - nlri_len:length])
nlri = NlriIPv4Unicast.parse(data[length - nlri_len : length])
msg.update(nlri)
return data[length:], msg

View file

@ -19,7 +19,7 @@ SAFI_IP_FLOWSPEC = 133
SAFI_VPN_FLOWSPEC = 134
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class AddressFamily:
def __init__(self, afi, safi):
self.afi = afi
@ -31,13 +31,13 @@ class AddressFamily:
return (self.afi, self.safi) == (other.afi, other.safi)
def __str__(self):
return f'afi: {self.afi}, safi: {self.safi}'
return f"afi: {self.afi}, safi: {self.safi}"
def __hash__(self):
return hash((self.afi, self.safi))
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class AF:
IPv4_UNICAST = AddressFamily(AFI_IP, SAFI_UNICAST)
IPv6_UNICAST = AddressFamily(AFI_IP6, SAFI_UNICAST)

View file

@ -13,7 +13,8 @@ from .rd import RouteDistinguisher
def decode_label(label):
# from frr
# frr encode just one label
return (label[0] << 12) | (label[1] << 4) | (label[2] & 0xf0) >> 4
return (label[0] << 12) | (label[1] << 4) | (label[2] & 0xF0) >> 4
def padding(databin, len_):
"""
@ -23,7 +24,8 @@ def padding(databin, len_):
"""
if len(databin) >= len_:
return databin
return databin + b'\0' * (len_ - len(databin))
return databin + b"\0" * (len_ - len(databin))
def dissect_nlri(nlri_data, afi, safi):
"""
@ -37,35 +39,35 @@ def dissect_nlri(nlri_data, afi, safi):
elif addr_family == AF.IPv6_UNICAST:
return NlriIPv6Unicast.parse(nlri_data)
return {'ip_prefix': 'Unknown'}
return {"ip_prefix": "Unknown"}
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class NlriIPv4Unicast:
@staticmethod
def parse(data):
"""parses prefixes from withdrawn_routes or nrli data"""
(prefix_len,) = struct.unpack_from('!B', data)
(prefix_len,) = struct.unpack_from("!B", data)
prefix = padding(data[1:], 4)
return {'ip_prefix': f'{ipaddress.IPv4Address(prefix)}/{prefix_len}'}
return {"ip_prefix": f"{ipaddress.IPv4Address(prefix)}/{prefix_len}"}
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class NlriIPv6Unicast:
@staticmethod
def parse(data):
"""parses prefixes from withdrawn_routes or nrli data"""
(prefix_len,) = struct.unpack_from('!B', data)
(prefix_len,) = struct.unpack_from("!B", data)
prefix = padding(data[1:], 16)
return {'ip_prefix': f'{ipaddress.IPv6Address(prefix)}/{prefix_len}'}
return {"ip_prefix": f"{ipaddress.IPv6Address(prefix)}/{prefix_len}"}
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class NlriIPv4Vpn:
UNPACK_STR = '!B3s8s'
UNPACK_STR = "!B3s8s"
@classmethod
def parse(cls, data):
@ -74,17 +76,17 @@ class NlriIPv4Vpn:
ipv4 = padding(data[offset:], 4)
# prefix_len = total_bits_len - label_bits_len - rd_bits_len
prefix_len = bit_len - 3*8 - 8*8
prefix_len = bit_len - 3 * 8 - 8 * 8
return {
'label': decode_label(label),
'rd': str(RouteDistinguisher(rd)),
'ip_prefix': f'{ipaddress.IPv4Address(ipv4)}/{prefix_len}',
"label": decode_label(label),
"rd": str(RouteDistinguisher(rd)),
"ip_prefix": f"{ipaddress.IPv4Address(ipv4)}/{prefix_len}",
}
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class NlriIPv6Vpn:
UNPACK_STR = '!B3s8s'
UNPACK_STR = "!B3s8s"
@classmethod
def parse(cls, data):
@ -93,48 +95,49 @@ class NlriIPv6Vpn:
offset = struct.calcsize(cls.UNPACK_STR)
ipv6 = padding(data[offset:], 16)
prefix_len = bit_len - 3*8 - 8*8
prefix_len = bit_len - 3 * 8 - 8 * 8
return {
'label': decode_label(label),
'rd': str(RouteDistinguisher(rd)),
'ip_prefix': f'{ipaddress.IPv6Address(ipv6)}/{prefix_len}',
"label": decode_label(label),
"rd": str(RouteDistinguisher(rd)),
"ip_prefix": f"{ipaddress.IPv6Address(ipv6)}/{prefix_len}",
}
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class NlriIPv4Mpls:
pass
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class NlriIPv6Mpls:
pass
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class NlriIPv4FlowSpec:
pass
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class NlriIPv6FlowSpec:
pass
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class NlriVpn4FlowSpec:
pass
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class NlriVpn6FlowSpec:
pass
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class NlriL2EVPN:
pass
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class NlriL2VPNFlowSpec:
pass

View file

@ -38,17 +38,18 @@ ORIGIN_EGP = 0x01
ORIGIN_INCOMPLETE = 0x02
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class PathAttribute:
PATH_ATTRS = {}
UNKNOWN_ATTR = None
UNPACK_STR = '!BB'
UNPACK_STR = "!BB"
@classmethod
def register_path_attr(cls, path_attr):
def _register_path_attr(subcls):
cls.PATH_ATTRS[path_attr] = subcls
return subcls
return _register_path_attr
@classmethod
@ -61,7 +62,7 @@ class PathAttribute:
offset = struct.calcsize(cls.UNPACK_STR)
# get attribute length
attr_len_str = '!H' if (flags & PATH_ATTR_FLAG_EXTENDED_LENGTH) else '!B'
attr_len_str = "!H" if (flags & PATH_ATTR_FLAG_EXTENDED_LENGTH) else "!B"
(attr_len,) = struct.unpack_from(attr_len_str, data[offset:])
@ -69,32 +70,34 @@ class PathAttribute:
path_attr_cls = cls.lookup_path_attr(type_code)
if path_attr_cls == cls.UNKNOWN_ATTR:
return data[offset + attr_len:], None
return data[offset + attr_len :], None
return data[offset+attr_len:], path_attr_cls.dissect(data[offset:offset+attr_len])
return data[offset + attr_len :], path_attr_cls.dissect(
data[offset : offset + attr_len]
)
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
@PathAttribute.register_path_attr(PATH_ATTR_TYPE_ORIGIN)
class PathAttrOrigin:
ORIGIN_STR = {
ORIGIN_IGP: 'IGP',
ORIGIN_EGP: 'EGP',
ORIGIN_INCOMPLETE: 'INCOMPLETE',
ORIGIN_IGP: "IGP",
ORIGIN_EGP: "EGP",
ORIGIN_INCOMPLETE: "INCOMPLETE",
}
@classmethod
def dissect(cls, data):
(origin,) = struct.unpack_from('!B', data)
(origin,) = struct.unpack_from("!B", data)
return {'origin': cls.ORIGIN_STR.get(origin, 'UNKNOWN')}
return {"origin": cls.ORIGIN_STR.get(origin, "UNKNOWN")}
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
@PathAttribute.register_path_attr(PATH_ATTR_TYPE_AS_PATH)
class PathAttrAsPath:
AS_PATH_TYPE_SET = 0x01
AS_PATH_TYPE_SEQUENCE= 0x02
AS_PATH_TYPE_SEQUENCE = 0x02
@staticmethod
def get_asn_len(asns):
@ -103,34 +106,34 @@ class PathAttrAsPath:
@classmethod
def dissect(cls, data):
(_type, _len) = struct.unpack_from('!BB', data)
(_type, _len) = struct.unpack_from("!BB", data)
data = data[2:]
_type_str = 'Ordred' if _type == cls.AS_PATH_TYPE_SEQUENCE else 'Raw'
_type_str = "Ordred" if _type == cls.AS_PATH_TYPE_SEQUENCE else "Raw"
segment = []
while data:
(asn,) = struct.unpack_from('!I', data)
(asn,) = struct.unpack_from("!I", data)
segment.append(asn)
data = data[4:]
return {'as_path': ' '.join(str(a) for a in segment)}
return {"as_path": " ".join(str(a) for a in segment)}
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
@PathAttribute.register_path_attr(PATH_ATTR_TYPE_NEXT_HOP)
class PathAttrNextHop:
@classmethod
def dissect(cls, data):
(nexthop,) = struct.unpack_from('!4s', data)
return {'bgp_nexthop': str(ipaddress.IPv4Address(nexthop))}
(nexthop,) = struct.unpack_from("!4s", data)
return {"bgp_nexthop": str(ipaddress.IPv4Address(nexthop))}
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class PathAttrMultiExitDisc:
pass
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
@PathAttribute.register_path_attr(PATH_ATTR_TYPE_MP_REACH_NLRI)
class PathAttrMpReachNLRI:
"""
@ -162,7 +165,8 @@ class PathAttrMpReachNLRI:
| Network Layer Reachability Information (variable) |
+---------------------------------------------------------+
"""
UNPACK_STR = '!HBB'
UNPACK_STR = "!HBB"
NLRI_RESERVED_LEN = 1
@staticmethod
@ -170,35 +174,35 @@ class PathAttrMpReachNLRI:
msg = {}
if nexthop_len == 4:
# IPv4
(ipv4,) = struct.unpack_from('!4s', nexthop_data)
msg['nxhp_ip'] = str(ipaddress.IPv4Address(ipv4))
(ipv4,) = struct.unpack_from("!4s", nexthop_data)
msg["nxhp_ip"] = str(ipaddress.IPv4Address(ipv4))
elif nexthop_len == 12:
# RD + IPv4
(rd, ipv4) = struct.unpack_from('!8s4s', nexthop_data)
msg['nxhp_ip'] = str(ipaddress.IPv4Address(ipv4))
msg['nxhp_rd'] = str(RouteDistinguisher(rd))
(rd, ipv4) = struct.unpack_from("!8s4s", nexthop_data)
msg["nxhp_ip"] = str(ipaddress.IPv4Address(ipv4))
msg["nxhp_rd"] = str(RouteDistinguisher(rd))
elif nexthop_len == 16:
# IPv6
(ipv6,) = struct.unpack_from('!16s', nexthop_data)
msg['nxhp_ip'] = str(ipaddress.IPv6Address(ipv6))
(ipv6,) = struct.unpack_from("!16s", nexthop_data)
msg["nxhp_ip"] = str(ipaddress.IPv6Address(ipv6))
elif nexthop_len == 24:
# RD + IPv6
(rd, ipv6) = struct.unpack_from('!8s16s', nexthop_data)
msg['nxhp_ip'] = str(ipaddress.IPv6Address(ipv6))
msg['nxhp_rd'] = str(RouteDistinguisher(rd))
(rd, ipv6) = struct.unpack_from("!8s16s", nexthop_data)
msg["nxhp_ip"] = str(ipaddress.IPv6Address(ipv6))
msg["nxhp_rd"] = str(RouteDistinguisher(rd))
elif nexthop_len == 32:
# IPv6 + IPv6 link-local
(ipv6, link_local)= struct.unpack_from('!16s16s', nexthop_data)
msg['nxhp_ip'] = str(ipaddress.IPv6Address(ipv6))
msg['nxhp_link-local'] = str(ipaddress.IPv6Address(link_local))
(ipv6, link_local) = struct.unpack_from("!16s16s", nexthop_data)
msg["nxhp_ip"] = str(ipaddress.IPv6Address(ipv6))
msg["nxhp_link-local"] = str(ipaddress.IPv6Address(link_local))
elif nexthop_len == 48:
# RD + IPv6 + RD + IPv6 link-local
u_str = '!8s16s8s16s'
(rd1, ipv6, rd2, link_local)= struct.unpack_from(u_str, nexthop_data)
msg['nxhp_rd1'] = str(RouteDistinguisher(rd1))
msg['nxhp_ip'] = str(ipaddress.IPv6Address(ipv6))
msg['nxhp_rd2'] = str(RouteDistinguisher(rd2))
msg['nxhp_link-local'] = str(ipaddress.IPv6Address(link_local))
u_str = "!8s16s8s16s"
(rd1, ipv6, rd2, link_local) = struct.unpack_from(u_str, nexthop_data)
msg["nxhp_rd1"] = str(RouteDistinguisher(rd1))
msg["nxhp_ip"] = str(ipaddress.IPv6Address(ipv6))
msg["nxhp_rd2"] = str(RouteDistinguisher(rd2))
msg["nxhp_link-local"] = str(ipaddress.IPv6Address(link_local))
return msg
@ -210,10 +214,10 @@ class PathAttrMpReachNLRI:
def dissect(cls, data):
(afi, safi, nexthop_len) = struct.unpack_from(cls.UNPACK_STR, data)
offset = struct.calcsize(cls.UNPACK_STR)
msg = {'afi': afi, 'safi': safi}
msg = {"afi": afi, "safi": safi}
# dissect nexthop
nexthop_data = data[offset: offset + nexthop_len]
nexthop_data = data[offset : offset + nexthop_len]
nexthop = cls.dissect_nexthop(nexthop_data, nexthop_len)
msg.update(nexthop)
@ -227,7 +231,7 @@ class PathAttrMpReachNLRI:
return msg
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
@PathAttribute.register_path_attr(PATH_ATTR_TYPE_MP_UNREACH_NLRI)
class PathAttrMpUnReachNLRI:
"""
@ -239,13 +243,14 @@ class PathAttrMpUnReachNLRI:
| Withdrawn Routes (variable) |
+---------------------------------------------------------+
"""
UNPACK_STR = '!HB'
UNPACK_STR = "!HB"
@classmethod
def dissect(cls, data):
(afi, safi) = struct.unpack_from(cls.UNPACK_STR, data)
offset = struct.calcsize(cls.UNPACK_STR)
msg = {'bmp_log_type': 'withdraw','afi': afi, 'safi': safi}
msg = {"bmp_log_type": "withdraw", "afi": afi, "safi": safi}
if data[offset:]:
# dissect withdrawn_routes
@ -254,51 +259,51 @@ class PathAttrMpUnReachNLRI:
return msg
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class PathAttrLocalPref:
pass
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class PathAttrAtomicAgregate:
pass
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class PathAttrAggregator:
pass
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class PathAttrCommunities:
pass
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class PathAttrOriginatorID:
pass
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class PathAttrClusterList:
pass
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class PathAttrExtendedCommunities:
pass
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class PathAttrPMSITunnel:
pass
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class PathAttrLinkState:
pass
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class PathAttrLargeCommunities:
pass

View file

@ -7,7 +7,7 @@ import ipaddress
import struct
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
class RouteDistinguisher:
"""
type 0:
@ -28,32 +28,32 @@ class RouteDistinguisher:
+ | 4-bytes AS number (4 bytes)| Service Provider 2 bytes)|
+-------------------------------------------------------------------------+
"""
def __init__(self, rd):
self.rd = rd
self.as_number = None
self.admin_ipv4 = None
self.four_bytes_as = None
self.assigned_sp = None
self.repr_str = ''
self.repr_str = ""
self.dissect()
def dissect(self):
(rd_type,) = struct.unpack_from('!H', self.rd)
(rd_type,) = struct.unpack_from("!H", self.rd)
if rd_type == 0:
(self.as_number,
self.assigned_sp) = struct.unpack_from('!HI', self.rd[2:])
self.repr_str = f'{self.as_number}:{self.assigned_sp}'
(self.as_number, self.assigned_sp) = struct.unpack_from("!HI", self.rd[2:])
self.repr_str = f"{self.as_number}:{self.assigned_sp}"
elif rd_type == 1:
(self.admin_ipv4,
self.assigned_sp) = struct.unpack_from('!IH', self.rd[2:])
(self.admin_ipv4, self.assigned_sp) = struct.unpack_from("!IH", self.rd[2:])
ipv4 = str(ipaddress.IPv4Address(self.admin_ipv4))
self.repr_str = f'{self.as_number}:{self.assigned_sp}'
self.repr_str = f"{self.as_number}:{self.assigned_sp}"
elif rd_type == 2:
(self.four_bytes_as,
self.assigned_sp) = struct.unpack_from('!IH', self.rd[2:])
self.repr_str = f'{self.four_bytes_as}:{self.assigned_sp}'
(self.four_bytes_as, self.assigned_sp) = struct.unpack_from(
"!IH", self.rd[2:]
)
self.repr_str = f"{self.four_bytes_as}:{self.assigned_sp}"
def __str__(self):
return self.repr_str

View file

@ -3764,12 +3764,12 @@ def verify_multicast_traffic(tgen, input_dict, return_traffic=False, expected=Tr
elif (
interface_json["pktsIn"] != 0 and interface_json["bytesIn"] != 0
):
traffic_dict[traffic_type][interface][
"pktsIn"
] = interface_json["pktsIn"]
traffic_dict[traffic_type][interface][
"bytesIn"
] = interface_json["bytesIn"]
traffic_dict[traffic_type][interface]["pktsIn"] = (
interface_json["pktsIn"]
)
traffic_dict[traffic_type][interface]["bytesIn"] = (
interface_json["bytesIn"]
)
logger.info(
"[DUT %s]: Multicast traffic is "
@ -3827,12 +3827,12 @@ def verify_multicast_traffic(tgen, input_dict, return_traffic=False, expected=Tr
interface_json["pktsOut"] != 0
and interface_json["bytesOut"] != 0
):
traffic_dict[traffic_type][interface][
"pktsOut"
] = interface_json["pktsOut"]
traffic_dict[traffic_type][interface][
"bytesOut"
] = interface_json["bytesOut"]
traffic_dict[traffic_type][interface]["pktsOut"] = (
interface_json["pktsOut"]
)
traffic_dict[traffic_type][interface]["bytesOut"] = (
interface_json["bytesOut"]
)
logger.info(
"[DUT %s]: Multicast traffic is "

View file

@ -224,16 +224,20 @@ def build_topo_from_json(tgen, topo=None):
)
# Assigning name to interfaces
topo["routers"][destRouter]["links"][curSwitch][
"interface"
] = "{}-{}-eth{}".format(
destRouter, curSwitch, topo["routers"][destRouter]["nextIfname"]
topo["routers"][destRouter]["links"][curSwitch]["interface"] = (
"{}-{}-eth{}".format(
destRouter,
curSwitch,
topo["routers"][destRouter]["nextIfname"],
)
)
topo["switches"][curSwitch]["links"][destRouter][
"interface"
] = "{}-{}-eth{}".format(
curSwitch, destRouter, topo["routers"][destRouter]["nextIfname"]
topo["switches"][curSwitch]["links"][destRouter]["interface"] = (
"{}-{}-eth{}".format(
curSwitch,
destRouter,
topo["routers"][destRouter]["nextIfname"],
)
)
topo["routers"][destRouter]["nextIfname"] += 1
@ -251,10 +255,10 @@ def build_topo_from_json(tgen, topo=None):
topo["routers"][destRouter]["links"][curSwitch]["ipv4"]
== "auto"
):
topo["routers"][destRouter]["links"][curSwitch][
"ipv4"
] = "{}/{}".format(
ipv4Next, topo["link_ip_start"]["v4mask"]
topo["routers"][destRouter]["links"][curSwitch]["ipv4"] = (
"{}/{}".format(
ipv4Next, topo["link_ip_start"]["v4mask"]
)
)
ipv4Next += 1
# IPv6
@ -263,10 +267,10 @@ def build_topo_from_json(tgen, topo=None):
topo["routers"][destRouter]["links"][curSwitch]["ipv6"]
== "auto"
):
topo["routers"][destRouter]["links"][curSwitch][
"ipv6"
] = "{}/{}".format(
ipv6Next, topo["link_ip_start"]["v6mask"]
topo["routers"][destRouter]["links"][curSwitch]["ipv6"] = (
"{}/{}".format(
ipv6Next, topo["link_ip_start"]["v6mask"]
)
)
ipv6Next = ipaddress.IPv6Address(int(ipv6Next) + ipv6Step)

View file

@ -2183,12 +2183,16 @@ class Router(Node):
daemon,
error.returncode,
error.cmd,
'\n:stdout: "{}"'.format(error.stdout.strip())
if error.stdout
else "",
'\n:stderr: "{}"'.format(error.stderr.strip())
if error.stderr
else "",
(
'\n:stdout: "{}"'.format(error.stdout.strip())
if error.stdout
else ""
),
(
'\n:stderr: "{}"'.format(error.stderr.strip())
if error.stderr
else ""
),
)
else:
logger.debug("%s: %s %s started", self, self.routertype, daemon)

File diff suppressed because one or more lines are too long

View file

@ -202,7 +202,6 @@ def teardown_module():
def clear_bsrp_data(tgen, topo):
"""
clear bsm databas after test"
Parameters

View file

@ -182,7 +182,6 @@ def teardown_module():
def clear_bsrp_data(tgen, topo):
"""
clear bsm databas after test"
Parameters

View file

@ -264,11 +264,14 @@ def verify_state_incremented(state_before, state_after):
for intf, v2 in v1.items():
for state, value in v2.items():
if value >= state_after[ttype][intf][state]:
errormsg = "[DUT: %s]: state %s value has not incremented, Initial value: %s, Current value: %s [FAILED!!]" % (
intf,
state,
value,
state_after[ttype][intf][state],
errormsg = (
"[DUT: %s]: state %s value has not incremented, Initial value: %s, Current value: %s [FAILED!!]"
% (
intf,
state,
value,
state_after[ttype][intf][state],
)
)
return errormsg

View file

@ -94,13 +94,11 @@ def config_to_dict_with_key(c, ck, k):
@overload
def config_subst(config: str, **kwargs) -> str:
...
def config_subst(config: str, **kwargs) -> str: ...
@overload
def config_subst(config: Iterable, **kwargs) -> Iterable:
...
def config_subst(config: Iterable, **kwargs) -> Iterable: ...
def config_subst(config: Iterable, **kwargs) -> Iterable:

View file

@ -89,14 +89,14 @@ def main(*args):
ecmd = "/usr/bin/nsenter"
eargs = [ecmd]
#start mucmd same way base process is started
# start mucmd same way base process is started
eargs.append(f"--mount=/proc/{pid}/ns/mnt")
eargs.append(f"--net=/proc/{pid}/ns/net")
eargs.append(f"--pid=/proc/{pid}/ns/pid_for_children")
eargs.append(f"--uts=/proc/{pid}/ns/uts")
eargs.append(f"--wd={rundir}")
eargs += args.shellcmd
#print("Using ", eargs)
# print("Using ", eargs)
return os.execvpe(ecmd, eargs, {**env, **envcfg})

View file

@ -15,6 +15,7 @@ from pathlib import Path
class MatchFoundError(Exception):
"""An error raised when a match is not found."""
def __init__(self, watchlog, match):
self.watchlog = watchlog
self.match = match

View file

@ -24,9 +24,7 @@ CWD = os.path.dirname(os.path.realpath(__file__))
def tgen(request):
"Setup/Teardown the environment and provide tgen argument to tests"
topodef = {
"s1": ("r1",)
}
topodef = {"s1": ("r1",)}
tgen = Topogen(topodef, request.module.__name__)
tgen.start_topology()
@ -46,12 +44,14 @@ def test_access_list_config_ordering(tgen):
r1 = tgen.gears["r1"]
output = r1.vtysh_multicmd([
"conf t",
"access-list test seq 1 permit host 10.0.0.1"])
output = r1.vtysh_multicmd(
["conf t", "access-list test seq 1 permit host 10.0.0.1"]
)
output = r1.vtysh_cmd("show ip access-list test json")
got = json.loads(output)
expected = json.loads('{"ZEBRA":{"test":{"type":"Standard", "addressFamily":"IPv4", "rules":[{"sequenceNumber":1, "filterType":"permit", "address":"10.0.0.1", "mask":"0.0.0.0"}]}}}')
expected = json.loads(
'{"ZEBRA":{"test":{"type":"Standard", "addressFamily":"IPv4", "rules":[{"sequenceNumber":1, "filterType":"permit", "address":"10.0.0.1", "mask":"0.0.0.0"}]}}}'
)
result = json_cmp(got, expected)
assert result is None
@ -59,11 +59,11 @@ def test_access_list_config_ordering(tgen):
# If the northbound mis-orders the create/delete then this test fails.
# https://github.com/FRRouting/frr/pull/15423/commits/38b85e0c2bc555b8827dbd2cb6515b6febf548b4
#
output = r1.vtysh_multicmd([
"conf t",
"access-list test seq 1 permit 10.0.0.0/8"])
output = r1.vtysh_multicmd(["conf t", "access-list test seq 1 permit 10.0.0.0/8"])
output = r1.vtysh_cmd("show ip access-list test json")
got = json.loads(output)
expected = json.loads('{"ZEBRA":{"test":{"type":"Zebra", "addressFamily":"IPv4", "rules":[{"sequenceNumber":1, "filterType":"permit", "prefix":"10.0.0.0/8", "exact-match":false}]}}}')
expected = json.loads(
'{"ZEBRA":{"test":{"type":"Zebra", "addressFamily":"IPv4", "rules":[{"sequenceNumber":1, "filterType":"permit", "prefix":"10.0.0.0/8", "exact-match":false}]}}}'
)
result = json_cmp(got, expected)
assert result is None

View file

@ -183,7 +183,6 @@ def teardown_module(mod):
logger.info("=" * 40)
def red_static(dut, config=True):
"""Local def for Redstribute static routes inside ospf."""
global topo
@ -367,7 +366,13 @@ def test_ospf_flood_red_tc1_p0(request):
},
}
result = verify_ospf_database(
tgen, topo, dut, input_dict_db, lsatype="router", rid="100.1.1.0", expected=False
tgen,
topo,
dut,
input_dict_db,
lsatype="router",
rid="100.1.1.0",
expected=False,
)
assert result is not True, (
"Testcase {} : Failed \n "
@ -573,7 +578,9 @@ def test_ospf_flood_red_tc2_p0(request):
result = verify_ospf_database(
tgen, topo, dut, input_dict_db, lsatype="router", rid=lsid
)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
assert result is True, "Testcase {} : Failed \n Error: {}".format(
tc_name, result
)
step("Wait for 120 secs and verify that LSA's are not refreshed. ")
# get LSA age
@ -636,7 +643,13 @@ def test_ospf_flood_red_tc2_p0(request):
},
}
result = verify_ospf_database(
tgen, topo, dut, input_dict_db, lsatype="router", rid="100.1.1.0", expected=False
tgen,
topo,
dut,
input_dict_db,
lsatype="router",
rid="100.1.1.0",
expected=False,
)
assert result is not True, (
"Testcase {} : Failed \n "
@ -815,7 +828,9 @@ def test_ospf_flood_red_tc3_p0(request):
result = verify_ospf_database(
tgen, topo, dut, input_dict_db, lsatype="router", rid=lsid
)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
assert result is True, "Testcase {} : Failed \n Error: {}".format(
tc_name, result
)
step("Wait for 120 secs and verify that LSA's are not refreshed. ")
# get LSA age
@ -1022,7 +1037,13 @@ def test_ospf_flood_red_tc3_p0(request):
},
}
result = verify_ospf_database(
tgen, topo, dut, input_dict_db, lsatype="router", rid="100.1.1.0", expected=False
tgen,
topo,
dut,
input_dict_db,
lsatype="router",
rid="100.1.1.0",
expected=False,
)
assert result is not True, (

View file

@ -165,7 +165,7 @@ def test_ospf_learning_tc15_p0(request):
step("Verify that Type 3 summary LSA is originated for the same Area 0")
ip = topo["routers"]["r1"]["links"]["r3-link0"]["ipv4"]
ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network)
ip_net = str(ipaddress.ip_interface("{}".format(ip)).network)
dut = "r0"
input_dict = {

View file

@ -177,7 +177,7 @@ def test_ospf_redistribution_tc5_p0(request):
step("verify intra area route is calculated for r0-r3 interface ip in R1")
ip = topo["routers"]["r0"]["links"]["r3"]["ipv4"]
ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network)
ip_net = str(ipaddress.ip_interface("{}".format(ip)).network)
nh = topo["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0]
input_dict = {
"r1": {"static_routes": [{"network": ip_net, "no_of_ip": 1, "routeType": "N"}]}
@ -301,7 +301,7 @@ def test_ospf_redistribution_tc6_p0(request):
step("verify intra area route is calculated for r0-r3 interface ip in R1")
ip = topo["routers"]["r0"]["links"]["r3"]["ipv4"]
ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network)
ip_net = str(ipaddress.ip_interface("{}".format(ip)).network)
nh = topo["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0]
input_dict = {
"r1": {"static_routes": [{"network": ip_net, "no_of_ip": 1, "routeType": "N"}]}

View file

@ -634,7 +634,7 @@ def test_ospf_show_p1(request):
# show ip ospf route
ip = topo["routers"]["r0"]["links"]["r3"]["ipv4"]
ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network)
ip_net = str(ipaddress.ip_interface("{}".format(ip)).network)
nh = topo["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0]
input_dict = {
"r1": {"static_routes": [{"network": ip_net, "no_of_ip": 1, "routeType": "N"}]}

View file

@ -190,8 +190,10 @@ def test_ospf_gr_helper_tc3_p1(request):
ospf_covergence is True
), "OSPF is not after reset config \n Error: {}".format(ospf_covergence)
step("Configure DR priority 100 on R0 and clear ospf neighbors "
"on all the routers.")
step(
"Configure DR priority 100 on R0 and clear ospf neighbors "
"on all the routers."
)
input_dict = {
"r0": {

View file

@ -64,16 +64,9 @@ def setup_module(module):
# This is a sample of configuration loading.
r1 = tgen.gears["r1"]
r1.load_config(
TopoRouter.RD_ZEBRA, os.path.join(CWD, "r1/zebra.conf")
)
r1.load_config(
TopoRouter.RD_OSPF, os.path.join(CWD, "r1/ospfd-3.conf"),
"-n 3"
)
r1.load_config(
TopoRouter.RD_SHARP, os.path.join(CWD, "r1/sharpd.conf")
)
r1.load_config(TopoRouter.RD_ZEBRA, os.path.join(CWD, "r1/zebra.conf"))
r1.load_config(TopoRouter.RD_OSPF, os.path.join(CWD, "r1/ospfd-3.conf"), "-n 3")
r1.load_config(TopoRouter.RD_SHARP, os.path.join(CWD, "r1/sharpd.conf"))
tgen.start_router()
@ -103,13 +96,15 @@ def test_install_sharp_instance_routes():
expected = json.loads(open(json_file).read())
test_func = partial(
topotest.router_json_cmp, r1, "show ip route summ json", expected)
topotest.router_json_cmp, r1, "show ip route summ json", expected
)
logger.info("Ensuring that they exist in the rib/fib")
_, result = topotest.run_and_expect(test_func, None, count=10, wait=1)
assertmsg = '"r1" sharp routes are not installed'
assert result is None, assertmsg
def test_ospf_instance_redistribute():
tgen = get_topogen()
@ -124,7 +119,8 @@ def test_ospf_instance_redistribute():
expected = json.loads(open(json_file).read())
test_func = partial(
topotest.router_json_cmp, r1, "show ip ospf 3 data json", expected)
topotest.router_json_cmp, r1, "show ip ospf 3 data json", expected
)
_, result = topotest.run_and_expect(test_func, None, count=10, wait=1)
assertmsg = '"r1" ospf instance 3 does not have the proper redistributed routes'
@ -139,7 +135,8 @@ def test_ospf_instance_redistribute():
expected = json.loads(open(json_file).read())
test_func = partial(
topotest.router_json_cmp, r1, "show ip ospf 3 data json", expected)
topotest.router_json_cmp, r1, "show ip ospf 3 data json", expected
)
_, result = topotest.run_and_expect(test_func, None, count=10, wait=1)
assertmsg = '"r1" ospf instance 3 does not have the proper redistributed routes'
@ -161,15 +158,14 @@ def test_ospf_instance_default_information():
expected = json.loads(open(json_file).read())
test_func = partial(
topotest.router_json_cmp, r1, "show ip ospf 3 data json", expected)
topotest.router_json_cmp, r1, "show ip ospf 3 data json", expected
)
_, result = topotest.run_and_expect(test_func, None, count=10, wait=1)
assertmsg = '"r1" ospf instance 3 does not properly redistribute the default route'
assert result is None, assertmsg
if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]
sys.exit(pytest.main(args))

View file

@ -182,9 +182,7 @@ def test_ospf_convergence():
"show ip ospf vrf {} route".format(vrf),
expected,
)
result, diff = topotest.run_and_expect(
test_func, "", count=80, wait=1
)
result, diff = topotest.run_and_expect(test_func, "", count=80, wait=1)
assertmsg = "OSPF did not converge on {}:\n{}".format(rname, diff)
assert result, assertmsg
@ -207,9 +205,7 @@ def test_ospf_kernel_route():
test_func = partial(
compare_show_ip_route_vrf, router.name, expected, vrf
)
result, diff = topotest.run_and_expect(
test_func, "", count=80, wait=1
)
result, diff = topotest.run_and_expect(test_func, "", count=80, wait=1)
assertmsg = 'OSPF IPv4 route mismatch in router "{}": {}'.format(
router.name, diff
)

View file

@ -199,9 +199,7 @@ def test_rib_step3():
pytest.skip(tgen.errors)
logger.info("Removing NSSA default on rt4")
tgen.net["rt3"].cmd(
'vtysh -c "conf t" -c "router ospf" -c "area 1 nssa"'
)
tgen.net["rt3"].cmd('vtysh -c "conf t" -c "router ospf" -c "area 1 nssa"')
for rname in ["rt1", "rt2", "rt3", "rt4"]:
router_compare_json_output(

View file

@ -97,14 +97,18 @@ def is_iproute2_json_supported():
Checks if the command 'ip -j route' is supported.
"""
try:
output = subprocess.run(['ip', '-j', 'route', 'get', '0.0.0.0'], stdout=subprocess.PIPE).stdout.decode()
output = subprocess.run(
["ip", "-j", "route", "get", "0.0.0.0"], stdout=subprocess.PIPE
).stdout.decode()
json.loads(output)
return True
except json.decoder.JSONDecodeError:
return False
@pytest.mark.skipif(not is_iproute2_json_supported(), reason="'ip -j route' not supported")
@pytest.mark.skipif(
not is_iproute2_json_supported(), reason="'ip -j route' not supported"
)
def test_all_routes_advertised():
tgen = get_topogen()
@ -135,9 +139,13 @@ def test_all_routes_advertised():
]
}
}
result = verify_ospf_rib(tgen, router_orig, input_dict, next_hop=network[1])
result = verify_ospf_rib(
tgen, router_orig, input_dict, next_hop=network[1]
)
assert result is True, "Error: {}".format(result)
result = verify_rib(tgen, "ipv4", router_orig, input_dict, next_hop=network[1])
result = verify_rib(
tgen, "ipv4", router_orig, input_dict, next_hop=network[1]
)
assert result is True, "Error: {}".format(result)
check_route(router_orig, network[0], network[1])
@ -181,7 +189,9 @@ def check_route(router_name, network, expected_nexthop):
output = router.cmd(f"ip -j route get {address}")
logger.info(output)
routes = json.loads(output)
assert routes[0]["gateway"] == expected_nexthop, f"{router_name} (kernel): no route {address} via {expected_nexthop}"
assert (
routes[0]["gateway"] == expected_nexthop
), f"{router_name} (kernel): no route {address} via {expected_nexthop}"
if __name__ == "__main__":

View file

@ -277,9 +277,7 @@ def _test_add_data(tgen, apibin):
"linkStateId": "230.0.0.2",
"advertisingRouter": "1.0.0.0",
"lsaSeqNumber": "80000001",
"opaqueValues": {
"opaqueData": "00000202"
}
"opaqueValues": {"opaqueData": "00000202"},
},
],
}
@ -330,8 +328,8 @@ def _test_add_data(tgen, apibin):
"advertisingRouter": "1.0.0.0",
"lsaSeqNumber": "80000001",
"opaqueValues": {
"opaqueData": "00010101",
}
"opaqueData": "00010101",
},
},
],
}
@ -381,8 +379,8 @@ def _test_add_data(tgen, apibin):
"advertisingRouter": "1.0.0.0",
"lsaSeqNumber": "80000001",
"opaqueValues": {
"opaqueData": "deadbeaf01234567",
}
"opaqueData": "deadbeaf01234567",
},
},
]
}
@ -434,8 +432,8 @@ def _test_add_data(tgen, apibin):
"advertisingRouter": "1.0.0.0",
"lsaSeqNumber": "80000002",
"opaqueValues": {
"opaqueData": "ebadf00d",
}
"opaqueData": "ebadf00d",
},
},
]
}
@ -1664,8 +1662,8 @@ def _test_opaque_link_local_lsa_crash(tgen, apibin):
"advertisingRouter": "1.0.0.0",
"lsaSeqNumber": "80000001",
"opaqueValues": {
"opaqueData": "feedaceedeadbeef",
}
"opaqueData": "feedaceedeadbeef",
},
},
],
}
@ -1695,8 +1693,8 @@ def _test_opaque_link_local_lsa_crash(tgen, apibin):
"advertisingRouter": "1.0.0.0",
"lsaSeqNumber": "80000001",
"opaqueValues": {
"opaqueData": "feedaceecafebeef",
}
"opaqueData": "feedaceecafebeef",
},
},
],
}

View file

@ -410,7 +410,7 @@ def test_ospfv3_learning_tc15_p0(request):
step("Verify that Type 3 summary LSA is originated for the same Area 0")
ip = topo["routers"]["r1"]["links"]["r3-link0"]["ipv6"]
ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network)
ip_net = str(ipaddress.ip_interface("{}".format(ip)).network)
input_dict = {
"r1": {

View file

@ -262,7 +262,7 @@ def test_ospfv3_redistribution_tc5_p0(request):
step("verify intra area route is calculated for r0-r3 interface ip in R1")
ip = topo["routers"]["r0"]["links"]["r3"]["ipv6"]
ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network)
ip_net = str(ipaddress.ip_interface("{}".format(ip)).network)
llip = get_llip("r0", "r1")
assert llip is not None, "Testcase {} : Failed \n Error: {}".format(tc_name, llip)
@ -379,7 +379,7 @@ def test_ospfv3_redistribution_tc6_p0(request):
step("verify intra area route is calculated for r0-r3 interface ip in R1")
ip = topo["routers"]["r0"]["links"]["r3"]["ipv6"]
ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network)
ip_net = str(ipaddress.ip_interface("{}".format(ip)).network)
llip = get_llip("r0", "r1")
assert llip is not None, "Testcase {} : Failed \n Error: {}".format(tc_name, llip)
nh = llip

View file

@ -1124,7 +1124,7 @@ def test_ospfv3_show_p1(request):
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
ip = topo["routers"]["r0"]["links"]["r3"]["ipv6"]
ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network)
ip_net = str(ipaddress.ip_interface("{}".format(ip)).network)
nh = topo["routers"]["r0"]["links"]["r1"]["ipv6"].split("/")[0]
input_dict = {
"r1": {

View file

@ -32,10 +32,7 @@ pytestmark = [
def tgen(request):
"Setup/Teardown the environment and provide tgen argument to tests"
topodef = {
"s1": ("r1", "r2"),
"s2": ("r1", "r3")
}
topodef = {"s1": ("r1", "r2"), "s2": ("r1", "r3")}
tgen = Topogen(topodef, request.module.__name__)
tgen.start_topology()
@ -68,16 +65,17 @@ def show_rip_json(router):
for route in routes:
match = re.match(
r"(.)\((.)\)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)", route)
r"(.)\((.)\)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)", route
)
if match is None:
continue
route_entry = {
"code": match[1],
"subCode": match[2],
"nextHop": match[4],
"metric": int(match[5]),
"from": match[6],
"code": match[1],
"subCode": match[2],
"nextHop": match[4],
"metric": int(match[5]),
"from": match[6],
}
if json.get(match[3]) is None:
@ -95,12 +93,8 @@ def expect_routes(router, routes, time_amount):
"Internal test function."
return topotest.json_cmp(show_rip_json(router), routes)
_, result = topotest.run_and_expect(test_function,
None,
count=time_amount,
wait=1)
assert result is None, "Unexpected routing table in {}".format(
router.name)
_, result = topotest.run_and_expect(test_function, None, count=time_amount, wait=1)
assert result is None, "Unexpected routing table in {}".format(router.name)
def expect_bfd_peers(router, peers):
@ -119,91 +113,87 @@ def test_rip_convergence(tgen):
"Test that RIP learns the neighbor routes."
expect_routes(
tgen.gears["r1"], {
"10.254.254.2/32": [{
"code": "R",
"subCode": "n",
"from": "192.168.0.2"
}],
"10.254.254.3/32": [{
"code": "R",
"subCode": "n",
"from": "192.168.1.2"
}],
"10.254.254.100/32": [{
"code": "R",
"subCode": "n",
"from": "192.168.0.2",
}, {
"code": "R",
"subCode": "n",
"from": "192.168.1.2",
}]
}, 40)
tgen.gears["r1"],
{
"10.254.254.2/32": [{"code": "R", "subCode": "n", "from": "192.168.0.2"}],
"10.254.254.3/32": [{"code": "R", "subCode": "n", "from": "192.168.1.2"}],
"10.254.254.100/32": [
{
"code": "R",
"subCode": "n",
"from": "192.168.0.2",
},
{
"code": "R",
"subCode": "n",
"from": "192.168.1.2",
},
],
},
40,
)
expect_bfd_peers(tgen.gears["r1"], [{
"peer": "192.168.0.2",
"status": "up",
"receive-interval": 1000,
"transmit-interval": 1000,
}, {
"peer": "192.168.1.2",
"status": "up",
"receive-interval": 1000,
"transmit-interval": 1000,
}])
expect_bfd_peers(
tgen.gears["r1"],
[
{
"peer": "192.168.0.2",
"status": "up",
"receive-interval": 1000,
"transmit-interval": 1000,
},
{
"peer": "192.168.1.2",
"status": "up",
"receive-interval": 1000,
"transmit-interval": 1000,
},
],
)
expect_routes(
tgen.gears["r2"], {
"10.254.254.1/32": [{
"code": "R",
"subCode": "n",
"from": "192.168.0.1"
}],
"10.254.254.3/32": [{
"code": "R",
"subCode": "n",
"from": "192.168.0.1"
}],
"10.254.254.100/32": [{
"code": "S",
"subCode": "r",
"from": "self"
}]
}, 40)
tgen.gears["r2"],
{
"10.254.254.1/32": [{"code": "R", "subCode": "n", "from": "192.168.0.1"}],
"10.254.254.3/32": [{"code": "R", "subCode": "n", "from": "192.168.0.1"}],
"10.254.254.100/32": [{"code": "S", "subCode": "r", "from": "self"}],
},
40,
)
expect_bfd_peers(tgen.gears["r2"], [{
"peer": "192.168.0.1",
"status": "up",
"receive-interval": 1000,
"transmit-interval": 1000,
}])
expect_bfd_peers(
tgen.gears["r2"],
[
{
"peer": "192.168.0.1",
"status": "up",
"receive-interval": 1000,
"transmit-interval": 1000,
}
],
)
expect_routes(
tgen.gears["r3"], {
"10.254.254.1/32": [{
"code": "R",
"subCode": "n",
"from": "192.168.1.1"
}],
"10.254.254.2/32": [{
"code": "R",
"subCode": "n",
"from": "192.168.1.1"
}],
"10.254.254.100/32": [{
"code": "S",
"subCode": "r",
"from": "self"
}]
}, 40)
tgen.gears["r3"],
{
"10.254.254.1/32": [{"code": "R", "subCode": "n", "from": "192.168.1.1"}],
"10.254.254.2/32": [{"code": "R", "subCode": "n", "from": "192.168.1.1"}],
"10.254.254.100/32": [{"code": "S", "subCode": "r", "from": "self"}],
},
40,
)
expect_bfd_peers(tgen.gears["r3"], [{
"peer": "192.168.1.1",
"status": "up",
"receive-interval": 1000,
"transmit-interval": 1000,
}])
expect_bfd_peers(
tgen.gears["r3"],
[
{
"peer": "192.168.1.1",
"status": "up",
"receive-interval": 1000,
"transmit-interval": 1000,
}
],
)
def test_rip_bfd_convergence(tgen):
@ -212,30 +202,30 @@ def test_rip_bfd_convergence(tgen):
tgen.gears["r3"].link_enable("r3-eth0", False)
expect_routes(
tgen.gears["r1"], {
"10.254.254.2/32": [{
"code": "R",
"subCode": "n",
"from": "192.168.0.2"
}],
tgen.gears["r1"],
{
"10.254.254.2/32": [{"code": "R", "subCode": "n", "from": "192.168.0.2"}],
"10.254.254.3/32": None,
"10.254.254.100/32": [{
"code": "R",
"subCode": "n",
"from": "192.168.0.2",
}]
}, 6)
"10.254.254.100/32": [
{
"code": "R",
"subCode": "n",
"from": "192.168.0.2",
}
],
},
6,
)
expect_routes(
tgen.gears["r3"], {
tgen.gears["r3"],
{
"10.254.254.1/32": None,
"10.254.254.2/32": None,
"10.254.254.100/32": [{
"code": "S",
"subCode": "r",
"from": "self"
}]
}, 6)
"10.254.254.100/32": [{"code": "S", "subCode": "r", "from": "self"}],
},
6,
)
def test_memory_leak(tgen):

View file

@ -151,7 +151,7 @@ def route_install_helper(iter):
logger.info(
"Limited memory available: {}, skipping x32 testcase".format(total_mem)
)
return;
return
installed_file = "{}/r1/installed.routes.json".format(CWD)
expected_installed = json.loads(open(installed_file).read())

View file

@ -30,35 +30,51 @@ from lib import topotest
from lib.topogen import Topogen, TopoRouter, get_topogen
from lib.topolog import logger
from scale_test_common import scale_build_common, scale_setup_module, route_install_helper, scale_test_memory_leak, scale_converge_protocols, scale_teardown_module
from scale_test_common import (
scale_build_common,
scale_setup_module,
route_install_helper,
scale_test_memory_leak,
scale_converge_protocols,
scale_teardown_module,
)
pytestmark = [pytest.mark.sharpd]
def build(tgen):
scale_build_common(tgen)
def setup_module(module):
scale_setup_module(module)
def teardown_module(_mod):
scale_teardown_module(_mod)
def test_converge_protocols():
scale_converge_protocols()
def test_route_install_2nh():
route_install_helper(1)
def test_route_install_4nh():
route_install_helper(2)
def test_route_install_16nh():
route_install_helper(4)
def test_memory_leak():
scale_test_memory_leak()
if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]
sys.exit(pytest.main(args))

View file

@ -30,35 +30,51 @@ from lib import topotest
from lib.topogen import Topogen, TopoRouter, get_topogen
from lib.topolog import logger
from scale_test_common import scale_build_common, scale_setup_module, route_install_helper, scale_test_memory_leak, scale_converge_protocols, scale_teardown_module
from scale_test_common import (
scale_build_common,
scale_setup_module,
route_install_helper,
scale_test_memory_leak,
scale_converge_protocols,
scale_teardown_module,
)
pytestmark = [pytest.mark.sharpd]
def build(tgen):
scale_build_common(tgen)
def setup_module(module):
scale_setup_module(module)
def teardown_module(_mod):
scale_teardown_module(_mod)
def test_converge_protocols():
scale_converge_protocols()
def test_route_install_1nh():
route_install_helper(0)
def test_route_install_8nh():
route_install_helper(3)
def test_route_install_32nh():
route_install_helper(5)
def test_memory_leak():
scale_test_memory_leak()
if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]
sys.exit(pytest.main(args))

View file

@ -63,16 +63,16 @@ def teardown_module(mod):
def test_zebra_srv6_encap_src_addr(tgen):
"Test SRv6 encapsulation source address."
logger.info(
"Test SRv6 encapsulation source address."
)
logger.info("Test SRv6 encapsulation source address.")
r1 = tgen.gears["r1"]
# Generate expected results
json_file = "{}/r1/expected_srv6_encap_src_addr.json".format(CWD)
expected = json.loads(open(json_file).read())
ok = topotest.router_json_cmp_retry(r1, "show segment-routing srv6 manager json", expected)
ok = topotest.router_json_cmp_retry(
r1, "show segment-routing srv6 manager json", expected
)
assert ok, '"r1" JSON output mismatches'
output = r1.cmd("ip sr tunsrc show")
@ -81,9 +81,7 @@ def test_zebra_srv6_encap_src_addr(tgen):
def test_zebra_srv6_encap_src_addr_unset(tgen):
"Test SRv6 encapsulation source address unset."
logger.info(
"Test SRv6 encapsulation source address unset."
)
logger.info("Test SRv6 encapsulation source address unset.")
r1 = tgen.gears["r1"]
# Unset SRv6 encapsulation source address
@ -101,7 +99,9 @@ def test_zebra_srv6_encap_src_addr_unset(tgen):
json_file = "{}/r1/expected_srv6_encap_src_addr_unset.json".format(CWD)
expected = json.loads(open(json_file).read())
ok = topotest.router_json_cmp_retry(r1, "show segment-routing srv6 manager json", expected)
ok = topotest.router_json_cmp_retry(
r1, "show segment-routing srv6 manager json", expected
)
assert ok, '"r1" JSON output mismatches'
output = r1.cmd("ip sr tunsrc show")
@ -110,9 +110,7 @@ def test_zebra_srv6_encap_src_addr_unset(tgen):
def test_zebra_srv6_encap_src_addr_set(tgen):
"Test SRv6 encapsulation source address set."
logger.info(
"Test SRv6 encapsulation source address set."
)
logger.info("Test SRv6 encapsulation source address set.")
r1 = tgen.gears["r1"]
# Set SRv6 encapsulation source address
@ -130,7 +128,9 @@ def test_zebra_srv6_encap_src_addr_set(tgen):
json_file = "{}/r1/expected_srv6_encap_src_addr_set.json".format(CWD)
expected = json.loads(open(json_file).read())
ok = topotest.router_json_cmp_retry(r1, "show segment-routing srv6 manager json", expected)
ok = topotest.router_json_cmp_retry(
r1, "show segment-routing srv6 manager json", expected
)
assert ok, '"r1" JSON output mismatches'
output = r1.cmd("ip sr tunsrc show")

View file

@ -549,7 +549,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ebgp(request):
protocol = "bgp"
ntwk_r2_vm1 = str(
ipaddress.ip_interface(
u"{}".format(topo["routers"]["r2"]["links"]["vm1"][addr_type])
"{}".format(topo["routers"]["r2"]["links"]["vm1"][addr_type])
).network
)
input_dict = {"r1": {"static_routes": [{"network": ntwk_r2_vm1}]}}
@ -569,7 +569,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ebgp(request):
dut = "r2"
ntwk_r2_vm6 = str(
ipaddress.ip_interface(
u"{}".format(topo["routers"]["r2"]["links"]["vm6"][addr_type])
"{}".format(topo["routers"]["r2"]["links"]["vm6"][addr_type])
).network
)
input_dict = {"r3": {"static_routes": [{"network": ntwk_r2_vm6}]}}
@ -912,7 +912,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ebgp(request):
protocol = "bgp"
ntwk_r2_vm1 = str(
ipaddress.ip_interface(
u"{}".format(topo["routers"]["r2"]["links"]["vm1"][addr_type])
"{}".format(topo["routers"]["r2"]["links"]["vm1"][addr_type])
).network
)
input_dict = {"r1": {"static_routes": [{"network": ntwk_r2_vm1}]}}
@ -929,7 +929,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ebgp(request):
dut = "r1"
ntwk_r2_vm1 = str(
ipaddress.ip_interface(
u"{}".format(topo["routers"]["r1"]["links"]["vm4"][addr_type])
"{}".format(topo["routers"]["r1"]["links"]["vm4"][addr_type])
).network
)
input_dict = {"r1": {"static_routes": [{"network": ntwk_r2_vm1}]}}
@ -943,7 +943,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ebgp(request):
dut = "r2"
ntwk_r2_vm1 = str(
ipaddress.ip_interface(
u"{}".format(topo["routers"]["r1"]["links"]["vm4"][addr_type])
"{}".format(topo["routers"]["r1"]["links"]["vm4"][addr_type])
).network
)
input_dict = {"r1": {"static_routes": [{"network": ntwk_r2_vm1}]}}
@ -957,7 +957,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ebgp(request):
protocol = "bgp"
ntwk_r2_vm6 = str(
ipaddress.ip_interface(
u"{}".format(topo["routers"]["r2"]["links"]["vm6"][addr_type])
"{}".format(topo["routers"]["r2"]["links"]["vm6"][addr_type])
).network
)
input_dict = {"r3": {"static_routes": [{"network": ntwk_r2_vm6}]}}

View file

@ -547,7 +547,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ibgp(request):
protocol = "bgp"
ntwk_r2_vm1 = str(
ipaddress.ip_interface(
u"{}".format(topo["routers"]["r2"]["links"]["vm1"][addr_type])
"{}".format(topo["routers"]["r2"]["links"]["vm1"][addr_type])
).network
)
input_dict = {"r1": {"static_routes": [{"network": ntwk_r2_vm1}]}}
@ -567,7 +567,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ibgp(request):
dut = "r2"
ntwk_r2_vm6 = str(
ipaddress.ip_interface(
u"{}".format(topo["routers"]["r2"]["links"]["vm6"][addr_type])
"{}".format(topo["routers"]["r2"]["links"]["vm6"][addr_type])
).network
)
input_dict = {"r3": {"static_routes": [{"network": ntwk_r2_vm6}]}}
@ -910,7 +910,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ibgp(request):
protocol = "bgp"
ntwk_r2_vm1 = str(
ipaddress.ip_interface(
u"{}".format(topo["routers"]["r2"]["links"]["vm1"][addr_type])
"{}".format(topo["routers"]["r2"]["links"]["vm1"][addr_type])
).network
)
input_dict = {"r1": {"static_routes": [{"network": ntwk_r2_vm1}]}}
@ -927,7 +927,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ibgp(request):
dut = "r1"
ntwk_r2_vm1 = str(
ipaddress.ip_interface(
u"{}".format(topo["routers"]["r1"]["links"]["vm4"][addr_type])
"{}".format(topo["routers"]["r1"]["links"]["vm4"][addr_type])
).network
)
input_dict = {"r1": {"static_routes": [{"network": ntwk_r2_vm1}]}}
@ -941,7 +941,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ibgp(request):
dut = "r2"
ntwk_r2_vm1 = str(
ipaddress.ip_interface(
u"{}".format(topo["routers"]["r1"]["links"]["vm4"][addr_type])
"{}".format(topo["routers"]["r1"]["links"]["vm4"][addr_type])
).network
)
input_dict = {"r1": {"static_routes": [{"network": ntwk_r2_vm1}]}}
@ -955,7 +955,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ibgp(request):
protocol = "bgp"
ntwk_r2_vm6 = str(
ipaddress.ip_interface(
u"{}".format(topo["routers"]["r2"]["links"]["vm6"][addr_type])
"{}".format(topo["routers"]["r2"]["links"]["vm6"][addr_type])
).network
)
input_dict = {"r3": {"static_routes": [{"network": ntwk_r2_vm6}]}}

View file

@ -22,9 +22,8 @@ sys.path.append(os.path.join(CWD, "../lib/"))
from lib.topogen import Topogen, TopoRouter
from lib.topolog import logger
pytestmark = [
pytest.mark.sharpd
]
pytestmark = [pytest.mark.sharpd]
def build_topo(tgen):
"Build function"
@ -42,6 +41,7 @@ def build_topo(tgen):
switch = tgen.add_switch("s2")
switch.add_link(r2)
# New form of setup/teardown using pytest fixture
@pytest.fixture(scope="module")
def tgen(request):
@ -79,22 +79,28 @@ def skip_on_failure(tgen):
if tgen.routers_have_failure():
pytest.skip("skipped because of previous test failure")
def fetch_iproute2_tc_info(r, interface):
qdisc = r.cmd("tc qdisc show dev %s" % interface)
tclass = r.cmd("tc class show dev %s" % interface)
tfilter = r.cmd("tc filter show dev %s" % interface)
return qdisc, tclass, tfilter
# ===================
# The tests functions
# ===================
def test_tc_basic(tgen):
"Test installing one pair of filter & class by sharpd"
r1 = tgen.gears["r1"]
intf = "r1-eth0"
r1.vtysh_cmd("sharp tc dev %s source 192.168.100.0/24 destination 192.168.101.0/24 ip-protocol tcp src-port 8000 dst-port 8001 rate 20mbit" % intf)
r1.vtysh_cmd(
"sharp tc dev %s source 192.168.100.0/24 destination 192.168.101.0/24 ip-protocol tcp src-port 8000 dst-port 8001 rate 20mbit"
% intf
)
time.sleep(3)
@ -115,6 +121,7 @@ def test_tc_basic(tgen):
assert "dst_port 8001" in tfilter
assert "src_port 8000" in tfilter
if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]
sys.exit(pytest.main(args))
sys.exit(pytest.main(args))

View file

@ -94,7 +94,7 @@ def test_zebra_netlink_batching(tgen):
}
match = {}
base = int(ipaddress.ip_address(u"2.1.3.7"))
base = int(ipaddress.ip_address("2.1.3.7"))
for i in range(base, base + count):
pfx = str(ipaddress.ip_network((i, 32)))
match[pfx] = [dict(entry, prefix=pfx)]

View file

@ -33,30 +33,36 @@ sys.path.append(os.path.join(CWD, "../"))
pytestmark = [pytest.mark.sharpd]
#GLOBAL VARIABLES
# GLOBAL VARIABLES
NH1 = "2.2.2.32"
def build_topo(tgen):
tgen.add_router("r1")
switch = tgen.add_switch("sw1")
switch.add_link(tgen.gears["r1"])
def setup_module(mod):
tgen = Topogen(build_topo, mod.__name__)
tgen.start_topology()
router_list = tgen.routers()
for rname, router in tgen.routers().items():
router.load_config(TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)))
router.load_config(
TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
)
router.load_config(
TopoRouter.RD_SHARP, os.path.join(CWD, "{}/sharpd.conf".format(rname))
)
tgen.start_router()
def teardown_module(_mod):
tgen = get_topogen()
tgen.stop_topology()
def test_verify_zebra_nh_resolution(request):
tgen = get_topogen()
tc_name = request.node.name
@ -67,31 +73,18 @@ def test_verify_zebra_nh_resolution(request):
step("Configure static route")
input_dict_1 = {
"r1": {
"static_routes": [
{"network": "2.2.2.0/24", "next_hop": "r1-eth0"}
]
}
}
"r1": {"static_routes": [{"network": "2.2.2.0/24", "next_hop": "r1-eth0"}]}
}
result = create_static_routes(tgen, input_dict_1)
assert result is True, "Testcase {} : Failed \n Error: {}".format(
tc_name, result
)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
step("Verify static routes in RIB of R1")
input_dict_2 = {
"r1": {
"static_routes": [
{"network": "2.2.2.0/24"}
]
}
}
input_dict_2 = {"r1": {"static_routes": [{"network": "2.2.2.0/24"}]}}
dut = "r1"
result = verify_rib(tgen, "ipv4", dut, input_dict_2)
assert result is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, result)
assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
step("Set the connected flag on the NH tracking entry")
r1.vtysh_cmd("sharp watch nexthop 2.2.2.32 connected")
@ -108,8 +101,7 @@ def test_verify_zebra_nh_resolution(request):
}
result = verify_ip_nht(tgen, input_dict_nh)
assert result is True, "Testcase {} : Failed \n"
"Error: Nexthop is missing in RIB".format(
tc_name, result)
"Error: Nexthop is missing in RIB".format(tc_name, result)
step("Add a .32/32 route with the NH as itself")
r1.vtysh_cmd("sharp install routes 2.2.2.32 nexthop 2.2.2.32 1")
@ -126,11 +118,12 @@ def test_verify_zebra_nh_resolution(request):
}
result = verify_ip_nht(tgen, input_dict_nh)
assert result is True, "Testcase {} : Failed \n"
"Error: Nexthop became unresolved".format(
tc_name, result)
"Error: Nexthop became unresolved".format(tc_name, result)
step("Add a .31/32 route with the NH as 2.2.2.32"
"to verify the NH Resolution behaviour")
step(
"Add a .31/32 route with the NH as 2.2.2.32"
"to verify the NH Resolution behaviour"
)
r1.vtysh_cmd("sharp install routes 2.2.2.31 nexthop 2.2.2.32 1")
step("Verify that NH 2.2.2.2/32 doesn't become unresolved")
@ -145,8 +138,8 @@ def test_verify_zebra_nh_resolution(request):
}
result = verify_ip_nht(tgen, input_dict_nh)
assert result is True, "Testcase {} : Failed \n"
"Error: Nexthop became unresolved".format(
tc_name, result)
"Error: Nexthop became unresolved".format(tc_name, result)
if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]