Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions examples/emulator/agent/sm_rc.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,16 +477,16 @@ sm_ag_if_ans_t write_ctrl_rc_sm(void const* data)
}

static
uint32_t *ric_req_id_list = NULL;
ric_gen_id_t *ric_id_list = NULL;
static
size_t sz_ric_req_id = 0;

static
void free_aperiodic_subscription(uint32_t ric_req_id)
void free_aperiodic_subscription(ric_gen_id_t ric_id)
{
for (size_t i = 0; i < sz_ric_req_id; i++) {
if (ric_req_id == ric_req_id_list[i])
(void)ric_req_id_list[i];
if (eq_ric_gen_id(&ric_id, &ric_id_list[i]))
(void)ric_id_list[i];
}
}

Expand All @@ -502,8 +502,9 @@ void* emulate_ric_ind(void* ptr)
d->hdr = fill_rnd_rc_ind_hdr();
d->msg = fill_rnd_rc_ind_msg();

async_event_agent_api(ric_req_id_list[j], d);
printf("Event for RIC Req ID %u generated\n", ric_req_id_list[j]);
async_event_agent_api(ric_id_list[j], d);
printf("Event for RAN_FUNC_ID %d RIC_REQ_ID %d INST_ID %d generated\n",
ric_id_list[j].ran_func_id, ric_id_list[j].ric_req_id, ric_id_list[j].ric_inst_id);
}
}

Expand All @@ -519,8 +520,8 @@ sm_ag_if_ans_t write_subs_rc_sm(void const* src)

wr_rc_sub_data_t* wr_rc = (wr_rc_sub_data_t*)src;

ric_req_id_list = realloc(ric_req_id_list, (sz_ric_req_id + 1) * sizeof(uint32_t));
(ric_req_id_list)[sz_ric_req_id] = wr_rc->ric_req_id;
ric_id_list = realloc(ric_id_list, (sz_ric_req_id + 1) * sizeof(ric_gen_id_t));
(ric_id_list)[sz_ric_req_id] = wr_rc->ric_id;
(sz_ric_req_id)++;

int rc = pthread_create(&t_ran_ctrl, NULL, emulate_ric_ind, NULL);
Expand Down
45 changes: 38 additions & 7 deletions src/agent/e2_agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,18 +503,44 @@ void e2_free_agent(e2_agent_t* ag)
free(ag);
}

void e2_async_event_agent(e2_agent_t* ag, uint32_t ric_req_id, void* ind_data)
// Nothing is subscribed under this RIC ID. Discard the payload rather than abort:
// the RAN owns no free function for it, so hand it to the RAN function's own SM,
// which frees it on the way out of on_indication, and throw the encoded buffers away.
static
void drop_orphan_aind(e2_agent_t* ag, ric_gen_id_t ric_id, void* ind_data)
{
printf("[E2 AGENT]: no subscription for RAN_FUNC_ID %d RIC_REQ_ID %d INST_ID %d, dropping indication\n",
ric_id.ran_func_id, ric_id.ric_req_id, ric_id.ric_inst_id);

sm_agent_t* sm = sm_plugin_ag(&ag->plugin, ric_id.ran_func_id);
if(sm == NULL){
printf("[E2 AGENT]: RAN_FUNC_ID %d has no service model either, leaking the indication data\n",
ric_id.ran_func_id);
return;
}

exp_ind_data_t exp = sm->proc.on_indication(sm, ind_data);
if(exp.has_value == true){
free(exp.data.ind_hdr);
free(exp.data.ind_msg);
free(exp.data.call_process_id);
}
}

void e2_async_event_agent(e2_agent_t* ag, ric_gen_id_t ric_id, void* ind_data)
{
assert(ag != NULL);

void* f = NULL;
void* l = NULL;
void* it = NULL;

ind_event_t tmp = {.ric_id.ric_req_id = ric_req_id,
.sm = NULL,
.action_id = 0 };

// Match the whole RIC ID. The Requestor ID alone does not identify a subscription
// -- E2AP identifies one by {RequestorID, InstanceID}, and an xApp may reuse a
// Requestor ID across RAN functions -- so ag->ind_event legitimately holds several
// entries sharing it. Keying on it alone hands the indication to whichever entry
// cmp_ric_gen_id happens to order first, and a service model that is given another
// one's ind_data aborts the RAN process.
assoc_rb_tree_t* tree = &ag->ind_event.right;

for(size_t i =0; i < 10; ++i){
Expand All @@ -523,7 +549,7 @@ void e2_async_event_agent(e2_agent_t* ag, uint32_t ric_req_id, void* ind_data)

f = assoc_rb_tree_front(tree);
l = assoc_rb_tree_end(tree);
it = find_if_rb_tree(tree, f, l, &tmp, eq_ind_event_ric_req_id);
it = find_if_rb_tree(tree, f, l, &ric_id, eq_ind_event);
if(it != l) break;

rc = pthread_mutex_unlock(&ag->mtx_ind_event);
Expand All @@ -534,7 +560,12 @@ void e2_async_event_agent(e2_agent_t* ag, uint32_t ric_req_id, void* ind_data)
usleep(10);
}

assert(it != l && "Not found RIC Request ID");
// The loop breaks while still holding the lock on success and releases it at the
// end of every failing iteration, so here the mutex is already unlocked.
if(it == l){
drop_orphan_aind(ag, ric_id, ind_data);
return;
}

ind_event_t* ind_ev = assoc_rb_tree_key(tree, it);

Expand Down
2 changes: 1 addition & 1 deletion src/agent/e2_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void e2_start_agent(e2_agent_t* ag);

void e2_free_agent(e2_agent_t* ag);

void e2_async_event_agent(e2_agent_t* ag, uint32_t ric_req_id, void* ind_data);
void e2_async_event_agent(e2_agent_t* ag, ric_gen_id_t ric_id, void* ind_data);

///////////////////////////////////////////////
// E2AP AGENT FUNCTIONAL PROCEDURES MESSAGES //
Expand Down
4 changes: 2 additions & 2 deletions src/agent/e2_agent_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ void stop_agent_api(void)
assert(rc == 0);
}

void async_event_agent_api(uint32_t ric_req_id, void* ind_data)
void async_event_agent_api(ric_gen_id_t ric_id, void* ind_data)
{
assert(agent != NULL);
e2_async_event_agent(agent, ric_req_id, ind_data);
e2_async_event_agent(agent, ric_id, ind_data);
}

5 changes: 4 additions & 1 deletion src/agent/e2_agent_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef E2_AGENT_API_MOSAIC_H
#define E2_AGENT_API_MOSAIC_H

#include "../lib/e2ap/ric_gen_id_wrapper.h"
#include "../sm/sm_io.h"
#include "../util/conf_file.h"
#include "../util/ngran_types.h"
Expand All @@ -20,7 +21,9 @@ void init_agent_api(int mcc,

void stop_agent_api(void);

void async_event_agent_api(uint32_t ric_req_id, void* ind_data);
// ric_id must be the full RIC ID of the subscription the indication answers:
// the Requestor ID alone does not identify one (see e2_async_event_agent).
void async_event_agent_api(ric_gen_id_t ric_id, void* ind_data);

#endif

7 changes: 6 additions & 1 deletion src/agent/endpoint_agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ void init_sctp_conn_client(e2ap_ep_ag_t* ep, const char* addr, int port)
int rc = inet_pton(AF_INET, addr, &servaddr.sin_addr);
assert(rc == 1);

// Association events report a nearRT-RIC that went away without a SHUTDOWN
// (SCTP_COMM_LOST) or came back under the same addresses (SCTP_RESTART).
// Subscribe to nothing else: cp_sctp_notification asserts on the types it
// does not decode.
struct sctp_event_subscribe evnts = { .sctp_data_io_event = 1,
.sctp_shutdown_event = 1};
.sctp_association_event = 1,
.sctp_shutdown_event = 1};

rc = setsockopt(sock_fd, IPPROTO_SCTP, SCTP_EVENTS, &evnts, sizeof (evnts));
assert(rc == 0);
Expand Down
Loading
Loading