pespin submitted this change.

View Change


Approvals: laforge: Looks good to me, approved Jenkins Builder: Verified fixeria: Looks good to me, but someone else must approve
Several fixes and improvement around env config use

For some unknown reason, when app is run as an escript it fails to
match/load the config files unless the AppName osmo-epdg is used.

Change-Id: I729513ff1f904b78971d22e49622707c8bc0e4aa
---
M config/sys.config
M src/epdg_diameter_swx.erl
2 files changed, 35 insertions(+), 14 deletions(-)

diff --git a/config/sys.config b/config/sys.config
index 23f7936..f9fd5ed 100755
--- a/config/sys.config
+++ b/config/sys.config
@@ -1,16 +1,16 @@
[%% ===========================================
%% Application config
%% ===========================================
- {epdg_diameter_swx,
+ {osmo_epdg,
[% Connection parameters
- {diameter_server_ip, "192.168.56.132"},
- {diameter_port, 3868},
+ {diameter_remote_ip, "127.0.0.1"},
+ {diameter_remote_port, 3868},
{diameter_proto, sctp},
% Server parameters
{vendor_id, 0},
- {origin_host, "aaa.gprs.fe80.eu"},
- {origin_realm, "gprs.fe80.eu"},
- {context_id, "gprs@giameter.com"}]},
+ {origin_host, "epdg.localdomain"},
+ {origin_realm, "localdomain"},
+ {context_id, "epdg@localdomain"}]},
%% ===========================================
%% SASL config
%% ===========================================
diff --git a/src/epdg_diameter_swx.erl b/src/epdg_diameter_swx.erl
index 9909446..fe89f11 100644
--- a/src/epdg_diameter_swx.erl
+++ b/src/epdg_diameter_swx.erl
@@ -59,6 +59,14 @@
-define(APP_ALIAS, ?MODULE).
-define(CALLBACK_MOD, epdg_diameter_swx_cb).
-define(DIAMETER_DICT_SWX, diameter_3gpp_ts29_273_swx).
+-define(ENV_APP_NAME, osmo_epdg).
+-define(ENV_DEFAULT_SESSION_ID, "epdg@localdomain").
+-define(ENV_DEFAULT_ORIG_REALM, "localdomain").
+-define(ENV_DEFAULT_ORIG_HOST, "epdg.localdomain").
+-define(ENV_DEFAULT_VENDOR_ID, 0).
+-define(ENV_DEFAULT_DIAMETER_PROTO, sctp).
+-define(ENV_DEFAULT_DIAMETER_REMOTE_IP, "127.0.0.1").
+-define(ENV_DEFAULT_DIAMETER_REMOTE_PORT, 3868).

-define(VENDOR_ID_3GPP, 10415).
-define(VENDOR_ID_3GPP2, 5535).
@@ -68,9 +76,9 @@
%% supporting multiple Diameter applications may or may not want to
%% configure a common callback module on all applications.
-define(SERVICE,
- [{'Origin-Host', application:get_env(?SERVER, origin_host, "aaa.example.org")},
- {'Origin-Realm', application:get_env(?SERVER, origin_realm, "realm.example.org")},
- {'Vendor-Id', application:get_env(?SERVER, vendor_id, 0)},
+ [{'Origin-Host', application:get_env(?ENV_APP_NAME, origin_host, ?ENV_DEFAULT_ORIG_HOST)},
+ {'Origin-Realm', application:get_env(?ENV_APP_NAME, origin_realm, ?ENV_DEFAULT_ORIG_REALM)},
+ {'Vendor-Id', application:get_env(?ENV_APP_NAME, vendor_id, ?ENV_DEFAULT_VENDOR_ID)},
{'Vendor-Specific-Application-Id',
[#'diameter_base_Vendor-Specific-Application-Id'{
'Vendor-Id' = ?VENDOR_ID_3GPP,
@@ -110,9 +118,9 @@
ok.

init(State) ->
- Proto = application:get_env(?SERVER, diameter_proto, sctp),
- Ip = application:get_env(?SERVER, diameter_server_ip, "192.168.56.132"),
- Port = application:get_env(?SERVER, diameter_port, 3868),
+ Proto = application:get_env(?ENV_APP_NAME, diameter_proto, ?ENV_DEFAULT_DIAMETER_PROTO),
+ Ip = application:get_env(?ENV_APP_NAME, diameter_remote_ip, ?ENV_DEFAULT_DIAMETER_REMOTE_IP),
+ Port = application:get_env(?ENV_APP_NAME, diameter_remote_port, ?ENV_DEFAULT_DIAMETER_REMOTE_PORT),
ok = diameter:start_service(?MODULE, ?SERVICE),
% lager:info("DiaServices is ~p~n", [DiaServ]),
{ok, _} = connect({address, Proto, Ip, Port}),
@@ -159,7 +167,7 @@
% parse_mar(#'MAA'{'Experimental-Result-Code' = [ResultCode] = MAA) ->

handle_call({mar, {IMSI, NumAuthItems, AuthScheme, RAT, CKey, IntegrityKey}}, _From, State) ->
- SessionId = diameter:session_id(application:get_env(?SERVER, origin_host, "aaa.example.org")),
+ SessionId = diameter:session_id(application:get_env(?ENV_APP_NAME, origin_host, ?ENV_DEFAULT_ORIG_HOST)),
MAR = #'MAR'{'Vendor-Specific-Application-Id' = #'Vendor-Specific-Application-Id'{
'Vendor-Id' = ?VENDOR_ID_3GPP,
'Auth-Application-Id' = [?DIAMETER_APP_ID_SWX]},
@@ -182,7 +190,7 @@
{reply, {error, Err}, State}
end;
handle_call({sar, {IMSI, Type, APN}}, _From, State) ->
- SessionId = diameter:session_id(application:get_env(?SERVER, origin_host, "aaa.example.org")),
+ SessionId = diameter:session_id(application:get_env(?ENV_APP_NAME, origin_host, ?ENV_DEFAULT_ORIG_HOST)),
SAR = #'SAR'{'Vendor-Specific-Application-Id' = #'Vendor-Specific-Application-Id'{
'Vendor-Id' = ?VENDOR_ID_3GPP,
'Auth-Application-Id' = [?DIAMETER_APP_ID_SWX]},
@@ -236,6 +244,7 @@

%% connect/2
connect(Name, {address, Protocol, IPAddr, Port}) ->
+ lager:notice("~s connecting to IP ~s port ~p~n", [Name, IPAddr, Port]),
{ok, IP} = inet_parse:address(IPAddr),
TransportOpts =
[{transport_module, tmod(Protocol)},

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

Gerrit-Project: erlang/osmo-epdg
Gerrit-Branch: master
Gerrit-Change-Id: I729513ff1f904b78971d22e49622707c8bc0e4aa
Gerrit-Change-Number: 34740
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de>
Gerrit-Reviewer: laforge <laforge@osmocom.org>
Gerrit-Reviewer: pespin <pespin@sysmocom.de>
Gerrit-MessageType: merged