pgw: Add support for PCRF emulation (CCR/CCA)

If mp_pcrf_local_ip is set to a non-empty string, the PGW testsuite
now emulates a PCRF and expects the PGW to perform the related
transactions - so far Credit-Control-Request INITIAL_REQUEST
at session creation, and TERMINATION_REQUST at session deletion.

Change-Id: I5f0c7a66d38e5c8b5f36b45717d49648a14ed7b2
diff --git a/library/DIAMETER_Templates.ttcn b/library/DIAMETER_Templates.ttcn
index 450e013..2cc2986 100644
--- a/library/DIAMETER_Templates.ttcn
+++ b/library/DIAMETER_Templates.ttcn
@@ -326,6 +326,51 @@
 		}
 	}
 }
+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 := {
@@ -879,4 +924,43 @@
 
 
 
+/* 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
+	});
+
 }