1{ pkgs, ... }:
2let
3 ifAddr =
4 node: iface: (pkgs.lib.head node.config.networking.interfaces.${iface}.ipv4.addresses).address;
5in
6{
7 name = "gobgpd";
8
9 meta = with pkgs.lib.maintainers; {
10 maintainers = [ higebu ];
11 };
12
13 nodes = {
14 node1 =
15 { nodes, ... }:
16 {
17 environment.systemPackages = [ pkgs.gobgp ];
18 networking.firewall.allowedTCPPorts = [ 179 ];
19 services.gobgpd = {
20 enable = true;
21 settings = {
22 global = {
23 config = {
24 as = 64512;
25 router-id = "192.168.255.1";
26 };
27 };
28 neighbors = [
29 {
30 config = {
31 neighbor-address = ifAddr nodes.node2 "eth1";
32 peer-as = 64513;
33 };
34 }
35 ];
36 };
37 };
38 };
39 node2 =
40 { nodes, ... }:
41 {
42 environment.systemPackages = [ pkgs.gobgp ];
43 networking.firewall.allowedTCPPorts = [ 179 ];
44 services.gobgpd = {
45 enable = true;
46 settings = {
47 global = {
48 config = {
49 as = 64513;
50 router-id = "192.168.255.2";
51 };
52 };
53 neighbors = [
54 {
55 config = {
56 neighbor-address = ifAddr nodes.node1 "eth1";
57 peer-as = 64512;
58 };
59 }
60 ];
61 };
62 };
63 };
64 };
65
66 testScript =
67 { nodes, ... }:
68 let
69 addr1 = ifAddr nodes.node1 "eth1";
70 addr2 = ifAddr nodes.node2 "eth1";
71 in
72 ''
73 start_all()
74
75 for node in node1, node2:
76 with subtest("should start gobgpd node"):
77 node.wait_for_unit("gobgpd.service")
78 with subtest("should open port 179"):
79 node.wait_for_open_port(179)
80
81 with subtest("should show neighbors by gobgp cli and BGP state should be ESTABLISHED"):
82 node1.wait_until_succeeds("gobgp neighbor ${addr2} | grep -q ESTABLISHED")
83 node2.wait_until_succeeds("gobgp neighbor ${addr1} | grep -q ESTABLISHED")
84 '';
85}