/** * Adds a new MIB in the SNMP MIB handler. * This method is to be called to set a specific agent to a specific OID. * This can be useful when dealing with MIB overlapping. * Some OID can be implemented in more than one MIB. In this case, * the OID nearer agent will be used on SNMP operations. * * @param mib The MIB to add. * @param oids The set of OIDs this agent implements. * * @return A reference to the SNMP MIB handler. * * @exception IllegalArgumentException If the parameter is null. * * @since 1.5 */ @Override public SnmpMibHandler addMib(SnmpMibAgent mib, SnmpOid[] oids) throws IllegalArgumentException { if (mib == null) { throw new IllegalArgumentException() ; } //If null oid array, just add it to the mib. if(oids == null) return addMib(mib); if(!mibs.contains(mib)) mibs.addElement(mib); for (int i = 0; i < oids.length; i++) { root.register(mib, oids[i].longValue()); } return this; }
private void createSnmpRequestHandler(SnmpAdaptorServer server, int id, DatagramSocket s, DatagramPacket p, SnmpMibTree tree, Vector<SnmpMibAgent> m, InetAddressAcl a, SnmpPduFactory factory, SnmpUserDataFactory dataFactory, MBeanServer f, ObjectName n) { final SnmpRequestHandler handler = new SnmpRequestHandler(this, id, s, p, tree, m, a, factory, dataFactory, f, n); threadService.submitTask(handler); }
/** * Full constructor */ public SnmpRequestHandler(SnmpAdaptorServer server, int id, DatagramSocket s, DatagramPacket p, SnmpMibTree tree, Vector<SnmpMibAgent> m, InetAddressAcl a, SnmpPduFactory factory, SnmpUserDataFactory dataFactory, MBeanServer f, ObjectName n) { super(server, id, f, n); // Need a reference on SnmpAdaptorServer for getNext & getBulk, // in case of oid equality (mib overlapping). // adaptor = server; socket = s; packet = p; root= tree; mibs = new Vector<>(m); subs= new Hashtable<>(mibs.size()); ipacl = a; pduFactory = factory ; userDataFactory = dataFactory ; //thread.start(); }
/** * The method takes the incoming get bulk requests and split it into * subrequests. */ private void splitBulkRequest(SnmpPduBulk req, int nonRepeaters, int maxRepetitions, int R) { // Send the getBulk to all agents // for(Enumeration<SnmpMibAgent> e= mibs.elements(); e.hasMoreElements(); ) { final SnmpMibAgent agent = e.nextElement(); if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) { SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag, "splitBulkRequest", "Create a sub with : " + agent + " " + nonRepeaters + " " + maxRepetitions + " " + R); } subs.put(agent, new SnmpSubBulkRequestHandler(adaptor, agent, req, nonRepeaters, maxRepetitions, R)); } }
public void printTree(String ident) { StringBuilder buff= new StringBuilder(); if (agents == null) { return; } for(Enumeration<SnmpMibAgent> e= agents.elements(); e.hasMoreElements(); ) { SnmpMibAgent mib= e.nextElement(); if (mib == null) buff.append("empty "); else buff.append(mib.getMibName()).append(" "); } ident+= " "; if (children == null) { return; } for(Enumeration<TreeNode> e= children.elements(); e.hasMoreElements(); ) { TreeNode node= e.nextElement(); node.printTree(ident); } }
private void removeAgentFully(SnmpMibAgent agent) { Vector<TreeNode> v = new Vector<>(); for(Enumeration<TreeNode> e= children.elements(); e.hasMoreElements(); ) { TreeNode node= e.nextElement(); node.removeAgentFully(agent); if(node.agents.isEmpty()) v.add(node); } for(Enumeration<TreeNode> e= v.elements(); e.hasMoreElements(); ) { children.removeElement(e.nextElement()); } removeAgent(agent); }
/** * SNMP V1/V2 . To be called with updateRequest. */ protected SnmpSubRequestHandler(SnmpMibAgent agent, SnmpPdu req) { if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) { SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "constructor", "creating instance for request " + String.valueOf(req.requestId)); } version= req.version; type= req.type; this.agent= agent; // We get a ref on the pdu in order to pass it to SnmpMibRequest. reqPdu = req; //Pre-allocate room for storing varbindlist and translation table. // int length= req.varBindList.length; translation= new int[length]; varBind= new NonSyncVector<SnmpVarBind>(length); }
/** * SNMP V1/V2 The constructor initialize the subrequest with the whole varbind list contained * in the original request. */ @SuppressWarnings("unchecked") // cast to NonSyncVector<SnmpVarBind> protected SnmpSubRequestHandler(SnmpMibAgent agent, SnmpPdu req, boolean nouse) { this(agent,req); // The translation table is easy in this case ... // int max= translation.length; SnmpVarBind[] list= req.varBindList; for(int i=0; i < max; i++) { translation[i]= i; ((NonSyncVector<SnmpVarBind>)varBind).addNonSyncElement(list[i]); } }