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