#!/usr/bin/perl
#
# $Copyright_v6PC$
#
# $Intap$
# $TINY: LLA_DAD_NSPostDAD_wSLL.seq,v 1.5 2002/03/05 03:04:56 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 host) {
    vCPP('-DRFLAG=0');
}
if($type eq router) {
    vCPP('-DRFLAG=1');
}
if($type eq special) {
    vCPP('-DRFLAG=any');
}


##########################################################
#----- Preparetion
vCapture($IF);
seqPrepareLLA($IF, $V6evalTool::NutDef{System});

#----- 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 ***");
vClear($IF);

#----- 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],");

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

if ($ret{status} == 0){
    %retSend=vSend($IF, DADNS_from_TN_wSLL);

    #----- check if NUT's address is configured
    vSleep($SAA::wait_addrconf);
    if (seqCheckNUTAddrConfigured($IF) eq TRUE) {
	vLog("NUT assigned the address to the interface.");
	if ($SAA::DupAddrDetectTransmits == 0) {
	    vLog("NUT transmit DAD NS though DupAddrDetectTransmits == 0");
	    seqNG();
	}else{
	    seqOK();
	}
    }else{
	vLog("Though NUT received invalid DAD NS (w/ SLL option),");
	vLog(" NUT seems to detect Address Duplication");
	seqNG();
    }
} else{
    vLog("TN wait DAD NS from NUT for $SAA::wait_dadns{$SAA::howto_addrconf}, but NUT had not transmit DAD NS");
    seqNG();
}
##########################################################


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

=head1 NAME

LLA_DAD_NSPostDAD_wSLL - check the process when NUT receives invalid DAD NS(contains SLL) with same Target address after sending DAD NS.

=head1 TARGET

All Node

=head1 SYNOPSIS

LLA_DAD_NSPostDAD_wSLL.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 configuration

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

B<Test for all node>

   NUT assignes autoconfigured address, even though NUT receives invalid 
   (contains SLL) DAD NS for same target address as NUT, while DAD process 
   (after transmitting DAD NS).

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

  ==== Action #1: DAD NS =========>
        name: DADNS_from_TN_wSLL

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

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

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


=back 1

=head1 JUDGEMENT

=over 1

=item Test for Link-local Unicast address autoconfiguration

B<Test for all NODE>

B<NUT performs Stateless Address Autoconfiguration(Link-local) 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

   Action #1. TN transmits invalid DAD NS which contains SLL
        name: DADNS_from_TN_wSLL
	src: ::0
	dst: solnode[NUT's tentative Link-local]
        TargetAddress: NUT's Link-local
	SLLOPT: TN's MAC address

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

   Judgement #2. 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 ( if NUT is a Router then 1)
        SFlag: 1
        OFlag: 1
	TLLOPT: NUT's MAC address

=back 1

=head1 REFERENCE

=begin html
<PRE>
RFC2462
<HR>
   (omit)
5.4.1.  Message Validation
<BR>
<A NAME="REF">
   <B>A node MUST silently discard any Neighbor Solicitation or
   Advertisement message that does not pass the validity checks
   specified in [DISCOVERY].</B></A> A solicitation that passes these validity  
   checks is called a valid solicitation or valid advertisement.
   (omit)
<BR>
</PRE>
<HR>
<PRE>
RFC2461
<HR>
   (omit)
4.3.  Neighbor Solicitation Message Format
<BR>
   Nodes send Neighbor Solicitations to request the link-layer address
   of a target node while also providing their own link-layer address to
   the target.  Neighbor Solicitations are multicast when the node needs
   to resolve an address and unicast when the node seeks to verify the
   reachability of a neighbor.
<BR>
         0                   1                   2                   3
         0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        |     Type      |     Code      |          Checksum             |
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        |                           Reserved                            |
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        |                                                               |
        +                                                               +
        |                                                               |
        +                       Target Address                          +
        |                                                               |
        +                                                               +
        |                                                               |
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        |   Options ...
        +-+-+-+-+-+-+-+-+-+-+-+-
<BR>
   IP Fields:
<BR>
   ICMP Fields:
<BR>
      Type           135
<BR>
      Code           0
<BR>
      Checksum       The ICMP checksum.  See [ICMPv6].
<BR>
      Reserved       This field is unused.  It MUST be initialized to
                     zero by the sender and MUST be ignored by the
                     receiver.
<BR>
      Target Address
                     The IP address of the target of the solicitation.
                     It MUST NOT be a multicast address.
<BR>
   Possible options:
<BR>
      Source link-layer address
                     The link-layer address for the sender. <B>MUST NOT be
                     included when the source IP address is the
                     unspecified address.</B>  Otherwise, on link layers
                     that have addresses this option MUST be included in
                     multicast solicitations and SHOULD be included in
                     unicast solicitations.
<BR>
      Future versions of this protocol may define new option types.
      Receivers MUST silently ignore any options they do not recognize
      and continue processing the message.
<BR>
   (omit)
<BR>
<BR>
7.1.1.  Validation of Neighbor Solicitations
<BR>
   <B>A node MUST silently discard any received Neighbor Solicitation
   messages that do not satisfy all of the following validity checks:</B>
<BR>
      - The IP Hop Limit field has a value of 255, i.e., the packet
        could not possibly have been forwarded by a router.
<BR>
      - If the message includes an IP Authentication Header, the message
        authenticates correctly.
<BR>
      - ICMP Checksum is valid.
<BR>
      - ICMP Code is 0.
<BR>
      - ICMP length (derived from the IP length) is 24 or more octets.
<BR>
      - Target Address is not a multicast address.
<BR>
      - All included options have a length that is greater than zero.
<BR>
      - If the IP source address is the unspecified address, the IP
        destination address is a solicited-node multicast address.
<BR>
      <B>- If the IP source address is the unspecified address, there is no
        source link-layer address option in the message.</B>
<BR>
   The contents of the Reserved field, and of any unrecognized options,
   MUST be ignored.  Future, backward-compatible changes to the protocol
   may specify the contents of the Reserved field or add new options;
   backward-incompatible changes may use different Code values.
<BR>
   The contents of any defined options that are not specified to be used
   with Neighbor Solicitation messages MUST be ignored and the packet
   processed as normal.  The only defined option that may appear is the
   Source Link-Layer Address option.
<BR>
   A Neighbor Solicitation that passes the validity checks is called a
   "valid solicitation".
<BR>
   (omit)
</PRE>

=end html

=head1 SEE ALSO

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

=end html

=cut

