4 # bgp_aggregate-address_origin.py
5 # Part of NetDEF Topology Tests
7 # Copyright (c) 2020 by
8 # Donatas Abraitis <donatas.abraitis@gmail.com>
10 # Permission to use, copy, modify, and/or distribute this software
11 # for any purpose with or without fee is hereby granted, provided
12 # that the above copyright notice and this permission notice appear
15 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
16 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
18 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
19 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
21 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
26 bgp_aggregate-address_origin.py:
28 Test if works the following commands:
30 address-family ipv4 unicast
31 aggregate-address 192.168.255.0/24 origin igp
41 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
42 sys
.path
.append(os
.path
.join(CWD
, "../"))
44 # pylint: disable=C0413
45 from lib
import topotest
46 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
47 from lib
.topolog
import logger
48 from lib
.micronet_compat
import Topo
50 pytestmark
= [pytest
.mark
.bgpd
]
53 class TemplateTopo(Topo
):
54 def build(self
, *_args
, **_opts
):
55 tgen
= get_topogen(self
)
57 for routern
in range(1, 3):
58 tgen
.add_router("r{}".format(routern
))
60 switch
= tgen
.add_switch("s1")
61 switch
.add_link(tgen
.gears
["r1"])
62 switch
.add_link(tgen
.gears
["r2"])
65 def setup_module(mod
):
66 tgen
= Topogen(TemplateTopo
, mod
.__name
__)
69 router_list
= tgen
.routers()
71 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
73 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
76 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
82 def teardown_module(mod
):
87 def test_bgp_aggregate_address_origin():
90 if tgen
.routers_have_failure():
91 pytest
.skip(tgen
.errors
)
93 router
= tgen
.gears
["r2"]
95 def _bgp_converge(router
):
96 output
= json
.loads(router
.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json"))
99 "bgpState": "Established",
100 "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 3}},
103 return topotest
.json_cmp(output
, expected
)
105 def _bgp_aggregate_address_has_metric(router
):
106 output
= json
.loads(router
.vtysh_cmd("show ip bgp 172.16.255.0/24 json"))
107 expected
= {"paths": [{"origin": "IGP"}]}
108 return topotest
.json_cmp(output
, expected
)
110 test_func
= functools
.partial(_bgp_converge
, router
)
111 success
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=0.5)
113 assert result
is None, 'Failed to see bgp convergence in "{}"'.format(router
)
115 test_func
= functools
.partial(_bgp_aggregate_address_has_metric
, router
)
116 success
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=0.5)
120 ), 'Failed to see applied ORIGIN (igp) for aggregated prefix in "{}"'.format(router
)
123 if __name__
== "__main__":
124 args
= ["-s"] + sys
.argv
[1:]
125 sys
.exit(pytest
.main(args
))