Commit ab27d02e authored by Robert Schmidt's avatar Robert Schmidt Committed by Guido Casati

Add new F1AP msg enc&dec library

Add a new target f1ap_lib that groups F1AP ASN.1 encoding&decoding for
messages defined f1ap_messages_types.h. The objective is to, for each
F1AP message,
- add encoder&decoder (similar to what already exists, but without
  mandatory message sending afterwards)
- eq_X() function that checks two messages for equality (to be used
  mostly in tests)
- cp_X() function that deep-copies a message, e.g., to be used when
  sending ITTI messages, instead of manual copying done currently
- free_X() function that frees the memory associated to a memory, to
  avoid memory leaks.

Each message will be tested, notably that encoding&decoding as well as
copying yield identical messages.

The actual message encoding & decoding, tests, and their use will be
done in the forthcoming commits.
parent ba208c0f
add_subdirectory(lib)
add_subdirectory(MESSAGES)
if(ENABLE_TESTS)
......@@ -5,4 +6,6 @@ if(ENABLE_TESTS)
target_link_libraries(f1ap_ids_test UTIL HASHTABLE minimal_lib)
add_dependencies(tests f1ap_ids_test)
add_test(NAME F1AP_ID_test COMMAND f1ap_ids_test)
add_subdirectory(tests)
endif()
add_library(f1ap_lib OBJECT
f1ap_lib_common.c
)
target_link_libraries(f1ap_lib PRIVATE asn1_f1ap)
target_include_directories(f1ap_lib PUBLIC
${CMAKE_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include "f1ap_lib_common.h"
#include "f1ap_messages_types.h"
#include "OCTET_STRING.h"
#include "common/utils/assertions.h"
#include "common/utils/utils.h"
bool eq_f1ap_plmn(const f1ap_plmn_t *a, const f1ap_plmn_t *b)
{
return a->mcc == b->mcc && a->mnc == b->mnc && a->mnc_digit_length == b->mnc_digit_length;
}
uint8_t *cp_octet_string(const OCTET_STRING_t *os, int *len)
{
uint8_t *buf = calloc_or_fail(os->size, sizeof(*buf));
memcpy(buf, os->buf, os->size);
*len = os->size;
return buf;
}
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#ifndef F1AP_LIB_COMMON_H_
#define F1AP_LIB_COMMON_H_
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
/* macro to look up IE. If mandatory and not found, macro will print
* descriptive debug message to stderr and force exit in calling function */
#define F1AP_LIB_FIND_IE(IE_TYPE, ie, container, IE_ID, mandatory) \
do { \
ie = NULL; \
for (IE_TYPE **ptr = container->protocolIEs.list.array; \
ptr < &container->protocolIEs.list.array[container->protocolIEs.list.count]; \
ptr++) { \
if ((*ptr)->id == IE_ID) { \
ie = *ptr; \
break; \
} \
} \
if (mandatory && ie == NULL) { \
fprintf(stderr, "%s(): could not find element " #IE_ID " with type " #IE_TYPE "\n", __func__); \
return false; \
} \
} while (0)
struct f1ap_plmn_t;
bool eq_f1ap_plmn(const struct f1ap_plmn_t *a, const struct f1ap_plmn_t *b);
struct OCTET_STRING;
uint8_t *cp_octet_string(const struct OCTET_STRING *os, int *len);
#endif /* F1AP_LIB_COMMON_H_ */
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#ifndef F1AP_LIB_EXTERN_H_
#define F1AP_LIB_EXTERN_H_
#endif /* F1AP_LIB_EXTERN_H_ */
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#ifndef F1AP_LIB_INCLUDES_H_
#define F1AP_LIB_INCLUDES_H_
#include "F1AP_F1AP-PDU.h"
#endif /* F1AP_LIB_INCLUDES_H_ */
add_executable(f1ap_lib_test f1ap_lib_test.c)
add_dependencies(tests f1ap_lib_test)
add_test(NAME f1ap_lib_test COMMAND f1ap_lib_test)
target_link_libraries(f1ap_lib_test PRIVATE f1ap_lib)
target_link_libraries(f1ap_lib_test PRIVATE asn1_f1ap)
target_include_directories(f1ap_lib_test PRIVATE ${CMAKE_SOURCE_DIR})
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include "common/utils/assertions.h"
#include "f1ap_messages_types.h"
#include "F1AP_F1AP-PDU.h"
void exit_function(const char *file, const char *function, const int line, const char *s, const int assert)
{
printf("detected error at %s:%d:%s: %s\n", file, line, function, s);
abort();
}
static F1AP_F1AP_PDU_t *f1ap_encode_decode(const F1AP_F1AP_PDU_t *enc_pdu)
{
//xer_fprint(stdout, &asn_DEF_F1AP_F1AP_PDU, enc_pdu);
DevAssert(enc_pdu != NULL);
char errbuf[1024];
size_t errlen = sizeof(errbuf);
int ret = asn_check_constraints(&asn_DEF_F1AP_F1AP_PDU, enc_pdu, errbuf, &errlen);
AssertFatal(ret == 0, "asn_check_constraints() failed: %s\n", errbuf);
uint8_t msgbuf[16384];
asn_enc_rval_t enc = aper_encode_to_buffer(&asn_DEF_F1AP_F1AP_PDU, NULL, enc_pdu, msgbuf, sizeof(msgbuf));
AssertFatal(enc.encoded > 0, "aper_encode_to_buffer() failed\n");
F1AP_F1AP_PDU_t *dec_pdu = NULL;
asn_codec_ctx_t st = {.max_stack_size = 100 * 1000};
asn_dec_rval_t dec = aper_decode(&st, &asn_DEF_F1AP_F1AP_PDU, (void **)&dec_pdu, msgbuf, enc.encoded, 0, 0);
AssertFatal(dec.code == RC_OK, "aper_decode() failed\n");
//xer_fprint(stdout, &asn_DEF_F1AP_F1AP_PDU, dec_pdu);
return dec_pdu;
}
static void f1ap_msg_free(F1AP_F1AP_PDU_t *pdu)
{
ASN_STRUCT_FREE(asn_DEF_F1AP_F1AP_PDU, pdu);
}
int main()
{
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment