Skip to content

Commit

Permalink
add TX rtp statistics counter rx_srtp_decrypt_errors (#1416)
Browse files Browse the repository at this point in the history
* add TX rtp statistics counter rx_srtp_decrypt_errors
  • Loading branch information
dmitry-sinina authored Jan 22, 2024
1 parent ea7b5e3 commit 37d8964
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 6 deletions.
4 changes: 4 additions & 0 deletions app/admin/cdr/tx_streams.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
:rx_out_of_buffer_errors,
:rx_rtp_parse_errors,
:rx_dropped_packets,
:rx_srtp_decrypt_errors,
:tx_packets,
:tx_bytes,
:tx_ssrc,
Expand Down Expand Up @@ -75,6 +76,7 @@ def scoped_collection
filter :rx_out_of_buffer_errors
filter :rx_rtp_parse_errors
filter :rx_dropped_packets
filter :rx_srtp_decrypt_errors
filter :tx_total_lost
filter :tx_rtcp_jitter_min
filter :tx_rtcp_jitter_max
Expand All @@ -97,6 +99,7 @@ def scoped_collection
column :rx_out_of_buffer_errors
column :rx_rtp_parse_errors
column :rx_dropped_packets
column :rx_srtp_decrypt_errors
column :tx_packets
column :tx_bytes
column :tx_ssrc do |c|
Expand Down Expand Up @@ -129,6 +132,7 @@ def scoped_collection
row :rx_out_of_buffer_errors
row :rx_rtp_parse_errors
row :rx_dropped_packets
row :rx_srtp_decrypt_errors
row :tx_packets
row :tx_bytes
row :tx_ssrc do |c|
Expand Down
1 change: 1 addition & 0 deletions app/models/rtp_statistics/tx_stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# rx_dropped_packets :bigint(8)
# rx_out_of_buffer_errors :bigint(8)
# rx_rtp_parse_errors :bigint(8)
# rx_srtp_decrypt_errors :bigint(8)
# time_end :timestamptz
# time_start :timestamptz not null
# tx_bytes :bigint(8)
Expand Down
241 changes: 241 additions & 0 deletions db/cdr_migrate/20240122201619_add_rx_srtp_decrypt_errors_counter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
class AddRxSrtpDecryptErrorsCounter < ActiveRecord::Migration[7.0]
def up
execute %q{
alter table rtp_statistics.tx_streams add rx_srtp_decrypt_errors bigint;
alter type rtp_statistics.tx_stream_ty add attribute rx_srtp_decrypt_errors bigint;
CREATE or replace FUNCTION switch.write_rtp_statistics(i_data json, i_pop_id integer, i_node_id integer, i_lega_gateway_id bigint, i_lega_gateway_external_id bigint, i_legb_gateway_id bigint, i_legb_gateway_external_id bigint, i_lega_local_tag character varying, i_legb_local_tag character varying) RETURNS void
LANGUAGE plpgsql SECURITY DEFINER COST 10
AS $$
DECLARE
v_rx rtp_statistics.rx_stream_ty;
v_tx_stream rtp_statistics.tx_stream_ty;
v_rtp_rx_stream_data rtp_statistics.rx_streams%rowtype;
v_rtp_tx_stream_data rtp_statistics.tx_streams%rowtype;
BEGIN
if i_data is null or json_array_length(i_data)=0 then
return;
end if;
for v_tx_stream IN select * from json_populate_recordset(null::rtp_statistics.tx_stream_ty,i_data) LOOP
if v_tx_stream.local_tag = i_lega_local_tag then
-- legA stream
v_rtp_tx_stream_data.gateway_id = i_lega_gateway_id;
v_rtp_tx_stream_data.gateway_external_id = i_lega_gateway_external_id;
elsif v_tx_stream.local_tag = i_legb_local_tag then
-- legb stream
v_rtp_tx_stream_data.gateway_id = i_legb_gateway_id;
v_rtp_tx_stream_data.gateway_external_id = i_legb_gateway_external_id;
else
-- unknown stream
end if;
v_rtp_tx_stream_data.id=nextval('rtp_statistics.tx_streams_id_seq'::regclass);
v_rtp_tx_stream_data.pop_id=i_pop_id;
v_rtp_tx_stream_data.node_id=i_node_id;
v_rtp_tx_stream_data.local_tag=v_tx_stream.local_tag;
v_rtp_tx_stream_data.time_start=to_timestamp(v_tx_stream.time_start);
v_rtp_tx_stream_data.time_end=to_timestamp(v_tx_stream.time_end);
v_rtp_tx_stream_data.rtcp_rtt_min=v_tx_stream.rtcp_rtt_min;
v_rtp_tx_stream_data.rtcp_rtt_max=v_tx_stream.rtcp_rtt_max;
v_rtp_tx_stream_data.rtcp_rtt_mean=v_tx_stream.rtcp_rtt_mean;
v_rtp_tx_stream_data.rtcp_rtt_std=v_tx_stream.rtcp_rtt_std;
v_rtp_tx_stream_data.rx_out_of_buffer_errors=v_tx_stream.rx_out_of_buffer_errors;
v_rtp_tx_stream_data.rx_rtp_parse_errors=v_tx_stream.rx_rtp_parse_errors;
v_rtp_tx_stream_data.rx_dropped_packets=v_tx_stream.rx_dropped_packets;
v_rtp_tx_stream_data.rx_srtp_decrypt_errors = v_tx_stream.rx_srtp_decrypt_errors;
v_rtp_tx_stream_data.tx_packets=v_tx_stream.tx_packets;
v_rtp_tx_stream_data.tx_bytes=v_tx_stream.tx_bytes;
v_rtp_tx_stream_data.tx_ssrc=v_tx_stream.tx_ssrc;
v_rtp_tx_stream_data.local_host=v_tx_stream.local_host;
v_rtp_tx_stream_data.local_port=v_tx_stream.local_port;
v_rtp_tx_stream_data.tx_total_lost=v_tx_stream.tx_total_lost;
v_rtp_tx_stream_data.tx_payloads_transcoded=string_to_array(v_tx_stream.tx_payloads_transcoded,',');
v_rtp_tx_stream_data.tx_payloads_relayed=string_to_array(v_tx_stream.tx_payloads_relayed,',');
v_rtp_tx_stream_data.tx_rtcp_jitter_min=v_tx_stream.tx_rtcp_jitter_min;
v_rtp_tx_stream_data.tx_rtcp_jitter_max=v_tx_stream.tx_rtcp_jitter_max;
v_rtp_tx_stream_data.tx_rtcp_jitter_mean=v_tx_stream.tx_rtcp_jitter_mean;
v_rtp_tx_stream_data.tx_rtcp_jitter_std=v_tx_stream.tx_rtcp_jitter_std;
INSERT INTO rtp_statistics.tx_streams VALUES(v_rtp_tx_stream_data.*);
PERFORM event.rtp_streams_insert_event('rtp_tx_stream', v_rtp_tx_stream_data);
FOREACH v_rx IN ARRAY v_tx_stream.rx LOOP
v_rtp_rx_stream_data = NULL;
v_rtp_rx_stream_data.id=nextval('rtp_statistics.rx_streams_id_seq'::regclass);
v_rtp_rx_stream_data.tx_stream_id = v_rtp_tx_stream_data.id;
v_rtp_rx_stream_data.time_start = v_rtp_tx_stream_data.time_start;
v_rtp_rx_stream_data.time_end = v_rtp_tx_stream_data.time_end;
v_rtp_rx_stream_data.pop_id=v_rtp_tx_stream_data.pop_id;
v_rtp_rx_stream_data.node_id=v_rtp_tx_stream_data.node_id;
v_rtp_rx_stream_data.gateway_id=v_rtp_tx_stream_data.gateway_id;
v_rtp_rx_stream_data.gateway_external_id=v_rtp_tx_stream_data.gateway_external_id;
v_rtp_rx_stream_data.local_tag=v_tx_stream.local_tag;
v_rtp_rx_stream_data.rx_ssrc=v_rx.rx_ssrc;
-- local socket info from TX stream
v_rtp_rx_stream_data.local_host = v_tx_stream.local_host;
v_rtp_rx_stream_data.remote_port = v_tx_stream.local_port;
v_rtp_rx_stream_data.remote_host=v_rx.remote_host;
v_rtp_rx_stream_data.remote_port=v_rx.remote_port;
v_rtp_rx_stream_data.rx_packets=v_rx.rx_packets;
v_rtp_rx_stream_data.rx_bytes=v_rx.rx_bytes;
v_rtp_rx_stream_data.rx_total_lost=v_rx.rx_total_lost;
v_rtp_rx_stream_data.rx_payloads_transcoded=string_to_array(v_rx.rx_payloads_transcoded,',');
v_rtp_rx_stream_data.rx_payloads_relayed=string_to_array(v_rx.rx_payloads_relayed,',');
v_rtp_rx_stream_data.rx_decode_errors=v_rx.rx_decode_errors;
v_rtp_rx_stream_data.rx_packet_delta_min=v_rx.rx_packet_delta_min;
v_rtp_rx_stream_data.rx_packet_delta_max=v_rx.rx_packet_delta_max;
v_rtp_rx_stream_data.rx_packet_delta_mean=v_rx.rx_packet_delta_mean;
v_rtp_rx_stream_data.rx_packet_delta_std=v_rx.rx_packet_delta_std;
v_rtp_rx_stream_data.rx_packet_jitter_min=v_rx.rx_packet_jitter_min;
v_rtp_rx_stream_data.rx_packet_jitter_max=v_rx.rx_packet_jitter_max;
v_rtp_rx_stream_data.rx_packet_jitter_mean=v_rx.rx_packet_jitter_mean;
v_rtp_rx_stream_data.rx_packet_jitter_std=v_rx.rx_packet_jitter_std;
v_rtp_rx_stream_data.rx_rtcp_jitter_min=v_rx.rx_rtcp_jitter_min;
v_rtp_rx_stream_data.rx_rtcp_jitter_max=v_rx.rx_rtcp_jitter_max;
v_rtp_rx_stream_data.rx_rtcp_jitter_mean=v_rx.rx_rtcp_jitter_mean;
v_rtp_rx_stream_data.rx_rtcp_jitter_std=v_rx.rx_rtcp_jitter_std;
INSERT INTO rtp_statistics.rx_streams VALUES(v_rtp_rx_stream_data.*);
PERFORM event.rtp_streams_insert_event('rtp_rx_stream', v_rtp_rx_stream_data);
END LOOP;
end loop;
RETURN;
END;
$$;
}
end

def down
execute %q{
CREATE or replace FUNCTION switch.write_rtp_statistics(i_data json, i_pop_id integer, i_node_id integer, i_lega_gateway_id bigint, i_lega_gateway_external_id bigint, i_legb_gateway_id bigint, i_legb_gateway_external_id bigint, i_lega_local_tag character varying, i_legb_local_tag character varying) RETURNS void
LANGUAGE plpgsql SECURITY DEFINER COST 10
AS $$
DECLARE
v_rx rtp_statistics.rx_stream_ty;
v_tx_stream rtp_statistics.tx_stream_ty;
v_rtp_rx_stream_data rtp_statistics.rx_streams%rowtype;
v_rtp_tx_stream_data rtp_statistics.tx_streams%rowtype;
BEGIN
if i_data is null or json_array_length(i_data)=0 then
return;
end if;
for v_tx_stream IN select * from json_populate_recordset(null::rtp_statistics.tx_stream_ty,i_data) LOOP
if v_tx_stream.local_tag = i_lega_local_tag then
-- legA stream
v_rtp_tx_stream_data.gateway_id = i_lega_gateway_id;
v_rtp_tx_stream_data.gateway_external_id = i_lega_gateway_external_id;
elsif v_tx_stream.local_tag = i_legb_local_tag then
-- legb stream
v_rtp_tx_stream_data.gateway_id = i_legb_gateway_id;
v_rtp_tx_stream_data.gateway_external_id = i_legb_gateway_external_id;
else
-- unknown stream
end if;
v_rtp_tx_stream_data.id=nextval('rtp_statistics.tx_streams_id_seq'::regclass);
v_rtp_tx_stream_data.pop_id=i_pop_id;
v_rtp_tx_stream_data.node_id=i_node_id;
v_rtp_tx_stream_data.local_tag=v_tx_stream.local_tag;
v_rtp_tx_stream_data.time_start=to_timestamp(v_tx_stream.time_start);
v_rtp_tx_stream_data.time_end=to_timestamp(v_tx_stream.time_end);
v_rtp_tx_stream_data.rtcp_rtt_min=v_tx_stream.rtcp_rtt_min;
v_rtp_tx_stream_data.rtcp_rtt_max=v_tx_stream.rtcp_rtt_max;
v_rtp_tx_stream_data.rtcp_rtt_mean=v_tx_stream.rtcp_rtt_mean;
v_rtp_tx_stream_data.rtcp_rtt_std=v_tx_stream.rtcp_rtt_std;
v_rtp_tx_stream_data.rx_out_of_buffer_errors=v_tx_stream.rx_out_of_buffer_errors;
v_rtp_tx_stream_data.rx_rtp_parse_errors=v_tx_stream.rx_rtp_parse_errors;
v_rtp_tx_stream_data.rx_dropped_packets=v_tx_stream.rx_dropped_packets;
v_rtp_tx_stream_data.tx_packets=v_tx_stream.tx_packets;
v_rtp_tx_stream_data.tx_bytes=v_tx_stream.tx_bytes;
v_rtp_tx_stream_data.tx_ssrc=v_tx_stream.tx_ssrc;
v_rtp_tx_stream_data.local_host=v_tx_stream.local_host;
v_rtp_tx_stream_data.local_port=v_tx_stream.local_port;
v_rtp_tx_stream_data.tx_total_lost=v_tx_stream.tx_total_lost;
v_rtp_tx_stream_data.tx_payloads_transcoded=string_to_array(v_tx_stream.tx_payloads_transcoded,',');
v_rtp_tx_stream_data.tx_payloads_relayed=string_to_array(v_tx_stream.tx_payloads_relayed,',');
v_rtp_tx_stream_data.tx_rtcp_jitter_min=v_tx_stream.tx_rtcp_jitter_min;
v_rtp_tx_stream_data.tx_rtcp_jitter_max=v_tx_stream.tx_rtcp_jitter_max;
v_rtp_tx_stream_data.tx_rtcp_jitter_mean=v_tx_stream.tx_rtcp_jitter_mean;
v_rtp_tx_stream_data.tx_rtcp_jitter_std=v_tx_stream.tx_rtcp_jitter_std;
INSERT INTO rtp_statistics.tx_streams VALUES(v_rtp_tx_stream_data.*);
PERFORM event.rtp_streams_insert_event('rtp_tx_stream', v_rtp_tx_stream_data);
FOREACH v_rx IN ARRAY v_tx_stream.rx LOOP
v_rtp_rx_stream_data = NULL;
v_rtp_rx_stream_data.id=nextval('rtp_statistics.rx_streams_id_seq'::regclass);
v_rtp_rx_stream_data.tx_stream_id = v_rtp_tx_stream_data.id;
v_rtp_rx_stream_data.time_start = v_rtp_tx_stream_data.time_start;
v_rtp_rx_stream_data.time_end = v_rtp_tx_stream_data.time_end;
v_rtp_rx_stream_data.pop_id=v_rtp_tx_stream_data.pop_id;
v_rtp_rx_stream_data.node_id=v_rtp_tx_stream_data.node_id;
v_rtp_rx_stream_data.gateway_id=v_rtp_tx_stream_data.gateway_id;
v_rtp_rx_stream_data.gateway_external_id=v_rtp_tx_stream_data.gateway_external_id;
v_rtp_rx_stream_data.local_tag=v_tx_stream.local_tag;
v_rtp_rx_stream_data.rx_ssrc=v_rx.rx_ssrc;
-- local socket info from TX stream
v_rtp_rx_stream_data.local_host = v_tx_stream.local_host;
v_rtp_rx_stream_data.remote_port = v_tx_stream.local_port;
v_rtp_rx_stream_data.remote_host=v_rx.remote_host;
v_rtp_rx_stream_data.remote_port=v_rx.remote_port;
v_rtp_rx_stream_data.rx_packets=v_rx.rx_packets;
v_rtp_rx_stream_data.rx_bytes=v_rx.rx_bytes;
v_rtp_rx_stream_data.rx_total_lost=v_rx.rx_total_lost;
v_rtp_rx_stream_data.rx_payloads_transcoded=string_to_array(v_rx.rx_payloads_transcoded,',');
v_rtp_rx_stream_data.rx_payloads_relayed=string_to_array(v_rx.rx_payloads_relayed,',');
v_rtp_rx_stream_data.rx_decode_errors=v_rx.rx_decode_errors;
v_rtp_rx_stream_data.rx_packet_delta_min=v_rx.rx_packet_delta_min;
v_rtp_rx_stream_data.rx_packet_delta_max=v_rx.rx_packet_delta_max;
v_rtp_rx_stream_data.rx_packet_delta_mean=v_rx.rx_packet_delta_mean;
v_rtp_rx_stream_data.rx_packet_delta_std=v_rx.rx_packet_delta_std;
v_rtp_rx_stream_data.rx_packet_jitter_min=v_rx.rx_packet_jitter_min;
v_rtp_rx_stream_data.rx_packet_jitter_max=v_rx.rx_packet_jitter_max;
v_rtp_rx_stream_data.rx_packet_jitter_mean=v_rx.rx_packet_jitter_mean;
v_rtp_rx_stream_data.rx_packet_jitter_std=v_rx.rx_packet_jitter_std;
v_rtp_rx_stream_data.rx_rtcp_jitter_min=v_rx.rx_rtcp_jitter_min;
v_rtp_rx_stream_data.rx_rtcp_jitter_max=v_rx.rx_rtcp_jitter_max;
v_rtp_rx_stream_data.rx_rtcp_jitter_mean=v_rx.rx_rtcp_jitter_mean;
v_rtp_rx_stream_data.rx_rtcp_jitter_std=v_rx.rx_rtcp_jitter_std;
INSERT INTO rtp_statistics.rx_streams VALUES(v_rtp_rx_stream_data.*);
PERFORM event.rtp_streams_insert_event('rtp_rx_stream', v_rtp_rx_stream_data);
END LOOP;
end loop;
RETURN;
END;
$$;
alter table rtp_statistics.tx_streams drop column rx_srtp_decrypt_errors;
alter type rtp_statistics.tx_stream_ty drop attribute rx_srtp_decrypt_errors;
}
end
end
10 changes: 7 additions & 3 deletions db/cdr_structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ CREATE TYPE rtp_statistics.tx_stream_ty AS (
tx_rtcp_jitter_max real,
tx_rtcp_jitter_mean real,
tx_rtcp_jitter_std real,
rx rtp_statistics.rx_stream_ty[]
rx rtp_statistics.rx_stream_ty[],
rx_srtp_decrypt_errors bigint
);


Expand Down Expand Up @@ -1015,6 +1016,7 @@ BEGIN
v_rtp_tx_stream_data.rx_out_of_buffer_errors=v_tx_stream.rx_out_of_buffer_errors;
v_rtp_tx_stream_data.rx_rtp_parse_errors=v_tx_stream.rx_rtp_parse_errors;
v_rtp_tx_stream_data.rx_dropped_packets=v_tx_stream.rx_dropped_packets;
v_rtp_tx_stream_data.rx_srtp_decrypt_errors = v_tx_stream.rx_srtp_decrypt_errors;
v_rtp_tx_stream_data.tx_packets=v_tx_stream.tx_packets;
v_rtp_tx_stream_data.tx_bytes=v_tx_stream.tx_bytes;
v_rtp_tx_stream_data.tx_ssrc=v_tx_stream.tx_ssrc;
Expand Down Expand Up @@ -3367,7 +3369,8 @@ CREATE TABLE rtp_statistics.tx_streams (
tx_rtcp_jitter_min real,
tx_rtcp_jitter_max real,
tx_rtcp_jitter_mean real,
tx_rtcp_jitter_std real
tx_rtcp_jitter_std real,
rx_srtp_decrypt_errors bigint
)
PARTITION BY RANGE (time_start);

Expand Down Expand Up @@ -4863,6 +4866,7 @@ INSERT INTO "public"."schema_migrations" (version) VALUES
('20231106100135'),
('20231106125344'),
('20231212213111'),
('20231231115209');
('20231231115209'),
('20240122201619');


1 change: 1 addition & 0 deletions spec/features/cdr/rtp_tx_streams/export_tx_streams_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
['Rx out of buffer errors', item.rx_out_of_buffer_errors.to_s],
['Rx rtp parse errors', item.rx_rtp_parse_errors.to_s],
['Rx dropped packets', item.rx_dropped_packets.to_s],
['Rx srtp decrypt errors', item.rx_srtp_decrypt_errors.to_s],
['Tx packets', item.tx_packets.to_s],
['Tx bytes', item.tx_bytes.to_s],
['Tx ssrc', item.tx_ssrc.to_s],
Expand Down
10 changes: 7 additions & 3 deletions spec/sql/switch/write_rtp_statistics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
"rtcp_rtt_std": 0.76767676,
"time_start": 10.seconds.ago.to_f,
"time_end": Time.now.to_f,
"rx_out_of_buffer_errors": 0,
"rx_rtp_parse_errors": 0,
"rx_dropped_packets": 0,
"rx_out_of_buffer_errors": 1,
"rx_rtp_parse_errors": 12,
"rx_dropped_packets": 11,
"rx_srtp_decrypt_errors": 150,
"rx": [
{
"rx_ssrc": 267_906_310,
Expand Down Expand Up @@ -79,6 +80,7 @@
"rx_out_of_buffer_errors": 0,
"rx_rtp_parse_errors": 0,
"rx_dropped_packets": 0,
"rx_srtp_decrypt_errors": 10,
"rx": [
{
"rx_ssrc": 267_906_310,
Expand Down Expand Up @@ -129,6 +131,7 @@
"rx_out_of_buffer_errors": 0,
"rx_rtp_parse_errors": 0,
"rx_dropped_packets": 0,
"rx_srtp_decrypt_errors": 8,
"rx": [
{
"rx_ssrc": 1_458_718_330,
Expand Down Expand Up @@ -178,6 +181,7 @@
"rx_out_of_buffer_errors": 0,
"rx_rtp_parse_errors": 0,
"rx_dropped_packets": 0,
"rx_srtp_decrypt_errors": 1,
"rx": [
{
"rx_ssrc": 1_458_718_330,
Expand Down

0 comments on commit 37d8964

Please sign in to comment.