fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/40544?usp=email )
Change subject: osmo_s1gw: move get_env/2 here and export it ......................................................................
osmo_s1gw: move get_env/2 here and export it
This allows using osmo_s1gw:get_env/2 from other modules too.
Change-Id: Ie7f29210e759be1a8a3f97533ab724049e70abae --- M src/osmo_s1gw.erl M src/osmo_s1gw_sup.erl 2 files changed, 30 insertions(+), 18 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/erlang/osmo-s1gw refs/changes/44/40544/1
diff --git a/src/osmo_s1gw.erl b/src/osmo_s1gw.erl index 71ac34c..d5f9efd 100644 --- a/src/osmo_s1gw.erl +++ b/src/osmo_s1gw.erl @@ -34,7 +34,23 @@
-module(osmo_s1gw).
--export([main/1]). +-export([get_env/2, + main/1]). + +-define(ENV_APP_NAME, osmo_s1gw). + + +%% ------------------------------------------------------------------ +%% public API +%% ------------------------------------------------------------------ + +-spec get_env(Param, Default) -> Value + when Param :: atom(), + Default :: term(), + Value :: term(). +get_env(Param, Default) -> + application:get_env(?ENV_APP_NAME, Param, Default). +
main(_Args) -> application:ensure_all_started(?MODULE), diff --git a/src/osmo_s1gw_sup.erl b/src/osmo_s1gw_sup.erl index 92f908b..279ad02 100644 --- a/src/osmo_s1gw_sup.erl +++ b/src/osmo_s1gw_sup.erl @@ -41,7 +41,6 @@ -include("s1ap.hrl").
-define(SERVER, ?MODULE). --define(ENV_APP_NAME, osmo_s1gw). -define(ENV_DEFAULT_SCTP_BUFSZ, 65536). -define(ENV_DEFAULT_SCTP_NODELAY, true). -define(ENV_DEFAULT_S1GW_BIND_ADDR, "127.0.1.1"). @@ -61,8 +60,8 @@
init([]) -> - PfcpLocAddr = get_env(pfcp_loc_addr, ?ENV_DEFAULT_PFCP_LOC_ADDR), - PfcpRemAddr = get_env(pfcp_rem_addr, ?ENV_DEFAULT_PFCP_REM_ADDR), + PfcpLocAddr = osmo_s1gw:get_env(pfcp_loc_addr, ?ENV_DEFAULT_PFCP_LOC_ADDR), + PfcpRemAddr = osmo_s1gw:get_env(pfcp_rem_addr, ?ENV_DEFAULT_PFCP_REM_ADDR),
SctpServer = {sctp_server, {sctp_server, start_link, [server_cfg()]}, permanent, @@ -84,28 +83,25 @@ %% private API %% ------------------------------------------------------------------
-get_env(Param, Default) -> - application:get_env(?ENV_APP_NAME, Param, Default). -
-spec client_cfg() -> sctp_client:cfg(). client_cfg() -> - SockOpts = #{sctp_nodelay => get_env(mme_nodelay, ?ENV_DEFAULT_SCTP_NODELAY), - recbuf => get_env(mme_recbuf, ?ENV_DEFAULT_SCTP_BUFSZ), - sndbuf => get_env(mme_sndbuf, ?ENV_DEFAULT_SCTP_BUFSZ)}, - #{laddr => get_env(mme_loc_addr, ?ENV_DEFAULT_MME_LOC_ADDR), - raddr => get_env(mme_rem_addr, ?ENV_DEFAULT_MME_REM_ADDR), - rport => get_env(mme_rem_port, ?ENV_DEFAULT_MME_REM_PORT), + SockOpts = #{sctp_nodelay => osmo_s1gw:get_env(mme_nodelay, ?ENV_DEFAULT_SCTP_NODELAY), + recbuf => osmo_s1gw:get_env(mme_recbuf, ?ENV_DEFAULT_SCTP_BUFSZ), + sndbuf => osmo_s1gw:get_env(mme_sndbuf, ?ENV_DEFAULT_SCTP_BUFSZ)}, + #{laddr => osmo_s1gw:get_env(mme_loc_addr, ?ENV_DEFAULT_MME_LOC_ADDR), + raddr => osmo_s1gw:get_env(mme_rem_addr, ?ENV_DEFAULT_MME_REM_ADDR), + rport => osmo_s1gw:get_env(mme_rem_port, ?ENV_DEFAULT_MME_REM_PORT), sockopts => maps:to_list(SockOpts)}.
-spec server_cfg() -> sctp_server:cfg(). server_cfg() -> - SockOpts = #{sctp_nodelay => get_env(s1gw_nodelay, ?ENV_DEFAULT_SCTP_NODELAY), - recbuf => get_env(s1gw_recbuf, ?ENV_DEFAULT_SCTP_BUFSZ), - sndbuf => get_env(s1gw_sndbuf, ?ENV_DEFAULT_SCTP_BUFSZ)}, - #{laddr => get_env(s1gw_bind_addr, ?ENV_DEFAULT_S1GW_BIND_ADDR), - lport => get_env(s1gw_bind_port, ?ENV_DEFAULT_S1GW_BIND_PORT), + SockOpts = #{sctp_nodelay => osmo_s1gw:get_env(s1gw_nodelay, ?ENV_DEFAULT_SCTP_NODELAY), + recbuf => osmo_s1gw:get_env(s1gw_recbuf, ?ENV_DEFAULT_SCTP_BUFSZ), + sndbuf => osmo_s1gw:get_env(s1gw_sndbuf, ?ENV_DEFAULT_SCTP_BUFSZ)}, + #{laddr => osmo_s1gw:get_env(s1gw_bind_addr, ?ENV_DEFAULT_S1GW_BIND_ADDR), + lport => osmo_s1gw:get_env(s1gw_bind_port, ?ENV_DEFAULT_S1GW_BIND_PORT), sockopts => maps:to_list(SockOpts), handler => sctp_proxy, priv => client_cfg()}.