#!/usr/bin/perl
#
# $Copyright_v6PC$
#
# $Intap$
# $TINY: RA_wPXLLA.seq,v 1.5 2002/03/05 03:04:59 masaxmasa Exp $
# 

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

#------------------------------------------------------
#----- get sequence arguments
#------------------------------------------------------
$howto_initNUT="none";
$send = "ok";
foreach (@ARGV) {
# How to configure address of NUT?
# sample: boot, ra, manual+_GLOBAL0A0N_UCAST
    /^addrconf=(\S+)/ && do {$SAA::howto_addrconf=$1; next; };

# How to initialize NUT?
# sample: none, DADSuccess_boot, DADFail_boot
    /^init=(\S+)/     && do {$howto_initNUT=$1; next; };

# "none" if send no pakcet to NUT in state DADPostSendNS
# sample: ok, none
    /^send=(\S+)/     && do {$send=$1; next; };

# sequence debug options
# sample: qR
    /^sd=(\S+)/       && do {$seqdebugopt=$1; next; };
    seqERROR("Unknown sequence option '$_'");
}
#------------------------------------------------------

#----- test condition
$IF=Link0;                 # network interface

$max_retry_count = 10;     # retry if NUT state becomes DADPostSendNS
$max_retry_count = 2 if $SAA::sd =~ /q/;    # quick retry
$send_interval  = 1;
	       # 1[sec] time between DAD NS and DAD NS, send to NUT
               #     (RandomDelay is 0-1sec  e.g. default RetransTimer 1000msec)


##########################################################
#----- Check Target Type

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

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

##########################################################
#----- initialize NUT
vLog("*** Target initialization phase ***");
if($V6evalTool::NutDef{System} ne "manual"){ vSleep($SAA::test_interval); }
$rret=vRemote("reboot_async.rmt","","timeout=$SAA::wait_rebootcmd");
vLog("reboot_async.rmt returned status $rret");

#----- start Capturing
vLog("*** Target testing phase ***");
vCapture($IF);

#----- LLA PHASE
#----- Wait DAD NS from NUT or timeout
vLog("TN wait DAD NS(DADNS_from_NUT) from NUT for $SAA::wait_dadns{$SAA::howto_addrconf} [sec],");

%ret1=vRecv($IF,$SAA::wait_dadns{$SAA::howto_addrconf},0,0,DADNS_from_NUT);

if ($ret1{status} != 0){
    vLog("TN wait DAD NS from NUT for $SAA::wait_dadns{$SAA::howto_addrconf}, but NUT had not transmit DAD NS");
    seqNG();
}

#----- RA PHASE
vLog("TN received DAD NS from NUT.");
vLog("OK! Let's go ahead!");
%ret2=vRecv($IF,$SAA::wait_rs,0,0,RS_from_NUT,RS_from_NUT_wSLL);

if ($ret2{status} != 0){
    vLog("Though TN had waited RS from NUT for $SAA::wait_rs,");
    vLog(" NUT seems not to send RS.");
    vLog(" Anyway TN is sending Unsolicited RA (Prefix=Link-Local)");
}else{
    vLog("TN received RS from NUT.");
    vLog("TN is sending RA (Prefix=Link-Local)");
}

vSend($IF, RA_LLA);

#----- Wait DAD NS from NUT or timeout
vLog("TN wait DAD NS for Link-local address from NUT for $SAA::wait_dadns{ra} [sec],");

%ret3=vRecv($IF,$SAA::wait_dadns{"ra"},0,0,DADNS_from_NUT);

if ($ret3{status} == 0){
    vLog("NUT had transmitted DAD NS for its Link-local address");
    vLog("by receiving RA with PrefixOption (Prefix==LLA).");
#----- check if NUT's address is configured
    vSleep($SAA::wait_addrconf_with_RA);

    if (seqCheckNUTAddrConfigured($IF) eq TRUE) {
       	vLog("NUT's Link-Local address is still available.");
        seqNG();
    }else{
       	vLog("NUT's Link-Local address is not available.");
       	seqNG();
    }
} elsif ($ret3{status} != 0){
    vLog("NUT had not transmitted DAD NS for Link-local address");
    vLog("by receiving RA with PrefixOption (Prefix==LLA).");
#----- check if NUT's address is configured
    if (seqCheckNUTAddrConfigured($IF) eq TRUE) {
       	vLog("NUT's Link-Local address is still available.");
        seqOK();
    }else{
       	vLog("NUT's Link-Local address is not available.");
       	seqNG();
    }
}

##########################################################


#end
########################################################################
__END__

=head1 NAME

RA_wPXLLA - check the process when NUT receives invalid RA which contains one Link-local prefix(PX=LLA)(NOT Re-assigning Link-local address)

=head1 TARGET

All Node

=head1 SYNOPSIS

RA_wPXLLA.seq [-tooloption ...] -pkt <packetdef> [addrconf=<addrconfname>] 

  -tooloption   : v6eval tool option
  <packetdef>   : packet definition file (v6eval tool option)
  <addrconfname>: how to configure address on NUT; boot/reboot

=begin html
<PRE>
 detail of v6eval tool option: see perldoc V6evalTool.pm, perldoc V6evalRemote.pm
</PRE>

=end html


=head1 INITIALIZATION

=begin html
<PRE>
 Reboot NUT or Initialize interface of NUT or Initialize IPv6 stack of NUT.
</PRE>

=end html

=head1 TEST PROCEDURE

=over 1

=item Test for Unicast address autoconfiguration

The following tests are prepared in this test package. See INDEX file.

B<Test for all node>

   When NUT receives invalid RA which contains Link-local Prefix,
   NUT MUST NOT assign autoconfigured address. 

B<Test sequence>

  TN                            NUT
  ---------------------------------
  Initialize NUT

  Configure address of NUT (reboot or interface initialization etc...)

  TN wait the DAD NS sent from NUT
  <=== Judgement #1: DAD NS =======
        name: DADNS_from_NUT

  <=== Judgement #2: RS ===========
        name: RS_from_NUT, RS_from_NUT_wSLL

  ==== Action #1: RA =============>
        name: RA_LLA

  X<== Judgement #3: DAD NS =======
        name: DADNS_from_NUT

  Wait for 5+DupAddrDetectTransmits*(RetransTimer/1000)[sec]

  Check if NUT's address is configured
  ==== Action #2: SOL NS =========>
        name: SOLNS_from_TN_SameTgt

  <=== Judgement #4: SOL NA =======
        name: NA_from_NUT, NA_from_NUT_woTLL



=back 1

=head1 JUDGEMENT

=over 1

=item Test for Unicast address autoconfiguration

B<Test for all NODE>

B<NUT performs Stateless Address Autoconfiguration on its interface>

   Judgement #1. NUT MUST transmit DAD NS for its autoconfigured Link-local address.
        name: DADNS_from_NUT
	src: ::0
	dst: solnode[NUT's tentative Link-local]
        TargetAddress: NUT's tentative Link-local

   Judgement #2. NUT SHOULD transmit RS.
        name: RS_from_NUT
	src: NUT's Link-local
	dst: allrouter

   Action #1. TN transmits RA which contains Link-local Prefix.
        name: RA_LLA
	src: TN's Link-local
	dst: allnode
	PXOPT: Link-local

   Judgement #3. NUT MUST NOT transmit DAD NS for its autoconfigured Link-local address in this timing.
        name: DADNS_from_NUT
        src: ::0
	dst: solnode[NUT's tentative Link-local]
        TargetAddress: NUT's tentative Link-local

   Action #2. TN transmits SOL NS to check if NUT's Link-local address is still available.
        name: SOLNS_from_TN_SameTgt
        src: TN's Link-local
	dst: solnode[NUT's Link-local]
        TargetAddress: NUT's Link-local

   Judgement #4. NUT MUST transmit SOL NA for its autoconfigured  Link-local address.
        name: NA_from_NUT, NA_from_NUT_woTLL
	src: NUT's Link-local
	dst: TN's Link-local
        TargetAddress: NUT's Link-local
        RFlag: 0
        SFlag: 1
        OFlag: 1


=back 1

=head1 REFERENCE

=begin html
<PRE>
RFC2462
<HR>
5.5.3.  Router Advertisement Processing <BR>
   (omit)
   For each Prefix-Information option in the Router Advertisement:
<BR>
    a) If the Autonomous flag is not set, silently ignore the
       Prefix Information
       option.
<BR>
<A NAME="REF"><B>
    b) If the prefix is the link-local prefix, silently ignore the
       Prefix Information option.
</B></A>
<BR>
    c) If the preferred lifetime is greater than the valid lifetime,
       silently ignore the Prefix Information option. A node MAY wish to
       log a system management error in this case.
<BR>
    d) If the prefix advertised does not match the prefix of an address
       already in the list, and the Valid Lifetime is not 0, form an
       address (and add it to the list) by combining the advertised
       prefix with the link's interface identifier as follows:
   (omit)
</PRE>
<BR>

=end html

=head1 SEE ALSO

=begin html
<PRE>
 detail of v6eval tool option: see perldoc V6evalTool.pm, perldoc V6evalRemote.pm
</PRE>

=end html

=cut

