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
12 changes: 12 additions & 0 deletions src/agent/e2_agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,3 +619,15 @@ void e2_send_control_failure(e2_agent_t* ag, const ric_control_failure_t* cf)
free_byte_array(ba);
}

void e2_send_ric_service_update(e2_agent_t* ag, const ric_service_update_t* su)
{
assert(ag != NULL);
assert(su != NULL);

e2ap_msg_t msg = {.type = RIC_SERVICE_UPDATE};
msg.u_msgs.ric_serv_updt = *su;

byte_array_t ba = e2ap_msg_enc_ag(&ag->ap, &msg);
e2ap_send_bytes_agent(&ag->ep, ba);
free_byte_array(ba);
}
2 changes: 2 additions & 0 deletions src/agent/e2_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ void e2_send_control_acknowledge(e2_agent_t* ag, const ric_control_acknowledge_t

void e2_send_control_failure(e2_agent_t* ag, const ric_control_failure_t* cf);

void e2_send_ric_service_update(e2_agent_t* ag, const ric_service_update_t* su);

////////////////////////////////////////////////

#undef NUM_HANDLE_MSG
Expand Down
48 changes: 48 additions & 0 deletions src/agent/e2_agent_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <assert.h> // for assert
#include <pthread.h> // for pthread_cr...
#include <stdatomic.h>
#include <string.h> // for strdup, strlen
#include <stdlib.h>
#include <stdio.h> // for NULL
#include "e2_agent.h" // for e2_free_agent
Expand Down Expand Up @@ -112,3 +114,49 @@ void async_event_agent_api(uint32_t ric_req_id, void* ind_data)
e2_async_event_agent(agent, ric_req_id, ind_data);
}

/* Re-advertise one RAN function to the RIC with a bumped revision.
*
* A service model whose RAN function definition changes at runtime -- because
* what it exposes depends on state the RAN learns after E2 SETUP -- has no way
* to tell the RIC without this: E2 SETUP happens once. The revision is
* per-call and monotonic, which is what makes the RIC replace the stored
* definition rather than reject it as a duplicate. */
void trigger_ric_service_update_api(uint16_t ran_func_id)
{
if (agent == NULL) {
printf("[E2 AGENT]: not initialised yet, skipping RIC Service Update\n");
return;
}

sm_agent_t* sm = sm_plugin_ag(&agent->plugin, ran_func_id);
if (sm == NULL) {
printf("[E2 AGENT]: no service model for RAN function %u, cannot send RIC Service Update\n", ran_func_id);
return;
}

static _Atomic uint16_t service_update_rev = 1;

sm_e2_setup_data_t setup = sm->proc.on_e2_setup(sm);

ric_service_update_t su = {0};
su.trans_id = (uint8_t)(atomic_load(&service_update_rev) % 256);

su.len_modified = 1;
su.modified = calloc(1, sizeof(ran_function_t));
assert(su.modified != NULL && "Memory exhausted");

su.modified[0].id = sm->info.id();
su.modified[0].rev = atomic_fetch_add(&service_update_rev, 1);
su.modified[0].defn.buf = setup.ran_fun_def;
su.modified[0].defn.len = setup.len_rfd;

const char* oid = sm->info.oid();
su.modified[0].oid.buf = (uint8_t*)strdup(oid);
su.modified[0].oid.len = strlen(oid);

e2_send_ric_service_update(agent, &su);

free(su.modified[0].defn.buf);
free(su.modified[0].oid.buf);
free(su.modified);
}
3 changes: 3 additions & 0 deletions src/agent/e2_agent_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "../sm/sm_io.h"
#include "../util/conf_file.h"
#include "../util/ngran_types.h"
#include <stdint.h>

void init_agent_api(int mcc,
int mnc,
Expand All @@ -22,5 +23,7 @@ void stop_agent_api(void);

void async_event_agent_api(uint32_t ric_req_id, void* ind_data);

void trigger_ric_service_update_api(uint16_t ran_func_id);

#endif

11 changes: 10 additions & 1 deletion src/agent/msg_handler_agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,16 @@ e2ap_msg_t e2ap_handle_service_update_ack_agent(e2_agent_t* ag, const e2ap_msg_t
{
assert(ag != NULL);
assert(msg != NULL);
assert(0!=0 && "Not implemented");
assert(msg->type == RIC_SERVICE_UPDATE_ACKNOWLEDGE);

const ric_service_update_ack_t* ack = &msg->u_msgs.ric_serv_updt_ack;
printf("[E2-AGENT]: RIC SERVICE UPDATE ACKNOWLEDGE rx (accepted=%zu, rejected=%zu)\n",
ack->len_accepted, ack->len_rejected);

for (size_t i = 0; i < ack->len_rejected; ++i) {
printf("[E2-AGENT]: RAN function %d REJECTED by the RIC, cause group %d\n",
ack->rejected[i].id, ack->rejected[i].cause.present);
}

e2ap_msg_t ans = {.type = NONE_E2_MSG_TYPE};
return ans;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/e2ap/v1_01/e2ap_types/ric_service_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bool eq_ric_service_update(const ric_service_update_t* m0, const ric_service_upd
return false;

for(size_t i = 0; i < m0->len_modified; ++i){
if(eq_ran_function(&m0->modified[i], &m1->modified[i]))
if(eq_ran_function(&m0->modified[i], &m1->modified[i]) == false)
return false;
}

Expand Down
3 changes: 3 additions & 0 deletions src/lib/e2ap/v1_01/e2ap_types/ric_service_update.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "common/e2ap_ran_function.h"
#include "common/e2ap_ran_function_id_rev.h"
#include "common/e2ap_global_node_id.h"

typedef struct {

Expand All @@ -20,6 +21,8 @@ typedef struct {

e2ap_ran_function_id_rev_t* deleted;
size_t len_deleted;

global_e2_node_id_t e2_node_id;
} ric_service_update_t;

bool eq_ric_service_update(const ric_service_update_t* m0, const ric_service_update_t* m1);
Expand Down
2 changes: 2 additions & 0 deletions src/lib/e2ap/v1_01/free/e2ap_msg_free.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ void e2ap_free_service_update(ric_service_update_t* su)
free(su->modified);

free(su->deleted);

free_global_e2_node_id(&su->e2_node_id);
}

// RIC -> E2
Expand Down
101 changes: 45 additions & 56 deletions src/lib/e2ap/v2_03/dec/e2ap_msg_dec_asn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1990,8 +1990,6 @@ e2ap_msg_t e2ap_dec_service_update(const E2AP_PDU_t* pdu)
{
assert(pdu != NULL);

assert(0!=0 && "Untested code");

e2ap_msg_t ret = {.type = RIC_SERVICE_UPDATE};
ric_service_update_t* su = &ret.u_msgs.ric_serv_updt;

Expand All @@ -2002,63 +2000,56 @@ e2ap_msg_t e2ap_dec_service_update(const E2AP_PDU_t* pdu)
assert(pdu->choice.initiatingMessage->value.present == InitiatingMessage__value_PR_RICserviceUpdate);

const RICserviceUpdate_t *out = &pdu->choice.initiatingMessage->value.choice.RICserviceUpdate;
assert(out->protocolIEs.list.count >= 1);

// TransactionID. Mandatory
// TransactionID. Mandatory (first IE)
const RICserviceUpdate_IEs_t* trans_id = out->protocolIEs.list.array[0];
assert(trans_id->id == ProtocolIE_ID_id_TransactionID);
assert(trans_id->criticality == Criticality_reject);
assert(trans_id->value.present == RICserviceUpdate_IEs__value_PR_TransactionID);
su->trans_id = trans_id->value.choice.TransactionID;

// List of RAN Functions Added
const RICserviceUpdate_IEs_t* ran_add = out->protocolIEs.list.array[1];
assert(ran_add->id == ProtocolIE_ID_id_RANfunctionsAdded);
assert(ran_add->criticality == Criticality_reject);
assert(ran_add->value.present == RICserviceUpdate_IEs__value_PR_RANfunctions_List);
const int sz_add = ran_add->value.choice.RANfunctions_List.list.count;
su->added = calloc(sz_add, sizeof(ran_function_t));
su->len_added = sz_add;
for(int i = 0; i < sz_add; ++i){
const RANfunction_ItemIEs_t* r = (const RANfunction_ItemIEs_t*)ran_add->value.choice.RANfunctions_List.list.array[i];
assert(r->id == ProtocolIE_ID_id_RANfunction_Item);
assert(r->criticality == Criticality_reject);
assert(r->value.present == RANfunction_ItemIEs__value_PR_RANfunction_Item);
su->added[i] = copy_ran_function(&r->value.choice.RANfunction_Item);
}

// List of RAN Functions Modified
const RICserviceUpdate_IEs_t* ran_mod = out->protocolIEs.list.array[2];
assert(ran_mod->id == ProtocolIE_ID_id_RANfunctionsModified);
assert(ran_mod->criticality == Criticality_reject);
assert(ran_mod->value.present == RICserviceUpdate_IEs__value_PR_RANfunctions_List);

const int sz_mod = ran_mod->value.choice.RANfunctions_List.list.count;
su->modified = calloc(sz_mod, sizeof(ran_function_t));
su->len_modified = sz_mod;
for(int i = 0; i < sz_mod; ++i){
const RANfunction_ItemIEs_t* r = (const RANfunction_ItemIEs_t*)ran_mod->value.choice.RANfunctions_List.list.array[i];
assert(r->id == ProtocolIE_ID_id_RANfunction_Item);
assert(r->criticality == Criticality_reject);
assert(r->value.present == RANfunction_ItemIEs__value_PR_RANfunction_Item);
su->modified[i] = copy_ran_function(&r->value.choice.RANfunction_Item);
// Remaining IEs are optional — iterate by ID
for (int elm = 1; elm < out->protocolIEs.list.count; ++elm) {
const RICserviceUpdate_IEs_t* ie = out->protocolIEs.list.array[elm];

if (ie->id == ProtocolIE_ID_id_RANfunctionsAdded) {
assert(ie->value.present == RICserviceUpdate_IEs__value_PR_RANfunctions_List);
const int sz = ie->value.choice.RANfunctions_List.list.count;
su->added = calloc(sz, sizeof(ran_function_t));
su->len_added = sz;
for (int i = 0; i < sz; ++i) {
const RANfunction_ItemIEs_t* r = (const RANfunction_ItemIEs_t*)ie->value.choice.RANfunctions_List.list.array[i];
assert(r->id == ProtocolIE_ID_id_RANfunction_Item);
assert(r->value.present == RANfunction_ItemIEs__value_PR_RANfunction_Item);
su->added[i] = copy_ran_function(&r->value.choice.RANfunction_Item);
}
} else if (ie->id == ProtocolIE_ID_id_RANfunctionsModified) {
assert(ie->value.present == RICserviceUpdate_IEs__value_PR_RANfunctions_List_1);
const int sz = ie->value.choice.RANfunctions_List_1.list.count;
su->modified = calloc(sz, sizeof(ran_function_t));
su->len_modified = sz;
for (int i = 0; i < sz; ++i) {
const RANfunction_ItemIEs_t* r = (const RANfunction_ItemIEs_t*)ie->value.choice.RANfunctions_List_1.list.array[i];
assert(r->id == ProtocolIE_ID_id_RANfunction_Item);
assert(r->value.present == RANfunction_ItemIEs__value_PR_RANfunction_Item);
su->modified[i] = copy_ran_function(&r->value.choice.RANfunction_Item);
}
} else if (ie->id == ProtocolIE_ID_id_RANfunctionsDeleted) {
assert(ie->value.present == RICserviceUpdate_IEs__value_PR_RANfunctionsID_List);
const int sz = ie->value.choice.RANfunctionsID_List.list.count;
su->deleted = calloc(sz, sizeof(e2ap_ran_function_id_rev_t));
su->len_deleted = sz;
for (int i = 0; i < sz; ++i) {
const RANfunctionID_ItemIEs_t* r = (const RANfunctionID_ItemIEs_t*)ie->value.choice.RANfunctionsID_List.list.array[i];
assert(r->id == ProtocolIE_ID_id_RANfunctionID_Item);
assert(r->value.present == RANfunctionID_ItemIEs__value_PR_RANfunctionID_Item);
su->deleted[i].id = r->value.choice.RANfunctionID_Item.ranFunctionID;
su->deleted[i].rev = r->value.choice.RANfunctionID_Item.ranFunctionRevision;
}
}
}

// List of RAN Functions Deleted
const RICserviceUpdate_IEs_t* ran_del = out->protocolIEs.list.array[3];
assert(ran_del->id == ProtocolIE_ID_id_RANfunctionsDeleted);
assert(ran_del->criticality == Criticality_reject);
assert(ran_del->value.present == RICserviceUpdate_IEs__value_PR_RANfunctionsID_List);
const int sz_del = ran_del->value.choice.RANfunctions_List.list.count;
su->deleted = calloc(sz_del, sizeof(e2ap_ran_function_id_rev_t));
su->len_deleted = sz_del;
for(int i = 0; i < sz_del; ++i){
const RANfunction_ItemIEs_t* r = (const RANfunction_ItemIEs_t*)ran_del->value.choice.RANfunctions_List.list.array[i];
assert(r->id == ProtocolIE_ID_id_RANfunction_Item);
assert(r->criticality == Criticality_reject);
assert(r->value.present == RANfunction_ItemIEs__value_PR_RANfunction_Item);
su->deleted[i].id = r->value.choice.RANfunction_Item.ranFunctionID;
su->deleted[i].rev = r->value.choice.RANfunction_Item.ranFunctionRevision;
}
return ret;
}

Expand All @@ -2068,8 +2059,6 @@ e2ap_msg_t e2ap_dec_service_update_ack(const E2AP_PDU_t* pdu)
{
assert(pdu != NULL);

assert(0!=0 && "Untested code");

e2ap_msg_t ret = {.type = RIC_SERVICE_UPDATE_ACKNOWLEDGE};
ric_service_update_ack_t* su = &ret.u_msgs.ric_serv_updt_ack;
// Message Type. Mandatory
Expand All @@ -2096,14 +2085,14 @@ e2ap_msg_t e2ap_dec_service_update_ack(const E2AP_PDU_t* pdu)
if(up_ack->id == ProtocolIE_ID_id_RANfunctionsAccepted){
// List of RAN Functions Accepted
RICserviceUpdateAcknowledge_IEs_t* update_ack = up_ack;
assert(update_ack->criticality == Criticality_ignore);
assert(update_ack->criticality == Criticality_reject);
assert(update_ack->value.present == RICserviceUpdateAcknowledge_IEs__value_PR_RANfunctionsID_List);
const int sz_acc = update_ack->value.choice.RANfunctionsID_List.list.count;
su->accepted = calloc(sz_acc, sizeof(ran_function_id_t));
su->len_accepted = sz_acc;
for(int i = 0; i < sz_acc; ++i){
const RANfunctionID_ItemIEs_t* r = (const RANfunctionID_ItemIEs_t*)update_ack->value.choice.RANfunctionsID_List.list.array[i];
assert(r->id == ProtocolIE_ID_id_RANfunction_Item);
assert(r->id == ProtocolIE_ID_id_RANfunctionID_Item);
assert(r->criticality == Criticality_reject);
assert(r->value.present == RANfunctionID_ItemIEs__value_PR_RANfunctionID_Item);
su->accepted[i].id = r->value.choice.RANfunctionID_Item.ranFunctionID;
Expand All @@ -2113,13 +2102,13 @@ e2ap_msg_t e2ap_dec_service_update_ack(const E2AP_PDU_t* pdu)
// List of RAN Functions Rejected
RICserviceUpdateAcknowledge_IEs_t* func_reject_ie = up_ack;
assert(func_reject_ie->id == ProtocolIE_ID_id_RANfunctionsRejected);
assert(func_reject_ie->criticality == Criticality_ignore);
assert(func_reject_ie->criticality == Criticality_reject);
assert(func_reject_ie->value.present == RICserviceUpdateAcknowledge_IEs__value_PR_RANfunctionsID_List);
const int sz_rej = func_reject_ie->value.choice.RANfunctionsIDcause_List.list.count;
su->rejected = calloc(sz_rej, sizeof( rejected_ran_function_t));
for(int i = 0; i < sz_rej; ++i){
const RANfunctionIDcause_ItemIEs_t * r = (const RANfunctionIDcause_ItemIEs_t * )func_reject_ie->value.choice.RANfunctionsIDcause_List.list.array[i];
assert(r->criticality == Criticality_ignore);
assert(r->criticality == Criticality_reject);
assert(r->id == ProtocolIE_ID_id_RANfunctionIEcause_Item);
assert(r->value.present == RANfunctionIDcause_ItemIEs__value_PR_RANfunctionIDcause_Item);

Expand Down
2 changes: 1 addition & 1 deletion src/lib/e2ap/v2_03/e2ap_types/ric_service_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bool eq_ric_service_update(const ric_service_update_t* m0, const ric_service_upd
return false;

for(size_t i = 0; i < m0->len_modified; ++i){
if(eq_ran_function(&m0->modified[i], &m1->modified[i]))
if(eq_ran_function(&m0->modified[i], &m1->modified[i]) == false)
return false;
}

Expand Down
3 changes: 3 additions & 0 deletions src/lib/e2ap/v2_03/e2ap_types/ric_service_update.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "common/e2ap_ran_function.h"
#include "common/e2ap_ran_function_id_rev.h"
#include "common/e2ap_global_node_id.h"

typedef struct {
uint8_t trans_id;
Expand All @@ -21,6 +22,8 @@ typedef struct {

e2ap_ran_function_id_rev_t* deleted;
size_t len_deleted;

global_e2_node_id_t e2_node_id;
} ric_service_update_t;

bool eq_ric_service_update(const ric_service_update_t* m0, const ric_service_update_t* m1);
Expand Down
Loading
Loading