2 # SPDX-License-Identifier: ISC
5 # test_bgp_sender-as-path-loop-detection.py
6 # Part of NetDEF Topology Tests
8 # Copyright (c) 2019 by
9 # Donatas Abraitis <donatas.abraitis@gmail.com>
13 Test if neighbor <neighbor> sender-as-path-loop-detection
14 command works as expeced.
23 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
24 sys
.path
.append(os
.path
.join(CWD
, "../"))
26 # pylint: disable=C0413
27 from lib
import topotest
28 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
31 pytestmark
= [pytest
.mark
.bgpd
]
35 for routern
in range(1, 4):
36 tgen
.add_router("r{}".format(routern
))
38 switch
= tgen
.add_switch("s1")
39 switch
.add_link(tgen
.gears
["r1"])
40 switch
.add_link(tgen
.gears
["r2"])
42 switch
= tgen
.add_switch("s2")
43 switch
.add_link(tgen
.gears
["r2"])
44 switch
.add_link(tgen
.gears
["r3"])
47 def setup_module(mod
):
48 tgen
= Topogen(build_topo
, mod
.__name
__)
51 router_list
= tgen
.routers()
53 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
55 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
58 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
64 def teardown_module(mod
):
69 def test_bgp_sender_as_path_loop_detection():
72 if tgen
.routers_have_failure():
73 pytest
.skip(tgen
.errors
)
78 output
= json
.loads(r2
.vtysh_cmd("show ip bgp neighbor 192.168.255.2 json"))
81 "bgpState": "Established",
82 "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 3}},
85 return topotest
.json_cmp(output
, expected
)
87 def _bgp_has_route_from_r1():
88 output
= json
.loads(r2
.vtysh_cmd("show ip bgp 172.16.255.253/32 json"))
93 "segments": [{"type": "as-sequence", "list": [65001, 65003]}],
99 return topotest
.json_cmp(output
, expected
)
101 def _bgp_suppress_route_to_r1():
103 r2
.vtysh_cmd("show ip bgp neighbor 192.168.255.2 advertised-routes json")
105 expected
= {"totalPrefixCounter": 0}
106 return topotest
.json_cmp(output
, expected
)
108 def _bgp_suppress_route_to_r3():
110 r2
.vtysh_cmd("show ip bgp neighbor 192.168.254.2 advertised-routes json")
112 expected
= {"totalPrefixCounter": 2}
113 return topotest
.json_cmp(output
, expected
)
115 test_func
= functools
.partial(_bgp_converge
)
116 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=0.5)
117 assert result
is None, "Failed bgp to convergence"
119 test_func
= functools
.partial(_bgp_has_route_from_r1
)
120 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=0.5)
121 assert result
is None, "Failed to see a route from r1"
123 test_func
= functools
.partial(_bgp_suppress_route_to_r3
)
124 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=0.5)
125 assert result
is None, "Route 172.16.255.253/32 should not be sent to r3 from r2"
127 test_func
= functools
.partial(_bgp_suppress_route_to_r1
)
128 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=0.5)
129 assert result
is None, "Routes should not be sent to r1 from r2"
132 if __name__
== "__main__":
133 args
= ["-s"] + sys
.argv
[1:]
134 sys
.exit(pytest
.main(args
))