fixeria has uploaded this change for review.

View Change

[REST] Integrate Erlang REST Framework

Change-Id: I20ad3208b8cd4f5483992e3bf22af30ff62b0311
Related: SYS#7066
---
M config/sys.config
M rebar.config
M rebar.lock
M src/osmo_s1gw.app.src
M src/osmo_s1gw.erl
M src/osmo_s1gw_sup.erl
A src/rest_server.erl
7 files changed, 106 insertions(+), 4 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/erlang/osmo-s1gw refs/changes/98/41098/1
diff --git a/config/sys.config b/config/sys.config
index 4e5a80c..5184ebb 100644
--- a/config/sys.config
+++ b/config/sys.config
@@ -25,7 +25,9 @@
%% {gtpu_kpi_table_name, "osmo-s1gw"}, %% the NFT table name to be used by this process
%% {gtpu_kpi_ul_addr, s1ap}, %% GTP-U UL address: s1ap | sctp (default: learn from S1AP)
%% {gtpu_kpi_dl_addr, s1ap}, %% GTP-U DL address: s1ap | sctp (default: learn from S1AP)
-%% {gtpu_kpi_interval, 3000} %% counter reporting interval (ms)
+%% {gtpu_kpi_interval, 3000}, %% counter reporting interval (ms)
+%% {rest_srv_port, 8080}, %% REST server port (default: 8080)
+%% {rest_srv_swagger_ui, true} %% REST Swagger UI (default: true)
]},
%% ================================================================================
%% kernel config
diff --git a/rebar.config b/rebar.config
index de8b023..d729401 100644
--- a/rebar.config
+++ b/rebar.config
@@ -16,7 +16,9 @@
{exometer_core,
{git, "https://github.com/Feuerlabs/exometer_core.git", {branch, "master"}}},
{exometer_report_statsd,
- {git, "https://github.com/osmocom/exometer_report_statsd.git", {branch, "counters"}}}
+ {git, "https://github.com/osmocom/exometer_report_statsd.git", {branch, "counters"}}},
+ {erf,
+ {git, "https://github.com/nomasystems/erf.git", {tag, "0.1.2"}}}
]}.

%% test deps
diff --git a/rebar.lock b/rebar.lock
index 647bca0..1efe90b 100644
--- a/rebar.lock
+++ b/rebar.lock
@@ -1,9 +1,17 @@
{"1.2.0",
[{<<"cut">>,{pkg,<<"cut">>,<<"1.0.3">>},1},
+ {<<"elli">>,
+ {git,"https://github.com/elli-lib/elli.git",
+ {ref,"3ec352293ef493c142767127f4113c85541c32cc"}},
+ 1},
{<<"enftables">>,
{git,"https://gitea.osmocom.org/erlang/enftables.git",
{ref,"8b9b4acd624b9d0d3a58d725f11afa96d31fe5d7"}},
0},
+ {<<"erf">>,
+ {git,"https://github.com/nomasystems/erf.git",
+ {ref,"0dac504f9988d3b96154c1e80b8af3defb772b58"}},
+ 0},
{<<"exometer_core">>,
{git,"https://github.com/Feuerlabs/exometer_core.git",
{ref,"fc744c45bbe5de2ab0ee550e2667f93f7abbb618"}},
@@ -25,6 +33,18 @@
{git,"https://gitea.osmocom.org/erlang/logger_gsmtap.git",
{ref,"5194badde912a8179f2a818155ee2b01f9e6377e"}},
0},
+ {<<"ncalendar">>,
+ {git,"https://github.com/nomasystems/ncalendar.git",
+ {ref,"aa5615f6723585e45e82fa5524cb976cdfe3d7f7"}},
+ 2},
+ {<<"ndto">>,
+ {git,"https://github.com/nomasystems/ndto.git",
+ {ref,"295281b72ea4ac85e7c4d5ca42337c68b1aac137"}},
+ 1},
+ {<<"njson">>,
+ {git,"https://github.com/nomasystems/njson.git",
+ {ref,"94c586b92a7e24c403089cdbe2994b7e7c87b9cc"}},
+ 1},
{<<"parse_trans">>,{pkg,<<"parse_trans">>,<<"3.4.1">>},1},
{<<"pfcplib">>,
{git,"https://github.com/travelping/pfcplib.git",
diff --git a/src/osmo_s1gw.app.src b/src/osmo_s1gw.app.src
index 13240dd..2885cc6 100644
--- a/src/osmo_s1gw.app.src
+++ b/src/osmo_s1gw.app.src
@@ -12,7 +12,8 @@
pfcplib,
enftables,
exometer_core,
- exometer_report_statsd
+ exometer_report_statsd,
+ erf
]},
{modules, []},
{mod, {osmo_s1gw_app, []}},
diff --git a/src/osmo_s1gw.erl b/src/osmo_s1gw.erl
index d5f9efd..e90d927 100644
--- a/src/osmo_s1gw.erl
+++ b/src/osmo_s1gw.erl
@@ -35,6 +35,7 @@
-module(osmo_s1gw).

-export([get_env/2,
+ get_priv/1,
main/1]).

-define(ENV_APP_NAME, osmo_s1gw).
@@ -52,6 +53,14 @@
application:get_env(?ENV_APP_NAME, Param, Default).


+-spec get_priv(Name) -> Path
+ when Name :: file:filename_all(),
+ Path :: file:filename_all().
+get_priv(Name) ->
+ PrivDir = code:priv_dir(?ENV_APP_NAME),
+ filename:join(PrivDir, Name).
+
+
main(_Args) ->
application:ensure_all_started(?MODULE),
timer:sleep(infinity).
diff --git a/src/osmo_s1gw_sup.erl b/src/osmo_s1gw_sup.erl
index 934f040..1616fe5 100644
--- a/src/osmo_s1gw_sup.erl
+++ b/src/osmo_s1gw_sup.erl
@@ -53,6 +53,8 @@
-define(ENV_DEFAULT_GTPU_KPI_ENABLE, false).
-define(ENV_DEFAULT_GTPU_KPI_TABLE_NAME, "osmo-s1gw").
-define(ENV_DEFAULT_GTPU_KPI_INTERVAL, 3000).
+-define(ENV_DEFAULT_REST_SRV_PORT, 8080).
+-define(ENV_DEFAULT_REST_SRV_SWAGGER_UI, true).

%% ------------------------------------------------------------------
%% supervisor API
@@ -87,9 +89,14 @@
5000,
worker,
[gtpu_kpi]},
+ RestServer = {rest_server, {erf, start_link, [rest_server_cfg()]},
+ permanent,
+ 5000,
+ worker,
+ [erf]},

s1gw_metrics:init(),
- {ok, {{one_for_one, 5, 10}, [EnbRegistry, SctpServer, PfcpPeer, GtpuKpi]}}.
+ {ok, {{one_for_one, 5, 10}, [EnbRegistry, SctpServer, PfcpPeer, GtpuKpi, RestServer]}}.


%% ------------------------------------------------------------------
@@ -126,4 +133,13 @@
table_name => osmo_s1gw:get_env(gtpu_kpi_table_name, ?ENV_DEFAULT_GTPU_KPI_TABLE_NAME),
interval => osmo_s1gw:get_env(gtpu_kpi_interval, ?ENV_DEFAULT_GTPU_KPI_INTERVAL)}.

+
+-spec rest_server_cfg() -> erf:conf().
+rest_server_cfg() ->
+ #{callback => rest_server,
+ spec_path => list_to_binary(osmo_s1gw:get_priv("openapi.json")),
+ port => osmo_s1gw:get_env(rest_srv_port, ?ENV_DEFAULT_REST_SRV_PORT),
+ swagger_ui => osmo_s1gw:get_env(rest_srv_swagger_ui, ?ENV_DEFAULT_REST_SRV_SWAGGER_UI)}.
+
+
%% vim:set ts=4 sw=4 et:
diff --git a/src/rest_server.erl b/src/rest_server.erl
new file mode 100644
index 0000000..c4e0373
--- /dev/null
+++ b/src/rest_server.erl
@@ -0,0 +1,52 @@
+%% Copyright (C) 2025 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
+%% Author: Vadim Yanitskiy <vyanitskiy@sysmocom.de>
+%%
+%% All Rights Reserved
+%%
+%% SPDX-License-Identifier: AGPL-3.0-or-later
+%%
+%% This program is free software; you can redistribute it and/or modify
+%% it under the terms of the GNU Affero General Public License as
+%% published by the Free Software Foundation; either version 3 of the
+%% License, or (at your option) any later version.
+%%
+%% This program is distributed in the hope that it will be useful,
+%% but WITHOUT ANY WARRANTY; without even the implied warranty of
+%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+%% GNU General Public License for more details.
+%%
+%% You should have received a copy of the GNU Affero General Public License
+%% along with this program. If not, see <https://www.gnu.org/licenses/>.
+%%
+%% Additional Permission under GNU AGPL version 3 section 7:
+%%
+%% If you modify this Program, or any covered work, by linking or
+%% combining it with runtime libraries of Erlang/OTP as released by
+%% Ericsson on https://www.erlang.org (or a modified version of these
+%% libraries), containing parts covered by the terms of the Erlang Public
+%% License (https://www.erlang.org/EPLICENSE), the licensors of this
+%% Program grant you additional permission to convey the resulting work
+%% without the need to license the runtime libraries of Erlang/OTP under
+%% the GNU Affero General Public License. Corresponding Source for a
+%% non-source form of such a combination shall include the source code
+%% for the parts of the runtime libraries of Erlang/OTP used as well as
+%% that of the covered work.
+
+-module(rest_server).
+
+-export([]).
+
+-include_lib("kernel/include/logger.hrl").
+
+
+%% ------------------------------------------------------------------
+%% public API
+%% ------------------------------------------------------------------
+
+
+%% ------------------------------------------------------------------
+%% private API
+%% ------------------------------------------------------------------
+
+
+%% vim:set ts=4 sw=4 et:

To view, visit change 41098. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: erlang/osmo-s1gw
Gerrit-Branch: master
Gerrit-Change-Id: I20ad3208b8cd4f5483992e3bf22af30ff62b0311
Gerrit-Change-Number: 41098
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy@sysmocom.de>