fixeria has uploaded this change for review. (
https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/41613?usp=email )
Change subject: sctp_proxy: add _from_{enb,mme} variants of sctp_send/2
......................................................................
sctp_proxy: add _from_{enb,mme} variants of sctp_send/2
The existing sctp_send/2 is sending data from an eNB towards
the MME. Sending data in the opposite direction is done in-place.
For the sake of readability, let's add the counterpart of sctp_send/2
and clarify the direction by adding _from_{enb,mme} to function names.
Change-Id: I388137e27ea5000f22e7a5b58d1ffcfd9caa1475
---
M src/sctp_proxy.erl
1 file changed, 35 insertions(+), 23 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/erlang/osmo-s1gw
refs/changes/13/41613/1
diff --git a/src/sctp_proxy.erl b/src/sctp_proxy.erl
index 3aa67d8..ad58d4b 100644
--- a/src/sctp_proxy.erl
+++ b/src/sctp_proxy.erl
@@ -165,7 +165,7 @@
%% Handle an eNB -> MME data forwarding request (forward)
connected(cast, {send_data, Data}, S0) ->
- sctp_send(Data, S0),
+ sctp_send_from_enb(Data, S0),
{keep_state, S0};
%% Handle an #sctp_assoc_change event (MME connection state)
@@ -184,26 +184,16 @@
%% Handle an #sctp_sndrcvinfo event (MME -> eNB data)
connected(info, {sctp, _Socket, MmeAddr, MmePort,
- {[#sctp_sndrcvinfo{assoc_id = Aid,
+ {[#sctp_sndrcvinfo{assoc_id = MmeAid,
stream = SID,
ssn = SSN,
tsn = TSN}], Data}},
- #{sock := Sock,
- enb_aid := EnbAid,
- mme_aid := Aid,
- handler := Pid} = S) ->
+ #{mme_aid := MmeAid} = S) ->
?LOG_DEBUG("MME connection (id=~p, ~p:~p) -> eNB: ~p",
- [Aid, MmeAddr, MmePort,
+ [MmeAid, MmeAddr, MmePort,
#{tsn => TSN, sid => SID, ssn => SSN,
len => byte_size(Data), data => Data}]),
- case s1ap_proxy:process_pdu(Pid, Data) of
- {forward, FwdData} ->
- sctp_server:send_data(EnbAid, FwdData);
- {reply, ReData} ->
- ok = sctp_common:send_data({Sock, Aid}, ReData);
- {drop, Data} ->
- ok %% no-op
- end,
+ sctp_send_from_mme(Data, S),
{keep_state, S};
connected(Event, EventData, S) ->
@@ -261,15 +251,20 @@
%% private API
%% ------------------------------------------------------------------
-%% Send a single message to the MME
-sctp_send(Data,
- #{sock := Sock,
- enb_aid := EnbAid,
- mme_aid := Aid,
- handler := Pid}) ->
+%% XXX: proper type
+-type state() :: map().
+
+
+%% Send a single message: eNB -> MME
+-spec sctp_send_from_enb(binary(), state()) -> ok | {error, term()}.
+sctp_send_from_enb(Data,
+ #{sock := Sock,
+ enb_aid := EnbAid,
+ mme_aid := MmeAid,
+ handler := Pid}) ->
case s1ap_proxy:process_pdu(Pid, Data) of
{forward, FwdData} ->
- ok = sctp_common:send_data({Sock, Aid}, FwdData);
+ sctp_common:send_data({Sock, MmeAid}, FwdData);
{reply, ReData} ->
sctp_server:send_data(EnbAid, ReData);
{drop, Data} ->
@@ -277,12 +272,29 @@
end.
+%% Send a single message: eNB <- MME
+-spec sctp_send_from_mme(binary(), state()) -> ok | {error, term()}.
+sctp_send_from_mme(Data,
+ #{sock := Sock,
+ enb_aid := EnbAid,
+ mme_aid := MmeAid,
+ handler := Pid}) ->
+ case s1ap_proxy:process_pdu(Pid, Data) of
+ {forward, FwdData} ->
+ sctp_server:send_data(EnbAid, FwdData);
+ {reply, ReData} ->
+ sctp_common:send_data({Sock, MmeAid}, ReData);
+ {drop, Data} ->
+ ok %% no-op
+ end.
+
+
%% Send pending messages to the MME
sctp_send_pending(#{tx_queue := Pending} = S) ->
sctp_send_pending(lists:reverse(Pending), S).
sctp_send_pending([Data | Pending], S) ->
- sctp_send(Data, S),
+ sctp_send_from_enb(Data, S),
s1gw_metrics:gauge_dec(?S1GW_GAUGE_S1AP_PROXY_UPLINK_PACKETS_QUEUED),
sctp_send_pending(Pending, S);
--
To view, visit https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/41613?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: I388137e27ea5000f22e7a5b58d1ffcfd9caa1475
Gerrit-Change-Number: 41613
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <[email protected]>