From b78fc66a635cafbaeac14f977e56637c91603133 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Wed, 11 Nov 2020 12:54:47 -0800 Subject: [PATCH 1/7] Fix protocol for ipv6 TSA route-map --- dockers/docker-fpm-frr/TSA | 4 +++- dockers/docker-fpm-frr/frr/bgpd/tsa/bgpd.tsa.isolate.conf.j2 | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dockers/docker-fpm-frr/TSA b/dockers/docker-fpm-frr/TSA index 441765694a4..838579f2045 100755 --- a/dockers/docker-fpm-frr/TSA +++ b/dockers/docker-fpm-frr/TSA @@ -24,12 +24,14 @@ then case "$route_map_name" in *V4*) ip_version=V4 + ip_protocol=ip ;; *V6*) ip_version=V6 + ip_protocol=ipv6 ;; esac - sonic-cfggen -d -a "{\"route_map_name\":\"$route_map_name\", \"ip_version\": \"$ip_version\"}" -y /etc/sonic/constants.yml -t /usr/share/sonic/templates/bgpd/tsa/bgpd.tsa.isolate.conf.j2 > "$TSA_FILE" + sonic-cfggen -d -a "{\"route_map_name\":\"$route_map_name\", \"ip_version\": \"$ip_version\", \"ip_protocol\": \"$ip_protocol\"}" -y /etc/sonic/constants.yml -t /usr/share/sonic/templates/bgpd/tsa/bgpd.tsa.isolate.conf.j2 > "$TSA_FILE" vtysh -f "$TSA_FILE" rm -f "$TSA_FILE" done diff --git a/dockers/docker-fpm-frr/frr/bgpd/tsa/bgpd.tsa.isolate.conf.j2 b/dockers/docker-fpm-frr/frr/bgpd/tsa/bgpd.tsa.isolate.conf.j2 index 88b1c5acb2e..94287bdcd30 100644 --- a/dockers/docker-fpm-frr/frr/bgpd/tsa/bgpd.tsa.isolate.conf.j2 +++ b/dockers/docker-fpm-frr/frr/bgpd/tsa/bgpd.tsa.isolate.conf.j2 @@ -1,5 +1,5 @@ route-map {{ route_map_name }} permit 2 - match ip address prefix-list PL_Loopback{{ ip_version }} + match {{ ip_protocol }} address prefix-list PL_Loopback{{ ip_version }} set community {{ constants.bgp.traffic_shift_community }} route-map {{ route_map_name }} deny 3 ! From d062c612f5d9dc889048a6a84a35713392032fcb Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Wed, 11 Nov 2020 12:59:06 -0800 Subject: [PATCH 2/7] Skip route-maps, which doesn't have V4, or V6 in their names --- dockers/docker-fpm-frr/TSA | 3 +++ dockers/docker-fpm-frr/TSB | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/dockers/docker-fpm-frr/TSA b/dockers/docker-fpm-frr/TSA index 838579f2045..dc96d32c458 100755 --- a/dockers/docker-fpm-frr/TSA +++ b/dockers/docker-fpm-frr/TSA @@ -30,6 +30,9 @@ then ip_version=V6 ip_protocol=ipv6 ;; + *) + continue + ;; esac sonic-cfggen -d -a "{\"route_map_name\":\"$route_map_name\", \"ip_version\": \"$ip_version\", \"ip_protocol\": \"$ip_protocol\"}" -y /etc/sonic/constants.yml -t /usr/share/sonic/templates/bgpd/tsa/bgpd.tsa.isolate.conf.j2 > "$TSA_FILE" vtysh -f "$TSA_FILE" diff --git a/dockers/docker-fpm-frr/TSB b/dockers/docker-fpm-frr/TSB index 84a3c183e65..68eee9c2faf 100755 --- a/dockers/docker-fpm-frr/TSB +++ b/dockers/docker-fpm-frr/TSB @@ -24,6 +24,15 @@ then TSB_FILE=$(mktemp) for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p'); do + case "$route_map_name" in + *V4*) + ;; + *V6*) + ;; + *) + continue + ;; + esac sonic-cfggen -d -a "{\"route_map_name\":\"$route_map_name\"}" -t /usr/share/sonic/templates/bgpd/tsa/bgpd.tsa.unisolate.conf.j2 > "$TSB_FILE" vtysh -f "$TSB_FILE" rm -f "$TSB_FILE" From 544f1eafce142279cc592c92c31ad0ccadb75cd2 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Wed, 11 Nov 2020 14:39:14 -0800 Subject: [PATCH 3/7] Add total_portstat.py which will output total traffic thoough the device for TSC --- dockers/docker-fpm-frr/Dockerfile.j2 | 1 + dockers/docker-fpm-frr/base_image_files/TSC | 5 +- .../base_image_files/total_portstat.py | 62 +++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 dockers/docker-fpm-frr/base_image_files/total_portstat.py diff --git a/dockers/docker-fpm-frr/Dockerfile.j2 b/dockers/docker-fpm-frr/Dockerfile.j2 index ab8b585899f..a5e2682cdaa 100644 --- a/dockers/docker-fpm-frr/Dockerfile.j2 +++ b/dockers/docker-fpm-frr/Dockerfile.j2 @@ -53,6 +53,7 @@ COPY ["snmp.conf", "/etc/snmp/frr.conf"] COPY ["TSA", "/usr/bin/TSA"] COPY ["TSB", "/usr/bin/TSB"] COPY ["TSC", "/usr/bin/TSC"] +COPY ["total_portstat.py", "/usr/bin/total_portstat.py"] COPY ["files/supervisor-proc-exit-listener", "/usr/bin"] COPY ["critical_processes", "/etc/supervisor"] RUN chmod a+x /usr/bin/TSA && \ diff --git a/dockers/docker-fpm-frr/base_image_files/TSC b/dockers/docker-fpm-frr/base_image_files/TSC index b8136ae4f4c..6e606bd3490 100755 --- a/dockers/docker-fpm-frr/base_image_files/TSC +++ b/dockers/docker-fpm-frr/base_image_files/TSC @@ -2,4 +2,7 @@ docker exec -i bgp /usr/bin/TSC -portstat -p 5 +TSC_FILE=$(mktemp) +portstat -p 5 -j > $(TSC_FILE) +python3 /usr/bin/total_portstat.py $(TSC_FILE) +rm -f $(TSC_FILE) \ No newline at end of file diff --git a/dockers/docker-fpm-frr/base_image_files/total_portstat.py b/dockers/docker-fpm-frr/base_image_files/total_portstat.py new file mode 100644 index 00000000000..f2882fb1f9b --- /dev/null +++ b/dockers/docker-fpm-frr/base_image_files/total_portstat.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 + +from __future__ import print_function +import json +import argparse + + +def get_filename(): + """ Read the name of the file from the command line """ + parser = argparse.ArgumentParser() + parser.add_argument('filename') + args = parser.parse_args() + return args.filename + +def get_json(filename): + """ Open the file and parse json from it """ + js = '' + json_started = False + with open(filename) as fp: + for line in fp: + s_line = line.strip() + if s_line == '{': + json_started = True + if json_started: + js += s_line + data = json.loads(js) + return data + +def convert_to_raw(value): + """ + Convert from a value from suffix to raw value + Example: + '1 KB/s' -> 10240.0 + """ + conversion = { + ' MB/s': 1024*1024*10, + ' KB/s': 1024*10, + ' B/s' : 1, + } + for suffix, multiplier in conversion.items(): + if value.endswith(suffix): + no_suffix_value = value.replace(suffix, '') + float_value = float(no_suffix_value) + return float_value * multiplier + raise RuntimeError("Can't convert value '%s'" % value) + +def main(): + """ + Main function. Read the data and output result + """ + filename = get_filename() + data = get_json(filename) + rx_bps_total = 0.0 + tx_bps_total = 0.0 + for _, obj in data.items(): + rx_bps_total += convert_to_raw(obj['RX_BPS']) + tx_bps_total += convert_to_raw(obj['TX_BPS']) + print("Total RX = %d b/s" % int(rx_bps_total)) + print("Total TX = %d b/s" % int(tx_bps_total)) + +if __name__ == '__main__': + main() From a601c93e4e9dce4ebcf668b9afd042bb5632adac Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Thu, 12 Nov 2020 09:51:12 -0800 Subject: [PATCH 4/7] Fix the test --- src/sonic-bgpcfgd/tests/data/sonic-cfggen/tsa/isolate.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/tsa/isolate.json b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/tsa/isolate.json index 708e4013f13..807dfe7e1a0 100644 --- a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/tsa/isolate.json +++ b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/tsa/isolate.json @@ -5,5 +5,6 @@ } }, "route_map_name": "test_rm_name", - "ip_version": "V4" + "ip_version": "V4", + "ip_protocol": "ip" } \ No newline at end of file From 39ba9c966ba8be60c9df8cae40830dbc0c5110a5 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Thu, 12 Nov 2020 12:43:56 -0800 Subject: [PATCH 5/7] Move the file to the correct place --- dockers/docker-fpm-frr/{base_image_files => }/total_portstat.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename dockers/docker-fpm-frr/{base_image_files => }/total_portstat.py (100%) diff --git a/dockers/docker-fpm-frr/base_image_files/total_portstat.py b/dockers/docker-fpm-frr/total_portstat.py similarity index 100% rename from dockers/docker-fpm-frr/base_image_files/total_portstat.py rename to dockers/docker-fpm-frr/total_portstat.py From 82fcc1240b6d0167dba30d39233abefae3b8cb97 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Fri, 13 Nov 2020 09:47:21 -0800 Subject: [PATCH 6/7] Revert "Move the file to the correct place" This reverts commit 39ba9c966ba8be60c9df8cae40830dbc0c5110a5. --- dockers/docker-fpm-frr/{ => base_image_files}/total_portstat.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename dockers/docker-fpm-frr/{ => base_image_files}/total_portstat.py (100%) diff --git a/dockers/docker-fpm-frr/total_portstat.py b/dockers/docker-fpm-frr/base_image_files/total_portstat.py similarity index 100% rename from dockers/docker-fpm-frr/total_portstat.py rename to dockers/docker-fpm-frr/base_image_files/total_portstat.py From f58df6284b1bf9a4eeac76e8b943dfe63c866db1 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Fri, 13 Nov 2020 09:47:47 -0800 Subject: [PATCH 7/7] Revert "Add total_portstat.py which will output total traffic thoough the device for TSC" This reverts commit 544f1eafce142279cc592c92c31ad0ccadb75cd2. --- dockers/docker-fpm-frr/Dockerfile.j2 | 1 - dockers/docker-fpm-frr/base_image_files/TSC | 5 +- .../base_image_files/total_portstat.py | 62 ------------------- 3 files changed, 1 insertion(+), 67 deletions(-) delete mode 100644 dockers/docker-fpm-frr/base_image_files/total_portstat.py diff --git a/dockers/docker-fpm-frr/Dockerfile.j2 b/dockers/docker-fpm-frr/Dockerfile.j2 index a5e2682cdaa..ab8b585899f 100644 --- a/dockers/docker-fpm-frr/Dockerfile.j2 +++ b/dockers/docker-fpm-frr/Dockerfile.j2 @@ -53,7 +53,6 @@ COPY ["snmp.conf", "/etc/snmp/frr.conf"] COPY ["TSA", "/usr/bin/TSA"] COPY ["TSB", "/usr/bin/TSB"] COPY ["TSC", "/usr/bin/TSC"] -COPY ["total_portstat.py", "/usr/bin/total_portstat.py"] COPY ["files/supervisor-proc-exit-listener", "/usr/bin"] COPY ["critical_processes", "/etc/supervisor"] RUN chmod a+x /usr/bin/TSA && \ diff --git a/dockers/docker-fpm-frr/base_image_files/TSC b/dockers/docker-fpm-frr/base_image_files/TSC index 6e606bd3490..b8136ae4f4c 100755 --- a/dockers/docker-fpm-frr/base_image_files/TSC +++ b/dockers/docker-fpm-frr/base_image_files/TSC @@ -2,7 +2,4 @@ docker exec -i bgp /usr/bin/TSC -TSC_FILE=$(mktemp) -portstat -p 5 -j > $(TSC_FILE) -python3 /usr/bin/total_portstat.py $(TSC_FILE) -rm -f $(TSC_FILE) \ No newline at end of file +portstat -p 5 diff --git a/dockers/docker-fpm-frr/base_image_files/total_portstat.py b/dockers/docker-fpm-frr/base_image_files/total_portstat.py deleted file mode 100644 index f2882fb1f9b..00000000000 --- a/dockers/docker-fpm-frr/base_image_files/total_portstat.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env python3 - -from __future__ import print_function -import json -import argparse - - -def get_filename(): - """ Read the name of the file from the command line """ - parser = argparse.ArgumentParser() - parser.add_argument('filename') - args = parser.parse_args() - return args.filename - -def get_json(filename): - """ Open the file and parse json from it """ - js = '' - json_started = False - with open(filename) as fp: - for line in fp: - s_line = line.strip() - if s_line == '{': - json_started = True - if json_started: - js += s_line - data = json.loads(js) - return data - -def convert_to_raw(value): - """ - Convert from a value from suffix to raw value - Example: - '1 KB/s' -> 10240.0 - """ - conversion = { - ' MB/s': 1024*1024*10, - ' KB/s': 1024*10, - ' B/s' : 1, - } - for suffix, multiplier in conversion.items(): - if value.endswith(suffix): - no_suffix_value = value.replace(suffix, '') - float_value = float(no_suffix_value) - return float_value * multiplier - raise RuntimeError("Can't convert value '%s'" % value) - -def main(): - """ - Main function. Read the data and output result - """ - filename = get_filename() - data = get_json(filename) - rx_bps_total = 0.0 - tx_bps_total = 0.0 - for _, obj in data.items(): - rx_bps_total += convert_to_raw(obj['RX_BPS']) - tx_bps_total += convert_to_raw(obj['TX_BPS']) - print("Total RX = %d b/s" % int(rx_bps_total)) - print("Total TX = %d b/s" % int(tx_bps_total)) - -if __name__ == '__main__': - main()