Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dockers/docker-fpm-frr/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
7 changes: 6 additions & 1 deletion dockers/docker-fpm-frr/TSA
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ then
case "$route_map_name" in
*V4*)
ip_version=V4
ip_protocol=ip
;;
*V6*)
ip_version=V6
ip_protocol=ipv6
;;
*)
continue
;;
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
Expand Down
9 changes: 9 additions & 0 deletions dockers/docker-fpm-frr/TSB
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 4 additions & 1 deletion dockers/docker-fpm-frr/base_image_files/TSC
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
@@ -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
!
62 changes: 62 additions & 0 deletions dockers/docker-fpm-frr/total_portstat.py
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
}
},
"route_map_name": "test_rm_name",
"ip_version": "V4"
"ip_version": "V4",
"ip_protocol": "ip"
}