Add enc/dec lib and unit test for E1AP Bearer Context Modification Failure
This commit is contained in:
@@ -615,5 +615,14 @@ typedef struct e1ap_lost_connection_t {
|
|||||||
int dummy;
|
int dummy;
|
||||||
} e1ap_lost_connection_t;
|
} e1ap_lost_connection_t;
|
||||||
|
|
||||||
|
/// @brief 9.2.2.6 BEARER CONTEXT MODIFICATION FAILURE
|
||||||
|
typedef struct e1ap_bearer_context_mod_failure_s {
|
||||||
|
// gNB-CU-CP UE E1AP ID (M)
|
||||||
|
uint32_t gNB_cu_cp_ue_id;
|
||||||
|
// gNB-CU-UP UE E1AP ID (M)
|
||||||
|
uint32_t gNB_cu_up_ue_id;
|
||||||
|
// NG-RAN PDU Session Resource Modified List (O)
|
||||||
|
e1ap_cause_t cause;
|
||||||
|
} e1ap_bearer_context_mod_failure_t;
|
||||||
|
|
||||||
#endif /* E1AP_MESSAGES_TYPES_H */
|
#endif /* E1AP_MESSAGES_TYPES_H */
|
||||||
|
|||||||
@@ -2128,3 +2128,101 @@ void free_e1ap_context_mod_response(const e1ap_bearer_modif_resp_t *msg)
|
|||||||
free(msg->pduSessionMod[i].ng_DL_UP_TL_info);
|
free(msg->pduSessionMod[i].ng_DL_UP_TL_info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ===========================================
|
||||||
|
* E1AP Bearer Context Modification Failure
|
||||||
|
* ============================================ */
|
||||||
|
|
||||||
|
/** @brief Bearer Context Modification Failure encoding (9.2.2.6 38.463)
|
||||||
|
* gNB-CU-UP → gNB-CU-CP */
|
||||||
|
struct E1AP_E1AP_PDU *encode_E1_bearer_context_mod_failure(const e1ap_bearer_context_mod_failure_t *msg)
|
||||||
|
{
|
||||||
|
E1AP_E1AP_PDU_t *pdu = calloc_or_fail(1, sizeof(*pdu));
|
||||||
|
pdu->present = E1AP_E1AP_PDU_PR_unsuccessfulOutcome;
|
||||||
|
asn1cCalloc(pdu->choice.unsuccessfulOutcome, type);
|
||||||
|
type->procedureCode = E1AP_ProcedureCode_id_bearerContextModification;
|
||||||
|
type->criticality = E1AP_Criticality_reject;
|
||||||
|
type->value.present = E1AP_UnsuccessfulOutcome__value_PR_BearerContextModificationFailure;
|
||||||
|
E1AP_BearerContextModificationFailure_t *out = &type->value.choice.BearerContextModificationFailure;
|
||||||
|
// gNB-CU-CP UE E1AP ID (M)
|
||||||
|
asn1cSequenceAdd(out->protocolIEs.list, E1AP_BearerContextModificationFailureIEs_t, ie1);
|
||||||
|
ie1->id = E1AP_ProtocolIE_ID_id_gNB_CU_CP_UE_E1AP_ID;
|
||||||
|
ie1->criticality = E1AP_Criticality_reject;
|
||||||
|
ie1->value.present = E1AP_BearerContextModificationFailureIEs__value_PR_GNB_CU_CP_UE_E1AP_ID;
|
||||||
|
ie1->value.choice.GNB_CU_CP_UE_E1AP_ID = msg->gNB_cu_cp_ue_id;
|
||||||
|
// gNB-CU-UP UE E1AP ID (M)
|
||||||
|
asn1cSequenceAdd(out->protocolIEs.list, E1AP_BearerContextModificationFailureIEs_t, ie2);
|
||||||
|
ie2->id = E1AP_ProtocolIE_ID_id_gNB_CU_UP_UE_E1AP_ID;
|
||||||
|
ie2->criticality = E1AP_Criticality_reject;
|
||||||
|
ie2->value.present = E1AP_BearerContextModificationFailureIEs__value_PR_GNB_CU_UP_UE_E1AP_ID;
|
||||||
|
ie2->value.choice.GNB_CU_UP_UE_E1AP_ID = msg->gNB_cu_up_ue_id;
|
||||||
|
// Cause (M)
|
||||||
|
asn1cSequenceAdd(out->protocolIEs.list, E1AP_BearerContextModificationFailureIEs_t, ie3);
|
||||||
|
ie3->id = E1AP_ProtocolIE_ID_id_Cause;
|
||||||
|
ie3->criticality = E1AP_Criticality_reject;
|
||||||
|
ie3->value.present = E1AP_BearerContextModificationFailureIEs__value_PR_Cause;
|
||||||
|
ie3->value.choice.Cause = e1_encode_cause_ie(&msg->cause);
|
||||||
|
return pdu;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @brief Bearer Context Modification Failure decoding (9.2.2.6 38.463)
|
||||||
|
* gNB-CU-UP → gNB-CU-CP */
|
||||||
|
bool decode_E1_bearer_context_mod_failure(e1ap_bearer_context_mod_failure_t *out, const E1AP_E1AP_PDU_t *pdu)
|
||||||
|
{
|
||||||
|
DevAssert(pdu != NULL);
|
||||||
|
_E1_EQ_CHECK_INT(pdu->present, E1AP_E1AP_PDU_PR_unsuccessfulOutcome);
|
||||||
|
E1AP_UnsuccessfulOutcome_t *type = pdu->choice.unsuccessfulOutcome;
|
||||||
|
_E1_EQ_CHECK_LONG(type->procedureCode, E1AP_ProcedureCode_id_bearerContextModification);
|
||||||
|
_E1_EQ_CHECK_INT(type->value.present, E1AP_UnsuccessfulOutcome__value_PR_BearerContextModificationFailure);
|
||||||
|
const E1AP_BearerContextModificationFailure_t *in = &type->value.choice.BearerContextModificationFailure;
|
||||||
|
// Check mandatory IEs first
|
||||||
|
E1AP_BearerContextModificationFailureIEs_t *ie;
|
||||||
|
E1AP_LIB_FIND_IE(E1AP_BearerContextModificationFailureIEs_t, ie, in, E1AP_ProtocolIE_ID_id_gNB_CU_CP_UE_E1AP_ID, true);
|
||||||
|
E1AP_LIB_FIND_IE(E1AP_BearerContextModificationFailureIEs_t, ie, in, E1AP_ProtocolIE_ID_id_gNB_CU_UP_UE_E1AP_ID, true);
|
||||||
|
E1AP_LIB_FIND_IE(E1AP_BearerContextModificationFailureIEs_t, ie, in, E1AP_ProtocolIE_ID_id_Cause, true);
|
||||||
|
for (int i = 0; i < in->protocolIEs.list.count; i++) {
|
||||||
|
ie = in->protocolIEs.list.array[i];
|
||||||
|
AssertFatal(ie != NULL, "in->protocolIEs.list.array[i] shall not be null");
|
||||||
|
switch (ie->id) {
|
||||||
|
case E1AP_ProtocolIE_ID_id_gNB_CU_CP_UE_E1AP_ID:
|
||||||
|
out->gNB_cu_cp_ue_id = ie->value.choice.GNB_CU_CP_UE_E1AP_ID;
|
||||||
|
break;
|
||||||
|
case E1AP_ProtocolIE_ID_id_gNB_CU_UP_UE_E1AP_ID:
|
||||||
|
out->gNB_cu_up_ue_id = ie->value.choice.GNB_CU_UP_UE_E1AP_ID;
|
||||||
|
break;
|
||||||
|
case E1AP_ProtocolIE_ID_id_Cause:
|
||||||
|
out->cause = e1_decode_cause_ie(&ie->value.choice.Cause);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
PRINT_ERROR("Invalid or unhandled optional IE (%ld) in Bearer Context Modification Failure message\n", ie->id);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @brief E1AP Bearer Context Modification Failure: deep copy */
|
||||||
|
e1ap_bearer_context_mod_failure_t cp_E1_bearer_context_mod_failure(const e1ap_bearer_context_mod_failure_t *msg)
|
||||||
|
{
|
||||||
|
e1ap_bearer_context_mod_failure_t cp = {0};
|
||||||
|
cp = *msg;
|
||||||
|
return cp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @brief E1AP Bearer Context Modification Failure: equality check */
|
||||||
|
bool eq_E1_bearer_context_mod_failure(const e1ap_bearer_context_mod_failure_t *a, const e1ap_bearer_context_mod_failure_t *b)
|
||||||
|
{
|
||||||
|
if (!a || !b)
|
||||||
|
return false; // Null-check both inputs
|
||||||
|
_E1_EQ_CHECK_INT(a->gNB_cu_cp_ue_id, b->gNB_cu_cp_ue_id);
|
||||||
|
_E1_EQ_CHECK_INT(a->gNB_cu_up_ue_id, b->gNB_cu_up_ue_id);
|
||||||
|
_E1_EQ_CHECK_INT(a->cause.type, b->cause.type);
|
||||||
|
_E1_EQ_CHECK_INT(a->cause.value, b->cause.value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @brief E1AP Bearer Context Modification Failure: free */
|
||||||
|
void free_E1_bearer_context_mod_failure(const e1ap_bearer_context_mod_failure_t *msg)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|||||||
@@ -52,4 +52,10 @@ void free_e1ap_context_mod_response(const e1ap_bearer_modif_resp_t *msg);
|
|||||||
e1ap_bearer_modif_resp_t cp_bearer_context_mod_response(const e1ap_bearer_modif_resp_t *msg);
|
e1ap_bearer_modif_resp_t cp_bearer_context_mod_response(const e1ap_bearer_modif_resp_t *msg);
|
||||||
bool eq_bearer_context_mod_response(const e1ap_bearer_modif_resp_t *a, const e1ap_bearer_modif_resp_t *b);
|
bool eq_bearer_context_mod_response(const e1ap_bearer_modif_resp_t *a, const e1ap_bearer_modif_resp_t *b);
|
||||||
|
|
||||||
|
struct E1AP_E1AP_PDU *encode_E1_bearer_context_mod_failure(const e1ap_bearer_context_mod_failure_t *msg);
|
||||||
|
bool decode_E1_bearer_context_mod_failure(e1ap_bearer_context_mod_failure_t *out, const struct E1AP_E1AP_PDU *pdu);
|
||||||
|
void free_E1_bearer_context_mod_failure(const e1ap_bearer_context_mod_failure_t *msg);
|
||||||
|
e1ap_bearer_context_mod_failure_t cp_E1_bearer_context_mod_failure(const e1ap_bearer_context_mod_failure_t *msg);
|
||||||
|
bool eq_E1_bearer_context_mod_failure(const e1ap_bearer_context_mod_failure_t *a, const e1ap_bearer_context_mod_failure_t *b);
|
||||||
|
|
||||||
#endif /* E1AP_BEARER_CONTEXT_MANAGEMENT_H_ */
|
#endif /* E1AP_BEARER_CONTEXT_MANAGEMENT_H_ */
|
||||||
|
|||||||
@@ -617,6 +617,49 @@ static void test_bearer_context_modification_response_fail(void)
|
|||||||
free_e1ap_context_mod_response(&orig);
|
free_e1ap_context_mod_response(&orig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @brief Test E1AP Bearer Context Modification Failure encoding/decoding */
|
||||||
|
static void test_bearer_context_modification_failure(void)
|
||||||
|
{
|
||||||
|
// Create the original failure struct
|
||||||
|
e1ap_bearer_context_mod_failure_t orig = {
|
||||||
|
.gNB_cu_cp_ue_id = 0x1111,
|
||||||
|
.gNB_cu_up_ue_id = 0x2222,
|
||||||
|
.cause.type = E1AP_CAUSE_TRANSPORT,
|
||||||
|
.cause.value = E1AP_TRANSPORT_CAUSE_RESOURCE_UNAVAILABLE,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Encode the original message
|
||||||
|
E1AP_E1AP_PDU_t *enc = encode_E1_bearer_context_mod_failure(&orig);
|
||||||
|
|
||||||
|
// Decode the encoded message
|
||||||
|
E1AP_E1AP_PDU_t *dec = e1ap_encode_decode(enc);
|
||||||
|
|
||||||
|
// Free the encoded message
|
||||||
|
e1ap_msg_free(enc);
|
||||||
|
|
||||||
|
// Decode into a new struct
|
||||||
|
e1ap_bearer_context_mod_failure_t decoded = {0};
|
||||||
|
AssertFatal(decode_E1_bearer_context_mod_failure(&decoded, dec),
|
||||||
|
"decode_E1_bearer_context_mod_failure(): could not decode message\n");
|
||||||
|
|
||||||
|
// Free the decoded PDU
|
||||||
|
e1ap_msg_free(dec);
|
||||||
|
|
||||||
|
// Compare original and decoded messages
|
||||||
|
AssertFatal(eq_E1_bearer_context_mod_failure(&orig, &decoded),
|
||||||
|
"eq_E1_bearer_context_mod_failure(): decoded message doesn't match\n");
|
||||||
|
|
||||||
|
// Deep copy the original message
|
||||||
|
e1ap_bearer_context_mod_failure_t cp = cp_E1_bearer_context_mod_failure(&orig);
|
||||||
|
|
||||||
|
// Compare original and copied messages
|
||||||
|
AssertFatal(eq_E1_bearer_context_mod_failure(&orig, &cp), "eq_E1_bearer_context_mod_failure(): copied message doesn't match\n");
|
||||||
|
|
||||||
|
// Free the decoded and copied messages
|
||||||
|
free_E1_bearer_context_mod_failure(&decoded);
|
||||||
|
free_E1_bearer_context_mod_failure(&cp);
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// E1 Bearer Context Setup
|
// E1 Bearer Context Setup
|
||||||
@@ -626,9 +669,10 @@ int main()
|
|||||||
test_e1_cuup_setup_request();
|
test_e1_cuup_setup_request();
|
||||||
test_e1_cuup_setup_response();
|
test_e1_cuup_setup_response();
|
||||||
test_e1_cuup_setup_failure();
|
test_e1_cuup_setup_failure();
|
||||||
// E1 Bearer Context Modification Request
|
// E1 Bearer Context Modification
|
||||||
test_bearer_context_modification_request();
|
test_bearer_context_modification_request();
|
||||||
test_bearer_context_modification_response();
|
test_bearer_context_modification_response();
|
||||||
test_bearer_context_modification_response_fail();
|
test_bearer_context_modification_response_fail();
|
||||||
|
test_bearer_context_modification_failure();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user