Skip to content

Commit

Permalink
change ergw_api:delete_context/1 to not block and choose random contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
RoadRunnr committed Jun 14, 2019
1 parent 1369da7 commit 85735c2
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/ergw_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ contexts(all) ->
<- gtp_context_reg:all(), is_pid(Pid)]).

delete_contexts(Count) ->
Contexts = lists:sublist(contexts(all), Count),
lists:foreach(fun(Pid) -> gtp_context:delete_context(Pid) end, Contexts).
delete_contexts(contexts(all), Count).

memory(Limit0) ->
Limit = min(Limit0, 100),
Expand All @@ -68,6 +67,14 @@ collect_contexts(Context, Tunnels) ->
Info = gtp_context:info(Context),
[Info#{'Process' => Context} | Tunnels].

delete_contexts(_Contexts, 0) ->
ok;
delete_contexts(Contexts, Count) ->
Id = rand:uniform(length(Contexts)),
Context = lists:nth(Id, Contexts),
gtp_context:trigger_delete_context(Context),
delete_contexts(Contexts -- [Context], Count - 1).

units(X) when X > 1024 * 1024 * 1024 ->
io_lib:format("~.4f GB", [X / math:pow(2, 30)]);
units(X) when X > 1024 * 1024 ->
Expand Down
4 changes: 4 additions & 0 deletions src/ggsn_gn.erl
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ handle_call({path_restart, Path}, _From,
handle_call({path_restart, _Path}, _From, State) ->
{reply, ok, State}.

handle_cast(delete_context, #{context := Context} = State) ->
delete_context(undefined, administrative, Context),
{noreply, State};

handle_cast({packet_in, _GtpPort, _IP, _Port, _Msg}, State) ->
lager:warning("packet_in not handled (yet): ~p", [_Msg]),
{noreply, State}.
Expand Down
4 changes: 4 additions & 0 deletions src/ggsn_gn_proxy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ handle_call({path_restart, Path}, _From, #{proxy_context := #context{path = Path
handle_call({path_restart, _Path}, _From, State) ->
{reply, ok, State}.

handle_cast(delete_context, State) ->
lager:warning("delete_context no handled(yet)"),
{reply, State};

handle_cast({packet_in, _GtpPort, _IP, _Port, _Msg}, State) ->
lager:warning("packet_in not handled (yet): ~p", [_Msg]),
{noreply, State}.
Expand Down
6 changes: 5 additions & 1 deletion src/gtp_context.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
send_request/6, resend_request/2,
request_finished/1,
path_restart/2,
terminate_colliding_context/1, terminate_context/1, delete_context/1,
terminate_colliding_context/1, terminate_context/1,
delete_context/1, trigger_delete_context/1,
remote_context_register/1, remote_context_register_new/1, remote_context_update/2,
enforce_restrictions/2,
info/1,
Expand Down Expand Up @@ -100,6 +101,9 @@ remote_context_update(OldContext, NewContext)
delete_context(Context) ->
gen_server:call(Context, delete_context).

trigger_delete_context(Context) ->
gen_server:cast(Context, delete_context).

triggered_offline_usage_report(Pid, ChargeEv, OldS, Response) ->
gen_server:cast(Pid, {triggered_offline_usage_report, ChargeEv, OldS, Response}).

Expand Down
4 changes: 4 additions & 0 deletions src/pgw_s5s8.erl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ handle_call({path_restart, Path}, _From,
handle_call({path_restart, _Path}, _From, State) ->
{reply, ok, State}.

handle_cast(delete_context, #{context := Context} = State) ->
delete_context(undefined, administrative, Context),
{noreply, State};

handle_cast({packet_in, _GtpPort, _IP, _Port, _Msg}, State) ->
lager:warning("packet_in not handled (yet): ~p", [_Msg]),
{noreply, State}.
Expand Down
4 changes: 4 additions & 0 deletions src/pgw_s5s8_proxy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ handle_call({path_restart, Path}, _From, #{proxy_context := #context{path = Path
handle_call({path_restart, _Path}, _From, State) ->
{reply, ok, State}.

handle_cast(delete_context, State) ->
lager:warning("delete_context no handled(yet)"),
{reply, State};

handle_cast({packet_in, _GtpPort, _IP, _Port, _Msg}, State) ->
lager:warning("packet_in not handled (yet): ~p", [_Msg]),
{noreply, State}.
Expand Down
4 changes: 4 additions & 0 deletions src/saegw_s11.erl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ handle_call({path_restart, Path}, _From,
handle_call({path_restart, _Path}, _From, State) ->
{reply, ok, State}.

handle_cast(delete_context, #{context := Context} = State) ->
delete_context(undefined, administrative, Context),
{noreply, State};

handle_cast({packet_in, _GtpPort, _IP, _Port, _Msg}, State) ->
lager:warning("packet_in not handled (yet): ~p", [_Msg]),
{noreply, State}.
Expand Down

0 comments on commit 85735c2

Please sign in to comment.