Skip to content

Commit

Permalink
remove Active mechanisms from gtp_path
Browse files Browse the repository at this point in the history
The same effect can be achived by setting {idle_,busy_}echo to off.
  • Loading branch information
RoadRunnr committed Oct 5, 2020
1 parent 7313735 commit 17b42a2
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 69 deletions.
8 changes: 4 additions & 4 deletions src/ggsn_gn.erl
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ handle_request(ReqKey,
DAF = proplists:get_bool('Dual Address Bearer Flag', gtp_v1_c:get_common_flags(IEs)),

Context1 = update_context_from_gtp_req(Request, Context0),
ContextPreAuth = gtp_path:bind(Request, false, Context1),
ContextPreAuth = gtp_path:bind(Request, Context1),

gtp_context:terminate_colliding_context(ContextPreAuth),

Expand Down Expand Up @@ -426,7 +426,7 @@ handle_request(ReqKey,
'Session' := Session} = Data0) ->

Context0 = update_context_from_gtp_req(Request, OldContext),
Context = gtp_path:bind(Request, false, Context0),
Context = gtp_path:bind(Request, Context0),
URRActions = update_session_from_gtp_req(IEs, Session, Context),

Data1 = if Context /= OldContext ->
Expand Down Expand Up @@ -490,7 +490,7 @@ handle_response({From, TermCause},
ie = #{?'Cause' := #cause{value = Cause}}} = Response,
_Request, _State,
#{context := Context0} = Data) ->
Context = gtp_path:bind(Response, false, Context0),
Context = gtp_path:bind(Response, Context0),
close_pdp_context(TermCause, Data),
if is_tuple(From) -> gen_statem:reply(From, {ok, Cause});
true -> ok
Expand Down Expand Up @@ -678,7 +678,7 @@ defer_usage_report(URRActions, UsageReport) ->

apply_context_change(NewContext0, OldContext, URRActions,
#{pfcp := PCtx0, pcc := PCC} = Data) ->
NewContext = gtp_path:bind(false, NewContext0),
NewContext = gtp_path:bind(NewContext0),
{PCtx, UsageReport} =
ergw_gsn_lib:modify_sgi_session(PCC, URRActions,
#{}, NewContext, PCtx0),
Expand Down
18 changes: 9 additions & 9 deletions src/ggsn_gn_proxy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ handle_request(ReqKey,
'Session' := Session} = Data) ->

Context1 = update_context_from_gtp_req(Request, Context0#context{state = #context_state{}}),
Context2 = gtp_path:bind(Request, false, Context1),
Context2 = gtp_path:bind(Request, Context1),

gtp_context:terminate_colliding_context(Context2),
gtp_context:remote_context_register_new(Context2),
Expand All @@ -297,7 +297,7 @@ handle_request(ReqKey,
{ok, _} = ergw_aaa_session:invoke(Session, SessionOpts, start, #{async => true}),

ProxyContext0 = init_proxy_context(ProxyGtpPort, Context2, ProxyInfo, ProxyGGSN),
ProxyContext1 = gtp_path:bind(true, ProxyContext0),
ProxyContext1 = gtp_path:bind(ProxyContext0),

ergw_sx_node:wait_connect(SxConnectId),
{Context, ProxyContext, PCtx} =
Expand All @@ -316,7 +316,7 @@ handle_request(ReqKey,
when ?IS_REQUEST_CONTEXT(ReqKey, Request, OldContext) ->

Context0 = update_context_from_gtp_req(Request, OldContext),
Context1 = gtp_path:bind(Request, false, Context0),
Context1 = gtp_path:bind(Request, Context0),

gtp_context:remote_context_update(OldContext, Context1),

Expand All @@ -340,8 +340,8 @@ handle_request(ReqKey,
proxy_context := ProxyContext0} = Data)
when ?IS_REQUEST_CONTEXT(ReqKey, Request, ProxyContext0) ->

Context = gtp_path:bind(false, Context0),
ProxyContext = gtp_path:bind(Request, true, ProxyContext0),
Context = gtp_path:bind(Context0),
ProxyContext = gtp_path:bind(Request, ProxyContext0),

DataNew = Data#{context => Context, proxy_context => ProxyContext},
forward_request(ggsn2sgsn, ReqKey, Request, DataNew, Data),
Expand All @@ -354,8 +354,8 @@ handle_request(ReqKey,
#{context := Context0,
proxy_context := ProxyContext0} = Data)
when ?IS_REQUEST_CONTEXT_OPTIONAL_TEI(ReqKey, Request, Context0) ->
Context = gtp_path:bind(Request, false, Context0),
ProxyContext = gtp_path:bind(true, ProxyContext0),
Context = gtp_path:bind(Request, Context0),
ProxyContext = gtp_path:bind(ProxyContext0),

DataNew = Data#{context => Context, proxy_context => ProxyContext},
forward_request(sgsn2ggsn, ReqKey, Request, DataNew, Data),
Expand Down Expand Up @@ -403,7 +403,7 @@ handle_response(#proxy_request{direction = sgsn2ggsn} = ProxyRequest,
?LOG(debug, "OK Proxy Response ~p", [Response]),

ProxyContext1 = update_context_from_gtp_req(Response, PrevProxyCtx),
ProxyContext = gtp_path:bind(Response, true, ProxyContext1),
ProxyContext = gtp_path:bind(Response, ProxyContext1),
gtp_context:remote_context_register(ProxyContext),

Return =
Expand Down Expand Up @@ -531,7 +531,7 @@ handle_sgsn_change(_, _, ProxyContext) ->

update_path_bind(NewContext0, OldContext)
when NewContext0 /= OldContext ->
NewContext = gtp_path:bind(false, NewContext0),
NewContext = gtp_path:bind(NewContext0),
gtp_path:unbind(OldContext),
NewContext;
update_path_bind(NewContext, _OldContext) ->
Expand Down
50 changes: 23 additions & 27 deletions src/gtp_path.erl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
-export([start_link/4, all/1,
maybe_new_path/3,
handle_request/2, handle_response/4,
bind/2, bind/3, unbind/1, down/2,
bind/1, bind/2, unbind/1, down/2,
get_handler/2, info/1]).

%% Validate environment Variables
Expand Down Expand Up @@ -69,19 +69,19 @@ handle_request(#request{gtp_port = GtpPort, ip = IP} = ReqKey, #gtp{version = Ve
handle_response(Path, Request, Ref, Response) ->
gen_statem:cast(Path, {handle_response, Request, Ref, Response}).

bind(Active, #context{remote_restart_counter = RestartCounter} = Context) ->
bind_path_recovery(RestartCounter, Active, bind_path(Context)).
bind(#context{remote_restart_counter = RestartCounter} = Context) ->
bind_path_recovery(RestartCounter, bind_path(Context)).

bind(#gtp{ie = #{{recovery, 0} :=
#recovery{restart_counter = RestartCounter}}
} = Request, Active, Context) ->
bind_path_recovery(RestartCounter, Active, bind_path(Request, Context));
} = Request, Context) ->
bind_path_recovery(RestartCounter, bind_path(Request, Context));
bind(#gtp{ie = #{{v2_recovery, 0} :=
#v2_recovery{restart_counter = RestartCounter}}
} = Request, Active, Context) ->
bind_path_recovery(RestartCounter, Active, bind_path(Request, Context));
bind(Request, Active, Context) ->
bind_path_recovery(undefined, Active, bind_path(Request, Context)).
} = Request, Context) ->
bind_path_recovery(RestartCounter, bind_path(Request, Context));
bind(Request, Context) ->
bind_path_recovery(undefined, bind_path(Request, Context)).

unbind(#context{version = Version, control_port = GtpPort,
remote_control_teid = #fq_teid{ip = RemoteIP}}) ->
Expand Down Expand Up @@ -146,8 +146,7 @@ stop(Path) ->

%% Timer value: echo = echo interval when peer is up.

-define(Defaults, [{active, false}, % keep probing path even when idle/down
{t3, 10 * 1000}, % echo retry interval
-define(Defaults, [{t3, 10 * 1000}, % echo retry interval
{n3, 5}, % echo retry count
{echo, 60 * 1000}, % echo ping interval
{idle_timeout, 1800 * 1000}, % time to keep the path entry when idle
Expand All @@ -172,8 +171,6 @@ validate_timeout(_Opt, infinity = Value) ->
validate_timeout(Opt, Value) ->
throw({error, {options, {Opt, Value}}}).

validate_option(active, Value) when is_boolean(Value) ->
Value;
validate_option(t3, Value)
when is_integer(Value) andalso Value > 0 ->
Value;
Expand Down Expand Up @@ -206,7 +203,7 @@ init([#gtp_port{name = PortName} = GtpPort, Version, RemoteIP, Args]) ->
State = #state{peer = #peer{state = up, contexts = 0},
echo = stopped},

Data0 = maps:with([active, t3, n3, echo,
Data0 = maps:with([t3, n3, echo,
idle_timeout, idle_echo,
down_timeout, down_echo], Args),
Data = Data0#{
Expand Down Expand Up @@ -257,18 +254,18 @@ handle_event({call, From}, all, _State, #{contexts := CtxS} = _Data) ->
Reply = maps:keys(CtxS),
{keep_state_and_data, [{reply, From, Reply}]};

handle_event({call, From}, {bind, Pid, Active}, #state{recovery = RstCnt} = State, Data) ->
register(Pid, Active, State, Data, [{reply, From, {ok, RstCnt}}]);
handle_event({call, From}, {bind, Pid}, #state{recovery = RstCnt} = State, Data) ->
register(Pid, State, Data, [{reply, From, {ok, RstCnt}}]);

handle_event({call, From}, {bind, Pid, Active, RstCnt}, State, Data) ->
handle_event({call, From}, {bind, Pid, RstCnt}, State, Data) ->
case update_restart_counter(RstCnt, State, Data) of
initial ->
register(Pid, Active, State#state{recovery = RstCnt}, Data, [{reply, From, ok}]);
register(Pid, State#state{recovery = RstCnt}, Data, [{reply, From, ok}]);
peer_restart ->
%% try again after state change
path_restart(RstCnt, State, Data, [postpone]);
no ->
register(Pid, Active, State, Data, [{reply, From, ok}])
register(Pid, State, Data, [{reply, From, ok}])
end;

handle_event({call, From}, {unbind, Pid}, State, Data) ->
Expand Down Expand Up @@ -386,10 +383,10 @@ enter_state_timeout_action(_State, _Data) ->

enter_state_echo_action(busy, #{echo := EchoInterval}) when is_integer(EchoInterval) ->
{{timeout, echo}, EchoInterval, start_echo};
enter_state_echo_action(idle, #{active := true, idle_echo := EchoInterval})
enter_state_echo_action(idle, #{idle_echo := EchoInterval})
when is_integer(EchoInterval) ->
{{timeout, echo}, EchoInterval, start_echo};
enter_state_echo_action(down, #{active := true, down_echo := EchoInterval})
enter_state_echo_action(down, #{down_echo := EchoInterval})
when is_integer(EchoInterval) ->
{{timeout, echo}, EchoInterval, start_echo};
enter_state_echo_action(_, _) ->
Expand Down Expand Up @@ -478,10 +475,9 @@ update_contexts(State0, #{gtp_port := GtpPort, version := Version, ip := IP} = D
Data = Data0#{contexts => CtxS},
{next_state, State, Data, Actions}.

register(Pid, Active, State, #{contexts := CtxS} = Data0, Actions) ->
register(Pid, State, #{contexts := CtxS} = Data, Actions) ->
?LOG(debug, "~s: register(~p)", [?MODULE, Pid]),
MRef = erlang:monitor(process, Pid),
Data = maps:update_with(active, fun(V) -> V or Active end, Data0),
update_contexts(State, Data, maps:put(Pid, MRef, CtxS), Actions).

unregister(Pid, State, #{contexts := CtxS} = Data, Actions)
Expand All @@ -500,12 +496,12 @@ bind_path(#context{version = Version, control_port = CntlGtpPort,
Path = maybe_new_path(CntlGtpPort, Version, RemoteCntlIP),
Context#context{path = Path}.

bind_path_recovery(RestartCounter, Active, #context{path = Path} = Context)
bind_path_recovery(RestartCounter, #context{path = Path} = Context)
when is_integer(RestartCounter) ->
ok = gen_statem:call(Path, {bind, self(), Active, RestartCounter}),
ok = gen_statem:call(Path, {bind, self(), RestartCounter}),
Context#context{remote_restart_counter = RestartCounter};
bind_path_recovery(_RestartCounter, Active, #context{path = Path} = Context) ->
{ok, PathRestartCounter} = gen_statem:call(Path, {bind, self(), Active}),
bind_path_recovery(_RestartCounter, #context{path = Path} = Context) ->
{ok, PathRestartCounter} = gen_statem:call(Path, {bind, self()}),
Context#context{remote_restart_counter = PathRestartCounter}.

send_echo_request(State, #{gtp_port := GtpPort, handler := Handler, ip := DstIP,
Expand Down
10 changes: 5 additions & 5 deletions src/pgw_s5s8.erl
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ handle_request(ReqKey,

Context1 = update_context_tunnel_ids(FqCntlTEID, FqDataTEID, Context0),
Context2 = update_context_from_gtp_req(Request, Context1),
ContextPreAuth = gtp_path:bind(Request, false, Context2),
ContextPreAuth = gtp_path:bind(Request, Context2),

gtp_context:terminate_colliding_context(ContextPreAuth),

Expand Down Expand Up @@ -473,7 +473,7 @@ handle_request(ReqKey,

Context0 = update_context_tunnel_ids(FqCntlTEID, FqDataTEID, OldContext),
Context1 = update_context_from_gtp_req(Request, Context0),
Context = gtp_path:bind(Request, false, Context1),
Context = gtp_path:bind(Request, Context1),
URRActions = update_session_from_gtp_req(IEs, Session, Context),

Data1 = if Context /= OldContext ->
Expand Down Expand Up @@ -642,7 +642,7 @@ handle_response(CommandReqKey,
#{context := Context0, pfcp := PCtx,
'Session' := Session} = Data0) ->
gtp_context:request_finished(CommandReqKey),
Context = gtp_path:bind(Response, false, Context0),
Context = gtp_path:bind(Response, Context0),
Data = Data0#{context => Context},

if Cause =:= request_accepted andalso BearerCause =:= request_accepted ->
Expand Down Expand Up @@ -672,7 +672,7 @@ handle_response({From, TermCause},
ie = #{?'Cause' := #v2_cause{v2_cause = RespCause}} = IEs} = Response,
_Request, _State,
#{context := Context0, 'Session' := Session} = Data) ->
Context = gtp_path:bind(Response, false, Context0),
Context = gtp_path:bind(Response, Context0),
process_secondary_rat_usage_data_reports(IEs, Context, Session),
close_pdn_context(TermCause, Data),
if is_tuple(From) -> gen_statem:reply(From, {ok, RespCause});
Expand Down Expand Up @@ -868,7 +868,7 @@ apply_context_change(NewContext0, OldContext, URRActions,
_ ->
#{}
end,
NewContext = gtp_path:bind(false, NewContext0),
NewContext = gtp_path:bind(NewContext0),
{PCtx, UsageReport} =
ergw_gsn_lib:modify_sgi_session(PCC, URRActions,
ModifyOpts, NewContext, PCtx0),
Expand Down
18 changes: 9 additions & 9 deletions src/pgw_s5s8_proxy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ handle_request(ReqKey,
'Session' := Session} = Data) ->

Context1 = update_context_from_gtp_req(Request, Context0#context{state = #context_state{}}),
Context2 = gtp_path:bind(Request, false, Context1),
Context2 = gtp_path:bind(Request, Context1),

gtp_context:terminate_colliding_context(Context2),
gtp_context:remote_context_register_new(Context2),
Expand All @@ -304,7 +304,7 @@ handle_request(ReqKey,
{ok, _} = ergw_aaa_session:invoke(Session, SessionOpts, start, #{async =>true}),

ProxyContext0 = init_proxy_context(ProxyGtpPort, Context2, ProxyInfo, ProxyGGSN),
ProxyContext1 = gtp_path:bind(true, ProxyContext0),
ProxyContext1 = gtp_path:bind(ProxyContext0),

ergw_sx_node:wait_connect(SxConnectId),
{Context, ProxyContext, PCtx} =
Expand All @@ -323,7 +323,7 @@ handle_request(ReqKey,
when ?IS_REQUEST_CONTEXT(ReqKey, Request, OldContext) ->

Context0 = update_context_from_gtp_req(Request, OldContext),
Context1 = gtp_path:bind(Request, false, Context0),
Context1 = gtp_path:bind(Request, Context0),

gtp_context:remote_context_update(OldContext, Context1),

Expand Down Expand Up @@ -444,7 +444,7 @@ handle_response(#proxy_request{direction = sgw2pgw} = ProxyRequest,
?LOG(debug, "OK Proxy Response ~p", [Response]),

ProxyContext1 = update_context_from_gtp_req(Response, PrevProxyCtx),
ProxyContext = gtp_path:bind(Response, true, ProxyContext1),
ProxyContext = gtp_path:bind(Response, ProxyContext1),
gtp_context:remote_context_register(ProxyContext),

Return =
Expand Down Expand Up @@ -615,7 +615,7 @@ handle_sgw_change(_, _, ProxyContext) ->

update_path_bind(NewContext0, OldContext)
when NewContext0 /= OldContext ->
NewContext = gtp_path:bind(false, NewContext0),
NewContext = gtp_path:bind(NewContext0),
gtp_path:unbind(OldContext),
NewContext;
update_path_bind(NewContext, _OldContext) ->
Expand Down Expand Up @@ -800,14 +800,14 @@ initiate_session_teardown(pgw2sgw,
bind_forward_path(sgw2pgw, Request, #{context := Context,
proxy_context := ProxyContext} = Data) ->
Data#{
context => gtp_path:bind(Request, false, Context),
proxy_context => gtp_path:bind(true, ProxyContext)
context => gtp_path:bind(Request, Context),
proxy_context => gtp_path:bind(ProxyContext)
};
bind_forward_path(pgw2sgw, Request, #{context := Context,
proxy_context := ProxyContext} = Data) ->
Data#{
context => gtp_path:bind(false, Context),
proxy_context => gtp_path:bind(Request, true, ProxyContext)
context => gtp_path:bind(Context),
proxy_context => gtp_path:bind(Request, ProxyContext)
}.

fteid_forward_context(#f_teid{ipv4 = IPv4, ipv6 = IPv6, teid = TEID},
Expand Down
10 changes: 5 additions & 5 deletions src/saegw_s11.erl
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ handle_request(ReqKey,

Context1 = update_context_tunnel_ids(FqCntlTEID, FqDataTEID, Context0),
Context2 = update_context_from_gtp_req(Request, Context1),
ContextPreAuth = gtp_path:bind(Request, false, Context2),
ContextPreAuth = gtp_path:bind(Request, Context2),

gtp_context:terminate_colliding_context(ContextPreAuth),

Expand Down Expand Up @@ -463,7 +463,7 @@ handle_request(ReqKey,

Context0 = update_context_tunnel_ids(FqCntlTEID, FqDataTEID, OldContext),
Context1 = update_context_from_gtp_req(Request, Context0),
Context = gtp_path:bind(Request, false, Context1),
Context = gtp_path:bind(Request, Context1),
URRActions = update_session_from_gtp_req(IEs, Session, Context),

Data1 = if Context /= OldContext ->
Expand Down Expand Up @@ -582,7 +582,7 @@ handle_response(_,
}} = IEs} = Response,
_Request, run,
#{context := Context0, pfcp := PCtx, 'Session' := Session} = Data0) ->
Context = gtp_path:bind(Response, false, Context0),
Context = gtp_path:bind(Response, Context0),
Data = Data0#{context => Context},

if Cause =:= request_accepted andalso BearerCause =:= request_accepted ->
Expand Down Expand Up @@ -612,7 +612,7 @@ handle_response({From, TermCause},
ie = #{?'Cause' := #v2_cause{v2_cause = Cause}}} = Response,
_Request, _State,
#{context := Context0} = Data) ->
Context = gtp_path:bind(Response, false, Context0),
Context = gtp_path:bind(Response, Context0),
close_pdn_context(TermCause, Data),
if is_tuple(From) -> gen_statem:reply(From, {ok, Cause});
true -> ok
Expand Down Expand Up @@ -801,7 +801,7 @@ defer_usage_report(URRActions, UsageReport) ->
apply_context_change(NewContext0, OldContext, URRActions,
#{pfcp := PCtx0, pcc := PCC} = Data) ->
ModifyOpts = #{send_end_marker => true},
NewContext = gtp_path:bind(false, NewContext0),
NewContext = gtp_path:bind(NewContext0),
{PCtx, UsageReport} =
ergw_gsn_lib:modify_sgi_session(PCC, URRActions,
ModifyOpts, NewContext, PCtx0),
Expand Down
3 changes: 3 additions & 0 deletions test/config_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,9 @@ config(_Config) ->
?ok_option(set_cfg_value([path_management, echo], 60 * 1000, ?PGW_PROXY_CONFIG)),
?ok_option(set_cfg_value([path_management, idle_echo], 60 * 1000, ?PGW_PROXY_CONFIG)),
?ok_option(set_cfg_value([path_management, down_echo], 60 * 1000, ?PGW_PROXY_CONFIG)),
?ok_option(set_cfg_value([path_management, echo], off, ?PGW_PROXY_CONFIG)),
?ok_option(set_cfg_value([path_management, idle_echo], off, ?PGW_PROXY_CONFIG)),
?ok_option(set_cfg_value([path_management, down_echo], off, ?PGW_PROXY_CONFIG)),
?ok_option(set_cfg_value([path_management, idle_timeout], 300 * 1000, ?PGW_PROXY_CONFIG)),
?ok_option(set_cfg_value([path_management, down_timeout], 7200 * 1000, ?PGW_PROXY_CONFIG)),
?ok_option(set_cfg_value([path_management, idle_timeout], 0, ?PGW_PROXY_CONFIG)),
Expand Down
Loading

0 comments on commit 17b42a2

Please sign in to comment.