fixeria has submitted this change. ( https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/40368?usp=email )
(
1 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one. )Change subject: s1ap_proxy: parse and store Global-ENB-ID IE ......................................................................
s1ap_proxy: parse and store Global-ENB-ID IE
This commit prepares for a follow-up change implementing the NFT-based KPI (GTP-U packets/bytes stats) reporting, which will need the Global-ENB-ID.
Change-Id: Icc24d4daf06d161d7b5b386456e8e92ac07d5eba Related: SYS#7307 --- M src/s1ap_proxy.erl 1 file changed, 56 insertions(+), 0 deletions(-)
Approvals: pespin: Looks good to me, but someone else must approve laforge: Looks good to me, approved Jenkins Builder: Verified
diff --git a/src/s1ap_proxy.erl b/src/s1ap_proxy.erl index 774fc66..bf5f849 100644 --- a/src/s1ap_proxy.erl +++ b/src/s1ap_proxy.erl @@ -67,8 +67,12 @@ -type enb_ue_id() :: 0..16#ffffff. -type erab_id() :: 0..16#ff. -type erab_uid() :: {mme_ue_id(), enb_ue_id(), erab_id()}. +-type plmn_id() :: {MCC :: nonempty_string(), + MNC :: nonempty_string()}.
-record(proxy_state, {erabs :: dict:dict(), + enb_id :: undefined | non_neg_integer(), + plmn_id :: undefined | plmn_id(), mme_ue_id :: undefined | mme_ue_id(), enb_ue_id :: undefined | enb_ue_id(), erab_id :: undefined | erab_id(), @@ -195,6 +199,35 @@ ok.
+%% Parse PLMN-ID as per 3GPP TS 24.008, Figure 10.5.13 +%% | MCC digit 2 | MCC digit 1 | octet 1 +%% | MNC digit 3 | MCC digit 3 | octet 2 +%% | MNC digit 2 | MNC digit 1 | octet 3 +-spec parse_plmn_id(<< _:24 >>) -> plmn_id(). +parse_plmn_id(<< MCC2:4, MCC1:4, + MNC3:4, MCC3:4, + MNC2:4, MNC1:4 >>) -> + MCC = parse_mcc_mnc(MCC1, MCC2, MCC3), + MNC = parse_mcc_mnc(MNC1, MNC2, MNC3), + {MCC, MNC}. + + +-define(UNHEX(H), H + 48). + +parse_mcc_mnc(D1, D2, 16#f) -> + [?UNHEX(D1), ?UNHEX(D2)]; + +parse_mcc_mnc(D1, D2, D3) -> + [?UNHEX(D1), ?UNHEX(D2), ?UNHEX(D3)]. + + +-spec parse_enb_id(tuple()) -> non_neg_integer(). +parse_enb_id({'macroENB-ID', << ID:20 >>}) -> ID; +parse_enb_id({'homeENB-ID', << ID:28 >>}) -> ID; +parse_enb_id({'short-macroENB-ID', << ID:18 >>}) -> ID; +parse_enb_id({'long-macroENB-ID', << ID:21 >>}) -> ID. + + %% Encode an S1AP PDU -spec encode_pdu(s1ap_pdu()) -> {ok, binary()} | {error, {asn1, tuple()}}. @@ -260,6 +293,17 @@ -spec handle_pdu(s1ap_pdu(), proxy_state()) -> {{proxy_action(), s1ap_pdu()}, proxy_state()} | {forward, proxy_state()}.
+%% 9.1.8.4 S1 SETUP REQUEST +handle_pdu({initiatingMessage, + #'InitiatingMessage'{procedureCode = ?'id-S1Setup', + value = C0}}, S0) -> + ?LOG_DEBUG("Processing S1 SETUP REQUEST"), + %% there's nothing to patch in this PDU, so we forward it as-is + %% TODO: check result of handle_ies(), inc. ?S1GW_CTR_S1AP_PROXY_IN_PKT_PROC_ERROR + {_, S1} = handle_ies(?'id-Global-ENB-ID', + C0#'S1SetupRequest'.protocolIEs, S0), + {forward, S1}; + %% 9.1.3.1 E-RAB SETUP REQUEST handle_pdu({Outcome = initiatingMessage, #'InitiatingMessage'{procedureCode = ?'id-E-RABSetup', @@ -538,6 +582,18 @@ Result :: {handle_ie_result(), proxy_state()}.
+handle_ie([?'id-Global-ENB-ID'], + #'Global-ENB-ID'{'pLMNidentity' = PLMNId, + 'eNB-ID' = ENBId} = C, S0) -> + %% store PLMNId/ENBId + %% TODO: use that as a context for logging + S1 = S0#proxy_state{plmn_id = parse_plmn_id(PLMNId), + enb_id = parse_enb_id(ENBId)}, + ?LOG_INFO("Global-ENB-ID: PLMN-ID=~p, eNB-ID=~p", + [S1#proxy_state.plmn_id, + S1#proxy_state.enb_id]), + {{ok, C}, S1}; + %% E-RAB SETUP REQUEST related IEs handle_ie([?'id-E-RABToBeSetupListBearerSUReq'], C, S) -> %% This IE contains a list of BearerSUReq, so patch inner IEs