From 3486ff958c293dca2d80ddf83f7c59b7111f55d0 Mon Sep 17 00:00:00 2001 From: Hoan Luu Huu <110280845+xquanluu@users.noreply.github.com> Date: Thu, 11 May 2023 02:41:39 +0700 Subject: [PATCH] feat: add protocol to sip-gateways (#166) * feat: add protocol to sip-gateways * add tls/srtp options * fix sql * update db script has new changes --------- Co-authored-by: Dave Horton --- db/jambones-sql.sql | 6 +-- db/jambones.sqs | 97 +++++++++++++++++++++------------------ db/upgrade-jambonz-db.js | 39 ++++++++++++++++ lib/models/sip-gateway.js | 4 ++ test/sip-gateways.js | 7 ++- 5 files changed, 104 insertions(+), 49 deletions(-) diff --git a/db/jambones-sql.sql b/db/jambones-sql.sql index f9c4604..59ec87e 100644 --- a/db/jambones-sql.sql +++ b/db/jambones-sql.sql @@ -1,5 +1,4 @@ /* SQLEditor (MySQL (2))*/ - SET FOREIGN_KEY_CHECKS=0; DROP TABLE IF EXISTS account_static_ips; @@ -145,7 +144,7 @@ regex VARCHAR(32) NOT NULL COMMENT 'regex-based pattern match against dialed num description VARCHAR(1024), priority INTEGER NOT NULL COMMENT 'lower priority routes are attempted first', PRIMARY KEY (lcr_route_sid) -) COMMENT='An ordered list of digit patterns in an LCR table. The pat'; +) COMMENT='An ordered list of digit patterns in an LCR table. The patterns are tested in sequence until one matches'; CREATE TABLE lcr ( @@ -156,7 +155,7 @@ default_carrier_set_entry_sid CHAR(36) COMMENT 'default carrier/route to use whe service_provider_sid CHAR(36), account_sid CHAR(36), PRIMARY KEY (lcr_sid) -) COMMENT='An LCR (least cost routing) table that is used by a service '; +) COMMENT='An LCR (least cost routing) table that is used by a service provider or account to make decisions about routing outbound calls when multiple carriers are available.'; CREATE TABLE password_settings ( @@ -430,6 +429,7 @@ inbound BOOLEAN NOT NULL COMMENT 'if true, whitelist this IP to allow inbound ca outbound BOOLEAN NOT NULL COMMENT 'if true, include in least-cost routing when placing calls to the PSTN', voip_carrier_sid CHAR(36) NOT NULL, is_active BOOLEAN NOT NULL DEFAULT 1, +protocol ENUM('udp','tcp','tls', 'tls/srtp') DEFAULT 'udp' COMMENT 'Outbound call protocol', PRIMARY KEY (sip_gateway_sid) ) COMMENT='A whitelisted sip gateway used for origination/termination'; diff --git a/db/jambones.sqs b/db/jambones.sqs index 480d7fd..d5eda5e 100644 --- a/db/jambones.sqs +++ b/db/jambones.sqs @@ -9,7 +9,7 @@ 283.00 - 220.00 + 200.00 25 @@ -87,7 +87,7 @@ - + @@ -148,7 +148,7 @@ - + @@ -225,7 +225,7 @@ - + @@ -279,7 +279,7 @@ - + @@ -316,7 +316,7 @@ - + @@ -471,7 +471,7 @@ - + @@ -537,7 +537,7 @@ - + @@ -737,7 +737,7 @@ - + @@ -819,7 +819,7 @@ - + @@ -872,7 +872,7 @@ - + @@ -999,7 +999,7 @@ - + @@ -1020,7 +1020,7 @@ - + @@ -1081,7 +1081,7 @@ - + @@ -1133,7 +1133,7 @@ - + @@ -1183,7 +1183,7 @@ - + @@ -1283,7 +1283,7 @@ - + @@ -1352,7 +1352,7 @@ - + @@ -1389,7 +1389,7 @@ - + @@ -1427,7 +1427,7 @@ - + @@ -1459,7 +1459,7 @@ - + @@ -1536,7 +1536,7 @@ - + @@ -1607,7 +1607,7 @@ - + @@ -1800,7 +1800,7 @@ - + @@ -1839,7 +1839,7 @@ - + @@ -1931,7 +1931,7 @@ - + @@ -2001,7 +2001,7 @@ - + @@ -2053,7 +2053,7 @@ - + @@ -2149,7 +2149,7 @@ - + @@ -2163,8 +2163,8 @@ 17.00 - 260.00 - 200.00 + 281.00 + 220.00 7 @@ -2249,7 +2249,14 @@ - + + + + + + + + @@ -2423,7 +2430,7 @@ - + @@ -2531,7 +2538,7 @@ - + @@ -2562,6 +2569,8 @@ + + @@ -2645,7 +2654,7 @@ - + @@ -2705,7 +2714,7 @@ - + @@ -2772,7 +2781,7 @@ - + @@ -2835,7 +2844,7 @@ - + @@ -2846,17 +2855,17 @@ - + - + - - - + + + - + diff --git a/db/upgrade-jambonz-db.js b/db/upgrade-jambonz-db.js index d06a1c8..d396f6b 100644 --- a/db/upgrade-jambonz-db.js +++ b/db/upgrade-jambonz-db.js @@ -89,6 +89,7 @@ const sql = { 'ALTER TABLE `users` ADD COLUMN `is_active` BOOLEAN NOT NULL default true', ], 8003: [ + 'SET FOREIGN_KEY_CHECKS=0', 'ALTER TABLE `voip_carriers` ADD COLUMN `register_status` VARCHAR(4096)', 'ALTER TABLE `sbc_addresses` ADD COLUMN `last_updated` DATETIME', 'ALTER TABLE `sbc_addresses` ADD COLUMN `tls_port` INTEGER', @@ -99,6 +100,44 @@ const sql = { sip_domain_name VARCHAR(255), monitoring_domain_name VARCHAR(255) )`, + 'DROP TABLE IF EXISTS `lcr_routes`', + 'DROP TABLE IF EXISTS `lcr_carrier_set_entry`', + `CREATE TABLE lcr_routes + ( + lcr_route_sid CHAR(36), + lcr_sid CHAR(36) NOT NULL, + regex VARCHAR(32) NOT NULL COMMENT 'regex-based pattern match against dialed number, used for LCR routing of PSTN calls', + description VARCHAR(1024), + priority INTEGER NOT NULL COMMENT 'lower priority routes are attempted first', + PRIMARY KEY (lcr_route_sid) + )`, + `CREATE TABLE lcr + ( + lcr_sid CHAR(36) NOT NULL UNIQUE , + name VARCHAR(64) COMMENT 'User-assigned name for this LCR table', + is_active BOOLEAN NOT NULL DEFAULT 1, + default_carrier_set_entry_sid CHAR(36) COMMENT 'default carrier/route to use when no digit match based results are found.', + service_provider_sid CHAR(36), + account_sid CHAR(36), + PRIMARY KEY (lcr_sid) + )`, + `CREATE TABLE lcr_carrier_set_entry + ( + lcr_carrier_set_entry_sid CHAR(36), + workload INTEGER NOT NULL DEFAULT 1 COMMENT 'represents a proportion of traffic to send through the associated carrier; can be used for load balancing traffic across carriers with a common priority for a destination', + lcr_route_sid CHAR(36) NOT NULL, + voip_carrier_sid CHAR(36) NOT NULL, + priority INTEGER NOT NULL DEFAULT 0 COMMENT 'lower priority carriers are attempted first', + PRIMARY KEY (lcr_carrier_set_entry_sid) + )`, + 'CREATE INDEX lcr_sid_idx ON lcr_routes (lcr_sid)', + 'ALTER TABLE lcr_routes ADD FOREIGN KEY lcr_sid_idxfk (lcr_sid) REFERENCES lcr (lcr_sid)', + 'CREATE INDEX lcr_sid_idx ON lcr (lcr_sid)', + 'ALTER TABLE lcr ADD FOREIGN KEY default_carrier_set_entry_sid_idxfk (default_carrier_set_entry_sid) REFERENCES lcr_carrier_set_entry (lcr_carrier_set_entry_sid)', + 'CREATE INDEX service_provider_sid_idx ON lcr (service_provider_sid)', + 'CREATE INDEX account_sid_idx ON lcr (account_sid)', + 'ALTER TABLE lcr_carrier_set_entry ADD FOREIGN KEY lcr_route_sid_idxfk (lcr_route_sid) REFERENCES lcr_routes (lcr_route_sid)', + 'ALTER TABLE lcr_carrier_set_entry ADD FOREIGN KEY voip_carrier_sid_idxfk_3 (voip_carrier_sid) REFERENCES voip_carriers (voip_carrier_sid)', ] }; diff --git a/lib/models/sip-gateway.js b/lib/models/sip-gateway.js index 7a316a2..8439560 100644 --- a/lib/models/sip-gateway.js +++ b/lib/models/sip-gateway.js @@ -58,6 +58,10 @@ SipGateway.fields = [ { name: 'application_sid', type: 'string' + }, + { + name: 'protocol', + type: 'string' } ]; diff --git a/test/sip-gateways.js b/test/sip-gateways.js index ef59463..8f6e17f 100644 --- a/test/sip-gateways.js +++ b/test/sip-gateways.js @@ -27,7 +27,8 @@ test('sip gateway tests', async(t) => { ipv4: '192.168.1.1', netmask: 32, inbound: true, - outbound: true + outbound: true, + protocol: 'tcp' } }); t.ok(result.statusCode === 201, 'successfully created sip gateway '); @@ -48,6 +49,7 @@ test('sip gateway tests', async(t) => { }); //console.log(`result: ${JSON.stringify(result)}`); t.ok(result.ipv4 === '192.168.1.1' , 'successfully retrieved voip carrier by sid'); + t.ok(result.protocol === 'tcp' , 'successfully retrieved voip carrier by sid'); /* update sip gateway */ @@ -58,7 +60,8 @@ test('sip gateway tests', async(t) => { body: { port: 5061, netmask:24, - outbound: false + outbound: false, + protocol: 'udp' } }); t.ok(result.statusCode === 204, 'successfully updated voip carrier');