|
| 1 | +# SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | +# Copyright (C) 2023 Nathan Mangar |
| 3 | + |
| 4 | +""" |
| 5 | +bgp_local_as_private_remove.py: |
| 6 | +Test if primary AS number is not removed in cases when `local-as` |
| 7 | +used together with `remove-private-AS`. |
| 8 | +""" |
| 9 | + |
| 10 | + |
| 11 | +__topotests_file__ = "bgp_local_as_private_remove/test_bgp_local_as_private_remove.py" |
| 12 | +__topotests_gitrev__ = "acddc0ed3ce0833490b7ef38ed000d54388ebea4" |
| 13 | + |
| 14 | +# pylint: disable=invalid-name, missing-class-docstring, missing-function-docstring, line-too-long, consider-using-f-string, wildcard-import, unused-wildcard-import, f-string-without-interpolation, too-few-public-methods |
| 15 | + |
| 16 | +from topotato import * |
| 17 | + |
| 18 | + |
| 19 | +@topology_fixture() |
| 20 | +def topology(topo): |
| 21 | + """ |
| 22 | + [ r1 ] |
| 23 | + | |
| 24 | + [ r4 ]--{ s1 }--[ r2 ] |
| 25 | + | | |
| 26 | + { s2 }--[ r3 ] |
| 27 | + """ |
| 28 | + |
| 29 | + topo.router("r1").lo_ip4.append("172.16.255.254/32") |
| 30 | + topo.router("r3").lo_ip4.append("172.16.255.255/32") |
| 31 | + topo.router("r1").iface_to("s1").ip4.append("192.168.255.1/24") |
| 32 | + topo.router("r2").iface_to("s1").ip4.append("192.168.255.2/24") |
| 33 | + topo.router("r3").iface_to("s1").ip4.append("192.168.255.1/24") |
| 34 | + topo.router("r4").iface_to("s1").ip4.append("192.168.255.3/24") |
| 35 | + |
| 36 | + |
| 37 | +class Configs(FRRConfigs): |
| 38 | + routers = ["r1", "r2", "r3", "r4"] |
| 39 | + |
| 40 | + zebra = """ |
| 41 | + #% extends "boilerplate.conf" |
| 42 | + #% block main |
| 43 | + #% for iface in router.ifaces |
| 44 | + interface {{ iface.ifname }} |
| 45 | + ip address {{ iface.ip4[0] }} |
| 46 | + ! |
| 47 | + #% endfor |
| 48 | + ip forwarding |
| 49 | + ! |
| 50 | + #% endblock |
| 51 | + """ |
| 52 | + |
| 53 | + bgpd = """ |
| 54 | + #% block main |
| 55 | + #% if router.name == 'r1' |
| 56 | + router bgp 65000 |
| 57 | + no bgp ebgp-requires-policy |
| 58 | + neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} remote-as 1000 |
| 59 | + neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} timers 3 10 |
| 60 | + neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} local-as 500 |
| 61 | + address-family ipv4 unicast |
| 62 | + neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} remove-private-AS |
| 63 | + redistribute connected |
| 64 | + exit-address-family |
| 65 | + ! |
| 66 | + #% elif router.name == 'r2' |
| 67 | + router bgp 1000 |
| 68 | + no bgp ebgp-requires-policy |
| 69 | + neighbor {{ routers.r1.iface_to('s1').ip4[0].ip }} remote-as 500 |
| 70 | + neighbor {{ routers.r1.iface_to('s1').ip4[0].ip }} timers 3 10 |
| 71 | + ! |
| 72 | + #% elif router.name == 'r3' |
| 73 | + router bgp 3000 |
| 74 | + no bgp ebgp-requires-policy |
| 75 | + neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} remote-as 1000 |
| 76 | + neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} timers 3 10 |
| 77 | + neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} local-as 500 |
| 78 | + address-family ipv4 unicast |
| 79 | + neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} remove-private-AS |
| 80 | + redistribute connected |
| 81 | + exit-address-family |
| 82 | + ! |
| 83 | + #% elif router.name == 'r4' |
| 84 | + router bgp 1000 |
| 85 | + no bgp ebgp-requires-policy |
| 86 | + neighbor {{ routers.r1.iface_to('s1').ip4[0].ip }} remote-as 500 |
| 87 | + neighbor {{ routers.r1.iface_to('s1').ip4[0].ip }} timers 3 10 |
| 88 | + ! |
| 89 | + #% endif |
| 90 | + #% endblock |
| 91 | + """ |
| 92 | + |
| 93 | + |
| 94 | +class BGPLocalAsPrivateRemove(TestBase, AutoFixture, topo=topology, configs=Configs): |
| 95 | + @topotatofunc |
| 96 | + def bgp_converge(self, _, r1, r2): |
| 97 | + expected = { |
| 98 | + str(r1.iface_to("s1").ip4[0].ip): { |
| 99 | + "bgpState": "Established", |
| 100 | + } |
| 101 | + } |
| 102 | + yield from AssertVtysh.make( |
| 103 | + r2, |
| 104 | + "bgpd", |
| 105 | + f"show ip bgp neighbor {r1.iface_to('s1').ip4[0].ip} json", |
| 106 | + maxwait=5.0, |
| 107 | + compare=expected, |
| 108 | + ) |
| 109 | + |
| 110 | + @topotatofunc |
| 111 | + def bgp_as_path_r2(self, _, r1, r2): |
| 112 | + expected = { |
| 113 | + "paths": [ |
| 114 | + { |
| 115 | + "aspath": { |
| 116 | + "string": "500", |
| 117 | + "length": 1, |
| 118 | + } |
| 119 | + } |
| 120 | + ] |
| 121 | + } |
| 122 | + yield from AssertVtysh.make( |
| 123 | + r2, |
| 124 | + "bgpd", |
| 125 | + f"show ip bgp 172.16.255.254/32 json", |
| 126 | + maxwait=5.0, |
| 127 | + compare=expected, |
| 128 | + ) |
| 129 | + |
| 130 | + @topotatofunc |
| 131 | + def bgp_as_path_r4(self, _, r1, r2, r4): |
| 132 | + expected = { |
| 133 | + "paths": [ |
| 134 | + { |
| 135 | + "aspath": { |
| 136 | + "string": "500 3000", |
| 137 | + "length": 2, |
| 138 | + } |
| 139 | + } |
| 140 | + ] |
| 141 | + } |
| 142 | + yield from AssertVtysh.make( |
| 143 | + r4, |
| 144 | + "bgpd", |
| 145 | + f"show ip bgp 172.16.255.254/32 json", |
| 146 | + maxwait=5.0, |
| 147 | + compare=expected, |
| 148 | + ) |
0 commit comments