lists.osmocom.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

gerrit-log

Thread Start a new thread
Download
Threads by month
  • ----- 2026 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2025 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
gerrit-log@lists.osmocom.org

August 2024

  • 1 participants
  • 1478 discussions
[L] Change in ...osmo-s1gw[master]: erab_fsm: E-RAB FSM implementation
by laforge 09 Aug '24

09 Aug '24
laforge has submitted this change. ( https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/37317?usp=email ) Change subject: erab_fsm: E-RAB FSM implementation ...................................................................... erab_fsm: E-RAB FSM implementation The E-RAB FSM will be used in follow-up patches. This patch also adds 'meck' dependency to the test profile, which is needed to mock the pfcp_peer API in the unit tests. Change-Id: Ic57e14675339b7cadb0cdd7cbc5d3a56288d7297 --- M contrib/generate_build_dep.sh M rebar.config A src/erab_fsm.erl A test/erab_fsm_test.erl A test/pfcp_mock.erl A test/pfcp_mock.hrl 6 files changed, 671 insertions(+), 1 deletion(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/contrib/generate_build_dep.sh b/contrib/generate_build_dep.sh index 3237ae3..08efac9 100755 --- a/contrib/generate_build_dep.sh +++ b/contrib/generate_build_dep.sh @@ -10,10 +10,12 @@ set -x rm -rf _checkouts _build -rebar3 get-deps +REBAR_PROFILE=default rebar3 get-deps +REBAR_PROFILE=test rebar3 get-deps mkdir _checkouts mv ./_build/default/lib/* _checkouts/ mv ./_build/default/plugins/* _checkouts/ +mv ./_build/test/lib/meck _checkouts/ # delete erlang bytecode find _checkouts/ -iname '*beam' -delete tar czf build_dep.tar.gz ./_checkouts diff --git a/rebar.config b/rebar.config index c3e68bb..91bd759 100644 --- a/rebar.config +++ b/rebar.config @@ -4,12 +4,21 @@ {minimum_otp_vsn, "25.2.3"}. +%% run-time deps {deps, [{logger_color_formatter, {git, "https://github.com/rlipscombe/logger_color_formatter.git", {tag, "0.5.0"}}}, {pfcplib, {git, "https://github.com/travelping/pfcplib.git", {branch, "master"}}} ]}. +%% test deps +{profiles, + [{test, [{deps, [{meck, + {git, "https://github.com/eproxus/meck.git", {tag, "0.9.2"}}} + ]} + ]} + ]}. + {plugins, [{provider_asn1, ".*", {git, "https://github.com/knusbaum/provider_asn1.git", {tag, "0.4.0"}}} ]}. diff --git a/src/erab_fsm.erl b/src/erab_fsm.erl new file mode 100644 index 0000000..5635086 --- /dev/null +++ b/src/erab_fsm.erl @@ -0,0 +1,424 @@ +%% Copyright (C) 2024 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de> +%% Author: Vadim Yanitskiy <vyanitskiy(a)sysmocom.de> +%% +%% All Rights Reserved +%% +%% SPDX-License-Identifier: AGPL-3.0-or-later +%% +%% This program is free software; you can redistribute it and/or modify +%% it under the terms of the GNU Affero General Public License as +%% published by the Free Software Foundation; either version 3 of the +%% License, or (at your option) any later version. +%% +%% This program is distributed in the hope that it will be useful, +%% but WITHOUT ANY WARRANTY; without even the implied warranty of +%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +%% GNU General Public License for more details. +%% +%% You should have received a copy of the GNU Affero General Public License +%% along with this program. If not, see <https://www.gnu.org/licenses/>. +%% +%% Additional Permission under GNU AGPL version 3 section 7: +%% +%% If you modify this Program, or any covered work, by linking or +%% combining it with runtime libraries of Erlang/OTP as released by +%% Ericsson on https://www.erlang.org (or a modified version of these +%% libraries), containing parts covered by the terms of the Erlang Public +%% License (https://www.erlang.org/EPLICENSE) the licensors of this +%% Program grant you additional permission to convey the resulting work +%% without the need to license the runtime libraries of Erlang/OTP under +%% the GNU Affero General Public License. Corresponding Source for a +%% non-source form of such a combination shall include the source code +%% for the parts of the runtime libraries of Erlang/OTP used as well as +%% that of the covered work. + +-module(erab_fsm). +-behaviour(gen_statem). + +-export([init/1, + callback_mode/0, + erab_wait_setup_req/3, + session_establish/3, + erab_wait_setup_rsp/3, + session_modify/3, + erab_setup/3, + session_delete/3, + erab_wait_release_rsp/3, + code_change/4, + terminate/3]). +-export([start_link/1, + erab_setup_req/2, + erab_setup_rsp/2, + erab_release_req/1, + erab_release_rsp/1, + shutdown/1]). + +-include_lib("kernel/include/logger.hrl"). +-include_lib("pfcplib/include/pfcp_packet.hrl"). + + +-define(ERAB_T_WAIT_SETUP_RSP, 5_000). +-define(ERAB_T_WAIT_RELEASE_RSP, 5_000). +-define(ERAB_T_SESSION_ESTABLISH, 2_000). +-define(ERAB_T_SESSION_MODIFY, 2_000). +-define(ERAB_T_SESSION_DELETE, 2_000). + +-type teid() :: 0..16#ffffffff. + +-record(erab_state, {from :: undefined | gen_statem:from(), %% destination to use when replying + teid_from_access :: undefined | teid(), %% TEID to be used in eNB -> UPF + teid_to_access :: undefined | teid(), %% TEID to be used in UPF -> eNB + teid_from_core :: undefined | teid(), %% TEID to be used in PGW -> UPF + teid_to_core :: undefined | teid(), %% TEID to be used in UPF -> PGW + seid_loc :: undefined | pfcp_peer:pfcp_seid(), %% local SEID, chosen by us + seid_rem :: undefined | pfcp_peer:pfcp_seid() %% remote SEID, chosen by the UPF + }). + +-type erab_state() :: #erab_state{}. + +%% ------------------------------------------------------------------ +%% public API +%% ------------------------------------------------------------------ + +-spec start_link(term()) -> gen_statem:start_ret(). +start_link(UID) -> + gen_statem:start_link(?MODULE, [UID], []). + + +%% @doc Indicate reception of E-RAB setup request (from the eNB). +%% @param Pid PID of an erab_fsm. +%% @param UID *unique* E-RAB identifier. +%% @param TEID TEID chosen by the eNB. +%% @returns TEID to be sent to the core; an error otherwise. +%% @end +-spec erab_setup_req(pid(), teid()) -> {ok, teid()} | + {error, term()}. +erab_setup_req(Pid, TEID) -> + gen_statem:call(Pid, {?FUNCTION_NAME, TEID}). + + +%% @doc Indicate reception of E-RAB setup response (from the core). +%% @param Pid PID of an erab_fsm. +%% @param TEID TEID chosen by the core. +%% @returns TEID to be sent to the eNB; an error otherwise. +%% @end +-spec erab_setup_rsp(pid(), teid()) -> {ok, teid()} | + {error, term()}. +erab_setup_rsp(Pid, TEID) -> + gen_statem:call(Pid, {?FUNCTION_NAME, TEID}). + + +-spec erab_release_req(pid()) -> ok. +erab_release_req(Pid) -> + gen_statem:call(Pid, ?FUNCTION_NAME). + + +-spec erab_release_rsp(pid()) -> ok. +erab_release_rsp(Pid) -> + gen_statem:cast(Pid, ?FUNCTION_NAME). + + +-spec shutdown(pid()) -> ok. +shutdown(Pid) -> + gen_statem:stop(Pid). + + +%% ------------------------------------------------------------------ +%% gen_statem API +%% ------------------------------------------------------------------ + +init([UID]) -> + set_logging_prefix(UID), + %% request a unieue SEID for this E-RAB FSM + {ok, SEID} = pfcp_peer:seid_alloc(), + {ok, erab_wait_setup_req, + #erab_state{seid_loc = SEID}}. + + +callback_mode() -> + [state_functions, state_enter]. + + +%% state WAIT_SETUP_REQ :: wait E-RAB SETUP Req from the Access +erab_wait_setup_req(enter, ?FUNCTION_NAME, S) -> + ?LOG_DEBUG("State enter: ~p", [?FUNCTION_NAME]), + {keep_state, S}; + +erab_wait_setup_req({call, From}, + {erab_setup_req, TEID_FromAcc}, + #erab_state{} = S) -> + ?LOG_DEBUG("Rx E-RAB SETUP Req (Access TEID ~p)", [TEID_FromAcc]), + {next_state, session_establish, + S#erab_state{from = From, + teid_from_access = TEID_FromAcc}}; + +erab_wait_setup_req(Event, EventData, S) -> + ?LOG_ERROR("Unexpected event ~p: ~p", [Event, EventData]), + {keep_state, S}. + + +%% state SESSION_ESTABLISH :: PFCP session establishment +session_establish(enter, OldState, S) -> + ?LOG_DEBUG("State change: ~p -> ~p", [OldState, ?FUNCTION_NAME]), + ok = session_establish_req(S), + {next_state, ?FUNCTION_NAME, S, %% loop transition to enable state_timeout + [{state_timeout, ?ERAB_T_SESSION_ESTABLISH, ?FUNCTION_NAME}]}; + +session_establish(state_timeout, _Timeout, + #erab_state{from = From}) -> + ?LOG_ERROR("PFCP session establishment timeout"), + {stop_and_reply, + {shutdown, timeout}, + {reply, From, {error, {timeout, ?FUNCTION_NAME}}}}; + +session_establish(info, #pfcp{} = PDU, + #erab_state{from = From, + seid_loc = SEID_Rsp} = S) -> + case PDU of + #pfcp{type = session_establishment_response, + seid = SEID_Rsp, %% matches F-SEID we sent in the ESTABLISH Req + ie = #{pfcp_cause := 'Request accepted', + f_seid := #f_seid{seid = F_SEID}, + created_pdr := [#{f_teid := #f_teid{teid = TEID_ToCore}}, + #{f_teid := #f_teid{teid = TEID_ToAcc}}]}} -> + ?LOG_DEBUG("PFCP session established"), + {next_state, erab_wait_setup_rsp, + S#erab_state{from = undefined, + seid_rem = F_SEID, %% SEID to be used in further requests from us + teid_to_core = TEID_ToCore, + teid_to_access = TEID_ToAcc}, + [{reply, From, {ok, TEID_ToCore}}]}; + _ -> + ?LOG_ERROR("Rx unexpected PFCP PDU: ~p", [PDU]), + {stop_and_reply, + {shutdown, unexp_pdu}, + {reply, From, {error, {unexp_pdu, ?FUNCTION_NAME}}}} + end; + +session_establish(Event, EventData, S) -> + ?LOG_ERROR("Unexpected event ~p: ~p", [Event, EventData]), + {keep_state, S}. + + +%% state WAIT_SETUP_RSP :: wait E-RAB SETUP Rsp from the Core +erab_wait_setup_rsp(enter, OldState, S) -> + ?LOG_DEBUG("State change: ~p -> ~p", [OldState, ?FUNCTION_NAME]), + {next_state, ?FUNCTION_NAME, S, %% loop transition to enable state_timeout + [{state_timeout, ?ERAB_T_WAIT_SETUP_RSP, ?FUNCTION_NAME}]}; + +erab_wait_setup_rsp(state_timeout, _Timeout, _S) -> + {stop, {shutdown, timeout}}; + +erab_wait_setup_rsp({call, From}, + {erab_setup_rsp, TEID_FromCore}, + #erab_state{} = S) -> + ?LOG_DEBUG("Rx E-RAB SETUP Rsp (Core TEID ~p)", [TEID_FromCore]), + {next_state, session_modify, + S#erab_state{from = From, + teid_from_core = TEID_FromCore}}; + +%% Catch-all handler for this state +erab_wait_setup_rsp(Event, EventData, S) -> + ?LOG_ERROR("Unexpected event ~p: ~p", [Event, EventData]), + {keep_state, S}. + + +%% state SESSION_MODIFY :: PFCP session modification +session_modify(enter, OldState, S) -> + ?LOG_DEBUG("State change: ~p -> ~p", [OldState, ?FUNCTION_NAME]), + ok = session_modify_req(S), + {next_state, ?FUNCTION_NAME, S, %% loop transition to enable state_timeout + [{state_timeout, ?ERAB_T_SESSION_MODIFY, ?FUNCTION_NAME}]}; + +session_modify(state_timeout, _Timeout, + #erab_state{from = From}) -> + ?LOG_ERROR("PFCP session modification timeout"), + {stop_and_reply, + {shutdown, timeout}, + {reply, From, {error, {timeout, ?FUNCTION_NAME}}}}; + +session_modify(info, #pfcp{} = PDU, + #erab_state{from = From, + seid_loc = SEID_Rsp, + teid_to_access = TEID_ToAcc} = S) -> + case PDU of + #pfcp{type = session_modification_response, + seid = SEID_Rsp, %% matches F-SEID we sent in the ESTABLISH Req + ie = #{pfcp_cause := 'Request accepted'}} -> + ?LOG_DEBUG("PFCP session modified"), + {next_state, erab_setup, + S#erab_state{from = undefined}, + [{reply, From, {ok, TEID_ToAcc}}]}; + _ -> + ?LOG_ERROR("Rx unexpected PFCP PDU: ~p", [PDU]), + {stop_and_reply, + {shutdown, unexp_pdu}, + {reply, From, {error, {unexp_pdu, ?FUNCTION_NAME}}}} + end; + +session_modify(Event, EventData, S) -> + ?LOG_ERROR("Unexpected event ~p: ~p", [Event, EventData]), + {keep_state, S}. + + +%% state SETUP :: E-RAB is fully setup +erab_setup(enter, OldState, S) -> + ?LOG_DEBUG("State change: ~p -> ~p", [OldState, ?FUNCTION_NAME]), + {keep_state, S}; + +erab_setup({call, From}, + erab_release_req, + #erab_state{} = S) -> + ?LOG_DEBUG("Rx E-RAB RELEASE Req"), + {next_state, session_delete, + S#erab_state{from = From}}; + +%% Catch-all handler for this state +erab_setup(Event, EventData, S) -> + ?LOG_ERROR("Unexpected event ~p: ~p", [Event, EventData]), + {keep_state, S}. + + +%% state SESSION_DELETE :: PFCP session deletion +session_delete(enter, OldState, + #erab_state{seid_rem = SEID_Req} = S) -> + ?LOG_DEBUG("State change: ~p -> ~p", [OldState, ?FUNCTION_NAME]), + ok = pfcp_peer:session_delete_req(SEID_Req), + {next_state, ?FUNCTION_NAME, %% loop transition to enable state_timeout + %% unset seid_rem to prevent terminate/3 from deleting the session again + S#erab_state{seid_rem = undefined}, + [{state_timeout, ?ERAB_T_SESSION_DELETE, ?FUNCTION_NAME}]}; + +session_delete(state_timeout, _Timeout, + #erab_state{from = From}) -> + ?LOG_ERROR("PFCP session modification timeout"), + {stop_and_reply, + {shutdown, timeout}, + {reply, From, {error, {timeout, ?FUNCTION_NAME}}}}; + +session_delete(info, #pfcp{} = PDU, + #erab_state{from = From, + seid_loc = SEID_Rsp} = S) -> + case PDU of + #pfcp{type = session_deletion_response, + seid = SEID_Rsp, %% matches F-SEID we sent in the ESTABLISH Req + ie = #{pfcp_cause := 'Request accepted'}} -> + ?LOG_DEBUG("PFCP session deleted"), + {next_state, erab_wait_release_rsp, + S#erab_state{from = undefined}, + [{reply, From, ok}]}; + _ -> + ?LOG_ERROR("Rx unexpected PFCP PDU: ~p", [PDU]), + {stop_and_reply, + {shutdown, unexp_pdu}, + {reply, From, {error, {unexp_pdu, ?FUNCTION_NAME}}}} + end; + +session_delete(Event, EventData, S) -> + ?LOG_ERROR("Unexpected event ~p: ~p", [Event, EventData]), + {keep_state, S}. + + +%% state WAIT_RELEASE_RSP :: wait E-RAB RELEASE Rsp from the Core +erab_wait_release_rsp(enter, OldState, S) -> + ?LOG_DEBUG("State change: ~p -> ~p", [OldState, ?FUNCTION_NAME]), + {next_state, ?FUNCTION_NAME, S, %% loop transition to enable state_timeout + [{state_timeout, ?ERAB_T_WAIT_RELEASE_RSP, ?FUNCTION_NAME}]}; + +erab_wait_release_rsp(state_timeout, _Timeout, _S) -> + {stop, {shutdown, timeout}}; + +erab_wait_release_rsp(cast, erab_release_rsp, + #erab_state{}) -> + ?LOG_DEBUG("Rx E-RAB RELEASE Rsp, we're done"), + {stop, normal}; %% we're done! + +%% Catch-all handler for this state +erab_wait_release_rsp(Event, EventData, S) -> + ?LOG_ERROR("Unexpected event ~p: ~p", [Event, EventData]), + {keep_state, S}. + + +code_change(_Vsn, State, S, _Extra) -> + {ok, State, S}. + + +terminate(Reason, State, S) -> + ?LOG_NOTICE("Terminating in state ~p, reason ~p", [State, Reason]), + case S of + %% PFCP session is not established or was deleted + #erab_state{seid_rem = undefined} -> + ok; + %% PFCP session is established, so we terminate it + #erab_state{seid_rem = SEID_Req} -> + ?LOG_INFO("Sending Session Deletion Req"), + pfcp_peer:session_delete_req(SEID_Req) + end. + + +%% ------------------------------------------------------------------ +%% private API +%% ------------------------------------------------------------------ + +%% set process metadata for the logger +set_logging_prefix(UID) -> + Prefix = io_lib:format("E-RAB ~p", [UID]), + logger:set_process_metadata(#{prefix => Prefix}). + + +-spec session_establish_req(erab_state()) -> pfcp_peer:pfcp_session_rsp(). +session_establish_req(#erab_state{seid_loc = F_SEID, %% used as F-SEID + teid_from_access = TEID_FromAcc}) -> + %% Packet Detection Rules + OHR = #outer_header_removal{header = 'GTP-U/UDP/IPv4'}, + PDRs = [#{pdr_id => {pdr_id, 1}, %% -- for Core -> Access + far_id => {far_id, 1}, %% see FARs below + precedence => {precedence, 255}, + outer_header_removal => OHR, + pdi => #{f_teid => #f_teid{teid = choose, + ipv4 = choose}, + source_interface => {source_interface, 'Core'}}}, + #{pdr_id => {pdr_id, 2}, %% -- for Access -> Core + far_id => {far_id, 2}, %% see FARs below + precedence => {precedence, 255}, + outer_header_removal => OHR, + pdi => #{f_teid => #f_teid{teid = choose, + ipv4 = choose}, + source_interface => {source_interface, 'Access'}}}], + %% Forwarding Action Rules + OHC = #outer_header_creation{n6 = false, + n19 = false, + type = 'GTP-U', + teid = TEID_FromAcc, + ipv4 = <<127,0,0,1>>}, %% XXX: Core facing addr of the UPF + FARs = [#{far_id => {far_id, 1}, %% -- for Core -> Access + %% We don't know the Core side TEID / GTP-U address yet, so we set + %% this FAR to DROP and modify it when we get E-RAB SETUP RESPONSE. + apply_action => #{'DROP' => []}}, + #{far_id => {far_id, 2}, %% -- for Access -> Core + apply_action => #{'FORW' => []}, + forwarding_parameters => + #{outer_header_creation => OHC, + destination_interface => {destination_interface, 'Core'}}}], + pfcp_peer:session_establish_req(F_SEID, PDRs, FARs). + + +-spec session_modify_req(erab_state()) -> pfcp_peer:pfcp_session_rsp(). +session_modify_req(#erab_state{seid_rem = SEID, %% SEID allocated to us + teid_from_core = TEID_FromCore}) -> + %% Forwarding Action Rules + OHC = #outer_header_creation{n6 = false, + n19 = false, + type = 'GTP-U', + teid = TEID_FromCore, + ipv4 = <<127,0,0,1>>}, %% XXX: Access facing addr of the UPF + FARs = [#{far_id => {far_id, 1}, %% -- for Core -> Access + %% Now we know the Core side TEID / GTP-U address, so we modify + %% this FAR (which was previously set to DROP) to FORW. + apply_action => #{'FORW' => []}, + forwarding_parameters => + #{outer_header_creation => OHC, + destination_interface => {destination_interface, 'Access'}}}], + pfcp_peer:session_modify_req(SEID, [], FARs). + +%% vim:set ts=4 sw=4 et: diff --git a/test/erab_fsm_test.erl b/test/erab_fsm_test.erl new file mode 100644 index 0000000..fce03fd --- /dev/null +++ b/test/erab_fsm_test.erl @@ -0,0 +1,122 @@ +-module(erab_fsm_test). + +-include_lib("eunit/include/eunit.hrl"). +-include("pfcp_mock.hrl"). + +%% ------------------------------------------------------------------ +%% setup functions +%% ------------------------------------------------------------------ + +-define(TC(Fun), {setup, + fun start/0, + fun stop/1, + Fun}). + + +start() -> + %% mock the PFCP peer API + pfcp_mock:mock_all(), + %% start an E-RAB FSM + {ok, Pid} = erab_fsm:start_link(?MODULE), + Pid. + + +stop(_Pid) -> + pfcp_mock:unmock_all(). + + +%% ------------------------------------------------------------------ +%% testcase descriptions +%% ------------------------------------------------------------------ + +erab_setup_test_() -> + [{"E-RAB setup :: success", + ?TC(fun test_erab_setup_success/1)}, + {"E-RAB setup :: PFCP session establishment error", + ?TC(fun test_erab_setup_pfcp_establish_error/1)}, + {"E-RAB setup :: PFCP session modification error", + ?TC(fun test_erab_setup_pfcp_modify_error/1)}]. + + +erab_release_test_() -> + [{"E-RAB release :: success", + ?TC(fun test_erab_release_success/1)}, + {"E-RAB release :: PFCP session deletion error", + ?TC(fun test_erab_release_pfcp_delete_error/1)}]. + + +erab_shutdown_test_() -> + [{"E-RAB shutdown (no session)", + ?TC(fun test_erab_shutdown_no_session/1)}, + {"E-RAB shutdown (expect session deletion)", + ?TC(fun test_erab_shutdown_session_del/1)}]. + + +%% ------------------------------------------------------------------ +%% actual testcases +%% ------------------------------------------------------------------ + +test_erab_setup_success(Pid) -> + [?_assertEqual({ok, ?TEID_ToCore}, erab_fsm:erab_setup_req(Pid, ?TEID_FromAcc)), + ?_assertEqual({ok, ?TEID_ToAcc}, erab_fsm:erab_setup_rsp(Pid, ?TEID_FromCore)), + ?_assertEqual(ok, erab_fsm:shutdown(Pid)), + ?_assertNot(erlang:is_process_alive(Pid))]. + + +test_erab_setup_pfcp_establish_error(Pid) -> + %% pfcp_peer:session_delete_req/1 shall not be called + ok = pfcp_mock:unmock_req(session_delete_req, 1), + %% pfcp_peer:session_establish_req/3 responds with a reject + PDU = pfcp_mock:pdu_rsp_reject(session_establishment_response, ?SEID_Loc), + pfcp_mock:mock_req(session_establish_req, PDU), + unlink(Pid), %% we expect the FSM to terminate abnormally + Error = {unexp_pdu, session_establish}, + [?_assertEqual({error, Error}, erab_fsm:erab_setup_req(Pid, ?TEID_FromAcc)), + ?_assertNot(erlang:is_process_alive(Pid))]. + + +test_erab_setup_pfcp_modify_error(Pid) -> + %% pfcp_peer:session_modify_req/3 responds with a reject + PDU = pfcp_mock:pdu_rsp_reject(session_modification_response, ?SEID_Loc), + pfcp_mock:mock_req(session_modify_req, PDU), + unlink(Pid), %% we expect the FSM to terminate abnormally + Error = {unexp_pdu, session_modify}, + [?_assertEqual({ok, ?TEID_ToCore}, erab_fsm:erab_setup_req(Pid, ?TEID_FromAcc)), + ?_assertEqual({error, Error}, erab_fsm:erab_setup_rsp(Pid, ?TEID_FromCore)), + ?_assertNot(erlang:is_process_alive(Pid))]. + + +test_erab_release_success(Pid) -> + [?_assertEqual({ok, ?TEID_ToCore}, erab_fsm:erab_setup_req(Pid, ?TEID_FromAcc)), + ?_assertEqual({ok, ?TEID_ToAcc}, erab_fsm:erab_setup_rsp(Pid, ?TEID_FromCore)), + ?_assertEqual(ok, erab_fsm:erab_release_req(Pid)), + ?_assertEqual(ok, erab_fsm:erab_release_rsp(Pid)), + ?_assertNot(erlang:is_process_alive(Pid))]. + + +test_erab_release_pfcp_delete_error(Pid) -> + %% pfcp_peer:session_delete_req/1 responds with a reject + PDU = pfcp_mock:pdu_rsp_reject(session_deletion_response, ?SEID_Loc), + pfcp_mock:mock_req(session_delete_req, PDU), + unlink(Pid), %% we expect the FSM to terminate abnormally + Error = {unexp_pdu, session_delete}, + [?_assertEqual({ok, ?TEID_ToCore}, erab_fsm:erab_setup_req(Pid, ?TEID_FromAcc)), + ?_assertEqual({ok, ?TEID_ToAcc}, erab_fsm:erab_setup_rsp(Pid, ?TEID_FromCore)), + ?_assertEqual({error, Error}, erab_fsm:erab_release_req(Pid)), + ?_assertNot(erlang:is_process_alive(Pid))]. + + +test_erab_shutdown_no_session(Pid) -> + %% pfcp_peer:session_delete_req/1 shall not be called + ok = pfcp_mock:unmock_req(session_delete_req, 1), + [?_assertEqual(ok, erab_fsm:shutdown(Pid)), + ?_assertNot(erlang:is_process_alive(Pid))]. + + +test_erab_shutdown_session_del(Pid) -> + [?_assertEqual({ok, ?TEID_ToCore}, erab_fsm:erab_setup_req(Pid, ?TEID_FromAcc)), + ?_assertEqual({ok, ?TEID_ToAcc}, erab_fsm:erab_setup_rsp(Pid, ?TEID_FromCore)), + ?_assertEqual(ok, erab_fsm:shutdown(Pid)), + ?_assertNot(erlang:is_process_alive(Pid))]. + +%% vim:set ts=4 sw=4 et: diff --git a/test/pfcp_mock.erl b/test/pfcp_mock.erl new file mode 100644 index 0000000..c9f8297 --- /dev/null +++ b/test/pfcp_mock.erl @@ -0,0 +1,104 @@ +-module(pfcp_mock). + +-export([mock_all/0, + mock_req/2, + unmock_all/0, + unmock_req/2]). +-export([pdu_rsp/3, + pdu_rsp_accept/2, + pdu_rsp_reject/2, + pdu_session_establish_rsp/0, + pdu_session_modify_rsp/0, + pdu_session_delete_rsp/0]). + +-include_lib("stdlib/include/assert.hrl"). +-include_lib("pfcplib/include/pfcp_packet.hrl"). +-include("pfcp_mock.hrl"). + +%% ------------------------------------------------------------------ +%% public API +%% ------------------------------------------------------------------ + +%% mock all pfcp_peer module functions +mock_all() -> + meck:new(pfcp_peer), + meck:expect(pfcp_peer, seid_alloc, fun() -> {ok, ?SEID_Loc} end), + mock_req(session_establish_req, pdu_session_establish_rsp()), + mock_req(session_modify_req, pdu_session_modify_rsp()), + mock_req(session_delete_req, pdu_session_delete_rsp()). + + +%% unmock all pfcp_peer module functions +unmock_all() -> + true = meck:validate(pfcp_peer), + meck:unload(pfcp_peer). + + +pfcp_req_stub(Rsp) -> + %% this code is executed by E-RAB FSM itself, + %% thus self() evaluates to its own Pid + self() ! Rsp, + ok. + + +%% mock one of the pfcp_peer:*_req functions +mock_req(session_establish_req = Fun, Rsp) -> + FunBody = fun(F_SEID, _PDRs, _FARs) -> + %% expect the E-RAB FSM to pass its local SEID as F-SEID + ?assertEqual(F_SEID, ?SEID_Loc), + pfcp_req_stub(Rsp) + end, + meck:expect(pfcp_peer, Fun, FunBody); + +mock_req(session_modify_req = Fun, Rsp) -> + FunBody = fun(SEID, _PDRs, _FARs) -> + %% expect the E-RAB FSM to pass the remote SEID + ?assertEqual(SEID, ?SEID_Rem), + pfcp_req_stub(Rsp) + end, + meck:expect(pfcp_peer, Fun, FunBody); + +mock_req(session_delete_req = Fun, Rsp) -> + FunBody = fun(SEID) -> + %% expect the E-RAB FSM to pass the remote SEID + ?assertEqual(SEID, ?SEID_Rem), + pfcp_req_stub(Rsp) + end, + meck:expect(pfcp_peer, Fun, FunBody). + + +%% unmock one of the pfcp_peer:*_req functions +unmock_req(Fun, Arity) -> + meck:delete(pfcp_peer, Fun, Arity). + + +%% ------------------------------------------------------------------ +%% PFCP PDU templates +%% ------------------------------------------------------------------ + +pdu_rsp(MsgType, SEID, IEs) -> + #pfcp{type = MsgType, seid = SEID, ie = IEs}. + +pdu_rsp_accept(MsgType, SEID) -> + pdu_rsp(MsgType, SEID, #{pfcp_cause => 'Request accepted'}). + +pdu_rsp_reject(MsgType, SEID) -> + pdu_rsp(MsgType, SEID, #{pfcp_cause => 'Request rejected'}). + + +pdu_session_establish_rsp() -> + IEs = #{pfcp_cause => 'Request accepted', + f_seid => #f_seid{seid = ?SEID_Rem}, + created_pdr => [#{f_teid => #f_teid{teid = ?TEID_ToCore}}, + #{f_teid => #f_teid{teid = ?TEID_ToAcc}}]}, + pdu_rsp(session_establishment_response, ?SEID_Loc, IEs). + + +pdu_session_modify_rsp() -> + pdu_rsp_accept(session_modification_response, ?SEID_Loc). + + +pdu_session_delete_rsp() -> + pdu_rsp_accept(session_deletion_response, ?SEID_Loc). + +%% vim:set ts=4 sw=4 et: diff --git a/test/pfcp_mock.hrl b/test/pfcp_mock.hrl new file mode 100644 index 0000000..06b5c5a --- /dev/null +++ b/test/pfcp_mock.hrl @@ -0,0 +1,9 @@ +-define(SEID_Loc, 16#dead). +-define(SEID_Rem, 16#beef). + +-define(TEID_FromAcc, 16#0001). +-define(TEID_FromCore, 16#0002). +-define(TEID_ToAcc, 16#0003). +-define(TEID_ToCore, 16#0004). + +%% vim:set ts=4 sw=4 et: -- To view, visit https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/37317?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: erlang/osmo-s1gw Gerrit-Branch: master Gerrit-Change-Id: Ic57e14675339b7cadb0cdd7cbc5d3a56288d7297 Gerrit-Change-Number: 37317 Gerrit-PatchSet: 12 Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
1 0
0 0
[L] Change in ...osmo-s1gw[master]: sctp_proxy: maintain opaque state for s1ap_proxy
by laforge 09 Aug '24

09 Aug '24
laforge has submitted this change. ( https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/37462?usp=email ) Change subject: sctp_proxy: maintain opaque state for s1ap_proxy ...................................................................... sctp_proxy: maintain opaque state for s1ap_proxy Change-Id: I6ea8479c1a66bca330a7d4030cc7cdf55a76b12c --- M src/s1ap_proxy.erl M src/sctp_proxy.erl M test/s1ap_proxy_test.erl 3 files changed, 172 insertions(+), 104 deletions(-) Approvals: Jenkins Builder: Verified osmith: Looks good to me, but someone else must approve laforge: Looks good to me, approved diff --git a/src/s1ap_proxy.erl b/src/s1ap_proxy.erl index 579df40..eaa7dfd 100644 --- a/src/s1ap_proxy.erl +++ b/src/s1ap_proxy.erl @@ -34,7 +34,9 @@ -module(s1ap_proxy). --export([handle_pdu/1, +-export([init/0, + deinit/1, + handle_pdu/2, encode_pdu/1, decode_pdu/1]). @@ -45,20 +47,37 @@ -include("S1AP-Containers.hrl"). -include("S1AP-Constants.hrl"). + +-record(proxy_state, { }). + +-type proxy_state() :: #proxy_state{}. + %% ------------------------------------------------------------------ %% public API %% ------------------------------------------------------------------ +%% Initialize per-connection data +-spec init() -> proxy_state(). +init() -> + #proxy_state{}. + + +%% De-initialize per-connection data +-spec deinit(proxy_state()) -> ok. +deinit(_S) -> + ok. + + %% Process an S1AP PDU --spec handle_pdu(binary()) -> binary(). -handle_pdu(Data) when is_binary(Data) -> +-spec handle_pdu(binary(), proxy_state()) -> {binary(), proxy_state()}. +handle_pdu(Data, S) when is_binary(Data) -> case decode_pdu(Data) of {ok, Pdu} -> ?LOG_INFO("S1AP PDU: ~p", [Pdu]), - handle_pdu(Data, Pdu); + handle_pdu(Data, Pdu, S); {error, {asn1, Error}} -> ?LOG_ERROR("S1AP PDU decoding failed: ~p", [Error]), - Data + {Data, S} end. @@ -80,73 +99,73 @@ 'S1AP-PDU-Descriptions':decode('S1AP-PDU', Data). -%% Helper function for handle_pdu/2. +%% Helper function for handle_pdu/3. %% Attempt to encode a new (modified) S1AP PDU, %% return a new binary() on success or Data on error. -handle_pdu_new(Data, NewPdu) -> +handle_pdu_new(Data, NewPdu, S) -> case encode_pdu(NewPdu) of {ok, NewData} -> - NewData; + {NewData, S}; {error, {asn1, Error}} -> ?LOG_ERROR("S1AP PDU encoding failed: ~p", [Error]), - Data + {Data, S} end. %% 9.1.3.1 E-RAB SETUP REQUEST handle_pdu(Data, {Outcome = initiatingMessage, #'InitiatingMessage'{procedureCode = ?'id-E-RABSetup', - value = Content} = Pdu}) -> + value = Content} = Pdu}, S0) -> ?LOG_DEBUG("Patching E-RAB SETUP REQUEST"), - IEs = handle_ies(Content#'E-RABSetupRequest'.protocolIEs, - ?'id-E-RABToBeSetupListBearerSUReq'), + {IEs, S1} = handle_ies(Content#'E-RABSetupRequest'.protocolIEs, + ?'id-E-RABToBeSetupListBearerSUReq', S0), NewContent = Content#'E-RABSetupRequest'{protocolIEs = IEs}, - handle_pdu_new(Data, {Outcome, Pdu#'InitiatingMessage'{value = NewContent}}); + handle_pdu_new(Data, {Outcome, Pdu#'InitiatingMessage'{value = NewContent}}, S1); %% 9.1.3.2 E-RAB SETUP RESPONSE handle_pdu(Data, {Outcome = successfulOutcome, #'SuccessfulOutcome'{procedureCode = ?'id-E-RABSetup', - value = Content} = Pdu}) -> + value = Content} = Pdu}, S0) -> ?LOG_DEBUG("Patching E-RAB SETUP RESPONSE"), - IEs = handle_ies(Content#'E-RABSetupResponse'.protocolIEs, - ?'id-E-RABSetupListBearerSURes'), + {IEs, S1} = handle_ies(Content#'E-RABSetupResponse'.protocolIEs, + ?'id-E-RABSetupListBearerSURes', S0), NewContent = Content#'E-RABSetupResponse'{protocolIEs = IEs}, - handle_pdu_new(Data, {Outcome, Pdu#'SuccessfulOutcome'{value = NewContent}}); + handle_pdu_new(Data, {Outcome, Pdu#'SuccessfulOutcome'{value = NewContent}}, S1); %% TODO: 9.1.3.3 E-RAB MODIFY REQUEST / (Optional) Transport Information %% 9.1.3.8 E-RAB MODIFICATION INDICATION handle_pdu(Data, {Outcome = initiatingMessage, #'InitiatingMessage'{procedureCode = ?'id-E-RABModificationIndication', - value = Content} = Pdu}) -> + value = Content} = Pdu}, S0) -> ?LOG_DEBUG("Patching E-RAB MODIFICATION INDICATION"), IEs = Content#'E-RABModificationIndication'.protocolIEs, %% E-RAB to be Modified List - IEs1 = handle_ies(IEs, ?'id-E-RABToBeModifiedListBearerModInd'), + {IEs1, S1} = handle_ies(IEs, ?'id-E-RABToBeModifiedListBearerModInd', S0), %% E-RAB not to be Modified List - IEs2 = handle_ies(IEs1, ?'id-E-RABNotToBeModifiedListBearerModInd'), + {IEs2, S2} = handle_ies(IEs1, ?'id-E-RABNotToBeModifiedListBearerModInd', S1), NewContent = Content#'E-RABModificationIndication'{protocolIEs = IEs2}, - handle_pdu_new(Data, {Outcome, Pdu#'InitiatingMessage'{value = NewContent}}); + handle_pdu_new(Data, {Outcome, Pdu#'InitiatingMessage'{value = NewContent}}, S2); %% 9.1.4.1 INITIAL CONTEXT SETUP REQUEST handle_pdu(Data, {Outcome = initiatingMessage, #'InitiatingMessage'{procedureCode = ?'id-InitialContextSetup', - value = Content} = Pdu}) -> + value = Content} = Pdu}, S0) -> ?LOG_DEBUG("Patching INITIAL CONTEXT SETUP REQUEST"), - IEs = handle_ies(Content#'InitialContextSetupRequest'.protocolIEs, - ?'id-E-RABToBeSetupListCtxtSUReq'), + {IEs, S1} = handle_ies(Content#'InitialContextSetupRequest'.protocolIEs, + ?'id-E-RABToBeSetupListCtxtSUReq', S0), NewContent = Content#'InitialContextSetupRequest'{protocolIEs = IEs}, - handle_pdu_new(Data, {Outcome, Pdu#'InitiatingMessage'{value = NewContent}}); + handle_pdu_new(Data, {Outcome, Pdu#'InitiatingMessage'{value = NewContent}}, S1); %% 9.1.4.3 INITIAL CONTEXT SETUP RESPONSE handle_pdu(Data, {Outcome = successfulOutcome, #'SuccessfulOutcome'{procedureCode = ?'id-InitialContextSetup', - value = Content} = Pdu}) -> + value = Content} = Pdu}, S0) -> ?LOG_DEBUG("Patching INITIAL CONTEXT SETUP RESPONSE"), - IEs = handle_ies(Content#'InitialContextSetupResponse'.protocolIEs, - ?'id-E-RABSetupListCtxtSURes'), + {IEs, S1} = handle_ies(Content#'InitialContextSetupResponse'.protocolIEs, + ?'id-E-RABSetupListCtxtSURes', S0), NewContent = Content#'InitialContextSetupResponse'{protocolIEs = IEs}, - handle_pdu_new(Data, {Outcome, Pdu#'SuccessfulOutcome'{value = NewContent}}); + handle_pdu_new(Data, {Outcome, Pdu#'SuccessfulOutcome'{value = NewContent}}, S1); %% TODO: 9.1.5.2 HANDOVER COMMAND :: (O) UL/DL Transport Layer Address %% TODO: 9.1.5.4 HANDOVER REQUEST :: (M) Transport Layer Address @@ -156,107 +175,108 @@ %% TODO: 9.1.5.9 PATH SWITCH REQUEST ACKNOWLEDGE :: (M) Transport Layer Address %% Proxy all other messages unmodified -handle_pdu(Data, _Pdu) -> - Data. +handle_pdu(Data, _Pdu, S) -> + {Data, S}. %% Handle a single IE (Information Element) --spec handle_ie(tuple()) -> tuple(). +-spec handle_ie(tuple(), proxy_state()) -> {tuple(), proxy_state()}. %% E-RAB SETUP REQUEST related IEs handle_ie(#'ProtocolIE-Field'{id = ?'id-E-RABToBeSetupListBearerSUReq', - value = Content}) -> + value = Content}, S) -> %% This IE contains a list of BearerSUReq, so patch inner IEs - handle_ies(Content, ?'id-E-RABToBeSetupItemBearerSUReq'); + handle_ies(Content, ?'id-E-RABToBeSetupItemBearerSUReq', S); handle_ie(#'ProtocolIE-Field'{id = ?'id-E-RABToBeSetupItemBearerSUReq', - value = Content}) -> + value = Content}, S) -> %% eNB -> MME direction: we pass our MME facing local address TLA = transp_layer_addr(mme_loc_addr), - Content#'E-RABToBeSetupItemBearerSUReq'{transportLayerAddress = TLA}; + {Content#'E-RABToBeSetupItemBearerSUReq'{transportLayerAddress = TLA}, S}; %% E-RAB SETUP RESPONSE related IEs handle_ie(#'ProtocolIE-Field'{id = ?'id-E-RABSetupListBearerSURes', - value = Content}) -> + value = Content}, S) -> %% This IE contains a list of BearerSURes, so patch inner IEs - handle_ies(Content, ?'id-E-RABSetupItemBearerSURes'); + handle_ies(Content, ?'id-E-RABSetupItemBearerSURes', S); handle_ie(#'ProtocolIE-Field'{id = ?'id-E-RABSetupItemBearerSURes', - value = Content}) -> + value = Content}, S) -> %% MME -> eNB direction: we pass our eNB facing local address TLA = transp_layer_addr(s1gw_bind_addr), - Content#'E-RABSetupItemBearerSURes'{transportLayerAddress = TLA}; + {Content#'E-RABSetupItemBearerSURes'{transportLayerAddress = TLA}, S}; %% E-RAB MODIFICATION INDICATION related IEs handle_ie(#'ProtocolIE-Field'{id = ?'id-E-RABToBeModifiedListBearerModInd', - value = Content}) -> + value = Content}, S) -> %% This IE contains a list of BearerModInd, so patch inner IEs - handle_ies(Content, ?'id-E-RABToBeModifiedItemBearerModInd'); + handle_ies(Content, ?'id-E-RABToBeModifiedItemBearerModInd', S); handle_ie(#'ProtocolIE-Field'{id = ?'id-E-RABToBeModifiedItemBearerModInd', - value = Content}) -> + value = Content}, S) -> %% eNB -> MME direction: we pass our MME facing local address TLA = transp_layer_addr(mme_loc_addr), - Content#'E-RABToBeModifiedItemBearerModInd'{transportLayerAddress = TLA}; + {Content#'E-RABToBeModifiedItemBearerModInd'{transportLayerAddress = TLA}, S}; handle_ie(#'ProtocolIE-Field'{id = ?'id-E-RABNotToBeModifiedListBearerModInd', - value = Content}) -> + value = Content}, S) -> %% This IE contains a list of BearerModInd, so patch inner IEs - handle_ies(Content, ?'id-E-RABNotToBeModifiedItemBearerModInd'); + handle_ies(Content, ?'id-E-RABNotToBeModifiedItemBearerModInd', S); handle_ie(#'ProtocolIE-Field'{id = ?'id-E-RABNotToBeModifiedItemBearerModInd', - value = Content}) -> + value = Content}, S) -> %% eNB -> MME direction: we pass our MME facing local address TLA = transp_layer_addr(mme_loc_addr), - Content#'E-RABNotToBeModifiedItemBearerModInd'{transportLayerAddress = TLA}; + {Content#'E-RABNotToBeModifiedItemBearerModInd'{transportLayerAddress = TLA}, S}; %% INITIAL CONTEXT SETUP REQUEST related IEs handle_ie(#'ProtocolIE-Field'{id = ?'id-E-RABToBeSetupListCtxtSUReq', - value = Content}) -> + value = Content}, S) -> %% This IE contains a list of CtxtSUReq, so patch inner IEs - handle_ies(Content, ?'id-E-RABToBeSetupItemCtxtSUReq'); + handle_ies(Content, ?'id-E-RABToBeSetupItemCtxtSUReq', S); handle_ie(#'ProtocolIE-Field'{id = ?'id-E-RABToBeSetupItemCtxtSUReq', - value = Content}) -> + value = Content}, S) -> %% eNB -> MME direction: we pass our MME facing local address TLA = transp_layer_addr(mme_loc_addr), - Content#'E-RABToBeSetupItemCtxtSUReq'{transportLayerAddress = TLA}; + {Content#'E-RABToBeSetupItemCtxtSUReq'{transportLayerAddress = TLA}, S}; %% INITIAL CONTEXT SETUP RESPONSE related IEs handle_ie(#'ProtocolIE-Field'{id = ?'id-E-RABSetupListCtxtSURes', - value = Content}) -> + value = Content}, S) -> %% This IE contains a list of CtxtSURes, so patch inner IEs - handle_ies(Content, ?'id-E-RABSetupItemCtxtSURes'); + handle_ies(Content, ?'id-E-RABSetupItemCtxtSURes', S); handle_ie(#'ProtocolIE-Field'{id = ?'id-E-RABSetupItemCtxtSURes', - value = Content}) -> + value = Content}, S) -> %% MME -> eNB direction: we pass our eNB facing local address TLA = transp_layer_addr(s1gw_bind_addr), - Content#'E-RABSetupItemCtxtSURes'{transportLayerAddress = TLA}; + {Content#'E-RABSetupItemCtxtSURes'{transportLayerAddress = TLA}, S}; %% Catch-all variant, which should not be called normally -handle_ie(#'ProtocolIE-Field'{value = Content} = IE) -> +handle_ie(#'ProtocolIE-Field'{value = Content} = IE, S) -> ?LOG_ERROR("[BUG] Unhandled S1AP IE: ~p", [IE]), - Content. + {Content, S}. %% Iterate over the given list of 'ProtocolIE-Field' IEs, %% calling function handle_ie/1 for IEs matching the given IEI. --spec handle_ies(list(), integer()) -> list(). -handle_ies(IEs, IEI) -> - handle_ies([], IEs, IEI). +-spec handle_ies(list(), integer(), proxy_state()) -> {list(), proxy_state()}. +handle_ies(IEs, IEI, S) -> + handle_ies([], IEs, IEI, S). -handle_ies(Acc, [IE | IEs], IEI) -> +handle_ies(Acc, [IE | IEs], IEI, S0) -> case IE of #'ProtocolIE-Field'{id = IEI} -> - NewIE = IE#'ProtocolIE-Field'{value = handle_ie(IE)}, - handle_ies([NewIE | Acc], IEs, IEI); + {Content, S1} = handle_ie(IE, S0), + NewIE = IE#'ProtocolIE-Field'{value = Content}, + handle_ies([NewIE | Acc], IEs, IEI, S1); _ -> - handle_ies([IE | Acc], IEs, IEI) + handle_ies([IE | Acc], IEs, IEI, S0) end; -handle_ies(Acc, [], _) -> - lists:reverse(Acc). +handle_ies(Acc, [], _IEI, S) -> + {lists:reverse(Acc), S}. %% GTP-U IP address (TransportLayerAddress) to be used while patching diff --git a/src/sctp_proxy.erl b/src/sctp_proxy.erl index ab147e6..148e00a 100644 --- a/src/sctp_proxy.erl +++ b/src/sctp_proxy.erl @@ -79,7 +79,8 @@ #{enb_aid => Aid, mme_addr => MmeAddr, mme_port => MmePort, - tx_queue => []}}. + tx_queue => [], + priv => s1ap_proxy:init()}}. callback_mode() -> @@ -131,16 +132,16 @@ %% CONNECTED state -connected(enter, OldState, S) -> +connected(enter, OldState, S0) -> ?LOG_INFO("State change: ~p -> ~p", [OldState, ?FUNCTION_NAME]), %% Send pending eNB -> MME messages (if any) - ok = sctp_send_pending(S), - {keep_state, maps:remove(tx_queue, S)}; + S1 = sctp_send_pending(S0), + {keep_state, S1}; %% Handle an eNB -> MME data forwarding request (forward) -connected(cast, {send_data, Data}, S) -> - ok = sctp_send(S, Data), - {keep_state, S}; +connected(cast, {send_data, Data}, S0) -> + S1 = sctp_send(Data, S0), + {keep_state, S1}; %% Handle an #sctp_assoc_change event (MME connection state) connected(info, {sctp, _Socket, MmeAddr, MmePort, @@ -158,11 +159,13 @@ %% Handle an #sctp_sndrcvinfo event (MME -> eNB data) connected(info, {sctp, _Socket, MmeAddr, MmePort, - {[#sctp_sndrcvinfo{assoc_id = Aid}], Data}}, S) -> + {[#sctp_sndrcvinfo{assoc_id = Aid}], Data}}, + #{enb_aid := EnbAid, priv := Priv} = S) -> ?LOG_DEBUG("MME connection (id=~p, ~p:~p) -> eNB: ~p", [Aid, MmeAddr, MmePort, Data]), - sctp_server:send_data(maps:get(enb_aid, S), handle_pdu(Data)), - {keep_state, S}; + {NewData, NewPriv} = handle_pdu(Data, Priv), + sctp_server:send_data(EnbAid, NewData), + {keep_state, S#{priv := NewPriv}}; %% Catch-all for other kinds of SCTP events connected(info, {sctp, _Socket, MmeAddr, MmePort, @@ -185,7 +188,10 @@ terminate(Reason, State, S) -> ?LOG_NOTICE("Terminating in state ~p, reason ~p", [State, Reason]), case S of - #{sock := Sock, mme_aid := Aid} -> + #{sock := Sock, + mme_aid := Aid, + priv := Priv} -> + s1ap_proxy:deinit(Priv), sctp_client:disconnect({Sock, Aid}), gen_sctp:close(Sock); #{sock := Sock} -> @@ -199,31 +205,36 @@ %% ------------------------------------------------------------------ %% A safe wrapper for s1ap_proxy:handle_pdu/1 --spec handle_pdu(binary()) -> binary(). -handle_pdu(Data) when is_binary(Data) -> - try s1ap_proxy:handle_pdu(Data) of - NewData -> NewData +-spec handle_pdu(binary(), term()) -> {binary(), term()}. +handle_pdu(Data, Priv) when is_binary(Data) -> + try s1ap_proxy:handle_pdu(Data, Priv) of + Result -> Result %% {NewData, NewPriv} catch Exception:Reason:StackTrace -> ?LOG_ERROR("An exception occurred: ~p, ~p, ~p", [Exception, Reason, StackTrace]), - Data %% proxy as-is + {Data, Priv} %% proxy as-is end. %% Send a single message to the MME -sctp_send(#{sock := Sock, mme_aid := Aid}, Data) -> - sctp_client:send_data({Sock, Aid}, handle_pdu(Data)). +sctp_send(Data, + #{sock := Sock, + mme_aid := Aid, + priv := Priv} = S) -> + {NewData, NewPriv} = handle_pdu(Data, Priv), + ok = sctp_client:send_data({Sock, Aid}, NewData), + S#{priv := NewPriv}. %% Send pending messages to the MME sctp_send_pending(#{tx_queue := Pending} = S) -> - sctp_send_pending(S, lists:reverse(Pending)). + sctp_send_pending(lists:reverse(Pending), S). -sctp_send_pending(S, [Data | Pending]) -> - sctp_send(S, Data), - sctp_send_pending(S, Pending); +sctp_send_pending([Data | Pending], S0) -> + S1 = sctp_send(Data, S0), + sctp_send_pending(Pending, S1); -sctp_send_pending(_S, []) -> - ok. +sctp_send_pending([], S) -> + S#{tx_queue := []}. %% vim:set ts=4 sw=4 et: diff --git a/test/s1ap_proxy_test.erl b/test/s1ap_proxy_test.erl index e694197..9830af8 100644 --- a/test/s1ap_proxy_test.erl +++ b/test/s1ap_proxy_test.erl @@ -6,7 +6,44 @@ -define(EXP_ADDR_BIN, << 16#7f, 16#00, 16#00, 16#01 >>). %% ------------------------------------------------------------------ -%% testcases +%% setup functions +%% ------------------------------------------------------------------ + +-define(TC(Fun), {setup, + fun start/0, + fun stop/1, + Fun}). + + +start() -> + s1ap_proxy:init(). + + +stop(S) -> + s1ap_proxy:deinit(S). + + +%% ------------------------------------------------------------------ +%% testcase descriptions +%% ------------------------------------------------------------------ + +s1ap_proxy_test_() -> + [{"S1 SETUP REQUEST (unmodified)", + ?TC(fun test_s1_setup_req/1)}, + {"E-RAB SETUP REQUEST", + ?TC(fun test_e_rab_setup_req/1)}, + {"E-RAB SETUP RESPONSE", + ?TC(fun test_e_rab_setup_rsp/1)}, + {"E-RAB MODIFICATION INDICATION", + ?TC(fun test_e_rab_modify_ind/1)}, + {"INITIAL CONTEXT SETUP REQUEST", + ?TC(fun test_initial_context_setup_req/1)}, + {"INITIAL CONTEXT SETUP RESPONSE", + ?TC(fun test_initial_context_setup_rsp/1)}]. + + +%% ------------------------------------------------------------------ +%% actual testcases %% ------------------------------------------------------------------ %% S1 SETUP REQUEST @@ -17,10 +54,10 @@ 16#0c, 16#0e, 16#40, 16#00, 16#f1, 16#10 >>. -s1_setup_req_test() -> +test_s1_setup_req(S) -> OrigData = s1_setup_req_pdu(), %% Expect the PDU to be proxied unmodified - ?assertEqual(OrigData, s1ap_proxy:handle_pdu(OrigData)). + [?_assertEqual({OrigData, S}, s1ap_proxy:handle_pdu(OrigData, S))]. %% [eNB -> MME] E-RAB SETUP REQUEST @@ -50,7 +87,7 @@ 16#16, 16#00, 16#15, 16#00, 16#10, 16#02, 16#05, 16#78 >>. -e_rab_setup_req_test() -> +test_e_rab_setup_req(S) -> %% Original input data TEID = << 16#00, 16#00, 16#00, 16#18 >>, OrigTLA = << 16#ac, 16#16, 16#00, 16#06 >>, @@ -60,7 +97,7 @@ ExpData = e_rab_setup_req_pdu(?EXP_ADDR_BIN, TEID), application:set_env(osmo_s1gw, mme_loc_addr, ?EXP_ADDR_STR), - ?assertEqual(ExpData, s1ap_proxy:handle_pdu(OrigData)). + [?_assertMatch({ExpData, _}, s1ap_proxy:handle_pdu(OrigData, S))]. %% [MME -> eNB] E-RAB SETUP RESPONSE @@ -74,7 +111,7 @@ TEID/bytes %% GTP-TEID >>. -e_rab_setup_rsp_test() -> +test_e_rab_setup_rsp(S) -> %% Original input data TEID = << 16#6c, 16#05, 16#bf, 16#56 >>, OrigTLA = << 16#c0, 16#a8, 16#68, 16#a7 >>, @@ -84,7 +121,7 @@ ExpData = e_rab_setup_rsp_pdu(?EXP_ADDR_BIN, TEID), application:set_env(osmo_s1gw, s1gw_bind_addr, ?EXP_ADDR_STR), - ?assertEqual(ExpData, s1ap_proxy:handle_pdu(OrigData)). + [?_assertMatch({ExpData, _}, s1ap_proxy:handle_pdu(OrigData, S))]. %% [eNB -> MME] E-RAB MODIFICATION INDICATION @@ -98,7 +135,7 @@ TEID/bytes %% GTP-TEID >>. -e_rab_modify_ind_test() -> +test_e_rab_modify_ind(S) -> %% Original input data TEID = << 16#3d, 16#b0, 16#b5, 16#1d >>, OrigTLA = << 16#c0, 16#a8, 16#12, 16#c6 >>, @@ -108,7 +145,7 @@ ExpData = e_rab_modify_ind_pdu(?EXP_ADDR_BIN, TEID), application:set_env(osmo_s1gw, mme_loc_addr, ?EXP_ADDR_STR), - ?assertEqual(ExpData, s1ap_proxy:handle_pdu(OrigData)). + [?_assertMatch({ExpData, _}, s1ap_proxy:handle_pdu(OrigData, S))]. %% [eNB -> MME] INITIAL CONTEXT SETUP REQUEST @@ -153,7 +190,7 @@ 16#10, 16#03, 16#ff, 16#ff, 16#74 >>. -initial_context_setup_req_test() -> +test_initial_context_setup_req(S) -> %% Original input data TEID = << 16#00, 16#00, 16#71, 16#23 >>, OrigTLA = << 16#c0, 16#a8, 16#02, 16#d2 >>, @@ -163,7 +200,7 @@ ExpData = initial_context_setup_req_pdu(?EXP_ADDR_BIN, TEID), application:set_env(osmo_s1gw, mme_loc_addr, ?EXP_ADDR_STR), - ?assertEqual(ExpData, s1ap_proxy:handle_pdu(OrigData)). + [?_assertMatch({ExpData, _}, s1ap_proxy:handle_pdu(OrigData, S))]. %% [MME -> eNB] INITIAL CONTEXT SETUP RESPONSE @@ -177,7 +214,7 @@ TEID/bytes %% GTP-TEID >>. -initial_context_setup_rsp_test() -> +test_initial_context_setup_rsp(S) -> %% Original input data TEID = << 16#00, 16#00, 16#00, 16#01 >>, OrigTLA = << 16#c0, 16#a8, 16#02, 16#cb >>, @@ -187,6 +224,6 @@ ExpData = initial_context_setup_rsp_pdu(?EXP_ADDR_BIN, TEID), application:set_env(osmo_s1gw, s1gw_bind_addr, ?EXP_ADDR_STR), - ?assertEqual(ExpData, s1ap_proxy:handle_pdu(OrigData)). + [?_assertMatch({ExpData, _}, s1ap_proxy:handle_pdu(OrigData, S))]. %% vim:set ts=4 sw=4 et: -- To view, visit https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/37462?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: erlang/osmo-s1gw Gerrit-Branch: master Gerrit-Change-Id: I6ea8479c1a66bca330a7d4030cc7cdf55a76b12c Gerrit-Change-Number: 37462 Gerrit-PatchSet: 6 Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
1 0
0 0
[L] Change in ...osmo-s1gw[master]: sctp_proxy: maintain opaque state for s1ap_proxy
by laforge 09 Aug '24

09 Aug '24
Attention is currently required from: fixeria. laforge has posted comments on this change by fixeria. ( https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/37462?usp=email ) Change subject: sctp_proxy: maintain opaque state for s1ap_proxy ...................................................................... Patch Set 6: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/37462?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: erlang/osmo-s1gw Gerrit-Branch: master Gerrit-Change-Id: I6ea8479c1a66bca330a7d4030cc7cdf55a76b12c Gerrit-Change-Number: 37462 Gerrit-PatchSet: 6 Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Comment-Date: Fri, 09 Aug 2024 17:29:35 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
1 0
0 0
[L] Change in ...osmo-s1gw[master]: erab_fsm: E-RAB FSM implementation
by laforge 09 Aug '24

09 Aug '24
Attention is currently required from: fixeria, osmith, pespin. laforge has posted comments on this change by fixeria. ( https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/37317?usp=email ) Change subject: erab_fsm: E-RAB FSM implementation ...................................................................... Patch Set 12: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/37317?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: erlang/osmo-s1gw Gerrit-Branch: master Gerrit-Change-Id: Ic57e14675339b7cadb0cdd7cbc5d3a56288d7297 Gerrit-Change-Number: 37317 Gerrit-PatchSet: 12 Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-Attention: osmith <osmith(a)sysmocom.de> Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Attention: pespin <pespin(a)sysmocom.de> Gerrit-Comment-Date: Fri, 09 Aug 2024 17:29:28 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
1 0
0 0
[L] Change in ...osmo-s1gw[master]: pfcp_peer: PFCP peer implementation
by laforge 09 Aug '24

09 Aug '24
Attention is currently required from: fixeria, osmith, pespin. laforge has posted comments on this change by fixeria. ( https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/37268?usp=email ) Change subject: pfcp_peer: PFCP peer implementation ...................................................................... Patch Set 11: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/37268?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: erlang/osmo-s1gw Gerrit-Branch: master Gerrit-Change-Id: I7bad0069dca2111006039d12e744a2bd6d2cb86e Gerrit-Change-Number: 37268 Gerrit-PatchSet: 11 Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-Attention: osmith <osmith(a)sysmocom.de> Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Attention: pespin <pespin(a)sysmocom.de> Gerrit-Comment-Date: Fri, 09 Aug 2024 17:29:20 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
1 0
0 0
[L] Change in ...osmo-s1gw[master]: erab_fsm: E-RAB FSM implementation
by laforge 09 Aug '24

09 Aug '24
Attention is currently required from: fixeria, osmith, pespin. laforge has posted comments on this change by fixeria. ( https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/37317?usp=email ) Change subject: erab_fsm: E-RAB FSM implementation ...................................................................... Patch Set 12: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/37317?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: erlang/osmo-s1gw Gerrit-Branch: master Gerrit-Change-Id: Ic57e14675339b7cadb0cdd7cbc5d3a56288d7297 Gerrit-Change-Number: 37317 Gerrit-PatchSet: 12 Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-Attention: osmith <osmith(a)sysmocom.de> Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Attention: pespin <pespin(a)sysmocom.de> Gerrit-Comment-Date: Fri, 09 Aug 2024 17:29:02 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
1 0
0 0
[L] Change in ...osmo-s1gw[master]: pfcp_peer: PFCP peer implementation
by laforge 09 Aug '24

09 Aug '24
Attention is currently required from: fixeria, osmith, pespin. laforge has posted comments on this change by fixeria. ( https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/37268?usp=email ) Change subject: pfcp_peer: PFCP peer implementation ...................................................................... Patch Set 11: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/37268?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: erlang/osmo-s1gw Gerrit-Branch: master Gerrit-Change-Id: I7bad0069dca2111006039d12e744a2bd6d2cb86e Gerrit-Change-Number: 37268 Gerrit-PatchSet: 11 Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-Attention: osmith <osmith(a)sysmocom.de> Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Attention: pespin <pespin(a)sysmocom.de> Gerrit-Comment-Date: Fri, 09 Aug 2024 17:28:40 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
1 0
0 0
[S] Change in ...osmo-s1gw[master]: erab_fsm: include Network Instance IE in PDRs and FARs
by fixeria 09 Aug '24

09 Aug '24
fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/37795?usp=email ) Change subject: erab_fsm: include Network Instance IE in PDRs and FARs ...................................................................... erab_fsm: include Network Instance IE in PDRs and FARs TODO: make the actual values configurable via env params. Change-Id: I4dbe8e0b1d14eed5fdb3f9f3f2543c44fd543d22 --- M src/erab_fsm.erl 1 file changed, 11 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/erlang/osmo-s1gw refs/changes/95/37795/1 diff --git a/src/erab_fsm.erl b/src/erab_fsm.erl index 5635086..57a39e3 100644 --- a/src/erab_fsm.erl +++ b/src/erab_fsm.erl @@ -369,6 +369,10 @@ -spec session_establish_req(erab_state()) -> pfcp_peer:pfcp_session_rsp(). session_establish_req(#erab_state{seid_loc = F_SEID, %% used as F-SEID teid_from_access = TEID_FromAcc}) -> + %% Network Instance IE values for core/access + %% TODO: make those configurable via env variables + NI_Core = << 16#09, "core-side" >>, + NI_Access = << 16#0a, "radio-side" >>, %% Packet Detection Rules OHR = #outer_header_removal{header = 'GTP-U/UDP/IPv4'}, PDRs = [#{pdr_id => {pdr_id, 1}, %% -- for Core -> Access @@ -377,6 +381,7 @@ outer_header_removal => OHR, pdi => #{f_teid => #f_teid{teid = choose, ipv4 = choose}, + network_instance => NI_Core, source_interface => {source_interface, 'Core'}}}, #{pdr_id => {pdr_id, 2}, %% -- for Access -> Core far_id => {far_id, 2}, %% see FARs below @@ -384,6 +389,7 @@ outer_header_removal => OHR, pdi => #{f_teid => #f_teid{teid = choose, ipv4 = choose}, + network_instance => NI_Access, source_interface => {source_interface, 'Access'}}}], %% Forwarding Action Rules OHC = #outer_header_creation{n6 = false, @@ -399,6 +405,7 @@ apply_action => #{'FORW' => []}, forwarding_parameters => #{outer_header_creation => OHC, + network_instance => NI_Access, destination_interface => {destination_interface, 'Core'}}}], pfcp_peer:session_establish_req(F_SEID, PDRs, FARs). @@ -406,6 +413,9 @@ -spec session_modify_req(erab_state()) -> pfcp_peer:pfcp_session_rsp(). session_modify_req(#erab_state{seid_rem = SEID, %% SEID allocated to us teid_from_core = TEID_FromCore}) -> + %% Network Instance IE value for access + %% TODO: make those configurable via env variables + NI_Access = << 16#0a, "radio-side" >>, %% Forwarding Action Rules OHC = #outer_header_creation{n6 = false, n19 = false, @@ -418,6 +428,7 @@ apply_action => #{'FORW' => []}, forwarding_parameters => #{outer_header_creation => OHC, + network_instance => NI_Access, destination_interface => {destination_interface, 'Access'}}}], pfcp_peer:session_modify_req(SEID, [], FARs). -- To view, visit https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/37795?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: I4dbe8e0b1d14eed5fdb3f9f3f2543c44fd543d22 Gerrit-Change-Number: 37795 Gerrit-PatchSet: 1 Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
1 0
0 0
[S] Change in libosmocore[master]: gb: add bssgp_parse_cell_id2/bssgp_create_cell_id2
by lynxis lazus 09 Aug '24

09 Aug '24
lynxis lazus has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/37794?usp=email ) Change subject: gb: add bssgp_parse_cell_id2/bssgp_create_cell_id2 ...................................................................... gb: add bssgp_parse_cell_id2/bssgp_create_cell_id2 Add bssgp_cell_id functions which use the new struct osmo_routing_area_id. Related: OS#6536 Change-Id: I6cdae75a32547968add2421a07d287a0a42bdbc0 --- M TODO-RELEASE M include/osmocom/gprs/gprs_bssgp.h M src/gb/gprs_bssgp.c 3 files changed, 37 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/94/37794/1 diff --git a/TODO-RELEASE b/TODO-RELEASE index 0ed7189..904d9e0 100644 --- a/TODO-RELEASE +++ b/TODO-RELEASE @@ -7,3 +7,4 @@ # If any interfaces have been added since the last public release: c:r:a + 1. # If any interfaces have been removed or changed since the last public release: c:r:0. #library what description / commit summary line +gb ADD add bssgp_parse_cell_id2/bssgp_create_cell_id2 diff --git a/include/osmocom/gprs/gprs_bssgp.h b/include/osmocom/gprs/gprs_bssgp.h index 6c04332..391f8c6 100644 --- a/include/osmocom/gprs/gprs_bssgp.h +++ b/include/osmocom/gprs/gprs_bssgp.h @@ -182,6 +182,12 @@ int bssgp_create_cell_id(uint8_t *buf, const struct gprs_ra_id *raid, uint16_t cid); +uint16_t bssgp_parse_cell_id2(struct osmo_routing_area_id *raid, uint16_t *cid, + const uint8_t *buf, size_t buf_len); +int bssgp_create_cell_id2(uint8_t *buf, size_t buf_len, + const struct osmo_routing_area_id *raid, + uint16_t cid); + /* Wrapper around TLV parser to parse BSSGP IEs */ static inline int bssgp_tlv_parse(struct tlv_parsed *tp, const uint8_t *buf, int len) { diff --git a/src/gb/gprs_bssgp.c b/src/gb/gprs_bssgp.c index 7abef80..e11299d 100644 --- a/src/gb/gprs_bssgp.c +++ b/src/gb/gprs_bssgp.c @@ -354,6 +354,20 @@ return osmo_load16be(buf+6); } +int bssgp_parse_cell_id2(struct osmo_routing_area_id *raid, uint16_t *cellid, + const uint8_t *buf, size_t buf_len) +{ + if (buf_len < 8) + return -EINVAL; + + /* 6 octets RAC */ + osmo_routing_area_id_decode(raid, buf, buf_len); + /* 2 octets CID */ + *cellid = osmo_load16be(buf+6); + + return 0; +} + int bssgp_create_cell_id(uint8_t *buf, const struct gprs_ra_id *raid, uint16_t cid) { @@ -365,6 +379,22 @@ return 8; } +int bssgp_create_cell_id2(uint8_t *buf, size_t buf_len, + const struct osmo_routing_area_id *raid, + uint16_t cid) +{ + if (buf_len < 8) + return -ENOMEM; + + /* 6 octets RAC */ + osmo_routing_area_id_encode_buf(buf, buf_len, raid); + + /* 2 octets CID */ + osmo_store16be(cid, buf+6); + + return 8; +} + /* Chapter 8.4 BVC-Reset Procedure */ static int bssgp_rx_bvc_reset(struct msgb *msg, struct tlv_parsed *tp, uint16_t ns_bvci) -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/37794?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I6cdae75a32547968add2421a07d287a0a42bdbc0 Gerrit-Change-Number: 37794 Gerrit-PatchSet: 1 Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu>
1 0
0 0
[L] Change in ...osmo-s1gw[master]: pfcp_peer: PFCP peer implementation
by fixeria 09 Aug '24

09 Aug '24
Attention is currently required from: laforge, osmith, pespin. Hello Jenkins Builder, laforge, osmith, pespin, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/37268?usp=email to look at the new patch set (#11). The following approvals got outdated and were removed: Code-Review+1 by laforge, Code-Review+1 by osmith, Verified+1 by Jenkins Builder Change subject: pfcp_peer: PFCP peer implementation ...................................................................... pfcp_peer: PFCP peer implementation Change-Id: I7bad0069dca2111006039d12e744a2bd6d2cb86e --- M config/sys.config M src/osmo_s1gw.app.src M src/osmo_s1gw_sup.erl A src/pfcp_peer.erl 4 files changed, 416 insertions(+), 3 deletions(-) git pull ssh://gerrit.osmocom.org:29418/erlang/osmo-s1gw refs/changes/68/37268/11 -- To view, visit https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/37268?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newpatchset Gerrit-Project: erlang/osmo-s1gw Gerrit-Branch: master Gerrit-Change-Id: I7bad0069dca2111006039d12e744a2bd6d2cb86e Gerrit-Change-Number: 37268 Gerrit-PatchSet: 11 Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-Attention: osmith <osmith(a)sysmocom.de> Gerrit-Attention: laforge <laforge(a)osmocom.org> Gerrit-Attention: pespin <pespin(a)sysmocom.de>
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • ...
  • 148
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.