[L] Change in osmo-ttcn3-hacks[master]: Asterisk: Initial AMI support
pespin has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36594?usp=email ) Change subject: Asterisk: Initial AMI support .. Patch Set 2: (1 comment) File asterisk/AMI_Functions.ttcn: https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36594/comment/eb4276c1_c703068e PS2, Line 109: var integer pos := f_strstr(str, ": ", 0); > Damn, I am late to the party :( I'll have a look tomorrow, thanks! -- To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36594?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-ttcn3-hacks Gerrit-Branch: master Gerrit-Change-Id: I2c570e4d04e7ab8c44962cf484e4bbc946209aee Gerrit-Change-Number: 36594 Gerrit-PatchSet: 2 Gerrit-Owner: pespin Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-Reviewer: jolly Gerrit-Reviewer: laforge Gerrit-Reviewer: osmith Gerrit-Reviewer: pespin Gerrit-Comment-Date: Thu, 18 Apr 2024 17:39:14 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: fixeria Gerrit-MessageType: comment
[L] Change in osmo-ttcn3-hacks[master]: Asterisk: Initial AMI support
Attention is currently required from: pespin. fixeria has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36594?usp=email ) Change subject: Asterisk: Initial AMI support .. Patch Set 2: (1 comment) File asterisk/AMI_Functions.ttcn: https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36594/comment/0706ff2c_22efea22 PS2, Line 109: var integer pos := f_strstr(str, ": ", 0); > Looks like you could use TITAN's TEXT encoder for doing this: […] Damn, I am late to the party :( -- To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36594?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-ttcn3-hacks Gerrit-Branch: master Gerrit-Change-Id: I2c570e4d04e7ab8c44962cf484e4bbc946209aee Gerrit-Change-Number: 36594 Gerrit-PatchSet: 2 Gerrit-Owner: pespin Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-Reviewer: jolly Gerrit-Reviewer: laforge Gerrit-Reviewer: osmith Gerrit-Reviewer: pespin Gerrit-Attention: pespin Gerrit-Comment-Date: Thu, 18 Apr 2024 16:32:09 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: fixeria Gerrit-MessageType: comment
[L] Change in osmo-ttcn3-hacks[master]: Asterisk: Initial AMI support
Attention is currently required from: pespin. fixeria has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36594?usp=email ) Change subject: Asterisk: Initial AMI support .. Patch Set 2: (1 comment) File asterisk/AMI_Functions.ttcn: https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36594/comment/fbca309d_39ffd603 PS2, Line 109: var integer pos := f_strstr(str, ": ", 0); Looks like you could use TITAN's TEXT encoder for doing this: ``` type record AMI_Field { charstring key, charstring val } with { encode "TEXT" variant "SEPARATOR(':')" }; type set of AMI_Field AMI_Msg with { encode "TEXT" variant "SEPARATOR('\r\n')" variant "END('\r\n')" }; external function enc_AMI_Msg(in AMI_Msg msg) return charstring with { extension "prototype(convert) encode(TEXT)" } external function dec_AMI_Msg(in charstring stream) return AMI_Msg with { extension "prototype(convert) decode(TEXT)" } ``` See https://gitlab.eclipse.org/eclipse/titan/titan.core/-/blob/master/usrguide/referenceguide/4-ttcn3_language_extensions.adoc?ref_type=heads#user-content-text-encoder-and-decoder. Not saying you have to do it this way, but if we can offload some work to TITAN - why not. I have a small self-test: ``` private type component dummy_CT { }; testcase TC_tuwat() runs on dummy_CT { var AMI_Msg msg := { { "field1", "value1" }, { "field2", "value2" }, { "field3", "value3" } }; var charstring text := enc_AMI_Msg(msg); log("AMI msg encoded: ", text); var AMI_Msg msg_dec := dec_AMI_Msg(text); log("AMI msg decoded: ", msg_dec); } ``` and here is the output it produces: ``` MTC@LEGION: AMI msg encoded: "field1:value1\r\nfield2:value2\r\nfield3:value3\r\n" MTC@LEGION: AMI msg decoded: { { key := "field1", val := "value1" }, { key := "field2", val := "value2" }, { key := "field3", val := "value3" } } ``` -- To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36594?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-ttcn3-hacks Gerrit-Branch: master Gerrit-Change-Id: I2c570e4d04e7ab8c44962cf484e4bbc946209aee Gerrit-Change-Number: 36594 Gerrit-PatchSet: 2 Gerrit-Owner: pespin Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-Reviewer: jolly Gerrit-Reviewer: laforge Gerrit-Reviewer: osmith Gerrit-Reviewer: pespin Gerrit-Attention: pespin Gerrit-Comment-Date: Thu, 18 Apr 2024 16:31:38 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Gerrit-MessageType: comment
[L] Change in osmo-ttcn3-hacks[master]: Asterisk: Initial AMI support
pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36594?usp=email ) Change subject: Asterisk: Initial AMI support .. Asterisk: Initial AMI support Introduce config and functions around TELNETasp_PT to implement an AMI interface client to interact with Asterisk. So far only the "Action: Login" case is implemented. Change-Id: I2c570e4d04e7ab8c44962cf484e4bbc946209aee --- A asterisk/AMI_Functions.ttcn M asterisk/Asterisk_Tests.default M asterisk/Asterisk_Tests.ttcn M asterisk/gen_links.sh M asterisk/regen_makefile.sh 5 files changed, 257 insertions(+), 1 deletion(-) Approvals: osmith: Looks good to me, but someone else must approve pespin: Looks good to me, approved Jenkins Builder: Verified jolly: Looks good to me, but someone else must approve diff --git a/asterisk/AMI_Functions.ttcn b/asterisk/AMI_Functions.ttcn new file mode 100644 index 000..53a7964 --- /dev/null +++ b/asterisk/AMI_Functions.ttcn @@ -0,0 +1,212 @@ +/* Asterisk's AMI interface functions in TTCN-3 + * (C) 2024 by sysmocom - s.f.m.c. GmbH + * Author: Pau Espin Pedrol + * All rights reserved. + * + * 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 + */ + +/* + * https://docs.asterisk.org/Configuration/Interfaces/Asterisk-Manager-Interface-AMI/AMI-v2-Specification/ + */ +module AMI_Functions { + +import from Misc_Helpers all; +import from TELNETasp_PortType all; +import from Osmocom_Types all; +import from TCCConversion_Functions all; +import from Socket_API_Definitions all; + +modulepar { + float mp_ami_prompt_timeout := 10.0; +} + +const charstring AMI_FIELD_ACTION := "Action"; +const charstring AMI_FIELD_USERNAME := "Username"; +const charstring AMI_FIELD_SECRET := "Secret"; +const charstring AMI_FIELD_RESPONSE := "Response"; + +type record AMI_Field { + charstring key, + charstring val +}; +type set of AMI_Field AMI_Msg; + +template (value) AMI_Field +ts_AMI_Field(template (value) charstring key, +template (value) charstring val) := { + key := key, + val := val +}; + +template (present) AMI_Field +tr_AMI_Field(template (present) charstring key := ?, +template (present) charstring val := ?) := { + key := key, + val := val +}; + +/* + * Field Templates: + */ + +template (value) AMI_Field +ts_AMI_Field_Action(template (value) charstring val) := ts_AMI_Field(AMI_FIELD_ACTION, val); +template (value) AMI_Field +ts_AMI_Field_Username(template (value) charstring val) := ts_AMI_Field(AMI_FIELD_USERNAME, val); +template (value) AMI_Field +ts_AMI_Field_Secret(template (value) charstring val) := ts_AMI_Field(AMI_FIELD_SECRET, val); + +template (present) AMI_Field +tr_AMI_Field_Action(template (present) charstring val := ?) := tr_AMI_Field(AMI_FIELD_ACTION, val); +template (present) AMI_Field +tr_AMI_Field_Username(template (present) charstring val := ?) := tr_AMI_Field(AMI_FIELD_USERNAME, val); +template (present) AMI_Field +tr_AMI_Field_Secret(template (present) charstring val := ?) := tr_AMI_Field(AMI_FIELD_SECRET, val); +template (present) AMI_Field +tr_AMI_Field_Response(template (present) charstring val := ?) := tr_AMI_Field(AMI_FIELD_RESPONSE, val); + + +template (present) AMI_Field +tr_AMI_Field_ResponseSuccess := tr_AMI_Field(AMI_FIELD_RESPONSE, "Success"); + + +/* + * Message Templates: + */ + +template (value) AMI_Msg +ts_AMI_Action_Login(charstring username, charstring secret) := { + ts_AMI_Field_Action("Login"), + ts_AMI_Field_Username(username), + ts_AMI_Field_Secret(secret) +}; + +template (present) AMI_Msg +tr_AMI_Action_Login(template(present) charstring username := ?, + template(present) charstring secret := ?) := superset( + tr_AMI_Field_Action("Login"), + tr_AMI_Field_Username(username), + tr_AMI_Field_Secret(secret) +); + +template (present) AMI_Msg +tr_AMI_Response_Success := superset( + tr_AMI_Field_ResponseSuccess +); + +/* + * Functions: + */ + +function f_AMI_Field_from_str(charstring str) return AMI_Field { + var AMI_Field field; + /* "each field is a key value pair delineated by a ':'. +* A single space MUST follow the ':' and precede the value. "*/ + var integer pos := f_strstr(str, ": ", 0); + if (pos < 0) { + Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, + log2str("Failed parsing AMI_Field: ", str)); + } + field.key := substr(str, 0, pos); + /* skip ": " */ + pos := pos + 2; + field.val := substr(str, pos, lengthof(str) - pos); + return field; +} + +function f_AMI_Msg_from_str(charstring str) return AMI_Msg { + var AMI_Msg msg := {}; + var Misc_Helpers.ro_charstring lines := f_str_split(str, "\n"); + +
[L] Change in osmo-ttcn3-hacks[master]: Asterisk: Initial AMI support
Attention is currently required from: fixeria, laforge. pespin has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36594?usp=email ) Change subject: Asterisk: Initial AMI support .. Patch Set 2: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36594?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-ttcn3-hacks Gerrit-Branch: master Gerrit-Change-Id: I2c570e4d04e7ab8c44962cf484e4bbc946209aee Gerrit-Change-Number: 36594 Gerrit-PatchSet: 2 Gerrit-Owner: pespin Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-Reviewer: jolly Gerrit-Reviewer: laforge Gerrit-Reviewer: osmith Gerrit-Reviewer: pespin Gerrit-Attention: laforge Gerrit-Attention: fixeria Gerrit-Comment-Date: Thu, 18 Apr 2024 13:46:52 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
[L] Change in osmo-ttcn3-hacks[master]: Asterisk: Initial AMI support
Attention is currently required from: fixeria, laforge, pespin. jolly has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36594?usp=email ) Change subject: Asterisk: Initial AMI support .. Patch Set 2: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36594?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-ttcn3-hacks Gerrit-Branch: master Gerrit-Change-Id: I2c570e4d04e7ab8c44962cf484e4bbc946209aee Gerrit-Change-Number: 36594 Gerrit-PatchSet: 2 Gerrit-Owner: pespin Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-Reviewer: jolly Gerrit-Reviewer: laforge Gerrit-Reviewer: osmith Gerrit-Attention: laforge Gerrit-Attention: pespin Gerrit-Attention: fixeria Gerrit-Comment-Date: Thu, 18 Apr 2024 13:33:12 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
[L] Change in osmo-ttcn3-hacks[master]: Asterisk: Initial AMI support
Attention is currently required from: fixeria, jolly, laforge, pespin. osmith has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36594?usp=email ) Change subject: Asterisk: Initial AMI support .. Patch Set 1: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36594?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-ttcn3-hacks Gerrit-Branch: master Gerrit-Change-Id: I2c570e4d04e7ab8c44962cf484e4bbc946209aee Gerrit-Change-Number: 36594 Gerrit-PatchSet: 1 Gerrit-Owner: pespin Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-Reviewer: jolly Gerrit-Reviewer: laforge Gerrit-Reviewer: osmith Gerrit-Attention: jolly Gerrit-Attention: laforge Gerrit-Attention: pespin Gerrit-Attention: fixeria Gerrit-Comment-Date: Thu, 18 Apr 2024 11:30:46 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
[L] Change in osmo-ttcn3-hacks[master]: Asterisk: Initial AMI support
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36594?usp=email ) Change subject: Asterisk: Initial AMI support .. Asterisk: Initial AMI support Introduce config and functions around TELNETasp_PT to implement an AMI interface client to interact with Asterisk. So far only the "Action: Login" case is implemented. Change-Id: I2c570e4d04e7ab8c44962cf484e4bbc946209aee --- A asterisk/AMI_Functions.ttcn M asterisk/Asterisk_Tests.default M asterisk/Asterisk_Tests.ttcn M asterisk/gen_links.sh M asterisk/regen_makefile.sh 5 files changed, 257 insertions(+), 1 deletion(-) git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks refs/changes/94/36594/1 diff --git a/asterisk/AMI_Functions.ttcn b/asterisk/AMI_Functions.ttcn new file mode 100644 index 000..53a7964 --- /dev/null +++ b/asterisk/AMI_Functions.ttcn @@ -0,0 +1,212 @@ +/* Asterisk's AMI interface functions in TTCN-3 + * (C) 2024 by sysmocom - s.f.m.c. GmbH + * Author: Pau Espin Pedrol + * All rights reserved. + * + * 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 + */ + +/* + * https://docs.asterisk.org/Configuration/Interfaces/Asterisk-Manager-Interface-AMI/AMI-v2-Specification/ + */ +module AMI_Functions { + +import from Misc_Helpers all; +import from TELNETasp_PortType all; +import from Osmocom_Types all; +import from TCCConversion_Functions all; +import from Socket_API_Definitions all; + +modulepar { + float mp_ami_prompt_timeout := 10.0; +} + +const charstring AMI_FIELD_ACTION := "Action"; +const charstring AMI_FIELD_USERNAME := "Username"; +const charstring AMI_FIELD_SECRET := "Secret"; +const charstring AMI_FIELD_RESPONSE := "Response"; + +type record AMI_Field { + charstring key, + charstring val +}; +type set of AMI_Field AMI_Msg; + +template (value) AMI_Field +ts_AMI_Field(template (value) charstring key, +template (value) charstring val) := { + key := key, + val := val +}; + +template (present) AMI_Field +tr_AMI_Field(template (present) charstring key := ?, +template (present) charstring val := ?) := { + key := key, + val := val +}; + +/* + * Field Templates: + */ + +template (value) AMI_Field +ts_AMI_Field_Action(template (value) charstring val) := ts_AMI_Field(AMI_FIELD_ACTION, val); +template (value) AMI_Field +ts_AMI_Field_Username(template (value) charstring val) := ts_AMI_Field(AMI_FIELD_USERNAME, val); +template (value) AMI_Field +ts_AMI_Field_Secret(template (value) charstring val) := ts_AMI_Field(AMI_FIELD_SECRET, val); + +template (present) AMI_Field +tr_AMI_Field_Action(template (present) charstring val := ?) := tr_AMI_Field(AMI_FIELD_ACTION, val); +template (present) AMI_Field +tr_AMI_Field_Username(template (present) charstring val := ?) := tr_AMI_Field(AMI_FIELD_USERNAME, val); +template (present) AMI_Field +tr_AMI_Field_Secret(template (present) charstring val := ?) := tr_AMI_Field(AMI_FIELD_SECRET, val); +template (present) AMI_Field +tr_AMI_Field_Response(template (present) charstring val := ?) := tr_AMI_Field(AMI_FIELD_RESPONSE, val); + + +template (present) AMI_Field +tr_AMI_Field_ResponseSuccess := tr_AMI_Field(AMI_FIELD_RESPONSE, "Success"); + + +/* + * Message Templates: + */ + +template (value) AMI_Msg +ts_AMI_Action_Login(charstring username, charstring secret) := { + ts_AMI_Field_Action("Login"), + ts_AMI_Field_Username(username), + ts_AMI_Field_Secret(secret) +}; + +template (present) AMI_Msg +tr_AMI_Action_Login(template(present) charstring username := ?, + template(present) charstring secret := ?) := superset( + tr_AMI_Field_Action("Login"), + tr_AMI_Field_Username(username), + tr_AMI_Field_Secret(secret) +); + +template (present) AMI_Msg +tr_AMI_Response_Success := superset( + tr_AMI_Field_ResponseSuccess +); + +/* + * Functions: + */ + +function f_AMI_Field_from_str(charstring str) return AMI_Field { + var AMI_Field field; + /* "each field is a key value pair delineated by a ':'. +* A single space MUST follow the ':' and precede the value. "*/ + var integer pos := f_strstr(str, ": ", 0); + if (pos < 0) { + Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, + log2str("Failed parsing AMI_Field: ", str)); + } + field.key := substr(str, 0, pos); + /* skip ": " */ + pos := pos + 2; + field.val := substr(str, pos, lengthof(str) - pos); + return field; +} + +function f_AMI_Msg_from_str(charstring str) return AMI_Msg { + var AMI_Msg msg := {}; + var Misc_Helpers.ro_charstring lines := f_str_split(str, "\n"); + + for (var integer i := 0; i < lengthof(lines); i := i + 1) { + var charstring line