//
// Copyright (C) 2003 Yokogawa Electric Corporation,
// INTAP(Interoperability Technology Association
// for Information Processing, Japan). 
// Copyright (C) IBM Corporation 2003.
// 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. However, using this software for the 
// purpose of testing or evaluating any products including merchantable 
// products may be permitted without any notification to the copyrighters.
// 
// 
// 
// 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.
//
//    Author: Kazuo Hiekata <hiekata@yamato.ibm.com>
//

#define NUT_ADDR         v4("192.168.1.1")
#define NUT_MAC_ADDR        nutether()

#define TN1_IPV4_ADDR       v4("192.168.10.1")
#define TN2_IPV4_ADDR       v4("192.168.10.2")
#define TN3_IPV4_ADDR       v4("192.168.10.3")
#define TN4_IPV4_ADDR       v4("192.168.10.4")
#define TN1_MAC_ADDR        ether("00:00:00:00:0a:01")
#define TN2_MAC_ADDR        ether("00:00:00:00:0a:02")
#define TN3_MAC_ADDR        ether("00:00:00:00:0a:03")
#define TN4_MAC_ADDR        ether("00:00:00:00:0a:04")

#define GROUP_1_ADDR        v4("224.10.10.1")
#define GROUP_2_ADDR        v4("224.10.10.2")
#define GROUP_MAC_ADDR_1    ether("01:00:5e:0a:0a:1")
#define GROUP_MAC_ADDR_2    ether("01:00:5e:0a:0a:2")

#define MCAST_QUERY             v4("224.0.0.1")
#define MCAST_REPORT            v4("224.0.0.22")
#define MCAST_QUERY_MAC_ADDR    ether("01:00:5e:00:00:01")
#define MCAST_REPORT_MAC_ADDR   ether("01:00:5e:00:00:16")


_HETHER_define(_HETHER_tn1_to_nut      , TN1_MAC_ADDR   , NUT_MAC_ADDR)
_HETHER_define(_HETHER_tn1_to_grp1      , TN1_MAC_ADDR   , GROUP_MAC_ADDR_1)
_HETHER_define(_HETHER_tn1_to_report      , TN1_MAC_ADDR   , MCAST_REPORT_MAC_ADDR)
_HETHER_define(_HETHER_nut_to_tn1      , NUT_MAC_ADDR   , TN1_MAC_ADDR)
_HETHER_define(_HETHER_nut_to_grp1      , NUT_MAC_ADDR , GROUP_MAC_ADDR_1)


//----------------------------------------------------------------------
// FEM_igmp_igmpquery
FEM_igmp_igmpquery(
	igmpquery_sample,
	_HETHER_tn1_to_grp1,
	{
		SourceAddress=TN1_IPV4_ADDR;
		DestinationAddress=GROUP_1_ADDR;
		TypeOfService = 192; //0xc0
		TTL = 1;
		option = opt_rtalert;
	},
	{
		GroupAddress = GROUP_1_ADDR;
		Resv = 0;
		SFlag = 0;
		QRV = 0;
		QQIC = 0;
		SourceAddress = TN2_IPV4_ADDR;
		SourceAddress = TN3_IPV4_ADDR;
		SourceAddress = TN4_IPV4_ADDR;
	}
)
//----------------------------------------------------------------------
// FEM_igmp_igmpv3report
FEM_igmp_igmpv3report(
	igmpv3report_sample_0,
	_HETHER_tn1_to_report,
	{
		SourceAddress=TN1_IPV4_ADDR;
		DestinationAddress=MCAST_REPORT;
		TypeOfService = 192; //0xc0
		TTL = 1;
		option = opt_rtalert;
	},
	{
		Reserved = 0;
	}
)
FEM_igmp_igmpv3report(
	igmpv3report_sample_1,
	_HETHER_tn1_to_report,
	{
		SourceAddress=TN1_IPV4_ADDR;
		DestinationAddress=MCAST_REPORT;
		TypeOfService = 192; //0xc0
		TTL = 1;
		option = opt_rtalert;
	},
	{
		Reserved = 0;
		IGMPv3_AddrRecord = addressrecord0;
		IGMPv3_AddrRecord = addressrecord1;
		IGMPv3_AddrRecord = addressrecord0;
		IGMPv3_AddrRecord = addressrecord1;
	}
)
IGMPv3_AddrRecord addressrecord0 {
		Type = 1;
		AuxDataLen = 2; // 32 bit * 2
		GroupAddress = GROUP_1_ADDR;
		SourceAddress = TN1_IPV4_ADDR;
		SourceAddress = TN2_IPV4_ADDR;
		SourceAddress = TN3_IPV4_ADDR;
		SourceAddress = TN4_IPV4_ADDR;
		AuxData = {0,1,2,3,4,5,6,7};
}
IGMPv3_AddrRecord addressrecord1 {
		Type = 4;
		AuxDataLen = 0;
		GroupAddress = GROUP_1_ADDR;
		SourceAddress = TN2_IPV4_ADDR;
}
//----------------------------------------------------------------------
// FEM_igmp_igmpv2report
FEM_igmp_igmpv2report(
	igmpv2report_sample,
	_HETHER_tn1_to_grp1,
	{
		SourceAddress=TN1_IPV4_ADDR;
		DestinationAddress=GROUP_1_ADDR;
		TypeOfService = 192; //0xc0
		TTL = 1;
		option = opt_rtalert;
	},
	{
		GroupAddress = GROUP_1_ADDR;
	}
)
//----------------------------------------------------------------------
// FEM_igmp_igmpv2leavegroup
FEM_igmp_igmpv2leavegroup(
	igmpv2leavegroup_sample,
	_HETHER_tn1_to_grp1,
	{
		SourceAddress=TN1_IPV4_ADDR;
		DestinationAddress=GROUP_1_ADDR;
		TypeOfService = 192; //0xc0
		TTL = 1;
		option = opt_rtalert;
	},
	{
		GroupAddress = GROUP_1_ADDR;
	}
)
//----------------------------------------------------------------------
// FEM_igmp_igmpv1report
FEM_igmp_igmpv1report(
	igmpv1report_sample,
	_HETHER_tn1_to_nut,
	{
		SourceAddress=TN1_IPV4_ADDR;
		DestinationAddress=GROUP_1_ADDR;
		Protocol = 2;
	},
	{
		GroupAddress = GROUP_1_ADDR;
	}
)

//================================================================
Opt_IPv4_RouterAlert opt_rtalert{
	Value = 0;
}

