Updates to snmp
authorMichael Spang <mspang@uwaterloo.ca>
Sat, 9 May 2009 04:41:34 +0000 (00:41 -0400)
committerMichael Spang <mspang@uwaterloo.ca>
Sat, 9 May 2009 04:41:34 +0000 (00:41 -0400)
CSC-MIB.txt
cscMIB.c [new file with mode: 0644]
cscMIB.h [new file with mode: 0644]
mib-tc-stats.c
mib-tc-stats.h
mib-tc-test.c [new file with mode: 0644]

index a93416c..97a314d 100644 (file)
@@ -23,32 +23,24 @@ cscMIB MODULE-IDENTITY
     DESCRIPTION  "Initial revision"
     ::= { csclub 2 }
 
     DESCRIPTION  "Initial revision"
     ::= { csclub 2 }
 
-netsched OBJECT IDENTIFIER ::= { cscMIB 2 }
-
-classTable OBJECT-TYPE
-    SYNTAX      SEQUENCE OF ClassEntry
-    MAX-ACCESS  not-accessible
-    ::= { netsched 1 }
-
-classEntry OBJECT-TYPE
-    SYNTAX      ClassEntry
-    MAX-ACCESS  not-accessible
-    INDEX       { ClassIndex }
-    ::= { classTable 1 }
-
-ClassEntry ::=
-    SEQUENCE {
-        classIndex              Integer32,
-        classOutOctets          Counter64,
-    }
-
-classIndex OBJECT-TYPE
-    SYNTAX      Integer32
+mirror OBJECT IDENTIFIER ::= { cscMIB 2 }
+
+cogentBytes OBJECT-TYPE
+    SYNTAX      Counter64
+    MAX-ACCESS  read-only
+    STATUS      current
+    ::= { mirror 1 }
+
+orionBytes OBJECT-TYPE
+    SYNTAX      Counter64
     MAX-ACCESS  read-only
     STATUS      current
     MAX-ACCESS  read-only
     STATUS      current
-    ::= { classEntry 1 }
+    ::= { mirror 2 }
 
 
-classOutOctets OBJECT-TYPE
+campusBytes OBJECT-TYPE
     SYNTAX      Counter64
     MAX-ACCESS  read-only
     SYNTAX      Counter64
     MAX-ACCESS  read-only
-    ::= { classEntry 2 }
+    STATUS      current
+    ::= { mirror 3 }
+
+END
diff --git a/cscMIB.c b/cscMIB.c
new file mode 100644 (file)
index 0000000..663ed84
--- /dev/null
+++ b/cscMIB.c
@@ -0,0 +1,103 @@
+/*
+ * Note: this file originally auto-generated by mib2c using
+ *        : mib2c.scalar.conf 11805 2005-01-07 09:37:18Z dts12 $
+ */
+
+#include <net-snmp/net-snmp-config.h>
+#include <net-snmp/net-snmp-includes.h>
+#include <net-snmp/agent/net-snmp-agent-includes.h>
+#include "cscMIB.h"
+#include "mib-tc-stats.h"
+
+/** Initializes the cscMIB module */
+void
+init_cscMIB(void)
+{
+    static oid      cogentBytes_oid[] =
+        { 1, 3, 6, 1, 4, 1, 27934, 2, 2, 1 };
+    static oid      orionBytes_oid[] =
+        { 1, 3, 6, 1, 4, 1, 27934, 2, 2, 2 };
+    static oid      campusBytes_oid[] =
+        { 1, 3, 6, 1, 4, 1, 27934, 2, 2, 3 };
+
+    DEBUGMSGTL(("cscMIB", "Initializing\n"));
+
+    netsnmp_register_scalar(netsnmp_create_handler_registration
+                            ("cogentBytes", handle_cogentBytes,
+                             cogentBytes_oid, OID_LENGTH(cogentBytes_oid),
+                             HANDLER_CAN_RONLY));
+    netsnmp_register_scalar(netsnmp_create_handler_registration
+                            ("orionBytes", handle_orionBytes,
+                             orionBytes_oid, OID_LENGTH(orionBytes_oid),
+                             HANDLER_CAN_RONLY));
+    netsnmp_register_scalar(netsnmp_create_handler_registration
+                            ("campusBytes", handle_campusBytes,
+                             campusBytes_oid, OID_LENGTH(campusBytes_oid),
+                             HANDLER_CAN_RONLY));
+}
+
+int
+handle_cogentBytes(netsnmp_mib_handler *handler,
+                   netsnmp_handler_registration *reginfo,
+                   netsnmp_agent_request_info *reqinfo,
+                   netsnmp_request_info *requests)
+{
+    uint64_t bytes;
+    mirror_stats_refresh();
+    bytes = get_class_byte_count(&cogent_class);
+
+    switch (reqinfo->mode) {
+        case MODE_GET:
+            snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER64,
+                    (u_char *)&bytes, sizeof(bytes));
+            break;
+        default:
+            die("unknown mode");
+    }
+
+    return SNMP_ERR_NOERROR;
+}
+
+int
+handle_orionBytes(netsnmp_mib_handler *handler,
+                  netsnmp_handler_registration *reginfo,
+                  netsnmp_agent_request_info *reqinfo,
+                  netsnmp_request_info *requests)
+{
+    uint64_t bytes;
+    mirror_stats_refresh();
+    bytes = get_class_byte_count(&orion_class);
+
+    switch (reqinfo->mode) {
+        case MODE_GET:
+            snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER64,
+                    (u_char *)&bytes, sizeof(bytes));
+            break;
+        default:
+            die("unknown mode");
+    }
+
+    return SNMP_ERR_NOERROR;
+}
+
+int
+handle_campusBytes(netsnmp_mib_handler *handler,
+                   netsnmp_handler_registration *reginfo,
+                   netsnmp_agent_request_info *reqinfo,
+                   netsnmp_request_info *requests)
+{
+    uint64_t bytes;
+    mirror_stats_refresh();
+    bytes = get_class_byte_count(&campus_class);
+
+    switch (reqinfo->mode) {
+        case MODE_GET:
+            snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER64,
+                    (u_char *)&bytes, sizeof(bytes));
+            break;
+        default:
+            die("unknown mode");
+    }
+
+    return SNMP_ERR_NOERROR;
+}
diff --git a/cscMIB.h b/cscMIB.h
new file mode 100644 (file)
index 0000000..63a036c
--- /dev/null
+++ b/cscMIB.h
@@ -0,0 +1,16 @@
+/*
+ * Note: this file originally auto-generated by mib2c using
+ *        : mib2c.scalar.conf 11805 2005-01-07 09:37:18Z dts12 $
+ */
+#ifndef CSCMIB_H
+#define CSCMIB_H
+
+/*
+ * function declarations 
+ */
+void            init_cscMIB(void);
+Netsnmp_Node_Handler handle_cogentBytes;
+Netsnmp_Node_Handler handle_orionBytes;
+Netsnmp_Node_Handler handle_campusBytes;
+
+#endif                          /* CSCMIB_H */
index 32e2f2d..b01a98e 100644 (file)
@@ -8,16 +8,12 @@
 #include <netlink/route/link.h>
 #include <netlink/cache-api.h>
 #include <netlink/object.h>
 #include <netlink/route/link.h>
 #include <netlink/cache-api.h>
 #include <netlink/object.h>
+#include "mib-tc-stats.h"
 
 static struct nl_cache *link_cache, *class_cache;
 static struct rtnl_link *eth;
 static int ifindex;
 
 
 static struct nl_cache *link_cache, *class_cache;
 static struct rtnl_link *eth;
 static int ifindex;
 
-struct class_info {
-    char *name;
-    char *id;
-};
-
 struct class_info cogent_class = { "cogent", "01:02", };
 struct class_info orion_class  = { "orion",  "01:03", };
 struct class_info campus_class = { "campus", "01:04", };
 struct class_info cogent_class = { "cogent", "01:02", };
 struct class_info orion_class  = { "orion",  "01:03", };
 struct class_info campus_class = { "campus", "01:04", };
@@ -104,13 +100,3 @@ void mirror_stats_cleanup(void) {
     nl_handle_destroy(nl_handle);
 }
 
     nl_handle_destroy(nl_handle);
 }
 
-int main(int argc, char *argv[]) {
-    mirror_stats_initialize();
-    for (;;) {
-        printf("%s %"PRIu64"\n", cogent_class.id, get_class_byte_count(&cogent_class));
-        printf("%s %"PRIu64"\n", orion_class.id, get_class_byte_count(&orion_class));
-        printf("%s %"PRIu64"\n", campus_class.id, get_class_byte_count(&campus_class));
-        sleep(1);
-        mirror_stats_refresh();
-    }
-}
index 463244f..53add1a 100644 (file)
@@ -9,7 +9,11 @@
 #include <netlink/cache-api.h>
 #include <netlink/object.h>
 
 #include <netlink/cache-api.h>
 #include <netlink/object.h>
 
-struct class_info;
+struct class_info {
+    char *name;
+    char *id;
+};
+
 extern struct class_info cogent_class;
 extern struct class_info orion_class;
 extern struct class_info campus_class;
 extern struct class_info cogent_class;
 extern struct class_info orion_class;
 extern struct class_info campus_class;
@@ -17,5 +21,5 @@ extern struct class_info campus_class;
 void mirror_stats_refresh(void);
 void mirror_stats_initialize(void);
 void mirror_stats_cleanup(void);
 void mirror_stats_refresh(void);
 void mirror_stats_initialize(void);
 void mirror_stats_cleanup(void);
-void die(char *);
+void die(const char *);
 uint64_t get_class_byte_count(struct class_info *);
 uint64_t get_class_byte_count(struct class_info *);
diff --git a/mib-tc-test.c b/mib-tc-test.c
new file mode 100644 (file)
index 0000000..aeaa2e8
--- /dev/null
@@ -0,0 +1,12 @@
+#include "mib-tc-stats.h"
+
+int main(int argc, char *argv[]) {
+    mirror_stats_initialize();
+    for (;;) {
+        printf("%s %"PRIu64"\n", cogent_class.id, get_class_byte_count(&cogent_class));
+        printf("%s %"PRIu64"\n", orion_class.id, get_class_byte_count(&orion_class));
+        printf("%s %"PRIu64"\n", campus_class.id, get_class_byte_count(&campus_class));
+        sleep(1);
+        mirror_stats_refresh();
+    }
+}