/src/open5gs/lib/sbi/nnrf-path.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) 2022-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-sbi.h" |
21 | | |
22 | | bool ogs_nnrf_nfm_send_nf_register(ogs_sbi_nf_instance_t *nf_instance) |
23 | 0 | { |
24 | 0 | bool rc; |
25 | 0 | ogs_sbi_request_t *request = NULL; |
26 | |
|
27 | 0 | ogs_assert(nf_instance); |
28 | | |
29 | 0 | request = ogs_nnrf_nfm_build_register(); |
30 | 0 | if (!request) { |
31 | 0 | ogs_error("No Request"); |
32 | 0 | return false; |
33 | 0 | } |
34 | | |
35 | 0 | rc = ogs_sbi_send_request_to_nrf( |
36 | 0 | OpenAPI_service_name_nnrf_nfm, NULL, |
37 | 0 | ogs_sbi_client_handler, request, nf_instance); |
38 | 0 | ogs_expect(rc == true); |
39 | |
|
40 | 0 | ogs_sbi_request_free(request); |
41 | |
|
42 | 0 | return rc; |
43 | 0 | } |
44 | | |
45 | | bool ogs_nnrf_nfm_send_nf_update(ogs_sbi_nf_instance_t *nf_instance) |
46 | 0 | { |
47 | 0 | bool rc; |
48 | 0 | ogs_sbi_request_t *request = NULL; |
49 | |
|
50 | 0 | ogs_assert(nf_instance); |
51 | | |
52 | 0 | request = ogs_nnrf_nfm_build_update(); |
53 | 0 | if (!request) { |
54 | 0 | ogs_error("No Request"); |
55 | 0 | return false; |
56 | 0 | } |
57 | | |
58 | 0 | rc = ogs_sbi_send_request_to_nrf( |
59 | 0 | OpenAPI_service_name_nnrf_nfm, NULL, |
60 | 0 | ogs_sbi_client_handler, request, nf_instance); |
61 | 0 | ogs_expect(rc == true); |
62 | |
|
63 | 0 | ogs_sbi_request_free(request); |
64 | |
|
65 | 0 | return rc; |
66 | 0 | } |
67 | | |
68 | | bool ogs_nnrf_nfm_send_nf_de_register(ogs_sbi_nf_instance_t *nf_instance) |
69 | 0 | { |
70 | 0 | bool rc; |
71 | 0 | ogs_sbi_request_t *request = NULL; |
72 | |
|
73 | 0 | ogs_assert(nf_instance); |
74 | | |
75 | 0 | request = ogs_nnrf_nfm_build_de_register(); |
76 | 0 | if (!request) { |
77 | 0 | ogs_error("No Request"); |
78 | 0 | return false; |
79 | 0 | } |
80 | | |
81 | 0 | rc = ogs_sbi_send_request_to_nrf( |
82 | 0 | OpenAPI_service_name_nnrf_nfm, NULL, |
83 | 0 | ogs_sbi_client_handler, request, nf_instance); |
84 | 0 | ogs_expect(rc == true); |
85 | |
|
86 | 0 | ogs_sbi_request_free(request); |
87 | |
|
88 | 0 | return rc; |
89 | 0 | } |
90 | | |
91 | | bool ogs_nnrf_nfm_send_nf_status_subscribe( |
92 | | OpenAPI_nf_type_e req_nf_type, char *req_nf_instance_id, |
93 | | OpenAPI_nf_type_e subscr_cond_nf_type, |
94 | | OpenAPI_service_name_e subscr_cond_service_name) |
95 | 0 | { |
96 | 0 | bool rc; |
97 | 0 | ogs_sbi_request_t *request = NULL; |
98 | 0 | ogs_sbi_subscription_data_t *subscription_data = NULL; |
99 | | |
100 | | /* Issue #2630 : The format of subscrCond is invalid. Must be 'oneOf'. */ |
101 | 0 | ogs_assert(!subscr_cond_nf_type || !subscr_cond_service_name); |
102 | | |
103 | 0 | subscription_data = ogs_sbi_subscription_data_add(); |
104 | 0 | if (!subscription_data) { |
105 | 0 | ogs_error("ogs_sbi_subscription_data_add() failed"); |
106 | 0 | return false; |
107 | 0 | } |
108 | | |
109 | 0 | subscription_data->req_nf_type = req_nf_type; |
110 | 0 | if (req_nf_instance_id) { |
111 | 0 | subscription_data->req_nf_instance_id = ogs_strdup(req_nf_instance_id); |
112 | 0 | ogs_assert(subscription_data->req_nf_instance_id); |
113 | 0 | } |
114 | | |
115 | 0 | if (subscr_cond_nf_type) |
116 | 0 | subscription_data->subscr_cond.nf_type = subscr_cond_nf_type; |
117 | 0 | else if (subscr_cond_service_name) |
118 | 0 | subscription_data->subscr_cond.service_name = subscr_cond_service_name; |
119 | 0 | else { |
120 | 0 | ogs_fatal("SubscrCond must be 'oneOf'."); |
121 | 0 | ogs_assert_if_reached(); |
122 | 0 | } |
123 | | |
124 | 0 | request = ogs_nnrf_nfm_build_status_subscribe(subscription_data); |
125 | 0 | if (!request) { |
126 | 0 | ogs_error("No Request"); |
127 | 0 | ogs_sbi_subscription_data_remove(subscription_data); |
128 | 0 | return false; |
129 | 0 | } |
130 | | |
131 | 0 | rc = ogs_sbi_send_request_to_nrf( |
132 | 0 | OpenAPI_service_name_nnrf_nfm, NULL, |
133 | 0 | ogs_sbi_client_handler, request, |
134 | 0 | OGS_UINT_TO_POINTER(subscription_data->pool_id)); |
135 | 0 | ogs_expect(rc == true); |
136 | |
|
137 | 0 | ogs_sbi_request_free(request); |
138 | |
|
139 | 0 | if (rc != true) |
140 | 0 | ogs_sbi_subscription_data_remove(subscription_data); |
141 | |
|
142 | 0 | return rc; |
143 | 0 | } |
144 | | |
145 | | bool ogs_nnrf_nfm_send_nf_status_subscribe_renew( |
146 | | ogs_sbi_subscription_data_t *subscription_data) |
147 | 0 | { |
148 | 0 | char *req_nf_instance_id = NULL; |
149 | 0 | OpenAPI_service_name_e subscr_cond_service_name = OpenAPI_service_name_NULL; |
150 | 0 | OpenAPI_nf_type_e req_nf_type; |
151 | 0 | OpenAPI_nf_type_e subscr_cond_nf_type; |
152 | 0 | bool rc; |
153 | |
|
154 | 0 | ogs_assert(subscription_data); |
155 | | |
156 | | /* |
157 | | * The old subscription still occupies subscription_data_pool here. |
158 | | * Keep local copies of the fields needed to rebuild the request, |
159 | | * remove the old subscription first so the pool has a free slot, |
160 | | * then resubscribe. Without this, a full pool would make renewal |
161 | | * fail forever even though the renewal itself does not change the |
162 | | * net occupancy. |
163 | | */ |
164 | 0 | req_nf_type = subscription_data->req_nf_type; |
165 | 0 | subscr_cond_nf_type = subscription_data->subscr_cond.nf_type; |
166 | |
|
167 | 0 | if (subscription_data->req_nf_instance_id) { |
168 | 0 | req_nf_instance_id = |
169 | 0 | ogs_strdup(subscription_data->req_nf_instance_id); |
170 | 0 | ogs_assert(req_nf_instance_id); |
171 | 0 | } |
172 | | |
173 | 0 | if (subscription_data->subscr_cond.service_name) |
174 | 0 | subscr_cond_service_name = subscription_data->subscr_cond.service_name; |
175 | |
|
176 | 0 | ogs_sbi_subscription_data_remove(subscription_data); |
177 | | /* subscription_data is invalid past this point */ |
178 | |
|
179 | 0 | rc = ogs_nnrf_nfm_send_nf_status_subscribe( |
180 | 0 | req_nf_type, req_nf_instance_id, |
181 | 0 | subscr_cond_nf_type, subscr_cond_service_name); |
182 | 0 | if (rc != true) |
183 | 0 | ogs_error("NF status subscription renewal failed"); |
184 | |
|
185 | 0 | ogs_free(req_nf_instance_id); |
186 | |
|
187 | 0 | return rc; |
188 | 0 | } |
189 | | |
190 | | bool ogs_nnrf_nfm_send_nf_status_update( |
191 | | ogs_sbi_subscription_data_t *subscription_data) |
192 | 0 | { |
193 | 0 | bool rc; |
194 | 0 | ogs_sbi_request_t *request = NULL; |
195 | |
|
196 | 0 | ogs_assert(subscription_data); |
197 | | |
198 | 0 | request = ogs_nnrf_nfm_build_status_update(subscription_data); |
199 | 0 | if (!request) { |
200 | 0 | ogs_error("No Request"); |
201 | 0 | return false; |
202 | 0 | } |
203 | | |
204 | 0 | rc = ogs_sbi_send_request_to_nrf( |
205 | 0 | OpenAPI_service_name_nnrf_nfm, NULL, |
206 | 0 | ogs_sbi_client_handler, request, |
207 | 0 | OGS_UINT_TO_POINTER(subscription_data->pool_id)); |
208 | 0 | ogs_expect(rc == true); |
209 | |
|
210 | 0 | ogs_sbi_request_free(request); |
211 | |
|
212 | 0 | return rc; |
213 | 0 | } |
214 | | |
215 | | bool ogs_nnrf_nfm_send_nf_status_unsubscribe( |
216 | | ogs_sbi_subscription_data_t *subscription_data) |
217 | 0 | { |
218 | 0 | bool rc; |
219 | 0 | ogs_sbi_request_t *request = NULL; |
220 | |
|
221 | 0 | ogs_assert(subscription_data); |
222 | | |
223 | 0 | request = ogs_nnrf_nfm_build_status_unsubscribe(subscription_data); |
224 | 0 | if (!request) { |
225 | 0 | ogs_error("No Request"); |
226 | 0 | return false; |
227 | 0 | } |
228 | | |
229 | 0 | rc = ogs_sbi_send_request_to_nrf( |
230 | 0 | OpenAPI_service_name_nnrf_nfm, NULL, |
231 | 0 | ogs_sbi_client_handler, request, |
232 | 0 | OGS_UINT_TO_POINTER(subscription_data->pool_id)); |
233 | 0 | ogs_expect(rc == true); |
234 | |
|
235 | 0 | ogs_sbi_request_free(request); |
236 | |
|
237 | 0 | return rc; |
238 | 0 | } |
239 | | |
240 | | bool ogs_nnrf_nfm_send_nf_list_retrieve(void) |
241 | 0 | { |
242 | 0 | bool rc; |
243 | 0 | ogs_sbi_request_t *request = NULL; |
244 | |
|
245 | 0 | request = ogs_nnrf_nfm_build_nflist_retrieve(); |
246 | 0 | if (!request) { |
247 | 0 | ogs_error("No Request"); |
248 | 0 | return false; |
249 | 0 | } |
250 | | |
251 | 0 | rc = ogs_sbi_send_request_to_nrf( |
252 | 0 | OpenAPI_service_name_nnrf_nfm, NULL, |
253 | 0 | ogs_sbi_client_handler, request, ogs_sbi_self()->nf_instance); |
254 | 0 | ogs_expect(rc == true); |
255 | |
|
256 | 0 | ogs_sbi_request_free(request); |
257 | |
|
258 | 0 | return rc; |
259 | 0 | } |
260 | | |
261 | | bool ogs_nnrf_nfm_send_nf_profile_get(char *nf_instance_id) |
262 | 0 | { |
263 | 0 | bool rc; |
264 | 0 | ogs_sbi_request_t *request = NULL; |
265 | |
|
266 | 0 | request = ogs_nnrf_nfm_build_profile_retrieve(nf_instance_id); |
267 | 0 | if (!request) { |
268 | 0 | ogs_error("No Request"); |
269 | 0 | return false; |
270 | 0 | } |
271 | | |
272 | 0 | rc = ogs_sbi_send_request_to_nrf( |
273 | 0 | OpenAPI_service_name_nnrf_nfm, NULL, |
274 | 0 | ogs_sbi_client_handler, request, ogs_sbi_self()->nf_instance); |
275 | 0 | ogs_expect(rc == true); |
276 | |
|
277 | 0 | ogs_sbi_request_free(request); |
278 | |
|
279 | 0 | return rc; |
280 | 0 | } |