fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/42430?usp=email )
Change subject: [REST] Implement PfcpAssoc{Setup,Release} ......................................................................
[REST] Implement PfcpAssoc{Setup,Release}
Change-Id: I2e24544563e4c4d23bb3d8a4a7b5434191b482d8 Related: SYS#7066 --- M contrib/osmo-s1gw-cli.py M doc/manuals/chapters/cli.adoc M src/pfcp_peer.erl M src/rest_server.erl 4 files changed, 65 insertions(+), 4 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/erlang/osmo-s1gw refs/changes/30/42430/1
diff --git a/contrib/osmo-s1gw-cli.py b/contrib/osmo-s1gw-cli.py index 50b545d..5d60e16 100755 --- a/contrib/osmo-s1gw-cli.py +++ b/contrib/osmo-s1gw-cli.py @@ -250,12 +250,16 @@ @cmd2.with_category(CAT_PFCP) def do_pfcp_assoc_setup(self, opts) -> None: ''' Initiate the PFCP Association Setup procedure ''' - raise NotImplementedError + data = self.iface.pfcp_assoc_setup() + if not data['success']: + self.perror('PFCP Association Setup request failed: {message}'.format(**data))
@cmd2.with_category(CAT_PFCP) def do_pfcp_assoc_release(self, opts) -> None: ''' Initiate the PFCP Association Release procedure ''' - raise NotImplementedError + data = self.iface.pfcp_assoc_release() + if not data['success']: + self.perror('PFCP Association Release request failed: {message}'.format(**data))
@cmd2.with_category(CAT_PFCP) def do_pfcp_heartbeat(self, opts) -> None: diff --git a/doc/manuals/chapters/cli.adoc b/doc/manuals/chapters/cli.adoc index 1b677f5..52fe54b 100644 --- a/doc/manuals/chapters/cli.adoc +++ b/doc/manuals/chapters/cli.adoc @@ -150,6 +150,14 @@ | Remote Recovery TimeStamp | 3965211123 | ----
+==== `pfcp_assoc_setup` + +Initiate the PFCP Association Setup procedure. + +==== `pfcp_assoc_release` + +Initiate the PFCP Association Release procedure. + ==== `pfcp_heartbeat`
Send a PFCP Heartbeat Request to the UPF and display the result. diff --git a/src/pfcp_peer.erl b/src/pfcp_peer.erl index 6308f50..aee679a 100644 --- a/src/pfcp_peer.erl +++ b/src/pfcp_peer.erl @@ -42,6 +42,8 @@ code_change/4, terminate/3]). -export([start_link/2, + assoc_setup/0, + assoc_release/0, seid_alloc/0, heartbeat_req/0, heartbeat_req/1, @@ -115,6 +117,18 @@ []).
+%% Initiate the PFCP Association Setup procedure +-spec assoc_setup() -> ok | {error, term()}. +assoc_setup() -> + gen_statem:call(?MODULE, ?FUNCTION_NAME). + + +%% Initiate the PFCP Association Release procedure +-spec assoc_release() -> ok | {error, term()}. +assoc_release() -> + gen_statem:call(?MODULE, ?FUNCTION_NAME). + + %% Request to allocate a unique SEID -spec seid_alloc() -> {ok, pfcp_seid()} | {error, term()}. @@ -240,6 +254,13 @@ {keep_state, S0} end;
+connecting({call, From}, assoc_setup, S) -> + %% Force retransmission of the PFCP Association Setup Request + {repeat_state, S, [{reply, From, ok}]}; + +connecting({call, From}, assoc_release, _S) -> + {keep_state_and_data, [{reply, From, {error, not_connected}}]}; + connecting(Event, EventData, S) -> handle_event(?FUNCTION_NAME, Event, EventData, S).
@@ -288,6 +309,14 @@ {keep_state, S0} end;
+connected({call, From}, assoc_setup, _S) -> + {keep_state_and_data, [{reply, From, {error, already_connected}}]}; + +connected({call, From}, assoc_release, S) -> + send_assoc_release(S), + {next_state, connecting, S#peer_state{rem_rts = undefined}, + [{reply, From, ok}]}; + %% Catch-all handler for this state connected(Event, EventData, S) -> handle_event(?FUNCTION_NAME, Event, EventData, S). diff --git a/src/rest_server.erl b/src/rest_server.erl index f6eee94..b326852 100644 --- a/src/rest_server.erl +++ b/src/rest_server.erl @@ -37,6 +37,8 @@ -export([config_read/1, metrics_list/1, pfcp_assoc_state/1, + pfcp_assoc_setup/1, + pfcp_assoc_release/1, pfcp_heartbeat/1, mme_list/1, mme_add/1, @@ -97,8 +99,26 @@ Info2 = maps:update_with(raddr, fun inet:ntoa/1, Info1), {200, [], rsp_map(Info2)}.
-%% TODO: PfcpAssocSetup :: Initiate the PFCP Association Setup procedure -%% TODO: PfcpAssocRelease :: Initiate the PFCP Association Release procedure +%% PfcpAssocSetup :: Initiate the PFCP Association Setup procedure +pfcp_assoc_setup(#{}) -> + case pfcp_peer:assoc_setup() of + ok -> + {200, [], rsp_map(#{success => true})}; + {error, Error} -> + {200, [], rsp_map(#{success => false, + message => Error})} + end. + + +%% PfcpAssocRelease :: Initiate the PFCP Association Release procedure +pfcp_assoc_release(#{}) -> + case pfcp_peer:assoc_release() of + ok -> + {200, [], rsp_map(#{success => true})}; + {error, Error} -> + {200, [], rsp_map(#{success => false, + message => Error})} + end.
%% PfcpHeartbeat :: Send a PFCP Heartbeat Request to the peer