Commits

stingh711  committed e4418aa

add mib for switch

  • Participants
  • Parent commits cbbff75
  • Tags tag_add_all_mibs_for_netbar

Comments (0)

Files changed (6)

File config.properties

 arp.sender.index.3=3
 arp.sender.ip.3=192.168.1.3
 
+#switch QS info data
+switch.number=1
+switch.ip.1=192.168.1.1
+switch.cpu.usage.1=10
+switch.mem.usage.1=30
+switch.broadcast.rate.1=10
+switch.voltage.1=15
+switch.cpu.temperature.1=70
+
+#switch interface table data
+switch.interface.table.number=2
+switch.interface.table.ip.1=192.168.1.1
+switch.interface.table.index.1=1
+switch.interface.table.desc.1=port1
+switch.interface.table.status.1=1
+switch.interface.table.speed.1=2
+switch.interface.table.mac.1=00:13:49:11:11:11
+switch.interface.table.in.1=9859485
+switch.interface.table.out.1=934
+switch.interface.table.ip.2=192.168.1.2
+switch.interface.table.index.2=2
+switch.interface.table.desc.2=port2
+switch.interface.table.status.2=1
+switch.interface.table.speed.2=2
+switch.interface.table.mac.2=00:13:49:11:11:12
+switch.interface.table.in.2=9859486
+switch.interface.table.out.2=453
 
 #traps parameters
 server.ip=172.25.21.69

File src/com/zyxel/enc/netbar/agent/AbstractTableGenerator.java

  * @author sting
  */
 public abstract class AbstractTableGenerator {
-    private MOTableSubIndex[] indexs = new MOTableSubIndex[]{new MOTableSubIndex(SMIConstants.SYNTAX_INTEGER, 1, 1)};
-    private MOTableIndex index = new MOTableIndex(indexs, false);
+    protected MOTableIndex index;
+    
+    public AbstractTableGenerator() {
+        MOTableSubIndex[] indexs = new MOTableSubIndex[]{new MOTableSubIndex(SMIConstants.SYNTAX_INTEGER, 1, 1)};
+        index = new MOTableIndex(indexs, false);
+    }
     
     public DefaultMOTable generateTable(OID oid) {
         DefaultMOTable table = new DefaultMOTable(oid, index, defineColumns());

File src/com/zyxel/enc/netbar/agent/Config.java

 import java.util.Properties;
 
 public class Config {
-	private static Properties properties;
+	private static final Properties properties;
 	static {
 		properties = new Properties();
 		try {
 	public static String get(String name) {
 		return properties.getProperty(name);
 	}
+        
+        public static Integer getInt(String name) {
+            return Integer.valueOf(get(name));
+        }
 }

File src/com/zyxel/enc/netbar/agent/NRrouterMib.java

 import com.zyxel.enc.netbar.agent.generator.FlowTableGenerator;
 import com.zyxel.enc.netbar.agent.generator.InterfaceTableGenerator;
 import com.zyxel.enc.netbar.agent.generator.LanInterfaceTableGenerator;
+import com.zyxel.enc.netbar.agent.generator.SwitchInterfaceTableGenerator;
 import com.zyxel.enc.netbar.agent.generator.TopArpSenderTableGenerator;
 import com.zyxel.enc.netbar.agent.generator.TopologyDeviceTableGenerator;
 import com.zyxel.enc.netbar.agent.generator.TopologyLinkTableGenerator;
     private static final OID oidFlowTable = new OID("1.3.6.1.4.1.890.1.5.17.1.4.1.1");
     private static final OID oidLanInterfaceTable = new OID("1.3.6.1.4.1.890.1.5.17.1.8.1.1");
     private static final OID oidTopArpTable = new OID("1.3.6.1.4.1.890.1.5.17.1.10.1.1.1");
+    private static final OID oidSwitchInterfaceTable = new OID("1.3.6.1.4.1.890.1.5.17.1.11.2.1.1");
+    
+    
     private static long startTime = 0;
 
-    private static String getCurrentTimeAsString() {
+    public static String getCurrentTimeAsString() {
         return new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date());
     }
 
         server.register(createFlowTable(), context);
         server.register(createLanInterfaceTable(), context);
         server.register(createTopArpSenderTable(), context);
+        
+        new SwitchDataHelper(server, context).registerQsInfoData();
+        
+        server.register(new SwitchInterfaceTableGenerator().generateTable(oidSwitchInterfaceTable), context);
     }
 
     @Override
     public void unregisterMOs(MOServer server, OctetString context) {
     }
 
-    private static TimeTicks getStartTime() {
+    public static TimeTicks getStartTime() {
         long ticks = (System.currentTimeMillis() - startTime) / 100;
         TimeTicks v = new TimeTicks(ticks & 0xFFFFFFFFL);
         return v;

File src/com/zyxel/enc/netbar/agent/SwitchDataHelper.java

+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.zyxel.enc.netbar.agent;
+
+import org.snmp4j.agent.DuplicateRegistrationException;
+import org.snmp4j.agent.MOServer;
+import org.snmp4j.agent.mo.MOAccessImpl;
+import org.snmp4j.agent.mo.snmp.DateAndTimeScalar;
+import org.snmp4j.smi.OID;
+import org.snmp4j.smi.OctetString;
+
+/**
+ * This class is used to help to register data for switch. Because switch's data 
+ * is also queried from router, it need some special handle.
+ * @author sting
+ */
+public class SwitchDataHelper {
+    private static final String cpuUsageOidPrefix = "1.3.6.1.4.1.890.1.5.17.1.11.1.1.";
+    private static final String memUsageOidPrefix = "1.3.6.1.4.1.890.1.5.17.1.11.1.2.";
+    private static final String broadcastRateOidPrefix = "1.3.6.1.4.1.890.1.5.17.1.11.1.3.";
+    private static final String voltageOidPrefix = "1.3.6.1.4.1.890.1.5.17.1.11.1.4.";
+    private static final String cpuTemperatureOidPrefix = "1.3.6.1.4.1.890.1.5.17.1.11.1.5.";
+    private static final String sysUptimeOidPrefix = "1.3.6.1.4.1.890.1.5.17.1.11.1.6.";
+    private static final String sysDateTimeOidPrefix = "1.3.6.1.4.1.890.1.5.17.1.11.1.7.";
+    private MOServer server;
+    private OctetString context;
+
+    public SwitchDataHelper(MOServer server, OctetString context) {
+        this.server = server;
+        this.context = context;
+    }
+
+    public void registerQsInfoData() throws DuplicateRegistrationException {
+        int number = Integer.parseInt(Config.get("switch.number"));
+        for (int i = 1; i <= number; i++) {
+            String ip = Config.get("switch.ip." + i);
+            OID cpuUsageOid = new OID(cpuUsageOidPrefix + ip);
+            server.register(MOCreator.createReadOnly(cpuUsageOid, Config.getInt("switch.cpu.usage." + i)), context);
+            OID memUsageOid = new OID(memUsageOidPrefix + ip);
+            server.register(MOCreator.createReadOnly(memUsageOid, Config.getInt("switch.mem.usage." + i)), context);
+            OID broadcastRateOid = new OID(broadcastRateOidPrefix + ip);
+            server.register(MOCreator.createReadOnly(broadcastRateOid, Config.getInt("switch.broadcast.rate." + i)), context);
+            OID voltageOid = new OID(voltageOidPrefix + ip);
+            server.register(MOCreator.createReadOnly(voltageOid, Config.getInt("switch.voltage." + i)), context);
+            OID cpuTemperature = new OID(cpuTemperatureOidPrefix + ip);
+            server.register(MOCreator.createReadOnly(cpuTemperature, Config.getInt("switch.cpu.temperature." + i)), context);
+            
+            OID sysUpTimeOid = new OID(sysUptimeOidPrefix + ip);
+            server.register(MOCreator.createTimeTicks(sysUpTimeOid, NRrouterMib.getStartTime()), context);
+            
+            OID sysDateTimeOid = new OID(sysDateTimeOidPrefix + ip);
+            server.register(new DateAndTimeScalar(sysDateTimeOid, MOAccessImpl.ACCESS_READ_ONLY, new OctetString(NRrouterMib.getCurrentTimeAsString())), context);
+        }
+    }
+}

File src/com/zyxel/enc/netbar/agent/generator/SwitchInterfaceTableGenerator.java

+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package com.zyxel.enc.netbar.agent.generator;
+
+import com.zyxel.enc.netbar.agent.AbstractTableGenerator;
+import com.zyxel.enc.netbar.agent.Config;
+import org.snmp4j.agent.mo.DefaultMOMutableRow2PC;
+import org.snmp4j.agent.mo.MOAccessImpl;
+import org.snmp4j.agent.mo.MOColumn;
+import org.snmp4j.agent.mo.MOMutableTableModel;
+import org.snmp4j.agent.mo.MOTableIndex;
+import org.snmp4j.agent.mo.MOTableSubIndex;
+import org.snmp4j.smi.Counter32;
+import org.snmp4j.smi.Integer32;
+import org.snmp4j.smi.OID;
+import org.snmp4j.smi.OctetString;
+import org.snmp4j.smi.SMIConstants;
+import org.snmp4j.smi.Variable;
+
+/**
+ *
+ * @author sting
+ */
+public class SwitchInterfaceTableGenerator extends AbstractTableGenerator {
+    public SwitchInterfaceTableGenerator() {
+        MOTableSubIndex[] indexs = new MOTableSubIndex[]{new MOTableSubIndex(SMIConstants.SYNTAX_IPADDRESS, 7, 15)};
+        index = new MOTableIndex(indexs, false);
+    }
+    @Override
+    public MOColumn[] defineColumns() {
+        MOColumn[] columns = new MOColumn[7];
+        columns[0] = new MOColumn(1, SMIConstants.SYNTAX_INTEGER, MOAccessImpl.ACCESS_READ_ONLY);
+        columns[1] = new MOColumn(2, SMIConstants.SYNTAX_OCTET_STRING, MOAccessImpl.ACCESS_READ_ONLY);
+        columns[2] = new MOColumn(3, SMIConstants.SYNTAX_INTEGER, MOAccessImpl.ACCESS_READ_ONLY);
+        columns[3] = new MOColumn(4, SMIConstants.SYNTAX_INTEGER, MOAccessImpl.ACCESS_READ_ONLY);
+        columns[4] = new MOColumn(5, SMIConstants.SYNTAX_OCTET_STRING, MOAccessImpl.ACCESS_READ_ONLY);
+        columns[5] = new MOColumn(6, SMIConstants.SYNTAX_COUNTER32, MOAccessImpl.ACCESS_READ_ONLY);
+        columns[6] = new MOColumn(7, SMIConstants.SYNTAX_COUNTER32, MOAccessImpl.ACCESS_READ_ONLY);
+        return columns;
+    }
+
+    @Override
+    public void setVariables(MOMutableTableModel model) {
+        int number = Integer.parseInt(Config.get("switch.interface.table.number"));
+        for (int i = 1; i <= number; i++) {
+            String ip = Config.get("switch.interface.table.ip." + i);
+            Variable[] v = new Variable[]{
+                new Integer32(Config.getInt("switch.interface.table.index." + i)),
+                new OctetString(Config.get("switch.interface.table.desc." + i)),
+                new Integer32(Config.getInt("switch.interface.table.status." + i)),
+                new Integer32(Config.getInt("switch.interface.table.speed." + i)),
+                new OctetString(Config.get("switch.interface.table.mac." + i)),
+                new Counter32(Config.getInt("switch.interface.table.in." + i)),
+                new Counter32(Config.getInt("switch.interface.table.out." + i))
+            };
+            model.addRow(new DefaultMOMutableRow2PC(new OID(String.valueOf(ip)), v));
+        }
+    }
+
+}