Skip to content

Commit

Permalink
rework contxt termination on AAA session stop
Browse files Browse the repository at this point in the history
- Remove no longer used stop_from_session and handle the newer
  stop session event accordingly.
- Update ergw_aaa for related changes.
  • Loading branch information
RoadRunnr committed Oct 29, 2019
1 parent c940ed4 commit dffaab4
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 42 deletions.
2 changes: 1 addition & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
1},
{<<"ergw_aaa">>,
{git,"git://github.com/travelping/ergw_aaa",
{ref,"dd753f4c788b92b25b7afd3bd5c500c4f149e479"}},
{ref,"3a4b9cb9291f6d57c7aaf0c3656b38194b89777e"}},
0},
{<<"erlando">>,
{git,"https://github.com/travelping/erlando.git",
Expand Down
12 changes: 4 additions & 8 deletions src/ggsn_gn.erl
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,6 @@ handle_event(info, {'DOWN', _MonitorRef, Type, Pid, _Info}, _State,
close_pdp_context(upf_failure, Data),
{next_state, shutdown, Data};

handle_event(info, stop_from_session, run, Data) ->
delete_context(undefined, normal, Data);
handle_event(info, stop_from_session, _State, _Data) ->
keep_state_and_data;

handle_event(info, #aaa_request{procedure = {_, 'ASR'}} = Request, run, Data) ->
ergw_aaa_session:response(Request, ok, #{}, #{}),
delete_context(undefined, administrative, Data);
Expand Down Expand Up @@ -254,9 +249,10 @@ handle_event(info, _Info, _State, Data) ->
lager:warning("~p, handle_info(~p, ~p)", [?MODULE, _Info, Data]),
keep_state_and_data;

handle_event(internal, {session, stop, _Session}, _State, Data) ->
close_pdp_context(normal, Data),
{next_state, shutdown, Data};
handle_event(internal, {session, stop, _Session}, run, Data) ->
delete_context(undefined, normal, Data);
handle_event(internal, {session, stop, _Session}, _, Data) ->
keep_state_and_data;

handle_event(internal, {session, {update_credits, _} = CreditEv, _}, _State,
#{context := Context, pfcp := PCtx0, pcc := PCC0} = Data) ->
Expand Down
12 changes: 4 additions & 8 deletions src/pgw_s5s8.erl
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,6 @@ handle_event(info, {'DOWN', _MonitorRef, Type, Pid, _Info}, _State,
close_pdn_context(upf_failure, Data),
{next_state, shutdown, Data};

handle_event(info, stop_from_session, run, Data) ->
delete_context(undefined, normal, Data);
handle_event(info, stop_from_session, _State, _Data) ->
keep_state_and_data;

handle_event(info, #aaa_request{procedure = {_, 'ASR'}} = Request, run, Data) ->
ergw_aaa_session:response(Request, ok, #{}, #{}),
delete_context(undefined, administrative, Data);
Expand Down Expand Up @@ -261,9 +256,10 @@ handle_event(info, {pfcp_timer, #{validity_time := ChargingKeys}}, _State, Data)
handle_event(info, _Info, _State, _Data) ->
keep_state_and_data;

handle_event(internal, {session, stop, _Session}, _State, Data) ->
close_pdn_context(normal, Data),
{next_state, shutdown, Data};
handle_event(internal, {session, stop, _Session}, run, Data) ->
delete_context(undefined, normal, Data);
handle_event(internal, {session, stop, _Session}, _, Data) ->
keep_state_and_data;

handle_event(internal, {session, {update_credits, _} = CreditEv, _}, _State,
#{context := Context, pfcp := PCtx0, pcc := PCC0} = Data) ->
Expand Down
12 changes: 4 additions & 8 deletions src/saegw_s11.erl
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,6 @@ handle_event(info, {'DOWN', _MonitorRef, Type, Pid, _Info}, _State,
close_pdn_context(upf_failure, Data),
{next_state, shutdown, Data};

handle_event(info, stop_from_session, run, Data) ->
delete_context(undefined, normal, Data);
handle_event(info, stop_from_session, _State, _Data) ->
keep_state_and_data;

handle_event(info, #aaa_request{procedure = {_, 'ASR'}} = Request, run, Data) ->
ergw_aaa_session:response(Request, ok, #{}, #{}),
delete_context(undefined, administrative, Data);
Expand Down Expand Up @@ -261,9 +256,10 @@ handle_event(info, {pfcp_timer, #{validity_time := ChargingKeys}}, _State, Data)
handle_event(info, _Info, _State, _Data) ->
keep_state_and_data;

handle_event(internal, {session, stop, _Session}, _State, Data) ->
close_pdn_context(normal, Data),
{next_state, shutdown, Data};
handle_event(internal, {session, stop, _Session}, run, Data) ->
delete_context(undefined, normal, Data);
handle_event(internal, {session, stop, _Session}, _, Data) ->
keep_state_and_data;

handle_event(internal, {session, {update_credits, _} = CreditEv, _}, _State,
#{context := Context, pfcp := PCtx0, pcc := PCC0} = Data) ->
Expand Down
4 changes: 0 additions & 4 deletions src/tdf.erl
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,6 @@ handle_event(info, {'DOWN', _MonitorRef, Type, Pid, _Info},
close_pdn_context(upf_failure, State, Data),
{next_state, shutdown, Data};

handle_event(info, stop_from_session, State, Data) ->
close_pdn_context(normal, State, Data),
{next_state, shutdown, Data};

handle_event(info, #aaa_request{procedure = {_, 'RAR'}} = Request, shutdown, _Data) ->
ergw_aaa_session:response(Request, {error, unknown_session}, #{}, #{}),
keep_state_and_data;
Expand Down
27 changes: 27 additions & 0 deletions test/ggsn_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@
'Volume-Quota-Threshold' => [10240]
}]
},
'Update-OCS-Fail' =>
#{'Result-Code' => 3001},
'Update-OCS' =>
#{'Result-Code' => 2001,
'Multiple-Services-Credit-Control' =>
Expand Down Expand Up @@ -403,6 +405,7 @@ common() ->
gx_asr,
gx_rar,
gy_asr,
gy_async_stop,
gx_invalid_charging_rulebase,
gx_invalid_charging_rule,
gx_rar_gy_interaction].
Expand Down Expand Up @@ -510,6 +513,11 @@ init_per_testcase(gy_validity_timer, Config) ->
set_online_charging(true),
load_ocs_config('Initial-OCS-VT', 'Update-OCS-VT'),
Config;
init_per_testcase(gy_async_stop, Config) ->
init_per_testcase(Config),
set_online_charging(true),
load_ocs_config('Initial-OCS-VT', 'Update-OCS-Fail'),
Config;
init_per_testcase(TestCase, Config)
when TestCase == simple_ocs;
TestCase == gy_ccr_asr_overlap;
Expand Down Expand Up @@ -2156,6 +2164,25 @@ gy_asr(Config) ->
meck_validate(Config),
ok.

%%--------------------------------------------------------------------
gy_async_stop() ->
[{doc, "Check that a error/stop from async session call terminates the context"}].
gy_async_stop(Config) ->
Cntl = whereis(gtpc_client_server),

{GtpC, _, _} = create_pdp_context(Config),

%% wait up to 10 secs for DPCR
Request = recv_pdu(Cntl, 5000),
?match(#gtp{type = delete_pdp_context_request}, Request),
Response = make_response(Request, simple, GtpC),
send_pdu(Cntl, GtpC, Response),

?equal([], outstanding_requests()),
ok = meck:wait(?HUT, terminate, '_', ?TIMEOUT),
meck_validate(Config),
ok.

%%--------------------------------------------------------------------
gx_invalid_charging_rulebase() ->
[{doc, "Check the reaction to a Gx CCA-I with an invalid Charging-Rule-Base-Name"}].
Expand Down
28 changes: 28 additions & 0 deletions test/pgw_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@
'Volume-Quota-Threshold' => [10240]
}]
},
'Update-OCS-Fail' =>
#{'Result-Code' => 3001},
'Update-OCS' =>
#{'Result-Code' => 2001,
'Multiple-Services-Credit-Control' =>
Expand Down Expand Up @@ -517,6 +519,7 @@ common() ->
gx_asr,
gx_rar,
gy_asr,
gy_async_stop,
gx_invalid_charging_rulebase,
gx_invalid_charging_rule,
gx_rar_gy_interaction,
Expand Down Expand Up @@ -642,6 +645,12 @@ init_per_testcase(gy_validity_timer, Config) ->
load_aaa_answer_config([{{gy, 'CCR-Initial'}, 'Initial-OCS-VT'},
{{gy, 'CCR-Update'}, 'Update-OCS-VT'}]),
Config;
init_per_testcase(gy_async_stop, Config) ->
init_per_testcase(Config),
set_online_charging(true),
load_aaa_answer_config([{{gy, 'CCR-Initial'}, 'Initial-OCS-VT'},
{{gy, 'CCR-Update'}, 'Update-OCS-Fail'}]),
Config;
init_per_testcase(TestCase, Config)
when TestCase == simple_ocs;
TestCase == gy_ccr_asr_overlap;
Expand Down Expand Up @@ -3296,6 +3305,25 @@ gy_asr(Config) ->
meck_validate(Config),
ok.

%%--------------------------------------------------------------------
gy_async_stop() ->
[{doc, "Check that a error/stop from async session call terminates the context"}].
gy_async_stop(Config) ->
Cntl = whereis(gtpc_client_server),

{GtpC, _, _} = create_session(Config),

%% wait up to 10 secs for DBR
Req = recv_pdu(Cntl, 10000),
?match(#gtp{type = delete_bearer_request}, Req),
Resp = make_response(Req, simple, GtpC),
send_pdu(Cntl, GtpC, Resp),

?equal([], outstanding_requests()),
ok = meck:wait(?HUT, terminate, '_', ?TIMEOUT),
meck_validate(Config),
ok.

%%--------------------------------------------------------------------
tdf_app_id() ->
[{doc, "Check Session with Gx TDF-Application-Identifier"}].
Expand Down
28 changes: 28 additions & 0 deletions test/saegw_s11_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@
'Volume-Quota-Threshold' => [10240]
}]
},
'Update-OCS-Fail' =>
#{'Result-Code' => 3001},
'Update-OCS' =>
#{'Result-Code' => 2001,
'Multiple-Services-Credit-Control' =>
Expand Down Expand Up @@ -390,6 +392,7 @@ common() ->
gx_asr,
gx_rar,
gy_asr,
gy_async_stop,
gx_invalid_charging_rulebase,
gx_invalid_charging_rule,
gx_rar_gy_interaction].
Expand Down Expand Up @@ -478,6 +481,12 @@ init_per_testcase(gy_validity_timer, Config) ->
set_online_charging(true),
load_ocs_config('Initial-OCS-VT', 'Update-OCS-VT'),
Config;
init_per_testcase(gy_async_stop, Config) ->
init_per_testcase(Config),
set_online_charging(true),
load_aaa_answer_config([{{gy, 'CCR-Initial'}, 'Initial-OCS-VT'},
{{gy, 'CCR-Update'}, 'Update-OCS-Fail'}]),
Config;
init_per_testcase(TestCase, Config)
when TestCase == simple_ocs;
TestCase == gy_ccr_asr_overlap;
Expand Down Expand Up @@ -1843,6 +1852,25 @@ gy_asr(Config) ->
meck_validate(Config),
ok.

%%--------------------------------------------------------------------
gy_async_stop() ->
[{doc, "Check that a error/stop from async session call terminates the context"}].
gy_async_stop(Config) ->
Cntl = whereis(gtpc_client_server),

{GtpC, _, _} = create_session(Config),

%% wait up to 10 secs for DBR
Req = recv_pdu(Cntl, 10000),
?match(#gtp{type = delete_bearer_request}, Req),
Resp = make_response(Req, simple, GtpC),
send_pdu(Cntl, GtpC, Resp),

?equal([], outstanding_requests()),
ok = meck:wait(?HUT, terminate, '_', ?TIMEOUT),
meck_validate(Config),
ok.

%%--------------------------------------------------------------------
gx_invalid_charging_rulebase() ->
[{doc, "Check the reaction to a Gx CCA-I with an invalid Charging-Rule-Base-Name"}].
Expand Down
29 changes: 16 additions & 13 deletions test/tdf_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ simple_session(Config) ->
}, URR),

{tdf, Pid} = gtp_context_reg:lookup({ue, <<3, "sgi">>, UeIP}),
Pid ! stop_from_session,
stop_session(Pid),

ct:sleep({seconds, 1}),

Expand Down Expand Up @@ -695,7 +695,7 @@ gy_validity_timer(Config) ->
?match(Y when Y >= 3 andalso Y < 10, length(CCRU)),

{tdf, Pid} = gtp_context_reg:lookup({ue, <<3, "sgi">>, UeIP}),
Pid ! stop_from_session,
stop_session(Pid),

ct:sleep({seconds, 1}),

Expand Down Expand Up @@ -771,7 +771,7 @@ simple_aaa(Config) ->
ergw_test_sx_up:usage_report('tdf-u', PCtx, MatchSpec, Report),

ct:sleep(100),
Server ! stop_from_session,
stop_session(Server),
ct:sleep(100),

H = meck:history(ergw_aaa_session),
Expand Down Expand Up @@ -865,7 +865,7 @@ simple_ofcs(Config) ->
ergw_test_sx_up:usage_report('tdf-u', PCtx, MatchSpec, Report),

ct:sleep(100),
Server ! stop_from_session,
stop_session(Server),
ct:sleep(100),

H = meck:history(ergw_aaa_session),
Expand Down Expand Up @@ -963,7 +963,7 @@ simple_ocs(Config) ->
ergw_test_sx_up:usage_report('tdf-u', PCtx, MatchSpec, Report),

ct:sleep(100),
Server ! stop_from_session,
stop_session(Server),
ct:sleep(100),

H = meck:history(ergw_aaa_session),
Expand Down Expand Up @@ -1087,7 +1087,7 @@ gy_ccr_asr_overlap(Config) ->
meck:passthrough([MSession, MSessionOpts, Procedure, Opts])
end),

Server ! stop_from_session,
stop_session(Server),

ct:sleep({seconds, 1}),

Expand Down Expand Up @@ -1165,7 +1165,7 @@ volume_threshold(Config) ->
?match(X when X == 1, length(CCRUvolqu)),

{tdf, Pid} = gtp_context_reg:lookup({ue, <<3, "sgi">>, UeIP}),
Pid ! stop_from_session,
stop_session(Pid),

ct:sleep({seconds, 1}),

Expand Down Expand Up @@ -1258,7 +1258,7 @@ gx_rar(Config) ->
?match(#{<<"r-0001">> := #{}}, PCR4),
?equal(false, maps:is_key(<<"r-0002">>, PCR4)),

Server ! stop_from_session,
stop_session(Server),

[Sx1, Sx2, Sx3, Sx4 | _] =
lists:filter(
Expand Down Expand Up @@ -1347,7 +1347,7 @@ gx_invalid_charging_rulebase(Config) ->
end, meck:history(ergw_aaa_session)),
?match(X when X == 1, length(CCRU)),

Server ! stop_from_session,
stop_session(Server),

ok = meck:wait(?HUT, terminate, '_', ?TIMEOUT),
wait4tunnels(?TIMEOUT),
Expand Down Expand Up @@ -1376,7 +1376,7 @@ gx_invalid_charging_rule(Config) ->
end, meck:history(ergw_aaa_session)),
?match(X when X == 1, length(CCRU)),

Server ! stop_from_session,
stop_session(Server),

ok = meck:wait(?HUT, terminate, '_', ?TIMEOUT),
wait4tunnels(?TIMEOUT),
Expand Down Expand Up @@ -1432,7 +1432,7 @@ gx_rar_gy_interaction(Config) ->
?equal(1, maps:size(T3)),
?equal(maps:keys(T1), maps:keys(T3)),

Server ! stop_from_session,
stop_session(Server),

ok = meck:wait(?HUT, terminate, '_', ?TIMEOUT),
wait4tunnels(?TIMEOUT),
Expand Down Expand Up @@ -1574,7 +1574,7 @@ redirect_info(Config) ->
}, URR),

{tdf, Pid} = gtp_context_reg:lookup({ue, <<3, "sgi">>, UeIP}),
Pid ! stop_from_session,
stop_session(Pid),

ct:sleep({seconds, 1}),

Expand Down Expand Up @@ -1710,7 +1710,7 @@ tdf_app_id(Config) ->
}, URR),

{tdf, Pid} = gtp_context_reg:lookup({ue, <<3, "sgi">>, UeIP}),
Pid ! stop_from_session,
stop_session(Pid),

ct:sleep({seconds, 1}),

Expand Down Expand Up @@ -1811,3 +1811,6 @@ set_online_charging(Set) ->
{ok, Cfg0} = application:get_env(ergw, charging),
Cfg = set_online_charging(['_', rulebase, '_'], Set, Cfg0),
ok = application:set_env(ergw, charging, Cfg).

stop_session(Pid) when is_pid(Pid) ->
Pid ! {update_session, #{}, [stop]}.

0 comments on commit dffaab4

Please sign in to comment.