#!/usr/bin/perl
#
# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
# Yokogawa Electric Corporation.
# All rights reserved.
# 
# Redistribution and use of this software in source and binary
# forms, with or without modification, are permitted provided that
# the following conditions and disclaimer are agreed and accepted
# by the user:
# 
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with
#    the distribution.
# 
# 3. Neither the names of the copyrighters, the name of the project
#    which is related to this software (hereinafter referred to as
#    "project") nor the names of the contributors may be used to
#    endorse or promote products derived from this software without
#    specific prior written permission.
# 
# 4. No merchantable use may be permitted without prior written
#    notification to the copyrighters.
# 
# 5. The copyrighters, the project and the contributors may prohibit
#    the use of this software at any time.
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHTERS, THE PROJECT AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING
# BUT NOT LIMITED THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.  IN NO EVENT SHALL THE
# COPYRIGHTERS, THE PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# $Id: IKEv2-SGW-R-1-2-3-1-A.seq,v 1.5 2009/05/28 07:26:47 akisada Exp $
#
################################################################

BEGIN
{
	push(@INC, '..');
}

END { }

use IKEv2;
use strict;


my $remote	= 'common_remote_index';


my $session = undef;
my $ret = undef;
my $str = undef;

my $ike_sa_init_req_param = undef;
my $ike_sa_init_resp_param = undef;
my $ike_auth_req_param = undef;
my $ike_auth_resp_param = undef;
my $create_child_sa_req_param = undef;
my $create_child_sa_resp_param = undef;
my $informational_req_param = undef;
my $informational_resp_param = undef;
my $material = undef;
my $child_sa_material_1 = undef;
my $child_sa_material_2 = undef;

my @local_informational_req = undef;
my @local_informational_resp = undef;


kLogHTML('<FONT COLOR="#FF0000" SIZE="+1"><U><B>TEST SETUP</B></U></FONT>');

my $tn = 'SGW';
my $nut = 'SGW';

#------------------------------#
# register IKEv2.pm            #
#------------------------------#
unless (IKEv2initialize($tn, $nut)) {
	IKEv2exitFatal('<FONT COLOR="#ff0000">IKEv2 module initializing failure</FONT>');
}


#------------------------------#
# configure TN                 #
#------------------------------#
unless (IKEv2setupTN()) {
	IKEv2exitFatal('<FONT COLOR="#ff0000">TN setup failure</FONT>');
}


#------------------------------#
# configure NUT                #
#------------------------------#
unless (IKEv2setupNUT()) {
	IKEv2exitFatal('<FONT COLOR="#ff0000">NUT setup failure</FONT>');
}

kLogHTML('<FONT COLOR="#FF0000" SIZE="+1"><U><B>TEST PROCEDURE</B></U></FONT>');


#------------------------------#
# prepare session handler      #
#------------------------------#
$session = IKEv2create_session('common_remote_index');
unless (defined($session)) {
	IKEv2exitFatal('<FONT COLOR="#ff0000">IKEv2 session creation failure</FONT>');
}


#--------------------------------------#
# send IKE_SA_INIT request to NUT      #
#--------------------------------------#
$str  = '<PRE>';
$str .= "    (R)             (I)\n";
$str .= "    NUT             TN1\n";
$str .= "     |               |\n";
$str .= "     |<--------------| IKE_SA_INIT request (HDR, SAi1, KEi, Ni)\n";
$str .= "     |               |\n";
$str .= "     V               V";
$str .= '</PRE>';

kLogHTML($str);



$ike_sa_init_req_param = devel_IKEv2send_IKE_SA_INIT_request($session, $remote);
unless (defined($ike_sa_init_req_param)) {
	kLogHTML(kDump_Common_Error());
	IKEv2exitFatal('<FONT COLOR="#ff0000">Can\'t send IKE_SA_INIT request.</FONT>');
}


#--------------------------------------#
# receive IKE_SA_INIT response by NUT  #
#--------------------------------------#
$str  = '<PRE>';
$str .= "    (R)             (I)\n";
$str .= "    NUT             TN1\n";
$str .= "     |               |\n";
$str .= "     |-------------->| IKE_SA_INIT response (HDR, SAr1, KEr, Nr)\n";
$str .= "     |               |\n";
$str .= "     V               V";
$str .= '</PRE>';

kLogHTML($str);


$ike_sa_init_resp_param = devel_IKEv2receive_IKE_SA_INIT_response($session,
								  $remote,
								  $ike_sa_init_req_param);
unless (defined($ike_sa_init_resp_param)) {
	kLogHTML(kDump_Common_Error());
	kLogHTML('<FONT COLOR="#ff0000">Can\'t observe IKE_SA_INIT response.</FONT>');
	IKEv2exitFail();
}


#--------------------------------------#
# generate keying material             #
#--------------------------------------#
$material = devel_IKEv2gen_keymat(1, $ike_sa_init_req_param, $ike_sa_init_resp_param);
unless (defined($material)) {
	kLogHTML(kDump_Common_Error());
	IKEv2exitFatal('<FONT COLOR="#ff0000">Can\'t generate keying material.</FONT>');
}


#--------------------------------------#
# send IKE_AUTH request to NUT         #
#--------------------------------------#
$str  = '<PRE>';
$str .= "    (R)             (I)\n";
$str .= "    NUT             TN1\n";
$str .= "     |               |\n";
$str .= "     |<--------------| IKE_AUTH request (HDR, SK {IDi, AUTH, N(USE_TRANSPORT_MODE), SAi2, TSi, TSr})\n";
$str .= "     |               |\n";
$str .= "     V               V";
$str .= '</PRE>';

kLogHTML($str);


$ike_auth_req_param = devel_IKEv2send_IKE_AUTH_request($session,
						       $remote,
						       $ike_sa_init_req_param,
						       $ike_sa_init_resp_param,
						       $material);
unless (defined($ike_auth_req_param)) {
	kLogHTML(kDump_Common_Error());
	IKEv2exitFatal('<FONT COLOR="#ff0000">Can\'t send IKE_AUTH request.</FONT>');
}


#--------------------------------------#
# receive IKE_AUTH response by NUT     #
#--------------------------------------#
$str  = '<PRE>';
$str .= "    (R)             (I)\n";
$str .= "    NUT             TN1\n";
$str .= "     |               |\n";
$str .= "     |-------------->| IKE_AUTH response (HDR, SK {IDr, AUTH, N(USE_TRANSPORT_MODE), SAr2, TSi, TSr)\n";
$str .= "     |               |\n";
$str .= "     V               V";
$str .= '</PRE>';

kLogHTML($str);


$ike_auth_resp_param = devel_IKEv2receive_IKE_AUTH_response($session,
							    $remote,
							    $ike_sa_init_req_param,
							    $ike_sa_init_resp_param,
							    $ike_auth_req_param,
							    $material);
unless (defined($ike_auth_resp_param)) {
	kLogHTML(kDump_Common_Error());
	kLogHTML('<FONT COLOR="#ff0000">Can\'t observe IKE_AUTH response.</FONT>');
	IKEv2exitFail();
}



#--------------------------------------#
# generate keying material (CHILD_SA)  #
#--------------------------------------#
$child_sa_material_1 = devel_IKEv2gen_child_sa_keymat(1,
						      $material,
						      $ike_sa_init_req_param,
						      $ike_sa_init_resp_param,
						      $ike_auth_req_param,
						      $ike_auth_resp_param,
						      undef,
						      undef);



#--------------------------------------#
# send CREATE_CHILD_SA request to NUT  #
#--------------------------------------#
$str  = '<PRE>';
$str .= "    (R)             (I)\n";
$str .= "    NUT             TN1\n";
$str .= "     |               |\n";
$str .= "     |<--------------| CREATE_CHILD_SA request (HDR, SK {IDi, AUTH, N(USE_TRANSPORT_MODE), SAi2, TSi, TSr})\n";
$str .= "     |               |\n";
$str .= "     V               V";
$str .= '</PRE>';

kLogHTML($str);



$create_child_sa_req_param = devel_IKEv2send_CREATE_CHILD_SA_request($session,
								     $remote,
								     $ike_sa_init_req_param,
								     $ike_sa_init_resp_param,
								     $ike_auth_req_param,
								     $material);
unless(defined($create_child_sa_req_param)) {
	kLogHTML(kDump_Common_Error());
	IKEv2exitFatal('<FONT COLOR="#ff0000">Can\'t send CREATE_CHILD_SA request.</FONT>');
}



#-----------------------------------------#
# receive CREATE_CHILD_SA response by NUT #
#-----------------------------------------#
$str  = '<PRE>';
$str .= "    (R)             (I)\n";
$str .= "    NUT             TN1\n";
$str .= "     |               |\n";
$str .= "     |-------------->| CREATE_CHILD_SA response (HDR, SK {IDr, AUTH, N(USE_TRANSPORT_MODE), SAr2, TSi, TSr)\n";
$str .= "     |               |\n";
$str .= "     V               V";
$str .= '</PRE>';

kLogHTML($str);



$create_child_sa_resp_param = devel_IKEv2receive_CREATE_CHILD_SA_response($session,
									  $remote,
									  $ike_sa_init_req_param,
									  $ike_sa_init_resp_param,
									  $create_child_sa_req_param,
									  $material);
unless(defined($create_child_sa_resp_param)) {
	kLogHTML(kDump_Common_Error());
	kLogHTML('<FONT COLOR="#ff0000">Can\'t observe CREATE_CHILD_SA response.</FONT>');
	IKEv2exitFail();
}



#------------------------------------------#
# generate keying material (2nd CHILD_SA)  #
#------------------------------------------#
$child_sa_material_2 = devel_IKEv2gen_child_sa_keymat(1,    # CREATE_CHILD_SA exchange
						      $material,
						      $ike_sa_init_req_param,
						      $ike_sa_init_resp_param,
						      $ike_auth_req_param,
						      $ike_auth_resp_param,
						      $create_child_sa_req_param,
						      $create_child_sa_resp_param);



#------------------------------------------------#
# send INFORMATIONAL Request (w/ delete payload) #
#------------------------------------------------#
$str  = '<PRE>';
$str .= "    (R)             (I)\n";
$str .= "    NUT             TN1\n";
$str .= "     |               |\n";
$str .= "     |<--------------| INFORMATIONAL Request (HDR, SK {D})\n";
$str .= "     |               |\n";
$str .= "     V               V";
$str .= '</PRE>';
        
kLogHTML($str);



my $req_delete_payload =
{	# Delete Payload
	'self'		=> 'D',	     # *** MUST BE HERE ***
	'nexttype'	=> undef,    # Next Payload
	'critical'	=> undef,    # Critical
	'reserved'	=> undef,    # RESERVED
	'length'	=> undef,    # Payload Length
	'id'		=> 'ESP',    # Protocol ID
	'spiSize'	=> '4',	     # SPI Size
	'spiCount'	=> '2',      # # of SPIs
	'spis'		=> $ike_auth_req_param->{'spi'}[0] . $create_child_sa_req_param->{'spi'}[0],    # SPI
};

my $common_informational_req = $gen_informational_req->{'common_remote_index'};
@local_informational_req = @{$common_informational_req};
# add Delete payload 
for (my $i = 0; $i < scalar(@local_informational_req); $i++) {
	if ($local_informational_req[$i]->{'self'} eq 'E') {
		splice(@local_informational_req, $i+1);
		push(@local_informational_req, $req_delete_payload);
		last;
	}
}
$gen_informational_req->{'EN-R-1-1-4-9.1'} = \@local_informational_req;


$informational_req_param = devel_IKEv2send_INFORMATIONAL_request($session,
								 'EN-R-1-1-4-9.1',
								 $ike_sa_init_req_param,
								 $ike_sa_init_resp_param,
								 $ike_auth_req_param,
								 $material);
unless(defined($informational_req_param)) {
	kLogHTML(kDump_Common_Error());
	kLogHTML('<FONT COLOR="#ff0000">Can\'t send INFORMATIONAL request.</FONT>');
	IKEv2exitFail();
}



#-----------------------------------------#
# receive INFORMATIONAL Request by NUT    #
#-----------------------------------------#
$str  = '<PRE>';
$str .= "    (R)             (I)\n";
$str .= "    NUT             TN1\n";
$str .= "     |               |\n";
$str .= "     |-------------->| INFORMATIONAL Response (HDR, SK {D})\n";
$str .= "     |               |\n";
$str .= "     V               V";
$str .= '</PRE>';

kLogHTML($str);


my $resp_delete_payload =
{	# Delete Payload
	'self'		=> 'D',		# *** MUST BE HERE ***
	'nexttype'	=> '0',		# Next Payload
	'critical'	=> '0',		# Critical
	'reserved'	=> '0',		# RESERVED
	'length'	=> '16',	# Payload Length
	'id'		=> 'ESP',	# Protocol ID
	'spiSize'	=> '4',		# SPI Size
	'spiCount'	=> '2',		# # of SPIs
	'spis'		=> $ike_auth_resp_param->{'spi'} . $create_child_sa_resp_param->{'spi'},	# SPI
};
my $common_informational_resp = $exp_informational_resp->{'common_remote_index'};
@local_informational_resp = @{$common_informational_resp};
# add Delete payload 
for (my $i = 0; $i < scalar(@local_informational_resp); $i++) {
	my $payload = $local_informational_resp[$i];

	if ($payload->{'self'} eq 'E') {
		push(@{$payload->{'innerPayloads'}}, $resp_delete_payload);
		$payload->{'innerType'} = $resp_delete_payload->{'self'};
		last;
	}
}
#set correct nexttype
for (my $i = 0; $i < scalar(@local_informational_resp); $i++) {
	my $payload = $local_informational_resp[$i];

	if ($payload->{'self'} eq 'HDR') {
		my $next = $local_informational_resp[$i+1]; 
		unless (defined($next)) {
			$payload->{'nexttype'} = '0';
			next;
		}
		if ($payload->{'nexttype'} eq $next->{'self'}) {
			next;
		}
		$payload->{'nexttype'} = $next->{'self'};
	}
}

$exp_informational_resp->{'EN-R-1-1-4-9.2'} = \@local_informational_resp;


$informational_resp_param = devel_IKEv2receive_INFORMATIONAL_response($session,
								      'EN-R-1-1-4-9.2',
								      $ike_sa_init_req_param,
								      $ike_sa_init_resp_param,
								      $informational_req_param,
								      $material);
unless (defined($informational_resp_param)) {
	kLogHTML(kDump_Common_Error());
	kLogHTML('<FONT COLOR="#ff0000">Can\'t observe INFORMATIONAL Response.</FONT>');
	IKEv2exitFail();
}


#--------------------------------------#
# exit with cleanup                    #
#--------------------------------------#
IKEv2exitPass();
# NOTREACHED

#
# perldoc
#
########################################################################
__END__

=head1 Title

  Test IKEv2.SGW.R.1.2.3.1: Receiving Delete Payload for Multiple CHILD_SA
  Part A: (BASIC)

=head1 Purpose

  To verify an IKEv2 device transmits a Delete Payload, when CHILD_SAs are deleted.

=head1 References

  * [RFC 4306] - Sections 2.4 and 3.11

=head1 Test Setup

  * Network Topology
      Connect the devices according to the Common Topology.
  * Configuration
      In each part, configure the devices according to the Common Configuration.
  * Pre-Sequence and Cleanup Sequence
      IKEv2 on the NUT is disabled after each part.

=head1 Procedure

=begin html

<BLOCKQUOTE>
<PRE>

   NUT                  TN1
  (SGW)                (SGW)
    |                    |
    |<-------------------| IKE_SA_INIT request (HDR, SAi1, KEi, Ni)
    |                    | (Packet #1)
    |------------------->| IKE_SA_INIT response (HDR, SAr1, KEr, Nr)
    |                    | (Judgement #1)
    |                    |
    |<-------------------| IKE_AUTH request (HDR, SK {IDi, AUTH, SAi2, TSi, TSr})
    |                    | (Packet #2)
    |------------------->| IKE_AUTH response (HDR, SK {IDr, AUTH, SAr2, TSi, TSr})
    |                    | (Judgement #2)
    |                    |
    |<-------------------| CREATE_CHILD_SA request (HDR, SK {SA, Ni, TSi, TSr})
    |                    | (Packet #3)
    |------------------->| CREATE_CHILD_SA response (HDR, SK {SA, Nr, TSi, TSr})
    |                    | (Judgement #3)
    |                    |
    |<-------------------| INFORMATIONAL request (HDR, SK {D})
    |                    | (Packet #4)
    |------------------->| INFORMATIONAL response (HDR, SK {D})
    |                    | (Judgement #4)
    |                    |
    V                    V
</PRE>
</BLOCKQUOTE>

<BLOCKQUOTE>
<TABLE BORDER>
<TR>
<TD><TT>Packet #1</TT></TD>
<TD><TT>See Common Packet #1</TT></TD>
</TR>
<TR>
<TD><TT>Packet #2</TT></TD>
<TD><TT>See below</TT></TD>
</TR>
<TR>
<TD><TT>Packet #3</TT></TD>
<TD><TT>See below</TT></TD>
</TR>
<TR>
<TD><TT>Packet #4</TT></TD>
<TD><TT>See below</TT></TD>
</TR>
</TABLE>
</BLOCKQUOTE>
<br>

<BLOCKQUOTE>
Packet #2: IKE_AUTH request
<TABLE BORDER>
<TR>
<TD>IPv6 Header</TD>
<TD colspan="2">Same as the Common Packet #5</TD>
</TR>
<TR>
<TD>UDP Header</TD>
<TD colspan="2">Same as the Common Packet #5</TD>
</TR>
<TR>
<TD>IKEv2 Header</TD>
<TD colspan="2">Same as the Common Packet #5</TD>
</TR>
<TR>
<TD>E Payload</TD>
<TD colspan="2">Same as the Common Packet #5</TD>
</TR>
<TR>
<TD>IDi Payload</TD>
<TD colspan="2">Same as the Common Packet #5</TD>
</TR>
<TR>
<TD>AUTH Payload</TD>
<TD colspan="2">Same as the Common Packet #5</TD>
</TR>
<TR>
<TD>N Payload</TD>
<TD colspan="2">Same as the Common Packet #5</TD>
</TR>
<TR>
<TD>SA Payload</TD>
<TD colspan="2">Same as the Common Packet #5</TD>
</TR>
<TR>
<TD rowspan="2">TSi Payload</TD>
<TD colspan="2">Other fields are same as the Common Packet #5</TD>
</TR>
<TR>
<TD>Traffic Selectors</TD>
<TD>See below</TD>
</TR>
<TR>
<TD rowspan="2">TSr Payload</TD>
<TD colspan="2">Other fields are same as the Common Packet #5</TD>
</TR>
<TR>
<TD>Traffic Selectors</TD>
<TD>See below</TD>
</TR>
</TABLE>
</BLOCKQUOTE>

<BLOCKQUOTE>
<TABLE BORDER>
<TR>
<TD rowspan="7">TSi Payload</TD>
<TD rowspan="7">Traffic Selector</TD>
<TD>TS Type</TD>
<TD>8 (IPV6_ADDR_RANGE)</TD>
</TR>
<TR>
<TD>IP Protocol ID</TD>
<TD>6 (TCP)</TD>
</TR>
<TR>
<TD>Selector Length</TD>
<TD>40</TD>
</TR>
<TR>
<TD>Start Port</TD>
<TD>0</TD>
</TR>
<TR>
<TD>End Port</TD>
<TD>65535</TD>
</TR>
<TR>
<TD>Starting Address</TD>
<TD>Prefix Y:0000:0000:0000:0000</TD>
</TR>
<TR>
<TD>Ending Address</TD>
<TD>Prefix Y:ffff:ffff:ffff:ffff</TD>
</TR>
</TABLE>
</BLOCKQUOTE>

<BLOCKQUOTE>
<TABLE BORDER>
<TR>
<TD rowspan="7">TSr Payload</TD>
<TD rowspan="7">Traffic Selector</TD>
<TD>TS Type</TD>
<TD>8 (IPV6_ADDR_RANGE)</TD>
</TR>
<TR>
<TD>IP Protocol ID</TD>
<TD>6 (TCP)</TD>
</TR>
<TR>
<TD>Selector Length</TD>
<TD>40</TD>
</TR>
<TR>
<TD>Start Port</TD>
<TD>0</TD>
</TR>
<TR>
<TD>End Port</TD>
<TD>65535</TD>
</TR>
<TR>
<TD>Starting Address</TD>
<TD>Prefix B:0000:0000:0000:0000</TD>
</TR>
<TR>
<TD>Ending Address</TD>
<TD>Prefix B:ffff:ffff:ffff:ffff</TD>
</TR>
</TABLE>
</BLOCKQUOTE>
<br>

<BLOCKQUOTE>
Packet #3: CREATE_CHILD_SA request
<TABLE BORDER>
<TR>
<TD>IPv6 Header</TD>
<TD colspan="2">Same as the Common Packet #9</TD>
</TR>
<TR>
<TD>UDP Header</TD>
<TD colspan="2">Same as the Common Packet #9</TD>
</TR>
<TR>
<TD>IKEv2 Header</TD>
<TD colspan="2">Same as the Common Packet #9</TD>
</TR>
<TR>
<TD>E Payload</TD>
<TD colspan="2">Same as the Common Packet #9</TD>
</TR>
<TR>
<TD>N Payload</TD>
<TD colspan="2">Same as the Common Packet #9</TD>
</TR>
<TR>
<TD>SA Payload</TD>
<TD colspan="2">Same as the Common Packet #9</TD>
</TR>
<TR>
<TD>Ni, Nr Payload</TD>
<TD colspan="2">Same as the Common Packet #9</TD>
</TR>
<TR>
<TD rowspan="2">TSi Payload</TD>
<TD colspan="2">Other fields are same as the Common Packet #9</TD>
</TR>
<TR>
<TD>Traffic Selectors</TD>
<TD>See below</TD>
</TR>
<TR>
<TD rowspan="2">TSr Payload</TD>
<TD colspan="2">Other fields are same as the Common Packet #9</TD>
</TR>
<TR>
<TD>Traffic Selectors</TD>
<TD>See below</TD>
</TR>
</TABLE>
</BLOCKQUOTE>

<BLOCKQUOTE>
<TABLE BORDER>
<TR>
<TD rowspan="7">TSi Payload</TD>
<TD rowspan="7">Traffic Selector</TD>
<TD>TS Type</TD>
<TD>8 (IPV6_ADDR_RANGE)</TD>
</TR>
<TR>
<TD>IP Protocol ID</TD>
<TD>58 (ICMPv6)</TD>
</TR>
<TR>
<TD>Selector Length</TD>
<TD>40</TD>
</TR>
<TR>
<TD>Start Port</TD>
<TD>0</TD>
</TR>
<TR>
<TD>End Port</TD>
<TD>65535</TD>
</TR>
<TR>
<TD>Starting Address</TD>
<TD>Prefix Y:0000:0000:0000:0000</TD>
</TR>
<TR>
<TD>Ending Address</TD>
<TD>Prefix Y:ffff:ffff:ffff:ffff</TD>
</TR>
</TABLE>
</BLOCKQUOTE>

<BLOCKQUOTE>
<TABLE BORDER>
<TR>
<TD rowspan="7">TSr Payload</TD>
<TD rowspan="7">Traffic Selector</TD>
<TD>TS Type</TD>
<TD>8 (IPV6_ADDR_RANGE)</TD>
</TR>
<TR>
<TD>IP Protocol ID</TD>
<TD>58 (ICMPv6)</TD>
</TR>
<TR>
<TD>Selector Length</TD>
<TD>40</TD>
</TR>
<TR>
<TD>Start Port</TD>
<TD>0</TD>
</TR>
<TR>
<TD>End Port</TD>
<TD>65535</TD>
</TR>
<TR>
<TD>Starting Address</TD>
<TD>Prefix B:0000:0000:0000:0000</TD>
</TR>
<TR>
<TD>Ending Address</TD>
<TD>Prefix B:ffff:ffff:ffff:ffff</TD>
</TR>
</TABLE>
</BLOCKQUOTE>
<br>

<BLOCKQUOTE>
Packet #4: INFORMATIONAL request
<TABLE BORDER>
<TR>
<TD>IPv6 Header</TD>
<TD colspan="2">Same as the Common Packet #17</TD>
</TR>
<TR>
<TD>UDP Header</TD>
<TD colspan="2">Same as the Common Packet #17</TD>
</TR>
<TR>
<TD>IKEv2 Header</TD>
<TD colspan="2">Same as the Common Packet #17</TD>
</TR>
<TR>
<TD rowspan="2">E Payload</TD>
<TD colspan="2">Other fields are same as the Common Packet #17</TD>
</TR>
<TR>
<TD>Next Payload</TD>
<TD>42 (Delete)</TD>
</TR>
<TR>
<TD rowspan="9">Delete Payload</TD>
<TD>Next Payload</TD>
<TD>0 (last)</TD>
</TR>
<TR>
<TD>Critical</TD>
<TD>0</TD>
</TR>
<TR>
<TD>Reserved</TD>
<TD>0</TD>
</TR>
<TR>
<TD>Payload Length</TD>
<TD>16</TD>
</TR>
<TR>
<TD>Procotol ID</TD>
<TD>3 (ESP)</TD>
</TR>
<TR>
<TD>SPI Size</TD>
<TD>4</TD>
</TR>
<TR>
<TD># of SPIs</TD>
<TD>2</TD>
</TR>
<TR>
<TD rowspan="2">Security Parameter Index(es) (SPI)</TD>
<TD>SPI negotiated by Initial Exchange</TD>
</TR>
<TR>
<TD>SPI negotiated by CREATE_CHILD_SA exchange</TD>
</TR>
</TABLE>
</BLOCKQUOTE>
<br>

=end html

  Part A: (ADVANCED)
     1. TN starts to negotiate with NUT by sending IKE_SA_INIT request.
     2. Observe the messages transmitted on Link A..
     3. After reception of IKE_SA_INIT response from the NUT, TN transmits an IKE_AUTH
         request to the NUT.
     4. Observe the messages transmitted on Link A..
     5. TN1 transmits a CREATE_CHILD_SA request to establish a new CHILD_SA to the NUT.
     6. Observe the messages transmitted on Link A..
     7. TN1 transmits an INFORMATIONAL request with a Delete payload including the first
         negotiated CHILD_SA's inbound SPI and the second negotiated CHILD_SA's inbound SPI.
     8. Observe the messages transmitted on Link A..

=head1 Observable Result

  Part A
       Step 2: Judgment #1
       The NUT transmits an IKE_SA_INIT response including "ENCR_3DES",
       "PRF_HMAC_SHA1", "AUTH_HMAC_SHA1_96" and "D-H group 2" as accepted
       algorithms.

       Step 4: Judgment #2
       The NUT transmits an IKE_AUTH response including "ENCR_3DES",
       "AUTH_HMAC_SHA1_96" and "No Extended Sequence Numbers" as accepted algorithms.

       Step 6: Judgment #3
       The NUT transmits a CREATE_CHILD_SA response including "ENCR_3DES",
       "AUTH_HMAC_SHA1_96" and "No Extended Sequence Numbers" as accepted algorithms.

       Step 8: Judgment #4
       The NUT transmits an INFORMATIONAL response with delete payload for SPIs which are
       negotiated by Initial Exchange and CREATE_CHILD_SA exchange.

=head1 Possible Problems

  * INFORMATIONAL response from NUT may not contain Delete Payload by
    implementation policy. This behavior is defined at section 1.4 in RFC 4306 as an
    exception.

=cut


