Skip to content

Commit c1b7aed

Browse files
Merge pull request #266 from dmitry-sinina/tags_to_routing_tag_detection
tag matching for routing tag detection rules
2 parents 842b419 + 4fd713f commit c1b7aed

File tree

8 files changed

+63
-25
lines changed

8 files changed

+63
-25
lines changed

db/migrate/20180119133842_create_tag_actions.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def up
1212
INSERT INTO class4.tag_actions(id,name) VALUES(2, 'Remove selected tags');
1313
INSERT INTO class4.tag_actions(id,name) VALUES(3, 'Append selected tags');
1414
INSERT INTO class4.tag_actions(id,name) VALUES(4, 'Intersection with selected tags');
15+
INSERT INTO class4.tag_actions(id,name) VALUES(5, 'Replace with selected tags');
1516
1617
-- References
1718
ALTER TABLE class4.customers_auth ADD tag_action_id smallint REFERENCES class4.tag_actions(id);

db/migrate/20180212105355_multiple_matching_conditions.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2560,9 +2560,15 @@ def up
25602560
25612561
25622562
select into v_area_direction * from class4.routing_tag_detection_rules
2563-
where (src_area_id is null OR src_area_id = v_ret.src_area_id) AND (dst_area_id is null OR dst_area_id=v_ret.dst_area_id)
2564-
order by src_area_id is null, dst_area_id is null
2565-
limit 1;
2563+
where
2564+
(src_area_id is null OR src_area_id = v_ret.src_area_id) AND
2565+
(dst_area_id is null OR dst_area_id=v_ret.dst_area_id) AND
2566+
yeti_ext.tag_compare(routing_tag_ids, v_call_tags)>0
2567+
order by
2568+
yeti_ext.tag_compare(routing_tag_ids, v_call_tags) desc,
2569+
src_area_id is null,
2570+
dst_area_id is null
2571+
limit 1;
25662572
if found then
25672573
v_call_tags=yeti_ext.tag_action(v_area_direction.tag_action_id, v_call_tags, v_area_direction.tag_action_value);
25682574
end if;
@@ -3336,7 +3342,7 @@ def up
33363342
INSERT INTO switch_interface_out (id, name, type, custom, rank, for_radius) VALUES (891, 'dst_number_radius', 'varchar', false, 1051, true);
33373343
INSERT INTO switch_interface_out (id, name, type, custom, rank, for_radius) VALUES (892, 'orig_gw_name', 'varchar', false, 1052, true);
33383344
INSERT INTO switch_interface_out (id, name, type, custom, rank, for_radius) VALUES (895, 'customer_name', 'varchar', false, 1055, true);
3339-
INSERT INTO switch_interface_out (id, name, type, custom, rank, for_radius) VALUES (894, 'customer_auth_name', 'varchar', false, 1054, true);
3345+
INSERT INTO switch_interface_out (id, name, type, custom, rank, for_radius) VALUES (894, 'customer_auth_name', 'varchar', true, 1054, true);
33403346
INSERT INTO switch_interface_out (id, name, type, custom, rank, for_radius) VALUES (896, 'customer_account_name', 'varchar', false, 1056, true);
33413347
INSERT INTO switch_interface_out (id, name, type, custom, rank, for_radius) VALUES (900, 'aleg_radius_acc_profile_id', 'smallint', false, 1024, false);
33423348
INSERT INTO switch_interface_out (id, name, type, custom, rank, for_radius) VALUES (901, 'bleg_radius_acc_profile_id', 'smallint', false, 1025, false);

db/secondbase/migrate/20180228200703_json_serialization.rb

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ def up
1717
add failed_resource_id bigint,
1818
add customer_price_no_vat numeric,
1919
add customer_duration integer,
20-
add vendor_duration integer;
20+
add vendor_duration integer,
21+
add customer_auth_name varchar;
2122
2223
alter table cdr.cdr_archive
2324
add column customer_external_id bigint,
@@ -33,7 +34,8 @@ def up
3334
add failed_resource_id bigint,
3435
add customer_price_no_vat numeric,
3536
add customer_duration integer,
36-
add vendor_duration integer;
37+
add vendor_duration integer,
38+
add customer_auth_name varchar;
3739
3840
create type switch.dynamic_cdr_data_ty as (
3941
customer_id integer,
@@ -47,6 +49,7 @@ def up
4749
vendor_acc_external_id bigint,
4850
customer_auth_id integer,
4951
customer_auth_external_id bigint,
52+
customer_auth_name varchar,
5053
destination_id bigint,
5154
destination_prefix character varying,
5255
dialpeer_id bigint,
@@ -193,6 +196,7 @@ def up
193196
194197
v_cdr.customer_auth_id:=v_dynamic.customer_auth_id;
195198
v_cdr.customer_auth_external_id:=v_dynamic.customer_auth_external_id;
199+
v_cdr.customer_auth_name:=v_dynamic.customer_auth_name;
196200
197201
v_cdr.vendor_id:=v_dynamic.vendor_id;
198202
v_cdr.vendor_external_id:=v_dynamic.vendor_external_id;
@@ -233,15 +237,18 @@ def up
233237
/* sockets addresses */
234238
v_cdr.sign_orig_transport_protocol_id=i_lega_transport_protocol_id;
235239
v_cdr.sign_orig_ip:=i_legA_remote_ip;
236-
v_cdr.sign_orig_port=i_legA_remote_port;
240+
v_cdr.sign_orig_port:=NULLIF(i_legA_remote_port,0);
241+
237242
v_cdr.sign_orig_local_ip:=i_legA_local_ip;
238-
v_cdr.sign_orig_local_port=i_legA_local_port;
243+
v_cdr.sign_orig_local_port=NULLIF(i_legA_local_port,0);
239244
240245
v_cdr.sign_term_transport_protocol_id=i_legb_transport_protocol_id;
241246
v_cdr.sign_term_ip:=i_legB_remote_ip;
242-
v_cdr.sign_term_port:=i_legB_remote_port;
247+
v_cdr.sign_term_port:=NULLIF(i_legB_remote_port,0);
248+
243249
v_cdr.sign_term_local_ip:=i_legB_local_ip;
244-
v_cdr.sign_term_local_port:=i_legB_local_port;
250+
v_cdr.sign_term_local_port:=NULLIF(i_legB_remote_port,0);
251+
245252
246253
v_cdr.local_tag=i_local_tag;
247254

db/secondbase/migrate/20180312211714_cdr_streaming.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def up
9898
9999
v_cdr.customer_auth_id:=v_dynamic.customer_auth_id;
100100
v_cdr.customer_auth_external_id:=v_dynamic.customer_auth_external_id;
101+
v_cdr.customer_auth_name:=v_dynamic.customer_auth_name;
101102
102103
v_cdr.vendor_id:=v_dynamic.vendor_id;
103104
v_cdr.vendor_external_id:=v_dynamic.vendor_external_id;
@@ -411,6 +412,7 @@ def down
411412
412413
v_cdr.customer_auth_id:=v_dynamic.customer_auth_id;
413414
v_cdr.customer_auth_external_id:=v_dynamic.customer_auth_external_id;
415+
v_cdr.customer_auth_name=v_dynamic.customer_auth_name;
414416
415417
v_cdr.vendor_id:=v_dynamic.vendor_id;
416418
v_cdr.vendor_external_id:=v_dynamic.vendor_external_id;

db/secondbase/structure.sql

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ CREATE TYPE switch.dynamic_cdr_data_ty AS (
194194
vendor_acc_external_id bigint,
195195
customer_auth_id integer,
196196
customer_auth_external_id bigint,
197+
customer_auth_name character varying,
197198
destination_id bigint,
198199
destination_prefix character varying,
199200
dialpeer_id bigint,
@@ -449,7 +450,8 @@ CREATE TABLE cdr.cdr (
449450
failed_resource_id bigint,
450451
customer_price_no_vat numeric,
451452
customer_duration integer,
452-
vendor_duration integer
453+
vendor_duration integer,
454+
customer_auth_name character varying
453455
);
454456

455457

@@ -1011,6 +1013,7 @@ BEGIN
10111013

10121014
v_cdr.customer_auth_id:=v_dynamic.customer_auth_id;
10131015
v_cdr.customer_auth_external_id:=v_dynamic.customer_auth_external_id;
1016+
v_cdr.customer_auth_name:=v_dynamic.customer_auth_name;
10141017

10151018
v_cdr.vendor_id:=v_dynamic.vendor_id;
10161019
v_cdr.vendor_external_id:=v_dynamic.vendor_external_id;
@@ -4015,7 +4018,8 @@ CREATE TABLE cdr.cdr_archive (
40154018
failed_resource_id bigint,
40164019
customer_price_no_vat numeric,
40174020
customer_duration integer,
4018-
vendor_duration integer
4021+
vendor_duration integer,
4022+
customer_auth_name character varying
40194023
);
40204024

40214025

db/seeds/main/class4.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,7 @@ INSERT INTO tag_actions VALUES (1, 'Clear tags');
943943
INSERT INTO tag_actions VALUES (2, 'Remove selected tags');
944944
INSERT INTO tag_actions VALUES (3, 'Append selected tags');
945945
INSERT INTO tag_actions VALUES (4, 'Intersection with selected tags');
946+
INSERT INTO tag_actions VALUES (5, 'Replace with selected tags');
946947

947948

948949
-- Completed on 2018-01-19 16:08:50 EET

db/seeds/main/switch15.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ INSERT INTO switch_interface_out (id, name, type, custom, rank, for_radius) VALU
104104
INSERT INTO switch_interface_out (id, name, type, custom, rank, for_radius) VALUES (891, 'dst_number_radius', 'varchar', false, 1051, true);
105105
INSERT INTO switch_interface_out (id, name, type, custom, rank, for_radius) VALUES (892, 'orig_gw_name', 'varchar', false, 1052, true);
106106
INSERT INTO switch_interface_out (id, name, type, custom, rank, for_radius) VALUES (895, 'customer_name', 'varchar', false, 1055, true);
107-
INSERT INTO switch_interface_out (id, name, type, custom, rank, for_radius) VALUES (894, 'customer_auth_name', 'varchar', false, 1054, true);
107+
INSERT INTO switch_interface_out (id, name, type, custom, rank, for_radius) VALUES (894, 'customer_auth_name', 'varchar', true, 1054, true);
108108
INSERT INTO switch_interface_out (id, name, type, custom, rank, for_radius) VALUES (896, 'customer_account_name', 'varchar', false, 1056, true);
109109
INSERT INTO switch_interface_out (id, name, type, custom, rank, for_radius) VALUES (900, 'aleg_radius_acc_profile_id', 'smallint', false, 1024, false);
110110
INSERT INTO switch_interface_out (id, name, type, custom, rank, for_radius) VALUES (901, 'bleg_radius_acc_profile_id', 'smallint', false, 1025, false);

db/structure.sql

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16512,9 +16512,15 @@ CREATE FUNCTION switch15.route(i_node_id integer, i_pop_id integer, i_protocol_i
1651216512

1651316513

1651416514
select into v_area_direction * from class4.routing_tag_detection_rules
16515-
where (src_area_id is null OR src_area_id = v_ret.src_area_id) AND (dst_area_id is null OR dst_area_id=v_ret.dst_area_id)
16516-
order by src_area_id is null, dst_area_id is null
16517-
limit 1;
16515+
where
16516+
(src_area_id is null OR src_area_id = v_ret.src_area_id) AND
16517+
(dst_area_id is null OR dst_area_id=v_ret.dst_area_id) AND
16518+
yeti_ext.tag_compare(routing_tag_ids, v_call_tags)>0
16519+
order by
16520+
yeti_ext.tag_compare(routing_tag_ids, v_call_tags) desc,
16521+
src_area_id is null,
16522+
dst_area_id is null
16523+
limit 1;
1651816524
if found then
1651916525
v_call_tags=yeti_ext.tag_action(v_area_direction.tag_action_id, v_call_tags, v_area_direction.tag_action_value);
1652016526
end if;
@@ -17459,9 +17465,15 @@ CREATE FUNCTION switch15.route_debug(i_node_id integer, i_pop_id integer, i_prot
1745917465

1746017466

1746117467
select into v_area_direction * from class4.routing_tag_detection_rules
17462-
where (src_area_id is null OR src_area_id = v_ret.src_area_id) AND (dst_area_id is null OR dst_area_id=v_ret.dst_area_id)
17463-
order by src_area_id is null, dst_area_id is null
17464-
limit 1;
17468+
where
17469+
(src_area_id is null OR src_area_id = v_ret.src_area_id) AND
17470+
(dst_area_id is null OR dst_area_id=v_ret.dst_area_id) AND
17471+
yeti_ext.tag_compare(routing_tag_ids, v_call_tags)>0
17472+
order by
17473+
yeti_ext.tag_compare(routing_tag_ids, v_call_tags) desc,
17474+
src_area_id is null,
17475+
dst_area_id is null
17476+
limit 1;
1746517477
if found then
1746617478
v_call_tags=yeti_ext.tag_action(v_area_direction.tag_action_id, v_call_tags, v_area_direction.tag_action_value);
1746717479
end if;
@@ -18351,9 +18363,15 @@ CREATE FUNCTION switch15.route_release(i_node_id integer, i_pop_id integer, i_pr
1835118363

1835218364

1835318365
select into v_area_direction * from class4.routing_tag_detection_rules
18354-
where (src_area_id is null OR src_area_id = v_ret.src_area_id) AND (dst_area_id is null OR dst_area_id=v_ret.dst_area_id)
18355-
order by src_area_id is null, dst_area_id is null
18356-
limit 1;
18366+
where
18367+
(src_area_id is null OR src_area_id = v_ret.src_area_id) AND
18368+
(dst_area_id is null OR dst_area_id=v_ret.dst_area_id) AND
18369+
yeti_ext.tag_compare(routing_tag_ids, v_call_tags)>0
18370+
order by
18371+
yeti_ext.tag_compare(routing_tag_ids, v_call_tags) desc,
18372+
src_area_id is null,
18373+
dst_area_id is null
18374+
limit 1;
1835718375
if found then
1835818376
v_call_tags=yeti_ext.tag_action(v_area_direction.tag_action_id, v_call_tags, v_area_direction.tag_action_value);
1835918377
end if;
@@ -19708,9 +19726,9 @@ CREATE TABLE class4.customers_auth (
1970819726
dst_number_max_length smallint DEFAULT 100 NOT NULL,
1970919727
check_account_balance boolean DEFAULT true NOT NULL,
1971019728
require_incoming_auth boolean DEFAULT false NOT NULL,
19729+
dst_number_min_length smallint DEFAULT 0 NOT NULL,
1971119730
tag_action_id smallint,
1971219731
tag_action_value smallint[] DEFAULT '{}'::smallint[] NOT NULL,
19713-
dst_number_min_length smallint DEFAULT 0 NOT NULL,
1971419732
ip inet[] DEFAULT '{127.0.0.0/8}'::inet[],
1971519733
src_prefix character varying[] DEFAULT '{""}'::character varying[],
1971619734
dst_prefix character varying[] DEFAULT '{""}'::character varying[],
@@ -26541,8 +26559,7 @@ ALTER TABLE ONLY sys.sensors
2654126559
-- PostgreSQL database dump complete
2654226560
--
2654326561

26544-
SET search_path TO gui, public, switch, billing, class4, runtime_stats, sys, logs, data_import
26545-
;
26562+
SET search_path TO gui, public, switch, billing, class4, runtime_stats, sys, logs, data_import;
2654626563

2654726564
INSERT INTO public.schema_migrations (version) VALUES ('20170822151410');
2654826565

0 commit comments

Comments
 (0)