|
1 | | -{ ... }: |
| 1 | +{ inputs, ... }: |
2 | 2 | { |
3 | 3 | name = "bgp-extended-nexthop"; |
4 | 4 |
|
| 5 | + # required in node c - gobgp module |
| 6 | + node.pkgsReadOnly = false; |
| 7 | + |
5 | 8 | defaults = { |
6 | 9 | networking.firewall.allowedTCPPorts = [ 179 ]; |
7 | 10 | }; |
|
29 | 32 | neighbor fe80::2 capability extended-nexthop |
30 | 33 | neighbor fe80::2 interface eth1 |
31 | 34 |
|
| 35 | + neighbor fe80::3 remote-as 64498 |
| 36 | + neighbor fe80::3 capability extended-nexthop |
| 37 | + neighbor fe80::3 interface eth1 |
| 38 | +
|
32 | 39 | address-family ipv4 unicast |
33 | 40 | network 198.51.100.0/25 |
34 | 41 | neighbor fe80::2 activate |
| 42 | + neighbor fe80::3 activate |
35 | 43 | exit-address-family |
36 | 44 |
|
37 | 45 | address-family ipv6 unicast |
38 | 46 | network 2001:db8:beef::/48 |
39 | 47 | neighbor fe80::2 activate |
| 48 | + neighbor fe80::3 activate |
40 | 49 | exit-address-family |
41 | 50 | ''; |
42 | 51 | }; |
|
102 | 111 | export all; |
103 | 112 | }; |
104 | 113 | } |
| 114 | +
|
| 115 | + protocol bgp c { |
| 116 | + local as 64497; |
| 117 | + neighbor fe80::3 as 64498; |
| 118 | + interface "eth1"; |
| 119 | +
|
| 120 | + ipv4 { |
| 121 | + extended next hop on; |
| 122 | + import all; |
| 123 | + export all; |
| 124 | + }; |
| 125 | +
|
| 126 | + ipv6 { |
| 127 | + import all; |
| 128 | + export all; |
| 129 | + }; |
| 130 | + } |
105 | 131 | ''; |
106 | 132 | }; |
107 | 133 | }; |
| 134 | + c = { |
| 135 | + imports = [ inputs.gobgp.nixosModules.gobgp ]; |
| 136 | + networking.interfaces = { |
| 137 | + eth1.ipv6.addresses = [ |
| 138 | + { |
| 139 | + address = "fe80::3"; |
| 140 | + prefixLength = 64; |
| 141 | + } |
| 142 | + ]; |
| 143 | + lo = { |
| 144 | + ipv4.routes = [ |
| 145 | + { |
| 146 | + address = "203.0.113.0"; |
| 147 | + prefixLength = 24; |
| 148 | + } |
| 149 | + ]; |
| 150 | + ipv6.routes = [ |
| 151 | + { |
| 152 | + address = "2001:db8:dead::"; |
| 153 | + prefixLength = 48; |
| 154 | + } |
| 155 | + ]; |
| 156 | + }; |
| 157 | + }; |
| 158 | + services.gobgpd = { |
| 159 | + enable = true; |
| 160 | + zebra = true; |
| 161 | + config = { |
| 162 | + global = { |
| 163 | + as = 64498; |
| 164 | + router-id = "192.0.2.3"; |
| 165 | + apply-policy = { |
| 166 | + default-import-policy = "accept-route"; |
| 167 | + export-policy-list = [ "c-out" ]; |
| 168 | + default-export-policy = "reject-route"; |
| 169 | + }; |
| 170 | + }; |
| 171 | + zebra = { |
| 172 | + enabled = true; |
| 173 | + redistribute-route-type-list = [ |
| 174 | + "kernel" |
| 175 | + "directly-connected" |
| 176 | + "static" |
| 177 | + ]; |
| 178 | + }; |
| 179 | + neighbors = { |
| 180 | + "a" = { |
| 181 | + neighbor-address = "fe80::1%eth1"; |
| 182 | + peer-as = 64496; |
| 183 | + afi-safis = { |
| 184 | + "ipv4-unicast" = { }; |
| 185 | + "ipv6-unicast" = { }; |
| 186 | + }; |
| 187 | + }; |
| 188 | + "b" = { |
| 189 | + neighbor-address = "fe80::2%eth1"; |
| 190 | + peer-as = 64497; |
| 191 | + afi-safis = { |
| 192 | + "ipv4-unicast" = { }; |
| 193 | + "ipv6-unicast" = { }; |
| 194 | + }; |
| 195 | + }; |
| 196 | + }; |
| 197 | + defined-sets.prefix-sets = { |
| 198 | + "c-out-ipv4".prefix-list = [ |
| 199 | + { |
| 200 | + ip-prefix = "203.0.113.0/24"; |
| 201 | + masklength-range = "24..32"; |
| 202 | + } |
| 203 | + ]; |
| 204 | + "c-out-ipv6".prefix-list = [ |
| 205 | + { |
| 206 | + ip-prefix = "2001:db8:dead::/48"; |
| 207 | + masklength-range = "48..128"; |
| 208 | + } |
| 209 | + ]; |
| 210 | + }; |
| 211 | + policy-definitions."c-out" = { |
| 212 | + statements = { |
| 213 | + "c-out-ipv4" = { |
| 214 | + actions.route-disposition = "accept-route"; |
| 215 | + conditions = { |
| 216 | + match-prefix-set = { |
| 217 | + prefix-set = "c-out-ipv4"; |
| 218 | + match-set-options = "any"; |
| 219 | + }; |
| 220 | + }; |
| 221 | + }; |
| 222 | + "c-out-ipv6" = { |
| 223 | + actions.route-disposition = "accept-route"; |
| 224 | + conditions = { |
| 225 | + match-prefix-set = { |
| 226 | + prefix-set = "c-out-ipv6"; |
| 227 | + match-set-options = "any"; |
| 228 | + }; |
| 229 | + }; |
| 230 | + }; |
| 231 | + }; |
| 232 | + }; |
| 233 | + }; |
| 234 | + }; |
| 235 | + }; |
108 | 236 | }; |
109 | 237 |
|
110 | 238 | testScript = '' |
|
117 | 245 | b.wait_for_unit("bird.service") |
118 | 246 |
|
119 | 247 | with subtest("ensure bgp sessions are established"): |
120 | | - a.wait_until_succeeds("vtysh -c 'show bgp ipv4 summary' | grep 'fe80::2.*1\\s*2\\s*N/A'") |
121 | | - a.wait_until_succeeds("vtysh -c 'show bgp ipv6 summary' | grep 'fe80::2.*1\\s*2\\s*N/A'") |
| 248 | + a.sleep(10) |
| 249 | + print(a.succeed("vtysh -c 'show bgp summary'")) |
| 250 | + print(c.succeed("gobgp neighbor")) |
| 251 | + a.wait_until_succeeds("vtysh -c 'show bgp ipv4 summary' | grep 'fe80::2.*2\\s*3\\s*N/A'") |
| 252 | + a.wait_until_succeeds("vtysh -c 'show bgp ipv4 summary' | grep 'fe80::3.*1\\s*3\\s*N/A'") |
122 | 253 | b.wait_until_succeeds("birdc show protocols | grep 'a.*Established'") |
| 254 | + b.wait_until_succeeds("birdc show protocols | grep 'c.*Established'") |
| 255 | + c.wait_until_succeeds("gobgp neighbor -a 'ipv4' | grep 'fe80::1%eth1.*Establ.*|.*3.*2'") |
| 256 | + c.wait_until_succeeds("gobgp neighbor -a 'ipv4' | grep 'fe80::2%eth1.*Establ.*|.*2.*2'") |
| 257 | +
|
| 258 | + # IPv6 DAD might need some time to complete for the local link address, which is required by frr |
| 259 | + a.wait_until_succeeds("vtysh -c 'show bgp ipv6 summary' | grep 'fe80::2.*2\\s*3\\s*N/A'") |
| 260 | + a.wait_until_succeeds("vtysh -c 'show bgp ipv6 summary' | grep 'fe80::3.*1\\s*3\\s*N/A'") |
| 261 | + c.wait_until_succeeds("gobgp neighbor -a 'ipv6' | grep 'fe80::1%eth1.*Establ.*|.*3.*2'") |
| 262 | + c.wait_until_succeeds("gobgp neighbor -a 'ipv6' | grep 'fe80::2%eth1.*Establ.*|.*2.*2'") |
123 | 263 |
|
124 | 264 | with subtest("ensure routes have been installed"): |
125 | | - a.succeed("ip route show | grep 198.51.100.128/25") |
126 | 265 | b.succeed("ip route show | grep 198.51.100.0/25") |
127 | | - a.succeed("ip -6 route show | grep 2001:db8:c0de::/48") |
| 266 | + c.succeed("ip route show | grep 198.51.100.0/25") |
| 267 | + a.succeed("ip route show | grep 198.51.100.128/25") |
| 268 | + # c.succeed("ip route show | grep 198.51.100.128/25") |
| 269 | + a.succeed("ip route show | grep 203.0.113.0/24") |
| 270 | + b.succeed("ip route show | grep 203.0.113.0/24") |
128 | 271 | b.succeed("ip -6 route show | grep 2001:db8:beef::/48") |
| 272 | + c.succeed("ip -6 route show | grep 2001:db8:beef::/48") |
| 273 | + a.succeed("ip -6 route show | grep 2001:db8:c0de::/48") |
| 274 | + # c.succeed("ip -6 route show | grep 2001:db8:c0de::/48") |
| 275 | + a.succeed("ip -6 route show | grep 2001:db8:dead::/48") |
| 276 | + b.succeed("ip -6 route show | grep 2001:db8:dead::/48") |
129 | 277 | ''; |
130 | 278 | } |
0 commit comments