at 18.03-beta 2.8 kB view raw
1# This test runs Quagga and checks if OSPF routing works. 2# 3# Network topology: 4# [ client ]--net1--[ router1 ]--net2--[ router2 ]--net3--[ server ] 5# 6# All interfaces are in OSPF Area 0. 7 8import ./make-test.nix ({ pkgs, ... }: 9 let 10 11 ifAddr = node: iface: (pkgs.lib.head node.config.networking.interfaces.${iface}.ipv4.addresses).address; 12 13 ospfConf = '' 14 interface eth2 15 ip ospf hello-interval 1 16 ip ospf dead-interval 5 17 ! 18 router ospf 19 network 192.168.0.0/16 area 0 20 ''; 21 22 in 23 { 24 name = "quagga"; 25 26 meta = with pkgs.stdenv.lib.maintainers; { 27 maintainers = [ tavyc ]; 28 }; 29 30 nodes = { 31 32 client = 33 { config, pkgs, nodes, ... }: 34 { 35 virtualisation.vlans = [ 1 ]; 36 networking.defaultGateway = ifAddr nodes.router1 "eth1"; 37 }; 38 39 router1 = 40 { config, pkgs, nodes, ... }: 41 { 42 virtualisation.vlans = [ 1 2 ]; 43 boot.kernel.sysctl."net.ipv4.ip_forward" = "1"; 44 networking.firewall.extraCommands = "iptables -A nixos-fw -i eth2 -p ospf -j ACCEPT"; 45 services.quagga.ospf = { 46 enable = true; 47 config = ospfConf; 48 }; 49 }; 50 51 router2 = 52 { config, pkgs, nodes, ... }: 53 { 54 virtualisation.vlans = [ 3 2 ]; 55 boot.kernel.sysctl."net.ipv4.ip_forward" = "1"; 56 networking.firewall.extraCommands = "iptables -A nixos-fw -i eth2 -p ospf -j ACCEPT"; 57 services.quagga.ospf = { 58 enable = true; 59 config = ospfConf; 60 }; 61 }; 62 63 server = 64 { config, pkgs, nodes, ... }: 65 { 66 virtualisation.vlans = [ 3 ]; 67 networking.defaultGateway = ifAddr nodes.router2 "eth1"; 68 networking.firewall.allowedTCPPorts = [ 80 ]; 69 networking.firewall.allowPing = true; 70 services.httpd.enable = true; 71 services.httpd.adminAddr = "foo@example.com"; 72 }; 73 }; 74 75 testScript = 76 { nodes, ... }: 77 '' 78 startAll; 79 80 # Wait for the networking to start on all machines 81 $_->waitForUnit("network.target") foreach values %vms; 82 83 # Wait for OSPF to form adjacencies 84 for my $gw ($router1, $router2) { 85 $gw->waitForUnit("ospfd"); 86 $gw->waitUntilSucceeds("vtysh -c 'show ip ospf neighbor' | grep Full"); 87 $gw->waitUntilSucceeds("vtysh -c 'show ip route' | grep '^O>'"); 88 } 89 90 # Test ICMP. 91 $client->succeed("ping -c 3 server >&2"); 92 93 # Test whether HTTP works. 94 $server->waitForUnit("httpd"); 95 $client->succeed("curl --fail http://server/ >&2"); 96 ''; 97 })