diff --git a/test_bgp_as_wide_bgp_identifier.py b/test_bgp_as_wide_bgp_identifier.py index a58bde2..6db73c3 100644 --- a/test_bgp_as_wide_bgp_identifier.py +++ b/test_bgp_as_wide_bgp_identifier.py @@ -1,107 +1,107 @@ -# SPDX-License-Identifier: GPL-2.0-or-later -# Copyright (C) 2022 Nathan Mangar - - -""" -rfc6286: Autonomous-System-Wide Unique BGP Identifier for BGP-4 -Test if 'Bad BGP Identifier' notification is sent only to -internal peers (autonomous-system-wide). eBGP peers are not -affected and should work. -""" - -__topotests_file__ = "bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py" -__topotests_gitrev__ = "4953ca977f3a5de8109ee6353ad07f816ca1774c" - -# pylint: disable=wildcard-import, unused-wildcard-import - -from topotato import * - - -@topology_fixture() -def topology(topo): - """ - [ r1 ] - | - { s1 }--[ r3 ] - | - [ r2 ] - - """ - - topo.router("r1").iface_to("s1").ip4.append("192.168.255.2/24") - topo.router("r2").iface_to("s1").ip4.append("192.168.255.1/24") - topo.router("r3").iface_to("s1").ip4.append("192.168.255.3/24") - - -class Configs(FRRConfigs): - routers = ["r1", "r2", "r3"] - - zebra = """ - #% extends "boilerplate.conf" - #% block main - #% for iface in router.ifaces - interface {{ iface.ifname }} - ip address {{ iface.ip4[0] }} - ! - #% endfor - ip forwarding - ! - #% endblock - """ - - bgpd = """ - #% block main - #% if router.name == 'r1' - router bgp 65001 - bgp router-id 10.10.10.10 - no bgp ebgp-requires-policy - neighbor 192.168.255.1 remote-as 65002 - neighbor 192.168.255.1 timers 3 10 - ! - #% elif router.name == 'r2' - router bgp 65002 - bgp router-id 10.10.10.10 - no bgp ebgp-requires-policy - neighbor 192.168.255.2 remote-as 65001 - neighbor 192.168.255.2 timers 3 10 - neighbor 192.168.255.3 remote-as 65002 - neighbor 192.168.255.3 timers 3 10 - ! - #% elif router.name == 'r3' - router bgp 65002 - bgp router-id 10.10.10.10 - no bgp ebgp-requires-policy - neighbor 192.168.255.1 remote-as 65002 - neighbor 192.168.255.1 timers 3 10 - ! - #% endif - #% endblock - """ - - -class TestBGPAsWideBGPIdentifier(TestBase, AutoFixture, topo=topology, configs=Configs): - @topotatofunc - def bgp_converge(self, _, r1): - expected = {"192.168.255.1": {"bgpState": "Established"}} - yield from AssertVtysh.make( - r1, - "bgpd", - "show ip bgp neighbor 192.168.255.1 json", - maxwait=2.0, - compare=expected, - ) - - @topotatofunc - def bgp_failed(self, _, r3): - expected = { - "192.168.255.1": { - "lastNotificationReason": "OPEN Message Error/Bad BGP Identifier" - } - } - yield from AssertVtysh.make( - r3, - "bgpd", - "show ip bgp neighbor 192.168.255.1 json", - maxwait=2.0, - compare=expected, - ) +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2022 Nathan Mangar + + +""" +rfc6286: Autonomous-System-Wide Unique BGP Identifier for BGP-4 +Test if 'Bad BGP Identifier' notification is sent only to +internal peers (autonomous-system-wide). eBGP peers are not +affected and should work. +""" + +__topotests_file__ = "bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py" +__topotests_gitrev__ = "4953ca977f3a5de8109ee6353ad07f816ca1774c" + +# pylint: disable=wildcard-import, unused-wildcard-import + +from topotato import * + + +@topology_fixture() +def topology(topo): + """ + [ r1 ] + | + { s1 }--[ r3 ] + | + [ r2 ] + + """ + + topo.router("r1").iface_to("s1").ip4.append("192.168.255.2/24") + topo.router("r2").iface_to("s1").ip4.append("192.168.255.1/24") + topo.router("r3").iface_to("s1").ip4.append("192.168.255.3/24") + + +class Configs(FRRConfigs): + routers = ["r1", "r2", "r3"] + + zebra = """ + #% extends "boilerplate.conf" + #% block main + #% for iface in router.ifaces + interface {{ iface.ifname }} + ip address {{ iface.ip4[0] }} + ! + #% endfor + ip forwarding + ! + #% endblock + """ + + bgpd = """ + #% block main + #% if router.name == 'r1' + router bgp 65001 + bgp router-id 10.10.10.10 + no bgp ebgp-requires-policy + neighbor 192.168.255.1 remote-as 65002 + neighbor 192.168.255.1 timers 3 10 + ! + #% elif router.name == 'r2' + router bgp 65002 + bgp router-id 10.10.10.10 + no bgp ebgp-requires-policy + neighbor 192.168.255.2 remote-as 65001 + neighbor 192.168.255.2 timers 3 10 + neighbor 192.168.255.3 remote-as 65002 + neighbor 192.168.255.3 timers 3 10 + ! + #% elif router.name == 'r3' + router bgp 65002 + bgp router-id 10.10.10.10 + no bgp ebgp-requires-policy + neighbor 192.168.255.1 remote-as 65002 + neighbor 192.168.255.1 timers 3 10 + ! + #% endif + #% endblock + """ + + +class TestBGPAsWideBGPIdentifier(TestBase, AutoFixture, topo=topology, configs=Configs): + @topotatofunc + def bgp_converge(self, _, r1): + expected = {"192.168.255.1": {"bgpState": "Established"}} + yield from AssertVtysh.make( + r1, + "bgpd", + "show ip bgp neighbor 192.168.255.1 json", + maxwait=2.0, + compare=expected, + ) + + @topotatofunc + def bgp_failed(self, _, r3): + expected = { + "192.168.255.1": { + "lastNotificationReason": "OPEN Message Error/Bad BGP Identifier" + } + } + yield from AssertVtysh.make( + r3, + "bgpd", + "show ip bgp neighbor 192.168.255.1 json", + maxwait=2.0, + compare=expected, + ) diff --git a/test_bgp_minimum_holdtime.py b/test_bgp_minimum_holdtime.py index a4e37b6..3f45201 100644 --- a/test_bgp_minimum_holdtime.py +++ b/test_bgp_minimum_holdtime.py @@ -1,88 +1,88 @@ -# SPDX-License-Identifier: GPL-2.0-or-later -# Copyright (C) 2022 Nathan Mangar - -""" -Test if minimum-holdtime works. -""" - -__topotests_file__ = "bgp_minimum_holdtime/test_bgp_minimum_holdtime.py" -__topotests_gitrev__ = "4953ca977f3a5de8109ee6353ad07f816ca1774c" - -# pylint: disable=wildcard-import, unused-wildcard-import - -from topotato import * - - -@topology_fixture() -def topology(topo): - """ - [ r1 ] - | - { s1 } - | - [ r2 ] - - """ - - topo.router("r1").iface_to("s1").ip4.append("192.168.255.1/24") - topo.router("r2").iface_to("s1").ip4.append("192.168.255.2/24") - - -class Configs(FRRConfigs): - routers = ["r1", "r2"] - - zebra = """ - #% extends "boilerplate.conf" - #% block main - #% if router.name == 'r1' - interface lo - ip address {{ routers.r1.lo_ip4[0] }} - ! - #% endif - #% for iface in router.ifaces - interface {{ iface.ifname }} - ip address {{ iface.ip4[0] }} - ! - #% endfor - ip forwarding - ! - #% endblock - """ - - bgpd = """ - #% block main - #% if router.name == 'r2' - router bgp 65001 - no bgp ebgp-requires-policy - neighbor 192.168.255.1 remote-as 65000 - neighbor 192.168.255.1 timers 3 10 - ! - #% elif router.name == 'r1' - router bgp 65000 - bgp minimum-holdtime 20 - neighbor 192.168.255.2 remote-as 65001 - neighbor 192.168.255.2 timers 3 10 - neighbor 192.168.255.2 timers connect 10 - ! - #% endif - #% endblock - """ - - -class TestBGPMinimumHoldtime(TestBase, AutoFixture, topo=topology, configs=Configs): - @topotatofunc - def bgp_neighbor_check_if_notification_sent(self, _, r1): - expected = { - "192.168.255.2": { - "connectionsEstablished": 0, - "lastNotificationReason": "OPEN Message Error/Unacceptable Hold Time", - "lastResetDueTo": "BGP Notification send", - } - } - yield from AssertVtysh.make( - r1, - "bgpd", - "show ip bgp neighbor 192.168.255.2 json", - maxwait=3.0, - compare=expected, - ) +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2022 Nathan Mangar + +""" +Test if minimum-holdtime works. +""" + +__topotests_file__ = "bgp_minimum_holdtime/test_bgp_minimum_holdtime.py" +__topotests_gitrev__ = "4953ca977f3a5de8109ee6353ad07f816ca1774c" + +# pylint: disable=wildcard-import, unused-wildcard-import + +from topotato import * + + +@topology_fixture() +def topology(topo): + """ + [ r1 ] + | + { s1 } + | + [ r2 ] + + """ + + topo.router("r1").iface_to("s1").ip4.append("192.168.255.1/24") + topo.router("r2").iface_to("s1").ip4.append("192.168.255.2/24") + + +class Configs(FRRConfigs): + routers = ["r1", "r2"] + + zebra = """ + #% extends "boilerplate.conf" + #% block main + #% if router.name == 'r1' + interface lo + ip address {{ routers.r1.lo_ip4[0] }} + ! + #% endif + #% for iface in router.ifaces + interface {{ iface.ifname }} + ip address {{ iface.ip4[0] }} + ! + #% endfor + ip forwarding + ! + #% endblock + """ + + bgpd = """ + #% block main + #% if router.name == 'r2' + router bgp 65001 + no bgp ebgp-requires-policy + neighbor 192.168.255.1 remote-as 65000 + neighbor 192.168.255.1 timers 3 10 + ! + #% elif router.name == 'r1' + router bgp 65000 + bgp minimum-holdtime 20 + neighbor 192.168.255.2 remote-as 65001 + neighbor 192.168.255.2 timers 3 10 + neighbor 192.168.255.2 timers connect 10 + ! + #% endif + #% endblock + """ + + +class TestBGPMinimumHoldtime(TestBase, AutoFixture, topo=topology, configs=Configs): + @topotatofunc + def bgp_neighbor_check_if_notification_sent(self, _, r1): + expected = { + "192.168.255.2": { + "connectionsEstablished": 0, + "lastNotificationReason": "OPEN Message Error/Unacceptable Hold Time", + "lastResetDueTo": "BGP Notification send", + } + } + yield from AssertVtysh.make( + r1, + "bgpd", + "show ip bgp neighbor 192.168.255.2 json", + maxwait=3.0, + compare=expected, + ) diff --git a/test_bgp_rmap_extcommunity_none.py b/test_bgp_rmap_extcommunity_none.py index 536f568..7b4b270 100644 --- a/test_bgp_rmap_extcommunity_none.py +++ b/test_bgp_rmap_extcommunity_none.py @@ -1,136 +1,136 @@ -# SPDX-License-Identifier: GPL-2.0-or-later -# Copyright (C) 2022 Nathan Mangar - -""" -Test if route-map extcommunity none works: - -route-map permit 10 - set extcommunity none -""" - -__topotests_file__ = "bgp_rmap_extcommunity_none/test_bgp_rmap_extcommunity_none.py" -__topotests_gitrev__ = "4953ca977f3a5de8109ee6353ad07f816ca1774c" - -# pylint: disable=wildcard-import, unused-wildcard-import, trailing-whitespace - -from topotato import * - - -@topology_fixture() -def topology(topo): - """ - [ r1 ] - | - { s1 } - | - [ r2 ] - - """ - topo.router("r2").lo_ip4.append("172.16.16.1/32") - topo.router("r1").iface_to("s1").ip4.append("192.168.1.1/24") - topo.router("r2").iface_to("s1").ip4.append("192.168.1.2/24") - - -class Configs(FRRConfigs): - routers = ["r1", "r2"] - - zebra = """ - #% extends "boilerplate.conf" - #% block main - #% if router.name == 'r2' - interface lo - ip address {{ routers.r2.lo_ip4[0] }} - ! - #% endif - #% for iface in router.ifaces - interface {{ iface.ifname }} - ip address {{ iface.ip4[0] }} - ! - #% endfor - ip forwarding - ! - #% endblock - """ - - bgpd = """ - #% block main - #% if router.name == 'r2' - router bgp 65002 - no bgp ebgp-requires-policy - neighbor 192.168.1.1 remote-as external - address-family ipv4 unicast - redistribute connected - neighbor 192.168.1.1 route-map r1 out - exit-address-family - ! - route-map r1 permit 10 - set community 123:123 - set extcommunity bandwidth 200 - ! - #% elif router.name == 'r1' - router bgp 65001 - no bgp ebgp-requires-policy - neighbor 192.168.1.2 remote-as external - ! - route-map r2 permit 10 - set extcommunity none - ! - #% endif - #% endblock - """ - - -class TestBGPExtCommunity(TestBase, AutoFixture, topo=topology, configs=Configs): - @topotatofunc - def bgp_converge(self, _, r1): - expected = { - "prefix": "172.16.16.1/32", - "paths": [ - { - "community": { - "string": "123:123", - }, - "extendedCommunity": {"string": "LB:65002:25000000 (200.000 Mbps)"}, - } - ], - } - yield from AssertVtysh.make( - r1, - "bgpd", - "show bgp ipv4 unicast 172.16.16.1/32 json", - maxwait=5.0, - compare=expected, - ) - - @topotatofunc - def bgp_extcommunity_strip(self, _, r1): - expected = { - "prefix": "172.16.16.1/32", - "paths": [ - { - "community": { - "string": "123:123", - }, - "extendedCommunity": None, - } - ], - } - yield from AssertVtysh.make( - r1, - "bgpd", - """ - enable - configure terminal - router bgp 65001 - address-family ipv4 - neighbor 192.168.1.2 route-map r2 in - """, - compare="", - ) - yield from AssertVtysh.make( - r1, - "bgpd", - "show bgp ipv4 unicast 172.16.16.1/32 json", - maxwait=5.0, - compare=expected, - ) +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2022 Nathan Mangar + +""" +Test if route-map extcommunity none works: + +route-map permit 10 + set extcommunity none +""" + +__topotests_file__ = "bgp_rmap_extcommunity_none/test_bgp_rmap_extcommunity_none.py" +__topotests_gitrev__ = "4953ca977f3a5de8109ee6353ad07f816ca1774c" + +# pylint: disable=wildcard-import, unused-wildcard-import, trailing-whitespace + +from topotato import * + + +@topology_fixture() +def topology(topo): + """ + [ r1 ] + | + { s1 } + | + [ r2 ] + + """ + topo.router("r2").lo_ip4.append("172.16.16.1/32") + topo.router("r1").iface_to("s1").ip4.append("192.168.1.1/24") + topo.router("r2").iface_to("s1").ip4.append("192.168.1.2/24") + + +class Configs(FRRConfigs): + routers = ["r1", "r2"] + + zebra = """ + #% extends "boilerplate.conf" + #% block main + #% if router.name == 'r2' + interface lo + ip address {{ routers.r2.lo_ip4[0] }} + ! + #% endif + #% for iface in router.ifaces + interface {{ iface.ifname }} + ip address {{ iface.ip4[0] }} + ! + #% endfor + ip forwarding + ! + #% endblock + """ + + bgpd = """ + #% block main + #% if router.name == 'r2' + router bgp 65002 + no bgp ebgp-requires-policy + neighbor 192.168.1.1 remote-as external + address-family ipv4 unicast + redistribute connected + neighbor 192.168.1.1 route-map r1 out + exit-address-family + ! + route-map r1 permit 10 + set community 123:123 + set extcommunity bandwidth 200 + ! + #% elif router.name == 'r1' + router bgp 65001 + no bgp ebgp-requires-policy + neighbor 192.168.1.2 remote-as external + ! + route-map r2 permit 10 + set extcommunity none + ! + #% endif + #% endblock + """ + + +class TestBGPExtCommunity(TestBase, AutoFixture, topo=topology, configs=Configs): + @topotatofunc + def bgp_converge(self, _, r1): + expected = { + "prefix": "172.16.16.1/32", + "paths": [ + { + "community": { + "string": "123:123", + }, + "extendedCommunity": {"string": "LB:65002:25000000 (200.000 Mbps)"}, + } + ], + } + yield from AssertVtysh.make( + r1, + "bgpd", + "show bgp ipv4 unicast 172.16.16.1/32 json", + maxwait=5.0, + compare=expected, + ) + + @topotatofunc + def bgp_extcommunity_strip(self, _, r1): + expected = { + "prefix": "172.16.16.1/32", + "paths": [ + { + "community": { + "string": "123:123", + }, + "extendedCommunity": None, + } + ], + } + yield from AssertVtysh.make( + r1, + "bgpd", + """ + enable + configure terminal + router bgp 65001 + address-family ipv4 + neighbor 192.168.1.2 route-map r2 in + """, + compare="", + ) + yield from AssertVtysh.make( + r1, + "bgpd", + "show bgp ipv4 unicast 172.16.16.1/32 json", + maxwait=5.0, + compare=expected, + ) diff --git a/test_bgp_route_map_match_ipv6_nexthop.py b/test_bgp_route_map_match_ipv6_nexthop.py index c8b3832..0713efd 100644 --- a/test_bgp_route_map_match_ipv6_nexthop.py +++ b/test_bgp_route_map_match_ipv6_nexthop.py @@ -1,173 +1,173 @@ -# SPDX-License-Identifier: GPL-2.0-or-later -# Copyright (C) 2022 Nathan Mangar - - -""" -Test if we can match BGP prefixes by next-hop which is -specified by an IPv6 Access-list, prefix-list or just an address. -""" - -__topotests_file__ = ( - "bgp_route_map_match_ipv6_nexthop/test_bgp_route_map_match_ipv6_nexthop.py" -) -__topotests_gitrev__ = "c75d6ccbfe95d2708618ade7cc7198e46ee467dd" - -# pylint: disable=wildcard-import, unused-wildcard-import - -from topotato import * - - -@topology_fixture() -def topology(topo): - """ - [ r1 ] - | - { s1 } - | - [ r2 ] - - """ - - topo.router("r1").iface_to("s1").ip6.append("2001:db8::1/64") - topo.router("r2").iface_to("s1").ip6.append("2001:db8::2/64") - - -class Configs(FRRConfigs): - routers = ["r1", "r2"] - - zebra = """ - #% extends "boilerplate.conf" - #% block main - #% if router.name == 'r1' - interface r1-eth0 - ipv6 address 2001:db8::1/64 - ! - #% endif - #% if router.name == 'r2' - interface lo - ipv6 address 2001:db8:1::1/128 - ipv6 address 2001:db8:2::1/128 - ipv6 address 2001:db8:3::1/128 - ipv6 address 2001:db8:4::1/128 - ipv6 address 2001:db8:5::1/128 - ! - interface r2-eth0 - ip address 2001:db8::2/64 - ! - #% endif - #% endblock - """ - - bgpd = """ - #% block main - #% if router.name == 'r2' - ! - bgp send-extra-data zebra - ! - router bgp 65002 - bgp router-id 10.10.10.2 - no bgp ebgp-requires-policy - neighbor 2001:db8::1 remote-as external - address-family ipv6 unicast - redistribute connected - neighbor 2001:db8::1 activate - neighbor 2001:db8::1 route-map r1 out - exit-address-family - ! - ipv6 prefix-list p1 permit 2001:db8:1::1/128 - ipv6 prefix-list p2 permit 2001:db8:2::1/128 - ipv6 prefix-list p3 permit 2001:db8:3::1/128 - ipv6 prefix-list p4 permit 2001:db8:4::1/128 - ipv6 prefix-list p5 permit 2001:db8:5::1/128 - ! - route-map r1 permit 10 - match ipv6 address prefix-list p1 - set ipv6 next-hop global 2001:db8:1::1 - route-map r1 permit 20 - match ipv6 address prefix-list p2 - set ipv6 next-hop global 2001:db8:2::1 - route-map r1 permit 30 - match ipv6 address prefix-list p3 - set ipv6 next-hop global 2001:db8:3::1 - route-map r1 permit 40 - match ipv6 address prefix-list p4 - set ipv6 next-hop global 2001:db8:4::1 - route-map r1 permit 50 - match ipv6 address prefix-list p5 - set ipv6 next-hop global 2001:db8:5::1 - ! - #% elif router.name == 'r1' - ! - bgp send-extra-data zebra - ! - ipv6 access-list nh1 permit 2001:db8:1::/64 - ipv6 access-list nh2 permit 2001:db8:2::/64 - ipv6 access-list nh3 permit 2001:db8:3::/64 - ! - ipv6 prefix-list nh4 permit 2001:db8:5::/64 le 128 - ! - router bgp 65001 - bgp router-id 10.10.10.1 - no bgp ebgp-requires-policy - neighbor 2001:db8::2 remote-as external - address-family ipv6 unicast - neighbor 2001:db8::2 activate - neighbor 2001:db8::2 route-map r2 in - exit-address-family - ! - route-map r2 permit 10 - match ipv6 next-hop nh1 - set community 65002:1 - route-map r2 permit 20 - match ipv6 next-hop nh2 - set community 65002:2 - route-map r2 permit 30 - match ipv6 next-hop nh3 - set community 65002:3 - route-map r2 permit 40 - match ipv6 next-hop address 2001:db8:4::1 - set community 65002:4 - route-map r2 permit 50 - match ipv6 next-hop prefix-list nh4 - set community 65002:5 - ! - #% endif - #% endblock - """ - - -class TestBGPRouteMapMatchIPV6NextHopAccessList( - TestBase, AutoFixture, topo=topology, configs=Configs -): - @topotatofunc - def bgp_converge(self, _, r1): - expected = { - "2001:db8:1::1/128": [ - { - "communities": "65002:1", - } - ], - "2001:db8:2::1/128": [ - { - "communities": "65002:2", - } - ], - "2001:db8:3::1/128": [ - { - "communities": "65002:3", - } - ], - "2001:db8:4::1/128": [ - { - "communities": "65002:4", - } - ], - "2001:db8:5::1/128": [ - { - "communities": "65002:5", - } - ], - } - yield from AssertVtysh.make( - r1, "zebra", "show ipv6 route json", maxwait=6.0, compare=expected - ) +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2022 Nathan Mangar + + +""" +Test if we can match BGP prefixes by next-hop which is +specified by an IPv6 Access-list, prefix-list or just an address. +""" + +__topotests_file__ = ( + "bgp_route_map_match_ipv6_nexthop/test_bgp_route_map_match_ipv6_nexthop.py" +) +__topotests_gitrev__ = "c75d6ccbfe95d2708618ade7cc7198e46ee467dd" + +# pylint: disable=wildcard-import, unused-wildcard-import + +from topotato import * + + +@topology_fixture() +def topology(topo): + """ + [ r1 ] + | + { s1 } + | + [ r2 ] + + """ + + topo.router("r1").iface_to("s1").ip6.append("2001:db8::1/64") + topo.router("r2").iface_to("s1").ip6.append("2001:db8::2/64") + + +class Configs(FRRConfigs): + routers = ["r1", "r2"] + + zebra = """ + #% extends "boilerplate.conf" + #% block main + #% if router.name == 'r1' + interface r1-eth0 + ipv6 address 2001:db8::1/64 + ! + #% endif + #% if router.name == 'r2' + interface lo + ipv6 address 2001:db8:1::1/128 + ipv6 address 2001:db8:2::1/128 + ipv6 address 2001:db8:3::1/128 + ipv6 address 2001:db8:4::1/128 + ipv6 address 2001:db8:5::1/128 + ! + interface r2-eth0 + ip address 2001:db8::2/64 + ! + #% endif + #% endblock + """ + + bgpd = """ + #% block main + #% if router.name == 'r2' + ! + bgp send-extra-data zebra + ! + router bgp 65002 + bgp router-id 10.10.10.2 + no bgp ebgp-requires-policy + neighbor 2001:db8::1 remote-as external + address-family ipv6 unicast + redistribute connected + neighbor 2001:db8::1 activate + neighbor 2001:db8::1 route-map r1 out + exit-address-family + ! + ipv6 prefix-list p1 permit 2001:db8:1::1/128 + ipv6 prefix-list p2 permit 2001:db8:2::1/128 + ipv6 prefix-list p3 permit 2001:db8:3::1/128 + ipv6 prefix-list p4 permit 2001:db8:4::1/128 + ipv6 prefix-list p5 permit 2001:db8:5::1/128 + ! + route-map r1 permit 10 + match ipv6 address prefix-list p1 + set ipv6 next-hop global 2001:db8:1::1 + route-map r1 permit 20 + match ipv6 address prefix-list p2 + set ipv6 next-hop global 2001:db8:2::1 + route-map r1 permit 30 + match ipv6 address prefix-list p3 + set ipv6 next-hop global 2001:db8:3::1 + route-map r1 permit 40 + match ipv6 address prefix-list p4 + set ipv6 next-hop global 2001:db8:4::1 + route-map r1 permit 50 + match ipv6 address prefix-list p5 + set ipv6 next-hop global 2001:db8:5::1 + ! + #% elif router.name == 'r1' + ! + bgp send-extra-data zebra + ! + ipv6 access-list nh1 permit 2001:db8:1::/64 + ipv6 access-list nh2 permit 2001:db8:2::/64 + ipv6 access-list nh3 permit 2001:db8:3::/64 + ! + ipv6 prefix-list nh4 permit 2001:db8:5::/64 le 128 + ! + router bgp 65001 + bgp router-id 10.10.10.1 + no bgp ebgp-requires-policy + neighbor 2001:db8::2 remote-as external + address-family ipv6 unicast + neighbor 2001:db8::2 activate + neighbor 2001:db8::2 route-map r2 in + exit-address-family + ! + route-map r2 permit 10 + match ipv6 next-hop nh1 + set community 65002:1 + route-map r2 permit 20 + match ipv6 next-hop nh2 + set community 65002:2 + route-map r2 permit 30 + match ipv6 next-hop nh3 + set community 65002:3 + route-map r2 permit 40 + match ipv6 next-hop address 2001:db8:4::1 + set community 65002:4 + route-map r2 permit 50 + match ipv6 next-hop prefix-list nh4 + set community 65002:5 + ! + #% endif + #% endblock + """ + + +class TestBGPRouteMapMatchIPV6NextHopAccessList( + TestBase, AutoFixture, topo=topology, configs=Configs +): + @topotatofunc + def bgp_converge(self, _, r1): + expected = { + "2001:db8:1::1/128": [ + { + "communities": "65002:1", + } + ], + "2001:db8:2::1/128": [ + { + "communities": "65002:2", + } + ], + "2001:db8:3::1/128": [ + { + "communities": "65002:3", + } + ], + "2001:db8:4::1/128": [ + { + "communities": "65002:4", + } + ], + "2001:db8:5::1/128": [ + { + "communities": "65002:5", + } + ], + } + yield from AssertVtysh.make( + r1, "zebra", "show ipv6 route json", maxwait=6.0, compare=expected + )