2016-04-20 17:41:05 +03:00
|
|
|
# This test runs Quagga and checks if OSPF routing works.
|
|
|
|
#
|
|
|
|
# Network topology:
|
|
|
|
# [ client ]--net1--[ router1 ]--net2--[ router2 ]--net3--[ server ]
|
|
|
|
#
|
|
|
|
# All interfaces are in OSPF Area 0.
|
|
|
|
|
2019-12-15 20:29:20 +03:00
|
|
|
import ./make-test-python.nix ({ pkgs, ... }:
|
2016-04-20 17:41:05 +03:00
|
|
|
let
|
|
|
|
|
2017-12-03 07:14:54 +03:00
|
|
|
ifAddr = node: iface: (pkgs.lib.head node.config.networking.interfaces.${iface}.ipv4.addresses).address;
|
2016-04-20 17:41:05 +03:00
|
|
|
|
|
|
|
ospfConf = ''
|
|
|
|
interface eth2
|
|
|
|
ip ospf hello-interval 1
|
|
|
|
ip ospf dead-interval 5
|
|
|
|
!
|
|
|
|
router ospf
|
|
|
|
network 192.168.0.0/16 area 0
|
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
name = "quagga";
|
|
|
|
|
|
|
|
meta = with pkgs.stdenv.lib.maintainers; {
|
|
|
|
maintainers = [ tavyc ];
|
|
|
|
};
|
|
|
|
|
|
|
|
nodes = {
|
|
|
|
|
|
|
|
client =
|
2018-07-20 23:56:59 +03:00
|
|
|
{ nodes, ... }:
|
2016-04-20 17:41:05 +03:00
|
|
|
{
|
|
|
|
virtualisation.vlans = [ 1 ];
|
|
|
|
networking.defaultGateway = ifAddr nodes.router1 "eth1";
|
|
|
|
};
|
|
|
|
|
|
|
|
router1 =
|
2018-07-20 23:56:59 +03:00
|
|
|
{ ... }:
|
2016-04-20 17:41:05 +03:00
|
|
|
{
|
|
|
|
virtualisation.vlans = [ 1 2 ];
|
|
|
|
boot.kernel.sysctl."net.ipv4.ip_forward" = "1";
|
|
|
|
networking.firewall.extraCommands = "iptables -A nixos-fw -i eth2 -p ospf -j ACCEPT";
|
|
|
|
services.quagga.ospf = {
|
|
|
|
enable = true;
|
|
|
|
config = ospfConf;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
router2 =
|
2018-07-20 23:56:59 +03:00
|
|
|
{ ... }:
|
2016-04-20 17:41:05 +03:00
|
|
|
{
|
|
|
|
virtualisation.vlans = [ 3 2 ];
|
|
|
|
boot.kernel.sysctl."net.ipv4.ip_forward" = "1";
|
|
|
|
networking.firewall.extraCommands = "iptables -A nixos-fw -i eth2 -p ospf -j ACCEPT";
|
|
|
|
services.quagga.ospf = {
|
|
|
|
enable = true;
|
|
|
|
config = ospfConf;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
server =
|
2018-07-20 23:56:59 +03:00
|
|
|
{ nodes, ... }:
|
2016-04-20 17:41:05 +03:00
|
|
|
{
|
|
|
|
virtualisation.vlans = [ 3 ];
|
|
|
|
networking.defaultGateway = ifAddr nodes.router2 "eth1";
|
|
|
|
networking.firewall.allowedTCPPorts = [ 80 ];
|
|
|
|
services.httpd.enable = true;
|
|
|
|
services.httpd.adminAddr = "foo@example.com";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript =
|
2018-07-20 23:56:59 +03:00
|
|
|
{ ... }:
|
2016-04-20 17:41:05 +03:00
|
|
|
''
|
2019-12-15 20:29:20 +03:00
|
|
|
start_all()
|
2016-04-20 17:41:05 +03:00
|
|
|
|
|
|
|
# Wait for the networking to start on all machines
|
2019-12-15 20:29:20 +03:00
|
|
|
for machine in client, router1, router2, server:
|
|
|
|
machine.wait_for_unit("network.target")
|
2016-04-20 17:41:05 +03:00
|
|
|
|
2019-12-15 20:29:20 +03:00
|
|
|
with subtest("Wait for OSPF to form adjacencies"):
|
|
|
|
for gw in router1, router2:
|
|
|
|
gw.wait_for_unit("ospfd")
|
|
|
|
gw.wait_until_succeeds("vtysh -c 'show ip ospf neighbor' | grep Full")
|
|
|
|
gw.wait_until_succeeds("vtysh -c 'show ip route' | grep '^O>'")
|
2016-04-20 17:41:05 +03:00
|
|
|
|
2019-12-15 20:29:20 +03:00
|
|
|
with subtest("Test ICMP"):
|
|
|
|
client.wait_until_succeeds("ping -c 3 server >&2")
|
2016-04-20 17:41:05 +03:00
|
|
|
|
2019-12-15 20:29:20 +03:00
|
|
|
with subtest("Test whether HTTP works"):
|
|
|
|
server.wait_for_unit("httpd")
|
|
|
|
client.succeed("curl --fail http://server/ >&2")
|
2016-04-20 17:41:05 +03:00
|
|
|
'';
|
|
|
|
})
|