tolerate GSUP disconnects

This commit is contained in:
Harald Welte 2019-08-20 20:05:36 +02:00
parent 299ba939ab
commit e795af37f8
3 changed files with 21 additions and 10 deletions

View File

@ -64,10 +64,17 @@ init([Address, Port, Options]) ->
ipa_proto:init(),
% register the GSUP codec with the IPA core; ignore result as we mgiht be doing this multiple times
ipa_proto:register_codec(?IPAC_PROTO_EXT_GSUP, fun gsup_protocol:encode/1, fun gsup_protocol:decode/1),
{ok, {Socket, IpaPid}} = ipa_proto:connect(Address, Port, Options),
true = ipa_proto:register_stream(Socket, ?IPAC_PROTO_EXT_GSUP, {process_id, self()}),
ipa_proto:unblock(Socket),
{ok, #gsupc_state{socket=Socket, ipa_pid=IpaPid}}.
lager:info("Connecting to GSUP HLR on IP ~s port ~p~n", [Address, Port]),
case ipa_proto:connect(Address, Port, Options) of
{ok, {Socket, IpaPid}} ->
lager:info("connected!~n", []),
true = ipa_proto:register_stream(Socket, ?IPAC_PROTO_EXT_GSUP, {process_id, self()}),
ipa_proto:unblock(Socket),
{ok, #gsupc_state{socket=Socket, ipa_pid=IpaPid}};
{error, econnrefused} ->
timer:sleep(5000),
{stop, connrefused}
end.
% send a given GSUP message and synchronously wait for message type ExpRes or ExpErr
@ -90,6 +97,9 @@ handle_cast(Info, S) ->
error_logger:error_report(["unknown handle_cast", {module, ?MODULE}, {info, Info}, {state, S}]),
{noreply, S}.
handle_info({ipa_closed, _}, S) ->
lager:error("GSUP connection has been closed, supervisor should reconnect us"),
{stop, ipa_closed, S};
handle_info(Info, S) ->
error_logger:error_report(["unknown handle_info", {module, ?MODULE}, {info, Info}, {state, S}]),
{noreply, S}.

View File

@ -68,11 +68,6 @@ init(State) ->
Proto = application:get_env(osmo_dia2gsup, diameter_proto, sctp),
listen({address, Proto, element(2,inet:parse_address(Ip)), Port}),
lager:info("Diameter HSS Application started on IP ~s, ~p port ~p~n", [Ip, Proto, Port]),
% GSUP side
HlrIp = application:get_env(osmo_dia2gsup, hlr_ip, "127.0.0.1"),
HlrPort = application:get_env(osmo_dia2gsup, hlr_port, 4222),
lager:info("Connecting to GSUP HLR on IP ~s port ~p~n", [HlrIp, HlrPort]),
{ok, _Pid} = gen_server:start_link({local, gsup_client}, gsup_client, [HlrIp, HlrPort, []], [{debug, [trace]}]),
{ok, State}.
%% @callback gen_server

View File

@ -9,9 +9,15 @@ start_link() ->
supervisor:start_link({local, ?SERVER}, ?MODULE, []).
init([]) ->
% GSUP side
HlrIp = application:get_env(osmo_dia2gsup, hlr_ip, "127.0.0.1"),
HlrPort = application:get_env(osmo_dia2gsup, hlr_port, 4222),
Args = [{local, gsup_client}, gsup_client, [HlrIp, HlrPort, []], [{debug, [trace]}]],
GsupChild = {gsup_client, {gen_server, start_link, Args}, permanent, 2000, worker, [gsup_client]},
% DIAMETER side
DiaServer = {osmo_dia2gsup,{osmo_dia2gsup,start_link,[]},
permanent,
5000,
worker,
[server_cb]},
{ok, { {one_for_one, 5, 10}, [DiaServer]} }.
{ok, { {one_for_one, 5, 10}, [DiaServer, GsupChild]} }.