Commits

stingh711 committed b280209

"fix bug in support switch interface table"

Comments (0)

Files changed (3)

config.properties

-agent.ip=172.25.21.69/161
+agent.ip=172.25.21.47/161
 
 hostname=NR Router
 mac=00:a0:c5:00:00:11
 arp.sender.index.3=3
 arp.sender.ip.3=192.168.1.3
 
-switch.number=1
+switch.number=2
 #switch QS info data
 switch.ip.1=192.168.1.1
 switch.cpu.usage.1=10
 switch.cpu.temperature.2=70
 
 #switch interface table data
-switch.number=1
 switch.1.ip=192.168.1.1
 switch.1.interface.table.number=2
 switch.1.interface.table.index.1=1

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

     private static final OID oidCurrentSessions = new OID("1.3.6.1.4.1.890.1.5.17.1.3.1.1");
     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 oidSwitchInterfaceTable = new OID("1.3.6.1.4.1.890.1.5.17.1.11.2.1.1");
     private static final OID oidTopArpTable = new OID("1.3.6.1.4.1.890.1.5.17.1.10.1.1.1");
 
 
         server.register(createTopArpSenderTable(), context);
 
         new SwitchDataHelper(server, context).registerQsInfoData();
-        List<DefaultMOTable> switchInterfaces = new SwitchInterfaceTableGenerator().generateTables();
-        for (DefaultMOTable t : switchInterfaces) {
-            server.register(t, context);
-        }
+        server.register(new SwitchInterfaceTableGenerator().generateTable(oidSwitchInterfaceTable), context);
     }
 
     @Override

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

  *
  * @author sting
  */
-public class SwitchInterfaceTableGenerator {
+public class SwitchInterfaceTableGenerator extends AbstractTableGenerator {
     private static final String PREFIX = "1.3.6.1.4.1.890.1.5.17.1.11.2.1.1";
 
     public SwitchInterfaceTableGenerator() {
     }
 
-    public DefaultMOTable generateTable(MOTableIndex index, OID oid, int number, String ip) {
-        DefaultMOTable table = new DefaultMOTable(oid, index, defineColumns());
-        MOMutableTableModel model = (MOMutableTableModel) table.getModel();
-        setVariables(model, number, ip);
-        table.setVolatile(true);
-
-        return table;
-    }
-
-    public List<DefaultMOTable> generateTables() {
-        int number = Integer.parseInt(Config.get("switch.number"));
-        List<DefaultMOTable> tables = new ArrayList<DefaultMOTable>(number);
-        for (int i = 1; i <= number; i++) {
-            MOTableSubIndex[] indexs = new MOTableSubIndex[]{new MOTableSubIndex(SMIConstants.SYNTAX_OCTET_STRING, 9, 18)};
-            MOTableIndex index = new MOTableIndex(indexs, false);
-            String ip = Config.get("switch." + i + ".ip");
-            OID oid = new OID(PREFIX);
-            tables.add(generateTable(index, oid, i, ip));
-        }
-        return tables;
-    }
-
+    @Override
     public MOColumn[] defineColumns() {
         MOColumn[] columns = new MOColumn[7];
         columns[0] = new MOColumn(1, SMIConstants.SYNTAX_INTEGER, MOAccessImpl.ACCESS_READ_ONLY);
         }
     }
 
+    @Override
+    public void setVariables(MOMutableTableModel model) {
+        int deviceNumber = Config.getInt("switch.number");
+        for (int i = 1; i <= deviceNumber; i++) {
+            String ip = Config.get("switch." + i + ".ip");
+            int interfaceNumber = Config.getInt("switch." + i + ".interface.table.number");
+            for (int j = 1; j <= interfaceNumber; j++) {
+                Variable[] v = new Variable[]{
+                    new Integer32(Config.getInt("switch." + i + ".interface.table.index." + j)),
+                    new OctetString(Config.get("switch." + i + ".interface.table.desc." + j)),
+                    new Integer32(Config.getInt("switch." + i + ".interface.table.status." + j)),
+                    new Integer32(Config.getInt("switch." + i + ".interface.table.speed." + j)),
+                    new OctetString(Config.get("switch." + i + ".interface.table.mac." + j)),
+                    new Counter32(Config.getInt("switch." + i + ".interface.table.in." + j)),
+                    new Counter32(Config.getInt("switch." + i + ".interface.table.out." + j))
+                };
+                model.addRow(new DefaultMOMutableRow2PC(new OID(ip + "." + j), v));
+
+            }
+        }
+    }
+
 }