[SBI] Change the reference count (#1440)

Change the client's reference count method
to use the same method as nf_instance
This commit is contained in:
Sukchan Lee 2022-04-10 20:09:27 +09:00
parent 49c34605db
commit e5ff03b249
10 changed files with 48 additions and 41 deletions

View File

@ -82,6 +82,8 @@ void ogs_sbi_client_init(int num_of_sockinfo_pool, int num_of_connection_pool)
}
void ogs_sbi_client_final(void)
{
ogs_sbi_client_remove_all();
ogs_pool_final(&client_pool);
ogs_pool_final(&sockinfo_pool);
ogs_pool_final(&connection_pool);
@ -100,6 +102,7 @@ ogs_sbi_client_t *ogs_sbi_client_add(ogs_sockaddr_t *addr)
ogs_assert(client);
memset(client, 0, sizeof(ogs_sbi_client_t));
client->reference_count++;
ogs_trace("ogs_sbi_client_add()");
ogs_assert(OGS_OK == ogs_copyaddrinfo(&client->node.addr, addr));
@ -151,6 +154,14 @@ void ogs_sbi_client_remove(ogs_sbi_client_t *client)
ogs_pool_free(&client_pool, client);
}
void ogs_sbi_client_remove_all(void)
{
ogs_sbi_client_t *client = NULL, *next_client = NULL;
ogs_list_for_each_safe(&ogs_sbi_self()->client_list, next_client, client)
ogs_sbi_client_remove(client);
}
ogs_sbi_client_t *ogs_sbi_client_find(ogs_sockaddr_t *addr)
{
ogs_sbi_client_t *client = NULL;

View File

@ -28,14 +28,29 @@
extern "C" {
#endif
#define OGS_SETUP_SBI_CLIENT(__cTX, __pCLIENT) \
#define OGS_SBI_SETUP_CLIENT(__cTX, __pClient) \
do { \
ogs_assert((__cTX)); \
ogs_assert((__pCLIENT)); \
if ((__cTX)->client != __pCLIENT) \
__pCLIENT->reference_count++; \
(__cTX)->client = __pCLIENT; \
ogs_trace("client->reference_count = %d", __pCLIENT->reference_count); \
ogs_assert((__pClient)); \
\
if ((__cTX)->client) { \
ogs_sbi_client_t *client = NULL; \
ogs_sockaddr_t *addr = NULL; \
char buf[OGS_ADDRSTRLEN]; \
\
client = ((__cTX)->client); \
ogs_assert(client); \
addr = client->node.addr; \
ogs_assert(addr); \
ogs_warn("NF EndPoint updated [%s:%d]", \
OGS_ADDR(addr, buf), OGS_PORT(addr)); \
ogs_sbi_client_remove(client); \
} \
\
(__pClient)->reference_count++; \
((__cTX)->client) = (__pClient); \
ogs_trace("client->reference_count = %d", \
(__pClient)->reference_count); \
} while(0)
typedef int (*ogs_sbi_client_cb_f)(ogs_sbi_response_t *response, void *data);
@ -66,6 +81,7 @@ void ogs_sbi_client_final(void);
ogs_sbi_client_t *ogs_sbi_client_add(ogs_sockaddr_t *addr);
void ogs_sbi_client_remove(ogs_sbi_client_t *client);
void ogs_sbi_client_remove_all(void);
ogs_sbi_client_t *ogs_sbi_client_find(ogs_sockaddr_t *addr);
bool ogs_sbi_client_send_request(

View File

@ -474,7 +474,7 @@ int ogs_sbi_context_parse_config(const char *local, const char *remote)
ogs_sbi_self()->nf_instance_id);
ogs_assert(nf_instance);
OGS_SETUP_SBI_CLIENT(nf_instance, client);
OGS_SBI_SETUP_CLIENT(nf_instance, client);
if (key) client->tls.key = key;
if (pem) client->tls.pem = pem;
@ -947,7 +947,7 @@ ogs_sbi_nf_service_t *ogs_sbi_nf_service_build_default(
(client->tls.key && client->tls.pem) ?
OpenAPI_uri_scheme_https : OpenAPI_uri_scheme_http);
ogs_assert(nf_service);
OGS_SETUP_SBI_CLIENT(nf_service, client);
OGS_SBI_SETUP_CLIENT(nf_service, client);
hostname = NULL;
ogs_list_for_each(&ogs_sbi_self()->server_list, server) {
@ -1073,13 +1073,8 @@ static void nf_service_associate_client(ogs_sbi_nf_service_t *nf_service)
}
}
if (client) {
if (nf_service->client && nf_service->client != client) {
ogs_warn("NF EndPoint updated [%s]", nf_service->id);
ogs_sbi_client_remove(nf_service->client);
}
OGS_SETUP_SBI_CLIENT(nf_service, client);
}
if (client)
OGS_SBI_SETUP_CLIENT(nf_service, client);
}
static void nf_service_associate_client_all(ogs_sbi_nf_instance_t *nf_instance)
@ -1131,12 +1126,7 @@ bool ogs_sbi_client_associate(ogs_sbi_nf_instance_t *nf_instance)
client = nf_instance_find_client(nf_instance);
if (!client) return false;
if (nf_instance->client && nf_instance->client != client) {
ogs_warn("NF EndPoint updated [%s]", nf_instance->id);
ogs_sbi_client_remove(nf_instance->client);
}
OGS_SETUP_SBI_CLIENT(nf_instance, client);
OGS_SBI_SETUP_CLIENT(nf_instance, client);
nf_service_associate_client_all(nf_instance);

View File

@ -163,7 +163,7 @@ bool ogs_nnrf_nfm_send_nf_status_subscribe(ogs_sbi_client_t *client,
subscription = ogs_sbi_subscription_add();
ogs_assert(subscription);
OGS_SETUP_SBI_CLIENT(subscription, client);
OGS_SBI_SETUP_CLIENT(subscription, client);
subscription->req_nf_type = req_nf_type;
if (req_nf_instance_id) {
subscription->req_nf_instance_id = ogs_strdup(req_nf_instance_id);

View File

@ -245,7 +245,7 @@ int amf_namf_comm_handle_n1_n2_message_transfer(
client = ogs_sbi_client_add(addr);
ogs_assert(client);
}
OGS_SETUP_SBI_CLIENT(&sess->paging, client);
OGS_SBI_SETUP_CLIENT(&sess->paging, client);
ogs_freeaddrinfo(addr);

View File

@ -94,11 +94,7 @@ int amf_nnssf_nsselection_handle_get(
ogs_assert(client);
}
if (sess->nssf.nrf.client && sess->nssf.nrf.client != client) {
ogs_warn("NSSF NRF URI Updated [%s]", sess->nssf.nrf.id);
ogs_sbi_client_remove(sess->nssf.nrf.client);
}
OGS_SETUP_SBI_CLIENT(&sess->nssf.nrf, client);
OGS_SBI_SETUP_CLIENT(&sess->nssf.nrf, client);
ogs_freeaddrinfo(addr);

View File

@ -245,7 +245,7 @@ bool nrf_nnrf_handle_nf_status_subscribe(
client = ogs_sbi_client_add(addr);
ogs_assert(client);
}
OGS_SETUP_SBI_CLIENT(subscription, client);
OGS_SBI_SETUP_CLIENT(subscription, client);
ogs_freeaddrinfo(addr);

View File

@ -90,7 +90,7 @@ bool pcf_npcf_am_policy_contrtol_handle_create(pcf_ue_t *pcf_ue,
client = ogs_sbi_client_add(addr);
ogs_assert(client);
}
OGS_SETUP_SBI_CLIENT(&pcf_ue->namf, client);
OGS_SBI_SETUP_CLIENT(&pcf_ue->namf, client);
ogs_freeaddrinfo(addr);
@ -274,7 +274,7 @@ bool pcf_npcf_smpolicycontrol_handle_create(pcf_sess_t *sess,
client = ogs_sbi_client_add(addr);
ogs_assert(client);
}
OGS_SETUP_SBI_CLIENT(&sess->nsmf, client);
OGS_SBI_SETUP_CLIENT(&sess->nsmf, client);
ogs_freeaddrinfo(addr);
@ -562,7 +562,7 @@ bool pcf_npcf_policyauthorization_handle_create(pcf_sess_t *sess,
client = ogs_sbi_client_add(addr);
ogs_assert(client);
}
OGS_SETUP_SBI_CLIENT(&app_session->naf, client);
OGS_SBI_SETUP_CLIENT(&app_session->naf, client);
ogs_freeaddrinfo(addr);

View File

@ -181,7 +181,7 @@ bool smf_nsmf_handle_create_sm_context(
client = ogs_sbi_client_add(addr);
ogs_assert(client);
}
OGS_SETUP_SBI_CLIENT(&sess->namf, client);
OGS_SBI_SETUP_CLIENT(&sess->namf, client);
ogs_freeaddrinfo(addr);

View File

@ -326,12 +326,6 @@ void af_sess_associate_pcf_client(af_sess_t *sess)
}
}
if (client) {
if (sess->pcf.client && sess->pcf.client != client) {
ogs_warn("PCF EndPoint updated");
ogs_sbi_client_remove(sess->pcf.client);
}
OGS_SETUP_SBI_CLIENT(&sess->pcf, client);
}
if (client)
OGS_SBI_SETUP_CLIENT(&sess->pcf, client);
}