2010-05-20 23:07:32 +02:00
|
|
|
# This is a simple distributed test involving a topology with two
|
|
|
|
# separate virtual networks - the "inside" and the "outside" - with a
|
|
|
|
# client on the inside network, a server on the outside network, and a
|
|
|
|
# router connected to both that performs Network Address Translation
|
|
|
|
# for the client.
|
|
|
|
|
|
|
|
{ pkgs, ... }:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
nodes =
|
2011-09-14 20:20:50 +02:00
|
|
|
{ client =
|
2010-05-21 16:12:03 +02:00
|
|
|
{ config, pkgs, nodes, ... }:
|
2010-05-20 23:07:32 +02:00
|
|
|
{ virtualisation.vlans = [ 1 ];
|
2010-05-21 16:12:03 +02:00
|
|
|
networking.defaultGateway =
|
|
|
|
nodes.router.config.networking.ifaces.eth2.ipAddress;
|
2010-05-20 23:07:32 +02:00
|
|
|
};
|
|
|
|
|
2011-09-14 20:20:50 +02:00
|
|
|
router =
|
2010-05-20 23:07:32 +02:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
{ virtualisation.vlans = [ 2 1 ];
|
2011-03-10 13:08:39 +01:00
|
|
|
networking.nat.enable = true;
|
|
|
|
networking.nat.internalIPs = "192.168.1.0/24";
|
|
|
|
networking.nat.externalInterface = "eth1";
|
2010-05-20 23:07:32 +02:00
|
|
|
};
|
|
|
|
|
2011-09-14 20:20:50 +02:00
|
|
|
server =
|
2010-05-20 23:07:32 +02:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
{ virtualisation.vlans = [ 2 ];
|
|
|
|
services.httpd.enable = true;
|
|
|
|
services.httpd.adminAddr = "foo@example.org";
|
2011-03-10 14:03:47 +01:00
|
|
|
services.vsftpd.enable = true;
|
|
|
|
services.vsftpd.anonymousUser = true;
|
2010-05-20 23:07:32 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript =
|
2010-05-21 16:31:05 +02:00
|
|
|
{ nodes, ... }:
|
2010-05-20 23:07:32 +02:00
|
|
|
''
|
|
|
|
startAll;
|
|
|
|
|
|
|
|
# The router should have access to the server.
|
|
|
|
$server->waitForJob("httpd");
|
2012-10-24 12:58:58 +02:00
|
|
|
$router->waitForJob("network.target");
|
2011-03-10 13:08:39 +01:00
|
|
|
$router->succeed("curl --fail http://server/ >&2");
|
|
|
|
|
|
|
|
# The client should be also able to connect via the NAT router.
|
|
|
|
$router->waitForJob("nat");
|
2012-10-24 12:58:58 +02:00
|
|
|
$client->waitForJob("network.target");
|
2011-03-10 13:08:39 +01:00
|
|
|
$client->succeed("curl --fail http://server/ >&2");
|
|
|
|
$client->succeed("ping -c 1 server >&2");
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2011-03-10 14:03:47 +01:00
|
|
|
# Test whether passive FTP works.
|
|
|
|
$server->waitForJob("vsftpd");
|
|
|
|
$server->succeed("echo Hello World > /home/ftp/foo.txt");
|
|
|
|
$client->succeed("curl -v ftp://server/foo.txt >&2");
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2011-03-10 14:03:47 +01:00
|
|
|
# Test whether active FTP works.
|
|
|
|
$client->succeed("curl -v -P - ftp://server/foo.txt >&2");
|
|
|
|
|
|
|
|
# Test ICMP.
|
|
|
|
$client->succeed("ping -c 1 router >&2");
|
|
|
|
$router->succeed("ping -c 1 client >&2");
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2011-03-10 13:08:39 +01:00
|
|
|
# If we turn off NAT, the client shouldn't be able to reach the server.
|
|
|
|
$router->succeed("stop nat");
|
|
|
|
$client->fail("curl --fail --connect-timeout 5 http://server/ >&2");
|
|
|
|
$client->fail("ping -c 1 server >&2");
|
|
|
|
|
|
|
|
# And make sure that restarting the NAT job works.
|
|
|
|
$router->succeed("start nat");
|
|
|
|
$client->succeed("curl --fail http://server/ >&2");
|
|
|
|
$client->succeed("ping -c 1 server >&2");
|
2010-05-20 23:07:32 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
}
|