// SCTP Conformance Test Suite Implementation
// (C) Copyright Fujitsu Ltd. 2008, 2009
//
// This file is part of the SCTP Conformance Test Suite implementation.
//
// The SCTP Conformance Test Suite implementation is free software;
// you can redistribute it and/or modify it under the terms of
// the GNU General Public License version 2 as published by
// the Free Software Foundation.
//
// The SCTP Conformance Test Suite implementation is distributed in the
// hope that it will be useful, but WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with GNU CC; see the file COPYING.  If not, write to
// the Free Software Foundation, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
//
// Please send any bug reports or fixes you make to the
// email address(es):
//    networktest sctp <networktest-sctp@lists.sourceforge.net>
//
// Or submit a bug report through the following website:
//    http://networktest.sourceforge.net/
//
// Written or modified by:
//    Hiroaki Kago <linuxsctp-kg@ml.css.fujitsu.com>
//    Wei Yongjun <yjwei@cn.fujitsu.com>
//
// Any bugs reported given to us we will try to fix... any fixes shared will
// be incorporated into the next SCTP release.
//

#include "../common/STD_PKT_COMMON.def"

#ifndef SNDTSN
#define SNDTSN	INITTSN
#endif
#ifndef SACK
#define SACK	0
#endif

#define DATA_FRAGMENT_SEND(_pNAME, _pBFLAG, _pEFLAG) \
PKG_SCTP_SHORT_SEND( \
	sctp_chunk_data_##_pNAME, \
	{ \
		chunk = chunk_data_##_pNAME; \
	} \
) \
CHUNK_DATA chunk_data_##_pNAME { \
	UFlag = 1; \
	BFlag = _pBFLAG; \
	EFlag = _pEFLAG; \
	TSN = SNDTSN; \
	Identifier = 0; \
	SequenceNumber = 0; \
	Protocol = 0; \
	payload = data##_pNAME; \
} \
Payload data##_pNAME { \
	data = repeat(0, 1432); \
} \
PKG_SCTP_SHORT_RECV( \
	sctp_chunk_sack_##_pNAME, \
	{ \
		chunk = chunk_sack_##_pNAME; \
	} \
) \
\
CHUNK_SACK chunk_sack_##_pNAME { \
	ACK = SNDTSN; \
	AdvRecvWindow = any; \
	NumOfGapAck = 0; \
	NumOfDupTSN = 0; \
}

// _pNAME, _pBFLAG, _pEFLAG
DATA_FRAGMENT_SEND(1st, 1, 0)
DATA_FRAGMENT_SEND(2nd, 0, 1)


#define PMTU	30000

//
// SCTP CHUNK_DATA
//
PKG_SCTP_SHORT_RECV(
	sctp_chunk_data_big,
	{
		chunk = chunk_data_big;
	}
)

CHUNK_DATA chunk_data_big {
	UFlag = 0;
	Identifier = 0;
	SequenceNumber = 0;
	payload = data_big;
}

Payload data_big {
#if ENABLE_IPV6
	data = left(data1500, 1432 - 1);
#else
	data = left(data1500, 1452 - 1);
#endif
	data = repeat(0x00, 1);
}

#if (ENABLE_IPV6 == 0)

FEM_icmp4_destination_unreachable(
	icmp_pkt_too_big,
	_HETHER_tn2nut,
	{
		_SRC(v4(SCTP4_TN_NET0_ADDR));
		_DST(v4(SCTP4_NUT_NET0_ADDR));
	},
	{
		Code = 4;
		Unused = PMTU;
		payload = errdata;
	}
)

Payload errdata {
	data = left(_PACKET_IPV4_NAME(sctp_chunk_data_big), 64);
}

#else 

FEM_icmp6_packet_too_big (
	icmp_pkt_too_big,
	_HETHER_tn2nut,
	{
		_SRC(SCTP6_TN_NET0_ADDR);
		_DST(SCTP6_NUT_NET0_ADDR);
	},
	{
		MTU = PMTU;
		payload = errdata;
	}
)

Payload errdata {
	data = left(_PACKET_IPV6_NAME(sctp_chunk_data_big), 64);
}

#endif

PKG_SCTP_SHORT_RECV(
	sctp_chunk_data_seg_1st,
	{
		chunk = chunk_data_seg_1st;
	}
)

CHUNK_DATA chunk_data_seg_1st {
	UFlag = 0;
	BFlag = 1;
	EFlag = 0;
	TSN = any;
	Identifier = any;
	SequenceNumber = any;
	Protocol = any;
	payload = data_seg_1st;
}

//
// IPv4 will set PMTU to 1492, it is this correct?
//
Payload data_seg_1st {
#if ENABLE_IPV6
	data = repeat(0, 1432);
#else
	data = repeat(0, 1444);
#endif
}

PKG_SCTP_SHORT_RECV(
	sctp_chunk_data_seg_2nd,
	{
		chunk = chunk_data_seg_2nd;
	}
)

CHUNK_DATA chunk_data_seg_2nd {
	UFlag = 0;
	BFlag = 0;
	EFlag = 1;
	TSN = any;
	Identifier = any;
	SequenceNumber = any;
	Protocol = any;
	payload = data_seg_2nd;
}

Payload data_seg_2nd {
#if ENABLE_IPV6
	data = repeat(0, 1432);
#else
	data = repeat(0, 1420);
#endif
}

