Skip to content

Commit

Permalink
topotato: wip test_bgp_local_as_private_remove.py
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Mangar <[email protected]>
  • Loading branch information
Nathan Mangar committed Aug 25, 2023
1 parent 59d16e7 commit 1d65d51
Showing 1 changed file with 148 additions and 0 deletions.
148 changes: 148 additions & 0 deletions test_bgp_local_as_private_remove.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2023 Nathan Mangar

"""
bgp_local_as_private_remove.py:
Test if primary AS number is not removed in cases when `local-as`
used together with `remove-private-AS`.
"""


__topotests_file__ = "bgp_local_as_private_remove/test_bgp_local_as_private_remove.py"
__topotests_gitrev__ = "acddc0ed3ce0833490b7ef38ed000d54388ebea4"

# 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

from topotato import *


@topology_fixture()
def topology(topo):
"""
[ r1 ]
|
[ r4 ]--{ s1 }--[ r2 ]
| |
{ s2 }--[ r3 ]
"""

topo.router("r1").lo_ip4.append("172.16.255.254/32")
topo.router("r3").lo_ip4.append("172.16.255.255/32")
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")
topo.router("r3").iface_to("s1").ip4.append("192.168.255.1/24")
topo.router("r4").iface_to("s1").ip4.append("192.168.255.3/24")


class Configs(FRRConfigs):
routers = ["r1", "r2", "r3", "r4"]

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 65000
no bgp ebgp-requires-policy
neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} remote-as 1000
neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} timers 3 10
neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} local-as 500
address-family ipv4 unicast
neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} remove-private-AS
redistribute connected
exit-address-family
!
#% elif router.name == 'r2'
router bgp 1000
no bgp ebgp-requires-policy
neighbor {{ routers.r1.iface_to('s1').ip4[0].ip }} remote-as 500
neighbor {{ routers.r1.iface_to('s1').ip4[0].ip }} timers 3 10
!
#% elif router.name == 'r3'
router bgp 3000
no bgp ebgp-requires-policy
neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} remote-as 1000
neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} timers 3 10
neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} local-as 500
address-family ipv4 unicast
neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} remove-private-AS
redistribute connected
exit-address-family
!
#% elif router.name == 'r4'
router bgp 1000
no bgp ebgp-requires-policy
neighbor {{ routers.r1.iface_to('s1').ip4[0].ip }} remote-as 500
neighbor {{ routers.r1.iface_to('s1').ip4[0].ip }} timers 3 10
!
#% endif
#% endblock
"""


class BGPLocalAsPrivateRemove(TestBase, AutoFixture, topo=topology, configs=Configs):
@topotatofunc
def bgp_converge(self, _, r1, r2):
expected = {
str(r1.iface_to("s1").ip4[0].ip): {
"bgpState": "Established",
}
}
yield from AssertVtysh.make(
r2,
"bgpd",
f"show ip bgp neighbor {r1.iface_to('s1').ip4[0].ip} json",
maxwait=5.0,
compare=expected,
)

@topotatofunc
def bgp_as_path_r2(self, _, r1, r2):
expected = {
"paths": [
{
"aspath": {
"string": "500",
"length": 1,
}
}
]
}
yield from AssertVtysh.make(
r2,
"bgpd",
f"show ip bgp 172.16.255.254/32 json",
maxwait=5.0,
compare=expected,
)

@topotatofunc
def bgp_as_path_r4(self, _, r1, r2, r4):
expected = {
"paths": [
{
"aspath": {
"string": "500 3000",
"length": 2,
}
}
]
}
yield from AssertVtysh.make(
r4,
"bgpd",
f"show ip bgp 172.16.255.254/32 json",
maxwait=5.0,
compare=expected,
)

0 comments on commit 1d65d51

Please sign in to comment.