/src/open5gs/lib/app/ogs-config.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2019-2023 by Sukchan Lee <acetcom@gmail.com> |
3 | | * |
4 | | * This file is part of Open5GS. |
5 | | * |
6 | | * This program is free software: you can redistribute it and/or modify |
7 | | * it under the terms of the GNU Affero General Public License as published by |
8 | | * the Free Software Foundation, either version 3 of the License, or |
9 | | * (at your option) any later version. |
10 | | * |
11 | | * This program is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU General Public License |
17 | | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
18 | | */ |
19 | | |
20 | | #include "ogs-app.h" |
21 | | |
22 | | static ogs_app_global_conf_t global_conf; |
23 | | static ogs_app_local_conf_t local_conf; |
24 | | |
25 | | static OGS_POOL(policy_conf_pool, ogs_app_policy_conf_t); |
26 | | static OGS_POOL(slice_conf_pool, ogs_app_slice_conf_t); |
27 | | static OGS_POOL(session_conf_pool, ogs_app_session_conf_t); |
28 | | |
29 | | static int initialized = 0; |
30 | | |
31 | | int ogs_app_config_init(void) |
32 | 0 | { |
33 | 0 | ogs_assert(initialized == 0); |
34 | | |
35 | 0 | memset(&global_conf, 0, sizeof(ogs_app_global_conf_t)); |
36 | 0 | memset(&local_conf, 0, sizeof(ogs_app_local_conf_t)); |
37 | |
|
38 | 0 | ogs_pool_init(&policy_conf_pool, OGS_MAX_NUM_OF_PLMN); |
39 | 0 | ogs_pool_init(&slice_conf_pool, OGS_MAX_NUM_OF_SLICE); |
40 | 0 | ogs_pool_init(&session_conf_pool, |
41 | 0 | OGS_MAX_NUM_OF_SLICE*OGS_MAX_NUM_OF_SESS); |
42 | | |
43 | 0 | initialized = 1; |
44 | |
|
45 | 0 | return OGS_OK; |
46 | 0 | } |
47 | | |
48 | | void ogs_app_config_final(void) |
49 | 0 | { |
50 | 0 | ogs_assert(initialized == 1); |
51 | | |
52 | 0 | ogs_app_policy_conf_remove_all(); |
53 | |
|
54 | 0 | ogs_pool_final(&policy_conf_pool); |
55 | 0 | ogs_pool_final(&slice_conf_pool); |
56 | 0 | ogs_pool_final(&session_conf_pool); |
57 | | |
58 | 0 | initialized = 0; |
59 | 0 | } |
60 | | |
61 | | static void recalculate_pool_size(void) |
62 | 0 | { |
63 | 0 | ogs_app()->pool.packet = |
64 | 0 | global_conf.max.ue * OGS_MAX_NUM_OF_PACKET_BUFFER; |
65 | |
|
66 | 0 | #define MAX_NUM_OF_TUNNEL 3 /* Num of Tunnel per Bearer */ |
67 | 0 | ogs_app()->pool.sess = global_conf.max.ue * OGS_MAX_NUM_OF_SESS; |
68 | 0 | ogs_app()->pool.bearer = ogs_app()->pool.sess * OGS_MAX_NUM_OF_BEARER; |
69 | 0 | ogs_app()->pool.tunnel = ogs_app()->pool.bearer * MAX_NUM_OF_TUNNEL; |
70 | |
|
71 | 0 | #define POOL_NUM_PER_UE 16 |
72 | 0 | ogs_app()->pool.timer = global_conf.max.ue * POOL_NUM_PER_UE; |
73 | 0 | ogs_app()->pool.message = global_conf.max.ue * POOL_NUM_PER_UE; |
74 | 0 | ogs_app()->pool.event = global_conf.max.ue * POOL_NUM_PER_UE; |
75 | 0 | ogs_app()->pool.socket = global_conf.max.ue * POOL_NUM_PER_UE; |
76 | 0 | ogs_app()->pool.xact = global_conf.max.ue * POOL_NUM_PER_UE; |
77 | 0 | ogs_app()->pool.stream = global_conf.max.ue * POOL_NUM_PER_UE; |
78 | |
|
79 | 0 | ogs_app()->pool.nf = global_conf.max.peer; |
80 | 0 | #define NF_SERVICE_PER_NF_INSTANCE 16 |
81 | 0 | ogs_app()->pool.nf_service = |
82 | 0 | ogs_app()->pool.nf * NF_SERVICE_PER_NF_INSTANCE; |
83 | 0 | ogs_app()->pool.subscription = |
84 | 0 | ogs_app()->pool.nf * NF_SERVICE_PER_NF_INSTANCE; |
85 | |
|
86 | 0 | ogs_app()->pool.gtp_node = ogs_app()->pool.nf; |
87 | 0 | if (global_conf.max.gtp_peer) |
88 | 0 | ogs_app()->pool.gtp_node = global_conf.max.gtp_peer; |
89 | | |
90 | | /* Num of TAI-LAI Mapping Table */ |
91 | 0 | ogs_app()->pool.csmap = ogs_app()->pool.nf; |
92 | |
|
93 | 0 | #define MAX_NUM_OF_IMPU 8 |
94 | 0 | ogs_app()->pool.impi = global_conf.max.ue; |
95 | 0 | ogs_app()->pool.impu = ogs_app()->pool.impi * MAX_NUM_OF_IMPU; |
96 | 0 | } |
97 | | |
98 | | ogs_app_global_conf_t *ogs_global_conf(void) |
99 | 0 | { |
100 | 0 | return &global_conf; |
101 | 0 | } |
102 | | |
103 | | ogs_app_local_conf_t *ogs_local_conf(void) |
104 | 0 | { |
105 | 0 | return &local_conf; |
106 | 0 | } |
107 | | |
108 | | int ogs_app_global_conf_prepare(void) |
109 | 0 | { |
110 | 0 | global_conf.sockopt.no_delay = true; |
111 | |
|
112 | 0 | #define MAX_NUM_OF_UE 1024 /* Num of UEs */ |
113 | 0 | #define MAX_NUM_OF_PEER 64 /* Num of Peer */ |
114 | |
|
115 | 0 | global_conf.max.ue = MAX_NUM_OF_UE; |
116 | 0 | global_conf.max.peer = MAX_NUM_OF_PEER; |
117 | |
|
118 | 0 | ogs_pkbuf_default_init(&global_conf.pkbuf_config); |
119 | |
|
120 | 0 | recalculate_pool_size(); |
121 | |
|
122 | 0 | return OGS_OK; |
123 | 0 | } |
124 | | |
125 | | static int global_conf_validation(void) |
126 | 0 | { |
127 | 0 | if (global_conf.parameter.no_ipv4 == 1 && |
128 | 0 | global_conf.parameter.no_ipv6 == 1) { |
129 | 0 | ogs_error("Both `no_ipv4` and `no_ipv6` set to `true` in `%s`", |
130 | 0 | ogs_app()->file); |
131 | 0 | return OGS_ERROR; |
132 | 0 | } |
133 | | |
134 | 0 | return OGS_OK; |
135 | 0 | } |
136 | | |
137 | | int ogs_app_count_nf_conf_sections(const char *conf_section) |
138 | 0 | { |
139 | 0 | if (!strcmp(conf_section, "amf")) |
140 | 0 | global_conf.parameter.amf_count++; |
141 | 0 | else if (!strcmp(conf_section, "smf")) |
142 | 0 | global_conf.parameter.smf_count++; |
143 | 0 | else if (!strcmp(conf_section, "upf")) |
144 | 0 | global_conf.parameter.upf_count++; |
145 | 0 | else if (!strcmp(conf_section, "ausf")) |
146 | 0 | global_conf.parameter.ausf_count++; |
147 | 0 | else if (!strcmp(conf_section, "udm")) |
148 | 0 | global_conf.parameter.udm_count++; |
149 | 0 | else if (!strcmp(conf_section, "pcf")) |
150 | 0 | global_conf.parameter.pcf_count++; |
151 | 0 | else if (!strcmp(conf_section, "nssf")) |
152 | 0 | global_conf.parameter.nssf_count++; |
153 | 0 | else if (!strcmp(conf_section, "bsf")) |
154 | 0 | global_conf.parameter.bsf_count++; |
155 | 0 | else if (!strcmp(conf_section, "udr")) |
156 | 0 | global_conf.parameter.udr_count++; |
157 | |
|
158 | 0 | return OGS_OK; |
159 | 0 | } |
160 | | |
161 | | int ogs_app_parse_global_conf(ogs_yaml_iter_t *parent) |
162 | 0 | { |
163 | 0 | int rv; |
164 | 0 | ogs_yaml_iter_t global_iter; |
165 | |
|
166 | 0 | ogs_assert(parent); |
167 | | |
168 | 0 | ogs_yaml_iter_recurse(parent, &global_iter); |
169 | 0 | while (ogs_yaml_iter_next(&global_iter)) { |
170 | 0 | const char *global_key = ogs_yaml_iter_key(&global_iter); |
171 | 0 | ogs_assert(global_key); |
172 | 0 | if (!strcmp(global_key, "parameter")) { |
173 | 0 | ogs_yaml_iter_t parameter_iter; |
174 | 0 | ogs_yaml_iter_recurse(&global_iter, ¶meter_iter); |
175 | 0 | while (ogs_yaml_iter_next(¶meter_iter)) { |
176 | 0 | const char *parameter_key = ogs_yaml_iter_key(¶meter_iter); |
177 | 0 | ogs_assert(parameter_key); |
178 | 0 | if (!strcmp(parameter_key, "no_hss")) { |
179 | 0 | global_conf.parameter.no_hss = |
180 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
181 | 0 | } else if (!strcmp(parameter_key, "no_mme")) { |
182 | 0 | global_conf.parameter.no_mme = |
183 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
184 | 0 | } else if (!strcmp(parameter_key, "no_sgwu")) { |
185 | 0 | global_conf.parameter.no_sgwu = |
186 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
187 | 0 | } else if (!strcmp(parameter_key, "no_sgwc")) { |
188 | 0 | global_conf.parameter.no_sgwc = |
189 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
190 | 0 | } else if (!strcmp(parameter_key, "no_sgw")) { |
191 | 0 | global_conf.parameter.no_sgw = |
192 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
193 | 0 | } else if (!strcmp(parameter_key, "no_pgw")) { |
194 | 0 | global_conf.parameter.no_pgw = |
195 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
196 | 0 | } else if (!strcmp(parameter_key, "no_pcrf")) { |
197 | 0 | global_conf.parameter.no_pcrf = |
198 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
199 | 0 | } else if (!strcmp(parameter_key, "no_nrf")) { |
200 | 0 | global_conf.parameter.no_nrf = |
201 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
202 | 0 | } else if (!strcmp(parameter_key, "no_scp")) { |
203 | 0 | global_conf.parameter.no_scp = |
204 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
205 | 0 | } else if (!strcmp(parameter_key, "no_sepp")) { |
206 | 0 | global_conf.parameter.no_sepp = |
207 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
208 | 0 | } else if (!strcmp(parameter_key, "no_amf")) { |
209 | 0 | global_conf.parameter.no_amf = |
210 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
211 | 0 | } else if (!strcmp(parameter_key, "no_smf")) { |
212 | 0 | global_conf.parameter.no_smf = |
213 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
214 | 0 | } else if (!strcmp(parameter_key, "no_upf")) { |
215 | 0 | global_conf.parameter.no_upf = |
216 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
217 | 0 | } else if (!strcmp(parameter_key, "no_ausf")) { |
218 | 0 | global_conf.parameter.no_ausf = |
219 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
220 | 0 | } else if (!strcmp(parameter_key, "no_udm")) { |
221 | 0 | global_conf.parameter.no_udm = |
222 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
223 | 0 | } else if (!strcmp(parameter_key, "no_pcf")) { |
224 | 0 | global_conf.parameter.no_pcf = |
225 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
226 | 0 | } else if (!strcmp(parameter_key, "no_nssf")) { |
227 | 0 | global_conf.parameter.no_nssf = |
228 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
229 | 0 | } else if (!strcmp(parameter_key, "no_bsf")) { |
230 | 0 | global_conf.parameter.no_bsf = |
231 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
232 | 0 | } else if (!strcmp(parameter_key, "no_udr")) { |
233 | 0 | global_conf.parameter.no_udr = |
234 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
235 | 0 | } else if (!strcmp(parameter_key, "no_ipv4")) { |
236 | 0 | global_conf.parameter.no_ipv4 = |
237 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
238 | 0 | } else if (!strcmp(parameter_key, "no_ipv6")) { |
239 | 0 | global_conf.parameter.no_ipv6 = |
240 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
241 | 0 | } else if (!strcmp(parameter_key, "prefer_ipv4")) { |
242 | 0 | global_conf.parameter.prefer_ipv4 = |
243 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
244 | 0 | } else if (!strcmp(parameter_key, "multicast")) { |
245 | 0 | global_conf.parameter.multicast = |
246 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
247 | 0 | } else if (!strcmp(parameter_key, "use_openair")) { |
248 | 0 | global_conf.parameter.use_openair = |
249 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
250 | 0 | } else if (!strcmp(parameter_key, "use_upg_vpp")) { |
251 | 0 | global_conf.parameter.use_upg_vpp = |
252 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
253 | 0 | } else if (!strcmp(parameter_key, "fake_csfb")) { |
254 | 0 | global_conf.parameter.fake_csfb = |
255 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
256 | 0 | } else if (!strcmp(parameter_key, |
257 | 0 | "no_ipv4v6_local_addr_in_packet_filter")) { |
258 | 0 | global_conf.parameter. |
259 | 0 | no_ipv4v6_local_addr_in_packet_filter = |
260 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
261 | 0 | } else if (!strcmp(parameter_key, |
262 | 0 | "no_pfcp_rr_select")) { |
263 | 0 | global_conf.parameter.no_pfcp_rr_select = |
264 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
265 | 0 | } else if (!strcmp(parameter_key, |
266 | 0 | "no_time_zone_information")) { |
267 | 0 | global_conf.parameter.no_time_zone_information = |
268 | 0 | ogs_yaml_iter_bool(¶meter_iter); |
269 | 0 | } else |
270 | 0 | ogs_warn("unknown key `%s`", parameter_key); |
271 | 0 | } |
272 | 0 | } else if (!strcmp(global_key, "sockopt")) { |
273 | 0 | ogs_yaml_iter_t sockopt_iter; |
274 | 0 | ogs_yaml_iter_recurse(&global_iter, &sockopt_iter); |
275 | 0 | while (ogs_yaml_iter_next(&sockopt_iter)) { |
276 | 0 | const char *sockopt_key = |
277 | 0 | ogs_yaml_iter_key(&sockopt_iter); |
278 | 0 | ogs_assert(sockopt_key); |
279 | 0 | if (!strcmp(sockopt_key, "no_delay")) { |
280 | 0 | global_conf.sockopt.no_delay = |
281 | 0 | ogs_yaml_iter_bool(&sockopt_iter); |
282 | 0 | } else if (!strcmp(sockopt_key, "linger")) { |
283 | 0 | const char *v = ogs_yaml_iter_value(&sockopt_iter); |
284 | 0 | if (v) |
285 | 0 | global_conf.sockopt.l_linger = atoi(v); |
286 | 0 | global_conf.sockopt.l_onoff = true; |
287 | 0 | } else |
288 | 0 | ogs_warn("unknown key `%s`", sockopt_key); |
289 | 0 | } |
290 | 0 | } else if (!strcmp(global_key, "max")) { |
291 | 0 | ogs_yaml_iter_t max_iter; |
292 | 0 | ogs_yaml_iter_recurse(&global_iter, &max_iter); |
293 | 0 | while (ogs_yaml_iter_next(&max_iter)) { |
294 | 0 | const char *max_key = ogs_yaml_iter_key(&max_iter); |
295 | 0 | ogs_assert(max_key); |
296 | 0 | if (!strcmp(max_key, "ue")) { |
297 | 0 | const char *v = ogs_yaml_iter_value(&max_iter); |
298 | 0 | if (v) global_conf.max.ue = atoi(v); |
299 | 0 | } else if (!strcmp(max_key, "peer") || |
300 | 0 | !strcmp(max_key, "enb")) { |
301 | 0 | const char *v = ogs_yaml_iter_value(&max_iter); |
302 | 0 | if (v) global_conf.max.peer = atoi(v); |
303 | 0 | } else if (!strcmp(max_key, "gtp_peer") || |
304 | 0 | !strcmp(max_key, "enb")) { |
305 | 0 | const char *v = ogs_yaml_iter_value(&max_iter); |
306 | 0 | if (v) global_conf.max.gtp_peer = atoi(v); |
307 | 0 | } else |
308 | 0 | ogs_warn("unknown key `%s`", max_key); |
309 | 0 | } |
310 | | |
311 | 0 | recalculate_pool_size(); |
312 | |
|
313 | 0 | } else if (!strcmp(global_key, "pool")) { |
314 | 0 | ogs_yaml_iter_t pool_iter; |
315 | 0 | ogs_yaml_iter_recurse(&global_iter, &pool_iter); |
316 | 0 | while (ogs_yaml_iter_next(&pool_iter)) { |
317 | 0 | const char *pool_key = ogs_yaml_iter_key(&pool_iter); |
318 | 0 | ogs_assert(pool_key); |
319 | 0 | if (!strcmp(pool_key, "128")) { |
320 | 0 | const char *v = ogs_yaml_iter_value(&pool_iter); |
321 | 0 | if (v) global_conf.pkbuf_config.cluster_128_pool = atoi(v); |
322 | 0 | } else if (!strcmp(pool_key, "256")) { |
323 | 0 | const char *v = ogs_yaml_iter_value(&pool_iter); |
324 | 0 | if (v) global_conf.pkbuf_config.cluster_256_pool = atoi(v); |
325 | 0 | } else if (!strcmp(pool_key, "512")) { |
326 | 0 | const char *v = ogs_yaml_iter_value(&pool_iter); |
327 | 0 | if (v) global_conf.pkbuf_config.cluster_512_pool = atoi(v); |
328 | 0 | } else if (!strcmp(pool_key, "1024")) { |
329 | 0 | const char *v = ogs_yaml_iter_value(&pool_iter); |
330 | 0 | if (v) global_conf.pkbuf_config.cluster_1024_pool = atoi(v); |
331 | 0 | } else if (!strcmp(pool_key, "2048")) { |
332 | 0 | const char *v = ogs_yaml_iter_value(&pool_iter); |
333 | 0 | if (v) global_conf.pkbuf_config.cluster_2048_pool = atoi(v); |
334 | 0 | } else if (!strcmp(pool_key, "8192")) { |
335 | 0 | const char *v = ogs_yaml_iter_value(&pool_iter); |
336 | 0 | if (v) global_conf.pkbuf_config.cluster_8192_pool = atoi(v); |
337 | 0 | } else if (!strcmp(pool_key, "32768")) { |
338 | 0 | const char *v = ogs_yaml_iter_value(&pool_iter); |
339 | 0 | if (v) global_conf.pkbuf_config.cluster_32768_pool = |
340 | 0 | atoi(v); |
341 | 0 | } else if (!strcmp(pool_key, "big")) { |
342 | 0 | const char *v = ogs_yaml_iter_value(&pool_iter); |
343 | 0 | if (v) global_conf.pkbuf_config.cluster_big_pool = atoi(v); |
344 | 0 | } else |
345 | 0 | ogs_warn("unknown key `%s`", pool_key); |
346 | 0 | } |
347 | 0 | } |
348 | 0 | } |
349 | | |
350 | 0 | rv = global_conf_validation(); |
351 | 0 | if (rv != OGS_OK) return rv; |
352 | | |
353 | 0 | return OGS_OK; |
354 | 0 | } |
355 | | |
356 | | static void regenerate_all_timer_duration(void) |
357 | 0 | { |
358 | 0 | ogs_assert(local_conf.time.message.duration); |
359 | | |
360 | 0 | local_conf.time.message.sbi.client_wait_duration = |
361 | 0 | local_conf.time.message.duration; |
362 | 0 | local_conf.time.message.sbi.connection_deadline = |
363 | 0 | local_conf.time.message.sbi.client_wait_duration + ogs_time_from_sec(1); |
364 | 0 | local_conf.time.message.sbi.reconnect_interval = |
365 | 0 | ogs_max(ogs_time_from_sec(3), |
366 | 0 | local_conf.time.message.sbi.client_wait_duration + |
367 | 0 | ogs_time_from_sec(1)); |
368 | 0 | local_conf.time.message.sbi.reconnect_interval_in_exception = |
369 | 0 | ogs_time_from_sec(2); |
370 | |
|
371 | 0 | #define PFCP_N1_RESPONSE_RETRY_COUNT 3 |
372 | 0 | local_conf.time.message.pfcp.n1_response_rcount = |
373 | 0 | PFCP_N1_RESPONSE_RETRY_COUNT; |
374 | 0 | local_conf.time.message.pfcp.t1_response_duration = |
375 | 0 | (local_conf.time.message.duration / |
376 | 0 | (local_conf.time.message.pfcp.n1_response_rcount + 1)); |
377 | 0 | ogs_assert(local_conf.time.message.pfcp.t1_response_duration); |
378 | | |
379 | 0 | #define PFCP_N1_HOLDING_RETRY_COUNT 1 |
380 | 0 | local_conf.time.message.pfcp.n1_holding_rcount = |
381 | 0 | PFCP_N1_HOLDING_RETRY_COUNT; |
382 | 0 | local_conf.time.message.pfcp.t1_holding_duration = |
383 | 0 | local_conf.time.message.pfcp.n1_response_rcount * |
384 | 0 | local_conf.time.message.pfcp.t1_response_duration; |
385 | 0 | ogs_assert(local_conf.time.message.pfcp.t1_holding_duration); |
386 | | |
387 | 0 | local_conf.time.message.pfcp.association_interval = |
388 | 0 | ogs_max(ogs_time_from_sec(3), |
389 | 0 | local_conf.time.message.sbi.client_wait_duration + |
390 | 0 | ogs_time_from_sec(1)); |
391 | |
|
392 | 0 | local_conf.time.message.pfcp.no_heartbeat_duration = |
393 | 0 | ogs_max(ogs_time_from_sec(10), |
394 | 0 | local_conf.time.message.sbi.client_wait_duration + |
395 | 0 | ogs_time_from_sec(1)); |
396 | |
|
397 | 0 | #define GTP_N3_RESPONSE_RETRY_COUNT 3 |
398 | 0 | local_conf.time.message.gtp.n3_response_rcount = |
399 | 0 | GTP_N3_RESPONSE_RETRY_COUNT; |
400 | 0 | local_conf.time.message.gtp.t3_response_duration = |
401 | 0 | (local_conf.time.message.duration / |
402 | 0 | (local_conf.time.message.gtp.n3_response_rcount + 1)); |
403 | 0 | ogs_assert(local_conf.time.message.gtp.t3_response_duration); |
404 | | |
405 | 0 | #define GTP_N3_HOLDING_RETRY_COUNT 1 |
406 | 0 | local_conf.time.message.gtp.n3_holding_rcount = GTP_N3_HOLDING_RETRY_COUNT; |
407 | 0 | local_conf.time.message.gtp.t3_holding_duration = |
408 | 0 | local_conf.time.message.gtp.n3_response_rcount * |
409 | 0 | local_conf.time.message.gtp.t3_response_duration; |
410 | 0 | ogs_assert(local_conf.time.message.gtp.t3_holding_duration); |
411 | |
|
412 | | #if 0 |
413 | | ogs_trace("%lld, %lld, %lld, %d, %lld, %d %lld, %d, %lld, %d, %lld", |
414 | | (long long)local_conf.time.message.duration, |
415 | | (long long)local_conf.time.message.sbi.client_wait_duration, |
416 | | (long long)local_conf.time.message.sbi.connection_deadline, |
417 | | local_conf.time.message.pfcp.n1_response_rcount, |
418 | | (long long)local_conf.time.message.pfcp.t1_response_duration, |
419 | | local_conf.time.message.pfcp.n1_holding_rcount, |
420 | | (long long)local_conf.time.message.pfcp.t1_holding_duration, |
421 | | local_conf.time.message.gtp.n3_response_rcount, |
422 | | (long long)local_conf.time.message.gtp.t3_response_duration, |
423 | | local_conf.time.message.gtp.n3_holding_rcount, |
424 | | (long long)local_conf.time.message.gtp.t3_holding_duration); |
425 | | ogs_trace("%lld, %lld, %lld", |
426 | | (long long)local_conf.time.message.sbi.reconnect_interval, |
427 | | (long long)local_conf.time.message.pfcp.association_interval, |
428 | | (long long)local_conf.time.message.pfcp.no_heartbeat_duration); |
429 | | #endif |
430 | 0 | } |
431 | | |
432 | | static int local_conf_prepare(void) |
433 | 0 | { |
434 | | /* <Heartbeat Checking Interval> |
435 | | * Heartbeat Interval(e.g: 10 seconds) + No Heartbeat Margin(1 second) */ |
436 | 0 | local_conf.time.nf_instance.no_heartbeat_margin = 1; |
437 | | |
438 | | /* 30 seconds */ |
439 | 0 | local_conf.time.nf_instance.validity_duration = 30; |
440 | | |
441 | | /* 86400 seconds = 1 day */ |
442 | 0 | local_conf.time.subscription.validity_duration = 86400; |
443 | | |
444 | | /* |
445 | | * Message Wait Duration : 10 seconds (Default) |
446 | | * |
447 | | * The paging retry timer is 2 seconds and the retry count is 3. |
448 | | * |
449 | | * It is recomended to set at least 9 seconds to reflect |
450 | | * the paging failure result to GTPv2-C or HTTP2(SBI). |
451 | | */ |
452 | 0 | local_conf.time.message.duration = ogs_time_from_sec(10); |
453 | | |
454 | | /* |
455 | | * Handover Wait Duration : 300 ms (Default) |
456 | | * |
457 | | * Time to wait for AMF/MME to send UEContextReleaseCommand |
458 | | * to the source gNB/eNB after receiving HandoverNotify |
459 | | */ |
460 | 0 | local_conf.time.handover.duration = ogs_time_from_msec(300); |
461 | | |
462 | | /* Size of internal metrics pool (amount of ogs_metrics_spec_t) */ |
463 | 0 | ogs_app()->metrics.max_specs = 512; |
464 | |
|
465 | 0 | regenerate_all_timer_duration(); |
466 | |
|
467 | 0 | return OGS_OK; |
468 | 0 | } |
469 | | |
470 | | static int local_conf_validation(void) |
471 | 0 | { |
472 | 0 | if (local_conf.time.nf_instance.validity_duration == 0) { |
473 | 0 | ogs_error("NF Instance validity-time should not 0"); |
474 | 0 | ogs_error("time:"); |
475 | 0 | ogs_error(" nf_instance:"); |
476 | 0 | ogs_error(" validity: 0"); |
477 | |
|
478 | 0 | return OGS_ERROR; |
479 | 0 | } |
480 | | |
481 | 0 | return OGS_OK; |
482 | 0 | } |
483 | | |
484 | | int ogs_app_parse_local_conf(const char *local) |
485 | 0 | { |
486 | 0 | int rv; |
487 | 0 | yaml_document_t *document = NULL; |
488 | 0 | ogs_yaml_iter_t root_iter; |
489 | 0 | int idx = 0; |
490 | |
|
491 | 0 | document = ogs_app()->document; |
492 | 0 | ogs_assert(document); |
493 | | |
494 | 0 | rv = local_conf_prepare(); |
495 | 0 | if (rv != OGS_OK) return rv; |
496 | | |
497 | 0 | ogs_yaml_iter_init(&root_iter, document); |
498 | 0 | while (ogs_yaml_iter_next(&root_iter)) { |
499 | 0 | const char *root_key = ogs_yaml_iter_key(&root_iter); |
500 | 0 | ogs_assert(root_key); |
501 | 0 | if (!strcmp(root_key, local) && |
502 | 0 | (idx++ == ogs_app()->config_section_id)) { |
503 | 0 | ogs_yaml_iter_t local_iter; |
504 | 0 | ogs_yaml_iter_recurse(&root_iter, &local_iter); |
505 | 0 | while (ogs_yaml_iter_next(&local_iter)) { |
506 | 0 | const char *local_key = ogs_yaml_iter_key(&local_iter); |
507 | 0 | ogs_assert(local_key); |
508 | 0 | if (!strcmp(local_key, "serving")) { |
509 | 0 | ogs_yaml_iter_t serving_array, serving_iter; |
510 | 0 | ogs_yaml_iter_recurse(&local_iter, &serving_array); |
511 | 0 | do { |
512 | 0 | const char *mnc = NULL, *mcc = NULL; |
513 | 0 | ogs_assert(local_conf.num_of_serving_plmn_id < |
514 | 0 | OGS_MAX_NUM_OF_PLMN); |
515 | | |
516 | 0 | OGS_YAML_ARRAY_NEXT(&serving_array, &serving_iter); |
517 | 0 | while (ogs_yaml_iter_next(&serving_iter)) { |
518 | 0 | const char *serving_key = |
519 | 0 | ogs_yaml_iter_key(&serving_iter); |
520 | 0 | ogs_assert(serving_key); |
521 | 0 | if (!strcmp(serving_key, "plmn_id")) { |
522 | 0 | ogs_yaml_iter_t plmn_id_iter; |
523 | |
|
524 | 0 | ogs_yaml_iter_recurse(&serving_iter, |
525 | 0 | &plmn_id_iter); |
526 | 0 | while (ogs_yaml_iter_next(&plmn_id_iter)) { |
527 | 0 | const char *id_key = |
528 | 0 | ogs_yaml_iter_key(&plmn_id_iter); |
529 | 0 | ogs_assert(id_key); |
530 | 0 | if (!strcmp(id_key, "mcc")) { |
531 | 0 | mcc = ogs_yaml_iter_value( |
532 | 0 | &plmn_id_iter); |
533 | 0 | } else if (!strcmp(id_key, "mnc")) { |
534 | 0 | mnc = ogs_yaml_iter_value( |
535 | 0 | &plmn_id_iter); |
536 | 0 | } |
537 | 0 | } |
538 | | |
539 | 0 | if (mcc && mnc) { |
540 | 0 | ogs_plmn_id_build( |
541 | 0 | &local_conf.serving_plmn_id[ |
542 | 0 | local_conf. |
543 | 0 | num_of_serving_plmn_id], |
544 | 0 | atoi(mcc), atoi(mnc), strlen(mnc)); |
545 | 0 | local_conf.num_of_serving_plmn_id++; |
546 | 0 | } else { |
547 | 0 | ogs_error("Invalid [MCC:%s, MNC:%s]", |
548 | 0 | mcc, mnc); |
549 | 0 | } |
550 | 0 | } else |
551 | 0 | ogs_warn("unknown key `%s`", serving_key); |
552 | 0 | } |
553 | 0 | } while (ogs_yaml_iter_type(&serving_array) == |
554 | 0 | YAML_SEQUENCE_NODE); |
555 | 0 | } else if (!strcmp(local_key, "time")) { |
556 | 0 | ogs_yaml_iter_t time_iter; |
557 | 0 | ogs_yaml_iter_recurse(&local_iter, &time_iter); |
558 | 0 | while (ogs_yaml_iter_next(&time_iter)) { |
559 | 0 | const char *time_key = ogs_yaml_iter_key(&time_iter); |
560 | 0 | ogs_assert(time_key); |
561 | 0 | if (!strcmp(time_key, "nf_instance")) { |
562 | 0 | ogs_yaml_iter_t sbi_iter; |
563 | 0 | ogs_yaml_iter_recurse(&time_iter, &sbi_iter); |
564 | |
|
565 | 0 | while (ogs_yaml_iter_next(&sbi_iter)) { |
566 | 0 | const char *sbi_key = |
567 | 0 | ogs_yaml_iter_key(&sbi_iter); |
568 | 0 | ogs_assert(sbi_key); |
569 | | |
570 | 0 | if (!strcmp(sbi_key, "heartbeat")) { |
571 | 0 | const char *v = ogs_yaml_iter_value( |
572 | 0 | &sbi_iter); |
573 | 0 | if (v) |
574 | 0 | local_conf.time.nf_instance. |
575 | 0 | heartbeat_interval = atoi(v); |
576 | 0 | } else if (!strcmp(sbi_key, "validity")) { |
577 | 0 | const char *v = |
578 | 0 | ogs_yaml_iter_value(&sbi_iter); |
579 | 0 | if (v) |
580 | 0 | local_conf.time.nf_instance. |
581 | 0 | validity_duration = atoi(v); |
582 | 0 | } else |
583 | 0 | ogs_warn("unknown key `%s`", sbi_key); |
584 | 0 | } |
585 | 0 | } else if (!strcmp(time_key, "subscription")) { |
586 | 0 | ogs_yaml_iter_t sbi_iter; |
587 | 0 | ogs_yaml_iter_recurse(&time_iter, &sbi_iter); |
588 | |
|
589 | 0 | while (ogs_yaml_iter_next(&sbi_iter)) { |
590 | 0 | const char *sbi_key = |
591 | 0 | ogs_yaml_iter_key(&sbi_iter); |
592 | 0 | ogs_assert(sbi_key); |
593 | | |
594 | 0 | if (!strcmp(sbi_key, "validity")) { |
595 | 0 | const char *v = |
596 | 0 | ogs_yaml_iter_value(&sbi_iter); |
597 | 0 | if (v) |
598 | 0 | local_conf.time.subscription. |
599 | 0 | validity_duration = atoi(v); |
600 | 0 | } else |
601 | 0 | ogs_warn("unknown key `%s`", sbi_key); |
602 | 0 | } |
603 | 0 | } else if (!strcmp(time_key, "message")) { |
604 | 0 | ogs_yaml_iter_t msg_iter; |
605 | 0 | ogs_yaml_iter_recurse(&time_iter, &msg_iter); |
606 | |
|
607 | 0 | while (ogs_yaml_iter_next(&msg_iter)) { |
608 | 0 | const char *msg_key = |
609 | 0 | ogs_yaml_iter_key(&msg_iter); |
610 | 0 | ogs_assert(msg_key); |
611 | | |
612 | 0 | if (!strcmp(msg_key, "duration")) { |
613 | 0 | const char *v = |
614 | 0 | ogs_yaml_iter_value(&msg_iter); |
615 | 0 | if (v) { |
616 | 0 | local_conf.time.message.duration = |
617 | 0 | ogs_time_from_msec(atoll(v)); |
618 | 0 | regenerate_all_timer_duration(); |
619 | 0 | } |
620 | 0 | } else |
621 | 0 | ogs_warn("unknown key `%s`", msg_key); |
622 | 0 | } |
623 | 0 | } else if (!strcmp(time_key, "handover")) { |
624 | 0 | ogs_yaml_iter_t msg_iter; |
625 | 0 | ogs_yaml_iter_recurse(&time_iter, &msg_iter); |
626 | |
|
627 | 0 | while (ogs_yaml_iter_next(&msg_iter)) { |
628 | 0 | const char *msg_key = |
629 | 0 | ogs_yaml_iter_key(&msg_iter); |
630 | 0 | ogs_assert(msg_key); |
631 | | |
632 | 0 | if (!strcmp(msg_key, "duration")) { |
633 | 0 | const char *v = |
634 | 0 | ogs_yaml_iter_value(&msg_iter); |
635 | 0 | if (v) { |
636 | 0 | local_conf.time.handover.duration = |
637 | 0 | ogs_time_from_msec(atoll(v)); |
638 | 0 | } |
639 | 0 | } else |
640 | 0 | ogs_warn("unknown key `%s`", msg_key); |
641 | 0 | } |
642 | 0 | } else if (!strcmp(time_key, "t3502")) { |
643 | | /* handle config in amf */ |
644 | 0 | } else if (!strcmp(time_key, "t3512")) { |
645 | | /* handle config in amf */ |
646 | 0 | } else if (!strcmp(time_key, "t3402")) { |
647 | | /* handle config in mme */ |
648 | 0 | } else if (!strcmp(time_key, "t3412")) { |
649 | | /* handle config in mme */ |
650 | 0 | } else if (!strcmp(time_key, "t3423")) { |
651 | | /* handle config in mme */ |
652 | 0 | } else |
653 | 0 | ogs_warn("unknown key `%s`", time_key); |
654 | 0 | } |
655 | 0 | } |
656 | 0 | } |
657 | 0 | } |
658 | 0 | } |
659 | | |
660 | 0 | rv = local_conf_validation(); |
661 | 0 | if (rv != OGS_OK) return rv; |
662 | | |
663 | 0 | return OGS_OK; |
664 | 0 | } |
665 | | |
666 | | int ogs_app_parse_sockopt_config( |
667 | | ogs_yaml_iter_t *parent, ogs_sockopt_t *option) |
668 | 0 | { |
669 | 0 | ogs_yaml_iter_t sockopt_iter; |
670 | |
|
671 | 0 | ogs_assert(parent); |
672 | 0 | ogs_assert(option); |
673 | | |
674 | 0 | ogs_sockopt_init(option); |
675 | |
|
676 | 0 | ogs_yaml_iter_recurse(parent, &sockopt_iter); |
677 | 0 | while (ogs_yaml_iter_next(&sockopt_iter)) { |
678 | 0 | const char *sockopt_key = ogs_yaml_iter_key(&sockopt_iter); |
679 | 0 | ogs_assert(sockopt_key); |
680 | | |
681 | 0 | if (!strcmp(sockopt_key, "sctp")) { |
682 | 0 | ogs_yaml_iter_t sctp_iter; |
683 | 0 | ogs_yaml_iter_recurse(&sockopt_iter, &sctp_iter); |
684 | |
|
685 | 0 | while (ogs_yaml_iter_next(&sctp_iter)) { |
686 | 0 | const char *sctp_key = ogs_yaml_iter_key(&sctp_iter); |
687 | 0 | ogs_assert(sctp_key); |
688 | 0 | if (!strcmp(sctp_key, "spp_hbinterval")) { |
689 | 0 | const char *v = ogs_yaml_iter_value(&sctp_iter); |
690 | 0 | if (v) option->sctp.spp_hbinterval = atoi(v); |
691 | 0 | } else if (!strcmp(sctp_key, "spp_sackdelay")) { |
692 | 0 | const char *v = ogs_yaml_iter_value(&sctp_iter); |
693 | 0 | if (v) option->sctp.spp_sackdelay = atoi(v); |
694 | 0 | } else if (!strcmp(sctp_key, "srto_initial")) { |
695 | 0 | const char *v = ogs_yaml_iter_value(&sctp_iter); |
696 | 0 | if (v) option->sctp.srto_initial = atoi(v); |
697 | 0 | } else if (!strcmp(sctp_key, "srto_min")) { |
698 | 0 | const char *v = ogs_yaml_iter_value(&sctp_iter); |
699 | 0 | if (v) option->sctp.srto_min = atoi(v); |
700 | 0 | } else if (!strcmp(sctp_key, "srto_max")) { |
701 | 0 | const char *v = ogs_yaml_iter_value(&sctp_iter); |
702 | 0 | if (v) option->sctp.srto_max = atoi(v); |
703 | 0 | } else if (!strcmp(sctp_key, "sinit_num_ostreams")) { |
704 | 0 | const char *v = ogs_yaml_iter_value(&sctp_iter); |
705 | 0 | if (v) option->sctp.sinit_num_ostreams = atoi(v); |
706 | 0 | } else if (!strcmp(sctp_key, "sinit_max_instreams")) { |
707 | 0 | const char *v = ogs_yaml_iter_value(&sctp_iter); |
708 | 0 | if (v) option->sctp.sinit_max_instreams = atoi(v); |
709 | 0 | } else if (!strcmp(sctp_key, "sinit_max_attempts")) { |
710 | 0 | const char *v = ogs_yaml_iter_value(&sctp_iter); |
711 | 0 | if (v) option->sctp.sinit_max_attempts = atoi(v); |
712 | 0 | } else if (!strcmp(sctp_key, "sinit_max_init_timeo")) { |
713 | 0 | const char *v = ogs_yaml_iter_value(&sctp_iter); |
714 | 0 | if (v) option->sctp.sinit_max_init_timeo = atoi(v); |
715 | 0 | } else { |
716 | 0 | ogs_error("unknown key `%s`", sctp_key); |
717 | 0 | return OGS_ERROR; |
718 | 0 | } |
719 | 0 | } |
720 | 0 | } else if (!strcmp(sockopt_key, "sctp_nodelay")) { |
721 | 0 | option->sctp_nodelay = ogs_yaml_iter_bool(&sockopt_iter); |
722 | 0 | } else if (!strcmp(sockopt_key, "tcp_nodelay")) { |
723 | 0 | option->tcp_nodelay = ogs_yaml_iter_bool(&sockopt_iter); |
724 | |
|
725 | 0 | } else if (!strcmp(sockopt_key, "so_linger")) { |
726 | 0 | ogs_yaml_iter_t so_linger_iter; |
727 | 0 | ogs_yaml_iter_recurse(&sockopt_iter, &so_linger_iter); |
728 | |
|
729 | 0 | while (ogs_yaml_iter_next(&so_linger_iter)) { |
730 | 0 | const char *so_linger_key = ogs_yaml_iter_key(&so_linger_iter); |
731 | 0 | ogs_assert(so_linger_key); |
732 | 0 | if (!strcmp(so_linger_key, "l_onoff")) { |
733 | 0 | option->so_linger.l_onoff = |
734 | 0 | ogs_yaml_iter_bool(&so_linger_iter); |
735 | 0 | } else if (!strcmp(so_linger_key, "l_linger")) { |
736 | 0 | const char *v = ogs_yaml_iter_value(&so_linger_iter); |
737 | 0 | if (v) option->so_linger.l_linger = atoi(v); |
738 | 0 | } else { |
739 | 0 | ogs_error("unknown key `%s`", so_linger_key); |
740 | 0 | return OGS_ERROR; |
741 | 0 | } |
742 | 0 | } |
743 | |
|
744 | 0 | } else if (!strcmp(sockopt_key, "so_bindtodevice")) { |
745 | 0 | option->so_bindtodevice = ogs_yaml_iter_value(&sockopt_iter); |
746 | |
|
747 | 0 | } else { |
748 | 0 | ogs_error("unknown key `%s`", sockopt_key); |
749 | 0 | return OGS_ERROR; |
750 | 0 | } |
751 | 0 | } |
752 | | |
753 | 0 | return OGS_OK; |
754 | 0 | } |
755 | | |
756 | | /*---------------------------------------------------------------------- |
757 | | * Function: ogs_app_parse_supi_range_conf |
758 | | * |
759 | | * Parse the supi_range configuration from a YAML iterator. |
760 | | * |
761 | | * The expected YAML format is: |
762 | | * |
763 | | * supi_range: |
764 | | * - 999700000000001-999700000099999 |
765 | | * - 310789000000005-310789000000888 |
766 | | * |
767 | | * Both start and end must be provided. |
768 | | * |
769 | | * Returns: |
770 | | * OGS_OK on success, OGS_ERROR on failure. |
771 | | *----------------------------------------------------------------------*/ |
772 | | int ogs_app_parse_supi_range_conf( |
773 | | ogs_yaml_iter_t *parent, ogs_supi_range_t *supi_range) |
774 | 0 | { |
775 | 0 | ogs_yaml_iter_t range_iter; |
776 | |
|
777 | 0 | ogs_assert(parent); |
778 | 0 | ogs_assert(supi_range); |
779 | | |
780 | 0 | memset(supi_range, 0, sizeof(ogs_supi_range_t)); |
781 | | |
782 | | /* Recurse into the supi_range array node */ |
783 | 0 | ogs_yaml_iter_recurse(parent, &range_iter); |
784 | 0 | ogs_assert(ogs_yaml_iter_type(&range_iter) != YAML_MAPPING_NODE); |
785 | | |
786 | 0 | do { |
787 | 0 | char *v = NULL; |
788 | 0 | char *start_str = NULL, *end_str = NULL; |
789 | |
|
790 | 0 | if (ogs_yaml_iter_type(&range_iter) == YAML_SEQUENCE_NODE) { |
791 | 0 | if (!ogs_yaml_iter_next(&range_iter)) |
792 | 0 | break; |
793 | 0 | } |
794 | | |
795 | 0 | v = (char *)ogs_yaml_iter_value(&range_iter); |
796 | |
|
797 | 0 | if (v) { |
798 | 0 | ogs_assert(supi_range->num < OGS_MAX_NUM_OF_SUPI_RANGE); |
799 | | |
800 | | /* Split the string on '-' */ |
801 | 0 | start_str = strsep(&v, "-"); |
802 | 0 | if (start_str == NULL || strlen(start_str) == 0) { |
803 | 0 | ogs_error("Invalid supi_range starter bound: %s", v); |
804 | 0 | return OGS_ERROR; |
805 | 0 | } |
806 | | |
807 | 0 | end_str = v; |
808 | 0 | if (end_str == NULL || strlen(end_str) == 0) { |
809 | 0 | ogs_error("Invalid supi_range upper bound: %s", v); |
810 | 0 | return OGS_ERROR; |
811 | 0 | } |
812 | | |
813 | 0 | supi_range->start[supi_range->num] = |
814 | 0 | ogs_uint64_from_string_decimal(start_str); |
815 | 0 | supi_range->end[supi_range->num] = |
816 | 0 | ogs_uint64_from_string_decimal(end_str); |
817 | |
|
818 | 0 | supi_range->num++; |
819 | 0 | } |
820 | |
|
821 | 0 | } while (ogs_yaml_iter_type(&range_iter) == YAML_SEQUENCE_NODE); |
822 | | |
823 | 0 | return OGS_OK; |
824 | 0 | } |
825 | | |
826 | | static int parse_br_conf(ogs_yaml_iter_t *parent, ogs_bitrate_t *br) |
827 | 0 | { |
828 | 0 | ogs_yaml_iter_t br_iter; |
829 | |
|
830 | 0 | ogs_assert(parent); |
831 | 0 | ogs_assert(br); |
832 | | |
833 | 0 | ogs_yaml_iter_recurse(parent, &br_iter); |
834 | |
|
835 | 0 | while (ogs_yaml_iter_next(&br_iter)) { |
836 | 0 | const char *br_key = ogs_yaml_iter_key(&br_iter); |
837 | 0 | ogs_assert(br_key); |
838 | 0 | if (!strcmp(br_key, OGS_DOWNLINK_STRING)) { |
839 | 0 | uint8_t unit = 0; |
840 | 0 | int n; |
841 | |
|
842 | 0 | ogs_yaml_iter_t downlink_iter; |
843 | 0 | ogs_yaml_iter_recurse(&br_iter, &downlink_iter); |
844 | |
|
845 | 0 | while (ogs_yaml_iter_next(&downlink_iter)) { |
846 | 0 | const char *downlink_key = |
847 | 0 | ogs_yaml_iter_key(&downlink_iter); |
848 | 0 | ogs_assert(downlink_key); |
849 | 0 | if (!strcmp(downlink_key, OGS_VALUE_STRING)) { |
850 | 0 | const char *v = ogs_yaml_iter_value(&downlink_iter); |
851 | 0 | if (v) br->downlink = atoi(v); |
852 | 0 | } else if (!strcmp(downlink_key, OGS_UNIT_STRING)) { |
853 | 0 | const char *v = ogs_yaml_iter_value(&downlink_iter); |
854 | 0 | if (v) { |
855 | 0 | unit = atoi(v); |
856 | 0 | if (unit == 0 || unit == 1 || unit == 2 || |
857 | 0 | unit == 3 || unit == 4) { |
858 | 0 | } else { |
859 | 0 | ogs_error("Unknown Unit [%d]", unit); |
860 | 0 | return OGS_ERROR; |
861 | 0 | } |
862 | 0 | } |
863 | 0 | } else |
864 | 0 | ogs_warn("unknown key `%s`", downlink_key); |
865 | 0 | } |
866 | | |
867 | 0 | for (n = 0; n < unit; n++) |
868 | 0 | br->downlink *= 1000; |
869 | 0 | } else if (!strcmp(br_key, OGS_UPLINK_STRING)) { |
870 | 0 | uint8_t unit = 0; |
871 | 0 | int n; |
872 | |
|
873 | 0 | ogs_yaml_iter_t uplink_iter; |
874 | 0 | ogs_yaml_iter_recurse(&br_iter, &uplink_iter); |
875 | |
|
876 | 0 | while (ogs_yaml_iter_next(&uplink_iter)) { |
877 | 0 | const char *uplink_key = |
878 | 0 | ogs_yaml_iter_key(&uplink_iter); |
879 | 0 | ogs_assert(uplink_key); |
880 | 0 | if (!strcmp(uplink_key, OGS_VALUE_STRING)) { |
881 | 0 | const char *v = ogs_yaml_iter_value(&uplink_iter); |
882 | 0 | if (v) br->uplink = atoi(v); |
883 | 0 | } else if (!strcmp(uplink_key, OGS_UNIT_STRING)) { |
884 | 0 | const char *v = ogs_yaml_iter_value(&uplink_iter); |
885 | 0 | if (v) { |
886 | 0 | unit = atoi(v); |
887 | 0 | if (unit == 0 || unit == 1 || unit == 2 || |
888 | 0 | unit == 3 || unit == 4) { |
889 | 0 | } else { |
890 | 0 | ogs_error("Unknown Unit [%d]", unit); |
891 | 0 | return OGS_ERROR; |
892 | 0 | } |
893 | 0 | } |
894 | 0 | } else |
895 | 0 | ogs_warn("unknown key `%s`", uplink_key); |
896 | 0 | } |
897 | | |
898 | 0 | for (n = 0; n < unit; n++) |
899 | 0 | br->uplink *= 1000; |
900 | 0 | } else |
901 | 0 | ogs_warn("unknown key `%s`", br_key); |
902 | 0 | } |
903 | | |
904 | 0 | return OGS_OK; |
905 | 0 | } |
906 | | |
907 | | static int parse_qos_conf(ogs_yaml_iter_t *parent, ogs_qos_t *qos) |
908 | 0 | { |
909 | 0 | int rv; |
910 | 0 | ogs_yaml_iter_t qos_iter; |
911 | |
|
912 | 0 | ogs_assert(parent); |
913 | 0 | ogs_assert(qos); |
914 | | |
915 | 0 | ogs_yaml_iter_recurse(parent, &qos_iter); |
916 | 0 | while (ogs_yaml_iter_next(&qos_iter)) { |
917 | 0 | const char *qos_key = ogs_yaml_iter_key(&qos_iter); |
918 | 0 | ogs_assert(qos_key); |
919 | 0 | if (!strcmp(qos_key, OGS_INDEX_STRING)) { |
920 | 0 | const char *v = ogs_yaml_iter_value(&qos_iter); |
921 | 0 | if (v) { |
922 | 0 | uint8_t index = atoi(v); |
923 | 0 | if (index == 1 || index == 2 || index == 3 || index == 4 || |
924 | 0 | index == 65 || index == 66 || index == 67 || index == 75 || |
925 | 0 | index == 71 || index == 72 || index == 73 || index == 74 || |
926 | 0 | index == 76 || index == 5 || index == 6 || index == 7 || |
927 | 0 | index == 8 || index == 9 || index == 69 || index == 70 || |
928 | 0 | index == 79 || index == 80 || index == 82 || index == 83 || |
929 | 0 | index == 84 || index == 85 || index == 86) |
930 | 0 | qos->index = index; |
931 | 0 | else { |
932 | 0 | ogs_error("Unknown QCI [%d]", index); |
933 | 0 | return OGS_ERROR; |
934 | 0 | } |
935 | 0 | } |
936 | 0 | } else if (!strcmp(qos_key, OGS_ARP_STRING)) { |
937 | 0 | ogs_yaml_iter_t arp_iter; |
938 | 0 | ogs_yaml_iter_recurse(&qos_iter, &arp_iter); |
939 | 0 | while (ogs_yaml_iter_next(&arp_iter)) { |
940 | 0 | const char *arp_key = ogs_yaml_iter_key(&arp_iter); |
941 | 0 | ogs_assert(arp_key); |
942 | 0 | if (!strcmp(arp_key, OGS_PRIORITY_LEVEL_STRING)) { |
943 | 0 | const char *v = ogs_yaml_iter_value(&arp_iter); |
944 | 0 | if (v) { |
945 | 0 | uint8_t priority_level = atoi(v); |
946 | 0 | if (priority_level >= 1 && priority_level <= 15) |
947 | 0 | qos->arp.priority_level = priority_level; |
948 | 0 | else { |
949 | 0 | ogs_error("Unknown Priority Level [%d]", |
950 | 0 | priority_level); |
951 | 0 | return OGS_ERROR; |
952 | 0 | } |
953 | 0 | } |
954 | 0 | } else if (!strcmp(arp_key, |
955 | 0 | OGS_PRE_EMPTION_CAPABILITY_STRING)) { |
956 | 0 | const char *v = ogs_yaml_iter_value(&arp_iter); |
957 | 0 | if (v) { |
958 | 0 | uint8_t pre_emption_capability = atoi(v); |
959 | 0 | if (pre_emption_capability == |
960 | 0 | OGS_5GC_PRE_EMPTION_DISABLED || |
961 | 0 | pre_emption_capability == |
962 | 0 | OGS_5GC_PRE_EMPTION_ENABLED) |
963 | 0 | qos->arp.pre_emption_capability = |
964 | 0 | pre_emption_capability; |
965 | 0 | else { |
966 | 0 | ogs_error("Unknown Preemption Capability [%d]", |
967 | 0 | pre_emption_capability); |
968 | 0 | return OGS_ERROR; |
969 | 0 | } |
970 | 0 | } |
971 | 0 | } else if (!strcmp(arp_key, |
972 | 0 | OGS_PRE_EMPTION_VULNERABILITY_STRING)) { |
973 | 0 | const char *v = ogs_yaml_iter_value(&arp_iter); |
974 | 0 | if (v) { |
975 | 0 | uint8_t pre_emption_vulnerability = atoi(v); |
976 | 0 | if (pre_emption_vulnerability == |
977 | 0 | OGS_5GC_PRE_EMPTION_DISABLED || |
978 | 0 | pre_emption_vulnerability == |
979 | 0 | OGS_5GC_PRE_EMPTION_ENABLED) |
980 | 0 | qos->arp.pre_emption_vulnerability = |
981 | 0 | pre_emption_vulnerability; |
982 | 0 | else { |
983 | 0 | ogs_error("Unknown Preemption Vulnerablility [%d]", |
984 | 0 | pre_emption_vulnerability); |
985 | 0 | return OGS_ERROR; |
986 | 0 | } |
987 | 0 | } |
988 | 0 | } else |
989 | 0 | ogs_warn("unknown key `%s`", arp_key); |
990 | 0 | } |
991 | 0 | } else if (!strcmp(qos_key, OGS_MBR_STRING)) { |
992 | 0 | rv = parse_br_conf(&qos_iter, &qos->mbr); |
993 | 0 | if (rv != OGS_OK) { |
994 | 0 | ogs_error("parse_br_conf() failed"); |
995 | 0 | return rv; |
996 | 0 | } |
997 | 0 | } else if (!strcmp(qos_key, OGS_GBR_STRING)) { |
998 | 0 | rv = parse_br_conf(&qos_iter, &qos->gbr); |
999 | 0 | if (rv != OGS_OK) { |
1000 | 0 | ogs_error("parse_br_conf() failed"); |
1001 | 0 | return rv; |
1002 | 0 | } |
1003 | 0 | } |
1004 | 0 | } |
1005 | | |
1006 | 0 | return OGS_OK; |
1007 | 0 | } |
1008 | | |
1009 | | static int session_conf_prepare(ogs_app_slice_conf_t *slice_conf) |
1010 | 0 | { |
1011 | 0 | ogs_assert(slice_conf); |
1012 | 0 | return OGS_OK; |
1013 | 0 | } |
1014 | | |
1015 | | static int session_conf_validation(ogs_app_slice_conf_t *slice_conf) |
1016 | 0 | { |
1017 | 0 | int rv, j, k; |
1018 | 0 | ogs_app_session_conf_t *session_conf = NULL; |
1019 | 0 | ogs_assert(slice_conf); |
1020 | | |
1021 | 0 | ogs_list_for_each(&slice_conf->sess_list, session_conf) { |
1022 | 0 | ogs_session_data_t *session_data = &session_conf->data; |
1023 | |
|
1024 | 0 | ogs_info("NAME[%s]", session_data->session.name); |
1025 | 0 | ogs_info("QCI[%d]", session_data->session.qos.index); |
1026 | 0 | ogs_info("ARP[%d:%d:%d]", |
1027 | 0 | session_data->session.qos.arp.priority_level, |
1028 | 0 | session_data->session.qos.arp.pre_emption_capability, |
1029 | 0 | session_data->session.qos.arp.pre_emption_vulnerability); |
1030 | 0 | ogs_info("AMBR[Downlink:%lld:Uplink:%lld]", |
1031 | 0 | (long long)session_data->session.ambr.downlink, |
1032 | 0 | (long long)session_data->session.ambr.uplink); |
1033 | 0 | for (j = 0; j < session_data->num_of_pcc_rule; j++) { |
1034 | 0 | ogs_info("PCC_RULE[%d]", j+1); |
1035 | 0 | ogs_info(" ID[%s]", session_data->pcc_rule[j].id); |
1036 | 0 | ogs_info(" NAME[%s]", session_data->pcc_rule[j].name); |
1037 | 0 | ogs_info(" QCI[%d]", session_data->pcc_rule[j].qos.index); |
1038 | 0 | ogs_info(" ARP[%d:%d:%d]", |
1039 | 0 | session_data->pcc_rule[j].qos.arp.priority_level, |
1040 | 0 | session_data->pcc_rule[j].qos.arp. |
1041 | 0 | pre_emption_capability, |
1042 | 0 | session_data->pcc_rule[j].qos.arp. |
1043 | 0 | pre_emption_vulnerability); |
1044 | 0 | ogs_info(" MBR[Downlink:%lld:Uplink:%lld]", |
1045 | 0 | (long long)session_data->pcc_rule[j].qos.mbr.downlink, |
1046 | 0 | (long long)session_data->pcc_rule[j].qos.mbr.uplink); |
1047 | 0 | ogs_info(" GBR[Downlink:%lld:Uplink:%lld]", |
1048 | 0 | (long long)session_data->pcc_rule[j].qos.gbr.downlink, |
1049 | 0 | (long long)session_data->pcc_rule[j].qos.gbr.uplink); |
1050 | 0 | ogs_info(" NUM_OF_FLOW [%d]", |
1051 | 0 | session_data->pcc_rule[j].num_of_flow); |
1052 | |
|
1053 | 0 | for (k = 0; k < session_data->pcc_rule[j].num_of_flow; k++) { |
1054 | 0 | ogs_info(" DIRECTION[%d]", |
1055 | 0 | session_data->pcc_rule[j].flow[k].direction); |
1056 | 0 | ogs_info(" DESCRIPTION[%s]", |
1057 | 0 | session_data->pcc_rule[j].flow[k].description); |
1058 | 0 | } |
1059 | 0 | } |
1060 | |
|
1061 | 0 | rv = ogs_check_br_conf(&session_data->session.ambr); |
1062 | 0 | if (rv != OGS_OK) { |
1063 | 0 | ogs_error("check_br_conf(AMBR) failed"); |
1064 | 0 | return rv; |
1065 | 0 | } |
1066 | 0 | rv = ogs_check_qos_conf(&session_data->session.qos); |
1067 | 0 | if (rv != OGS_OK) { |
1068 | 0 | ogs_error("check_qos_conf(SESS) failed"); |
1069 | 0 | return rv; |
1070 | 0 | } |
1071 | 0 | } |
1072 | | |
1073 | 0 | return OGS_OK; |
1074 | 0 | } |
1075 | | |
1076 | | int ogs_app_parse_session_conf( |
1077 | | ogs_yaml_iter_t *parent, ogs_app_slice_conf_t *slice_conf) |
1078 | 0 | { |
1079 | 0 | int rv; |
1080 | 0 | ogs_yaml_iter_t session_array, session_iter; |
1081 | |
|
1082 | 0 | ogs_assert(parent); |
1083 | 0 | ogs_assert(slice_conf); |
1084 | | |
1085 | 0 | rv = session_conf_prepare(slice_conf); |
1086 | 0 | if (rv != OGS_OK) return rv; |
1087 | | |
1088 | 0 | ogs_yaml_iter_recurse(parent, &session_array); |
1089 | 0 | do { |
1090 | 0 | const char *name = NULL; |
1091 | 0 | ogs_app_session_conf_t *session_conf = NULL; |
1092 | 0 | ogs_session_data_t *session_data = NULL; |
1093 | |
|
1094 | 0 | OGS_YAML_ARRAY_NEXT(&session_array, &session_iter); |
1095 | 0 | while (ogs_yaml_iter_next(&session_iter)) { |
1096 | 0 | const char *session_key = ogs_yaml_iter_key(&session_iter); |
1097 | 0 | ogs_assert(session_key); |
1098 | 0 | if (!strcmp(session_key, OGS_NAME_STRING)) { |
1099 | 0 | name = (char *)ogs_yaml_iter_value(&session_iter); |
1100 | 0 | } |
1101 | 0 | } |
1102 | | |
1103 | 0 | if (name) { |
1104 | 0 | session_conf = ogs_app_session_conf_add(slice_conf, (char *)name); |
1105 | 0 | if (!session_conf) { |
1106 | 0 | ogs_error("ogs_app_session_conf_add() failed [DNN:%s]", name); |
1107 | 0 | return OGS_ERROR; |
1108 | 0 | } |
1109 | 0 | } else { |
1110 | 0 | ogs_error("No APN/DNN"); |
1111 | 0 | return OGS_ERROR; |
1112 | 0 | } |
1113 | | |
1114 | 0 | session_data = &session_conf->data; |
1115 | 0 | OGS_YAML_ARRAY_RECURSE(&session_array, &session_iter); |
1116 | 0 | while (ogs_yaml_iter_next(&session_iter)) { |
1117 | 0 | const char *session_key = ogs_yaml_iter_key(&session_iter); |
1118 | 0 | ogs_assert(session_key); |
1119 | 0 | if (!strcmp(session_key, OGS_TYPE_STRING)) { |
1120 | 0 | const char *v = ogs_yaml_iter_value(&session_iter); |
1121 | 0 | if (v) { |
1122 | 0 | uint8_t session_type = atoi(v); |
1123 | 0 | if (session_type == OGS_PDU_SESSION_TYPE_IPV4 || |
1124 | 0 | session_type == OGS_PDU_SESSION_TYPE_IPV6 || |
1125 | 0 | session_type == OGS_PDU_SESSION_TYPE_IPV4V6 || |
1126 | 0 | session_type == OGS_PDU_SESSION_TYPE_UNSTRUCTURED || |
1127 | 0 | session_type == OGS_PDU_SESSION_TYPE_ETHERNET) |
1128 | 0 | session_data->session.session_type = session_type; |
1129 | 0 | else { |
1130 | 0 | ogs_error("Unknown Session Type [%d]", session_type); |
1131 | 0 | return OGS_ERROR; |
1132 | 0 | } |
1133 | 0 | } |
1134 | 0 | } else if (!strcmp(session_key, OGS_AMBR_STRING)) { |
1135 | 0 | rv = parse_br_conf(&session_iter, &session_data->session.ambr); |
1136 | 0 | if (rv != OGS_OK) { |
1137 | 0 | ogs_error("parse_qos_conf() failed"); |
1138 | 0 | return rv; |
1139 | 0 | } |
1140 | 0 | } else if (!strcmp(session_key, OGS_QOS_STRING)) { |
1141 | 0 | rv = parse_qos_conf(&session_iter, &session_data->session.qos); |
1142 | 0 | if (rv != OGS_OK) { |
1143 | 0 | ogs_error("parse_qos_conf() failed"); |
1144 | 0 | return rv; |
1145 | 0 | } |
1146 | 0 | } else if (!strcmp(session_key, OGS_PCC_RULE_STRING)) { |
1147 | 0 | int pcc_rule_index = 0; |
1148 | 0 | ogs_yaml_iter_t pcc_rule_array, pcc_rule_iter; |
1149 | 0 | ogs_yaml_iter_recurse(&session_iter, &pcc_rule_array); |
1150 | 0 | do { |
1151 | 0 | ogs_pcc_rule_t *pcc_rule = NULL; |
1152 | |
|
1153 | 0 | ogs_assert(session_data->num_of_pcc_rule < |
1154 | 0 | OGS_MAX_NUM_OF_PCC_RULE); |
1155 | 0 | pcc_rule = &session_data-> |
1156 | 0 | pcc_rule[session_data->num_of_pcc_rule]; |
1157 | |
|
1158 | 0 | OGS_YAML_ARRAY_NEXT(&pcc_rule_array, &pcc_rule_iter); |
1159 | 0 | while (ogs_yaml_iter_next(&pcc_rule_iter)) { |
1160 | 0 | const char *pcc_rule_key = |
1161 | 0 | ogs_yaml_iter_key(&pcc_rule_iter); |
1162 | 0 | ogs_assert(pcc_rule_key); |
1163 | 0 | if (!strcmp(pcc_rule_key, OGS_QOS_STRING)) { |
1164 | 0 | rv = parse_qos_conf(&pcc_rule_iter, &pcc_rule->qos); |
1165 | 0 | if (rv != OGS_OK) { |
1166 | 0 | ogs_error("parse_qos_conf() failed"); |
1167 | 0 | return rv; |
1168 | 0 | } |
1169 | 0 | } else if (!strcmp(pcc_rule_key, OGS_FLOW_STRING)) { |
1170 | 0 | ogs_yaml_iter_t flow_array, flow_iter; |
1171 | 0 | ogs_yaml_iter_recurse( &pcc_rule_iter, &flow_array); |
1172 | 0 | do { |
1173 | 0 | ogs_flow_t *flow = NULL; |
1174 | |
|
1175 | 0 | ogs_assert(pcc_rule->num_of_flow < |
1176 | 0 | OGS_MAX_NUM_OF_FLOW_IN_PCC_RULE); |
1177 | 0 | flow = &pcc_rule->flow[pcc_rule->num_of_flow]; |
1178 | |
|
1179 | 0 | OGS_YAML_ARRAY_NEXT(&flow_array, &flow_iter); |
1180 | 0 | while (ogs_yaml_iter_next(&flow_iter)) { |
1181 | 0 | const char *flow_key = |
1182 | 0 | ogs_yaml_iter_key(&flow_iter); |
1183 | 0 | ogs_assert(flow_key); |
1184 | 0 | if (!strcmp(flow_key, |
1185 | 0 | OGS_DIRECTION_STRING)) { |
1186 | 0 | const char *v = |
1187 | 0 | ogs_yaml_iter_value(&flow_iter); |
1188 | 0 | if (v) { |
1189 | 0 | uint8_t direction = atoi(v); |
1190 | 0 | if (direction == |
1191 | 0 | OGS_FLOW_DOWNLINK_ONLY || |
1192 | 0 | direction == |
1193 | 0 | OGS_FLOW_UPLINK_ONLY) |
1194 | 0 | flow->direction = direction; |
1195 | 0 | else { |
1196 | 0 | ogs_error( |
1197 | 0 | "Unknown Direction [%d]", |
1198 | 0 | direction); |
1199 | 0 | return OGS_ERROR; |
1200 | 0 | } |
1201 | 0 | } |
1202 | 0 | } else if (!strcmp(flow_key, |
1203 | 0 | OGS_DESCRIPTION_STRING)) { |
1204 | 0 | const char *v = |
1205 | 0 | (char *)ogs_yaml_iter_value( |
1206 | 0 | &flow_iter); |
1207 | 0 | if (v) { |
1208 | 0 | flow->description = ogs_strdup(v); |
1209 | 0 | ogs_assert(flow->description); |
1210 | 0 | } |
1211 | 0 | } |
1212 | 0 | } |
1213 | | |
1214 | 0 | if (flow->direction && flow->description) |
1215 | 0 | pcc_rule->num_of_flow++; |
1216 | |
|
1217 | 0 | } while (ogs_yaml_iter_type(&flow_array) == |
1218 | 0 | YAML_SEQUENCE_NODE); |
1219 | |
|
1220 | 0 | } else |
1221 | 0 | ogs_warn("unknown key `%s`", pcc_rule_key); |
1222 | 0 | } |
1223 | | |
1224 | 0 | if (pcc_rule->qos.index && |
1225 | 0 | pcc_rule->qos.arp.priority_level && |
1226 | 0 | pcc_rule->qos.arp.pre_emption_capability && |
1227 | 0 | pcc_rule->qos.arp.pre_emption_vulnerability) { |
1228 | | |
1229 | | /* EPC: Charing-Rule-Name */ |
1230 | 0 | ogs_assert(!pcc_rule->name); |
1231 | 0 | pcc_rule->name = ogs_msprintf("%s-g%d", |
1232 | 0 | session_data->session.name, pcc_rule_index+1); |
1233 | 0 | ogs_assert(pcc_rule->name); |
1234 | | |
1235 | | /* 5GC: PCC-Rule-Id */ |
1236 | 0 | ogs_assert(!pcc_rule->id); |
1237 | 0 | pcc_rule->id = ogs_msprintf("%s-n%d", |
1238 | 0 | session_data->session.name, pcc_rule_index+1); |
1239 | 0 | ogs_assert(pcc_rule->id); |
1240 | | |
1241 | 0 | pcc_rule->precedence = pcc_rule_index+1; |
1242 | 0 | pcc_rule_index++; |
1243 | |
|
1244 | 0 | session_data->num_of_pcc_rule++; |
1245 | 0 | } else |
1246 | 0 | ogs_warn("Mandatory is MISSING - " |
1247 | 0 | "QCI[%d], ARP[%d:%d:%d]", |
1248 | 0 | pcc_rule->qos.index, |
1249 | 0 | pcc_rule->qos.arp.priority_level, |
1250 | 0 | pcc_rule->qos.arp. |
1251 | 0 | pre_emption_capability, |
1252 | 0 | pcc_rule->qos.arp. |
1253 | 0 | pre_emption_vulnerability); |
1254 | |
|
1255 | 0 | } while (ogs_yaml_iter_type(&pcc_rule_array) == |
1256 | 0 | YAML_SEQUENCE_NODE); |
1257 | 0 | } |
1258 | 0 | } |
1259 | |
|
1260 | 0 | } while (ogs_yaml_iter_type(&session_array) == YAML_SEQUENCE_NODE); |
1261 | | |
1262 | 0 | rv = session_conf_validation(slice_conf); |
1263 | 0 | if (rv != OGS_OK) return rv; |
1264 | | |
1265 | 0 | return OGS_OK; |
1266 | 0 | } |
1267 | | |
1268 | | ogs_app_policy_conf_t *ogs_app_policy_conf_add( |
1269 | | ogs_supi_range_t *supi_range, ogs_plmn_id_t *plmn_id) |
1270 | 0 | { |
1271 | 0 | ogs_app_policy_conf_t *policy_conf = NULL; |
1272 | |
|
1273 | 0 | ogs_assert(supi_range || plmn_id); |
1274 | | |
1275 | 0 | ogs_pool_alloc(&policy_conf_pool, &policy_conf); |
1276 | 0 | if (!policy_conf) { |
1277 | 0 | ogs_error("Maximum number of policy_conf[%d] reached", |
1278 | 0 | OGS_MAX_NUM_OF_PLMN); |
1279 | 0 | return NULL; |
1280 | 0 | } |
1281 | 0 | memset(policy_conf, 0, sizeof *policy_conf); |
1282 | |
|
1283 | 0 | if (supi_range) { |
1284 | 0 | int i; |
1285 | |
|
1286 | 0 | memcpy(&policy_conf->supi_range, supi_range, sizeof(ogs_supi_range_t)); |
1287 | |
|
1288 | 0 | ogs_info("SUPI[%d]", policy_conf->supi_range.num); |
1289 | 0 | for (i = 0; i < policy_conf->supi_range.num; i++) |
1290 | 0 | ogs_info(" START[%lld]-END[%lld]", |
1291 | 0 | (long long)policy_conf->supi_range.start[i], |
1292 | 0 | (long long)policy_conf->supi_range.end[i]); |
1293 | |
|
1294 | 0 | } |
1295 | 0 | if (plmn_id) { |
1296 | 0 | policy_conf->plmn_id_valid = true; |
1297 | 0 | memcpy(&policy_conf->plmn_id, plmn_id, sizeof(ogs_plmn_id_t)); |
1298 | 0 | ogs_info("PLMN_ID[MCC:%03d.MNC:%03d]", |
1299 | 0 | ogs_plmn_id_mcc(&policy_conf->plmn_id), |
1300 | 0 | ogs_plmn_id_mnc(&policy_conf->plmn_id)); |
1301 | 0 | } |
1302 | |
|
1303 | 0 | ogs_list_init(&policy_conf->slice_list); |
1304 | |
|
1305 | 0 | ogs_list_add(&local_conf.policy_list, policy_conf); |
1306 | |
|
1307 | 0 | ogs_info("POLICY config added [%d]", |
1308 | 0 | ogs_list_count(&local_conf.policy_list)); |
1309 | 0 | return policy_conf; |
1310 | 0 | } |
1311 | | |
1312 | | ogs_app_policy_conf_t *ogs_app_policy_conf_find( |
1313 | | char *supi, ogs_plmn_id_t *plmn_id) |
1314 | 0 | { |
1315 | 0 | ogs_app_policy_conf_t *policy_conf; |
1316 | 0 | int i; |
1317 | |
|
1318 | 0 | char *supi_type = NULL; |
1319 | 0 | char *supi_id = NULL; |
1320 | 0 | uint64_t supi_decimal; |
1321 | |
|
1322 | 0 | ogs_assert(supi); |
1323 | | |
1324 | 0 | supi_type = ogs_id_get_type(supi); |
1325 | 0 | ogs_assert(supi_type); |
1326 | 0 | supi_id = ogs_id_get_value(supi); |
1327 | 0 | ogs_assert(supi_id); |
1328 | | |
1329 | 0 | supi_decimal = ogs_uint64_from_string_decimal(supi_id); |
1330 | |
|
1331 | 0 | ogs_free(supi_type); |
1332 | 0 | ogs_free(supi_id); |
1333 | |
|
1334 | 0 | ogs_list_for_each(&local_conf.policy_list, policy_conf) { |
1335 | | /* If supi_range is set, check if supi_decimal falls within |
1336 | | * any of the defined ranges. |
1337 | | */ |
1338 | 0 | if (policy_conf->supi_range.num > 0) { |
1339 | 0 | int in_range = 0; |
1340 | 0 | for (i = 0; i < policy_conf->supi_range.num; i++) { |
1341 | 0 | if ((supi_decimal >= policy_conf->supi_range.start[i]) && |
1342 | 0 | (supi_decimal <= policy_conf->supi_range.end[i])) { |
1343 | 0 | in_range = 1; |
1344 | 0 | break; |
1345 | 0 | } |
1346 | 0 | } |
1347 | 0 | if (!in_range) { |
1348 | 0 | continue; |
1349 | 0 | } |
1350 | 0 | } |
1351 | | |
1352 | | /* If a plmn_id is set and it does not match the |
1353 | | * current policy's plmn_id, skip this policy. |
1354 | | */ |
1355 | 0 | if (policy_conf->plmn_id_valid && |
1356 | 0 | memcmp(&policy_conf->plmn_id, plmn_id, |
1357 | 0 | sizeof(ogs_plmn_id_t)) != 0) { |
1358 | 0 | continue; |
1359 | 0 | } |
1360 | | |
1361 | | /* Both conditions met; return this policy configuration */ |
1362 | 0 | return policy_conf; |
1363 | 0 | } |
1364 | | |
1365 | 0 | return NULL; |
1366 | 0 | } |
1367 | | void ogs_app_policy_conf_remove(ogs_app_policy_conf_t *policy_conf) |
1368 | 0 | { |
1369 | 0 | ogs_assert(policy_conf); |
1370 | | |
1371 | 0 | ogs_list_remove(&local_conf.policy_list, policy_conf); |
1372 | |
|
1373 | 0 | ogs_app_slice_conf_remove_all(policy_conf); |
1374 | |
|
1375 | 0 | ogs_pool_free(&policy_conf_pool, policy_conf); |
1376 | |
|
1377 | 0 | ogs_info("POLICY config removed [%d]", |
1378 | 0 | ogs_list_count(&local_conf.policy_list)); |
1379 | 0 | } |
1380 | | void ogs_app_policy_conf_remove_all(void) |
1381 | 0 | { |
1382 | 0 | ogs_app_policy_conf_t *policy_conf = NULL, *next_conf = NULL;; |
1383 | |
|
1384 | 0 | ogs_list_for_each_safe(&local_conf.policy_list, next_conf, policy_conf) |
1385 | 0 | ogs_app_policy_conf_remove(policy_conf); |
1386 | 0 | } |
1387 | | |
1388 | | ogs_app_slice_conf_t *ogs_app_slice_conf_add( |
1389 | | ogs_app_policy_conf_t *policy_conf, ogs_s_nssai_t *s_nssai) |
1390 | 0 | { |
1391 | 0 | ogs_app_slice_conf_t *slice_conf = NULL; |
1392 | |
|
1393 | 0 | ogs_assert(policy_conf); |
1394 | 0 | ogs_assert(s_nssai); |
1395 | | |
1396 | 0 | ogs_pool_alloc(&slice_conf_pool, &slice_conf); |
1397 | 0 | if (!slice_conf) { |
1398 | 0 | ogs_error("Maximum number of slice_conf[%d] reached", |
1399 | 0 | OGS_MAX_NUM_OF_SLICE); |
1400 | 0 | return NULL; |
1401 | 0 | } |
1402 | 0 | memset(slice_conf, 0, sizeof *slice_conf); |
1403 | |
|
1404 | 0 | slice_conf->data.s_nssai.sst = s_nssai->sst; |
1405 | 0 | slice_conf->data.s_nssai.sd.v = s_nssai->sd.v; |
1406 | |
|
1407 | 0 | ogs_list_init(&slice_conf->sess_list); |
1408 | |
|
1409 | 0 | ogs_list_add(&policy_conf->slice_list, slice_conf); |
1410 | |
|
1411 | 0 | slice_conf->policy_conf = policy_conf; |
1412 | |
|
1413 | 0 | ogs_info("SLICE config added [%d]", |
1414 | 0 | ogs_list_count(&policy_conf->slice_list)); |
1415 | 0 | return slice_conf; |
1416 | 0 | } |
1417 | | |
1418 | | ogs_app_slice_conf_t *ogs_app_slice_conf_find_by_s_nssai( |
1419 | | ogs_app_policy_conf_t *policy_conf, ogs_s_nssai_t *s_nssai) |
1420 | 0 | { |
1421 | 0 | ogs_app_slice_conf_t *slice_conf = NULL; |
1422 | |
|
1423 | 0 | ogs_assert(policy_conf); |
1424 | 0 | ogs_assert(s_nssai); |
1425 | | |
1426 | 0 | ogs_list_for_each(&policy_conf->slice_list, slice_conf) { |
1427 | 0 | if (slice_conf->data.s_nssai.sst == s_nssai->sst && |
1428 | 0 | slice_conf->data.s_nssai.sd.v == s_nssai->sd.v) |
1429 | 0 | break; |
1430 | 0 | } |
1431 | |
|
1432 | 0 | return slice_conf; |
1433 | 0 | } |
1434 | | void ogs_app_slice_conf_remove(ogs_app_slice_conf_t *slice_conf) |
1435 | 0 | { |
1436 | 0 | ogs_app_policy_conf_t *policy_conf = NULL; |
1437 | |
|
1438 | 0 | ogs_assert(slice_conf); |
1439 | 0 | policy_conf = slice_conf->policy_conf; |
1440 | 0 | ogs_assert(policy_conf); |
1441 | | |
1442 | 0 | ogs_list_remove(&policy_conf->slice_list, slice_conf); |
1443 | |
|
1444 | 0 | ogs_app_session_conf_remove_all(slice_conf); |
1445 | |
|
1446 | 0 | ogs_pool_free(&slice_conf_pool, slice_conf); |
1447 | |
|
1448 | 0 | ogs_info("SLICE config removed [%d]", |
1449 | 0 | ogs_list_count(&policy_conf->slice_list)); |
1450 | 0 | } |
1451 | | void ogs_app_slice_conf_remove_all(ogs_app_policy_conf_t *policy_conf) |
1452 | 0 | { |
1453 | 0 | ogs_app_slice_conf_t *slice_conf = NULL, *next_conf = NULL;; |
1454 | |
|
1455 | 0 | ogs_assert(policy_conf); |
1456 | | |
1457 | 0 | ogs_list_for_each_safe(&policy_conf->slice_list, next_conf, slice_conf) |
1458 | 0 | ogs_app_slice_conf_remove(slice_conf); |
1459 | 0 | } |
1460 | | |
1461 | | int ogs_app_check_policy_conf(void) |
1462 | 0 | { |
1463 | 0 | ogs_app_policy_conf_t *policy_conf = NULL; |
1464 | |
|
1465 | 0 | ogs_list_for_each(&ogs_local_conf()->policy_list, policy_conf) { |
1466 | 0 | ogs_app_slice_conf_t *slice_conf = NULL; |
1467 | 0 | bool default_indicator = false; |
1468 | |
|
1469 | 0 | ogs_list_for_each(&policy_conf->slice_list, slice_conf) { |
1470 | 0 | if (slice_conf->data.default_indicator == true) |
1471 | 0 | default_indicator = true; |
1472 | |
|
1473 | 0 | if (ogs_list_count(&slice_conf->sess_list) == 0) { |
1474 | 0 | ogs_error("At least 1 Session is required"); |
1475 | 0 | return OGS_ERROR; |
1476 | 0 | } |
1477 | 0 | } |
1478 | | |
1479 | 0 | if (default_indicator == false) { |
1480 | 0 | ogs_error("At least 1 Default S-NSSAI is required"); |
1481 | 0 | return OGS_ERROR; |
1482 | 0 | } |
1483 | 0 | } |
1484 | | |
1485 | 0 | return OGS_OK; |
1486 | 0 | } |
1487 | | |
1488 | | ogs_app_session_conf_t *ogs_app_session_conf_add( |
1489 | | ogs_app_slice_conf_t *slice_conf, char *name) |
1490 | 0 | { |
1491 | 0 | ogs_app_session_conf_t *session_conf = NULL; |
1492 | |
|
1493 | 0 | ogs_assert(slice_conf); |
1494 | 0 | ogs_assert(name); |
1495 | | |
1496 | 0 | ogs_pool_alloc(&session_conf_pool, &session_conf); |
1497 | 0 | if (!session_conf) { |
1498 | 0 | ogs_error("Maximum number of session_conf[%d] reached", |
1499 | 0 | OGS_MAX_NUM_OF_SLICE*OGS_MAX_NUM_OF_SESS); |
1500 | 0 | return NULL; |
1501 | 0 | } |
1502 | 0 | memset(session_conf, 0, sizeof *session_conf); |
1503 | |
|
1504 | 0 | session_conf->data.session.name = ogs_strdup(name); |
1505 | 0 | if (!session_conf->data.session.name) { |
1506 | 0 | ogs_error("No memory for DNN[%s]", name); |
1507 | 0 | ogs_pool_free(&session_conf_pool, session_conf); |
1508 | 0 | return NULL; |
1509 | 0 | } |
1510 | | |
1511 | 0 | ogs_list_add(&slice_conf->sess_list, session_conf); |
1512 | |
|
1513 | 0 | session_conf->slice_conf = slice_conf; |
1514 | |
|
1515 | 0 | ogs_info("SESSION config added [%d]", |
1516 | 0 | ogs_list_count(&slice_conf->sess_list)); |
1517 | |
|
1518 | 0 | return session_conf; |
1519 | 0 | } |
1520 | | ogs_app_session_conf_t *ogs_app_session_conf_find_by_dnn( |
1521 | | ogs_app_slice_conf_t *slice_conf, char *name) |
1522 | 0 | { |
1523 | 0 | ogs_app_session_conf_t *session_conf = NULL; |
1524 | |
|
1525 | 0 | ogs_assert(slice_conf); |
1526 | 0 | ogs_assert(name); |
1527 | | |
1528 | 0 | ogs_list_for_each(&slice_conf->sess_list, session_conf) { |
1529 | 0 | ogs_assert(session_conf->data.session.name); |
1530 | 0 | if (strcmp(session_conf->data.session.name, name) == 0) |
1531 | 0 | break; |
1532 | 0 | } |
1533 | | |
1534 | 0 | return session_conf; |
1535 | 0 | } |
1536 | | void ogs_app_session_conf_remove(ogs_app_session_conf_t *session_conf) |
1537 | 0 | { |
1538 | 0 | ogs_app_slice_conf_t *slice_conf = NULL; |
1539 | |
|
1540 | 0 | ogs_assert(session_conf); |
1541 | 0 | slice_conf = session_conf->slice_conf; |
1542 | 0 | ogs_assert(slice_conf); |
1543 | | |
1544 | 0 | ogs_list_remove(&slice_conf->sess_list, session_conf); |
1545 | |
|
1546 | 0 | OGS_SESSION_DATA_FREE(&session_conf->data); |
1547 | | |
1548 | 0 | ogs_pool_free(&session_conf_pool, session_conf); |
1549 | |
|
1550 | 0 | ogs_info("SESSION config removed [%d]", |
1551 | 0 | ogs_list_count(&slice_conf->sess_list)); |
1552 | 0 | } |
1553 | | void ogs_app_session_conf_remove_all(ogs_app_slice_conf_t *slice_conf) |
1554 | 0 | { |
1555 | 0 | ogs_app_session_conf_t *session_conf = NULL, *next_conf = NULL;; |
1556 | |
|
1557 | 0 | ogs_assert(slice_conf); |
1558 | | |
1559 | 0 | ogs_list_for_each_safe(&slice_conf->sess_list, next_conf, session_conf) |
1560 | 0 | ogs_app_session_conf_remove(session_conf); |
1561 | 0 | } |
1562 | | |
1563 | | int ogs_app_config_session_data( |
1564 | | char *supi, ogs_plmn_id_t *plmn_id, ogs_s_nssai_t *s_nssai, char *dnn, |
1565 | | ogs_session_data_t *session_data) |
1566 | 0 | { |
1567 | 0 | ogs_app_policy_conf_t *policy_conf = NULL; |
1568 | 0 | ogs_app_slice_conf_t *slice_conf = NULL; |
1569 | 0 | ogs_app_session_conf_t *session_conf = NULL; |
1570 | |
|
1571 | 0 | ogs_assert(supi); |
1572 | 0 | ogs_assert(dnn); |
1573 | 0 | ogs_assert(session_data); |
1574 | | |
1575 | 0 | policy_conf = ogs_app_policy_conf_find(supi, plmn_id); |
1576 | 0 | if (!policy_conf) { |
1577 | 0 | if (plmn_id) |
1578 | 0 | ogs_error("No POLICY [SUPI:%s] [MCC:%03d,MNC:%03d]", |
1579 | 0 | supi, ogs_plmn_id_mcc(plmn_id), ogs_plmn_id_mnc(plmn_id)); |
1580 | 0 | else |
1581 | 0 | ogs_error("No POLICY [SUPI:%s]", supi); |
1582 | |
|
1583 | 0 | return OGS_ERROR; |
1584 | 0 | } |
1585 | | |
1586 | 0 | if (s_nssai) { |
1587 | 0 | slice_conf = ogs_app_slice_conf_find_by_s_nssai(policy_conf, s_nssai); |
1588 | 0 | if (!slice_conf) { |
1589 | 0 | ogs_error("No SLICE [SST:%d, SD:0x%x]", |
1590 | 0 | s_nssai->sst, s_nssai->sd.v); |
1591 | 0 | return OGS_ERROR; |
1592 | 0 | } |
1593 | 0 | } else { |
1594 | 0 | slice_conf = ogs_list_first(&policy_conf->slice_list); |
1595 | 0 | if (!slice_conf) { |
1596 | 0 | ogs_error("No default SLICE for EPC"); |
1597 | 0 | return OGS_ERROR; |
1598 | 0 | } |
1599 | 0 | } |
1600 | 0 | session_conf = ogs_app_session_conf_find_by_dnn(slice_conf, dnn); |
1601 | 0 | if (!session_conf) { |
1602 | 0 | ogs_error("No SESSION [%s]", dnn); |
1603 | 0 | return OGS_ERROR; |
1604 | 0 | } |
1605 | | |
1606 | 0 | OGS_STORE_SESSION_DATA(session_data, &session_conf->data); |
1607 | | |
1608 | 0 | return OGS_OK; |
1609 | 0 | } |