blob: af8f51406b6cd1afc2dac269563363f57a13d374 [file] [log] [blame]
Pau Espin Pedrol867b1302024-01-24 16:14:28 +01001module DIAMETER_ts32_299_Templates {
2
3/* (C) 2023 by sysmocom s.f.m.c. GmbH <info@sysmocom.de
4 * All rights reserved.
5 *
6 * Released under the terms of GNU General Public License, Version 2 or
7 * (at your option) any later version.
8 *
9 * SPDX-License-Identifier: GPL-2.0-or-later
10 *
11 * Templates for AVPs and messages for TS 32.299
12 */
13
14import from General_Types all;
15import from DIAMETER_Types all;
16import from DIAMETER_Templates all;
17import from Osmocom_Types all;
18import from Misc_Helpers all;
19
20/*******************************
21 * S6a 3GPP TS 32.299 section 7
22 *******************************/
23
24/* Gy AID : 3GPP TS 32.299 7.1.6, RFC4006 3.1: c_DIAMETER_CREDIT_CONTROL_AID */
25
26/* 3GPP TS 32.299 6.4.2 Credit-Control-Request */
27template (present) PDU_DIAMETER
28tr_DIA_Gy_CCR(template (present) DCC_NONE_CC_Request_Type req_type := INITIAL_REQUEST)
29:= tr_DIAMETER(flags:='11000000'B, cmd_code:=Credit_Control,
30 avps := superset(
31 tr_AVP_SessionId,
32 tr_AVP_OriginHost,
33 tr_AVP_OriginRealm,
34 tr_AVP_DestinationRealm,
35 tr_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)),
36 tr_AVP_CcReqType(req_type),
37 tr_AVP_CcReqNum(?)
38 ));
39
40/* 3GPP TS 32.299 6.4.3 Credit-Control-Answer message */
41template (value) PDU_DIAMETER
42ts_DIA_Gy_CCA(template (value) UINT32 hbh_id, template (value) UINT32 ete_id,
43 template (value) octetstring sess_id,
44 template (value) DCC_NONE_CC_Request_Type req_type,
45 template (value) AVP_Unsigned32 req_num)
46:= ts_DIAMETER(flags:='01000000'B, cmd_code:=Credit_Control,
47 app_id:=int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4), hbh_id:=hbh_id, ete_id:=ete_id,
48 avps := {
49 ts_AVP_SessionId(sess_id),
50 ts_AVP_ResultCode(DIAMETER_SUCCESS),
51 ts_AVP_OriginHost("ocs.localdomain"),
52 ts_AVP_OriginRealm("localdomain"),
53 ts_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)),
54 ts_AVP_CcReqType(req_type),
55 ts_AVP_CcReqNum(req_num)//,
56 // qos
57 // default eps bearer qos
58 // supported features
59 // origin
60 });
61/* Same as ts_DIA_Gy_CCA, but with extra AVP to grant access for limited amount of seconds */
62template (value) PDU_DIAMETER
63ts_DIA_Gy_CCA_ValidityTime(template (value) UINT32 hbh_id, template (value) UINT32 ete_id,
64 template (value) octetstring sess_id,
65 template (value) DCC_NONE_CC_Request_Type req_type,
66 template (value) AVP_Unsigned32 req_num,
67 uint32_t validity_time)
68:= ts_DIAMETER(flags:='01000000'B, cmd_code:=Credit_Control,
69 app_id:=int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4), hbh_id:=hbh_id, ete_id:=ete_id,
70 avps := {
71 ts_AVP_SessionId(sess_id),
72 ts_AVP_ResultCode(DIAMETER_SUCCESS),
73 ts_AVP_OriginHost("ocs.localdomain"),
74 ts_AVP_OriginRealm("localdomain"),
75 ts_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)),
76 ts_AVP_CcReqType(req_type),
77 ts_AVP_CcReqNum(req_num),
78 ts_AVP_Multiple_Services_Credit_Control({
79 ts_AVP_Validity_Time(validity_time),
80 ts_AVP_Granted_Service_Unit({
81 //ts_AVP_CC_Time(validity_time*2),
82 ts_AVP_CC_Total_Octets(1000)
83 })
84 })
85 //,
86 // qos
87 // default eps bearer qos
88 // supported features
89 // origin
90 });
91/* Same as ts_DIA_Gy_CCA_ValidityTime, but with extra AVP to grant access for limited amount of octets */
92template (value) PDU_DIAMETER
93ts_DIA_Gy_CCA_ValidityTimeVolumeThreshold(template (value) UINT32 hbh_id, template (value) UINT32 ete_id,
94 template (value) octetstring sess_id,
95 template (value) DCC_NONE_CC_Request_Type req_type,
96 template (value) AVP_Unsigned32 req_num,
97 uint32_t validity_time, uint32_t volume_threhsold)
98:= ts_DIAMETER(flags:='01000000'B, cmd_code:=Credit_Control,
99 app_id:=int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4), hbh_id:=hbh_id, ete_id:=ete_id,
100 avps := {
101 ts_AVP_SessionId(sess_id),
102 ts_AVP_ResultCode(DIAMETER_SUCCESS),
103 ts_AVP_OriginHost("ocs.localdomain"),
104 ts_AVP_OriginRealm("localdomain"),
105 ts_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)),
106 ts_AVP_CcReqType(req_type),
107 ts_AVP_CcReqNum(req_num),
108 ts_AVP_Multiple_Services_Credit_Control({
109 ts_AVP_Validity_Time(validity_time),
110 ts_AVP_Granted_Service_Unit({
111 ts_AVP_CC_Total_Octets(volume_threhsold*100)
112 }),
113 ts_AVP_3GPP_VolumeQuotaThreshold(volume_threhsold)
114 })
115 //,
116 // qos
117 // default eps bearer qos
118 // supported features
119 // origin
120 });
121
122function f_validate_gy_cc_report(PDU_DIAMETER rx_dia, template (present) DCA_3GPP_Reporting_Reason repreason_exp := ?,
123 template (present) integer cc_time_exp := ?,
124 template (present) integer cc_in_oct_exp := ?,
125 template (present) integer cc_out_oct_exp := ?)
126{
127 var AVP multi_services_cc, used_service_unit;
128 var AVP_Grouped multi_services_cc_data, used_service_unit_data;
129 var template (omit) AVP repreason_tpl;
130 var AVP repreason, cc_time, cc_in_oct, cc_out_oct;
131
132 multi_services_cc := f_DIAMETER_get_avp_or_fail(rx_dia, c_AVP_Code_DCC_NONE_Multiple_Services_Credit_Control);
133 multi_services_cc_data := valueof(multi_services_cc.avp_data.avp_DCC_NONE_Multiple_Services_Credit_Control);
134
135 used_service_unit := f_AVP_Grouped_get_avp_or_fail(multi_services_cc_data, c_AVP_Code_DCC_NONE_Used_Service_Unit);
136 used_service_unit_data := valueof(used_service_unit.avp_data.avp_DCC_NONE_Used_Service_Unit);
137
138 /* Reporting-Reason can be either inside Multiple-Services-Credit-Control or inside Used-Service-Unit */
139 repreason_tpl := f_AVP_Grouped_get_avp(multi_services_cc_data, c_AVP_Code_DCA_3GPP_Reporting_Reason);
140 if (istemplatekind(repreason_tpl, "omit")) {
141 repreason := f_AVP_Grouped_get_avp_or_fail(used_service_unit_data, c_AVP_Code_DCA_3GPP_Reporting_Reason);
142 } else {
143 repreason := valueof(repreason_tpl);
144 }
145 if (not match(repreason.avp_data.avp_DCA_3GPP_Reporting_Reason, repreason_exp)) {
146 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
147 log2str("3GPP-Reporting-Reason mismatch ", repreason, " vs exp ", repreason_exp));
148 }
149
150 cc_time := f_AVP_Grouped_get_avp_or_fail(used_service_unit_data, c_AVP_Code_DCC_NONE_CC_Time);
151 if (not match(oct2int(cc_time.avp_data.avp_DCC_NONE_CC_Time), cc_time_exp)) {
152 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
153 log2str("3GPP-CC-Time mismatch ", cc_time, " vs exp ", cc_time_exp));
154 }
155
156 cc_in_oct := f_AVP_Grouped_get_avp_or_fail(used_service_unit_data, c_AVP_Code_DCC_NONE_CC_Input_Octets);
157 if (not match(oct2int(cc_in_oct.avp_data.avp_DCC_NONE_CC_Input_Octets), cc_in_oct_exp)) {
158 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
159 log2str("3GPP-CC-Input-Octets mismatch ", cc_in_oct, " vs exp ", cc_in_oct_exp));
160 }
161
162 cc_out_oct := f_AVP_Grouped_get_avp_or_fail(used_service_unit_data, c_AVP_Code_DCC_NONE_CC_Output_Octets);
163 if (not match(oct2int(cc_out_oct.avp_data.avp_DCC_NONE_CC_Output_Octets), cc_out_oct_exp)) {
164 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
165 log2str("3GPP-CC-Output-Octets mismatch ", cc_out_oct, " vs exp ", cc_out_oct_exp));
166 }
167}
168
169} /* module */