From abbab7118cf9e364d0e8bfb3ca9cb35b006926ce Mon Sep 17 00:00:00 2001 From: Lwithwma Brahma Date: Wed, 20 Oct 2021 10:50:22 +0530 Subject: [PATCH] mcastmngr: correct stats output Corrected the read_mcast_stats function, to display "ubus call mcast stats" correct output for multiple iptv bridges Test: "ubus call mcast stats" showing correct output for both single and multiple bridge. --- .../files/broadcom/usr/libexec/rpcd/mcast | 26 ++++++------------- mcastmngr/files/linux/usr/libexec/rpcd/mcast | 26 ++++++------------- 2 files changed, 16 insertions(+), 36 deletions(-) diff --git a/mcastmngr/files/broadcom/usr/libexec/rpcd/mcast b/mcastmngr/files/broadcom/usr/libexec/rpcd/mcast index b6ab92bd4..b568df64d 100755 --- a/mcastmngr/files/broadcom/usr/libexec/rpcd/mcast +++ b/mcastmngr/files/broadcom/usr/libexec/rpcd/mcast @@ -64,23 +64,11 @@ read_mcast_stats() { json_init json_add_array "snooping" - json_add_object "" IFS=" " for intf in $ifaces; do - while read line; do - # reading each line - case $line in - br-*) - snoop_iface="$(echo $line | awk -F ' ' '{ print $1 }')" - if [ "$snoop_iface" != "$intf" ]; then - continue - fi - json_add_string "interface" "$intf" - json_add_array "groups" - break - ;; - esac - done < /tmp/igmp_stats + json_add_object "" + json_add_string "interface" "$intf" + json_add_array "groups" IFS=" " for gip_addr in $mcast_addrs; do grp_obj_added=0 @@ -116,12 +104,14 @@ read_mcast_stats() { ;; esac done < /tmp/igmp_stats - json_close_array #close the associated devices array - json_close_object # close the groups object + if [ $grp_obj_added -eq 1 ]; then + json_close_array #close the associated devices array + json_close_object # close the groups object + fi done # close the loop for group addresses json_close_array #close the groups array + json_close_object # close the snooping object done # close the loop for interfaces - json_close_object # close the snooping object json_close_array # close the snooping array json_dump diff --git a/mcastmngr/files/linux/usr/libexec/rpcd/mcast b/mcastmngr/files/linux/usr/libexec/rpcd/mcast index 62b399a4d..62c85bbce 100755 --- a/mcastmngr/files/linux/usr/libexec/rpcd/mcast +++ b/mcastmngr/files/linux/usr/libexec/rpcd/mcast @@ -85,23 +85,11 @@ read_mcast_stats() { json_init json_add_array "snooping" - json_add_object "" IFS=" " for intf in $ifaces; do - while read line; do - # reading each line - case $line in - br-*) - snoop_iface="$(echo $line | awk -F ' ' '{ print $1 }')" - if [ "$snoop_iface" != "$intf" ]; then - continue - fi - json_add_string "interface" "$intf" - json_add_array "groups" - break - ;; - esac - done < "$temp_igmp_file" + json_add_object "" + json_add_string "interface" "$intf" + json_add_array "groups" IFS=" " for gip_addr in $mcast_addrs; do grp_obj_added=0 @@ -137,12 +125,14 @@ read_mcast_stats() { ;; esac done < "$temp_igmp_file" - json_close_array #close the associated devices array - json_close_object # close the groups object + if [ $grp_obj_added -eq 1 ]; then + json_close_array #close the associated devices array + json_close_object # close the groups object + fi done # close the loop for group addresses json_close_array #close the groups array + json_close_object # close the snooping object done # close the loop for interfaces - json_close_object # close the snooping object json_close_array # close the snooping array json_dump