|
| 1 | +# SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | +# Copyright (C) 2023 Nathan Mangar |
| 3 | + |
| 4 | +""" |
| 5 | +Check if `bgp default-originate timer` commands takes an effect: |
| 6 | +1. Set bgp default-originate timer 3600 |
| 7 | +2. No default route is advertised because the timer is running for 3600 seconds |
| 8 | +3. We reduce it to 10 seconds |
| 9 | +4. Default route is advertised |
| 10 | +""" |
| 11 | + |
| 12 | + |
| 13 | +__topotests_replaces__ = { |
| 14 | + "bgp_default_originate_timer/": "1bfbdc17f20fe4e9d66c9adcbfa48b7a7adfdc29", |
| 15 | +} |
| 16 | + |
| 17 | +# 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, unused-argument, attribute-defined-outside-init |
| 18 | +from topotato.v1 import * |
| 19 | + |
| 20 | + |
| 21 | +@topology_fixture() |
| 22 | +def topology(topo): |
| 23 | + """ |
| 24 | + [ r1 ] |
| 25 | + | |
| 26 | + [ r2 ] |
| 27 | + | |
| 28 | + [ r3 ] |
| 29 | + """ |
| 30 | + |
| 31 | + |
| 32 | +class Configs(FRRConfigs): |
| 33 | + routers = ["r1", "r2", "r3"] |
| 34 | + |
| 35 | + zebra = """ |
| 36 | + #% extends "boilerplate.conf" |
| 37 | + ## nothing needed |
| 38 | + """ |
| 39 | + |
| 40 | + bgpd = """ |
| 41 | + #% extends "boilerplate.conf" |
| 42 | + #% block main |
| 43 | + #% if router.name == 'r1' |
| 44 | + router bgp 65001 |
| 45 | + no bgp ebgp-requires-policy |
| 46 | + bgp default-originate timer 3600 |
| 47 | + neighbor {{ routers.r2.ifaces[0].ip4[0].ip }} remote-as external |
| 48 | + neighbor {{ routers.r2.ifaces[0].ip4[0].ip }} timers 1 3 |
| 49 | + neighbor {{ routers.r2.ifaces[0].ip4[0].ip }} timers connect 1 |
| 50 | + neighbor {{ routers.r3.ifaces[0].ip4[0].ip }} remote-as external |
| 51 | + neighbor {{ routers.r3.ifaces[0].ip4[0].ip }} timers 1 3 |
| 52 | + neighbor {{ routers.r3.ifaces[0].ip4[0].ip }} timers connect 1 |
| 53 | + address-family ipv4 |
| 54 | + neighbor {{ routers.r2.ifaces[0].ip4[0].ip }} default-originate route-map default |
| 55 | + exit-address-family |
| 56 | + ! |
| 57 | + bgp community-list standard r3 seq 5 permit 65003:1 |
| 58 | + ! |
| 59 | + route-map default permit 10 |
| 60 | + match community r3 |
| 61 | + exit |
| 62 | + #% elif router.name == 'r2' |
| 63 | + router bgp 65002 |
| 64 | + no bgp ebgp-requires-policy |
| 65 | + neighbor {{ routers.r1.ifaces[0].ip4[0].ip }} remote-as external |
| 66 | + neighbor {{ routers.r1.ifaces[0].ip4[0].ip }} timers 1 3 |
| 67 | + neighbor {{ routers.r1.ifaces[0].ip4[0].ip }} timers connect 1 |
| 68 | + ! |
| 69 | + #% elif router.name == 'r3' |
| 70 | + router bgp 65003 |
| 71 | + no bgp ebgp-requires-policy |
| 72 | + neighbor {{ routers.r1.ifaces[0].ip4[0].ip }} remote-as external |
| 73 | + neighbor {{ routers.r1.ifaces[0].ip4[0].ip }} timers 1 3 |
| 74 | + neighbor {{ routers.r1.ifaces[0].ip4[0].ip }} timers connect 1 |
| 75 | + address-family ipv4 unicast |
| 76 | + redistribute connected route-map r1 |
| 77 | + exit-address-family |
| 78 | + ! |
| 79 | + route-map r1 permit 10 |
| 80 | + set community 65003:1 |
| 81 | + exit |
| 82 | + #% endif |
| 83 | + #% endblock |
| 84 | + """ |
| 85 | + |
| 86 | + |
| 87 | +class BGPDefaultOriginateTimer(TestBase, AutoFixture, topo=topology, configs=Configs): |
| 88 | + # Negative check function not yet implemented |
| 89 | + # |
| 90 | + # @topotatofunc |
| 91 | + # def bgp_default_received_from_r1(self, _, r1, r2): |
| 92 | + # expected = { |
| 93 | + # "paths": [ |
| 94 | + # { |
| 95 | + # "nexthops": [ |
| 96 | + # { |
| 97 | + # "hostname": "r1", |
| 98 | + # "ip": str(r1.iface_to("s1").ip4[0].ip), |
| 99 | + # } |
| 100 | + # ], |
| 101 | + # } |
| 102 | + # ], |
| 103 | + # } |
| 104 | + |
| 105 | + # yield from AssertVtysh.make( |
| 106 | + # r2, |
| 107 | + # "bgpd", |
| 108 | + # f"show bgp ipv4 unicast 0.0.0.0/0 json", |
| 109 | + # maxwait=30.0, |
| 110 | + # compare=expected, |
| 111 | + # ) |
| 112 | + |
| 113 | + @topotatofunc |
| 114 | + def bgp_default_received_from_r1_2(self, _, r1, r2, r3): |
| 115 | + expected = { |
| 116 | + "paths": [ |
| 117 | + { |
| 118 | + "nexthops": [ |
| 119 | + { |
| 120 | + "hostname": "r1", |
| 121 | + "ip": str(r1.ifaces[0].ip4[0].ip), |
| 122 | + } |
| 123 | + ], |
| 124 | + } |
| 125 | + ], |
| 126 | + } |
| 127 | + |
| 128 | + yield from ReconfigureFRR.make( |
| 129 | + r1, |
| 130 | + "bgpd", |
| 131 | + """ |
| 132 | + router bgp |
| 133 | + bgp default-originate timer 10 |
| 134 | + """, |
| 135 | + compare="", |
| 136 | + ) |
| 137 | + |
| 138 | + yield from ReconfigureFRR.make( |
| 139 | + r3, |
| 140 | + "bgpd", |
| 141 | + """ |
| 142 | + route-map r1 permit 10 |
| 143 | + set metric 1 |
| 144 | + """, |
| 145 | + compare="", |
| 146 | + ) |
| 147 | + |
| 148 | + yield from AssertVtysh.make( |
| 149 | + r2, |
| 150 | + "bgpd", |
| 151 | + f"show bgp ipv4 unicast 0.0.0.0/0 json", |
| 152 | + maxwait=20.0, |
| 153 | + compare=expected, |
| 154 | + ) |
0 commit comments