pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/43674?usp=email )
Change subject: Move HTTP2_Msg to its own file ......................................................................
Move HTTP2_Msg to its own file
It is so far only used by HTTP2_Server_Emulation, but it will be reused by HTTP2_Adapter in a follow-up patch.
Change-Id: Ib5ec7c2bb6882b2359c6b98836c01f70b1c28585 --- A library/HTTP2_Msg.ttcn M library/HTTP2_Server_Emulation.ttcn M smf/gen_links.sh 3 files changed, 102 insertions(+), 73 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks refs/changes/74/43674/1
diff --git a/library/HTTP2_Msg.ttcn b/library/HTTP2_Msg.ttcn new file mode 100644 index 0000000..3ff6ab8 --- /dev/null +++ b/library/HTTP2_Msg.ttcn @@ -0,0 +1,100 @@ +/* HTTP2 Emulation in TTCN-3 + * + * (C) 2026 by sysmocom - s.f.m.c. GmbH info@sysmocom.de + * + * Released under the terms of GNU General Public License, Version 2 or + * (at your option) any later version. + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This module implements a HTTP/HTTPs 2.0 server, + */ + +module HTTP2_Msg { + +import from HTTP2_Types all; +import from HTTP2_CodecPort all; +import from HTTP2_CodecPort_CtrlFunct all; +import from IPL4asp_Types all; +import from IPL4asp_PortType all; +import from Socket_API_Definitions all; + +import from HTTP2_Templates all; +import from HTTP2_Functions all; + +import from Native_Functions all; +import from Misc_Helpers all; + + +/*************** + * HTTP2_Msg + **************/ + +type record HTTP2_Msg { + IPL4asp_Types.ConnectionId conn_id, + integer stream_id, + HTTP2_header_block hb, + HTTP2_Data_frame body optional +} + +template (present) HTTP2_Msg +tr_HTTP2_Msg(template (present) IPL4asp_Types.ConnectionId conn_id := ?, + template (present) integer stream_id := ?, + template (present) HTTP2_header_block hb := ?, + template HTTP2_Data_frame body := *) := { + conn_id := conn_id, + stream_id := stream_id, + hb := hb, + body := body +} + +template (value) HTTP2_Msg +ts_HTTP2_Msg(template (value) IPL4asp_Types.ConnectionId conn_id, + template (value) integer stream_id, + template (value) HTTP2_header_block hb, + template (omit) HTTP2_Data_frame body := omit) := { + conn_id := conn_id, + stream_id := stream_id, + hb := hb, + body := body +} + +template (value) HTTP2_Msg +ts_HTTP2_Msg_Status(template (value) IPL4asp_Types.ConnectionId conn_id, + template (value) integer stream_id, + template (value) integer status, + template (omit) HTTP2_header_list headers := omit, + template (omit) HTTP2_Data_frame body := omit) := +ts_HTTP2_Msg(conn_id, + stream_id, + hb := ts_HTTP2_header_block(pseudo_headers := ts_HTTP2_pseudo_headers_Resp(status), + headers := headers), + body := body + ); + +template (value) HTTP2_Msg +ts_HTTP2_Msg_200_OK(template (value) IPL4asp_Types.ConnectionId conn_id, + template (value) integer stream_id, + template (omit) HTTP2_header_list headers := omit, + template (omit) HTTP2_Data_frame body := omit) := +ts_HTTP2_Msg_Status(conn_id, stream_id, 200, headers, body); + +template (value) HTTP2_Msg +ts_HTTP2_Msg_201_Created(template (value) IPL4asp_Types.ConnectionId conn_id, + template (value) integer stream_id, + template (omit) HTTP2_header_list headers := omit, + template (omit) HTTP2_Data_frame body := omit) := +ts_HTTP2_Msg_Status(conn_id, stream_id, 201, headers, body); + + +function f_HTTP2_Msg_append_hdr_content_length(inout HTTP2_Msg http2_msg) +{ + if (not ispresent(http2_msg.body)) { + return; + } + var integer content_length := lengthof(http2_msg.body.data); /* TODO: http2_msg.body.padding ? */ + http2_msg.hb.headers := http2_msg.hb.headers & + { valueof(ts_HTTP2_Hdr_content_length(int2str(content_length))) }; +} + +} diff --git a/library/HTTP2_Server_Emulation.ttcn b/library/HTTP2_Server_Emulation.ttcn index 46b30d0..528cd94 100644 --- a/library/HTTP2_Server_Emulation.ttcn +++ b/library/HTTP2_Server_Emulation.ttcn @@ -21,82 +21,11 @@
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;
- -/*************** - * HTTP2_Msg - **************/ - -type record HTTP2_Msg { - IPL4asp_Types.ConnectionId conn_id, - integer stream_id, - HTTP2_header_block hb, - HTTP2_Data_frame body optional -} - -template (present) HTTP2_Msg -tr_HTTP2_Msg(template (present) IPL4asp_Types.ConnectionId conn_id := ?, - template (present) integer stream_id := ?, - template (present) HTTP2_header_block hb := ?, - template HTTP2_Data_frame body := *) := { - conn_id := conn_id, - stream_id := stream_id, - hb := hb, - body := body -} - -template (value) HTTP2_Msg -ts_HTTP2_Msg(template (value) IPL4asp_Types.ConnectionId conn_id, - template (value) integer stream_id, - template (value) HTTP2_header_block hb, - template (omit) HTTP2_Data_frame body := omit) := { - conn_id := conn_id, - stream_id := stream_id, - hb := hb, - body := body -} - -template (value) HTTP2_Msg -ts_HTTP2_Msg_Status(template (value) IPL4asp_Types.ConnectionId conn_id, - template (value) integer stream_id, - template (value) integer status, - template (omit) HTTP2_header_list headers := omit, - template (omit) HTTP2_Data_frame body := omit) := -ts_HTTP2_Msg(conn_id, - stream_id, - hb := ts_HTTP2_header_block(pseudo_headers := ts_HTTP2_pseudo_headers_Resp(status), - headers := headers), - body := body - ); - -template (value) HTTP2_Msg -ts_HTTP2_Msg_200_OK(template (value) IPL4asp_Types.ConnectionId conn_id, - template (value) integer stream_id, - template (omit) HTTP2_header_list headers := omit, - template (omit) HTTP2_Data_frame body := omit) := -ts_HTTP2_Msg_Status(conn_id, stream_id, 200, headers, body); - -template (value) HTTP2_Msg -ts_HTTP2_Msg_201_Created(template (value) IPL4asp_Types.ConnectionId conn_id, - template (value) integer stream_id, - template (omit) HTTP2_header_list headers := omit, - template (omit) HTTP2_Data_frame body := omit) := -ts_HTTP2_Msg_Status(conn_id, stream_id, 201, headers, body); - - -function f_HTTP2_Msg_append_hdr_content_length(inout HTTP2_Msg http2_msg) -{ - if (not ispresent(http2_msg.body)) { - return; - } - var integer content_length := lengthof(http2_msg.body.data); /* TODO: http2_msg.body.padding ? */ - http2_msg.hb.headers := http2_msg.hb.headers & - { valueof(ts_HTTP2_Hdr_content_length(int2str(content_length))) }; -} - /********************* * HTTP2_Server_Conn ********************/ diff --git a/smf/gen_links.sh b/smf/gen_links.sh index 352f4a9..b95339f 100755 --- a/smf/gen_links.sh +++ b/smf/gen_links.sh @@ -126,7 +126,7 @@ FILES+="SCTP_Templates.ttcn " FILES+="NTP_Functions.ttcn PFCP_Templates.ttcn PFCP_CodecPort.ttcn PFCP_CodecPort_CtrlFunct.ttcn PFCP_CodecPort_CtrlFunctDef.cc PFCP_Emulation.ttcn " FILES+="Mutex.ttcn " -FILES+="HTTP2_CodecPort.ttcn HTTP2_CodecPort_CtrlFunct.ttcn HTTP2_CodecPort_CtrlFunctDef.cc HTTP2_Templates.ttcn HTTP2_Functions.ttcn HTTP2_Adapter.ttcn HTTP2_Server_Emulation.ttcn " +FILES+="HTTP2_CodecPort.ttcn HTTP2_CodecPort_CtrlFunct.ttcn HTTP2_CodecPort_CtrlFunctDef.cc HTTP2_Templates.ttcn HTTP2_Functions.ttcn HTTP2_Msg.ttcn HTTP2_Adapter.ttcn HTTP2_Server_Emulation.ttcn " FILES+="TS29503_Nudm_SDM_Templates.ttcn TS29502_Nsmf_PDUSession_Templates.ttcn TS29512_Npcf_SMPolicyControl_Templates.ttcn TS29518_Namf_Communication_Templates.ttcn " FILES+="NG_NAS_Osmo_Types.ttcn NG_NAS_Osmo_Templates.ttcn NG_NAS_Functions.ttcn " gen_links $DIR $FILES