From 52c713c4525baa3c9e8e6f9bb01486e6e44dfff7 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 16 Jul 2017 15:44:44 +0200 Subject: [PATCH] Implement L1CTL port type (dual-faced port on top of UnixDomain) --- lapd/L1CTL_PortType.ttcn | 52 ++++++++++++++++++++++++++++++++++++++++ lapd/L1CTL_Test.ttcn | 28 ++++++++++++++++++++++ lapd/L1CTL_Types.ttcn | 27 +++++++++++++++++++++ lapd/gen_links.sh | 6 +++++ lapd/regen_makefile.sh | 2 +- 5 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 lapd/L1CTL_PortType.ttcn diff --git a/lapd/L1CTL_PortType.ttcn b/lapd/L1CTL_PortType.ttcn new file mode 100644 index 000000000..d726ce4a6 --- /dev/null +++ b/lapd/L1CTL_PortType.ttcn @@ -0,0 +1,52 @@ +/* dual-faced port that wraps an Unixdomain port and encodes/decodes L1CTL */ +module L1CTL_PortType { + import from L1CTL_Types all; + import from UD_PortType all; + import from UD_Types all; + + type record L1CTL_connect { + charstring path + } + + type record L1CTL_connect_result { + UD_Result_code result_code optional, + charstring err optional + } + + private function L1CTL_to_UD_connect(in L1CTL_connect pin, out UD_connect pout) { + pout.path := pin.path; + pout.id := 0; + } with { extension "prototype(fast)" } + + private function UD_to_L1CTL_connect_result(in UD_connect_result pin, out L1CTL_connect_result pout) { + pout.result_code := pin.result.result_code; + pout.err := pin.result.err; + } with { extension "prototype(fast)" } + + private function L1CTL_to_UD_ul(in L1ctlUlMessage pin, out UD_send_data pout) { + var L1ctlUlMessageLV msg_lv := { msg := pin }; + pout.data := enc_L1ctlUlMessageLV(msg_lv); + pout.id := 0; + } with { extension "prototype(fast)" } + + private function UD_to_L1CTL_dl(in UD_send_data pin, out L1ctlDlMessage pout) { + var L1ctlDlMessageLV msg_lv := dec_L1ctlDlMessageLV(pin.data); + pout:= msg_lv.msg; + } with { extension "prototype(fast)" } + + type port L1CTL_PT message { + out L1ctlUlMessage + out L1CTL_connect + in L1ctlDlMessage + in L1CTL_connect_result + in UD_listen_result + in UD_connected + } with { extension "user UD_PT + out(L1ctlUlMessage -> UD_send_data: function(L1CTL_to_UD_ul); + L1CTL_connect -> UD_connect: function(L1CTL_to_UD_connect)) + in(UD_send_data -> L1ctlDlMessage: function(UD_to_L1CTL_dl); + UD_connect_result -> L1CTL_connect_result: function(UD_to_L1CTL_connect_result); + UD_listen_result -> UD_listen_result: simple; + UD_connected -> UD_connected: simple + )" } +} diff --git a/lapd/L1CTL_Test.ttcn b/lapd/L1CTL_Test.ttcn index b0486febb..faaf4ae7c 100644 --- a/lapd/L1CTL_Test.ttcn +++ b/lapd/L1CTL_Test.ttcn @@ -2,6 +2,7 @@ module L1CTL_Test { import from GSM_Types all; import from Osmocom_Types all; import from L1CTL_Types all; + import from L1CTL_PortType all; const octetstring c_ul_param_req := '1300000000000000001d0000'O; const octetstring c_ul_data_req := '060a0128284018001d000103490615004001c0000000000000000000000000'O; @@ -13,8 +14,29 @@ module L1CTL_Test { const octetstring c_dl_data_ind := '03000000900003670015f5613f3f00002d063f0328e36712ead000002b2b2b2b2b2b2b2b2b2b2b'O; type component dummy_CT { + var charstring l1ctl_sock_path := "/tmp/osmocom_l2"; + port L1CTL_PT L1CTL; }; + template L1ctlUlMessage t_L1ctlResetReq(template L1ctlResetType rst_type) := { + header := t_L1ctlHeader(L1CTL_RESET_REQ), + ul_info := omit, + payload := { + reset_req := { + reset_type := rst_type, + padding := '000000'O + } + } + }; + + //template UD_send_data + + function f_init() runs on dummy_CT { + map(self:L1CTL, system:L1CTL); + L1CTL.send(L1CTL_connect:{path:=l1ctl_sock_path}); + L1CTL.receive(L1CTL_connect_result:{result_code := SUCCESS, err:=omit}); + } + testcase TC_si1() runs on dummy_CT { log("L1CTL_PARAM_REQ: ", dec_L1ctlUlMessage(c_ul_param_req)); log("L1CTL_DATA_REQ: ", dec_L1ctlUlMessage(c_ul_data_req)); @@ -25,7 +47,13 @@ module L1CTL_Test { log("L1CTL_DATA_IND: ", dec_L1ctlDlMessage(c_dl_data_ind)); setverdict(pass); } + + testcase TC_l1ctl() runs on dummy_CT { + f_init(); + L1CTL.send(t_L1ctlResetReq(L1CTL_RES_T_FULL)); + } control { execute(TC_si1()); + execute(TC_l1ctl()); } } diff --git a/lapd/L1CTL_Types.ttcn b/lapd/L1CTL_Types.ttcn index 2a0aa4eeb..07d7bb55e 100644 --- a/lapd/L1CTL_Types.ttcn +++ b/lapd/L1CTL_Types.ttcn @@ -72,6 +72,12 @@ module L1CTL_Types { OCT2 padding } with { variant "" }; + template L1ctlHeader t_L1ctlHeader(template L1ctlMsgType msg_type) := { + msg_type := msg_type, + flags := { padding := '0000000'B, f_done := false }, + padding := '0000'O + }; + type uint8_t RslChanNr; type uint8_t RslLinkId; @@ -268,4 +274,25 @@ module L1CTL_Types { external function dec_L1ctlUlMessage(in octetstring stream) return L1ctlUlMessage with { extension "prototype(convert) decode(RAW)" }; + type record L1ctlUlMessageLV { + uint16_t len, + L1ctlUlMessage msg + } with { variant (len) "LENGTHTO(msg)" }; + + external function enc_L1ctlUlMessageLV(in L1ctlUlMessageLV msg) return octetstring + with { extension "prototype(convert) encode(RAW)" }; + external function dec_L1ctlUlMessageLV(in octetstring stream) return L1ctlUlMessageLV + with { extension "prototype(convert) decode(RAW)" }; + + type record L1ctlDlMessageLV { + uint16_t len, + L1ctlDlMessage msg + } with { variant (len) "LENGTHTO(msg)" }; + + external function enc_L1ctlDlMessageLV(in L1ctlDlMessageLV msg) return octetstring + with { extension "prototype(convert) encode(RAW)" }; + external function dec_L1ctlDlMessageLV(in octetstring stream) return L1ctlDlMessageLV + with { extension "prototype(convert) decode(RAW)" }; + + } with { encode "RAW" }; diff --git a/lapd/gen_links.sh b/lapd/gen_links.sh index 630b15602..7c0193e22 100755 --- a/lapd/gen_links.sh +++ b/lapd/gen_links.sh @@ -11,6 +11,12 @@ gen_links() { done } +DIR=$BASEDIR/titan.TestPorts.UNIX_DOMAIN_SOCKETasp/src +FILES="UD_PT.cc UD_PT.hh UD_PortType.ttcn UD_Types.ttcn" +gen_links $DIR $FILES + + + DIR=../sysinfo FILES="General_Types.ttcn GSM_Types.ttcn Osmocom_Types.ttcn" gen_links $DIR $FILES diff --git a/lapd/regen_makefile.sh b/lapd/regen_makefile.sh index a772686c0..8d321ac44 100755 --- a/lapd/regen_makefile.sh +++ b/lapd/regen_makefile.sh @@ -1,6 +1,6 @@ #!/bin/sh -FILES="*.ttcn" +FILES="*.ttcn UD_PT.cc UD_PT.hh" ttcn3_makefilegen -f L1CTL_Test.ttcn $FILES sed -i -e 's/# TTCN3_DIR = /TTCN3_DIR = \/usr/' Makefile