File size: 4,734 Bytes
258fb37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
 * Copyright (C) 2022-2023 by Sukchan Lee <acetcom@gmail.com>
 *
 * This file is part of Open5GS.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#include "ogs-sbi.h"

bool ogs_nnrf_nfm_send_nf_register(ogs_sbi_nf_instance_t *nf_instance)
{
    bool rc;
    ogs_sbi_request_t *request = NULL;

    ogs_assert(nf_instance);

    request = ogs_nnrf_nfm_build_register();
    if (!request) {
        ogs_error("No Request");
        return false;
    }

    rc = ogs_sbi_send_notification_request(
            OGS_SBI_SERVICE_TYPE_NNRF_NFM, NULL, request, nf_instance);
    ogs_expect(rc == true);

    ogs_sbi_request_free(request);

    return rc;
}

bool ogs_nnrf_nfm_send_nf_update(ogs_sbi_nf_instance_t *nf_instance)
{
    bool rc;
    ogs_sbi_request_t *request = NULL;

    ogs_assert(nf_instance);

    request = ogs_nnrf_nfm_build_update();
    if (!request) {
        ogs_error("No Request");
        return false;
    }

    rc = ogs_sbi_send_notification_request(
            OGS_SBI_SERVICE_TYPE_NNRF_NFM, NULL, request, nf_instance);
    ogs_expect(rc == true);

    ogs_sbi_request_free(request);

    return rc;
}

bool ogs_nnrf_nfm_send_nf_de_register(ogs_sbi_nf_instance_t *nf_instance)
{
    bool rc;
    ogs_sbi_request_t *request = NULL;

    ogs_assert(nf_instance);

    request = ogs_nnrf_nfm_build_de_register();
    if (!request) {
        ogs_error("No Request");
        return false;
    }

    rc = ogs_sbi_send_notification_request(
            OGS_SBI_SERVICE_TYPE_NNRF_NFM, NULL, request, nf_instance);
    ogs_expect(rc == true);

    ogs_sbi_request_free(request);

    return rc;
}

bool ogs_nnrf_nfm_send_nf_status_subscribe(
        OpenAPI_nf_type_e req_nf_type, char *req_nf_instance_id,
        OpenAPI_nf_type_e subscr_cond_nf_type,
        char *subscr_cond_service_name)
{
    bool rc;
    ogs_sbi_request_t *request = NULL;
    ogs_sbi_subscription_data_t *subscription_data = NULL;

    /* Issue #2630 : The format of subscrCond is invalid. Must be 'oneOf'. */
    ogs_assert(!subscr_cond_nf_type || !subscr_cond_service_name);

    subscription_data = ogs_sbi_subscription_data_add();
    ogs_assert(subscription_data);

    subscription_data->req_nf_type = req_nf_type;
    if (req_nf_instance_id)
        subscription_data->req_nf_instance_id = ogs_strdup(req_nf_instance_id);

    if (subscr_cond_nf_type)
        subscription_data->subscr_cond.nf_type = subscr_cond_nf_type;
    else if (subscr_cond_service_name)
        subscription_data->subscr_cond.service_name =
            ogs_strdup(subscr_cond_service_name);
    else {
        ogs_fatal("SubscrCond must be 'oneOf'.");
        ogs_assert_if_reached();
    }

    request = ogs_nnrf_nfm_build_status_subscribe(subscription_data);
    if (!request) {
        ogs_error("No Request");
        return false;
    }

    rc = ogs_sbi_send_notification_request(
            OGS_SBI_SERVICE_TYPE_NNRF_NFM, NULL, request, subscription_data);
    ogs_expect(rc == true);

    ogs_sbi_request_free(request);

    return rc;
}

bool ogs_nnrf_nfm_send_nf_status_update(
        ogs_sbi_subscription_data_t *subscription_data)
{
    bool rc;
    ogs_sbi_request_t *request = NULL;

    ogs_assert(subscription_data);

    request = ogs_nnrf_nfm_build_status_update(subscription_data);
    if (!request) {
        ogs_error("No Request");
        return false;
    }

    rc = ogs_sbi_send_notification_request(
            OGS_SBI_SERVICE_TYPE_NNRF_NFM, NULL, request, subscription_data);
    ogs_expect(rc == true);

    ogs_sbi_request_free(request);

    return rc;
}

bool ogs_nnrf_nfm_send_nf_status_unsubscribe(
        ogs_sbi_subscription_data_t *subscription_data)
{
    bool rc;
    ogs_sbi_request_t *request = NULL;

    ogs_assert(subscription_data);

    request = ogs_nnrf_nfm_build_status_unsubscribe(subscription_data);
    if (!request) {
        ogs_error("No Request");
        return false;
    }

    rc = ogs_sbi_send_notification_request(
            OGS_SBI_SERVICE_TYPE_NNRF_NFM, NULL, request, subscription_data);
    ogs_expect(rc == true);

    ogs_sbi_request_free(request);

    return rc;
}