#!/usr/bin/perl
#
# $Copyright_v6PC$
#
# $Copyright$
#
# $TAHI: ct/nd/hostRecvRs.seq,v 1.24 2004/04/02 02:28:22 akisada Exp $

########################################################################
BEGIN { $V6evalTool::TestVersion = '$Name:  $ '; }
 
use V6evalTool;
use nd;

ndOptions(@ARGV);

# The following generate debugging messages.
$nd::debug=$ndOpt_v|$ndOpt_vv;

# You can specifies debug options to a remote control program.
# If you want to know more detail, please see the following:
# - V6evalTool.pm: perldoc V6evalTool
# - V6evalRemote.pm: perldoc V6evalRemote
$nd::remote_debug="-o1" if $ndOpt_vv;

$IF=Link0;
$exit_rtn=$V6evalTool::exitPass;
$idx=0;

#
#
#
$type=$V6evalTool::NutDef{Type};
if($type eq router) {
    vLogHTML("This test is for the host only<BR>");
    exit $V6evalTool::exitHostOnly;
}

$type=$V6evalTool::NutDef{Type};
if($type ne host) {
    vLogHTML(ndErrmsg("ERROR: $V6evalTool::NutDef{Type}: ".
		      "Unknown target type<BR>"));
    exit $V6evalTool::exitFail;
}

# sub test definition:
# - sending pattern,
# - SLLA vs cached LLA
# - expected state
# - message
#
$idx_ptn=0;
$idx_lla=1;
$idx_exp=2;
$idx_msg=3;
$idx_inc_ip=4;
$idx_prb_ip=5;
$idx_rpy_ip=6;
$idx_ign_ip=7;
$idx_non_n=8;
$idx_rpy_n=9;
$idx_ign_n=10;
$idx_stl_sr=11;
$idx_ign_sr=12;
@null=();

#
@def_rs_tn2allrouter_sll=
    (
     rs_tn2allrouter_sll,
     same,
     NONCE,
     'RS w/ SLL',
     \@null, \@null, \@null, \@null,
     \@null, \@null, \@null,
     \@null, \@null
     );

#
@def_rs_tn2allnode_sll_invalid_multidst=
    (
     rs_tn2allnode_sll_invalid_multidst,
     same,
     NONCE,
     'RS w/ SLL, src=all-nodes (INVALID)',
     \@null, \@null, \@null, \@null,
     \@null, \@null, \@null,
     \@null, \@null
     );

#
@def_rs_tn2nut_sll_invalid_unidst=
    (
     rs_tn2nut_sll_invalid_unidst,
     same,
     NONCE,
     'RS w/ SLL, src=unicast (INVALID)',
     \@null, \@null, \@null, \@null,
     \@null, \@null, \@null,
     \@null, \@null
     );

#
#
#
@defs=
    (
     \@def_rs_tn2allrouter_sll,
     \@def_rs_tn2allnode_sll_invalid_multidst,
     \@def_rs_tn2nut_sll_invalid_unidst,
     );

#
#
#
vCapture($IF);

#
#
#
$idx=0;
foreach(@defs) {
    $exp=@$_[$idx_exp];
    $msg=@$_[$idx_msg];
    vLogHTML("<HR><FONT SIZE=\"+2\">*** No neighbor cache entry vs. $msg ***</FONT><BR>");
    $s=checkState($_);
    if($s =~ /$exp/) {
        $result{$idx}=$V6evalTool::exitPass;
        vLogHTML("<A NAME=\"T$idx\">OK: The target was in $s state</A><BR>");
    } else {
        $exit_rtn=$V6evalTool::exitFail;
        $result{$idx}=$exit_rtn;
        vLogHTML("<A NAME=\"T$idx\">".
		 ndErrmsg("NG: The target was in $s state")."</A><BR>");
    }
    $title{$idx}="<TD>$msg</TD><TD>exp:$exp</TD><TD>result:$s</TD>";
    $idx++;
}
$idx--;

#
#
#
@col=('PTN', 'EXP', 'RESULT');
ndPrintSummaryHTML("*** Test Summary: No neighbor cache entry vs. RS ***", @col,
                   %title, %result, $idx);

#
#
#
vLogHTML("*** EOT ***<BR>");
exit $exit_rtn;

#
#
#
sub checkState(\@) {
    my($def)=@_;
    my($ptn)=@$def[$idx_ptn];
    my($lla)=@$def[$idx_lla];
    my($exp)=@$def[$idx_exp];
    my($msg)=@$def[$idx_msg];

    my($inc_ip)=@$def[$idx_inc_ip];
    my($prb_ip)=@$def[$idx_prb_ip];
    my($rpy_ip)=@$def[$idx_rpy_ip];
    my($ign_ip)=@$def[$idx_ign_ip];

    my($non_n)=@$def[$idx_non_n];
    my($rpy_n)=@$def[$idx_rpy_n];
    my($ign_n)=@$def[$idx_ign_n];

    my($stl_sr)=@$def[$idx_stl_sr];
    my($ign_sr)=@$def[$idx_ign_sr];

    vLogHTML("<FONT SIZE=\"+1\">Initialization</FONT><BR>");
    goto error if nd2NoNce($IF) != 0;
    vClear($IF);

    vLogHTML("<FONT SIZE=\"+1\">Test</FONT><BR>");
    $pktdesc{$ptn}="Send $msg";
    my(%ret)=vSend($IF, $ptn);
    my($s)=ndStatusNum2Str(ndStatus(
                                    $IF, $ret{sentTime1},
                                    @$inc_ip, @$prb_ip, @$rpy_ip, @$ign_ip,
                                    @$non_n, @$rpy_n, @$ign_n,
                                    @$stl_sr, @$ign_sr,
                                    )
                       );
    return $s;

error:
    return("ERROR");
}


########################################################################
__END__

=head1 NAME

hostRecvRs - Verifying that NS has no effect on a host's neighbor cache entry

=head1 TARGET

Host

=head1 SYNOPSIS

  hostRecvRs.seq [-tooloption ...] -p hostRecvRs.def

=head1 INITIALIZATION

  Clear a neighbor cache entry for TN.

=head1 TEST PROCEDURE

B<hostRecvRs> verifies that NS has no effect on a host's neighbor cache entry.

=begin html
<PRE>
  TN               NUT
  ----------------------
  State: No neighbor cache entry (for TN)
<BR>
  ==== <A HREF="#JDG1">RS</A> ===>
       valid RS:
           src=TN's link-local
           dst=all-router
           w/ SLLA
       invalid RS:
<BR>
  <A HREF="#JDG1">Judgment</A>: <A HREF="nd.html">Examining NUT's neighbor cache state</A>
</pre>

=end html

=head1 JUDGMENT

=begin html
<PRE>
<A NAME="JDG1"></A>
  1. A host must silently discard any received RS messages.
  ===============================================+===========================
  RS sent by TN                                  | NUT's Neighbor Cache
                                                 | Entry State
  ---------------------+--------------+----------+--------+------------------
  Destination          | SLLA         | Validity | Current | New
  =====================+==============+==========+========+==================
  all-router           | TN's LLA     | valid    | none   | unchanged
  ---------------------+--------------+----------+--------+------------------
  all-node             | TN's LLA     | invalid  | none   | unchanged
  ---------------------+--------------+----------+--------+------------------
  NUT's link-local     | TN's LLA     | invalid  | none   | unchanged
  =====================+==============+==========+========+==================
</PRE>

=end html

=head1 TERMINATION

  N/A

=head1 NOTE

  The test does not invoke any remote command.

=head1 REFERENCE

=begin html
<pre>
RFC2461
<hr>
6.2.6.  Processing Router Solicitations<BR>
   <B>A host MUST silently discard any received Router Solicitation
   messages.</B>
</pre>

=end html

=head1 SEE ALSO

  perldoc V6evalTool
  perldoc V6evalRemote

=cut
