pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/43673?usp=email )
Change subject: HTTP2_Adapter: Support multiple concurrent open client connections ......................................................................
HTTP2_Adapter: Support multiple concurrent open client connections
Change-Id: I194ba7d5ad72363a0e398847360e985e7f7ec6cb --- M library/HTTP2_Adapter.ttcn M smf/SMF_Session_CT_5G.ttcn 2 files changed, 63 insertions(+), 35 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks refs/changes/73/43673/1
diff --git a/library/HTTP2_Adapter.ttcn b/library/HTTP2_Adapter.ttcn index 787dff0..8616ea4 100644 --- a/library/HTTP2_Adapter.ttcn +++ b/library/HTTP2_Adapter.ttcn @@ -24,16 +24,19 @@ import from Native_Functions all; import from Misc_Helpers all;
+const integer HTTP2_MAX_NUM_CLIENTS := 4; + type component HTTP2_CT { - port HTTP2_CODEC_PT HTTP2; + port HTTP2_CODEC_PT HTTP2[HTTP2_MAX_NUM_CLIENTS]; /* double underscore to have "g_pars" available on components extending this one: */ - var template (omit) HTTP2_Adapter_Params g_http2_pars; + var HTTP2_Adapter_Params g_http2_pars[HTTP2_MAX_NUM_CLIENTS];
/* Connection identifier of the client / server itself */ - var IPL4asp_Types.ConnectionId g_self_conn_id := -1; + var IPL4asp_Types.ConnectionId g_self_conn_id[HTTP2_MAX_NUM_CLIENTS]; };
type record HTTP2_Adapter_Params { + integer idx, charstring local_host, integer local_port, charstring remote_host, @@ -42,11 +45,13 @@ };
template (value) HTTP2_Adapter_Params -ts_HTTP2_Adapter_Params(template (value) charstring local_host, +ts_HTTP2_Adapter_Params(template (value) integer idx, + template (value) charstring local_host, template (value) integer local_port, template (value) charstring remote_host, template (value) integer remote_port, template (value) boolean use_ssl) := { + idx := idx, local_host := local_host, local_port := local_port, remote_host := remote_host, @@ -55,7 +60,10 @@ }
function f_http2_adapter_init() runs on HTTP2_CT { - map(self:HTTP2, system:HTTP2_CODEC_PT); + for(var integer i := 0; i < HTTP2_MAX_NUM_CLIENTS; i := i + 1) { + map(self:HTTP2[i], system:HTTP2_CODEC_PT); + g_self_conn_id[i] := -1; + } }
private function f_http2_adapter_getMsgLen(in octetstring pl_stream, @@ -66,34 +74,45 @@ }
-private function f_set_tcp_segmentation() +private function f_set_tcp_segmentation(integer idx := 0) runs on HTTP2_CT { /* Set function for dissecting the binary stream into packets */ var f_IPL4_getMsgLen vl_f := refers(f_http2_adapter_getMsgLen); - HTTP2_CodecPort_CtrlFunct.f_IPL4_setGetMsgLen(HTTP2, g_self_conn_id, vl_f, {}); + HTTP2_CodecPort_CtrlFunct.f_IPL4_setGetMsgLen(HTTP2[idx], g_self_conn_id[idx], vl_f, {}); +} + +/* Obtain index of free slot which can be then used to connect, etc., negative on error. */ +function f_http2_adapter_find_free_idx() +runs on HTTP2_CT return integer { + for(var integer i := 0; i < HTTP2_MAX_NUM_CLIENTS; i := i + 1) { + if (g_self_conn_id[i] == -1) { + return i; + } + } + return -1; }
/* Function to use to connect as client to a remote IPA Server */ function f_http2_adapter_connect(charstring remote_host, IPL4asp_Types.PortNumber remote_port, - charstring local_host, IPL4asp_Types.PortNumber local_port, boolean use_ssl := false) + charstring local_host, IPL4asp_Types.PortNumber local_port, boolean use_ssl := false, integer idx := 0) runs on HTTP2_CT { var IPL4asp_Types.Result res; - res := HTTP2_CodecPort_CtrlFunct.f_IPL4_connect(HTTP2, remote_host, remote_port, + res := HTTP2_CodecPort_CtrlFunct.f_IPL4_connect(HTTP2[idx], remote_host, remote_port, local_host, local_port, 0, { tcp:={} }); if (not ispresent(res.connId)) { - setverdict(fail, "Could not connect HTTP2 socket from ", local_host, " port ", local_port, - " to ", remote_host, " port ", remote_port, "; check your configuration"); - mtc.stop; + Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, + log2str(idx, ": Could not connect HTTP2 socket from ", local_host, " port ", local_port, + " to ", remote_host, " port ", remote_port, "; check your configuration")); } - g_self_conn_id := res.connId; - g_http2_pars := ts_HTTP2_Adapter_Params(remote_host, remote_port, local_host, local_port, use_ssl); + g_self_conn_id[idx] := res.connId; + g_http2_pars[idx] := valueof(ts_HTTP2_Adapter_Params(idx, remote_host, remote_port, local_host, local_port, use_ssl));
- f_set_tcp_segmentation(); - HTTP2.send(ts_HTTP2_Send_magic(g_self_conn_id)); - f_http2_adapter_initial_handshake(); + f_set_tcp_segmentation(idx := idx); + HTTP2[idx].send(ts_HTTP2_Send_magic(g_self_conn_id[idx])); + f_http2_adapter_initial_handshake(idx := idx); }
-private function f_http2_adapter_initial_handshake() +private function f_http2_adapter_initial_handshake(integer idx := 0) runs on HTTP2_CT { var HTTP2_Frame rx_http_frame; var template (value) HTTP2_Setting_list settings := { @@ -101,31 +120,33 @@ 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)); - as_http2_adapter_receive(rx_http_frame, tr_HTTP2_Frame_Settings(ack_flag := false)); - as_http2_adapter_receive(rx_http_frame, tr_HTTP2_Frame_Settings(ack_flag := true)); - f_http2_adapter_send(ts_HTTP2_Frame_Window_Update(0, 1073741824)); + 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); }
-function f_http2_adapter_close() +function f_http2_adapter_close(integer idx := 0) runs on HTTP2_CT { var IPL4asp_Types.Result res; - res := HTTP2_CodecPort_CtrlFunct.f_IPL4_close(HTTP2, g_self_conn_id, {tcp := {}}); - g_self_conn_id := -1; + res := HTTP2_CodecPort_CtrlFunct.f_IPL4_close(HTTP2[idx], g_self_conn_id[idx], {tcp := {}}); + g_self_conn_id[idx] := -1; }
-function f_http2_adapter_send(template (value) HTTP2_Frame http2_frame) +function f_http2_adapter_send(template (value) HTTP2_Frame http2_frame, + integer idx := 0) runs on HTTP2_CT { - HTTP2.send(ts_HTTP2_Send(g_self_conn_id, http2_frame)); + 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 := ?) + template (present) HTTP2_Frame exp_http2_frame := ?, + integer idx := 0) runs on HTTP2_CT { var HTTP2_Recv http2_rx; - [] HTTP2.receive(tr_HTTP2_Recv(g_self_conn_id, exp_http2_frame, omit)) -> value 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; } } diff --git a/smf/SMF_Session_CT_5G.ttcn b/smf/SMF_Session_CT_5G.ttcn index 8821260..c5000bc 100644 --- a/smf/SMF_Session_CT_5G.ttcn +++ b/smf/SMF_Session_CT_5G.ttcn @@ -68,7 +68,6 @@
function f_n11_init() runs on SMF_Session_CT { f_http2_adapter_init(); - f_http2_adapter_connect(mp_smf_hostname, mp_smf_sbi_port, mp_amf_local_ip, -1); }
function f_http2_encode_body_multipart_json_5gnas(octetstring json_encoded, @@ -104,6 +103,7 @@ 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) SmContextCreateData sm_contexts; @@ -148,11 +148,15 @@ }; 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);
/////////// START MUTUAL EXCLUSION ZONE //////////// @@ -170,7 +174,8 @@
f_http2_adapter_send(ts_HTTP2_Frame_Data(3, end_stream_flag := true, - data := body)); + data := body), + idx := http2_idx);
/* Expect UDM to receive GET sm-data: */ as_nudm_sdm_get_sm_data(); @@ -182,7 +187,8 @@ tr_HTTP2_Frame_Header(stream_id := http2_stream_id, end_stream_flag := false, end_header_flag := true, - header_block_fragment := ?)); + 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), *}); @@ -194,8 +200,9 @@ as_http2_adapter_receive(rx_http_frame, tr_HTTP2_Frame_Data(stream_id := http2_stream_id, end_stream_flag := true, - data := char2oct("{}"))); - f_http2_adapter_close(); + data := char2oct("{}")), + idx := http2_idx); + f_http2_adapter_close(idx := http2_idx);
/* Expect PCF to receive POST sm-policies: */ as_npcf_smpolicycontrol_post_sm_policies();