From 9575db4aae37a80284e1bddbfc205f0a956e0a88 Mon Sep 17 00:00:00 2001 From: Bob Lantz Date: Fri, 29 May 2009 15:45:33 -0700 Subject: [PATCH] Failover: Minor changes to failover tests Now setup scripts should accept a controller argument if desired. Add two failover tests to tests.txt, but third test (controller stops responding) is experimental for now. --- regress/bin/of_kmod_setup.pl | 7 ++- regress/bin/of_kmod_veth_setup.pl | 7 ++- regress/bin/of_nf2_setup.pl | 7 ++- regress/bin/of_user_setup.pl | 7 ++- regress/bin/of_user_veth_setup.pl | 7 ++- regress/bin/of_user_veth_test.pl | 2 +- regress/lib/Perl5/OF/OFUtil.pm | 50 ++++++++--------- regress/lib/Perl5/Test/TestLib.pm | 55 +++++++++++++++++-- .../regress/test_failover_close/run.pl | 23 +++++--- .../regress/test_failover_startup/run.pl | 15 +++-- .../test_failover_stop_responding/run.pl | 23 +++++--- regress/projects/black_box/regress/tests.txt | 6 ++ 12 files changed, 140 insertions(+), 69 deletions(-) diff --git a/regress/bin/of_kmod_setup.pl b/regress/bin/of_kmod_setup.pl index 18ff44f..5571dff 100755 --- a/regress/bin/of_kmod_setup.pl +++ b/regress/bin/of_kmod_setup.pl @@ -5,10 +5,11 @@ use Getopt::Long; use OF::OFUtil; use Test::TestLib; -my $mapFile; +my $mapFile, $controller; # Process command line options -unless ( GetOptions( "map=s" => \$mapFile, ) ) { +unless ( GetOptions( "map=s" => \$mapFile, + "controller=s", \$controller) ) { print "unrecognized option\n"; exit 1; } @@ -17,4 +18,4 @@ if ( defined($mapFile) ) { nftest_process_iface_map($mapFile); } -setup_kmod(); +setup_kmod($controller); diff --git a/regress/bin/of_kmod_veth_setup.pl b/regress/bin/of_kmod_veth_setup.pl index 7b971f3..2270a3a 100755 --- a/regress/bin/of_kmod_veth_setup.pl +++ b/regress/bin/of_kmod_veth_setup.pl @@ -5,10 +5,11 @@ use Getopt::Long; use OF::OFUtil; use Test::TestLib; -my $mapFile; +my ($mapFile, $controller); # Process command line options -unless ( GetOptions( "map=s" => \$mapFile, ) ) { +unless ( GetOptions( "map=s" => \$mapFile, + "controller=s", \$controller) ) { print "unrecognized option\n"; exit 1; } @@ -21,4 +22,4 @@ else { nftest_process_iface_map("$ENV{'OFT_ROOT'}/bin/veth.map"); } -setup_kmod(); +setup_kmod($controller); diff --git a/regress/bin/of_nf2_setup.pl b/regress/bin/of_nf2_setup.pl index 65ecac5..1363d72 100755 --- a/regress/bin/of_nf2_setup.pl +++ b/regress/bin/of_nf2_setup.pl @@ -6,13 +6,14 @@ use Data::Dumper; use OF::OFUtil; use Test::TestLib; -my $mapFile; +my ($mapFile, $controller); print "Calling of_nf2_setup.pl\n"; print Dumper(@ARGV) . "\n"; # Process command line options -unless ( GetOptions( "map=s" => \$mapFile, ) ) { +unless ( GetOptions( "map=s" => \$mapFile, + "controller=s", \$controller) ) { print "unrecognized option\n"; exit 1; } @@ -21,4 +22,4 @@ if ( defined($mapFile) ) { nftest_process_iface_map($mapFile); } -setup_NF2(); +setup_NF2($controller); diff --git a/regress/bin/of_user_setup.pl b/regress/bin/of_user_setup.pl index ea6f8c3..896a821 100755 --- a/regress/bin/of_user_setup.pl +++ b/regress/bin/of_user_setup.pl @@ -5,10 +5,11 @@ use Getopt::Long; use OF::OFUtil; use Test::TestLib; -my $mapFile; +my ($mapFile, $controller); # Process command line options -unless ( GetOptions( "map=s" => \$mapFile, ) ) { +unless ( GetOptions( "map=s" => \$mapFile, + "controller=s", \$controller) ) { print "unrecognized option\n"; exit 1; } @@ -17,4 +18,4 @@ if ( defined($mapFile) ) { nftest_process_iface_map($mapFile); } -setup_user(); +setup_user($controller); diff --git a/regress/bin/of_user_veth_setup.pl b/regress/bin/of_user_veth_setup.pl index dd9104e..be8fafd 100755 --- a/regress/bin/of_user_veth_setup.pl +++ b/regress/bin/of_user_veth_setup.pl @@ -5,10 +5,11 @@ use Getopt::Long; use OF::OFUtil; use Test::TestLib; -my $mapFile; +my ($mapFile, $controller); # Process command line options -unless ( GetOptions( "map=s" => \$mapFile, ) ) { +unless ( GetOptions( "map=s" => \$mapFile, + "controller=s", \$controller) ) { print "unrecognized option\n"; exit 1; } @@ -21,4 +22,4 @@ else { nftest_process_iface_map("$ENV{'OFT_ROOT'}/bin/veth.map"); } -setup_user(); +setup_user($controller); diff --git a/regress/bin/of_user_veth_test.pl b/regress/bin/of_user_veth_test.pl index 527bfaa..7d73068 100755 --- a/regress/bin/of_user_veth_test.pl +++ b/regress/bin/of_user_veth_test.pl @@ -23,6 +23,6 @@ sub INT_Handler { } my $of_port = get_of_port(); -push @ARGV, "--map=$ENV{'OFT_ROOT'}/bin/veth.map", "--root=$ENV{'OFT_ROOT'}", "--common-st-args=user_veth", "--controller=localhost:$of_port"; +push( @ARGV, "--map=$ENV{'OFT_ROOT'}/bin/veth.map", "--root=$ENV{'OFT_ROOT'}", "--common-st-args=user_veth"); run_regress_test( \&INT_Handler, @ARGV ); diff --git a/regress/lib/Perl5/OF/OFUtil.pm b/regress/lib/Perl5/OF/OFUtil.pm index ee1c754..03cd354 100644 --- a/regress/lib/Perl5/OF/OFUtil.pm +++ b/regress/lib/Perl5/OF/OFUtil.pm @@ -160,6 +160,17 @@ sub setup_pcap_interfaces { } } +sub start_ofprotocol { + + my ( $controller ) = @_; + if ( !$controller) { $controller = nftest_default_controllers(); } + + my $cmd = "${openflow_dir}/secchan/ofprotocol unix:/var/run/test $controller --inactivity-probe=999999 &"; + + print "about to run $cmd\n"; + system($cmd); +} + sub setup_kmod { setup_pcap_interfaces(); @@ -190,7 +201,7 @@ sub setup_kmod { `${openflow_dir}/utilities/dpctl addif nl:0 $iface`; } - system("${openflow_dir}/secchan/ofprotocol --inactivity-probe=999999 nl:0 tcp:127.0.0.1 &"); + start_ofprotocol(@_); } sub setup_NF2 { @@ -239,9 +250,10 @@ sub setup_NF2 { print "added interface\n"; } - system("${openflow_dir}/secchan/ofprotocol --inactivity-probe=999999 nl:0 tcp:127.0.0.1 &"); + start_ofprotocol(@_); } + sub setup_user { setup_pcap_interfaces(); @@ -252,11 +264,11 @@ sub setup_user { $if_string .= nftest_get_iface("eth$i") . ','; } $if_string .= nftest_get_iface("eth8"); - print "about to create ofdatapath punix:/var/run/test -i $if_string \& \ -n"; - system("${openflow_dir}/udatapath/ofdatapath punix:/var/run/test -i $if_string \&"); - print "about to create ofprotocol \& \n"; - system("${openflow_dir}/secchan/ofprotocol --inactivity-probe=999999 unix:/var/run/test tcp:127.0.0.1 &"); + + print "about to create ofdatapath` punix:/var/run/test -i $if_string \& \n"; + system("${openflow_dir}/udatapath/ofdatapath punix:/var/run/test -i $if_string \&"); + + start_ofprotocol(@_); } sub teardown_kmod { @@ -355,7 +367,7 @@ sub compare { sub create_controller_socket { my ($host, $port) = @_; - print "about to make socket\n"; + print "about to make socket: tcp:$host:$port\n"; my $sock = new IO::Socket::INET( LocalHost => $host, LocalPort => $port, @@ -611,26 +623,14 @@ sub set_config { syswrite( $sock, $set_config ); } + sub run_black_box_test { - - my ( $test_ref, $argv_ref ) = @_; + + my ( $test_ref, $argv_ref, $dont_exit ) = @_; my %options = nftest_init( $argv_ref, \@interfaces, ); - my $host = 'localhost'; - my $port = $of_port; - # extract host and port from controller string if passed in - if (defined $options{'controller'}) { - # Assume fully qualified string : tcp:: - # Jean II - ($proto, $host, $port) = split(/:/,$options{'controller'}); - # Check for string missing the protocol - Jean II - if ( ! defined ($port) ) { - $proto = "tcp"; - ($host, $port) = split(/:/,$options{'controller'}); - } - } - #!!! + my ($proto, $host, $port) = nftest_parse_controllers( $options{'controller'} ); print "using host $host and port $port\n"; $sock = create_controller_socket($host, $port); @@ -679,7 +679,7 @@ sub run_black_box_test { print "FAIL: $total_errors errors\n"; $exitCode = 1; } - exit($exitCode); + if (!$dont_exit ) { exit($exitCode); } }; } diff --git a/regress/lib/Perl5/Test/TestLib.pm b/regress/lib/Perl5/Test/TestLib.pm index 3e2903d..d2fa8bf 100644 --- a/regress/lib/Perl5/Test/TestLib.pm +++ b/regress/lib/Perl5/Test/TestLib.pm @@ -25,13 +25,15 @@ use Test::PacketLib; use threads; use threads::shared; use Net::RawIP; -use Getopt::Long; +use Getopt::Long qw(GetOptionsFromArray); use vars qw(@ISA @EXPORT); # needed cos strict is on @ISA = ('Exporter'); @EXPORT = qw( &nftest_init + &nftest_default_controllers + &nftest_parse_controllers &nftest_start &nftest_restart &nftest_send @@ -156,6 +158,45 @@ my %vhostsARPdisable : shared; my %vhARPReqLog : shared; my %vhARPRepLog : shared; + + +############################################################### +# Name: nftest_default_controllers +# +# Returns a string of two default controllers (to support +# failover testing) +############################################################### +sub nftest_default_controllers { return "tcp:127.0.0.1:6633,tcp:127.0.0.1:6634"; } + +############################################################### +# Name: nftest_parse_controllers +# +# Parses a list of controllers for easy access +# +# Arguments: controllers controller parameter string +# +# Returns: list of ((proto,host,port)...) +# +############################################################### +sub nftest_parse_controllers { + # Parse a list of proto:host:port,proto:host:port... + my @controllers = split(/,/, $_[0]); + my @default_controllers = split(/,/, nftest_default_controllers()); + my ($proto, $host, $port) = split(/:/, $default_controllers[0]); + my @results = (); + foreach my $controller (@controllers) { + my @params = split(/:/, $controller); + # Accept "proto:host:port", "host:port", "host", or "" + if (@params == 1) { $controller = "$proto:$controller:$port"; } + if (@params == 2) { $controller = "$proto:$controller"; } + if (@params < 1 || @params > 3) { die "bad controller specified: $controller\n"; } + @params = split(/:/, $controller); + # print "parse: adding $params[0], $params[1], $params[2]\n"; + push(@results, @params); + } + return @results; +} + ############################################################### # Name: nftest_init # @@ -178,8 +219,9 @@ sub nftest_init { $options{'base_idle'} = 2; unless ( - GetOptions( - \%options, + GetOptionsFromArray( + \@ARGV, + \%options, "map=s", "controller=s", "port_base=i", @@ -202,8 +244,11 @@ sub nftest_init { # next in line for generalizing the tests $options{'num_ports'} = 4; - - if ( not defined ($options{'controller'})) { die "please define controller\n"}; + + if ( not defined ($options{'controller'})) { + $options{'controller'} = nftest_default_controllers(); + print "Using default controller(s) $options{'controller'}\n"; + } # Process the mappings if specified, else use defaults if ( defined( $options{'map'} ) ) { diff --git a/regress/projects/black_box/regress/test_failover_close/run.pl b/regress/projects/black_box/regress/test_failover_close/run.pl index 7f3cdb7..06fd9a7 100755 --- a/regress/projects/black_box/regress/test_failover_close/run.pl +++ b/regress/projects/black_box/regress/test_failover_close/run.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -# Simple Two-controller Failover test +# Simple two-controller failover test # # For this test to work, the switch must be set up to use our # two "controllers", e.g. @@ -8,11 +8,14 @@ # ofprotocol --controller=tcp:127.0.0.1:6633,tcp:127.0.0.1:6634 # # If you use different ports than the defaults, then you must -# pass the --controller option into this script as well -# +# pass the --controller option into this script as well. # # Failover test 2: Controller is fine, but closes connection # +# For this test, we accept the Hello sequence and then close +# the socket. Then we listen for a failover connection on the +# second socket. +# use strict; use OF::Includes; @@ -20,14 +23,16 @@ use OF::Includes; # Save ARGV for future reference my @ARGS = @ARGV; -print "Failover Close() Test phase 1: calling run_black_box_test with @ARGV\n"; +my $test = "Failover test 2 (connection closed)"; + +print "$test phase 1: calling run_black_box_test with @ARGV\n"; # Start up, say Hello, and close connection sub close_failover_test_phase_1 { my ($sock) = @_; - print "Close() Failover: got socket $sock\n"; - print "Startup Failover Close() Test: finished Hello sequence on first controller\n"; - print "Startup Failover Close() Test: closing socket\n"; + print "$test: Got socket $sock\n"; + print "$test: Finished Hello sequence on first controller\n"; + print "$test: Closing socket\n"; $sock->close(); } @@ -55,9 +60,9 @@ for (my $i = 0; $i < @ARGV; $i++) { sub close_failover_test_phase_2 { - print "Close() Failover: Failover to second controller succeeded\n"; + print "$test: Failover to second controller succeeded\n"; } -print "Failover Close() Test phase 2: calling run_black_box_test with @ARGV\n"; +print "$test: Calling run_black_box_test with @ARGV\n"; run_black_box_test( \&close_failover_test_phase_2, \@ARGV ); # do exit this time diff --git a/regress/projects/black_box/regress/test_failover_startup/run.pl b/regress/projects/black_box/regress/test_failover_startup/run.pl index 579528b..701951e 100755 --- a/regress/projects/black_box/regress/test_failover_startup/run.pl +++ b/regress/projects/black_box/regress/test_failover_startup/run.pl @@ -2,20 +2,25 @@ # Simple two-controller failover test # -# Failover Test #1: Startup Failover -# # For this test to work, the switch must be set up to use our # two "controllers", e.g. # # ofprotocol --controller=tcp:127.0.0.1:6633,tcp:127.0.0.1:6634 # # If you use different ports than the defaults, then you must -# pass the --controller option into this script as well +# pass the --controller option into this script as well. +# +# Failover Test 1: Startup Failover +# +# For this test, we listen on the second controller port rather +# than the first. # use strict; use OF::Includes; +my $test="Failover test 1 (startup failover)"; + # If no controllers specified, use default if (not @ARGV =~ "--controller") { push( @ARGV, "--controller=" . nftest_default_controllers() ); @@ -30,10 +35,10 @@ for (my $i = 0; $i < @ARGV; $i++) { } } -"Startup Failover Test: calling run_black_box_test with @ARGV\n"; +print "$test: Calling run_black_box_test with @ARGV\n"; sub startup_failover_test { - print "Startup Failover Test: failed over successfully\n"; + print "$test: Failed over successfully\n"; } run_black_box_test( \&startup_failover_test, \@ARGV ); diff --git a/regress/projects/black_box/regress/test_failover_stop_responding/run.pl b/regress/projects/black_box/regress/test_failover_stop_responding/run.pl index 0b4a125..50a4a47 100755 --- a/regress/projects/black_box/regress/test_failover_stop_responding/run.pl +++ b/regress/projects/black_box/regress/test_failover_stop_responding/run.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -# Simple Two-controller Failover test +# Simple two-controller failover test # # For this test to work, the switch must be set up to use our # two "controllers", e.g. @@ -8,10 +8,13 @@ # ofprotocol --controller=tcp:127.0.0.1:6633,tcp:127.0.0.1:6634 # # If you use different ports than the defaults, then you must -# pass the --controller option into this script as well +# pass the --controller option into this script as well. # # Failover test 3: Controller is fine, but stops responding # +# For this test, we accept the Hello sequence on the first port +# but then listen for a failover connection on the second port. +# use strict; use OF::Includes; @@ -19,15 +22,17 @@ use OF::Includes; # Save ARGV for future reference my @ARGS = @ARGV; -print "Failover Stop Responding Test phase 1: calling run_black_box_test with @ARGV\n"; +my $test="Failover test 3 (controller stops responding)"; + +print "$test phase 1: calling run_black_box_test with @ARGV\n"; # Start up, say Hello, and close connection sub stop_responding_test_phase_1 { my ($sock) = @_; - print "Close() Failover: got socket $sock\n"; - print "Startup Failover Stop Responding Test: finished Hello sequence on first controller\n"; - print "Startup Failover Close() Test: not closing socket\n"; - print "Startup Failover Close() Test: invoking phase 2\n"; + print "$test: Got socket $sock\n"; + print "$test: Finished Hello sequence on first controller\n"; + print "$test: Not closing socket\n"; + print "$test: Invoking phase 2\n"; stop_responding_phase_2(); } @@ -50,11 +55,11 @@ sub stop_responding_phase_2 { # run_black_box_test() will use bar's port rather than foo's for (my $i = 0; $i < @ARGV; $i++) { if ($ARGV[$i] =~ /controller=[^,]*,([^\s]+)/ ) { - print "failover_startup: got controller $1\n"; + print "$test: got controller $1\n"; $ARGV[$i] = "--controller=$1"; } } - print "Failover Stop Responding Test phase 2: calling run_black_box_test with @ARGV\n"; + print "$test: Calling run_black_box_test with @ARGV\n"; run_black_box_test( \&close_failover_test_phase_2, \@ARGV ); # do exit this time } diff --git a/regress/projects/black_box/regress/tests.txt b/regress/projects/black_box/regress/tests.txt index e9cd9d0..cf61938 100644 --- a/regress/projects/black_box/regress/tests.txt +++ b/regress/projects/black_box/regress/tests.txt @@ -47,6 +47,10 @@ test_ip_offset/run.pl test_tcp_options/run.pl ##test_llc/run.pl +# Failover Tests +test_failover_startup/run.pl +test_failover_close/run.pl + # BELOW NOT INCLUDED IN CURRRENT RELEASE # WILL BE AVAILABLE SOON # Stress Tests / Performance Evaluation @@ -61,3 +65,5 @@ test_tcp_options/run.pl #test_forward_latency/run.pl #test_switch_bandwidth_random/run.pl #test_switch_bandwidth_random/run.pl +# Additional Failover tests +#test_failover_stop_responding/run.pl