module DIAMETER_Templates {

/* (C) 2019 by Harald Welte <laforge@gnumonks.org>
 * All rights reserved.
 *
 * Released under the terms of GNU General Public License, Version 2 or
 * (at your option) any later version.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

import from DIAMETER_Types all;
import from Osmocom_Types all;

/* https://www.iana.org/assignments/aaa-parameters/aaa-parameters.xhtml#aaa-parameters-4 */
type enumerated DIAMETER_Resultcode {
	/* Informational */
	DIAMETER_MULTI_ROUND_AUTH 			(1001),

	/* Success */
	DIAMETER_SUCCESS				(2001),
	DIAMETER_LIMITED_SUCCESS			(2002),
	DIAMETER_FIRST_REGISTRATION			(2003),
	DIAMETER_SUBSEQUENT_REGISTRATION		(2004),
	DIAMETER_UNREGISTERED_SERVICE 			(2005),
	DIAMETER_SUCCESS_SERVER_NAME_NOT_STORED		(2006),
	DIAMETER_SERVER_SELECTION			(2007),
	DIAMETER_SUCCESS_AUTH_SENT_SERVER_NOT_STORED 	(2008),
	DIAMETER_SUCCESS_RELOCATE_HA			(2009),

	/* Protocol Errors */
	DIAMETER_COMMAND_UNSUPPORTED			(3001),
	DIAMETER_UNABLE_TO_DELIVER			(3002),
	DIAMETER_REALM_NOT_SERVED			(3003),
	DIAMETER_TOO_BUSY				(3004),
	DIAMETER_LOOP_DETECTED				(3005),
	DIAMETER_REDIRECT_INDICATION			(3006),
	DIAMETER_APPLICATION_UNSUPPORTED		(3007),
	DIAMETER_INVALID_HDR_BITS			(3008),
	DIAMETER_INVALID_AVP_BITS			(3009),
	DIAMETER_UNKNOWN_PEER				(3010),
	DIAMETER_REALM_REDIRECT_INDICATION		(3011),

	/* Transient Failures */
	DIAMETER_AUTHENTICATION_REJECTED		(4001),
	DIAMETER_OUT_OF_SPACE				(4002),
	ELECTION_LOST					(4003),
	DIAMETER_ERROR_MIP_REPLY_FAILURE		(4005),
	DIAMETER_ERROR_HA_NOT_AVAILABLE			(4006),
	DIAMETER_ERROR_BAD_KEY				(4007),
	DIAMETER_ERROR_MIP_FILTER_NOT_SUPPORTED		(4008),
	DIAMETER_END_USER_SERVICE_DENIED		(4010),
	DIAMETER_CREDIT_CONTROL_NOT_APPLICABLE		(4011),
	DIAMETER_CREDIT_LIMIT_REACHED			(4012),
	DIAMETER_USER_NAME_REQUIRED			(4013),
	RESOURCE_FAILURE				(4014),

	DIAMETER_AUTHENTICATION_DATA_UNAVAILABLE	(4181),
	DIAMETER_ERROR_CAMEL_SUBSCRIPTION_PRESENT	(4882),

	/* Permanent Failure */
	DIAMETER_AVP_UNSUPPORTED			(5001),
	DIAMETER_UNKNOWN_SESSION_ID			(5002),
	DIAMETER_AUTHORIZATION_REJECTED			(5003),
	DIAMETER_INVALID_AVP_VALUE			(5004),
	DIAMETER_MISSING_AVP				(5005),
	DIAMETER_RESOURCES_EXCEEDED			(5006),
	DIAMETER_CONTRADICTING_AVPS			(5007),
	DIAMETER_AVP_NOT_ALLOWED			(5008),
	DIAMETER_AVP_OCCURS_TOO_MANY_TIMES		(5009),
	DIAMETER_NO_COMMON_APPLICATION			(5010),
	DIAMETER_UNSUPPORTED_VERSION			(5011),
	DIAMETER_UNABLE_TO_COMPLY			(5012),
	DIAMETER_INVALID_BIT_IN_HEADER			(5013),
	DIAMETER_INVALID_AVP_LENGTH			(5014),
	DIAMETER_INVALID_MESSAGE_LENGTH			(5015),
	DIAMETER_INVALID_AVP_BIT_COMBO			(5016),
	DIAMETER_NO_COMMON_SECURITY			(5017),
	DIAMETER_RADIUS_AVP_UNTRANSLATABLE		(5018),
	DIAMETER_ERROR_NO_FOREIGN_HA_SERVICE		(5024),
	DIAMETER_ERROR_END_TO_END_MIP_KEY_ENCRYPTION	(5025),
	DIAMETER_USER_UNKNOWN				(5030),
	DIAMETER_RATING_FAILED				(5031),
	DIAMETER_ERROR_USER_UNKNOWN			(5032),
	DIAMETER_ERROR_IDENTITIES_DONT_MATCH		(5033),
	DIAMETER_ERROR_IDENTITY_NOT_REGISTERED		(5034),
	DIAMETER_ERROR_ROAMING_NOT_ALLOWED		(5035),
	DIAMETER_ERROR_IDENTITY_ALREADY_REGISTERED	(5036),
	DIAMETER_ERROR_AUTH_SCHEME_NOT_SUPPORTED	(5037),
	DIAMETER_ERROR_IN_ASSIGNMENT_TYPE		(5038),
	DIAMETER_ERROR_TOO_MUCH_DATA			(5039),
	DIAMETER_ERROR_NOT_SUPPORTED_USER_DATA 		(5040),
	DIAMETER_ERROR_MIP6_AUTH_MODE			(5041),
	UNKNOWN_BINDING_TEMPLATE_NAME			(5042),
	BINDING_FAILURE					(5043),
	MAX_BINDINGS_SET_FAILURE			(5044),
	MAXIMUM_BINDINGS_REACHED_FOR_ENDPOINT		(5045),
	SESSION_EXISTS					(5046),
	INSUFFICIENT_CLASSIFIERS			(5047),
	DIAMETER_ERROR_EAP_CODE_UNKNOWN			(5048)
};

/* 3GPP TS 29.272 Section 7.1.8 */
const uint32_t c_DIAMETER_3GPP_Gx_AID := 16777238;
const uint32_t c_DIAMETER_3GPP_S6_AID := 16777251;
const uint32_t c_DIAMETER_3GPP_S13_AID := 16777252;
const uint32_t c_DIAMETER_3GPP_S7_AID := 16777308;

const octetstring c_def_sess_id := char2oct("ttcn3.session");

template (value) PDU_DIAMETER
ts_DIAMETER(template (value) BIT8 flags,
	    template (value) Command_Code cmd_code,
	    template (value) OCTET4 app_id := '00000000'O,
	    template (value) UINT32 hbh_id := '00000000'O,
	    template (value) UINT32 ete_id := '00000000'O,
	    template (value) AVP_list avps := {}
) := {
	version := 1,
	message_length := 0, /* overwritten */
	RPETxxxx := flags,
	command_code := cmd_code,
	application_id := app_id,
	hop_by_hop_id := hbh_id,
	end_to_end_id := ete_id,
	avps := avps
}
template (present) PDU_DIAMETER
tr_DIAMETER(template (present) BIT8 flags := ?,
	    template (present) Command_Code cmd_code := ?,
	    template (present) OCTET4 app_id := ?,
	    template (present) UINT32 hbh_id := ?,
	    template (present) UINT32 ete_id := ?,
	    template (present) AVP_list avps := ?) := {
	version := 1,
	message_length := ?,
	RPETxxxx := flags,
	command_code := cmd_code,
	application_id := app_id,
	hop_by_hop_id := hbh_id,
	end_to_end_id := ete_id,
	avps := avps
}
template (present) PDU_DIAMETER
tr_DIAMETER_A(
	    template (present) Command_Code cmd_code := ?,
	    template (present) OCTET4 app_id := ?,
	    template (present) UINT32 hbh_id := ?,
	    template (present) UINT32 ete_id := ?,
	    template (present) AVP_list avps := ?) :=
	tr_DIAMETER('0???????'B, cmd_code, app_id, hbh_id, ete_id, avps);
template (present) PDU_DIAMETER
tr_DIAMETER_R(
	    template (present) Command_Code cmd_code := ?,
	    template (present) OCTET4 app_id := ?,
	    template (present) UINT32 hbh_id := ?,
	    template (present) UINT32 ete_id := ?,
	    template (present) AVP_list avps := ?) :=
	tr_DIAMETER('1???????'B, cmd_code, app_id, hbh_id, ete_id, avps);


template (value) AVP_Header
ts_DIA_Hdr(template (value) AVP_Code avp_code,
		template (value) BIT8 flags := '01000000'B) := {
	avp_code := avp_code,
	VMPxxxxx := flags,
	avp_length := 0, /* overwritten */
	vendor_id := omit
}
template (present) AVP_Header
tr_DIA_Hdr(template (present) AVP_Code avp_code,
		template (present) BIT8 flags := '0???????'B) := {
	avp_code := avp_code,
	VMPxxxxx := flags,
	avp_length := ?, /* overwritten */
	vendor_id := omit
}

template (value) AVP_Header
ts_DIA_Hdr_3GPP(template (value) AVP_Code avp_code,
		template (value) BIT8 flags := '11000000'B) := {
	avp_code := avp_code,
	VMPxxxxx := flags,
	avp_length := 0, /* overwritten */
	vendor_id := vendor_id_3GPP
}
template (present) AVP_Header
tr_DIA_Hdr_3GPP(template (present) AVP_Code avp_code,
		template (present) BIT8 flags := '1???????'B) := {
	avp_code := avp_code,
	VMPxxxxx := flags,
	avp_length := ?, /* overwritten */
	vendor_id := vendor_id_3GPP
}

template (present) GenericAVP tr_SubcrIdType(template (present) DCC_NONE_Subscription_Id_Type t) := {
	avp := {
		avp_header := tr_DIA_Hdr(c_AVP_Code_DCC_NONE_Subscription_Id_Type),
		avp_data := {
			avp_DCC_NONE_Subscription_Id_Type := t
		}
	}
}

template (value) GenericAVP ts_AVP_OriginHost(template (value) charstring host) := {
	avp := {
		avp_header := ts_DIA_Hdr(c_AVP_Code_BASE_NONE_Origin_Host),
		avp_data := {
			avp_BASE_NONE_Origin_Host := host
		}
	}
}
template (present) GenericAVP tr_AVP_OriginHost(template (present) charstring host := ?) := {
	avp := {
		avp_header := tr_DIA_Hdr(c_AVP_Code_BASE_NONE_Origin_Host),
		avp_data := {
			avp_BASE_NONE_Origin_Host := host
		}
	}
}


template (value) GenericAVP ts_AVP_OriginRealm(template (value) charstring realm) := {
	avp := {
		avp_header := ts_DIA_Hdr(c_AVP_Code_BASE_NONE_Origin_Realm),
		avp_data := {
			avp_BASE_NONE_Origin_Realm := realm
		}
	}
}
template (present) GenericAVP tr_AVP_OriginRealm(template (present) charstring realm := ?) := {
	avp := {
		avp_header := tr_DIA_Hdr(c_AVP_Code_BASE_NONE_Origin_Realm),
		avp_data := {
			avp_BASE_NONE_Origin_Realm := realm
		}
	}
}


template (value) GenericAVP ts_AVP_OriginStateId(template (value) OCTET4 state_id) := {
	avp := {
		avp_header := ts_DIA_Hdr(c_AVP_Code_BASE_NONE_Origin_State_Id),
		avp_data := {
			avp_BASE_NONE_Origin_State_Id := state_id
		}
	}
}
template (present) GenericAVP tr_AVP_OriginStateId(template (present) OCTET4 state_id := ?) := {
	avp := {
		avp_header := tr_DIA_Hdr(c_AVP_Code_BASE_NONE_Origin_State_Id),
		avp_data := {
			avp_BASE_NONE_Origin_State_Id := state_id
		}
	}
}

template (value) GenericAVP ts_AVP_HostIpAddr(template (value) OCTET4 ipv4_addr) := {
	avp := {
		avp_header := ts_DIA_Hdr(c_AVP_Code_BASE_NONE_Host_IP_Address),
		avp_data := {
			avp_BASE_NONE_Host_IP_Address := {
				address_type := IP,
				address_data := ipv4_addr
			}
		}
	}
}

template (value) GenericAVP ts_AVP_VendorId(Vendor_Id vendor_id) := {
	avp := {
		avp_header := ts_DIA_Hdr(c_AVP_Code_BASE_NONE_Vendor_Id, '00000000'B),
		avp_data := {
			avp_BASE_NONE_Vendor_Id := int2oct(enum2int(vendor_id), 4)
		}
	}
}

template (value) GenericAVP ts_AVP_ProductName(charstring name) := {
	avp := {
		avp_header := ts_DIA_Hdr(c_AVP_Code_BASE_NONE_Product_Name, '00000000'B),
		avp_data := {
			avp_BASE_NONE_Product_Name := char2oct(name)
		}
	}
}

template (value) GenericAVP ts_AVP_FwRevision(octetstring fw_version) := {
	avp := {
		avp_header := ts_DIA_Hdr(c_AVP_Code_BASE_NONE_Firmware_Revision, '00000000'B),
		avp_data := {
			avp_BASE_NONE_Firmware_Revision := fw_version
		}
	}
}

template (value) GenericAVP ts_AVP_InbSecId(template (value) OCTET4 inb_sec_id) := {
	avp := {
		avp_header := ts_DIA_Hdr(c_AVP_Code_BASE_NONE_Inband_Security_Id),
		avp_data := {
			avp_BASE_NONE_Inband_Security_Id := inb_sec_id
		}
	}
}

template (value) GenericAVP ts_AVP_VendorSpecAppId(Vendor_Id vendor_id, uint32_t auth_app_id) := {
	avp := {
		avp_header := ts_DIA_Hdr(c_AVP_Code_BASE_NONE_Vendor_Specific_Application_Id),
		avp_data := {
			avp_BASE_NONE_Vendor_Specific_Application_Id := {
				{
					avp := {
						avp_header := ts_DIA_Hdr(c_AVP_Code_BASE_NONE_Vendor_Id),
						avp_data := {
							avp_BASE_NONE_Vendor_Id := int2oct(enum2int(vendor_id), 4)
						}
					}
				}, {
					avp := {
						avp_header := ts_DIA_Hdr(c_AVP_Code_BASE_NONE_Auth_Application_Id),
						avp_data := {
							avp_BASE_NONE_Auth_Application_Id := int2oct(auth_app_id, 4)
						}
					}
				}
			}
		}
	}
}

template (value) GenericAVP ts_AVP_AuthAppId(template (value) OCTET4 auth_app_id) := {
	avp := {
		avp_header := ts_DIA_Hdr(c_AVP_Code_BASE_NONE_Auth_Application_Id),
		avp_data := {
			avp_BASE_NONE_Auth_Application_Id := auth_app_id
		}
	}
}
template (present) GenericAVP tr_AVP_AuthAppId(template (present) OCTET4 auth_app_id := ?) := {
	avp := {
		avp_header := tr_DIA_Hdr(c_AVP_Code_BASE_NONE_Auth_Application_Id),
		avp_data := {
			avp_BASE_NONE_Auth_Application_Id := auth_app_id
		}
	}
}

template (value) GenericAVP ts_AVP_CcReqType(template (value) DCC_NONE_CC_Request_Type r) := {
	avp := {
		avp_header := ts_DIA_Hdr(c_AVP_Code_DCC_NONE_CC_Request_Type),
		avp_data := {
			avp_DCC_NONE_CC_Request_Type := r
		}
	}
}
template (present) GenericAVP tr_AVP_CcReqType(template (present) DCC_NONE_CC_Request_Type r := ?) := {
	avp := {
		avp_header := tr_DIA_Hdr(c_AVP_Code_DCC_NONE_CC_Request_Type),
		avp_data := {
			avp_DCC_NONE_CC_Request_Type := r
		}
	}
}

template (value) GenericAVP ts_AVP_CcReqNum(template (value) AVP_Unsigned32 n) := {
	avp := {
		avp_header := ts_DIA_Hdr(c_AVP_Code_DCC_NONE_CC_Request_Number),
		avp_data := {
			avp_DCC_NONE_CC_Request_Number := n
		}
	}
}
template (present) GenericAVP tr_AVP_CcReqNum(template (present) AVP_Unsigned32 n := ?) := {
	avp := {
		avp_header := tr_DIA_Hdr(c_AVP_Code_DCC_NONE_CC_Request_Number),
		avp_data := {
			avp_DCC_NONE_CC_Request_Number := n
		}
	}
}




template (value) GenericAVP ts_AVP_SuppVendorIdRaw(uint32_t vendor_id) := {
	avp := {
		avp_header := ts_DIA_Hdr(c_AVP_Code_BASE_NONE_Supported_Vendor_Id),
		avp_data := {
			avp_BASE_NONE_Supported_Vendor_Id := int2oct(vendor_id, 4)
		}
	}
}
template (value) GenericAVP ts_AVP_SuppVendorId(Vendor_Id vendor_id) :=
	ts_AVP_SuppVendorIdRaw(enum2int(vendor_id));

template (value) GenericAVP ts_AVP_ResultCode(DIAMETER_Resultcode res_code) := {
	avp := {
		avp_header := ts_DIA_Hdr(c_AVP_Code_BASE_NONE_Result_Code),
		avp_data := {
			avp_BASE_NONE_Result_Code := int2oct(enum2int(res_code), 4)
		}
	}
}
template (present) GenericAVP tr_AVP_ResultCode(DIAMETER_Resultcode res_code) := {
	avp := {
		avp_header := tr_DIA_Hdr(c_AVP_Code_BASE_NONE_Result_Code),
		avp_data := {
			avp_BASE_NONE_Result_Code := int2oct(enum2int(res_code), 4)
		}
	}
}

template (value) GenericAVP ts_AVP_AuthSessionState(template (value) BASE_NONE_Auth_Session_State ass := NO_STATE_MAINTAINED) := {
	avp := {
		avp_header := ts_DIA_Hdr(c_AVP_Code_BASE_NONE_Auth_Session_State),
		avp_data := {
			avp_BASE_NONE_Auth_Session_State := ass
		}
	}
}
template (present) GenericAVP tr_AVP_AuthSessionState(template (present) BASE_NONE_Auth_Session_State ass := ?) := {
	avp := {
		avp_header := tr_DIA_Hdr(c_AVP_Code_BASE_NONE_Auth_Session_State),
		avp_data := {
			avp_BASE_NONE_Auth_Session_State := ass
		}
	}
}

template (value) GenericAVP ts_AVP_SessionId(template (value) octetstring session_id) := {
	avp := {
		avp_header := ts_DIA_Hdr(c_AVP_Code_BASE_NONE_Session_Id),
		avp_data := {
			avp_BASE_NONE_Session_Id := session_id
		}
	}
}
template (present) GenericAVP tr_AVP_SessionId(template (present) octetstring session_id := ?) := {
	avp := {
		avp_header := tr_DIA_Hdr(c_AVP_Code_BASE_NONE_Session_Id),
		avp_data := {
			avp_BASE_NONE_Session_Id := session_id
		}
	}
}

/* 3.3 Destination Realm */
template (value) GenericAVP ts_AVP_DestinationRealm(template (value) charstring dest_realm) := {
	avp := {
		avp_header := ts_DIA_Hdr(c_AVP_Code_BASE_NONE_Destination_Realm),
		avp_data := {
			avp_BASE_NONE_Destination_Realm := dest_realm
		}
	}
}
template (present) GenericAVP tr_AVP_DestinationRealm(template (present) charstring dest_realm := ?) := {
	avp := {
		avp_header := tr_DIA_Hdr(c_AVP_Code_BASE_NONE_Destination_Realm),
		avp_data := {
			avp_BASE_NONE_Destination_Realm := dest_realm
		}
	}
}

/* 8.14 User-Name */
template (value) GenericAVP ts_AVP_UserName(template (value) octetstring uid) := {
	avp := {
		avp_header := ts_DIA_Hdr(c_AVP_Code_BASE_NONE_User_Name),
		avp_data := {
			avp_BASE_NONE_User_Name := uid
		}
	}
}
template (present) GenericAVP tr_AVP_UserName(template (present) octetstring uid := ?) := {
	avp := {
		avp_header := tr_DIA_Hdr(c_AVP_Code_BASE_NONE_User_Name),
		avp_data := {
			avp_BASE_NONE_User_Name := uid
		}
	}
}
template (value) GenericAVP ts_AVP_UserNameImsi(hexstring imsi) := ts_AVP_UserName(char2oct(hex2str(imsi)));
template (present) GenericAVP tr_AVP_UserNameImsi(hexstring imsi) := tr_AVP_UserName(char2oct(hex2str(imsi)));



/* TS 29.262 7.3.53 RAND */
template (value) GenericAVP ts_AVP_RAND(template (value) octetstring rand) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_RAND),
		avp_data := {
			avp_AAA_3GPP_RAND := rand
		}
	}
}

/* TS 29.262 7.3.54 XRES */
template (value) GenericAVP ts_AVP_XRES(template (value) octetstring xres) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_XRES),
		avp_data := {
			avp_AAA_3GPP_XRES := xres
		}
	}
}

/* TS 29.262 7.3.55 XRES */
template (value) GenericAVP ts_AVP_AUTN(template (value) octetstring autn) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_AUTN),
		avp_data := {
			avp_AAA_3GPP_AUTN := autn
		}
	}
}

/* TS 29.262 7.3.56 KASME */
template (value) GenericAVP ts_AVP_KASME(template (value) octetstring kasme) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_KASME),
		avp_data := {
			avp_AAA_3GPP_KASME := kasme
		}
	}
}

/* TS 29.262 7.3.23 Item-Number */
template (value) GenericAVP ts_AVP_ItemNumber(uint32_t num) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_KASME),
		avp_data := {
			avp_AAA_3GPP_Item_Number := int2oct(num, 4)
		}
	}
}

/* TS 29.262 7.3.18 E-UTRAN Vector */
template (value) GenericAVP ts_AVP_EutranVec(uint32_t item_num, octetstring rand, octetstring xres,
					     octetstring autn, octetstring kasme) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_E_UTRAN_Vector),
		avp_data := {
			avp_AAA_3GPP_E_UTRAN_Vector := {
				ts_AVP_ItemNumber(item_num),
				ts_AVP_RAND(rand),
				ts_AVP_XRES(xres),
				ts_AVP_AUTN(autn),
				ts_AVP_KASME(kasme)
			}
		}
	}
}

/* TS 29.262 7.3.2 Subscription-Data */
template (value) GenericAVP ts_AVP_3GPP_SubscriptionData(template (value) AVP_list content) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_Subscription_Data),
		avp_data := {
			avp_AAA_3GPP_Subscription_Data := content
		}
	}
}
template (present) GenericAVP
tr_AVP_3GPP_SubscriptionData(template (present) AVP_list content := ?) := {
	avp := {
		avp_header := tr_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_Subscription_Data),
		avp_data := {
			avp_AAA_3GPP_Subscription_Data := content
		}
	}
}


/* TS 29.262 7.3.17 Authentication-Info */
template (value) GenericAVP ts_AVP_3GPP_AuthInfo(template (value) AVP_list content) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_Authentication_Info),
		avp_data := {
			avp_AAA_3GPP_Authentication_Info := content
		}
	}
}
template (present) GenericAVP
tr_AVP_3GPP_AuthInfo(template (present) AVP_list content := ?) := {
	avp := {
		avp_header := tr_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_Authentication_Info),
		avp_data := {
			avp_AAA_3GPP_Authentication_Info := content
		}
	}
}

/* TS 29.262 7.3.9 Visited-PLMN-Id */
template (value) GenericAVP ts_AVP_3GPP_VisitedPlmnId(template (value) octetstring id) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_Visited_PLMN_Id),
		avp_data := {
			avp_AAA_3GPP_Visited_PLMN_Id := id
		}
	}
}
template (present) GenericAVP tr_AVP_3GPP_VisitedPlmnId(template (present) octetstring id := ?) := {
	avp := {
		avp_header := tr_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_Visited_PLMN_Id),
		avp_data := {
			avp_AAA_3GPP_Visited_PLMN_Id := id
		}
	}
}

/* TS 29.262 7.3.13 RAT-Type */
template (value) GenericAVP ts_AVP_3GPP_RatType(template (value) PCC_3GPP_RAT_Type rat_type) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_PCC_3GPP_RAT_Type),
		avp_data := {
			avp_PCC_3GPP_RAT_Type := rat_type
		}
	}
}
template (present) GenericAVP tr_AVP_3GPP_RatType(template (present) PCC_3GPP_RAT_Type rat_type := ?) := {
	avp := {
		avp_header := tr_DIA_Hdr_3GPP(c_AVP_Code_PCC_3GPP_RAT_Type),
		avp_data := {
			avp_PCC_3GPP_RAT_Type := rat_type
		}
	}
}

/* TS 29.262 7.3.7 ULR-Flags */
template (value) GenericAVP ts_AVP_3GPP_UlrFlags(template (value) UINT32 flags) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_ULR_Flags),
		avp_data := {
			avp_AAA_3GPP_ULR_Flags := flags
		}
	}
}
template (present) GenericAVP tr_AVP_3GPP_UlrFlags(template (present) UINT32 flags := ?) := {
	avp := {
		avp_header := tr_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_ULR_Flags),
		avp_data := {
			avp_AAA_3GPP_ULR_Flags := flags
		}
	}
}

/* TS 29.262 7.3.8 ULA-Flags */
template (value) GenericAVP ts_AVP_3GPP_UlaFlags(template (value) UINT32 flags) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_ULA_Flags),
		avp_data := {
			avp_AAA_3GPP_ULA_Flags := flags
		}
	}
}
template (present) GenericAVP tr_AVP_3GPP_UlaFlags(template (present) UINT32 flags := ?) := {
	avp := {
		avp_header := tr_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_ULA_Flags),
		avp_data := {
			avp_AAA_3GPP_ULA_Flags := flags
		}
	}
}



template (value) GenericAVP ts_AVP_NumOfReqVectors(template (value) UINT32 num_req := '00000004'O) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_Number_Of_Requested_Vectors),
		avp_data := {
			avp_AAA_3GPP_Number_Of_Requested_Vectors := num_req
		}
	}
}

template (value) GenericAVP ts_AVP_ImmReqPref(template (value) UINT32 par := '00000000'O) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_Immediate_Response_Preferred),
		avp_data := {
			avp_AAA_3GPP_Immediate_Response_Preferred := par
		}
	}
}


/* 7.3.11 Requested-EUTRAN-Authentication-Info */
template (value) GenericAVP ts_AVP_RequestedEutranAuthInfo(template (value) UINT32 num_vec := '00000004'O) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_Requested_EUTRAN_Authentication_Info),
		avp_data := {
			avp_AAA_3GPP_Requested_EUTRAN_Authentication_Info := {
				ts_AVP_NumOfReqVectors(num_vec),
				ts_AVP_ImmReqPref('00000000'O)
			}
		}
	}
}


/* TS 29.262 7.3.27 Context-Identifier */
template (value) GenericAVP ts_AVP_3GPP_ContextId(uint32_t ctx) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_Context_Identifier),
		avp_data := {
			avp_AAA_3GPP_Context_Identifier := int2oct(ctx, 4)
		}
	}
}

/* Ts 29.262 7.3.29 Subscriber-Status */
template (value) GenericAVP ts_AVP_3GPP_SubscriberStatus(template (value) AAA_3GPP_Subscriber_Status sts) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_Subscriber_Status),
		avp_data := {
			avp_AAA_3GPP_Subscriber_Status := sts
		}
	}
}

template (value) GenericAVP ts_AVP_3GPP_SubscrRauTauTmr(uint32_t tmr) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_Subscribed_Periodic_RAU_TAU_Timer),
		avp_data := {
			avp_AAA_3GPP_Subscribed_Periodic_RAU_TAU_Timer := int2oct(tmr, 4)
		}
	}
}

/* TS 29.262 7.3.33 All-APN-Configurations-Included-Indicator */
template (value) GenericAVP ts_AVP_3GPP_AllApnConfigsIncl(template (value) AAA_3GPP_All_APN_Configurations_Included_Indicator ind := All_APN_CONFIGURATIONS_INCLUDED) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_All_APN_Configurations_Included_Indicator),
		avp_data := {
			avp_AAA_3GPP_All_APN_Configurations_Included_Indicator := ind
		}
	}
}

/* TS 29.262 7.3.34 APN-Configuration-Profile */
template (value) GenericAVP ts_AVP_3GPP_ApnConfigProfile(template (value) AVP_list content) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_APN_Configuration_Profile),
		avp_data := {
			avp_AAA_3GPP_APN_Configuration_Profile := content
		}
	}
}

/* TS 29.262 7.3.35 APN-Configuration */
template (value) GenericAVP ts_AVP_3GPP_ApnConfig(uint32_t ctx, AAA_3GPP_PDN_Type pdn_type,
						  charstring apn) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_APN_Configuration_Profile),
		avp_data := {
			avp_AAA_3GPP_APN_Configuration := {
				ts_AVP_3GPP_ContextId(ctx),
				ts_AVP_3GPP_PdnType(pdn_type),
				ts_AVP_3GPP_EpsSubscrQosProfile(1, 1),
				ts_AVP_ServiceSelection(apn)
			}
		}
	}
}

/* TS 29.262 7.3.36 Service-Selection (refers to RFC 5778) */
template (value) GenericAVP ts_AVP_ServiceSelection(charstring apn) := {
	avp := {
		avp_header := ts_DIA_Hdr(c_AVP_Code_MIPv6_NONE_Service_Selection),
		avp_data := {
			avp_MIPv6_NONE_Service_Selection := char2oct(apn)
		}
	}
}

template (value) GenericAVP ts_AVP_3GPP_QosClassId(uint32_t id) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_PCC_3GPP_QoS_Class_Identifier),
		avp_data := {
			avp_PCC_3GPP_QoS_Class_Identifier := int2oct(id, 4)
		}
	}
}

template (value) GenericAVP ts_AVP_3GPP_PriorityLevel(uint32_t prio) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_PCC_3GPP_Priority_Level),
		avp_data := {
			avp_PCC_3GPP_Priority_Level := int2oct(prio, 4)
		}
	}
}


template (value) GenericAVP ts_AVP_3GPP_AllocRetenPrio(uint32_t prio) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_PCC_3GPP_Allocation_Retention_Priority),
		avp_data := {
			avp_PCC_3GPP_Allocation_Retention_Priority := {
				ts_AVP_3GPP_PriorityLevel(prio)
				/* pre-emption capability */
				/* pre-emption vulnerability */
			}
		}
	}
}

template (value) GenericAVP ts_AVP_3GPP_EpsSubscrQosProfile(uint32_t qos_class, uint32_t prio) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_EPS_Subscribed_QoS_Profile),
		avp_data := {
			avp_AAA_3GPP_EPS_Subscribed_QoS_Profile := {
				ts_AVP_3GPP_QosClassId(qos_class),
				ts_AVP_3GPP_AllocRetenPrio(prio)
			}
		}
	}
}


/* TS 29.262 7.3.41 AMBR */
template (value) GenericAVP ts_AVP_3GPP_AMBR(uint32_t ul, uint32_t dl) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_AMBR),
		avp_data := {
			avp_AAA_3GPP_AMBR := {
				ts_AVP_3GPP_MaxReqBwUL(ul),
				ts_AVP_3GPP_MaxReqBwDL(dl)
			}
		}
	}
}

template (value) GenericAVP ts_AVP_3GPP_MaxReqBwUL(uint32_t bw) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_RX_3GPP_Max_Requested_Bandwidth_UL),
		avp_data := {
			avp_RX_3GPP_Max_Requested_Bandwidth_UL := int2oct(bw, 4)
		}
	}
}

template (value) GenericAVP ts_AVP_3GPP_MaxReqBwDL(uint32_t bw) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_RX_3GPP_Max_Requested_Bandwidth_DL),
		avp_data := {
			avp_RX_3GPP_Max_Requested_Bandwidth_DL := int2oct(bw, 4)
		}
	}
}



/* TS 29.262 7.3.62 PDN-Type */
template (value) GenericAVP ts_AVP_3GPP_PdnType(template (value) AAA_3GPP_PDN_Type pdn_type) := {
	avp := {
		avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_AAA_3GPP_PDN_Type),
		avp_data := {
			avp_AAA_3GPP_PDN_Type := pdn_type
		}
	}
}



/* 5.3.2 Capabilities Exchange Answer */
template (value) PDU_DIAMETER
ts_DIA_CEA(template (value) UINT32 hbh_id, template (value) UINT32 ete_id,
	   template (value) charstring origin_host, template (value) charstring origin_realm,
	   template (value) octetstring host_ip, uint32_t vendor_app_id)
:= ts_DIAMETER(flags:='00000000'B, cmd_code:=Capabilities_Exchange, hbh_id:=hbh_id, ete_id:=ete_id,
	avps := {
		ts_AVP_ResultCode(DIAMETER_SUCCESS),
		ts_AVP_OriginHost(origin_host),
		ts_AVP_OriginRealm(origin_realm),
		ts_AVP_HostIpAddr(host_ip),
		ts_AVP_VendorId(vendor_id_3GPP),
		ts_AVP_ProductName("TTCN-3 Testsuite"),
		ts_AVP_OriginStateId('00000001'O),
		ts_AVP_SuppVendorIdRaw(5535), /* 3GPP2 */
		ts_AVP_SuppVendorId(vendor_id_3GPP),
		ts_AVP_SuppVendorIdRaw(13019), /* ETSI */
		ts_AVP_AuthAppId('FFFFFFFF'O),
		ts_AVP_InbSecId('00000000'O),
		ts_AVP_VendorSpecAppId(vendor_id_3GPP, vendor_app_id)
	});


template (value) PDU_DIAMETER
ts_DIA_AIR(/* template (value) */ hexstring imsi,
	   template (value) octetstring sess_id := c_def_sess_id,
	   template (value) charstring orig_host := "ttcn3.localdomain",
	   template (value) charstring orig_realm := "localdomain",
	   template (value) charstring dest_realm := "localdomain",
	   template (value) UINT32 hbh_id := '00000000'O,
	   template (value) UINT32 ete_id := '00000000'O) :=
	ts_DIAMETER(flags := '11000000'B,
		    cmd_code := Authentication_Information,
		    app_id := int2oct(c_DIAMETER_3GPP_S6_AID, 4),
		    hbh_id := hbh_id,
		    ete_id := ete_id,
		    avps := {
			ts_AVP_SessionId(sess_id),
			ts_AVP_DestinationRealm(dest_realm),
			ts_AVP_OriginHost(orig_host),
			ts_AVP_OriginRealm(orig_realm),
			ts_AVP_UserNameImsi(imsi),
			/* Requested EUTRAN Auth Info */
			ts_AVP_RequestedEutranAuthInfo,
			ts_AVP_AuthSessionState(NO_STATE_MAINTAINED),
			ts_AVP_3GPP_VisitedPlmnId('11111F'O)
	});
template (present) PDU_DIAMETER
tr_DIA_AIR(/* template (present) */ hexstring imsi,
	   template (present) octetstring sess_id := ?,
	   template (present) charstring dest_realm := ?,
	   template (present) UINT32 hbh_id := ?,
	   template (present) UINT32 ete_id := ?) :=
	tr_DIAMETER(flags := '1???????'B,
		    cmd_code := Authentication_Information,
		    app_id := int2oct(c_DIAMETER_3GPP_S6_AID, 4),
		    hbh_id := hbh_id, ete_id := ete_id,
		    avps := superset(
			tr_AVP_SessionId(sess_id),
			tr_AVP_DestinationRealm(dest_realm),
			tr_AVP_UserNameImsi(imsi),
			tr_AVP_3GPP_VisitedPlmnId
	));

/* TS 29.262 5.2.3.1 + 7.2.6 Authentication Information Answer */
template (value) PDU_DIAMETER
ts_DIA_AIA(template (value) AVP_list auth_info_contents,
	   template (value) octetstring sess_id := c_def_sess_id,
	   template (value) charstring orig_host := "hss.localdomain",
	   template (value) charstring orig_realm := "localdomain",
	   template (value) UINT32 hbh_id := '00000000'O,
	   template (value) UINT32 ete_id := '00000000'O) :=
	ts_DIAMETER(flags := '01000000'B,
		    cmd_code := Authentication_Information,
		    app_id := int2oct(c_DIAMETER_3GPP_S6_AID, 4),
		    hbh_id := hbh_id,
		    ete_id := ete_id,
		    avps := {
			ts_AVP_SessionId(sess_id),
			ts_AVP_ResultCode(DIAMETER_SUCCESS),
			ts_AVP_AuthSessionState(NO_STATE_MAINTAINED),
			ts_AVP_OriginHost(orig_host),
			ts_AVP_OriginRealm(orig_realm),
			ts_AVP_3GPP_AuthInfo(auth_info_contents)
	});
template (present) PDU_DIAMETER
tr_DIA_AIA(template (present) AVP_list auth_info_contents := ?,
	   template (present) octetstring sess_id := ?,
	   template (present) charstring orig_host := ?,
	   template (present) charstring orig_realm := ?,
	   template (present) UINT32 hbh_id := ?,
	   template (present) UINT32 ete_id := ?) :=
	tr_DIAMETER(flags := '0???????'B,
		    cmd_code := Authentication_Information,
		    app_id := int2oct(c_DIAMETER_3GPP_S6_AID, 4),
		    hbh_id := hbh_id,
		    ete_id := ete_id,
		    avps := superset(
			tr_AVP_SessionId(sess_id),
			tr_AVP_ResultCode(DIAMETER_SUCCESS),
			tr_AVP_AuthSessionState(NO_STATE_MAINTAINED),
			tr_AVP_3GPP_AuthInfo(auth_info_contents),
			tr_AVP_OriginHost(orig_host),
			tr_AVP_OriginRealm(orig_realm)
	));


/* TS 29.262 7.2.3 Update Location Request */
template (value) PDU_DIAMETER
ts_DIA_ULR(/* template (value) */ hexstring imsi,
	   template (value) octetstring sess_id := c_def_sess_id,
	   template (value) charstring orig_host := "ttcn3.localdomain",
	   template (value) charstring orig_realm := "localdomain",
	   template (value) charstring dest_realm := "localdomain",
	   template (value) UINT32 hbh_id := '00000000'O,
	   template (value) UINT32 ete_id := '00000000'O) :=
	ts_DIAMETER(flags := '11000000'B,
		    cmd_code := Update_Location,
		    app_id := int2oct(c_DIAMETER_3GPP_S6_AID, 4),
		    hbh_id := hbh_id,
		    ete_id := ete_id,
		    avps := {
			ts_AVP_SessionId(sess_id),
			ts_AVP_AuthSessionState(NO_STATE_MAINTAINED),
			ts_AVP_UserNameImsi(imsi),
			ts_AVP_3GPP_UlrFlags('00000000'O),
			ts_AVP_3GPP_VisitedPlmnId('11111F'O),
			ts_AVP_3GPP_RatType(EUTRAN),
			ts_AVP_OriginHost(orig_host),
			ts_AVP_OriginRealm(orig_realm),
			ts_AVP_DestinationRealm(dest_realm)
	});
template (present) PDU_DIAMETER
tr_DIA_ULR(/* template (present) */ hexstring imsi,
	   template (present) octetstring sess_id := ?,
	   template (present) charstring orig_host := ?,
	   template (present) charstring orig_realm := ?,
	   template (present) charstring dest_realm := ?,
	   template (present) UINT32 hbh_id := ?,
	   template (present) UINT32 ete_id := ?) :=
	tr_DIAMETER(flags := '11000000'B,
		    cmd_code := Update_Location,
		    app_id := int2oct(c_DIAMETER_3GPP_S6_AID, 4),
		    hbh_id := hbh_id,
		    ete_id := ete_id,
		    avps := superset(
			tr_AVP_SessionId(sess_id),
			tr_AVP_AuthSessionState,
			tr_AVP_OriginHost(orig_host),
			tr_AVP_OriginRealm(orig_realm),
			tr_AVP_DestinationRealm(dest_realm),
			tr_AVP_UserNameImsi(imsi),
			tr_AVP_3GPP_RatType(EUTRAN),
			tr_AVP_3GPP_UlrFlags,
			tr_AVP_3GPP_VisitedPlmnId
	));

template (value) PDU_DIAMETER
ts_DIA_ULA(template (value) AVP_list sub_data,
	   template (value) octetstring sess_id := c_def_sess_id,
	   template (value) charstring orig_host := "hss.localdomain",
	   template (value) charstring orig_realm := "localdomain",
	   template (value) UINT32 hbh_id := '00000000'O,
	   template (value) UINT32 ete_id := '00000000'O) :=
	ts_DIAMETER(flags:='01000000'B,
		    cmd_code := Update_Location,
		    app_id := int2oct(c_DIAMETER_3GPP_S6_AID, 4),
		    hbh_id := hbh_id,
		    ete_id := ete_id,
		    avps := {
			ts_AVP_SessionId(sess_id),
			ts_AVP_ResultCode(DIAMETER_SUCCESS), /* optional */
			ts_AVP_AuthSessionState(NO_STATE_MAINTAINED),
			ts_AVP_OriginHost(orig_host),
			ts_AVP_OriginRealm(orig_realm),
			ts_AVP_3GPP_UlaFlags('00000002'O),
			ts_AVP_3GPP_SubscriptionData(sub_data)
	});
template (present) PDU_DIAMETER
tr_DIA_ULA(template (present) AVP_list sub_data := ?,
	   template (present) octetstring sess_id := ?,
	   template (present) charstring orig_host := ?,
	   template (present) charstring orig_realm := ?,
	   template (present) UINT32 hbh_id := ?,
	   template (present) UINT32 ete_id := ?) :=
	tr_DIAMETER(flags := '0???????'B,
		    cmd_code := Update_Location,
		    app_id := int2oct(c_DIAMETER_3GPP_S6_AID, 4),
		    hbh_id := hbh_id,
		    ete_id := ete_id,
		    avps := superset(
			tr_AVP_SessionId(sess_id),
			tr_AVP_ResultCode(DIAMETER_SUCCESS),
			tr_AVP_AuthSessionState,
			tr_AVP_OriginHost(orig_host),
			tr_AVP_OriginRealm(orig_realm),
			tr_AVP_3GPP_UlaFlags,
			tr_AVP_3GPP_SubscriptionData(sub_data)
	));



/* RFC 4006 3.1.  Credit-Control-Request (CCR) Command */
template (present) PDU_DIAMETER
tr_DIA_CCR(template (present) DCC_NONE_CC_Request_Type req_type := INITIAL_REQUEST)
:= tr_DIAMETER(flags:='11000000'B, cmd_code:=Credit_Control,
			    app_id:=int2oct(c_DIAMETER_3GPP_Gx_AID, 4),
	avps := superset(
		tr_AVP_SessionId,
		tr_AVP_OriginHost,
		tr_AVP_OriginRealm,
		tr_AVP_DestinationRealm,
		tr_AVP_AuthAppId(int2oct(c_DIAMETER_3GPP_Gx_AID, 4)),
		tr_AVP_CcReqType(req_type),
		tr_AVP_CcReqNum(?)
	));


/* RFC 4006 3.2.  Credit-Control-Answer (CCA) Command */
template (value) PDU_DIAMETER
ts_DIA_CCA(template (value) UINT32 hbh_id, template (value) UINT32 ete_id,
	   template (value) octetstring sess_id,
	   template (value) DCC_NONE_CC_Request_Type req_type,
	   template (value) AVP_Unsigned32 req_num)

:= ts_DIAMETER(flags:='01000000'B, cmd_code:=Credit_Control,
		app_id:=int2oct(c_DIAMETER_3GPP_Gx_AID, 4), hbh_id:=hbh_id, ete_id:=ete_id,
	avps := {
		ts_AVP_SessionId(sess_id),
		ts_AVP_ResultCode(DIAMETER_SUCCESS),
		ts_AVP_OriginHost("pcrf.localdomain"),
		ts_AVP_OriginRealm("localdomain"),
		ts_AVP_AuthAppId(int2oct(c_DIAMETER_3GPP_Gx_AID, 4)),
		ts_AVP_CcReqType(req_type),
		ts_AVP_CcReqNum(req_num)//,
		// qos
		// default eps bearer qos
		// supported features
		// origin
	});

/* RFC 6733, section 5.5.1 "Device-Watchdog-Request" */
template (value) PDU_DIAMETER
ts_DIA_DWR(template (value) OCTET4 state_id := '00000000'O,
	   template (value) charstring orig_host := "ttcn3.localdomain",
	   template (value) charstring orig_realm := "localdomain",
	   template (value) UINT32 hbh_id := '00000000'O,
	   template (value) UINT32 ete_id := '00000000'O) :=
	ts_DIAMETER(flags := '10000000'B,
		    cmd_code := Device_Watchdog,
		    app_id := '00000000'O,
		    hbh_id := hbh_id,
		    ete_id := ete_id,
		    avps := {
			ts_AVP_OriginHost(orig_host),
			ts_AVP_OriginRealm(orig_realm),
			ts_AVP_OriginStateId(state_id)
	});
template (present) PDU_DIAMETER
tr_DIA_DWR(template (present) OCTET4 state_id := ?,
	   template (present) charstring orig_host := ?,
	   template (present) charstring orig_realm := ?,
	   template (present) UINT32 hbh_id := ?,
	   template (present) UINT32 ete_id := ?) :=
	tr_DIAMETER(flags := '1???????'B,
		    cmd_code := Device_Watchdog,
		    app_id := '00000000'O,
		    hbh_id := hbh_id,
		    ete_id := ete_id,
		    avps := superset(
			tr_AVP_OriginHost(orig_host),
			tr_AVP_OriginRealm(orig_realm),
			tr_AVP_OriginStateId(state_id)
	));

/* RFC 6733, section 5.5.2 "Device-Watchdog-Answer" */
template (value) PDU_DIAMETER
ts_DIA_DWA(template (value) OCTET4 state_id := '00000000'O,
	   template (value) charstring orig_host := "ttcn3.localdomain",
	   template (value) charstring orig_realm := "localdomain",
	   template (value) UINT32 hbh_id := '00000000'O,
	   template (value) UINT32 ete_id := '00000000'O) :=
	ts_DIAMETER(flags := '00000000'B,
		    cmd_code := Device_Watchdog,
		    app_id := '00000000'O,
		    hbh_id := hbh_id,
		    ete_id := ete_id,
		    avps := {
			ts_AVP_ResultCode(DIAMETER_SUCCESS),
			ts_AVP_OriginHost(orig_host),
			ts_AVP_OriginRealm(orig_realm),
			ts_AVP_OriginStateId(state_id)
	});
template (present) PDU_DIAMETER
tr_DIA_DWA(template (present) OCTET4 state_id := ?,
	   template (present) charstring orig_host := ?,
	   template (present) charstring orig_realm := ?,
	   template (present) UINT32 hbh_id := ?,
	   template (present) UINT32 ete_id := ?) :=
	tr_DIAMETER(flags := '0???????'B,
		    cmd_code := Device_Watchdog,
		    app_id := '00000000'O,
		    hbh_id := hbh_id,
		    ete_id := ete_id,
		    avps := superset(
			tr_AVP_ResultCode(DIAMETER_SUCCESS),
			tr_AVP_OriginHost(orig_host),
			tr_AVP_OriginRealm(orig_realm),
			tr_AVP_OriginStateId(state_id)
	));

}
