From e440e6695aef24ac8c88d852071efb96d192b618 Mon Sep 17 00:00:00 2001 From: Harry Tran Date: Mon, 28 Oct 2019 16:20:54 -0400 Subject: [PATCH] Reorganize directories and switch libaries to using asn1c - Move official components (e2agent.cpp and ric_sim.cpp) to top directory - Move miscellaneous test components to /test - Switch E2AP libraries from using asn1 to asn1c Change-Id: I6136ad4db63ecb58744ce2a838a391b28a3cfd67 Signed-off-by: Harry Tran --- simulators/e2sim/.gitignore | 9 +- simulators/e2sim/CMakeLists.txt | 114 ++++--- simulators/e2sim/README.md | 57 ++-- simulators/e2sim/build_e2sim | 131 ++------ simulators/e2sim/docker/Dockerfile | 4 + simulators/e2sim/{src/e2agent.cpp => e2sim.cpp} | 24 +- .../helm/e2sim/templates/bin/_e2sim-run.sh.tpl | 2 +- simulators/e2sim/ricsim.cpp | 89 ++++++ simulators/e2sim/src/{ => DEF}/e2sim_defs.cpp | 0 simulators/e2sim/src/{ => DEF}/e2sim_defs.h | 10 +- simulators/e2sim/src/E2AP/E2SM/e2sm.c | 196 ++++++++++++ .../src/E2AP/{e2ap_asn_codec.hpp => E2SM/e2sm.h} | 64 ++-- .../e2sim/src/E2AP/XML/E2AP_ENDCX2SetupFailure.xml | 21 ++ .../e2sim/src/E2AP/XML/E2AP_ENDCX2SetupRequest.xml | 67 ++++ .../src/E2AP/XML/E2AP_ENDCX2SetupResponse.xml | 97 ++++++ .../e2sim/src/E2AP/XML/E2AP_ErrorIndication.xml | 21 ++ .../src/E2AP/XML/E2AP_RICindication_type1.xml | 74 +++++ .../src/E2AP/XML/E2AP_RICindication_type2.xml | 74 +++++ .../src/E2AP/XML/E2AP_RICsubscriptionRequest.xml | 50 +++ .../XML/E2AP_RICsubscriptionRequest_Ashwin.xml | 50 +++ .../src/E2AP/XML/E2AP_RICsubscriptionResponse.xml | 46 +++ .../e2sim/src/E2AP/XML/E2AP_X2SetupFailure.xml | 21 ++ .../e2sim/src/E2AP/XML/E2AP_X2SetupRequest.xml | 57 ++++ .../e2sim/src/E2AP/XML/E2AP_X2SetupResponse.xml | 69 +++++ .../e2sim/src/E2AP/XML/reference_constants.txt | 16 + simulators/e2sim/src/E2AP/e2ap_asn1c_codec.c | 143 +++++++++ simulators/e2sim/src/E2AP/e2ap_asn1c_codec.h | 44 +++ simulators/e2sim/src/E2AP/e2ap_message_handler.cpp | 344 ++++++++++++++------- simulators/e2sim/src/E2AP/e2ap_message_handler.hpp | 18 +- simulators/e2sim/src/SCTP/e2sim_sctp.cpp | 56 +++- simulators/e2sim/src/SCTP/e2sim_sctp.hpp | 4 +- simulators/e2sim/src/e2sim.c | 241 --------------- simulators/e2sim/test/Misc/CMakeLists.txt | 86 ++++++ simulators/e2sim/test/Misc/test_asn1c.cpp | 79 +++++ .../ONS2019 => test/Pendulum}/Pendulum_asn_codec.c | 0 .../ONS2019 => test/Pendulum}/Pendulum_asn_codec.h | 0 .../Pendulum}/Serial/adruino_serial.c | 0 .../Pendulum}/Serial/adruino_serial.h | 0 .../Pendulum}/Serial/arduino-serial-lib.c | 0 .../Pendulum}/Serial/arduino-serial-lib.h | 0 .../{src/ONS2019 => test/Pendulum}/demo_setup.txt | 0 .../{src => test/Pendulum}/e2sim_closedloop.c | 0 .../e2sim/{src => test/Pendulum}/e2sim_serial.c | 0 .../{src => test/Pendulum}/e2sim_test_client.c | 0 .../{src => test/Pendulum}/e2termination_test.cpp | 0 .../{src/ONS2019 => test/Pendulum}/pendulum.asn1 | 0 simulators/e2sim/test/WLG/CMakeLists.txt | 59 ++++ .../e2sim/{build_docker => test/WLG/build_wlg.sh} | 7 +- simulators/e2sim/test/WLG/ric_perf.cpp | 287 +++++++++++++++++ .../e2ap_asn_codec.cpp => test/WLG/ric_wlg.cpp} | 120 +++---- simulators/e2sim/test/X2/CMakeLists.txt | 49 +++ simulators/e2sim/{src => test/X2}/x2agent.cpp | 0 simulators/e2sim/test/X2/x2term.cpp | 72 +++++ .../e2sim/{src => test/X2}/x2termination_test.cpp | 4 +- .../e2sim/{src => test}/rmr_interface/README | 0 .../{src => test}/rmr_interface/rmr_install.sh | 0 .../tests/receiver/build_and_run_recvr.sh | 0 .../rmr_interface/tests/receiver/rmr_rcvr.c | 0 .../tests/sender/build_and_run_sender.sh | 0 .../rmr_interface/tests/sender/rmr_sender.c | 0 .../rmr_interface/tests/sender/rmr_wrapper.h | 0 .../e2sim/tools/asn_defs/generate_e2ap_e2sm_codes | 39 +++ simulators/e2sim/tools/build_helper.bash | 35 ++- .../{build_and_run_e2agent => tools/install_asn1c} | 29 +- simulators/e2sim/tools/install_dependencies | 38 +++ 65 files changed, 2404 insertions(+), 713 deletions(-) rename simulators/e2sim/{src/e2agent.cpp => e2sim.cpp} (85%) create mode 100644 simulators/e2sim/ricsim.cpp rename simulators/e2sim/src/{ => DEF}/e2sim_defs.cpp (100%) rename simulators/e2sim/src/{ => DEF}/e2sim_defs.h (84%) create mode 100644 simulators/e2sim/src/E2AP/E2SM/e2sm.c rename simulators/e2sim/src/E2AP/{e2ap_asn_codec.hpp => E2SM/e2sm.h} (77%) create mode 100644 simulators/e2sim/src/E2AP/XML/E2AP_ENDCX2SetupFailure.xml create mode 100644 simulators/e2sim/src/E2AP/XML/E2AP_ENDCX2SetupRequest.xml create mode 100644 simulators/e2sim/src/E2AP/XML/E2AP_ENDCX2SetupResponse.xml create mode 100644 simulators/e2sim/src/E2AP/XML/E2AP_ErrorIndication.xml create mode 100644 simulators/e2sim/src/E2AP/XML/E2AP_RICindication_type1.xml create mode 100644 simulators/e2sim/src/E2AP/XML/E2AP_RICindication_type2.xml create mode 100644 simulators/e2sim/src/E2AP/XML/E2AP_RICsubscriptionRequest.xml create mode 100644 simulators/e2sim/src/E2AP/XML/E2AP_RICsubscriptionRequest_Ashwin.xml create mode 100644 simulators/e2sim/src/E2AP/XML/E2AP_RICsubscriptionResponse.xml create mode 100644 simulators/e2sim/src/E2AP/XML/E2AP_X2SetupFailure.xml create mode 100644 simulators/e2sim/src/E2AP/XML/E2AP_X2SetupRequest.xml create mode 100644 simulators/e2sim/src/E2AP/XML/E2AP_X2SetupResponse.xml create mode 100644 simulators/e2sim/src/E2AP/XML/reference_constants.txt create mode 100644 simulators/e2sim/src/E2AP/e2ap_asn1c_codec.c create mode 100644 simulators/e2sim/src/E2AP/e2ap_asn1c_codec.h delete mode 100644 simulators/e2sim/src/e2sim.c create mode 100644 simulators/e2sim/test/Misc/CMakeLists.txt create mode 100644 simulators/e2sim/test/Misc/test_asn1c.cpp rename simulators/e2sim/{src/ONS2019 => test/Pendulum}/Pendulum_asn_codec.c (100%) rename simulators/e2sim/{src/ONS2019 => test/Pendulum}/Pendulum_asn_codec.h (100%) rename simulators/e2sim/{src/ONS2019 => test/Pendulum}/Serial/adruino_serial.c (100%) rename simulators/e2sim/{src/ONS2019 => test/Pendulum}/Serial/adruino_serial.h (100%) rename simulators/e2sim/{src/ONS2019 => test/Pendulum}/Serial/arduino-serial-lib.c (100%) rename simulators/e2sim/{src/ONS2019 => test/Pendulum}/Serial/arduino-serial-lib.h (100%) rename simulators/e2sim/{src/ONS2019 => test/Pendulum}/demo_setup.txt (100%) rename simulators/e2sim/{src => test/Pendulum}/e2sim_closedloop.c (100%) rename simulators/e2sim/{src => test/Pendulum}/e2sim_serial.c (100%) rename simulators/e2sim/{src => test/Pendulum}/e2sim_test_client.c (100%) rename simulators/e2sim/{src => test/Pendulum}/e2termination_test.cpp (100%) rename simulators/e2sim/{src/ONS2019 => test/Pendulum}/pendulum.asn1 (100%) create mode 100644 simulators/e2sim/test/WLG/CMakeLists.txt rename simulators/e2sim/{build_docker => test/WLG/build_wlg.sh} (95%) create mode 100644 simulators/e2sim/test/WLG/ric_perf.cpp rename simulators/e2sim/{src/E2AP/e2ap_asn_codec.cpp => test/WLG/ric_wlg.cpp} (60%) create mode 100644 simulators/e2sim/test/X2/CMakeLists.txt rename simulators/e2sim/{src => test/X2}/x2agent.cpp (100%) create mode 100644 simulators/e2sim/test/X2/x2term.cpp rename simulators/e2sim/{src => test/X2}/x2termination_test.cpp (98%) rename simulators/e2sim/{src => test}/rmr_interface/README (100%) rename simulators/e2sim/{src => test}/rmr_interface/rmr_install.sh (100%) rename simulators/e2sim/{src => test}/rmr_interface/tests/receiver/build_and_run_recvr.sh (100%) rename simulators/e2sim/{src => test}/rmr_interface/tests/receiver/rmr_rcvr.c (100%) rename simulators/e2sim/{src => test}/rmr_interface/tests/sender/build_and_run_sender.sh (100%) rename simulators/e2sim/{src => test}/rmr_interface/tests/sender/rmr_sender.c (100%) rename simulators/e2sim/{src => test}/rmr_interface/tests/sender/rmr_wrapper.h (100%) create mode 100755 simulators/e2sim/tools/asn_defs/generate_e2ap_e2sm_codes rename simulators/e2sim/{build_and_run_e2agent => tools/install_asn1c} (81%) create mode 100755 simulators/e2sim/tools/install_dependencies diff --git a/simulators/e2sim/.gitignore b/simulators/e2sim/.gitignore index 16821e3..4cc349e 100644 --- a/simulators/e2sim/.gitignore +++ b/simulators/e2sim/.gitignore @@ -3,7 +3,10 @@ rmr/ temp/ .tags .tags1 +.asn tools/asn1c -build_and_run_e2sim -test_e2_termination -upload_to_demo_laptop +tools/asn_defs/*.asn +tools/asn_defs/*.asn1 + +test/WLG/build/ +test/X2/build/ diff --git a/simulators/e2sim/CMakeLists.txt b/simulators/e2sim/CMakeLists.txt index 3349545..c4e867a 100644 --- a/simulators/e2sim/CMakeLists.txt +++ b/simulators/e2sim/CMakeLists.txt @@ -1,71 +1,61 @@ -# Copyright 2019 AT&T Intellectual Property -# Copyright 2019 Nokia -# -# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 -# -# 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. -# +#/***************************************************************************** +# * +# Copyright 2019 AT&T Intellectual Property * +# Copyright 2019 Nokia * +# * +# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * +# * +# 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. * +# * +#******************************************************************************/ cmake_minimum_required(VERSION 3.5.1) set(CMAKE_CXX_COMPILER "/usr/bin/g++") set(CMAKE_CXX_STANDARD 14) -project(e2sim) - -set (HOME_DIR $ENV{HOME}) - -include_directories("src") -include_directories("src/ASN1/lib") -include_directories("src/SCTP/") -include_directories("src/E2AP") -include_directories("src/X2AP") - -#for ASN1_API -#include_directories("src/ASN1") -#include_directories("src/ASN1/asn") -#include_directories("src/ASN1/generated") -#add_library(ASN1_API -# "src/ASN1/lib/asn_x2ap.cpp" -#) - -link_directories("build") +add_definitions("-D ASN_DISABLE_OER_SUPPORT") -#----------------------------------------------- -file(GLOB E2AGENT_SOURCES - "src/e2agent.cpp" - "src/e2sim_defs.cpp" - "src/SCTP/*.cpp" - "src/E2AP/*.cpp" - ) -add_executable(e2agent ${E2AGENT_SOURCES}) - -#for ASN1_API -target_link_libraries(e2agent ASN1_API) +project(e2sim) -#----------------------------------------------- -file(GLOB E2TERM_SOURCES - "src/e2termination_test.cpp" - "src/e2sim_defs.cpp" - "src/SCTP/*.cpp" - "src/E2AP/*.cpp" +set (E2SIM_ROOT ./) + +include_directories("${E2SIM_ROOT}/src") +include_directories("${E2SIM_ROOT}/src/DEF") +include_directories("${E2SIM_ROOT}/src/SCTP/") +include_directories("${E2SIM_ROOT}/src/E2AP") +include_directories("${E2SIM_ROOT}/src/E2AP/E2SM") +include_directories("${E2SIM_ROOT}/ASN1c") + +find_library( SCTP_STD_LIB sctp ) #needed for sctp_sendmsg + +#---------------------------------------------- +file(GLOB E2SIM_SOURCES + "${E2SIM_ROOT}/e2sim.cpp" + "${E2SIM_ROOT}/src/DEF/*.cpp" + "${E2SIM_ROOT}/src/SCTP/*.cpp" + "${E2SIM_ROOT}/src/E2AP/*.c" + "${E2SIM_ROOT}/src/E2AP/*.cpp" + "${E2SIM_ROOT}/ASN1c/*.c" ) -add_executable(e2term ${E2TERM_SOURCES}) -target_link_libraries(e2term ASN1_API) - -#----------------------------------------------- -file(GLOB X2TERM_SOURCES - "src/x2termination_test.cpp" - "src/e2sim_defs.cpp" - "src/SCTP/*.cpp" - "src/X2AP/*.cpp" +add_executable(e2sim ${E2SIM_SOURCES}) +target_link_libraries( e2sim ${SCTP_STD_LIB} ) + +#---------------------------------------------- +file(GLOB RICSIM_SOURCES + "${E2SIM_ROOT}/ricsim.cpp" + "${E2SIM_ROOT}/src/DEF/*.cpp" + "${E2SIM_ROOT}/src/SCTP/*.cpp" + "${E2SIM_ROOT}/src/E2AP/*.c" + "${E2SIM_ROOT}/src/E2AP/*.cpp" + "${E2SIM_ROOT}/ASN1c/*.c" ) -add_executable(x2term ${X2TERM_SOURCES}) -target_link_libraries(x2term ASN1_API) +add_executable(ricsim ${RICSIM_SOURCES}) +target_link_libraries( ricsim ${SCTP_STD_LIB} ) diff --git a/simulators/e2sim/README.md b/simulators/e2sim/README.md index 6c8d10c..db93deb 100644 --- a/simulators/e2sim/README.md +++ b/simulators/e2sim/README.md @@ -1,4 +1,4 @@ -/***************************************************************************** +#/***************************************************************************** # * # Copyright 2019 AT&T Intellectual Property * # Copyright 2019 Nokia * @@ -15,11 +15,11 @@ # See the License for the specific language governing permissions and * # limitations under the License. * # * -******************************************************************************/ +#******************************************************************************/ -# INSTALLATION - * Tested environment: Ubuntu 16.04 - * Install dependencies + +# INSTALLATION (tested on Ubuntu 16.04) + 1. Install dependencies $ sudo apt-get update $ sudo apt-get install -y build-essential @@ -35,40 +35,51 @@ libboost-all-dev $ sudo apt-get clean - ## Build - $ ./build_e2sim + 2. SET ENVIRONMENT VARIABLE + Add this line to `~/.bashrc` + export E2SIM_DIR= -# SET ENVIRONMENT VARIABLE - Add this line to `~/.bashrc` - $ export E2SIM_DIR= + 3. Build the official e2sim + $ ./build_e2sim -# RUN E2SIM - $ cd $E2SIM_DIR/build/ - $ ./e2agent [SERVER IP] [PORT] +# USAGE + $ $E2SIM_DIR/build/e2sim [SERVER IP] [PORT] - By default, SERVER IP = 127.0.0.1, PORT = 36422 (X2AP Port) + By default, SERVER IP = 127.0.0.1, PORT = 36421 # DOCKER Note: The commands in this section must be run from $E2SIM_DIR * Build docker image - $ ./build_docker + $ sudo docker build -f docker/Dockerfile -t [DOCKER_IMAGE]:[TAG] . - ## Run docker container - $ sudo docker run --rm --net host -it e2agent sh -c "./build/e2agent [SERVER IP] [PORT]" + * Example how to run docker container + $ sudo docker run --rm --net host -it [DOCKER_IMAGE]:[TAG] sh -c "./build/e2sim [SERVER IP] [PORT]" -# SUPPORTED MESSAGE FLOWS (Last updated May 24, 2019) +# SUPPORTED MESSAGE FLOWS -- X2 SETUP REQUEST (RIC -> RAN) -- X2 SETUP RESPONSE (RAN -> RIC) +- RIC INDICATION (RAN -> RIC) version 1.3.0 September 13, 2019 + SgNBAdditionRequest + +- RIC SUBSCRIPTION REQUEST (RIC -> RAN) version 1.2.0 May 24, 2019 +- RIC SUBSCRIPTION RESPONSE (RAN -> RIC) +- RIC SUBSCRIPTION FAILURE (RAN -> RIC) - ENDC X2 SETUP REQUEST (RIC -> RAN) - ENDC X2 SETUP RESPONSE (RAN -> RIC) -- RIC SUBSCRIPTION REQUEST (RIC -> RAN) -- RIC SUBSCRIPTION RESPONSE (RAN -> RIC) -- RIC SUBSCRIPTION FAILURE (RAN -> RIC) +- X2 SETUP REQUEST (RIC -> RAN) +- X2 SETUP RESPONSE (RAN -> RIC) + +# GENERATING ASN1C CODES FOR E2AP, E2SM, X2AP + 1. Install asn1c compiler + ./tools/install_asn1c + 2. Generate asn1c codes using e2ap, e2sm and x2ap specs + Download the following files into tools/asn_defs + - e2ap-v031.asn + - e2sm-gNB-X2-release-1-v041.asn + - x2ap-no-desc-15-04.asn # Change logs: 03/12/2019: currently supports sending and receiving X2 SETUP messages diff --git a/simulators/e2sim/build_e2sim b/simulators/e2sim/build_e2sim index a24ba14..ede61a7 100755 --- a/simulators/e2sim/build_e2sim +++ b/simulators/e2sim/build_e2sim @@ -1,105 +1,50 @@ #!/bin/bash -# -# -# Copyright 2019 AT&T Intellectual Property -# Copyright 2019 Nokia -# -# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 -# -# 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. -# -# build utility for E2 Agent +#/***************************************************************************** +# * +# Copyright 2019 AT&T Intellectual Property * +# Copyright 2019 Nokia * +# * +# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * +# * +# 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. * +# * +#******************************************************************************/ set -e -E2SIM_DIR=$PWD -ASN1_C_DIR=$E2SIM_DIR/build/CMakeFiles/ASN1 - +E2SIM_VERSION='1.3.0' +export E2SIM_DIR=$PWD source $E2SIM_DIR/tools/build_helper.bash +DOCKER_IMAGE='e2sim' -print_help() -{ +print_help() { echo " This program installs E2 Simulator You should have ubuntu 14.xx, updated, and the Linux kernel >= 3.14 The program is run by default with no option - Options + USAGE: + ./build_e2sim [OPTIONS] + + OPTIONS: --clean Erase all files to make a rebuild from start + --docker + Build docker image -h Print this help " } -generate_asn1c_codes() -{ - X2AP_RELEASE="R14" - X2AP_ASN_FILES="x2ap-14.6.0.asn1" - ASN_SOURCE_X2AP=$E2SIM_DIR/src/X2AP/MESSAGES/ASN1/${X2AP_RELEASE}/${X2AP_ASN_FILES} - - ASN_SOURCE_Pendulum=$E2SIM_DIR/src/ONS2019/pendulum.asn1 - - done_flag="$ASN1_C_DIR"/done - - #-ot = older than, -nt = newer than - - if [ "$done_flag" -ot $ASN_SOURCE_X2AP ] ; then - echo_info "Generate C codes for from source file" - #echo_info $ASN_SOURCE - - rm -f "$ASN1_C_DIR"/*.c "$ASN1_C_DIR"/*.h - mkdir -p $ASN1_C_DIR - asn1c -pdu=all -fcompound-names -gen-PER -no-gen-OER -no-gen-example \ - -fno-include-deps -D $ASN1_C_DIR $ASN_SOURCE_X2AP \ - |& egrep -v "^Copied|^Compiled" | sort -u - - asn1c -pdu=all -fcompound-names -gen-PER -no-gen-OER -no-gen-example \ - -fno-include-deps -D $ASN1_C_DIR $ASN_SOURCE_Pendulum \ - |& egrep -v "^Copied|^Compiled" | sort -u - - echo_success "ASN1 C codes generated at: $ASN1_C_DIR" - fi - touch $done_flag -} - -install_rmr() -{ - echo_info "Will install rmr library" - /bin/bash rmr_interface/rmr_install.sh -} - -compile_asn_api_lib() -{ - echo_info "Will complie ASN1_API library" - # rm -rf build/libASN1_API.a - # rm -rf build/asn_x2ap.o - # rm -rf build/asn_e2ap.o - - g++ -O3 -std=c++14 -Wall \ - -I./src/ASN1/ -I./src/ASN1/asn/ -I./src/ASN1/generated/ \ - -c src/ASN1/lib/asn_e2ap.cpp \ - -o build/asn_e2ap.o - ar -crv build/libASN1_API.a build/asn_e2ap.o - - g++ -O3 -std=c++14 -Wall \ - -I./src/ASN1/ -I./src/ASN1/asn/ -I./src/ASN1/generated/ \ - -c src/ASN1/lib/asn_x2ap.cpp \ - -o build/asn_x2ap.o - ar -crv build/libASN1_API.a build/asn_x2ap.o -} - -function main() -{ - +function main(){ case "$1" in --clean) echo_info "Will clean all previously producted files under build/" @@ -108,17 +53,13 @@ function main() exit ;; - "") - ;; - - --rmr) - install_rmr + --docker) + echo "Will build docker image ${DOCKER_IMAGE}:${E2SIM_VERSION}" + sudo docker build -f docker/Dockerfile -t $DOCKER_IMAGE:$E2SIM_VERSION . exit ;; - --lib) - compile_asn_api_lib - exit + "") ;; -h) @@ -132,11 +73,6 @@ function main() BUILD_DIR=$E2SIM_DIR/build mkdir -p $BUILD_DIR - mkdir -p $BUILD_DIR/log - - # generate_asn1c_codes #X2AP, pendulum - - compile_asn_api_lib echo_info "Will build e2sim" cd $BUILD_DIR @@ -145,7 +81,6 @@ function main() make -j`nproc` echo_success "e2sim compiled" - } main "$@" diff --git a/simulators/e2sim/docker/Dockerfile b/simulators/e2sim/docker/Dockerfile index f1b6b62..3bee1c0 100644 --- a/simulators/e2sim/docker/Dockerfile +++ b/simulators/e2sim/docker/Dockerfile @@ -36,6 +36,10 @@ RUN apt-get update \ bison \ flex \ libboost-all-dev \ + iputils-ping \ + net-tools \ + nano \ + vim \ && apt-get clean # Copy E2Sim sources into the container diff --git a/simulators/e2sim/src/e2agent.cpp b/simulators/e2sim/e2sim.cpp similarity index 85% rename from simulators/e2sim/src/e2agent.cpp rename to simulators/e2sim/e2sim.cpp index 07d52cd..77f6be1 100644 --- a/simulators/e2sim/src/e2agent.cpp +++ b/simulators/e2sim/e2sim.cpp @@ -24,33 +24,12 @@ #include "e2sim_defs.h" #include "e2sim_sctp.hpp" -#include "asn_e2ap.hpp" #include "e2ap_message_handler.hpp" using namespace std; -void test(void) -{ - e2ap_pdu_t* pdu = new_e2ap_pdu(); - - gNB_config gnb_cfg; - - e2ap_create_ENDCX2SetupResponse(pdu, gnb_cfg); - - e2ap_print_pdu(pdu); - - //Encode into buffer - sctp_buffer_t data; - e2ap_encode_pdu(pdu, data.buffer, sizeof(data.buffer), data.len); - -} - int main(int argc, char* argv[]){ - - LOG_I("E2 Agent (E2 Simulator) Version %s", VERSION); - - // test(); - // return 0; + LOG_I("Start E2 Agent (E2 Simulator)"); options_t ops = read_input_options(argc, argv); @@ -60,6 +39,7 @@ int main(int argc, char* argv[]){ sctp_buffer_t recv_buf; LOG_I("[SCTP] Waiting for SCTP data"); + while(1) //constantly looking for data on SCTP interface { if(sctp_receive_data(client_fd, recv_buf) <= 0) diff --git a/simulators/e2sim/helm/e2sim/templates/bin/_e2sim-run.sh.tpl b/simulators/e2sim/helm/e2sim/templates/bin/_e2sim-run.sh.tpl index 8f7c954..35e01c4 100755 --- a/simulators/e2sim/helm/e2sim/templates/bin/_e2sim-run.sh.tpl +++ b/simulators/e2sim/helm/e2sim/templates/bin/_e2sim-run.sh.tpl @@ -51,4 +51,4 @@ else echo "e2sim starting at ${E2SIM_BIND_ADDR}:${E2SIM_PORT:-36421}" fi -${E2SIM:-/home/e2sim/build/e2agent} ${E2SIM_BIND_ADDR} ${E2SIM_PORT:-36421} +${E2SIM:-/home/e2sim/build/e2sim} ${E2SIM_BIND_ADDR} ${E2SIM_PORT:-36421} diff --git a/simulators/e2sim/ricsim.cpp b/simulators/e2sim/ricsim.cpp new file mode 100644 index 0000000..e42e9d2 --- /dev/null +++ b/simulators/e2sim/ricsim.cpp @@ -0,0 +1,89 @@ +/***************************************************************************** +# * +# Copyright 2019 AT&T Intellectual Property * +# Copyright 2019 Nokia * +# * +# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * +# * +# 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. * +# * +******************************************************************************/ + +#include +#include +#include + +#include "e2sim_sctp.hpp" +#include "e2ap_message_handler.hpp" + +extern "C" { + #include "e2sim_defs.h" + #include "E2AP-PDU.h" + #include "e2ap_asn1c_codec.h" +} + +using namespace std; + +void encode_and_send_sctp_data(E2AP_PDU_t* pdu, int client_fd) +{ + uint8_t *buf; + sctp_buffer_t data; + + data.len = e2ap_asn1c_encode_pdu(pdu, &buf); + memcpy(data.buffer, buf, data.len); + + sctp_send_data(client_fd, data); +} + +void wait_for_sctp_data(int client_fd) +{ + sctp_buffer_t recv_buf; + if(sctp_receive_data(client_fd, recv_buf) > 0) + { + LOG_I("[SCTP] Received new data of size %d", recv_buf.len); + e2ap_handle_sctp_data(client_fd, recv_buf); + } +} + +int main(int argc, char* argv[]){ + LOG_I("Start RIC Simulator"); + + options_t ops = read_input_options(argc, argv); + int client_fd = sctp_start_client(ops.server_ip, ops.server_port); + + //1. Send ENDCX2Setup + E2AP_PDU_t* pdu_setup = e2ap_xml_to_pdu("E2AP_ENDCX2SetupRequest.xml"); + e2ap_asn1c_print_pdu(pdu_setup); + encode_and_send_sctp_data(pdu_setup, client_fd); + LOG_I("[SCTP] Sent ENDC X2 SETUP REQUEST"); + + //2. Receive ENDCX2SetupResponse + wait_for_sctp_data(client_fd); + + //3. Send RICSubscriptionRequest + E2AP_PDU_t* pdu_sub = e2ap_xml_to_pdu("E2AP_RICsubscriptionRequest_Ashwin.xml"); + e2ap_asn1c_print_pdu(pdu_sub); + encode_and_send_sctp_data(pdu_sub, client_fd); + LOG_I("[SCTP] Sent RIC SUBSCRIPTION REQUEST"); + + //4. Receive RICSubscriptionResponse + while(1){ + wait_for_sctp_data(client_fd); + } + + + //--------------------------------------- + close(client_fd); + LOG_I("[SCTP] Connection closed."); + + return 0; + +} diff --git a/simulators/e2sim/src/e2sim_defs.cpp b/simulators/e2sim/src/DEF/e2sim_defs.cpp similarity index 100% rename from simulators/e2sim/src/e2sim_defs.cpp rename to simulators/e2sim/src/DEF/e2sim_defs.cpp diff --git a/simulators/e2sim/src/e2sim_defs.h b/simulators/e2sim/src/DEF/e2sim_defs.h similarity index 84% rename from simulators/e2sim/src/e2sim_defs.h rename to simulators/e2sim/src/DEF/e2sim_defs.h index 30a0165..74bf619 100644 --- a/simulators/e2sim/src/e2sim_defs.h +++ b/simulators/e2sim/src/DEF/e2sim_defs.h @@ -20,12 +20,16 @@ #ifndef E2SIM_DEFS_H #define E2SIM_DEFS_H -#include +// #include +#include +#include #define VERSION "1.2.0" //May 2019 #define DEFAULT_SCTP_IP "127.0.0.1" -#define X2AP_SCTP_PORT 36422 -#define MAX_SCTP_BUFFER 1024 +#define X2AP_PPID (452984832) //27 = 1b, PPID = 1b000000(hex) -> 452984832(dec) +#define X2AP_SCTP_PORT 36421 +#define RIC_SCTP_SRC_PORT 36422 +#define MAX_SCTP_BUFFER 1024 #define WORKDIR_ENV "E2SIM_DIR" //environment variable #define LOG_I(...) {printf(__VA_ARGS__); printf("\n");} diff --git a/simulators/e2sim/src/E2AP/E2SM/e2sm.c b/simulators/e2sim/src/E2AP/E2SM/e2sm.c new file mode 100644 index 0000000..6cad6cd --- /dev/null +++ b/simulators/e2sim/src/E2AP/E2SM/e2sm.c @@ -0,0 +1,196 @@ +/***************************************************************************** +# * +# Copyright 2019 AT&T Intellectual Property * +# Copyright 2019 Nokia * +# * +# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * +# * +# 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. * +# * +******************************************************************************/ +#include "e2sm.h" + +#include "ActionParameter-Item.h" +#include "ActionParameter-Value.h" +#include "PLMN-Identity.h" +#include "GlobalENB-ID.h" +#include "GlobalGNB-ID.h" +#include "Interface-ID.h" +#include "ProtocolIE-Field.h" +#include "InterfaceMessageType.h" +#include "InterfaceProtocolIE-Item.h" + +static PLMN_Identity_t *createPLMN_ID(const unsigned char *data) { + + PLMN_Identity_t *plmnId = calloc(1, sizeof(PLMN_Identity_t)); + ASN_STRUCT_RESET(asn_DEF_PLMN_Identity, plmnId); + plmnId->size = 3; + plmnId->buf = calloc(1, 3); + memcpy(plmnId->buf, data, 3); + + return plmnId; +} + +static GNB_ID_t *createGnb_id(const unsigned char *data, int numOfBits) { + + if (numOfBits < 22 || numOfBits > 32) { + printf("[Error] GNB_ID_t number of bits = %d, needs to be 22 .. 32", numOfBits); + return NULL; + } + + GNB_ID_t *gnb = calloc(1, sizeof(GNB_ID_t)); + ASN_STRUCT_RESET(asn_DEF_GNB_ID, gnb); + + gnb->present = GNB_ID_PR_gNB_ID; + gnb->choice.gNB_ID.size = numOfBits % 8 == 0 ? (unsigned int)(numOfBits / 8) : (unsigned int)(numOfBits / 8 + 1); + gnb->choice.gNB_ID.bits_unused = gnb->choice.gNB_ID.size * 8 - numOfBits; + gnb->choice.gNB_ID.buf = calloc(1, gnb->choice.gNB_ID.size); + memcpy(gnb->choice.gNB_ID.buf, data, gnb->choice.gNB_ID.size); + gnb->choice.gNB_ID.buf[gnb->choice.gNB_ID.size - 1] = + ((unsigned)(gnb->choice.gNB_ID.buf[gnb->choice.gNB_ID.size - 1] >> (unsigned)gnb->choice.gNB_ID.bits_unused) + << (unsigned)gnb->choice.gNB_ID.bits_unused); + + return gnb; +} + +static GlobalGNB_ID_t *createGlobalGNB_ID(PLMN_Identity_t *plmnIdentity, GNB_ID_t *gnb) { + + GlobalGNB_ID_t *ggnbId = calloc(1, sizeof(GlobalGNB_ID_t)); + ASN_STRUCT_RESET(asn_DEF_GlobalGNB_ID, ggnbId); + + memcpy(&ggnbId->pLMN_Identity, plmnIdentity, sizeof(PLMN_Identity_t)); + memcpy(&ggnbId->gNB_ID, gnb, sizeof(GNB_ID_t)); + + return ggnbId; +} + +static Interface_ID_t *createInterfaceIDForGnb(GlobalGNB_ID_t *gnb) { + + Interface_ID_t *interfaceId = calloc(1, sizeof(Interface_ID_t)); + ASN_STRUCT_RESET(asn_DEF_Interface_ID, interfaceId); + + interfaceId->present = Interface_ID_PR_global_gNB_ID; + interfaceId->choice.global_gNB_ID = gnb; + + return interfaceId; +} + +static InterfaceMessageType_t *createInterfaceMessageInitiating(long procedureCode) { + + InterfaceMessageType_t *intMsgT = calloc(1, sizeof(InterfaceMessageType_t)); + ASN_STRUCT_RESET(asn_DEF_InterfaceMessageType, intMsgT); + + intMsgT->procedureCode = procedureCode; + intMsgT->typeOfMessage = TypeOfMessage_initiating_message; + + return intMsgT; +} + +E2SM_gNB_X2_eventTriggerDefinition_t* create_eventTriggerDefinition(void) +{ + //PLMN_Identity + unsigned char plmnidData[3] = {0x33, 0xF4, 0x55}; + PLMN_Identity_t *plmnid = createPLMN_ID(plmnidData); + // xer_fprint(stdout, &asn_DEF_PLMN_Identity, (void *)plmnid); + + //GNB_ID + unsigned char gnbData[3] = {0x99, 0xaa, 0xbb}; + GNB_ID_t *gnb = createGnb_id(gnbData, 26); + // xer_fprint(stdout, &asn_DEF_GNB_ID, (void *)gnb); + + //GlobalGNB_ID + GlobalGNB_ID_t *globaGnb = createGlobalGNB_ID(plmnid, gnb); + // xer_fprint(stdout, &asn_DEF_GlobalGNB_ID, (void *)globaGnb); + + //Interface_ID + Interface_ID_t *gnbInterfaceId = createInterfaceIDForGnb(globaGnb); + // xer_fprint(stdout, &asn_DEF_Interface_ID, (void *)gnbInterfaceId); + + //InterfaceMessageType + InterfaceMessageType_t *initiatingInterface = createInterfaceMessageInitiating(35); + + //EventTriggerDefinition + E2SM_gNB_X2_eventTriggerDefinition_t *eventTrigger = calloc(1, sizeof(E2SM_gNB_X2_eventTriggerDefinition_t)); + ASN_STRUCT_RESET(asn_DEF_E2SM_gNB_X2_eventTriggerDefinition, eventTrigger); + + memcpy(&eventTrigger->interface_ID , gnbInterfaceId, sizeof(Interface_ID_t)); + + eventTrigger->interfaceDirection = 0; + memcpy(&eventTrigger->interfaceMessageType, initiatingInterface, sizeof(InterfaceMessageType_t)); + + return eventTrigger; +} + +#define E2AP_ASN1C_FIND_PROTOCOLIE_BY_ID(IE_TYPE, ie, container, IE_ID) \ + do {\ + IE_TYPE **ptr; \ + ie = NULL; \ + for (ptr = container->protocolIEs.list.array; \ + ptr < &container->protocolIEs.list.array[container->protocolIEs.list.count]; \ + ptr++) { \ + if((*ptr)->id == IE_ID) { \ + ie = *ptr; \ + break; \ + } \ + } \ + } while(0) + + +void test_eventTriggerDefinition(void) +{ + E2SM_gNB_X2_eventTriggerDefinition_t *eventTrigger = create_eventTriggerDefinition(); + + xer_fprint(stdout, &asn_DEF_E2SM_gNB_X2_eventTriggerDefinition, (void *)eventTrigger); + printf("\n"); + + uint8_t *eventBuff; + int eventBuff_len; + + eventBuff_len = aper_encode_to_new_buffer(&asn_DEF_E2SM_gNB_X2_eventTriggerDefinition, + 0, eventTrigger, (void **)&eventBuff); + + LOG_I("Encoded eventBuff_len = %d", eventBuff_len); + + //----------------------------------------------------------------------- + E2AP_PDU_t* pdu = e2ap_xml_to_pdu("E2AP_RICsubscriptionRequest.xml"); + e2ap_asn1c_print_pdu(pdu); + + InitiatingMessage_t *initiatingMessage = pdu->choice.initiatingMessage; + xer_fprint(stdout, &asn_DEF_InitiatingMessage, (void *)initiatingMessage); + + RICsubscriptionRequest_t *request = &initiatingMessage->value.choice.RICsubscriptionRequest; + xer_fprint(stdout, &asn_DEF_RICsubscriptionRequest, (void *)request); + + LOG_I("num of IEs = %d", request->protocolIEs.list.count); + + + RICsubscriptionRequest_IEs_t *ie; + + ie = request->protocolIEs.list.array[2]; + + // E2AP_ASN1C_FIND_PROTOCOLIE_BY_ID(RICsubscriptionRequest_IEs_t, ie, request, ProtocolIE_ID_id_RICsubscription); + // E2AP_ASN1C_FIND_PROTOCOLIE_BY_ID(RICsubscriptionRequest_IEs_t, ie, request, ProtocolIE_ID_id_RICrequestID); + + assert( ie != NULL); + + xer_fprint(stdout, &asn_DEF_RICsubscription, (void *)ie); + // xer_fprint(stdout, &asn_DEF_RICrequestID, (void *)ie); + + +} + +// +// typedef struct ProtocolIE_Container_119P0 { +// A_SEQUENCE_OF(struct RICsubscriptionRequest_IEs) list; +// +// /* Context for parsing across buffer boundaries */ +// asn_struct_ctx_t _asn_ctx; +// } ProtocolIE_Container_119P0_t; diff --git a/simulators/e2sim/src/E2AP/e2ap_asn_codec.hpp b/simulators/e2sim/src/E2AP/E2SM/e2sm.h similarity index 77% rename from simulators/e2sim/src/E2AP/e2ap_asn_codec.hpp rename to simulators/e2sim/src/E2AP/E2SM/e2sm.h index 6fd6170..19f30a2 100644 --- a/simulators/e2sim/src/E2AP/e2ap_asn_codec.hpp +++ b/simulators/e2sim/src/E2AP/E2SM/e2sm.h @@ -1,34 +1,30 @@ -/***************************************************************************** -# * -# Copyright 2019 AT&T Intellectual Property * -# Copyright 2019 Nokia * -# * -# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * -# * -# 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. * -# * -******************************************************************************/ -#ifndef E2AP_ASN_CODEC_HPP -#define E2AP_ASN_CODEC_HPP - -#include "e2sim_defs.h" -#include "asn_e2ap.hpp" - -#define ERROR_MESSAGE_BUFFER 1024 -#define PDU_PRINT_BUFFER 4096 - -void e2ap_encode_pdu(e2ap_pdu_t* pdu, unsigned char* buf, int buf_size, int &encoded_size); - -void e2ap_decode_pdu(e2ap_pdu_t* pdu, unsigned char* buf, int &encoded_size); - -void e2ap_print_pdu(e2ap_pdu_t* pdu); - -#endif +/***************************************************************************** +# * +# Copyright 2019 AT&T Intellectual Property * +# Copyright 2019 Nokia * +# * +# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * +# * +# 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. * +# * +******************************************************************************/ +#ifndef E2SM_H +#define E2SM_H + +#include "E2SM-gNB-X2-eventTriggerDefinition.h" +#include "E2AP-PDU.h" +#include "e2ap_asn1c_codec.h" + +E2SM_gNB_X2_eventTriggerDefinition_t* create_eventTriggerDefinition(void); + +void test_eventTriggerDefinition(void); + +#endif diff --git a/simulators/e2sim/src/E2AP/XML/E2AP_ENDCX2SetupFailure.xml b/simulators/e2sim/src/E2AP/XML/E2AP_ENDCX2SetupFailure.xml new file mode 100644 index 0000000..633baee --- /dev/null +++ b/simulators/e2sim/src/E2AP/XML/E2AP_ENDCX2SetupFailure.xml @@ -0,0 +1,21 @@ + + + 36 + + + + + + 5 + + + + + + + + + + + + diff --git a/simulators/e2sim/src/E2AP/XML/E2AP_ENDCX2SetupRequest.xml b/simulators/e2sim/src/E2AP/XML/E2AP_ENDCX2SetupRequest.xml new file mode 100644 index 0000000..ddb071a --- /dev/null +++ b/simulators/e2sim/src/E2AP/XML/E2AP_ENDCX2SetupRequest.xml @@ -0,0 +1,67 @@ + + + 36 + + + + + + 244 + + + + + + 21 + + + + 61 62 63 + + + 00110101000000000001 + + + + + + + 250 + + + + + + 0 + + 61 62 63 + + 0110010001100101011001100000 + + + 61 62 + + 61 62 63 + + + + 21400 + 3400 + + + + + + + + + + + + + + + + + + diff --git a/simulators/e2sim/src/E2AP/XML/E2AP_ENDCX2SetupResponse.xml b/simulators/e2sim/src/E2AP/XML/E2AP_ENDCX2SetupResponse.xml new file mode 100644 index 0000000..896eed6 --- /dev/null +++ b/simulators/e2sim/src/E2AP/XML/E2AP_ENDCX2SetupResponse.xml @@ -0,0 +1,97 @@ + + + 36 + + + + + + 246 + + + + + + 252 + + + + 02 F8 29 + + + 000000000001001000110100 + + + + + + + 253 + + + + + + 99 + + 02 F8 29 + + 000000000000011110101011000000010010 + + + + 02 F8 29 + + + + + 100 + + + 9 + + + 9 + + + + + + + 100 + + + 9 + + + 9 + + + + + + + + + + + + + + + + 04 05 + + + + + + + + + + + + + + diff --git a/simulators/e2sim/src/E2AP/XML/E2AP_ErrorIndication.xml b/simulators/e2sim/src/E2AP/XML/E2AP_ErrorIndication.xml new file mode 100644 index 0000000..8974693 --- /dev/null +++ b/simulators/e2sim/src/E2AP/XML/E2AP_ErrorIndication.xml @@ -0,0 +1,21 @@ + + + 3 + + + + + + 5 + + + + + + + + + + + + diff --git a/simulators/e2sim/src/E2AP/XML/E2AP_RICindication_type1.xml b/simulators/e2sim/src/E2AP/XML/E2AP_RICindication_type1.xml new file mode 100644 index 0000000..e4e3f38 --- /dev/null +++ b/simulators/e2sim/src/E2AP/XML/E2AP_RICindication_type1.xml @@ -0,0 +1,74 @@ + + + 205 + + + + + + 60030 + + + + 6 + 12 + + + + + 60003 + + + 10 + + + + 60017 + + + 100 + + + + 60028 + + + 100 + + + + 60029 + + + + + + + 60026 + + + 10 74 68 65 10 68 65 6C 40 + + + + 60027 + + + + 00 1B 40 80 80 00 00 08 00 6F 00 02 00 0C 00 F8 + 00 05 08 4D 86 D6 40 00 CB 00 20 31 32 33 34 35 + 36 37 38 39 31 32 33 34 35 36 37 38 39 31 32 33 + 34 35 36 37 38 39 31 32 33 34 35 00 CC 00 06 08 + 07 D0 20 03 E8 00 CE 00 0C 0B 49 6E 66 6F 72 6D + 61 74 69 6F 6E 01 17 00 08 00 33 32 31 34 35 36 + 30 01 13 00 01 22 00 CD 00 1B 00 00 D1 00 16 1A + 11 50 00 08 21 09 E0 41 41 42 42 43 43 44 44 45 + 45 5A 5A 59 58 + + + + + + + + diff --git a/simulators/e2sim/src/E2AP/XML/E2AP_RICindication_type2.xml b/simulators/e2sim/src/E2AP/XML/E2AP_RICindication_type2.xml new file mode 100644 index 0000000..92bc727 --- /dev/null +++ b/simulators/e2sim/src/E2AP/XML/E2AP_RICindication_type2.xml @@ -0,0 +1,74 @@ + + + 205 + + + + + + 60030 + + + + 6 + 12 + + + + + 60003 + + + 10 + + + + 60017 + + + 100 + + + + 60028 + + + 100 + + + + 60029 + + + + + + + 60026 + + + 10 74 68 65 10 68 65 6C 40 + + + + 60027 + + + + 00 1B 40 80 80 00 00 08 00 6F 00 02 00 0C 00 F8 + 00 05 08 4D 86 D6 40 00 CB 00 20 31 32 33 34 35 + 36 37 38 39 31 32 33 34 35 36 37 38 39 31 32 33 + 34 35 36 37 38 39 31 32 33 34 35 00 CC 00 06 08 + 07 D0 20 03 E8 00 CE 00 0C 0B 49 6E 66 6F 72 6D + 61 74 69 6F 6E 01 17 00 08 00 33 32 31 34 35 36 + 30 01 13 00 01 23 00 CD 00 1B 00 00 D1 00 16 1A + 11 50 00 08 21 09 E0 41 41 42 42 43 43 44 44 45 + 45 5A 5A 59 58 + + + + + + + + diff --git a/simulators/e2sim/src/E2AP/XML/E2AP_RICsubscriptionRequest.xml b/simulators/e2sim/src/E2AP/XML/E2AP_RICsubscriptionRequest.xml new file mode 100644 index 0000000..ab3ea11 --- /dev/null +++ b/simulators/e2sim/src/E2AP/XML/E2AP_RICsubscriptionRequest.xml @@ -0,0 +1,50 @@ + + + 201 + + + + + + 60030 + + + + 1 + 200 + + + + + 60003 + + + 33 + + + + 60033 + + + + 00 01 02 03 40 0b 16 02 00 23 40 + + + 60011 + + + + 255 + + + + + + + + + + + + + diff --git a/simulators/e2sim/src/E2AP/XML/E2AP_RICsubscriptionRequest_Ashwin.xml b/simulators/e2sim/src/E2AP/XML/E2AP_RICsubscriptionRequest_Ashwin.xml new file mode 100644 index 0000000..524f7af --- /dev/null +++ b/simulators/e2sim/src/E2AP/XML/E2AP_RICsubscriptionRequest_Ashwin.xml @@ -0,0 +1,50 @@ + + + 201 + + + + + + 60030 + + + + 2 + 1 + + + + + 60003 + + + 0 + + + + 60033 + + + + 10 54 65 73 10 54 65 73 40 1B 40 + + + 60011 + + + + 4 + + + + + + + + + + + + + diff --git a/simulators/e2sim/src/E2AP/XML/E2AP_RICsubscriptionResponse.xml b/simulators/e2sim/src/E2AP/XML/E2AP_RICsubscriptionResponse.xml new file mode 100644 index 0000000..b7ea847 --- /dev/null +++ b/simulators/e2sim/src/E2AP/XML/E2AP_RICsubscriptionResponse.xml @@ -0,0 +1,46 @@ + + + 201 + + + + + + 60030 + + + + 2 + 205 + + + + + 60003 + + + 0 + + + + 60012 + + + + + 60013 + + + + 1 + + + + + + + + + + + diff --git a/simulators/e2sim/src/E2AP/XML/E2AP_X2SetupFailure.xml b/simulators/e2sim/src/E2AP/XML/E2AP_X2SetupFailure.xml new file mode 100644 index 0000000..53acf31 --- /dev/null +++ b/simulators/e2sim/src/E2AP/XML/E2AP_X2SetupFailure.xml @@ -0,0 +1,21 @@ + + + 6 + + + + + + 5 + + + + + + + + + + + + diff --git a/simulators/e2sim/src/E2AP/XML/E2AP_X2SetupRequest.xml b/simulators/e2sim/src/E2AP/XML/E2AP_X2SetupRequest.xml new file mode 100644 index 0000000..9f0f286 --- /dev/null +++ b/simulators/e2sim/src/E2AP/XML/E2AP_X2SetupRequest.xml @@ -0,0 +1,57 @@ + + + 6 + + + + + + 21 + + + + 13 30 23 + + + 11111111111111111111 + + + + + + + 20 + + + + + + 503 + + 13 30 23 + + 1111111111111111111100000000 + + + 00 00 + + 13 30 23 + + + + 0 + 0 + + + + + + + + + + + + + + diff --git a/simulators/e2sim/src/E2AP/XML/E2AP_X2SetupResponse.xml b/simulators/e2sim/src/E2AP/XML/E2AP_X2SetupResponse.xml new file mode 100644 index 0000000..03682d9 --- /dev/null +++ b/simulators/e2sim/src/E2AP/XML/E2AP_X2SetupResponse.xml @@ -0,0 +1,69 @@ + + + 6 + + + + + + 21 + + + + 02 F8 39 + + + 00000000111000110000 + + + + + + + 20 + + + + + + 0 + + 02 F8 39 + + 0000000011100011000000000000 + + + 00 01 + + 02 F8 39 + + + + 21400 + 3400 + + + + + + + + + + + 24 + + + + + 02 F8 39 + 00 00 + + + + + + + + + diff --git a/simulators/e2sim/src/E2AP/XML/reference_constants.txt b/simulators/e2sim/src/E2AP/XML/reference_constants.txt new file mode 100644 index 0000000..b9a3b54 --- /dev/null +++ b/simulators/e2sim/src/E2AP/XML/reference_constants.txt @@ -0,0 +1,16 @@ +/* Dependencies */ +typedef enum Criticality { + Criticality_reject = 0, + Criticality_ignore = 1, + Criticality_notify = 2 +} e_Criticality; + + +-- Event Trigger Definition OCTET STRING contents +E2SM-gNB-X2-eventTriggerDefinition ::= SEQUENCE{ + interface-ID Interface-ID, + interfaceDirection InterfaceDirection, + interfaceMessageType InterfaceMessageType, + interfaceProtocolIE-List SEQUENCE (SIZE(1..maxofInterfaceProtocolIE)) OF InterfaceProtocolIE-Item OPTIONAL, + ... +} diff --git a/simulators/e2sim/src/E2AP/e2ap_asn1c_codec.c b/simulators/e2sim/src/E2AP/e2ap_asn1c_codec.c new file mode 100644 index 0000000..5205b16 --- /dev/null +++ b/simulators/e2sim/src/E2AP/e2ap_asn1c_codec.c @@ -0,0 +1,143 @@ +/***************************************************************************** +# * +# Copyright 2019 AT&T Intellectual Property * +# Copyright 2019 Nokia * +# * +# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * +# * +# 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. * +# * +******************************************************************************/ +#include "e2ap_asn1c_codec.h" + +void e2ap_asn1c_print_pdu(const E2AP_PDU_t* pdu) +{ + xer_fprint(stdout, &asn_DEF_E2AP_PDU, (void *)pdu); + printf("\n"); +} + +void asn1c_xer_print(asn_TYPE_descriptor_t *typeDescriptor, void *data) +{ + xer_fprint(stdout, typeDescriptor, (void *)data); + printf("\n"); +} + + +E2AP_PDU_t* e2ap_xml_to_pdu(char const* xml_message) +{ + // E2AP_PDU_t *pdu = new E2AP_PDU_t(); + E2AP_PDU_t *pdu = calloc(1, sizeof(E2AP_PDU_t)); + + assert(pdu != 0); + + uint8_t buf[MAX_XML_BUFFER]; + asn_dec_rval_t rval; + size_t size; + FILE *f; + + char XML_path[300]; + char *work_dir = getenv(WORKDIR_ENV); + + strcpy(XML_path, work_dir); + strcat(XML_path, E2AP_XML_DIR); + strcat(XML_path, xml_message); + + LOG_D("Generate E2AP PDU from XML file: %s\n", XML_path); + memset(buf, 0, sizeof(buf)); + + f = fopen(XML_path, "r"); + if(!f){ + LOG_E("Unable to open %s. Make sure you have set the Environment Variable E2SIM_DIR, see README", XML_path) + } + + assert(f); + + size = fread(buf, 1, sizeof(buf), f); + if(size == 0 || size == sizeof(buf)) + { + LOG_E("Input too long: %s", XML_path); + exit(1); + } + + fclose(f); + + rval = xer_decode(0, &asn_DEF_E2AP_PDU, (void **)&pdu, buf, size); + + assert(rval.code == RC_OK); + + return pdu; +} + +int e2ap_asn1c_encode_pdu(E2AP_PDU_t* pdu, unsigned char **buffer) +{ + int len; + + *buffer = NULL; + assert(pdu != NULL); + assert(buffer != NULL); + + len = aper_encode_to_new_buffer(&asn_DEF_E2AP_PDU, 0, pdu, (void **)buffer); + + if (len < 0) { + LOG_E("[E2AP ASN] Unable to aper encode"); + exit(1); + } + else { + LOG_D("[E2AP ASN] Encoded succesfully, encoded size = %d", len); + } + + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_E2AP_PDU, pdu); + + return len; +} + +void e2ap_asn1c_decode_pdu(E2AP_PDU_t* pdu, unsigned char *buffer, int len) +{ + asn_dec_rval_t dec_ret; + + assert(buffer != NULL); + + dec_ret = aper_decode(NULL, &asn_DEF_E2AP_PDU, (void **)&pdu, buffer, len, 0, 0); + + if (dec_ret.code != RC_OK) { + LOG_E("[E2AP ASN] Failed to decode pdu"); + exit(1); + } + else { + LOG_D("[E2AP ASN] Decoded succesfully"); + } +} + +int e2ap_asn1c_get_procedureCode(E2AP_PDU_t* pdu) +{ + int procedureCode = -1; + + switch(pdu->present) + { + case E2AP_PDU_PR_initiatingMessage: + procedureCode = pdu->choice.initiatingMessage->procedureCode; + break; + + case E2AP_PDU_PR_successfulOutcome: + procedureCode = pdu->choice.successfulOutcome->procedureCode; + break; + + case E2AP_PDU_PR_unsuccessfulOutcome: + procedureCode = pdu->choice.unsuccessfulOutcome->procedureCode; + break; + + default: + LOG_E("[E2AP] Error: Unknown index %d in E2AP PDU", (int)pdu->present); + break; + } + + return procedureCode; +} diff --git a/simulators/e2sim/src/E2AP/e2ap_asn1c_codec.h b/simulators/e2sim/src/E2AP/e2ap_asn1c_codec.h new file mode 100644 index 0000000..1362638 --- /dev/null +++ b/simulators/e2sim/src/E2AP/e2ap_asn1c_codec.h @@ -0,0 +1,44 @@ +/***************************************************************************** +# * +# Copyright 2019 AT&T Intellectual Property * +# Copyright 2019 Nokia * +# * +# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * +# * +# 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. * +# * +******************************************************************************/ +#ifndef E2AP_ASN1C_CODEC_H +#define E2AP_ASN1C_CODEC_H + +#include "e2sim_defs.h" +#include "E2AP-PDU.h" +#include "InitiatingMessage.h" +#include "SuccessfulOutcome.h" +#include "UnsuccessfulOutcome.h" + +#define ASN1C_PDU_PRINT_BUFFER 4096 +#define MAX_XML_BUFFER 10000 +#define E2AP_XML_DIR "/src/E2AP/XML/" + +void e2ap_asn1c_print_pdu(const E2AP_PDU_t* pdu); + +void asn1c_xer_print(asn_TYPE_descriptor_t *typeDescriptor, void *data); + +E2AP_PDU_t* e2ap_xml_to_pdu(char const* xml_message); + +int e2ap_asn1c_encode_pdu(E2AP_PDU_t* pdu, unsigned char **buffer); + +void e2ap_asn1c_decode_pdu(E2AP_PDU_t* pdu, unsigned char *buffer, int len); + +int e2ap_asn1c_get_procedureCode(E2AP_PDU_t* pdu); + +#endif diff --git a/simulators/e2sim/src/E2AP/e2ap_message_handler.cpp b/simulators/e2sim/src/E2AP/e2ap_message_handler.cpp index d511949..d8f5e6b 100644 --- a/simulators/e2sim/src/E2AP/e2ap_message_handler.cpp +++ b/simulators/e2sim/src/E2AP/e2ap_message_handler.cpp @@ -17,37 +17,38 @@ # * ******************************************************************************/ #include "e2ap_message_handler.hpp" +#include void e2ap_handle_sctp_data(int &socket_fd, sctp_buffer_t &data) { //decode the data into E2AP-PDU - e2ap_pdu_t* pdu = new_e2ap_pdu(); + E2AP_PDU_t* pdu = new E2AP_PDU_t(); - e2ap_decode_pdu(pdu, data.buffer, data.len); + e2ap_asn1c_decode_pdu(pdu, data.buffer, data.len); - e2ap_print_pdu(pdu); + e2ap_asn1c_print_pdu(pdu); - int index = e2ap_get_index(pdu); - int procedureCode = e2ap_get_procedureCode(pdu); + int procedureCode = e2ap_asn1c_get_procedureCode(pdu); + int index = (int)pdu->present; - LOG_I("[E2AP] Unpacked E2AP-PDU: index = %d, procedureCode = %d\n", index, procedureCode); + LOG_D("[E2AP] Unpacked E2AP-PDU: index = %d, procedureCode = %d\n", + index, procedureCode); switch(procedureCode) { - case 6: //X2Setup + case ProcedureCode_id_x2Setup: //X2Setup = 6 switch(index) { - case 1: //initiatingMessage - LOG_D("[E2AP] Received X2-SETUP-REQUEST"); + case E2AP_PDU_PR_initiatingMessage: //initiatingMessage + LOG_I("[E2AP] Received X2-SETUP-REQUEST"); e2ap_handle_X2SetupRequest(pdu, socket_fd); break; - case 2: //successfulOutcome - LOG_D("[E2AP] Received X2-SETUP-RESPONSE"); - //e2ap_handle_X2SetupResponse(pdu, socket_fd); + case E2AP_PDU_PR_successfulOutcome: //successfulOutcome + LOG_I("[E2AP] Received X2-SETUP-RESPONSE"); break; - case 3: + case E2AP_PDU_PR_unsuccessfulOutcome: break; default: @@ -56,21 +57,22 @@ void e2ap_handle_sctp_data(int &socket_fd, sctp_buffer_t &data) } break; - case 36: //ENDCX2Setup + case ProcedureCode_id_endcX2Setup: //ENDCX2Setup = 36 switch(index) { - case 1: //initiatingMessage - LOG_D("[E2AP] Received ENDC-X2-SETUP-REQUEST"); + case E2AP_PDU_PR_initiatingMessage: //initiatingMessage + LOG_I("[E2AP] Received ENDC-X2-SETUP-REQUEST"); e2ap_handle_ENDCX2SetupRequest(pdu, socket_fd); break; - case 2: //successfulOutcome - LOG_D("[E2AP] Received ENDC-X2-SETUP-RESPONSE"); - //x2ap_handle_X2SetupResponse(pdu, socket_fd); + case E2AP_PDU_PR_successfulOutcome: //successfulOutcome + LOG_I("[E2AP] Received ENDC-X2-SETUP-RESPONSE"); + //no handler yet break; - case 3: - LOG_D("[E2AP] Received ENDC-X2-SETUP-FAILURE"); + case E2AP_PDU_PR_unsuccessfulOutcome: + LOG_I("[E2AP] Received ENDC-X2-SETUP-FAILURE"); + //no handler yet break; default: @@ -79,25 +81,60 @@ void e2ap_handle_sctp_data(int &socket_fd, sctp_buffer_t &data) } break; - case 201: //RIC SUBSCRIPTION + case ProcedureCode_id_reset: //reset = 7 switch(index) { - case 1: //initiatingMessage - LOG_D("[E2AP] Received RIC-SUBSCRIPTION-REQUEST"); - e2ap_handle_RICSubscriptionRequest(pdu, socket_fd); + case E2AP_PDU_PR_initiatingMessage: + LOG_I("[E2AP] Received RESET-REQUEST"); break; - case 2: - LOG_D("[E2AP] Received RIC-SUBSCRIPTION-RESPONSE"); + case E2AP_PDU_PR_successfulOutcome: break; - case 3: - LOG_D("[E2AP] Received RIC-SUBSCRIPTION-FAILURE"); + case E2AP_PDU_PR_unsuccessfulOutcome: break; default: - LOG_E("[E2AP] Invalid message index=%d in E2AP-PDU", index); - break; + LOG_E("[E2AP] Invalid message index=%d in E2AP-PDU", index); + break; + } + break; + + case ProcedureCode_id_ricSubscription: //RIC SUBSCRIPTION = 201 + switch(index) + { + case E2AP_PDU_PR_initiatingMessage: //initiatingMessage + LOG_I("[E2AP] Received RIC-SUBSCRIPTION-REQUEST"); + //e2ap_handle_RICSubscriptionRequest(pdu, socket_fd); + e2ap_handle_RICSubscriptionRequest_securityDemo(pdu, socket_fd); + break; + + case E2AP_PDU_PR_successfulOutcome: + LOG_I("[E2AP] Received RIC-SUBSCRIPTION-RESPONSE"); + break; + + case E2AP_PDU_PR_unsuccessfulOutcome: + LOG_I("[E2AP] Received RIC-SUBSCRIPTION-FAILURE"); + break; + + default: + LOG_E("[E2AP] Invalid message index=%d in E2AP-PDU", index); + break; + } + break; + + case ProcedureCode_id_ricIndication: // 205 + switch(index) + { + case E2AP_PDU_PR_initiatingMessage: //initiatingMessage + LOG_I("[E2AP] Received RIC-INDICATION"); + // e2ap_handle_RICSubscriptionRequest(pdu, socket_fd); + break; + + default: + LOG_E("[E2AP] Invalid message index=%d in E2AP-PDU %d", index, + (int)ProcedureCode_id_ricIndication); + break; } break; @@ -107,55 +144,49 @@ void e2ap_handle_sctp_data(int &socket_fd, sctp_buffer_t &data) } } -void e2ap_handle_X2SetupRequest(e2ap_pdu_t* pdu, int &socket_fd) +/* +Simply send back X2SetupResponse +Todo: add more handling options (failure, duplicated request, etc.) +*/ +void e2ap_handle_X2SetupRequest(E2AP_PDU_t* pdu, int &socket_fd) { - /* - Simply send back X2SetupResponse - Todo: add more handling options (failure, duplicated request, etc.) - */ + E2AP_PDU_t* res_pdu = e2ap_xml_to_pdu("E2AP_X2SetupResponse.xml"); - e2ap_pdu_t* res_pdu = new_e2ap_pdu(); - eNB_config cfg; + LOG_D("[E2AP] Created X2-SETUP-RESPONSE"); - e2ap_create_X2SetupResponse(res_pdu, cfg); - LOG_D("[E2AP] Created X2-SETUP-RESPONSE") + e2ap_asn1c_print_pdu(res_pdu); - e2ap_print_pdu(res_pdu); + uint8_t *buf; + sctp_buffer_t data; - //encode response pdu into buffer - sctp_buffer_t res_data; - e2ap_encode_pdu(res_pdu, res_data.buffer, sizeof(res_data.buffer), res_data.len); + data.len = e2ap_asn1c_encode_pdu(res_pdu, &buf); + memcpy(data.buffer, buf, data.len); //send response data over sctp - if(sctp_send_data(socket_fd, res_data) > 0) { + if(sctp_send_data(socket_fd, data) > 0) { LOG_I("[SCTP] Sent X2-SETUP-RESPONSE"); } else { LOG_E("[SCTP] Unable to send X2-SETUP-RESPONSE to peer"); } } -void e2ap_handle_X2SetupResponse(e2ap_pdu_t* pdu, int &socket_fd) -{ - ; -} - -void e2ap_handle_ENDCX2SetupRequest(e2ap_pdu_t* pdu, int &socket_fd) +/* +Simply send back ENDCX2SetupResponse +Todo: add more handling options (failure, duplicated request, etc.) +*/ +void e2ap_handle_ENDCX2SetupRequest(E2AP_PDU_t* pdu, int &socket_fd) { - /* - Simply send back ENDCX2SetupResponse - Todo: add more handling options (failure, duplicated request, etc.) - */ + E2AP_PDU_t* res_pdu = e2ap_xml_to_pdu("E2AP_ENDCX2SetupResponse.xml"); - e2ap_pdu_t* res_pdu = new_e2ap_pdu(); - gNB_config gnb_cfg; - - e2ap_create_ENDCX2SetupResponse(res_pdu, gnb_cfg); LOG_D("[E2AP] Created ENDC-X2-SETUP-RESPONSE"); - e2ap_print_pdu(res_pdu); + e2ap_asn1c_print_pdu(res_pdu); + uint8_t *buf; sctp_buffer_t data; - e2ap_encode_pdu(res_pdu, data.buffer, sizeof(data.buffer), data.len); + + data.len = e2ap_asn1c_encode_pdu(res_pdu, &buf); + memcpy(data.buffer, buf, data.len); //send response data over sctp if(sctp_send_data(socket_fd, data) > 0) { @@ -165,76 +196,159 @@ void e2ap_handle_ENDCX2SetupRequest(e2ap_pdu_t* pdu, int &socket_fd) } } -void e2ap_handle_RICSubscriptionRequest(e2ap_pdu_t* pdu, int &socket_fd) +/* +Simply send back hard-coded RICSubscriptionResponse +Todo: add more handling options (failure, duplicated request, etc.) +*/ +void e2ap_handle_RICSubscriptionRequest(E2AP_PDU_t* pdu, int &socket_fd) { - RICsubscription_params_t params; - e2ap_parse_RICsubscriptionRequest(pdu, params); + E2AP_PDU_t* res_pdu = e2ap_xml_to_pdu("E2AP_RICsubscriptionResponse.xml"); - /* Example handling logic - - Accept if request id is even-numbered -> send back response - in this case, accept every other actions + LOG_D("[E2AP] Created RIC-SUBSCRIPTION-RESPONSE"); - - Reject if request id is odd-numbered -> send back failure - */ + e2ap_asn1c_print_pdu(res_pdu); - e2ap_pdu_t* res_pdu = new_e2ap_pdu(); - bool is_failure = false; + uint8_t *buf; + sctp_buffer_t data; - if(params.request_id % 2 == 0) - { - for(size_t i = 0; i < params.actionList.size(); i++) - { - if(i%2 == 0){ - params.actionList[i].isAdmitted = true; - } else { - params.actionList[i].isAdmitted = false; - params.actionList[i].notAdmitted_cause = RICcause_radioNetwork; - params.actionList[i].notAdmitted_subCause = 5; - } - } + data.len = e2ap_asn1c_encode_pdu(res_pdu, &buf); + memcpy(data.buffer, buf, data.len); - e2ap_create_RICsubscriptionResponse(res_pdu, params); - LOG_I("[E2AP] Created RIC-SUBSCRIPTION-RESPONSE"); + //send response data over sctp + if(sctp_send_data(socket_fd, data) > 0) { + LOG_I("[SCTP] Sent RIC-SUBSCRIPTION-RESPONSE"); + } else { + LOG_E("[SCTP] Unable to send RIC-SUBSCRIPTION-RESPONSE to peer"); } - else - { - is_failure = true; +} - for(size_t i = 0; i < params.actionList.size(); i++) - { - params.actionList[i].isAdmitted = false; - params.actionList[i].notAdmitted_cause = RICcause_radioNetwork; - params.actionList[i].notAdmitted_subCause = 5; - } +void e2ap_handle_RICSubscriptionRequest_securityDemo(E2AP_PDU_t* pdu, int &socket_fd) +{ + E2AP_PDU_t* res_pdu = e2ap_xml_to_pdu("E2AP_RICsubscriptionResponse.xml"); - e2ap_create_RICsubscriptionFailure(res_pdu, params); - LOG_I("[E2AP] Created RIC-SUBSCRIPTION-FAILURE"); - } + LOG_D("[E2AP] Created RIC-SUBSCRIPTION-RESPONSE"); - e2ap_print_pdu(res_pdu); + e2ap_asn1c_print_pdu(res_pdu); - //Encode into buffer + uint8_t *buf; sctp_buffer_t data; - e2ap_encode_pdu(res_pdu, data.buffer, sizeof(data.buffer), data.len); + + data.len = e2ap_asn1c_encode_pdu(res_pdu, &buf); + memcpy(data.buffer, buf, data.len); //send response data over sctp - if(sctp_send_data(socket_fd, data) > 0) - { - if(is_failure) { - LOG_I("[SCTP] Sent RIC-SUBSCRIPTION-FAILURE"); - } - else { - LOG_I("[SCTP] Sent RIC-SUBSCRIPTION-RESPONSE"); - } + if(sctp_send_data(socket_fd, data) > 0) { + LOG_I("[SCTP] Sent RIC-SUBSCRIPTION-RESPONSE"); + } else { + LOG_E("[SCTP] Unable to send RIC-SUBSCRIPTION-RESPONSE to peer"); } - else - { - if(is_failure) { - LOG_I("[SCTP] Unable to send RIC-SUBSCRIPTION-FAILURE"); + + //Start sending RIC Indication + int count1 = 0, count2 = 0; + + E2AP_PDU_t* indication_type1 = e2ap_xml_to_pdu("E2AP_RICindication_type1.xml"); + E2AP_PDU_t* indication_type2 = e2ap_xml_to_pdu("E2AP_RICindication_type2.xml"); + + uint8_t *buf1, *buf2; + sctp_buffer_t data1, data2; + data1.len = e2ap_asn1c_encode_pdu(indication_type1, &buf1); + memcpy(data1.buffer, buf1, data1.len); + + data2.len = e2ap_asn1c_encode_pdu(indication_type2, &buf2); + memcpy(data2.buffer, buf2, data2.len); + + while(1){ + sleep(1); + //type1 + if(sctp_send_data(socket_fd, data1) > 0) { + count1++; + LOG_I("[SCTP] Sent RIC-INDICATION SgNBAdditionRequest Type 1, count1 = %d", count1); + } else { + LOG_E("[SCTP] Unable to send RIC-INDICATION to peer"); } - else { - LOG_E("[SCTP] Unable to send RIC-SUBSCRIPTION-RESPONSE"); + + sleep(1); + //type2 + if(sctp_send_data(socket_fd, data2) > 0) { + count2++; + LOG_I("[SCTP] Sent RIC-INDICATION SgNBAdditionRequest Type 2, count2 = %d", count2); + } else { + LOG_E("[SCTP] Unable to send RIC-INDICATION to peer"); } - } + } //end while } + +// void e2ap_handle_RICSubscriptionRequest_old(e2ap_pdu_t* pdu, int &socket_fd) +// { +// RICsubscription_params_t params; +// e2ap_parse_RICsubscriptionRequest(pdu, params); +// +// /* Example handling logic +// - Accept if request id is even-numbered -> send back response +// in this case, accept every other actions +// +// - Reject if request id is odd-numbered -> send back failure +// */ +// +// e2ap_pdu_t* res_pdu = new_e2ap_pdu(); +// bool is_failure = false; +// +// if(params.request_id % 2 == 0) +// { +// for(size_t i = 0; i < params.actionList.size(); i++) +// { +// if(i%2 == 0){ +// params.actionList[i].isAdmitted = true; +// } else { +// params.actionList[i].isAdmitted = false; +// params.actionList[i].notAdmitted_cause = RICcause_radioNetwork; +// params.actionList[i].notAdmitted_subCause = 5; +// } +// } +// +// e2ap_create_RICsubscriptionResponse(res_pdu, params); +// LOG_I("[E2AP] Created RIC-SUBSCRIPTION-RESPONSE"); +// } +// else +// { +// is_failure = true; +// +// for(size_t i = 0; i < params.actionList.size(); i++) +// { +// params.actionList[i].isAdmitted = false; +// params.actionList[i].notAdmitted_cause = RICcause_radioNetwork; +// params.actionList[i].notAdmitted_subCause = 5; +// } +// +// e2ap_create_RICsubscriptionFailure(res_pdu, params); +// LOG_I("[E2AP] Created RIC-SUBSCRIPTION-FAILURE"); +// } +// +// e2ap_print_pdu(res_pdu); +// +// //Encode into buffer +// sctp_buffer_t data; +// e2ap_encode_pdu(res_pdu, data.buffer, sizeof(data.buffer), data.len); +// +// //send response data over sctp +// if(sctp_send_data(socket_fd, data) > 0) +// { +// if(is_failure) { +// LOG_I("[SCTP] Sent RIC-SUBSCRIPTION-FAILURE"); +// } +// else { +// LOG_I("[SCTP] Sent RIC-SUBSCRIPTION-RESPONSE"); +// } +// } +// else +// { +// if(is_failure) { +// LOG_I("[SCTP] Unable to send RIC-SUBSCRIPTION-FAILURE"); +// } +// else { +// LOG_E("[SCTP] Unable to send RIC-SUBSCRIPTION-RESPONSE"); +// } +// } +// +// } diff --git a/simulators/e2sim/src/E2AP/e2ap_message_handler.hpp b/simulators/e2sim/src/E2AP/e2ap_message_handler.hpp index 42bb80f..c7af948 100644 --- a/simulators/e2sim/src/E2AP/e2ap_message_handler.hpp +++ b/simulators/e2sim/src/E2AP/e2ap_message_handler.hpp @@ -19,19 +19,23 @@ #ifndef E2AP_MESSAGE_HANDLER_HPP #define E2AP_MESSAGE_HANDLER_HPP -#include "e2sim_defs.h" #include "e2sim_sctp.hpp" -#include "asn_e2ap.hpp" -#include "e2ap_asn_codec.hpp" + +extern "C" { + #include "e2sim_defs.h" + #include "e2ap_asn1c_codec.h" +} void e2ap_handle_sctp_data(int &socket_fd, sctp_buffer_t &data); -void e2ap_handle_X2SetupRequest(e2ap_pdu_t* pdu, int &socket_fd); +void e2ap_handle_X2SetupRequest(E2AP_PDU_t* pdu, int &socket_fd); + +void e2ap_handle_X2SetupResponse(E2AP_PDU_t* pdu, int &socket_fd); -void e2ap_handle_X2SetupResponse(e2ap_pdu_t* pdu, int &socket_fd); +void e2ap_handle_ENDCX2SetupRequest(E2AP_PDU_t* pdu, int &socket_fd); -void e2ap_handle_ENDCX2SetupRequest(e2ap_pdu_t* pdu, int &socket_fd); +void e2ap_handle_RICSubscriptionRequest(E2AP_PDU_t* pdu, int &socket_fd); -void e2ap_handle_RICSubscriptionRequest(e2ap_pdu_t* pdu, int &socket_fd); +void e2ap_handle_RICSubscriptionRequest_securityDemo(E2AP_PDU_t* pdu, int &socket_fd); #endif diff --git a/simulators/e2sim/src/SCTP/e2sim_sctp.cpp b/simulators/e2sim/src/SCTP/e2sim_sctp.cpp index 3d808c5..15892d4 100644 --- a/simulators/e2sim/src/SCTP/e2sim_sctp.cpp +++ b/simulators/e2sim/src/SCTP/e2sim_sctp.cpp @@ -29,6 +29,16 @@ #include "e2sim_sctp.hpp" // #include "e2sim_defs.h" + +#include +#include +#include +#include +#include +#include +#include +#include + int sctp_start_server(const char *server_ip_str, const int server_port) { if(server_port < 1 || server_port > 65535) { @@ -108,18 +118,14 @@ int sctp_start_client(const char *server_ip_str, const int server_port) { server4_addr.sin_family = AF_INET; server4_addr.sin_port = htons(server_port); - server_addr = (struct sockaddr*)&server4_addr; - af = AF_INET; addr_len = sizeof(server4_addr); } else if(inet_pton(AF_INET6, server_ip_str, &server6_addr.sin6_addr) == 1) { server6_addr.sin6_family = AF_INET6; server6_addr.sin6_port = htons(server_port); - server_addr = (struct sockaddr*)&server6_addr; - af = AF_INET6; addr_len = sizeof(server6_addr); } else { @@ -127,25 +133,47 @@ int sctp_start_client(const char *server_ip_str, const int server_port) exit(1); } - if((client_fd = socket(af, SOCK_STREAM, IPPROTO_SCTP)) == -1) + if((client_fd = socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP)) == -1) { perror("socket"); exit(1); } - LOG_I("[SCTP] Connecting to server at %s:%d ...", server_ip_str, server_port); + //-------------------------------- + //Bind before connect + auto optval = 1; + if( setsockopt(client_fd, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof optval) != 0 ){ + perror("setsockopt port"); + exit(1); + } + + if( setsockopt(client_fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval) != 0 ){ + perror("setsockopt addr"); + exit(1); + } + struct sockaddr_in6 client6_addr {}; + client6_addr.sin6_family = AF_INET6; + client6_addr.sin6_port = htons(RIC_SCTP_SRC_PORT); + client6_addr.sin6_addr = in6addr_any; + + LOG_I("[SCTP] Binding client socket to source port %d", RIC_SCTP_SRC_PORT); + if(bind(client_fd, (struct sockaddr*)&client6_addr, sizeof(client6_addr)) == -1) { + perror("bind"); + exit(1); + } + // end binding --------------------- + + LOG_I("[SCTP] Connecting to server at %s:%d ...", server_ip_str, server_port); if(connect(client_fd, server_addr, addr_len) == -1) { perror("connect"); exit(1); } - assert(client_fd != 0); LOG_I("[SCTP] Connection established"); return client_fd; - } int sctp_accept_connection(const char *server_ip_str, const int server_fd) @@ -193,6 +221,18 @@ int sctp_send_data(int &socket_fd, sctp_buffer_t &data) return sent_len; } +int sctp_send_data_X2AP(int &socket_fd, sctp_buffer_t &data) +{ + int sent_len = sctp_sendmsg(socket_fd, (void*)(&(data.buffer[0])), data.len, + NULL, 0, (uint32_t) X2AP_PPID, 0, 0, 0, 0); + + if(sent_len == -1) { + perror("[SCTP] sctp_send_data"); + exit(1); + } + +} + /* Receive data from SCTP socket Outcome of recv() diff --git a/simulators/e2sim/src/SCTP/e2sim_sctp.hpp b/simulators/e2sim/src/SCTP/e2sim_sctp.hpp index 636f4e7..b16fcf6 100644 --- a/simulators/e2sim/src/SCTP/e2sim_sctp.hpp +++ b/simulators/e2sim/src/SCTP/e2sim_sctp.hpp @@ -32,8 +32,8 @@ int sctp_accept_connection(const char *server_ip_str, const int server_fd); int sctp_send_data(int &socket_fd, sctp_buffer_t &data); -int sctp_receive_data(int &socket_fd, sctp_buffer_t &data); - +int sctp_send_data_X2AP(int &socket_fd, sctp_buffer_t &data); +int sctp_receive_data(int &socket_fd, sctp_buffer_t &data); #endif diff --git a/simulators/e2sim/src/e2sim.c b/simulators/e2sim/src/e2sim.c deleted file mode 100644 index 2f49bea..0000000 --- a/simulators/e2sim/src/e2sim.c +++ /dev/null @@ -1,241 +0,0 @@ -/* - * - * Copyright 2019 AT&T Intellectual Property - * Copyright 2019 Nokia - * - * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 - * - * 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. - * - */ - - -#include -#include -#include -#include -#include -#include //for close() -#include //for inet_ntop() - -#include "e2sim_defs.h" -#include "e2sim_sctp.h" -#include "x2ap_message_handler.h" - -//OSN 2019 -#include "Pendulum_asn_codec.h" -#include "adruino_serial.h" - -//rmr -#include -#include -#include -#include "rmr_wrapper.h" - -static void pendulum_control_E2_agent(int client_fd) -{ - printf("--------------------------------------\n"); - printf("E2 AGENT - START PENDULUM CONTROL\n"); - printf("--------------------------------------\n"); - - uint8_t *buffer; - uint32_t len; - clock_t begin; - double rtt; //ms - - uint8_t recv_buf[MAX_SCTP_BUFFER]; - int recv_len; - - double angle; - double torque; - long sqn; - int count = 0; - - //serial - int serial_fd; - char serial_buffer[MAX_SERIAL_BUFFER]; - serial_fd = start_serial_inferface(DEFAULT_BAUDRATE, DEFAULT_SERIAL_PORT); - - int MSG_NUM = 10; - - // printf("Enter number of messages: "); - // scanf("%d", &MSG_NUM); - // - // //fgets(serial_buffer, MAX_SERIAL_BUFFER, stdin); - // serialport_write(serial_fd, serial_buffer); - - serialport_write(serial_fd, "hello arduino\n"); - - // for(int i = 0; i < MSG_NUM; i++) - while(1) - { - - printf("----------------\n"); - count += 1; - buffer = NULL; - len = 0; - - //1.Read from serial - serial_readline(serial_fd, serial_buffer, MAX_SERIAL_BUFFER); - if(serial_buffer[0] == '\n') - { - //printf("RECEIVED EOL\n"); - continue; - } - //printf("[Adruino] %s", serial_buffer); - - begin = clock(); - - //2. Encode pendulum angle to ASN1 message - len = pendulum_create_asn_msg(&buffer, 0, 0, 0, serial_buffer); - - //3. Send ASN1 message to socket - if(sctp_send_to_socket(client_fd, buffer, (size_t)len) > 0){ - printf("Sent ASN1 message to E2 Termination\n"); - } - - // 4. Receive response from E2 Termination - memset(recv_buf, 0, sizeof(recv_buf)); - recv_len = 0; - recv_len = recv(client_fd, &recv_buf, sizeof(recv_buf), 0); - if(recv_len == -1) - { - perror("recv()"); - return; - } - - char *recv_str; - recv_str = pendulum_get_strval(recv_buf, recv_len); - printf("Received response message #%d from xApp: %s\n", count, recv_str); - - // 5. TODO: Send response to serial - serial_writeline(serial_fd, recv_str); - - //serialport_write(serial_fd, "hello\n"); - - begin = clock() - begin; - rtt = 1000*((double)begin)/CLOCKS_PER_SEC; // in ms - printf("E2Agent-RIC-E2Agent RTT = %f ms\n", rtt); - } - - - close(client_fd); -} - -int main(int argc, char *argv[]) -{ - printf("E2 Simulator. Version %s\n", VERSION); - // test_rmr(); return 0; - // test_adruino_serial(); return 0; - - char* server_ip = DEFAULT_SCTP_IP; - int server_port = X2AP_SCTP_PORT; - - int server_fd; - int client_fd; - struct sockaddr client_addr; - socklen_t client_addr_size; - - //read input - if(argc == 3) //user provided IP and PORT - { - server_ip = argv[1]; - server_port = atoi(argv[2]); - if(server_port < 1 || server_port > 65535) { - printf("Invalid port number (%d). Valid values are between 1 and 65535.\n" , server_port); - return -1; - } - } - else if(argc == 2) //user provided only IP - { - server_ip = argv[1]; - } - else if(argc == 1) - { - server_ip = DEFAULT_SCTP_IP; - } - else - { - printf("Unrecognized option.\n"); - printf("Usage: %s [SERVER IP ADDRESS] [SERVER PORT]\n", argv[0]); - return -1; - } - - server_fd = sctp_start_server(server_ip, server_port); - - printf("Waiting for connection...\n"); - client_fd = accept(server_fd, &client_addr, &client_addr_size); - if(client_fd == -1){ - perror("accept()"); - close(client_fd); - return -1; - } - - //Todo: retrieve client ip addr - struct sockaddr_in* client_ipv4 = (struct sockaddr_in*)&client_addr; - char client_ip_addr[INET_ADDRSTRLEN]; - inet_ntop(AF_INET, &(client_ipv4->sin_addr), client_ip_addr, INET_ADDRSTRLEN); - - printf("New client connected from %s\n", client_ip_addr); - - // while(1) //put while loop if want to receive from multiple clients - // { - uint8_t recv_buf[MAX_SCTP_BUFFER]; - int recv_len = 0; - - memset(recv_buf, 0, sizeof(recv_buf)); - - printf("------------------------\n"); - recv_len = recv(client_fd, &recv_buf, sizeof(recv_buf), 0); - if(recv_len == -1) - { - perror("recv()"); - return -1; - } - else if(recv_len == 0) - { - printf("\nConnection from %s closed by remote peer\n", client_ip_addr); - if(close(client_fd) == -1) - { - perror("close"); - } - return -1; - } - - //printf("Received a message of size %d\n", recv_len); - - //TODO: check PPID here before calling x2ap handler - - sctp_data_t response = {NULL, 0}; - x2ap_eNB_handle_message(recv_buf, recv_len, &response); - - //======================================================================= - //reply to client - assert(response.data != NULL); - if(sctp_send_to_socket(client_fd, response.data, (size_t)response.len) > 0){ - printf("Sent X2 SETUP RESPONSE \n"); - } else{ - perror("send to socket"); - return -1; - } - - printf("X2 Setup Completed \n"); - - //========================================================================= - // Pendulum interaction - // Send pendulum state to E2 Termination and receive response - pendulum_control_E2_agent(client_fd); - // } //end while - - close(client_fd); - - return 0; -} diff --git a/simulators/e2sim/test/Misc/CMakeLists.txt b/simulators/e2sim/test/Misc/CMakeLists.txt new file mode 100644 index 0000000..bf6c51c --- /dev/null +++ b/simulators/e2sim/test/Misc/CMakeLists.txt @@ -0,0 +1,86 @@ +#/***************************************************************************** +# * +# Copyright 2019 AT&T Intellectual Property * +# Copyright 2019 Nokia * +# * +# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * +# * +# 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. * +# * +#******************************************************************************/ + +cmake_minimum_required(VERSION 3.5.1) +set(CMAKE_CXX_COMPILER "/usr/bin/g++") +set(CMAKE_CXX_STANDARD 14) + +add_definitions("-D ASN_DISABLE_OER_SUPPORT") + +project(e2sim) + +set (HOME_DIR $ENV{HOME}) +#set (E2SIM_ROOT ../../../) + +include_directories("src") +include_directories("src/SCTP/") +include_directories("src/E2AP") +include_directories("src/E2AP/E2SM") +include_directories("ASN1c") + +find_library( SCTP_LIBRARY sctp ) #needed for sctp_sendmsg + +#---------------------------------------------- +file(GLOB E2AGENT_SOURCES + "src/e2agent.cpp" + "src/e2sim_defs.cpp" + "src/SCTP/*.cpp" + "src/E2AP/*.c" + "src/E2AP/*.cpp" + "ASN1c/*.c" + ) +add_executable(e2agent ${E2AGENT_SOURCES}) +target_link_libraries( e2agent ${SCTP_LIBRARY} ) + +#---------------------------------------------- +file(GLOB RICSIM_SOURCES + "src/ric_sim.cpp" + "src/e2sim_defs.cpp" + "src/SCTP/*.cpp" + "src/E2AP/*.c" + "src/E2AP/*.cpp" + "ASN1c/*.c" + ) +add_executable(ric_sim ${RICSIM_SOURCES}) +target_link_libraries( ric_sim ${SCTP_LIBRARY} ) + + +#---------------------------------------------- +file(GLOB X2TERM_SOURCES + "src/x2term.cpp" + "src/e2sim_defs.cpp" + "src/SCTP/*.cpp" + "src/E2AP/*.c" + "src/E2AP/*.cpp" + "ASN1c/*.c" + ) +add_executable(x2term ${X2TERM_SOURCES}) +target_link_libraries( x2term ${SCTP_LIBRARY} ) + + +#----------------------------------------------- +file(GLOB TEST + "src/test_asn1c.cpp" + "src/e2sim_defs.cpp" +# "src/SCTP/*.cpp" + "ASN1c/*.c" + "src/E2AP/*.c" + "src/E2AP/E2SM/*.c" + ) +add_executable(test_asn1c ${TEST}) diff --git a/simulators/e2sim/test/Misc/test_asn1c.cpp b/simulators/e2sim/test/Misc/test_asn1c.cpp new file mode 100644 index 0000000..d10273c --- /dev/null +++ b/simulators/e2sim/test/Misc/test_asn1c.cpp @@ -0,0 +1,79 @@ +/***************************************************************************** +# * +# Copyright 2019 AT&T Intellectual Property * +# Copyright 2019 Nokia * +# * +# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * +# * +# 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. * +# * +******************************************************************************/ + +#include +#include +#include +#include +#include + +extern "C" { + #include "e2sim_defs.h" + #include "E2AP-PDU.h" + #include "e2ap_asn1c_codec.h" + #include "e2sm.h" + +} + +using namespace std; + +int main(int argc, char* argv[]){ + + LOG_I("Test ASN1c"); + + test_eventTriggerDefinition(); + return 0; + + E2AP_PDU_t* pdu = e2ap_xml_to_pdu("E2AP_X2SetupRequest.xml"); + // E2AP_PDU_t* pdu = e2ap_xml_to_pdu("E2AP_X2SetupResponse.xml"); + // E2AP_PDU_t* pdu = e2ap_xml_to_pdu("E2AP_X2SetupFailure.xml"); + + // E2AP_PDU_t* pdu = e2ap_xml_to_pdu("E2AP_ENDCX2SetupRequest.xml"); + // E2AP_PDU_t* pdu = e2ap_xml_to_pdu("E2AP_ENDCX2SetupResponse.xml"); + // E2AP_PDU_t* pdu = e2ap_xml_to_pdu("E2AP_ENDCX2SetupFailure.xml"); + + // E2AP_PDU_t* pdu = e2ap_xml_to_pdu("E2AP_RICsubscriptionRequest.xml"); + // E2AP_PDU_t* pdu = e2ap_xml_to_pdu("E2AP_RICsubscriptionResponse.xml"); + // E2AP_PDU_t* pdu = e2ap_xml_to_pdu("E2AP_ErrorIndication.xml"); + + e2ap_asn1c_print_pdu(pdu); + + /* Test encoding */ + uint8_t *buf; + sctp_buffer_t data; + + data.len = e2ap_asn1c_encode_pdu(pdu, &buf); + memcpy(data.buffer, buf, data.len); + + /* Test decoding */ + E2AP_PDU_t* pdu1 = new E2AP_PDU_t(); + + e2ap_asn1c_decode_pdu(pdu1, data.buffer, data.len); + + e2ap_asn1c_print_pdu(pdu1); + + int index = (int)pdu1->present; + + int pCode = e2ap_asn1c_get_procedureCode(pdu1); + + LOG_I("Index = %d, procedureCode = %d", index, pCode); + + + return 0; +} diff --git a/simulators/e2sim/src/ONS2019/Pendulum_asn_codec.c b/simulators/e2sim/test/Pendulum/Pendulum_asn_codec.c similarity index 100% rename from simulators/e2sim/src/ONS2019/Pendulum_asn_codec.c rename to simulators/e2sim/test/Pendulum/Pendulum_asn_codec.c diff --git a/simulators/e2sim/src/ONS2019/Pendulum_asn_codec.h b/simulators/e2sim/test/Pendulum/Pendulum_asn_codec.h similarity index 100% rename from simulators/e2sim/src/ONS2019/Pendulum_asn_codec.h rename to simulators/e2sim/test/Pendulum/Pendulum_asn_codec.h diff --git a/simulators/e2sim/src/ONS2019/Serial/adruino_serial.c b/simulators/e2sim/test/Pendulum/Serial/adruino_serial.c similarity index 100% rename from simulators/e2sim/src/ONS2019/Serial/adruino_serial.c rename to simulators/e2sim/test/Pendulum/Serial/adruino_serial.c diff --git a/simulators/e2sim/src/ONS2019/Serial/adruino_serial.h b/simulators/e2sim/test/Pendulum/Serial/adruino_serial.h similarity index 100% rename from simulators/e2sim/src/ONS2019/Serial/adruino_serial.h rename to simulators/e2sim/test/Pendulum/Serial/adruino_serial.h diff --git a/simulators/e2sim/src/ONS2019/Serial/arduino-serial-lib.c b/simulators/e2sim/test/Pendulum/Serial/arduino-serial-lib.c similarity index 100% rename from simulators/e2sim/src/ONS2019/Serial/arduino-serial-lib.c rename to simulators/e2sim/test/Pendulum/Serial/arduino-serial-lib.c diff --git a/simulators/e2sim/src/ONS2019/Serial/arduino-serial-lib.h b/simulators/e2sim/test/Pendulum/Serial/arduino-serial-lib.h similarity index 100% rename from simulators/e2sim/src/ONS2019/Serial/arduino-serial-lib.h rename to simulators/e2sim/test/Pendulum/Serial/arduino-serial-lib.h diff --git a/simulators/e2sim/src/ONS2019/demo_setup.txt b/simulators/e2sim/test/Pendulum/demo_setup.txt similarity index 100% rename from simulators/e2sim/src/ONS2019/demo_setup.txt rename to simulators/e2sim/test/Pendulum/demo_setup.txt diff --git a/simulators/e2sim/src/e2sim_closedloop.c b/simulators/e2sim/test/Pendulum/e2sim_closedloop.c similarity index 100% rename from simulators/e2sim/src/e2sim_closedloop.c rename to simulators/e2sim/test/Pendulum/e2sim_closedloop.c diff --git a/simulators/e2sim/src/e2sim_serial.c b/simulators/e2sim/test/Pendulum/e2sim_serial.c similarity index 100% rename from simulators/e2sim/src/e2sim_serial.c rename to simulators/e2sim/test/Pendulum/e2sim_serial.c diff --git a/simulators/e2sim/src/e2sim_test_client.c b/simulators/e2sim/test/Pendulum/e2sim_test_client.c similarity index 100% rename from simulators/e2sim/src/e2sim_test_client.c rename to simulators/e2sim/test/Pendulum/e2sim_test_client.c diff --git a/simulators/e2sim/src/e2termination_test.cpp b/simulators/e2sim/test/Pendulum/e2termination_test.cpp similarity index 100% rename from simulators/e2sim/src/e2termination_test.cpp rename to simulators/e2sim/test/Pendulum/e2termination_test.cpp diff --git a/simulators/e2sim/src/ONS2019/pendulum.asn1 b/simulators/e2sim/test/Pendulum/pendulum.asn1 similarity index 100% rename from simulators/e2sim/src/ONS2019/pendulum.asn1 rename to simulators/e2sim/test/Pendulum/pendulum.asn1 diff --git a/simulators/e2sim/test/WLG/CMakeLists.txt b/simulators/e2sim/test/WLG/CMakeLists.txt new file mode 100644 index 0000000..4faee6a --- /dev/null +++ b/simulators/e2sim/test/WLG/CMakeLists.txt @@ -0,0 +1,59 @@ +#/***************************************************************************** +# * +# Copyright 2019 AT&T Intellectual Property * +# Copyright 2019 Nokia * +# * +# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * +# * +# 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. * +# * +#******************************************************************************/ + +cmake_minimum_required(VERSION 3.5.1) +set(CMAKE_CXX_COMPILER "/usr/bin/g++") +set(CMAKE_CXX_STANDARD 14) + +add_definitions("-D ASN_DISABLE_OER_SUPPORT") + +set (E2SIM_ROOT ../../) + +include_directories("${E2SIM_ROOT}/src") +include_directories("${E2SIM_ROOT}/src/DEF") +include_directories("${E2SIM_ROOT}/src/SCTP/") +include_directories("${E2SIM_ROOT}/src/E2AP") +include_directories("${E2SIM_ROOT}/src/E2AP/E2SM") +include_directories("${E2SIM_ROOT}/ASN1c") + +find_library( SCTP_STD_LIB sctp ) #needed for sctp_sendmsg + +#---------------------------------------------- +file(GLOB WLG_SOURCES + "${E2SIM_ROOT}/test/WLG/ric_wlg.cpp" + "${E2SIM_ROOT}/src/DEF/*.cpp" + "${E2SIM_ROOT}/src/SCTP/*.cpp" + "${E2SIM_ROOT}/src/E2AP/*.c" + "${E2SIM_ROOT}/src/E2AP/*.cpp" + "${E2SIM_ROOT}/ASN1c/*.c" + ) +add_executable(ric_wlg ${WLG_SOURCES}) +target_link_libraries( ric_wlg ${SCTP_STD_LIB} ) + +#---------------------------------------------- +file(GLOB RICPERF_SOURCES + "${E2SIM_ROOT}/test/WLG/ric_perf.cpp" + "${E2SIM_ROOT}/src/DEF/*.cpp" + "${E2SIM_ROOT}/src/SCTP/*.cpp" + "${E2SIM_ROOT}/src/E2AP/*.c" + "${E2SIM_ROOT}/src/E2AP/*.cpp" + "${E2SIM_ROOT}/ASN1c/*.c" + ) +add_executable(ric_perf ${RICPERF_SOURCES}) +target_link_libraries( ric_perf ${SCTP_STD_LIB} ) diff --git a/simulators/e2sim/build_docker b/simulators/e2sim/test/WLG/build_wlg.sh similarity index 95% rename from simulators/e2sim/build_docker rename to simulators/e2sim/test/WLG/build_wlg.sh index b04e565..2f81b56 100755 --- a/simulators/e2sim/build_docker +++ b/simulators/e2sim/test/WLG/build_wlg.sh @@ -19,4 +19,9 @@ #******************************************************************************/ set -e -sudo docker build -f docker/Dockerfile -t e2agent . + +mkdir -p build +cd build +rm -rf CMakeCache.txt +cmake .. +make -j`nproc` diff --git a/simulators/e2sim/test/WLG/ric_perf.cpp b/simulators/e2sim/test/WLG/ric_perf.cpp new file mode 100644 index 0000000..ae140f8 --- /dev/null +++ b/simulators/e2sim/test/WLG/ric_perf.cpp @@ -0,0 +1,287 @@ +/***************************************************************************** +# * +# Copyright 2019 AT&T Intellectual Property * +# Copyright 2019 Nokia * +# * +# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * +# * +# 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. * +# * +******************************************************************************/ + +#include +#include +#include + +#include "e2sim_sctp.hpp" +#include "e2ap_message_handler.hpp" + +extern "C" { + #include "e2sim_defs.h" + #include "E2AP-PDU.h" + #include "e2ap_asn1c_codec.h" + + #include "ProtocolIE-Field.h" +} + +using namespace std; + +void encode_and_send_sctp_data(E2AP_PDU_t* pdu, int client_fd) +{ + uint8_t *buf; + sctp_buffer_t data; + + data.len = e2ap_asn1c_encode_pdu(pdu, &buf); + memcpy(data.buffer, buf, data.len); + + sctp_send_data(client_fd, data); +} + +void wait_for_sctp_data(int client_fd) +{ + sctp_buffer_t recv_buf; + if(sctp_receive_data(client_fd, recv_buf) > 0) + { + LOG_I("[SCTP] Received new data of size %d", recv_buf.len); + e2ap_handle_sctp_data(client_fd, recv_buf); + } +} + +void set_seqnum(E2AP_PDU_t* pdu) +{ + InitiatingMessage_t *initiatingMessage = pdu->choice.initiatingMessage; + // xer_fprint(stdout, &asn_DEF_InitiatingMessage, (void *)initiatingMessage); + + RICsubscriptionRequest_t *request = &initiatingMessage->value.choice.RICsubscriptionRequest; + xer_fprint(stdout, &asn_DEF_RICsubscriptionRequest, (void *)request); + + LOG_I("num of IEs = %d", request->protocolIEs.list.count); + + RICsubscriptionRequest_IEs_t *ie; + + ie = request->protocolIEs.list.array[2]; + + xer_fprint(stdout, &asn_DEF_RICsubscription, (void *)ie); + + // e2ap_asn1c_print_pdu(pdu); +} + +int subresponse_get_sequenceNum(E2AP_PDU_t* pdu) +{ + SuccessfulOutcome_t *responseMsg = pdu->choice.successfulOutcome; + + RICrequestID_t *requestid; + + int num_IEs = responseMsg->value.choice.RICsubscriptionResponse.protocolIEs.list.count; + + for(int edx = 0; edx < num_IEs; edx++) + { + RICsubscriptionResponse_IEs_t *memb_ptr = + responseMsg->value.choice.RICsubscriptionResponse.protocolIEs.list.array[edx]; + + switch(memb_ptr->id) + { + case (ProtocolIE_ID_id_RICrequestID): + requestid = &memb_ptr->value.choice.RICrequestID; + // xer_fprint(stdout, &asn_DEF_RICrequestID, (void *)requestid); + return requestid->ricRequestSequenceNumber; + break; + } + } +} + +void subrequest_set_sequenceNum(E2AP_PDU_t* pdu, int seq) +{ + InitiatingMessage_t *initiatingMessage = pdu->choice.initiatingMessage; + + RICrequestID_t *requestid; + + int num_IEs = initiatingMessage->value.choice.RICsubscriptionRequest.protocolIEs.list.count; + + for(int edx = 0; edx < num_IEs; edx++) + { + RICsubscriptionRequest_IEs_t *memb_ptr = + initiatingMessage->value.choice.RICsubscriptionRequest.protocolIEs.list.array[edx]; + + switch(memb_ptr->id) + { + case (ProtocolIE_ID_id_RICrequestID): + requestid = &memb_ptr->value.choice.RICrequestID; + requestid->ricRequestSequenceNumber = seq; + break; + } + } + +} + +void subscription_response_get_field(E2AP_PDU_t* pdu) +{ + SuccessfulOutcome_t *responseMsg = pdu->choice.successfulOutcome; + + RICrequestID_t *requestid; + RANfunctionID_t * ranfunctionid; + RICsubscription_t * ricsubscription; + + int requestID_val, sequenceNum; + + int num_IEs = responseMsg->value.choice.RICsubscriptionResponse.protocolIEs.list.count; + + LOG_I("num of IEs = %d", num_IEs); + + for(int edx = 0; edx < num_IEs; edx++) + { + RICsubscriptionResponse_IEs_t *memb_ptr = + responseMsg->value.choice.RICsubscriptionResponse.protocolIEs.list.array[edx]; + + switch(memb_ptr->id) + { + case (ProtocolIE_ID_id_RICrequestID): + requestid = &memb_ptr->value.choice.RICrequestID; + xer_fprint(stdout, &asn_DEF_RICrequestID, (void *)requestid); + requestID_val = requestid->ricRequestorID; + sequenceNum = requestid->ricRequestSequenceNumber; + requestid->ricRequestSequenceNumber = 202; + break; + + case (ProtocolIE_ID_id_RANfunctionID): + ranfunctionid = &memb_ptr->value.choice.RANfunctionID; + xer_fprint(stdout, &asn_DEF_RANfunctionID, (void *)ranfunctionid); + break; + + // case (ProtocolIE_ID_id_RICsubscription): + // ricsubscription = &memb_ptr->value.choice.RICsubscription; + // xer_fprint(stdout, &asn_DEF_RICsubscription, (void *)ricsubscription); + // break; + } + } + + LOG_I("Request ID = %d, seq = %d", requestID_val, sequenceNum); +} + +void subscription_request_get_field(E2AP_PDU_t* pdu) +{ + InitiatingMessage_t *initiatingMessage = pdu->choice.initiatingMessage; + + RICrequestID_t *requestid; + RANfunctionID_t * ranfunctionid; + RICsubscription_t * ricsubscription; + + int num_IEs = initiatingMessage->value.choice.RICsubscriptionRequest.protocolIEs.list.count; + + LOG_I("num of IEs = %d", num_IEs); + + for(int edx = 0; edx < num_IEs; edx++) + { + RICsubscriptionRequest_IEs_t *memb_ptr = + initiatingMessage->value.choice.RICsubscriptionRequest.protocolIEs.list.array[edx]; + + switch(memb_ptr->id) + { + case (ProtocolIE_ID_id_RICrequestID): + requestid = &memb_ptr->value.choice.RICrequestID; + xer_fprint(stdout, &asn_DEF_RICrequestID, (void *)requestid); + break; + + case (ProtocolIE_ID_id_RANfunctionID): + ranfunctionid = &memb_ptr->value.choice.RANfunctionID; + xer_fprint(stdout, &asn_DEF_RANfunctionID, (void *)ranfunctionid); + break; + + case (ProtocolIE_ID_id_RICsubscription): + ricsubscription = &memb_ptr->value.choice.RICsubscription; + xer_fprint(stdout, &asn_DEF_RICsubscription, (void *)ricsubscription); + break; + } + } +} + +int main(int argc, char* argv[]){ + LOG_I("Start RIC Simulator - Performance Test"); + + options_t ops = read_input_options(argc, argv); + int client_fd = sctp_start_client(ops.server_ip, ops.server_port); + + //1. Send ENDCX2Setup + E2AP_PDU_t* pdu_setup = e2ap_xml_to_pdu("E2AP_ENDCX2SetupRequest.xml"); + // e2ap_asn1c_print_pdu(pdu_setup); + encode_and_send_sctp_data(pdu_setup, client_fd); + LOG_I("[SCTP] Sent ENDC X2 SETUP REQUEST"); + + //2. Receive ENDCX2SetupResponse + wait_for_sctp_data(client_fd); + + //3. Send RICSubscriptionRequest + E2AP_PDU_t* pdu_sub = e2ap_xml_to_pdu("E2AP_RICsubscriptionRequest_Ashwin.xml"); + e2ap_asn1c_print_pdu(pdu_sub); + encode_and_send_sctp_data(pdu_sub, client_fd); + LOG_I("[SCTP] Sent RIC SUBSCRIPTION REQUEST"); + + + //4. Receive RIC SUBSCRIPT RESPONSE + int count = 0; + + while(1) + { + usleep(1000); //sleep for one ms + + sctp_buffer_t recv_buf; + + int res_seq; + + if(sctp_receive_data(client_fd, recv_buf) > 0) + { + LOG_I("[SCTP] Received new data of size %d", recv_buf.len); + // e2ap_handle_sctp_data(client_fd, recv_buf); + + E2AP_PDU_t* res_pdu = new E2AP_PDU_t(); + + e2ap_asn1c_decode_pdu(res_pdu, recv_buf.buffer, recv_buf.len); + + int procedureCode = e2ap_asn1c_get_procedureCode(res_pdu); + int index = (int)res_pdu->present; + + if(index == E2AP_PDU_PR_successfulOutcome && \ + procedureCode == ProcedureCode_id_ricSubscription) + { + res_seq =subresponse_get_sequenceNum(res_pdu); + count++; + + LOG_I("Received RIC SUBSCRIPTION RESPONSE, seq = %d, totalCount = %d",\ + res_seq, count); + + //Put res_seq in new subscription request + E2AP_PDU_t* req_pdu = e2ap_xml_to_pdu("E2AP_RICsubscriptionRequest.xml"); + subrequest_set_sequenceNum(req_pdu, res_seq); + // e2ap_asn1c_print_pdu(req_pdu); + + encode_and_send_sctp_data(req_pdu, client_fd); + LOG_I("Send new SUBSCRIPT REQUEST, seq = %d", res_seq); + } + + } + } + + + // E2AP_PDU_t* res_pdu = e2ap_xml_to_pdu("E2AP_RICsubscriptionResponse.xml"); + // + // //Extract subscription response sequence number + // int res_seq = subresponse_get_sequenceNum(res_pdu); + // LOG_I("Subscription Response SeqNo = %d", res_seq); + // + // //Put responseSeq in new subscription request + // E2AP_PDU_t* req_pdu = e2ap_xml_to_pdu("E2AP_RICsubscriptionRequest.xml"); + // + // subrequest_set_sequenceNum(req_pdu, res_seq); + + // e2ap_asn1c_print_pdu(req_pdu); + + return 0; +} diff --git a/simulators/e2sim/src/E2AP/e2ap_asn_codec.cpp b/simulators/e2sim/test/WLG/ric_wlg.cpp similarity index 60% rename from simulators/e2sim/src/E2AP/e2ap_asn_codec.cpp rename to simulators/e2sim/test/WLG/ric_wlg.cpp index a1a6bee..309153d 100644 --- a/simulators/e2sim/src/E2AP/e2ap_asn_codec.cpp +++ b/simulators/e2sim/test/WLG/ric_wlg.cpp @@ -1,59 +1,61 @@ -/***************************************************************************** -# * -# Copyright 2019 AT&T Intellectual Property * -# Copyright 2019 Nokia * -# * -# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * -# * -# 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. * -# * -******************************************************************************/ - -#include "e2ap_asn_codec.hpp" - -void e2ap_encode_pdu(e2ap_pdu_t* pdu, unsigned char* buf, int buf_size, int &encoded_size) -{ - char err_buf[ERROR_MESSAGE_BUFFER]; - - encoded_size = e2ap_asn_per_encode(pdu, buf, buf_size, err_buf, sizeof(err_buf)); - - if(encoded_size != -1) - { - LOG_D("[E2AP] ASN Encode successful, encoded_size = %d", encoded_size); - } - else - { - LOG_E("[E2AP] Encode error: %s", err_buf); - exit(1); - } - -} - -void e2ap_decode_pdu(e2ap_pdu_t* pdu, unsigned char* buf, int &encoded_size) -{ - char err_buf[ERROR_MESSAGE_BUFFER]; - - int rc = e2ap_asn_per_decode(pdu, buf, encoded_size, err_buf, sizeof(err_buf)); - if(rc == -1) { - LOG_E("[E2AP] Decode error: %s", err_buf); - } else { - LOG_D("[E2AP] ASN decode successful"); - } -} - -void e2ap_print_pdu(e2ap_pdu_t* pdu) -{ - char pdu_str[PDU_PRINT_BUFFER]; - - e2ap_asn_print(pdu, pdu_str, sizeof(pdu_str)); - - LOG_D("[E2AP] %s", pdu_str); -} +/***************************************************************************** +# * +# Copyright 2019 AT&T Intellectual Property * +# Copyright 2019 Nokia * +# * +# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * +# * +# 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. * +# * +******************************************************************************/ + +#include +#include +#include + +#include "e2sim_sctp.hpp" +#include "e2ap_message_handler.hpp" + +extern "C" { + #include "e2sim_defs.h" + #include "E2AP-PDU.h" + #include "e2ap_asn1c_codec.h" + + #include "ProtocolIE-Field.h" +} + +using namespace std; + + +int main(int argc, char* argv[]){ + LOG_I("Start RIC WLG"); + + options_t ops = read_input_options(argc, argv); + + int server_fd = sctp_start_server(ops.server_ip, ops.server_port); + int client_fd = sctp_accept_connection(ops.server_ip, server_fd); + + sctp_buffer_t recv_buf; + + LOG_I("[SCTP] Waiting for SCTP data"); + + while(1) //constantly looking for data on SCTP interface + { + if(sctp_receive_data(client_fd, recv_buf) <= 0) + break; + + LOG_I("[SCTP] Received new data of size %d", recv_buf.len); + + e2ap_handle_sctp_data(client_fd, recv_buf); + } + + return 0; +} diff --git a/simulators/e2sim/test/X2/CMakeLists.txt b/simulators/e2sim/test/X2/CMakeLists.txt new file mode 100644 index 0000000..b257505 --- /dev/null +++ b/simulators/e2sim/test/X2/CMakeLists.txt @@ -0,0 +1,49 @@ +#/***************************************************************************** +# * +# Copyright 2019 AT&T Intellectual Property * +# Copyright 2019 Nokia * +# * +# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * +# * +# 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. * +# * +#******************************************************************************/ + +cmake_minimum_required(VERSION 3.5.1) +set(CMAKE_CXX_COMPILER "/usr/bin/g++") +set(CMAKE_CXX_STANDARD 14) + +add_definitions("-D ASN_DISABLE_OER_SUPPORT") + +project(x2term) + +set (E2SIM_ROOT ../../) + +include_directories("${E2SIM_ROOT}/src") +include_directories("${E2SIM_ROOT}/src/DEF") +include_directories("${E2SIM_ROOT}/src/SCTP/") +include_directories("${E2SIM_ROOT}/src/E2AP") +include_directories("${E2SIM_ROOT}/src/E2AP/E2SM") +include_directories("${E2SIM_ROOT}/ASN1c") + +find_library( SCTP_STD_LIB sctp ) #needed for sctp_sendmsg + +#---------------------------------------------- +file(GLOB X2TERM_SOURCES + "${E2SIM_ROOT}/test/X2/x2term.cpp" + "${E2SIM_ROOT}/src/DEF/*.cpp" + "${E2SIM_ROOT}/src/SCTP/*.cpp" + "${E2SIM_ROOT}/src/E2AP/*.c" + "${E2SIM_ROOT}/src/E2AP/*.cpp" + "${E2SIM_ROOT}/ASN1c/*.c" + ) +add_executable(x2term ${X2TERM_SOURCES}) +target_link_libraries( x2term ${SCTP_STD_LIB} ) diff --git a/simulators/e2sim/src/x2agent.cpp b/simulators/e2sim/test/X2/x2agent.cpp similarity index 100% rename from simulators/e2sim/src/x2agent.cpp rename to simulators/e2sim/test/X2/x2agent.cpp diff --git a/simulators/e2sim/test/X2/x2term.cpp b/simulators/e2sim/test/X2/x2term.cpp new file mode 100644 index 0000000..9feccca --- /dev/null +++ b/simulators/e2sim/test/X2/x2term.cpp @@ -0,0 +1,72 @@ +/***************************************************************************** +# * +# Copyright 2019 AT&T Intellectual Property * +# Copyright 2019 Nokia * +# * +# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * +# * +# 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. * +# * +******************************************************************************/ + +#include +#include +#include + +#include "e2sim_sctp.hpp" +#include "e2ap_message_handler.hpp" + +extern "C" { + #include "e2sim_defs.h" + #include "E2AP-PDU.h" + #include "e2ap_asn1c_codec.h" +} + +using namespace std; + +void encode_and_send_sctp_data(E2AP_PDU_t* pdu, int client_fd) +{ + uint8_t *buf; + sctp_buffer_t data; + + data.len = e2ap_asn1c_encode_pdu(pdu, &buf); + memcpy(data.buffer, buf, data.len); + + // sctp_send_data(client_fd, data); + sctp_send_data_X2AP(client_fd, data); +} + +void wait_for_sctp_data(int client_fd) +{ + sctp_buffer_t recv_buf; + if(sctp_receive_data(client_fd, recv_buf) > 0) + { + LOG_I("[SCTP] Received new data of size %d", recv_buf.len); + e2ap_handle_sctp_data(client_fd, recv_buf); + } +} + + +int main(int argc, char* argv[]){ + LOG_I("Start RIC Simulator"); + + options_t ops = read_input_options(argc, argv); + int client_fd = sctp_start_client(ops.server_ip, ops.server_port); + + //Send X2 Setup Request + E2AP_PDU_t* pdu_setup = e2ap_xml_to_pdu("E2AP_X2SetupRequest.xml"); + e2ap_asn1c_print_pdu(pdu_setup); + + encode_and_send_sctp_data(pdu_setup, client_fd); + + //wait to receive X2SetupResponse + wait_for_sctp_data(client_fd); +} diff --git a/simulators/e2sim/src/x2termination_test.cpp b/simulators/e2sim/test/X2/x2termination_test.cpp similarity index 98% rename from simulators/e2sim/src/x2termination_test.cpp rename to simulators/e2sim/test/X2/x2termination_test.cpp index c6c9138..1953ce6 100644 --- a/simulators/e2sim/src/x2termination_test.cpp +++ b/simulators/e2sim/test/X2/x2termination_test.cpp @@ -111,8 +111,8 @@ int main(int argc, char* argv[]){ int client_fd = sctp_start_client(ops.server_ip, ops.server_port); - // test_X2Setup(client_fd); - test_ENDCX2Setup(client_fd); + test_X2Setup(client_fd); + // test_ENDCX2Setup(client_fd); return 0; diff --git a/simulators/e2sim/src/rmr_interface/README b/simulators/e2sim/test/rmr_interface/README similarity index 100% rename from simulators/e2sim/src/rmr_interface/README rename to simulators/e2sim/test/rmr_interface/README diff --git a/simulators/e2sim/src/rmr_interface/rmr_install.sh b/simulators/e2sim/test/rmr_interface/rmr_install.sh similarity index 100% rename from simulators/e2sim/src/rmr_interface/rmr_install.sh rename to simulators/e2sim/test/rmr_interface/rmr_install.sh diff --git a/simulators/e2sim/src/rmr_interface/tests/receiver/build_and_run_recvr.sh b/simulators/e2sim/test/rmr_interface/tests/receiver/build_and_run_recvr.sh similarity index 100% rename from simulators/e2sim/src/rmr_interface/tests/receiver/build_and_run_recvr.sh rename to simulators/e2sim/test/rmr_interface/tests/receiver/build_and_run_recvr.sh diff --git a/simulators/e2sim/src/rmr_interface/tests/receiver/rmr_rcvr.c b/simulators/e2sim/test/rmr_interface/tests/receiver/rmr_rcvr.c similarity index 100% rename from simulators/e2sim/src/rmr_interface/tests/receiver/rmr_rcvr.c rename to simulators/e2sim/test/rmr_interface/tests/receiver/rmr_rcvr.c diff --git a/simulators/e2sim/src/rmr_interface/tests/sender/build_and_run_sender.sh b/simulators/e2sim/test/rmr_interface/tests/sender/build_and_run_sender.sh similarity index 100% rename from simulators/e2sim/src/rmr_interface/tests/sender/build_and_run_sender.sh rename to simulators/e2sim/test/rmr_interface/tests/sender/build_and_run_sender.sh diff --git a/simulators/e2sim/src/rmr_interface/tests/sender/rmr_sender.c b/simulators/e2sim/test/rmr_interface/tests/sender/rmr_sender.c similarity index 100% rename from simulators/e2sim/src/rmr_interface/tests/sender/rmr_sender.c rename to simulators/e2sim/test/rmr_interface/tests/sender/rmr_sender.c diff --git a/simulators/e2sim/src/rmr_interface/tests/sender/rmr_wrapper.h b/simulators/e2sim/test/rmr_interface/tests/sender/rmr_wrapper.h similarity index 100% rename from simulators/e2sim/src/rmr_interface/tests/sender/rmr_wrapper.h rename to simulators/e2sim/test/rmr_interface/tests/sender/rmr_wrapper.h diff --git a/simulators/e2sim/tools/asn_defs/generate_e2ap_e2sm_codes b/simulators/e2sim/tools/asn_defs/generate_e2ap_e2sm_codes new file mode 100755 index 0000000..87ced95 --- /dev/null +++ b/simulators/e2sim/tools/asn_defs/generate_e2ap_e2sm_codes @@ -0,0 +1,39 @@ +#!/bin/bash +#/***************************************************************************** +# * +# Copyright 2019 AT&T Intellectual Property * +# Copyright 2019 Nokia * +# * +# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * +# * +# 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. * +# * +#******************************************************************************/ + +E2AP_asn="e2ap-v031.asn" +E2SM_asn="e2sm-gNB-X2-release-1-v041.asn" +X2AP_asn="x2ap-no-desc-15-04.asn" + +GEN_DIR=../../src/ASN1c/ + +rm -f $GEN_DIR/*.c $GEN_DIR/*.h + +asn1c -pdu=all -fcompound-names -gen-PER -no-gen-OER -no-gen-example \ + -fno-include-deps -D $GEN_DIR $E2AP_asn $X2AP_asn \ + |& egrep -v "^Copied|^Compiled" | sort -u + +asn1c -pdu=all -fcompound-names -gen-PER -no-gen-OER -no-gen-example \ + -fno-include-deps -D $GEN_DIR $E2SM_asn $X2AP_asn \ + |& egrep -v "^Copied|^Compiled" | sort -u + +echo "ASN1 C codes generated at $GEN_DIR" + +# asn1c -fcompound-names -fno-include-deps -findirect-choice -gen-PER -no-gen-OER /tmp/e2ap-v031.asn /tmp/x2ap-no-desc-15-04.asn diff --git a/simulators/e2sim/tools/build_helper.bash b/simulators/e2sim/tools/build_helper.bash index 647d597..1759621 100644 --- a/simulators/e2sim/tools/build_helper.bash +++ b/simulators/e2sim/tools/build_helper.bash @@ -1,20 +1,21 @@ -# -# -# Copyright 2019 AT&T Intellectual Property -# Copyright 2019 Nokia -# -# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 -# -# 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. -# +#/***************************************************************************** +# * +# Copyright 2019 AT&T Intellectual Property * +# Copyright 2019 Nokia * +# * +# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * +# * +# 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. * +# * +#******************************************************************************/ ####################################### # Helper Func diff --git a/simulators/e2sim/build_and_run_e2agent b/simulators/e2sim/tools/install_asn1c similarity index 81% rename from simulators/e2sim/build_and_run_e2agent rename to simulators/e2sim/tools/install_asn1c index 1af78d6..7d1391f 100755 --- a/simulators/e2sim/build_and_run_e2agent +++ b/simulators/e2sim/tools/install_asn1c @@ -1,4 +1,5 @@ -#***************************************************************************** +#!/bin/bash +#/***************************************************************************** # * # Copyright 2019 AT&T Intellectual Property * # Copyright 2019 Nokia * @@ -15,18 +16,16 @@ # See the License for the specific language governing permissions and * # limitations under the License. * # * -#***************************************************************************** +#******************************************************************************/ -# Run a default build and run the e2sim executable - -set -e - -clear - -./build_e2sim --clean - -./build_e2sim - -echo "===================== Running E2 Agent Simulator ========================" - -./build/e2agent +echo "Will install asn1c" +sudo rm -rf asn1c +git clone https://gerrit.o-ran-sc.org/r/com/asn1c.git +cd asn1c/ +autoreconf -iv +./configure +cd examples +chmod u+x crfc2asn1.pl +cd .. +make +sudo make install diff --git a/simulators/e2sim/tools/install_dependencies b/simulators/e2sim/tools/install_dependencies new file mode 100755 index 0000000..c5b3d7b --- /dev/null +++ b/simulators/e2sim/tools/install_dependencies @@ -0,0 +1,38 @@ +#!/bin/bash +#/***************************************************************************** +# * +# Copyright 2019 AT&T Intellectual Property * +# Copyright 2019 Nokia * +# * +# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * +# * +# 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. * +# * +#******************************************************************************/ + +sudo apt-get update \ + && sudo apt-get install -y \ + build-essential \ + git \ + cmake \ + libsctp-dev \ + lksctp-tools \ + autoconf \ + automake \ + libtool \ + bison \ + flex \ + libboost-all-dev \ + iputils-ping \ + net-tools \ + nano \ + vim \ + && sudo apt-get clean -- 2.16.6