File size: 2,914 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
/*
 * Copyright (C) 2019,2020 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 "sbi-path.h"
#include "nnrf-handler.h"
#include "nnssf-handler.h"

bool nssf_nnrf_nsselection_handle_get(
        ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg)
{
    int status = OGS_SBI_HTTP_STATUS_OK;
    char *strerror = NULL;

    OpenAPI_authorized_network_slice_info_t AuthorizedNetworkSliceInfo;
    OpenAPI_nsi_information_t NsiInformation;

    nssf_nsi_t *nsi = NULL;

    ogs_sbi_message_t sendmsg;
    ogs_sbi_response_t *response = NULL;

    ogs_assert(stream);
    ogs_assert(recvmsg);

    if (!recvmsg->param.nf_id) {
        status = OGS_SBI_HTTP_STATUS_BAD_REQUEST;
        strerror = ogs_msprintf("No nf-id");
        goto cleanup;
    }

    if (!recvmsg->param.nf_type) {
        status = OGS_SBI_HTTP_STATUS_BAD_REQUEST;
        strerror = ogs_msprintf("No nf-type");
        goto cleanup;
    }

    if (!recvmsg->param.slice_info_request_for_pdu_session_presence) {
        status = OGS_SBI_HTTP_STATUS_BAD_REQUEST;
        strerror = ogs_msprintf("Not implemented except PDU session");
        goto cleanup;
    }

    nsi = nssf_nsi_find_by_s_nssai(&recvmsg->param.s_nssai);
    if (!nsi) {
        status = OGS_SBI_HTTP_STATUS_FORBIDDEN;
        strerror = ogs_msprintf("Cannot find NSI by S-NSSAI[SST:%d SD:0x%x]",
            recvmsg->param.s_nssai.sst, recvmsg->param.s_nssai.sd.v);
        goto cleanup;
    }

    memset(&NsiInformation, 0, sizeof(NsiInformation));
    NsiInformation.nrf_id = nsi->nrf_id;
    NsiInformation.nsi_id = nsi->nsi_id;

    memset(&AuthorizedNetworkSliceInfo, 0, sizeof(AuthorizedNetworkSliceInfo));
    AuthorizedNetworkSliceInfo.nsi_information = &NsiInformation;

    memset(&sendmsg, 0, sizeof(sendmsg));
    sendmsg.AuthorizedNetworkSliceInfo = &AuthorizedNetworkSliceInfo;

    response = ogs_sbi_build_response(&sendmsg, OGS_SBI_HTTP_STATUS_OK);
    ogs_assert(response);
    ogs_assert(true == ogs_sbi_server_send_response(stream, response));

    return true;

cleanup:
    ogs_assert(strerror);

    ogs_error("%s", strerror);
    ogs_sbi_server_send_error(stream, status, recvmsg, strerror, NULL,
            NULL);
    ogs_free(strerror);

    return false;
}