Skip to content

Commit eac3579

Browse files
committed
tests/bgp-extended-nexthop: add gobgp
1 parent f01d645 commit eac3579

File tree

1 file changed

+153
-5
lines changed

1 file changed

+153
-5
lines changed

tests/bgp-extended-nexthop/default.nix

Lines changed: 153 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
{ ... }:
1+
{ inputs, ... }:
22
{
33
name = "bgp-extended-nexthop";
44

5+
# required in node c - gobgp module
6+
node.pkgsReadOnly = false;
7+
58
defaults = {
69
networking.firewall.allowedTCPPorts = [ 179 ];
710
};
@@ -29,14 +32,20 @@
2932
neighbor fe80::2 capability extended-nexthop
3033
neighbor fe80::2 interface eth1
3134
35+
neighbor fe80::3 remote-as 64498
36+
neighbor fe80::3 capability extended-nexthop
37+
neighbor fe80::3 interface eth1
38+
3239
address-family ipv4 unicast
3340
network 198.51.100.0/25
3441
neighbor fe80::2 activate
42+
neighbor fe80::3 activate
3543
exit-address-family
3644
3745
address-family ipv6 unicast
3846
network 2001:db8:beef::/48
3947
neighbor fe80::2 activate
48+
neighbor fe80::3 activate
4049
exit-address-family
4150
'';
4251
};
@@ -102,9 +111,128 @@
102111
export all;
103112
};
104113
}
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+
}
105131
'';
106132
};
107133
};
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+
};
108236
};
109237

110238
testScript = ''
@@ -117,14 +245,34 @@
117245
b.wait_for_unit("bird.service")
118246
119247
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'")
122253
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'")
123263
124264
with subtest("ensure routes have been installed"):
125-
a.succeed("ip route show | grep 198.51.100.128/25")
126265
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")
128271
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")
129277
'';
130278
}

0 commit comments

Comments
 (0)