pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/43675?usp=email )
Change subject: HTTP2_Adapter: Use HTTP2_Msg in user APIs ......................................................................
HTTP2_Adapter: Use HTTP2_Msg in user APIs
This allows simplifying usual user logic where only wanted thing is to send a Header+optData (request) and receive back a Header+optData (Response).
Change-Id: I79d74939d8280dfff5ee61c59072466916300017 --- M library/HTTP2_Adapter.ttcn M smf/SMF_Session_CT_5G.ttcn 2 files changed, 101 insertions(+), 62 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks refs/changes/75/43675/1
diff --git a/library/HTTP2_Adapter.ttcn b/library/HTTP2_Adapter.ttcn index 8616ea4..25f9d6f 100644 --- a/library/HTTP2_Adapter.ttcn +++ b/library/HTTP2_Adapter.ttcn @@ -20,6 +20,8 @@ import from Socket_API_Definitions all;
import from HTTP2_Templates all; +import from HTTP2_Functions all; +import from HTTP2_Msg all;
import from Native_Functions all; import from Misc_Helpers all; @@ -120,10 +122,10 @@ ts_HTTP2_Setting_INITIAL_WINDOW_SIZE(4194304), ts_HTTP2_Setting_MAX_HEADER_LIST_SIZE(10485760) } - f_http2_adapter_send(ts_HTTP2_Frame_Settings(settings := settings), idx := idx); - as_http2_adapter_receive(rx_http_frame, tr_HTTP2_Frame_Settings(ack_flag := false), idx := idx); - as_http2_adapter_receive(rx_http_frame, tr_HTTP2_Frame_Settings(ack_flag := true), idx := idx); - f_http2_adapter_send(ts_HTTP2_Frame_Window_Update(0, 1073741824), idx := idx); + f_http2_adapter_send_frame(ts_HTTP2_Frame_Settings(settings := settings), idx := idx); + as_http2_adapter_receive_frame(rx_http_frame, tr_HTTP2_Frame_Settings(ack_flag := false), idx := idx); + as_http2_adapter_receive_frame(rx_http_frame, tr_HTTP2_Frame_Settings(ack_flag := true), idx := idx); + f_http2_adapter_send_frame(ts_HTTP2_Frame_Window_Update(0, 1073741824), idx := idx); }
function f_http2_adapter_close(integer idx := 0) @@ -133,21 +135,79 @@ g_self_conn_id[idx] := -1; }
-function f_http2_adapter_send(template (value) HTTP2_Frame http2_frame, - integer idx := 0) +private function f_http2_adapter_send_frame(template (value) HTTP2_Frame http2_frame, + integer idx := 0) runs on HTTP2_CT { HTTP2[idx].send(ts_HTTP2_Send(g_self_conn_id[idx], http2_frame)); }
-altstep as_http2_adapter_receive(out HTTP2_Frame rx_http_frame, - template (present) HTTP2_Frame exp_http2_frame := ?, - integer idx := 0) +function f_http2_adapter_send(template (value) HTTP2_Msg http2_msg) +runs on HTTP2_CT +{ + var HTTP2_Msg msg := valueof(http2_msg); + var template (value) HTTP2_Frame http2_frame; + var integer last_stream_id := msg.stream_id; + var octetstring hdr_enc; + var integer idx := msg.conn_id; + + /* Send Header: */ + f_HTTP2_Msg_append_hdr_content_length(msg); + hdr_enc := f_HTTP2_header_block_encode(msg.hb); + http2_frame := ts_HTTP2_Frame_Header(msg.stream_id, + end_stream_flag := not ispresent(msg.body), + end_header_flag := true, + header_block_fragment := hdr_enc); + f_http2_adapter_send_frame(http2_frame, idx := idx); + + /* Send body: */ + if (ispresent(msg.body)) { + http2_frame := ts_HTTP2_Frame_Data(msg.body.stream_id, + msg.body.end_stream_flag, + msg.body.data, + msg.body.padding); + f_http2_adapter_send_frame(http2_frame, idx := idx); + } +} + +private altstep as_http2_adapter_receive_frame(out HTTP2_Frame rx_http2_frame, + template (present) HTTP2_Frame exp_http2_frame := ?, + integer idx := 0) runs on HTTP2_CT { var HTTP2_Recv http2_rx; [] HTTP2[idx].receive(tr_HTTP2_Recv(g_self_conn_id[idx], exp_http2_frame, omit)) -> value http2_rx { - rx_http_frame := http2_rx.frame; + rx_http2_frame := http2_rx.frame; + } +} + +altstep as_http2_adapter_receive(out HTTP2_Msg http2_rx_msg, + template (present) HTTP2_Msg http2_exp_msg := ?, + integer idx := 0) +runs on HTTP2_CT +{ + var HTTP2_Frame rx_http2_frame; + [] as_http2_adapter_receive_frame(rx_http2_frame, + tr_HTTP2_Frame_Header(stream_id := http2_exp_msg.stream_id, + header_block_fragment := ?), + idx := idx) { + var template (omit) HTTP2_Data_frame body := omit; + var HTTP2_header_block hb; + + hb := f_HTTP2_header_block_decode(rx_http2_frame.header_frame.header_block_fragment); + if (not rx_http2_frame.header_frame.end_stream_flag) { /* Expect body */ + var HTTP2_Frame body_frame; + as_http2_adapter_receive_frame(body_frame, HTTP2_Frame:{ data_frame := http2_exp_msg.body }); + body := body_frame.data_frame; + } else if (not istemplatekind(http2_exp_msg.body, "*") and + not istemplatekind(http2_exp_msg.body, "omit")) { + Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, + log2str(idx, ": Expecting body but header came with end_stream_flag = true!")); + } + http2_rx_msg := valueof(ts_HTTP2_Msg(idx, + rx_http2_frame.header_frame.stream_id, + hb, + body)); } }
diff --git a/smf/SMF_Session_CT_5G.ttcn b/smf/SMF_Session_CT_5G.ttcn index c5000bc..1551489 100644 --- a/smf/SMF_Session_CT_5G.ttcn +++ b/smf/SMF_Session_CT_5G.ttcn @@ -8,6 +8,7 @@ import from HTTP2_Types all; import from HTTP2_Templates all; import from HTTP2_Functions all; +import from HTTP2_Msg all; import from HTTP2_Adapter all; import from HTTP2_Server_Emulation all;
@@ -90,21 +91,17 @@ * 3GPP TS 29.502 6.1.3.2 */ function f_n11_create_session() runs on SMF_Session_CT { - var octetstring hdr_enc; - var template (value) HTTP2_pseudo_headers pseudo_hdr; - var template (value) HTTP2_header_list hdr_li; - var template (value) HTTP2_header_block tx_hb; - var template (present) HTTP2_header_block exp_rx_hb; - var HTTP2_header_block rx_hb; var template (value) NG_NAS_UL_Message_Type nas_ul_msg; var ProcedureTransactionIdentifier pti := f_next_pti(); var template (value) octetstring body; - var HTTP2_Frame rx_http_frame; var template (value) TS29502_Nsmf_PDUSession.PlmnId plmn_id := TS29502_Nsmf_PDUSession_Templates.ts_PlmnId("001", "001"); var template (value) TS29502_Nsmf_PDUSession.PlmnIdNid plmn_id_nid := TS29502_Nsmf_PDUSession_Templates.ts_PlmnIdNid(plmn_id.mcc, plmn_id.mnc); var integer pdu_sess_id := 1; var integer http2_idx; var integer http2_stream_id := 3; + var template (value) HTTP2_Msg http2_tx; + var HTTP2_Msg http2_rx; + var template (present) HTTP2_Msg http2_exp_rx;
var template (value) SmContextCreateData sm_contexts; var octetstring sm_contexts_enc; @@ -134,30 +131,26 @@ var octetstring nas_enc := enc_NG_NAS_UL_Message_Type(valueof(nas_ul_msg));
body := f_http2_encode_body_multipart_json_5gnas(sm_contexts_enc, nas_enc, boundary); - - pseudo_hdr := ts_HTTP2_pseudo_headers_Req(method := "POST", - scheme := "http", - authority := Nsmf_uri_hostport, - path := Nsmf_PDUSession_path_sm_contexts); - hdr_li := { - ts_HTTP2_Hdr_content_type("multipart/related; boundary="" & boundary & """), - ts_HTTP2_Hdr_accept("application/json,application/vnd.3gpp.ngap,application/problem+json"), - ts_HTTP2_Hdr_user_agent("ttcn3-amf"), - ts_HTTP2_Hdr_content_length(int2str(lengthof(body))), - ts_HTTP2_Hdr_accept_encoding("gzip") - }; - tx_hb := ts_HTTP2_header_block(pseudo_hdr, hdr_li); - hdr_enc := f_HTTP2_header_block_encode(valueof(tx_hb)); - http2_idx := f_http2_adapter_find_free_idx(); - f_http2_adapter_connect(mp_smf_hostname, mp_smf_sbi_port, mp_amf_local_ip, -1, idx := http2_idx); - f_http2_adapter_send(ts_HTTP2_Frame_Header(http2_stream_id, - end_stream_flag := false, - end_header_flag := true, - header_block_fragment := hdr_enc - ), - idx := http2_idx); + http2_tx := ts_HTTP2_Msg(http2_idx, + http2_stream_id, + hb := { + pseudo_headers := ts_HTTP2_pseudo_headers_Req(method := "POST", + scheme := "http", + authority := Nsmf_uri_hostport, + path := Nsmf_PDUSession_path_sm_contexts), + headers := { + ts_HTTP2_Hdr_content_type("multipart/related; boundary="" & boundary & """), + ts_HTTP2_Hdr_accept("application/json,application/vnd.3gpp.ngap,application/problem+json"), + ts_HTTP2_Hdr_user_agent("ttcn3-amf"), + ts_HTTP2_Hdr_accept_encoding("gzip") + } + }, + body := ts_HTTP2_Data_frame(http2_stream_id, + end_stream_flag := true, + data := body));
+ f_http2_adapter_connect(mp_smf_hostname, mp_smf_sbi_port, mp_amf_local_ip, -1, idx := http2_idx);
/////////// START MUTUAL EXCLUSION ZONE //////////// /* This code block cannot be executed by more than one component at a time because @@ -172,10 +165,7 @@ * expected to have SEID set to 0, as per 3GPP TS 29.244, section 7.2.2.4.2. */ f_PFCPEM_subscribe_seid(c_SEID0);
- f_http2_adapter_send(ts_HTTP2_Frame_Data(3, - end_stream_flag := true, - data := body), - idx := http2_idx); + f_http2_adapter_send(http2_tx);
/* Expect UDM to receive GET sm-data: */ as_nudm_sdm_get_sm_data(); @@ -183,25 +173,14 @@ as_nudm_sdm_post_sdm_subscriptions();
/* Expect to receive "201 Created body={}" answer to our Nsmf sm-contexts request: */ - as_http2_adapter_receive(rx_http_frame, - tr_HTTP2_Frame_Header(stream_id := http2_stream_id, - end_stream_flag := false, - end_header_flag := true, - header_block_fragment := ?), - idx := http2_idx); - rx_hb := f_HTTP2_header_block_decode(rx_http_frame.header_frame.header_block_fragment); - exp_rx_hb := tr_HTTP2_header_block(pseudo_headers := tr_HTTP2_pseudo_headers_Resp(201), - headers := {*, tr_HTTP2_Hdr_location(tr_Nsmf_PDUSession_uri_sm_contexts), *}); - if (not match(rx_hb, exp_rx_hb)) { - Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, - log2str("Rx unexpected HTTP2 response hdr: ", rx_hb, " vs exp ", exp_rx_hb)); - - } - as_http2_adapter_receive(rx_http_frame, - tr_HTTP2_Frame_Data(stream_id := http2_stream_id, - end_stream_flag := true, - data := char2oct("{}")), - idx := http2_idx); + http2_exp_rx := tr_HTTP2_Msg(http2_idx, + http2_stream_id, + tr_HTTP2_header_block(pseudo_headers := tr_HTTP2_pseudo_headers_Resp(201), + headers := {*, tr_HTTP2_Hdr_location(tr_Nsmf_PDUSession_uri_sm_contexts), *}), + tr_HTTP2_Data_frame(stream_id := http2_stream_id, + end_stream_flag := true, + data := char2oct("{}"))); + as_http2_adapter_receive(http2_rx, http2_exp_rx, idx := http2_idx); f_http2_adapter_close(idx := http2_idx);
/* Expect PCF to receive POST sm-policies: */