fixeria has uploaded this change for review.

View Change

enft_kpi: keep NFT counters intact

We don't want to reset counters if an eNB reconnects.
This is also what osmo-hnbgw does.

Change-Id: Id6db327b445b8597d39a1d838077e7002d538db5
Related: SYS#7307
---
M src/enft_kpi.erl
1 file changed, 16 insertions(+), 22 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/erlang/osmo-s1gw refs/changes/46/40446/1
diff --git a/src/enft_kpi.erl b/src/enft_kpi.erl
index e251a3b..9086298 100644
--- a/src/enft_kpi.erl
+++ b/src/enft_kpi.erl
@@ -210,7 +210,7 @@
{ok, #{genb_id := GlobalENBId,
mon_ref := MonRef} = ES} ->
erlang:demonitor(MonRef, [flush]),
- enb_del_nft_counters(ES, Cfg),
+ enb_del_nft_rules(ES, Cfg),
R1 = dict:erase(Pid, R0),
?LOG_INFO("eNB (pid ~p, ~p) has been unregistered",
[Pid, GlobalENBId]),
@@ -295,7 +295,7 @@
?LOG_INFO("eNB process ~p terminated with reason ~p", [Pid, Reason]),
case dict:find(Pid, R0) of
{ok, ES} ->
- enb_del_nft_counters(ES, Cfg),
+ enb_del_nft_rules(ES, Cfg),
R1 = dict:erase(Pid, R0),
?LOG_INFO("eNB (pid ~p) has been unregistered", [Pid]),
{noreply, S#state{registry = R1}};
@@ -395,37 +395,31 @@
end.


--spec enb_del_nft_counters(ES0, Cfg) -> ES1
+-spec enb_del_nft_rules(ES0, Cfg) -> ES1
when Cfg :: cfg(),
ES0 :: enb_state(),
ES1 :: enb_state().
-enb_del_nft_counters(#{ul := ULS} = ES, Cfg) ->
- enb_del_nft_counter(ULS, ES, Cfg),
- enb_del_nft_counters(maps:remove(ul, ES), Cfg);
+enb_del_nft_rules(#{ul := ULS} = ES, Cfg) ->
+ enb_del_nft_rule(ULS, Cfg),
+ enb_del_nft_rules(maps:remove(ul, ES), Cfg);

-enb_del_nft_counters(#{dl := DLS} = ES, Cfg) ->
- enb_del_nft_counter(DLS, ES, Cfg),
- enb_del_nft_counters(maps:remove(dl, ES), Cfg);
+enb_del_nft_rules(#{dl := DLS} = ES, Cfg) ->
+ enb_del_nft_rule(DLS, Cfg),
+ enb_del_nft_rules(maps:remove(dl, ES), Cfg);

%% no UL/DL state => nothing to delete
-enb_del_nft_counters(ES, _Cfg) -> ES.
+enb_del_nft_rules(ES, _Cfg) -> ES.


--spec enb_del_nft_counter(S, ES, Cfg) -> ok | {error, term()}
+-spec enb_del_nft_rule(S, Cfg) -> ok | {error, term()}
when S :: enb_uldl_state(),
- ES :: enb_state(),
Cfg :: cfg().
-enb_del_nft_counter(#{uldl := ULDL, handle := Handle},
- #{genb_id := GlobalENBId, pid := Pid},
- #{table_name := TName}) ->
- ?LOG_DEBUG("eNB (pid ~p, ~p): deleting NFT counter for ~p",
- [Pid, GlobalENBId, ULDL]),
- CtrName = enb_nft_counter_name(ULDL, GlobalENBId),
+enb_del_nft_rule(#{uldl := ULDL, handle := Handle},
+ #{table_name := TName}) ->
+ %% keep the counter intact, remove the rule only
+ %% we don't want to reset counters if eNB reconnects
CName = enb_nft_chain_name(ULDL),
- Counter = enftables:nft_counter(TName, CtrName),
- Cmds = [enftables:nft_cmd_del_rule(TName, CName, Handle),
- enftables:nft_cmd_del_counter(Counter)
- ],
+ Cmds = [enftables:nft_cmd_del_rule(TName, CName, Handle)],
case nft_exec(Cmds) of
ok -> ok;
{error, Error} ->

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

Gerrit-MessageType: newchange
Gerrit-Project: erlang/osmo-s1gw
Gerrit-Branch: master
Gerrit-Change-Id: Id6db327b445b8597d39a1d838077e7002d538db5
Gerrit-Change-Number: 40446
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy@sysmocom.de>