fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/38684?usp=email )
Change subject: s1ap_proxy: add E-RAB introspection API ......................................................................
s1ap_proxy: add E-RAB introspection API
Change-Id: I43dcfa613a4ee0de5b2f6619911fd92b1675acd6 --- M src/s1ap_proxy.erl M test/s1ap_proxy_test.erl 2 files changed, 33 insertions(+), 8 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/erlang/osmo-s1gw refs/changes/84/38684/1
diff --git a/src/s1ap_proxy.erl b/src/s1ap_proxy.erl index 4452269..ea20106 100644 --- a/src/s1ap_proxy.erl +++ b/src/s1ap_proxy.erl @@ -42,6 +42,8 @@ terminate/2]). -export([start_link/0, process_pdu/2, + fetch_erab/2, + fetch_erab_list/1, shutdown/1]).
-include_lib("kernel/include/logger.hrl"). @@ -92,6 +94,18 @@ gen_server:call(Pid, {?FUNCTION_NAME, PDU}).
+%% Fetch a single E-RAB from the registry (by UID) +-spec fetch_erab(pid(), erab_uid()) -> {ok, pid()} | error. +fetch_erab(Pid, UID) -> + gen_server:call(Pid, {?FUNCTION_NAME, UID}). + + +%% Fetch all E-RABs from the registry in form of a list +-spec fetch_erab_list(pid()) -> [{erab_uid(), pid()}]. +fetch_erab_list(Pid) -> + gen_server:call(Pid, ?FUNCTION_NAME). + + -spec shutdown(pid()) -> ok. shutdown(Pid) -> gen_server:stop(Pid). @@ -111,6 +125,14 @@ {Reply, S1} = handle_pdu_bin(OrigData, S0), {reply, Reply, S1};
+handle_call({fetch_erab, UID}, _From, + #proxy_state{erabs = ERABs} = S) -> + {reply, dict:find(UID, ERABs), S}; + +handle_call(fetch_erab_list, _From, + #proxy_state{erabs = ERABs} = S) -> + {reply, dict:to_list(ERABs), S}; + handle_call(Info, From, #proxy_state{} = S) -> ?LOG_ERROR("unknown ~p() from ~p: ~p", [?FUNCTION_NAME, From, Info]), diff --git a/test/s1ap_proxy_test.erl b/test/s1ap_proxy_test.erl index cb562a2..9e94716 100644 --- a/test/s1ap_proxy_test.erl +++ b/test/s1ap_proxy_test.erl @@ -67,7 +67,9 @@ SetupRspExp = e_rab_setup_rsp_pdu(?ADDR_C2U, ?TEID_C2U),
[?_assertEqual({forward, SetupReqExp}, s1ap_proxy:process_pdu(Pid, SetupReqIn)), - ?_assertEqual({forward, SetupRspExp}, s1ap_proxy:process_pdu(Pid, SetupRspIn))]. + ?_assertEqual({forward, SetupRspExp}, s1ap_proxy:process_pdu(Pid, SetupRspIn)), + ?_assertMatch({ok, _}, s1ap_proxy:fetch_erab(Pid, {7, 9, 6})), + ?_assertMatch([_], s1ap_proxy:fetch_erab_list(Pid))].
test_e_rab_setup_req_fail(#{handler := Pid}) -> @@ -79,9 +81,8 @@ SetupReqIn = e_rab_setup_req_pdu(?ADDR_U2C, ?TEID_U2C), SetupRspExp = e_rab_setup_rsp_fail_pdu(),
- %% TODO: make sure that the E-RAB FSM has been terminated - - [?_assertEqual({reply, SetupRspExp}, s1ap_proxy:process_pdu(Pid, SetupReqIn))]. + [?_assertEqual({reply, SetupRspExp}, s1ap_proxy:process_pdu(Pid, SetupReqIn)), + ?_assertEqual([], s1ap_proxy:fetch_erab_list(Pid))].
test_e_rab_release_cmd(#{handler := Pid}) -> @@ -94,12 +95,12 @@ %% [eNB -> MME] E-RAB RELEASE RESPONSE ReleaseRsp = e_rab_release_rsp_pdu(),
- %% TODO: make sure that the E-RAB FSM has been terminated - [?_assertMatch({forward, _}, s1ap_proxy:process_pdu(Pid, SetupReq)), ?_assertMatch({forward, _}, s1ap_proxy:process_pdu(Pid, SetupRsp)), + ?_assertMatch([_], s1ap_proxy:fetch_erab_list(Pid)), ?_assertEqual({forward, ReleaseCmd}, s1ap_proxy:process_pdu(Pid, ReleaseCmd)), - ?_assertEqual({forward, ReleaseRsp}, s1ap_proxy:process_pdu(Pid, ReleaseRsp))]. + ?_assertEqual({forward, ReleaseRsp}, s1ap_proxy:process_pdu(Pid, ReleaseRsp)), + ?_assertEqual([], s1ap_proxy:fetch_erab_list(Pid))].
test_e_rab_release_ind(#{handler := Pid}) -> @@ -111,6 +112,7 @@ ReleaseInd = e_rab_release_ind_pdu(),
%% TODO: make sure that the E-RAB FSM has been terminated + %% FIXME: erab_fsm does not tear down immediately, but after a timeout
[?_assertMatch({forward, _}, s1ap_proxy:process_pdu(Pid, SetupReq)), ?_assertMatch({forward, _}, s1ap_proxy:process_pdu(Pid, SetupRsp)), @@ -135,7 +137,8 @@ InitCtxSetupRspExp = initial_context_setup_rsp_pdu(?ADDR_C2U, ?TEID_C2U),
[?_assertEqual({forward, InitCtxSetupReqExp}, s1ap_proxy:process_pdu(Pid, InitCtxSetupReqIn)), - ?_assertEqual({forward, InitCtxSetupRspExp}, s1ap_proxy:process_pdu(Pid, InitCtxSetupRspIn))]. + ?_assertEqual({forward, InitCtxSetupRspExp}, s1ap_proxy:process_pdu(Pid, InitCtxSetupRspIn)), + ?_assertMatch([_], s1ap_proxy:fetch_erab_list(Pid))].
%% ------------------------------------------------------------------