fixeria has submitted this change. ( 
https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/41530?usp=email )

Change subject: config/sys.config: group sctp_{client,server} params into maps
......................................................................

config/sys.config: group sctp_{client,server} params into maps

A follow-up patch brings even more SCTP SockOpts related params.
Let's prepare for this by grouping the existing sctp_{client,server}
related variables into distinct maps and moving the socket options
into their own sub-map.  Keep support for legacy options, for the
sake of backwards compatibility.

This helps to avoid having two instances of each new parameter
(s1gw_ and mme_) and generally improves readability/editability
of the config file.

Change-Id: Ib573915fdeb3ce73a1f6110c19fd6b1d46e68a03
Related: SYS#7653
---
M config/sys.config
M src/osmo_s1gw_sup.erl
M src/sctp_common.erl
3 files changed, 67 insertions(+), 26 deletions(-)

Approvals:
  laforge: Looks good to me, approved
  pespin: Looks good to me, but someone else must approve
  jolly: Looks good to me, but someone else must approve
  Jenkins Builder: Verified




diff --git a/config/sys.config b/config/sys.config
index 9ad1ca2..f17dd13 100644
--- a/config/sys.config
+++ b/config/sys.config
@@ -2,18 +2,30 @@

 [%% 
================================================================================
  %% application config
- %%
- %%   eNB              S1GW
- %% +-----+     +----------------+
- %% | ... | --> | s1gw_bind_addr |             MME
- %% +-----+     +----------------+     +-----------------+
- %%             |  mme_loc_addr  | --> |  mme_rem_addr   |
- %%             +----------------+     +-----------------+
  %% 
================================================================================
- {osmo_s1gw,
-  [{s1gw_bind_addr, "127.0.1.1"}, %% S1GW bind address for incoming eNB 
connections
-   {mme_loc_addr, "127.0.2.1"}, %% local address for outgoing connections to 
the MME
-   {mme_rem_addr, "127.0.2.10"}, %% remote address for outgoing connections to 
the MME
+ {osmo_s1gw, [
+   %% SCTP server configuration
+   {sctp_server, #{
+      %% local (bind) address for incoming eNB connections
+      laddr => "127.0.1.1",
+      %% local (bind) port for incoming eNB connections
+      lport => 36412,
+      %% socket options (recbuf, sndbuf, nodelay)
+      %% if omitted or left empty, defaults apply
+      sockopts => #{ }
+   }},
+   %% SCTP client configuration
+   {sctp_client, #{
+      %% local (bind) address for outgoing connections to the MME
+      laddr => "127.0.2.1",
+      %% remote address for outgoing connections to the MME
+      raddr => "127.0.2.10",
+      %% remote port for outgoing connections to the MME
+      rport => 36412,
+      %% socket options (recbuf, sndbuf, nodelay)
+      %% if omitted or left empty, defaults apply
+      sockopts => #{ }
+   }},
    {pfcp_loc_addr, "127.0.1.1"}, %% local address for incoming PFCP PDUs from 
the UPF
    {pfcp_rem_addr, "127.0.1.2"} %% remote address for outgoing PFCP PDUs to 
the UPF
 %% Optional PFCP Network Instance IEs (omitted if not configured)
diff --git a/src/osmo_s1gw_sup.erl b/src/osmo_s1gw_sup.erl
index 1616fe5..bde7b54 100644
--- a/src/osmo_s1gw_sup.erl
+++ b/src/osmo_s1gw_sup.erl
@@ -41,8 +41,6 @@
 -include("s1ap.hrl").

 -define(SERVER, ?MODULE).
--define(ENV_DEFAULT_SCTP_BUFSZ, 65536).
--define(ENV_DEFAULT_SCTP_NODELAY, true).
 -define(ENV_DEFAULT_S1GW_BIND_ADDR, "127.0.1.1").
 -define(ENV_DEFAULT_S1GW_BIND_PORT, ?S1AP_PORT).
 -define(ENV_DEFAULT_MME_LOC_ADDR, "127.0.2.1").
@@ -103,26 +101,44 @@
 %% private API
 %% ------------------------------------------------------------------

+-spec parse_env_map(map()) -> map().
+parse_env_map(M0) ->
+    M1 = maps:map(fun(_, P) -> osmo_s1gw:get_env(P, undefined) end, M0),
+    maps:filter(fun(_, V) -> V =/= undefined end, M1).
+

 -spec client_cfg() -> sctp_client:cfg().
 client_cfg() ->
-    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)}.
+    %% parse old/legacy environment options, if any
+    OldCfg = parse_env_map(#{laddr => mme_loc_addr,
+                             raddr => mme_rem_addr,
+                             rport => mme_rem_port}),
+    OldSockOpts = parse_env_map(#{nodelay => mme_nodelay,
+                                  recbuf => mme_recbuf,
+                                  sndbuf => mme_sndbuf}),
+    %% parse the new sctp_client configuration block
+    Cfg = maps:merge(OldCfg, osmo_s1gw:get_env(sctp_client, #{ })),
+    SockOpts = maps:merge(OldSockOpts, maps:get(sockopts, Cfg, #{ })),
+    #{laddr => maps:get(laddr, Cfg, ?ENV_DEFAULT_MME_LOC_ADDR),
+      raddr => maps:get(raddr, Cfg, ?ENV_DEFAULT_MME_REM_ADDR),
+      rport => maps:get(rport, Cfg, ?ENV_DEFAULT_MME_REM_PORT),
+      sockopts => sctp_common:gen_sockopts(SockOpts)}.


 -spec server_cfg() -> sctp_server:cfg().
 server_cfg() ->
-    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),
+    %% parse old/legacy environment options, if any
+    DefCfg = parse_env_map(#{laddr => s1gw_bind_addr,
+                             lport => s1gw_bind_port}),
+    DefSockOpts = parse_env_map(#{nodelay => s1gw_nodelay,
+                                  recbuf => s1gw_recbuf,
+                                  sndbuf => s1gw_sndbuf}),
+    %% parse the new sctp_server configuration block
+    Cfg = maps:merge(DefCfg, osmo_s1gw:get_env(sctp_server, #{ })),
+    SockOpts = maps:merge(DefSockOpts, maps:get(sockopts, Cfg, #{ })),
+    #{laddr => maps:get(laddr, Cfg, ?ENV_DEFAULT_S1GW_BIND_ADDR),
+      lport => maps:get(lport, Cfg, ?ENV_DEFAULT_S1GW_BIND_PORT),
+      sockopts => sctp_common:gen_sockopts(SockOpts),
       handler => sctp_proxy,
       priv => client_cfg()}.

diff --git a/src/sctp_common.erl b/src/sctp_common.erl
index 9b86b50..9a57798 100644
--- a/src/sctp_common.erl
+++ b/src/sctp_common.erl
@@ -36,6 +36,7 @@

 -export([parse_addr/1,
          report_error/1,
+         gen_sockopts/1,
          send_data/2,
          shutdown/1]).

@@ -46,6 +47,10 @@
 -include("s1ap.hrl").


+-define(SOCKOPTS_DEFAULT_BUFSZ, 65536).
+-define(SOCKOPTS_DEFAULT_NODELAY, true).
+
+
 -type sock_aid() :: {gen_sctp:sctp_socket(),
                      gen_sctp:assoc_id()}.

@@ -84,6 +89,14 @@
     end.


+-spec gen_sockopts(map()) -> [gen_sctp:option()].
+gen_sockopts(SockOptsCfg) ->
+    SockOpts = #{recbuf => maps:get(recbuf, SockOptsCfg, 
?SOCKOPTS_DEFAULT_BUFSZ),
+                 sndbuf => maps:get(sndbuf, SockOptsCfg, 
?SOCKOPTS_DEFAULT_BUFSZ),
+                 sctp_nodelay => maps:get(nodelay, SockOptsCfg, 
?SOCKOPTS_DEFAULT_NODELAY)},
+    maps:to_list(SockOpts).
+
+
 -spec send_data(sock_aid(), binary()) -> ok | {error, term()}.
 send_data({Sock, Aid}, Data) ->
     gen_sctp:send(Sock, #sctp_sndrcvinfo{stream = ?S1AP_SCTP_STREAM,

--
To view, visit https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/41530?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: erlang/osmo-s1gw
Gerrit-Branch: master
Gerrit-Change-Id: Ib573915fdeb3ce73a1f6110c19fd6b1d46e68a03
Gerrit-Change-Number: 41530
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: jolly <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>

Reply via email to