diff --git a/src/ergw_proxy_lib.erl b/src/ergw_proxy_lib.erl index 76638516..0d0f8e78 100644 --- a/src/ergw_proxy_lib.erl +++ b/src/ergw_proxy_lib.erl @@ -52,7 +52,7 @@ get_seq_no(#tunnel{socket = Socket}, ReqKey, Request) -> ergw_gtp_c_socket:get_seq_no(Socket, ReqId). %% choose_gw/4 -choose_gw([], _NodeSelect, _Version, _Socket) -> +choose_gw([], _NodeSelect, _Version, #socket{}) -> {error, ?CTX_ERR(?FATAL, no_resources_available)}; choose_gw(Nodes, NodeSelect, Version, #socket{name = Name} = Socket) -> {Candidate, Next} = ergw_node_selection:snaptr_candidate(Nodes), @@ -71,7 +71,7 @@ choose_gw(Nodes, NodeSelect, Version, #socket{name = Name} = Socket) -> select_gw(#{imsi := IMSI, gwSelectionAPN := APN}, Version, Services, NodeSelect, Socket) -> FQDN = ergw_node_selection:apn_to_fqdn(APN, IMSI), case ergw_node_selection:candidates(FQDN, Services, NodeSelect) of - Nodes when is_list(Nodes), length(Nodes) /= 0 -> + [_|_] = Nodes -> choose_gw(Nodes, NodeSelect, Version, Socket); _ -> {error, ?CTX_ERR(?FATAL, system_failure)} diff --git a/test/proxy_lib_SUITE.erl b/test/proxy_lib_SUITE.erl index a779935a..4f9009a0 100644 --- a/test/proxy_lib_SUITE.erl +++ b/test/proxy_lib_SUITE.erl @@ -29,6 +29,10 @@ {static, [ %% APN NAPTR alternative + {"web.apn.epc.mnc001.mcc001.3gppnetwork.org", {0,0}, + [{"x-3gpp-pgw","x-s5-gtp"},{"x-3gpp-pgw","x-s8-gtp"}, + {"x-3gpp-pgw","x-gn"},{"x-3gpp-pgw","x-gp"}], + ?'CP-Node'}, {"web.apn.epc.mnc001.mcc001.3gppnetwork.org", {300,64536}, [{"x-3gpp-pgw","x-s5-gtp"},{"x-3gpp-pgw","x-s8-gtp"}, {"x-3gpp-pgw","x-gn"},{"x-3gpp-pgw","x-gp"}], @@ -128,6 +132,11 @@ proxy_lookup(_Config) -> PI7 = PI#{gwSelectionAPN => apn(<<"web.mnc567.mcc001.gprs">>)}, {error, Proxy7} = ergw_proxy_lib:select_gw(PI7, v1, ?SERVICES, NodeSelect, Socket), ?match(#ctx_err{level = ?FATAL, reply = system_failure}, Proxy7), + + PI8 = PI#{gwSelectionAPN => apn(<<"web.apn.epc.mnc001.mcc001.3gppnetwork.org">>)}, + ok = gtp_path_reg:register({<<"TEST">>, v1, ?'CP-IP'}, down), + {error, Proxy8} = ergw_proxy_lib:select_gw(PI8, v1, ?SERVICES, NodeSelect, Socket), + ?match(#ctx_err{level = ?FATAL, reply = no_resources_available}, Proxy8), ok. apn(Bin) ->