diff --git a/CMakeLists.txt b/CMakeLists.txt index 7249eda..d802104 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,10 @@ add_subdirectory(libs) add_executable(iqos_xapp src/main.cpp) ## Link libraries -target_include_directories(iqos_xapp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) +target_include_directories(iqos_xapp PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${CMAKE_CURRENT_SOURCE_DIR}/libs/flexric/src/xApp +) target_link_libraries(iqos_xapp PUBLIC e42_xapp -pthread diff --git a/README.md b/README.md index 5813981..3e86ee8 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,31 @@ Add a paragraph about the application here... ## Requirements -- Swig v4.1 or newer (for xapp_sdk); -- libsctp-dev -- libpcre2-dev +- Near-RT RIC FlexRIC; -## Getting Started \ No newline at end of file +## Getting Started + +### Installing the xApp + +After installing FlexRIC, clone the xApp repository with the following command. + +```shell +git clone --recurse-submodules -j8 git@github.com:gercom-ufpa/iqos-xapp.git +``` + +Build the xApp. + +```shell +cd iqos-xapp +mkdir -p build && cd build +cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DE2AP_VERSION=E2AP_V3 -DKPM_VERSION=KPM_V3_00 .. +ninja iqos-xapp +``` + +### Running the xApp + +After building, the xApp can be run with the following command. + +```shell +./iqos-xapp -c xApp.conf +``` diff --git a/configs/xApp.conf b/configs/xApp.conf new file mode 100644 index 0000000..3a5aca5 --- /dev/null +++ b/configs/xApp.conf @@ -0,0 +1,6 @@ +[NEAR-RIC] +NEAR_RIC_IP = 127.0.0.1 + +[XAPP] +DB_DIR = /tmp/ +DB_NAME = iqos_xapp_db \ No newline at end of file diff --git a/include/defer.hpp b/include/defer.hpp new file mode 100644 index 0000000..d9c4b2e --- /dev/null +++ b/include/defer.hpp @@ -0,0 +1,27 @@ +#ifndef DEFER_HPP +#define DEFER_HPP + +#pragma once + +template +struct privDefer +{ + F f; + explicit privDefer(F f) : f(f) {} + ~privDefer() { f(); } +}; + +template +privDefer defer_func(F f) +{ + return privDefer(f); +} + +#if !defined(DEFER_1) && !defined(DEFER_2) && !defined(DEFER_3) && !defined(defer) +#define DEFER_1(x, y) x##y +#define DEFER_2(x, y) DEFER_1(x, y) +#define DEFER_3(x) DEFER_2(x, __COUNTER__) +#define defer(code) auto DEFER_3(_defer_) = defer_func([&]() { code; }) +#endif + +#endif //DEFER_HPP diff --git a/src/main.cpp b/src/main.cpp index 815c82a..7869ffa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,35 @@ #include +#include -int main() { - std::cout << "Hello, FlexRIC!" << '\n'; - return 0; -} \ No newline at end of file +#include "../libs/flexric/src/xApp/e42_xapp_api.h" +#include "defer.hpp" + +int main(int argc, char *argv[]) { + // format args + fr_args_t args{init_fr_args(argc, argv)}; + + // set FlexRIC IP (just for development) + args.ip = {"192.168.122.20"}; + + // init xApp + init_xapp_api(&args); + sleep(1); + + // get E2 Nodes + e2_node_arr_xapp_t e2Nodes{e2_nodes_xapp_api()}; + assert(e2Nodes.len > 0 && "There are no E2 nodes connected!"); + + // free memory allocated to E2 Nodes when finished + defer(free_e2_node_arr_xapp(&e2Nodes)); + + // TODO: print E2 nodes infos + std::cout << "There are " << static_cast(e2Nodes.len) << " E2 nodes connected" << '\n'; + + // wait until all xApp processes have been completed + while (try_stop_xapp_api() == false) { + usleep(1000); // 1 ms + } + + std::cout << "Hello, FlexRIC :)!" << '\n'; + return EXIT_SUCCESS; +}