]> git.puffer.fish Git - matthieu/frr.git/commitdiff
pimd: Add generic function to retrieve mroute stats
authorDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 13 Jul 2016 15:41:41 +0000 (11:41 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 13 Jul 2016 15:41:41 +0000 (11:41 -0400)
Add a generic function to retrieve mroute statistics
from the kernel.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
pimd/pim_cmd.c
pimd/pim_mroute.c
pimd/pim_mroute.h
pimd/pim_oil.h

index f27e3ff76d7246092872d80231e182f9be352c0d..13cc30527455bcfb56dcdaa04821f31c43234983 100644 (file)
@@ -22,8 +22,6 @@
 
 #include <zebra.h>
 
-#include <sys/ioctl.h>
-
 #include "command.h"
 #include "if.h"
 #include "prefix.h"
@@ -2309,37 +2307,21 @@ static void show_mroute_count(struct vty *vty)
   for (ALL_LIST_ELEMENTS_RO(qpim_channel_oil_list, node, c_oil)) {
     char group_str[100]; 
     char source_str[100];
-    struct sioc_sg_req sgreq;
 
     if (!c_oil->installed)
       continue;
 
-    memset(&sgreq, 0, sizeof(sgreq));
-    sgreq.src = c_oil->oil.mfcc_origin;
-    sgreq.grp = c_oil->oil.mfcc_mcastgrp;
+    pim_mroute_update_counters (c_oil);
 
     pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
     pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str, sizeof(source_str));
 
-    if (ioctl(qpim_mroute_socket_fd, SIOCGETSGCNT, &sgreq)) {
-      int e = errno;
-      vty_out(vty,
-             "ioctl(SIOCGETSGCNT=%lu) failure for (S,G)=(%s,%s): errno=%d: %s%s",
-             (unsigned long)SIOCGETSGCNT,
-             source_str,
-             group_str,
-             e,
-             safe_strerror(e),
-             VTY_NEWLINE);           
-      continue;
-    }
-    
     vty_out(vty, "%-15s %-15s %7ld %10ld %7ld %s",
            source_str,
            group_str,
-           sgreq.pktcnt,
-           sgreq.bytecnt,
-           sgreq.wrong_if,
+           c_oil->cc.pktcnt,
+           c_oil->cc.bytecnt,
+           c_oil->cc.wrong_if,
            VTY_NEWLINE);
   }
 
@@ -2347,40 +2329,21 @@ static void show_mroute_count(struct vty *vty)
   for (ALL_LIST_ELEMENTS_RO(qpim_static_route_list, node, s_route)) {
     char group_str[100];
     char source_str[100];
-    struct sioc_sg_req sgreq;
 
     if (!s_route->c_oil.installed)
       continue;
 
-    memset(&sgreq, 0, sizeof(sgreq));
-    sgreq.src = s_route->c_oil.oil.mfcc_origin;
-    sgreq.grp = s_route->c_oil.oil.mfcc_mcastgrp;
+    pim_mroute_update_counters (&s_route->c_oil);
 
     pim_inet4_dump("<group?>", s_route->c_oil.oil.mfcc_mcastgrp, group_str, sizeof(group_str));
     pim_inet4_dump("<source?>", s_route->c_oil.oil.mfcc_origin, source_str, sizeof(source_str));
 
-    if (ioctl(qpim_mroute_socket_fd, SIOCGETSGCNT, &sgreq)) {
-      int e = errno;
-      vty_out(vty,
-         "ioctl(SIOCGETSGCNT=%lu) failure for (S,G)=(%s,%s): errno=%d: %s%s",
-         /* note that typeof ioctl defs can vary across platforms, from
-          * int, to unsigned int, to long unsigned int
-          */
-         (unsigned long)SIOCGETSGCNT,
-         source_str,
-         group_str,
-         e,
-         safe_strerror(e),
-         VTY_NEWLINE);
-      continue;
-    }
-
     vty_out(vty, "%-15s %-15s %7ld %10ld %7ld %s",
        source_str,
        group_str,
-       sgreq.pktcnt,
-       sgreq.bytecnt,
-       sgreq.wrong_if,
+       s_route->c_oil.cc.pktcnt,
+       s_route->c_oil.cc.bytecnt,
+       s_route->c_oil.cc.wrong_if,
        VTY_NEWLINE);
   }
 }
index 4d9a9d0b7ededb7f6f34f55577b99bfffafa434d..b5463fac599881d000007fa8dce584bc1c574f3e 100644 (file)
@@ -143,6 +143,8 @@ pim_mroute_msg_nocache (int fd, struct interface *ifp, const struct igmpmsg *msg
     return 0;
   }
 
+  pim_upstream_keep_alive_timer_start (up, PIM_KEEPALIVE_PERIOD);
+
   up->channel_oil = pim_channel_oil_add(msg->im_dst,
                                        msg->im_src,
                                        pim_ifp->mroute_vif_index);
@@ -629,3 +631,40 @@ int pim_mroute_del (struct channel_oil *c_oil)
 
   return 0;
 }
+
+void
+pim_mroute_update_counters (struct channel_oil *c_oil)
+{
+  struct sioc_sg_req sgreq;
+
+  memset (&sgreq, 0, sizeof(sgreq));
+  sgreq.src = c_oil->oil.mfcc_origin;
+  sgreq.grp = c_oil->oil.mfcc_mcastgrp;
+
+  c_oil->cc.oldpktcnt = c_oil->cc.pktcnt;
+  c_oil->cc.oldbytecnt = c_oil->cc.bytecnt;
+  c_oil->cc.oldwrong_if = c_oil->cc.wrong_if;
+
+  if (ioctl (qpim_mroute_socket_fd, SIOCGETSGCNT, &sgreq))
+    {
+      char group_str[100];
+      char source_str[100];
+
+      pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
+      pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str, sizeof(source_str));
+
+      zlog_warn ("ioctl(SIOCGETSGCNT=%lu) failure for (S,G)=(%s,%s): errno=%d: %s",
+                (unsigned long)SIOCGETSGCNT,
+                source_str,
+                group_str,
+                errno,
+                safe_strerror(errno));
+      return;
+    }
+
+  c_oil->cc.pktcnt = sgreq.pktcnt;
+  c_oil->cc.bytecnt = sgreq.bytecnt;
+  c_oil->cc.wrong_if = sgreq.wrong_if;
+
+  return;
+}
index 25532614ac9b9c52ef67e51bdfef6b9524cd7e2c..176fb81cbc592a086dc4473810546b75a491f9c0 100644 (file)
@@ -174,4 +174,5 @@ int pim_mroute_del(struct channel_oil *c_oil);
 
 int pim_mroute_msg(int fd, const char *buf, int buf_size);
 
+void pim_mroute_update_counters (struct channel_oil *c_oil);
 #endif /* PIM_MROUTE_H */
index 143f2345f9375164dc286f6520265e7342bd37bf..c63c026c0f29b5f967c91eba2eb02f6c257aa742 100644 (file)
 #define PIM_OIF_PIM_REGISTER_VIF   (MAXVIFS - 1)
 #define PIM_MAX_USABLE_VIFS        (MAXVIFS - 2)
 
+
+struct channel_counts
+{
+  unsigned long pktcnt;
+  unsigned long oldpktcnt;
+  unsigned long bytecnt;
+  unsigned long oldbytecnt;
+  unsigned long wrong_if;
+  unsigned long oldwrong_if;
+};
+
 /*
   qpim_channel_oil_list holds a list of struct channel_oil.
 
@@ -64,6 +75,7 @@ struct channel_oil {
   int           oil_ref_count;
   time_t        oif_creation[MAXVIFS];
   uint32_t      oif_flags[MAXVIFS];
+  struct channel_counts cc;
 };
 
 void pim_channel_oil_free(struct channel_oil *c_oil);