/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, subscription_data); |
134 | 0 | ogs_expect(rc == true); |
135 | |
|
136 | 0 | ogs_sbi_request_free(request); |
137 | |
|
138 | 0 | if (rc != true) |
139 | 0 | ogs_sbi_subscription_data_remove(subscription_data); |
140 | |
|
141 | 0 | return rc; |
142 | 0 | } |
143 | | |
144 | | bool ogs_nnrf_nfm_send_nf_status_subscribe_renew( |
145 | | ogs_sbi_subscription_data_t *subscription_data) |
146 | 0 | { |
147 | 0 | char *req_nf_instance_id = NULL; |
148 | 0 | OpenAPI_service_name_e subscr_cond_service_name = OpenAPI_service_name_NULL; |
149 | 0 | OpenAPI_nf_type_e req_nf_type; |
150 | 0 | OpenAPI_nf_type_e subscr_cond_nf_type; |
151 | 0 | bool rc; |
152 | |
|
153 | 0 | ogs_assert(subscription_data); |
154 | | |
155 | | /* |
156 | | * The old subscription still occupies subscription_data_pool here. |
157 | | * Keep local copies of the fields needed to rebuild the request, |
158 | | * remove the old subscription first so the pool has a free slot, |
159 | | * then resubscribe. Without this, a full pool would make renewal |
160 | | * fail forever even though the renewal itself does not change the |
161 | | * net occupancy. |
162 | | */ |
163 | 0 | req_nf_type = subscription_data->req_nf_type; |
164 | 0 | subscr_cond_nf_type = subscription_data->subscr_cond.nf_type; |
165 | |
|
166 | 0 | if (subscription_data->req_nf_instance_id) { |
167 | 0 | req_nf_instance_id = |
168 | 0 | ogs_strdup(subscription_data->req_nf_instance_id); |
169 | 0 | ogs_assert(req_nf_instance_id); |
170 | 0 | } |
171 | | |
172 | 0 | if (subscription_data->subscr_cond.service_name) |
173 | 0 | subscr_cond_service_name = subscription_data->subscr_cond.service_name; |
174 | |
|
175 | 0 | ogs_sbi_subscription_data_remove(subscription_data); |
176 | | /* subscription_data is invalid past this point */ |
177 | |
|
178 | 0 | rc = ogs_nnrf_nfm_send_nf_status_subscribe( |
179 | 0 | req_nf_type, req_nf_instance_id, |
180 | 0 | subscr_cond_nf_type, subscr_cond_service_name); |
181 | 0 | if (rc != true) |
182 | 0 | ogs_error("NF status subscription renewal failed"); |
183 | |
|
184 | 0 | ogs_free(req_nf_instance_id); |
185 | |
|
186 | 0 | return rc; |
187 | 0 | } |
188 | | |
189 | | bool ogs_nnrf_nfm_send_nf_status_update( |
190 | | ogs_sbi_subscription_data_t *subscription_data) |
191 | 0 | { |
192 | 0 | bool rc; |
193 | 0 | ogs_sbi_request_t *request = NULL; |
194 | |
|
195 | 0 | ogs_assert(subscription_data); |
196 | | |
197 | 0 | request = ogs_nnrf_nfm_build_status_update(subscription_data); |
198 | 0 | if (!request) { |
199 | 0 | ogs_error("No Request"); |
200 | 0 | return false; |
201 | 0 | } |
202 | | |
203 | 0 | rc = ogs_sbi_send_request_to_nrf( |
204 | 0 | OpenAPI_service_name_nnrf_nfm, NULL, |
205 | 0 | ogs_sbi_client_handler, request, subscription_data); |
206 | 0 | ogs_expect(rc == true); |
207 | |
|
208 | 0 | ogs_sbi_request_free(request); |
209 | |
|
210 | 0 | return rc; |
211 | 0 | } |
212 | | |
213 | | bool ogs_nnrf_nfm_send_nf_status_unsubscribe( |
214 | | ogs_sbi_subscription_data_t *subscription_data) |
215 | 0 | { |
216 | 0 | bool rc; |
217 | 0 | ogs_sbi_request_t *request = NULL; |
218 | |
|
219 | 0 | ogs_assert(subscription_data); |
220 | | |
221 | 0 | request = ogs_nnrf_nfm_build_status_unsubscribe(subscription_data); |
222 | 0 | if (!request) { |
223 | 0 | ogs_error("No Request"); |
224 | 0 | return false; |
225 | 0 | } |
226 | | |
227 | 0 | rc = ogs_sbi_send_request_to_nrf( |
228 | 0 | OpenAPI_service_name_nnrf_nfm, NULL, |
229 | 0 | ogs_sbi_client_handler, request, subscription_data); |
230 | 0 | ogs_expect(rc == true); |
231 | |
|
232 | 0 | ogs_sbi_request_free(request); |
233 | |
|
234 | 0 | return rc; |
235 | 0 | } |
236 | | |
237 | | bool ogs_nnrf_nfm_send_nf_list_retrieve(void) |
238 | 0 | { |
239 | 0 | bool rc; |
240 | 0 | ogs_sbi_request_t *request = NULL; |
241 | |
|
242 | 0 | request = ogs_nnrf_nfm_build_nflist_retrieve(); |
243 | 0 | if (!request) { |
244 | 0 | ogs_error("No Request"); |
245 | 0 | return false; |
246 | 0 | } |
247 | | |
248 | 0 | rc = ogs_sbi_send_request_to_nrf( |
249 | 0 | OpenAPI_service_name_nnrf_nfm, NULL, |
250 | 0 | ogs_sbi_client_handler, request, ogs_sbi_self()->nf_instance); |
251 | 0 | ogs_expect(rc == true); |
252 | |
|
253 | 0 | ogs_sbi_request_free(request); |
254 | |
|
255 | 0 | return rc; |
256 | 0 | } |
257 | | |
258 | | bool ogs_nnrf_nfm_send_nf_profile_get(char *nf_instance_id) |
259 | 0 | { |
260 | 0 | bool rc; |
261 | 0 | ogs_sbi_request_t *request = NULL; |
262 | |
|
263 | 0 | request = ogs_nnrf_nfm_build_profile_retrieve(nf_instance_id); |
264 | 0 | if (!request) { |
265 | 0 | ogs_error("No Request"); |
266 | 0 | return false; |
267 | 0 | } |
268 | | |
269 | 0 | rc = ogs_sbi_send_request_to_nrf( |
270 | 0 | OpenAPI_service_name_nnrf_nfm, NULL, |
271 | 0 | ogs_sbi_client_handler, request, ogs_sbi_self()->nf_instance); |
272 | 0 | ogs_expect(rc == true); |
273 | |
|
274 | 0 | ogs_sbi_request_free(request); |
275 | |
|
276 | 0 | return rc; |
277 | 0 | } |