fixeria has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/40438?usp=email )


Change subject: enft_kpi: make enb_set_addr/1 non-blocking
......................................................................

enft_kpi: make enb_set_addr/1 non-blocking

This function is called each time a new E-REB is established, while
the result, be it success or failure, does not matter to s1ap_proxy.
Use gen_server:cast/2 instead of gen_server:call/2 to avoid blocking.

Change-Id: Iacd380f66fc0249a6a645293abd5aac9cdba34d5
Related: SYS#7307
---
M src/enft_kpi.erl
1 file changed, 29 insertions(+), 30 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/erlang/osmo-s1gw 
refs/changes/38/40438/1

diff --git a/src/enft_kpi.erl b/src/enft_kpi.erl
index 9b4caf1..d5d5ce3 100644
--- a/src/enft_kpi.erl
+++ b/src/enft_kpi.erl
@@ -117,11 +117,10 @@
     gen_server:call(?MODULE, {?FUNCTION_NAME, GlobalENBId}).


--spec enb_set_addr(ULDLAddr) -> ok | {error, term()}
+-spec enb_set_addr(ULDLAddr) -> ok
     when ULDLAddr :: uldl_addr().
 enb_set_addr(ULDLAddr) ->
-    %% TODO: use cast here to avoid blocking
-    gen_server:call(?MODULE, {?FUNCTION_NAME, ULDLAddr}).
+    gen_server:cast(?MODULE, {?FUNCTION_NAME, self(), ULDLAddr}).


 -spec enb_unregister() -> ok | {error, term()}.
@@ -203,33 +202,6 @@
             {reply, ok, S#state{registry = R1}}
     end;

-handle_call({enb_set_addr, {ULDL, Addr}}, {Pid, _Ref},
-            #state{registry = R} = S0) ->
-    case dict:find(Pid, R) of
-        %% the given UL/DL Addr is already known
-        {ok, #{genb_id := GlobalENBId,
-               ULDL := #{addr := Addr}}} ->
-            ?LOG_DEBUG("eNB (pid ~p, ~p): ~p address ~p is already known",
-                       [Pid, GlobalENBId, ULDL, Addr]),
-            {reply, ok, S0};
-        %% the given UL/DL Addr differs from stored Addr
-        {ok, #{genb_id := GlobalENBId,
-               ULDL := #{addr := OldAddr}}} ->
-            ?LOG_ERROR("eNB (pid ~p, ~p): ~p address ~p -> ~p change?!?",
-                       [Pid, GlobalENBId, ULDL, OldAddr, Addr]),
-            {reply, {error, addr_mismatch}, S0};
-        %% UL/DL state is missing => create it
-        {ok, #{genb_id := GlobalENBId} = ES} ->
-            ?LOG_DEBUG("eNB (pid ~p, ~p): ~p address ~p indicated, "
-                       "creating NFT counters and rules",
-                       [Pid, GlobalENBId, ULDL, Addr]),
-            {Reply, S1} = enb_set_addr({ULDL, Addr}, ES, S0),
-            {reply, Reply, S1};
-        error ->
-            ?LOG_ERROR("eNB (pid ~p) is *not* registered", [Pid]),
-            {reply, {error, not_registered}, S0}
-    end;
-
 handle_call(enb_unregister, {Pid, _Ref},
             #state{cfg = Cfg, registry = R0} = S) ->
     case dict:find(Pid, R0) of
@@ -269,6 +241,33 @@
     ?LOG_DEBUG("ignore ~p(): ~p", [?FUNCTION_NAME, Info]),
     {noreply, S};

+handle_cast({enb_set_addr, Pid, {ULDL, Addr}},
+            #state{registry = R} = S0) ->
+    case dict:find(Pid, R) of
+        %% the given UL/DL Addr is already known
+        {ok, #{genb_id := GlobalENBId,
+               ULDL := #{addr := Addr}}} ->
+            ?LOG_DEBUG("eNB (pid ~p, ~p): ~p address ~p is already known",
+                       [Pid, GlobalENBId, ULDL, Addr]),
+            {noreply, S0};
+        %% the given UL/DL Addr differs from stored Addr
+        {ok, #{genb_id := GlobalENBId,
+               ULDL := #{addr := OldAddr}}} ->
+            ?LOG_ERROR("eNB (pid ~p, ~p): ~p address ~p -> ~p change?!?",
+                       [Pid, GlobalENBId, ULDL, OldAddr, Addr]),
+            {noreply, S0};
+        %% UL/DL state is missing => create it
+        {ok, #{genb_id := GlobalENBId} = ES} ->
+            ?LOG_DEBUG("eNB (pid ~p, ~p): ~p address ~p indicated, "
+                       "creating NFT counters and rules",
+                       [Pid, GlobalENBId, ULDL, Addr]),
+            {_, S1} = enb_set_addr({ULDL, Addr}, ES, S0),
+            {noreply, S1};
+        error ->
+            ?LOG_ERROR("eNB (pid ~p) is *not* registered", [Pid]),
+            {noreply, S0}
+    end;
+
 handle_cast(report_nft_counters,
             #state{cfg = #{table_name := TName},
                    registry = R0} = S) ->

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

Gerrit-MessageType: newchange
Gerrit-Project: erlang/osmo-s1gw
Gerrit-Branch: master
Gerrit-Change-Id: Iacd380f66fc0249a6a645293abd5aac9cdba34d5
Gerrit-Change-Number: 40438
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <[email protected]>

Reply via email to