1. /*
  2. * @(#)file SnmpMibAgent.java
  3. * @(#)author Sun Microsystems, Inc.
  4. * @(#)version 4.40
  5. * @(#)date 04/09/15
  6. *
  7. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  8. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  9. *
  10. */
  11. package com.sun.jmx.snmp.agent;
  12. // java imports
  13. //
  14. import java.io.Serializable;
  15. import java.util.Vector;
  16. import java.util.Enumeration;
  17. import java.util.Set;
  18. // jmx imports
  19. //
  20. import javax.management.MBeanServer;
  21. import javax.management.MBeanRegistration;
  22. import javax.management.ObjectName;
  23. import javax.management.MalformedObjectNameException;
  24. import javax.management.InstanceNotFoundException;
  25. import javax.management.ServiceNotFoundException;
  26. import javax.management.ReflectionException;
  27. import javax.management.MBeanException;
  28. import com.sun.jmx.snmp.SnmpVarBind;
  29. import com.sun.jmx.snmp.SnmpDefinitions;
  30. import com.sun.jmx.snmp.SnmpStatusException;
  31. import com.sun.jmx.snmp.SnmpPdu;
  32. import com.sun.jmx.snmp.SnmpOid;
  33. import com.sun.jmx.snmp.SnmpEngine;
  34. /**
  35. * Abstract class for representing an SNMP agent.
  36. *
  37. * The class is used by the SNMP protocol adaptor as the entry point in
  38. * the SNMP agent to query.
  39. *
  40. * <p><b>This API is a Sun Microsystems internal API and is subject
  41. * to change without notice.</b></p>
  42. * @version 4.40 12/19/03
  43. * @author Sun Microsystems, Inc
  44. */
  45. public abstract class SnmpMibAgent
  46. implements SnmpMibAgentMBean, MBeanRegistration, Serializable {
  47. /**
  48. * Default constructor.
  49. */
  50. public SnmpMibAgent() {
  51. }
  52. // ---------------------------------------------------------------------
  53. // PUBLIC METHODS
  54. //----------------------------------------------------------------------
  55. /**
  56. * Initializes the MIB (with no registration of the MBeans into the
  57. * MBean server).
  58. *
  59. * @exception IllegalAccessException The MIB can not be initialized.
  60. */
  61. public abstract void init() throws IllegalAccessException;
  62. /**
  63. * Initializes the MIB but each single MBean representing the MIB
  64. * is inserted into the MBean server.
  65. *
  66. * @param server The MBean server to register the service with.
  67. * @param name The object name.
  68. *
  69. * @return The name of the SNMP MIB registered.
  70. *
  71. * @exception java.lang.Exception
  72. */
  73. public abstract ObjectName preRegister(MBeanServer server,
  74. ObjectName name)
  75. throws java.lang.Exception;
  76. /**
  77. * Not used in this context.
  78. */
  79. public void postRegister (Boolean registrationDone) {
  80. }
  81. /**
  82. * Not used in this context.
  83. */
  84. public void preDeregister() throws java.lang.Exception {
  85. }
  86. /**
  87. * Not used in this context.
  88. */
  89. public void postDeregister() {
  90. }
  91. /**
  92. * Processes a <CODE>get</CODE> operation.
  93. * This method must update the SnmpVarBinds contained in the
  94. * <var>{@link SnmpMibRequest} req</var> parameter.
  95. *
  96. * @param req The SnmpMibRequest object holding the list of variable to
  97. * be retrieved. This list is composed of
  98. * <CODE>SnmpVarBind</CODE> objects.
  99. *
  100. * @exception SnmpStatusException An error occured during the operation.
  101. */
  102. public abstract void get(SnmpMibRequest req)
  103. throws SnmpStatusException;
  104. /**
  105. * Processes a <CODE>getNext</CODE> operation.
  106. * This method must update the SnmpVarBinds contained in the
  107. * <var>{@link SnmpMibRequest} req</var> parameter.
  108. *
  109. * @param req The SnmpMibRequest object holding the list of
  110. * OIDs from which the next variables should be retrieved.
  111. * This list is composed of <CODE>SnmpVarBind</CODE> objects.
  112. *
  113. * @exception SnmpStatusException An error occured during the operation.
  114. */
  115. public abstract void getNext(SnmpMibRequest req)
  116. throws SnmpStatusException;
  117. /**
  118. * Processes a <CODE>getBulk</CODE> operation.
  119. * This method must update the SnmpVarBinds contained in the
  120. * <var>{@link SnmpMibRequest} req</var> parameter.
  121. *
  122. * @param req The SnmpMibRequest object holding the list of variable to
  123. * be retrieved. This list is composed of
  124. * <CODE>SnmpVarBind</CODE> objects.
  125. *
  126. * @param nonRepeat The number of variables, starting with the first
  127. * variable in the variable-bindings, for which a single
  128. * lexicographic successor is requested.
  129. *
  130. * @param maxRepeat The number of lexicographic successors requested
  131. * for each of the last R variables. R is the number of variables
  132. * following the first <CODE>nonRepeat</CODE> variables for which
  133. * multiple lexicographic successors are requested.
  134. *
  135. * @exception SnmpStatusException An error occured during the operation.
  136. */
  137. public abstract void getBulk(SnmpMibRequest req, int nonRepeat,
  138. int maxRepeat)
  139. throws SnmpStatusException;
  140. /**
  141. * Processes a <CODE>set</CODE> operation.
  142. * This method must update the SnmpVarBinds contained in the
  143. * <var>{@link SnmpMibRequest} req</var> parameter.
  144. * This method is called during the second phase of the SET two-phase
  145. * commit.
  146. *
  147. * @param req The SnmpMibRequest object holding the list of variable to
  148. * be set. This list is composed of
  149. * <CODE>SnmpVarBind</CODE> objects.
  150. *
  151. * @exception SnmpStatusException An error occured during the operation.
  152. * Throwing an exception in this method will break the
  153. * atomicity of the SET operation. Care must be taken so that
  154. * the exception is thrown in the {@link #check(SnmpMibRequest)}
  155. * method instead.
  156. */
  157. public abstract void set(SnmpMibRequest req)
  158. throws SnmpStatusException;
  159. /**
  160. * Checks if a <CODE>set</CODE> operation can be performed.
  161. * If the operation can not be performed, the method should throw an
  162. * <CODE>SnmpStatusException</CODE>.
  163. * This method is called during the first phase of the SET two-phase
  164. * commit.
  165. *
  166. * @param req The SnmpMibRequest object holding the list of variable to
  167. * be set. This list is composed of
  168. * <CODE>SnmpVarBind</CODE> objects.
  169. *
  170. * @exception SnmpStatusException The <CODE>set</CODE> operation
  171. * cannot be performed.
  172. */
  173. public abstract void check(SnmpMibRequest req)
  174. throws SnmpStatusException;
  175. /**
  176. * Gets the root object identifier of the MIB.
  177. * <P>The root object identifier is the object identifier uniquely
  178. * identifying the MIB.
  179. *
  180. * @return The root object identifier.
  181. */
  182. public abstract long[] getRootOid();
  183. // ---------------------------------------------------------------------
  184. // GETTERS AND SETTERS
  185. // ---------------------------------------------------------------------
  186. /**
  187. * Gets the reference to the MBean server in which the SNMP MIB is
  188. * registered.
  189. *
  190. * @return The MBean server or null if the MIB is not registered in any
  191. * MBean server.
  192. */
  193. public MBeanServer getMBeanServer() {
  194. return server;
  195. }
  196. /**
  197. * Gets the reference to the SNMP protocol adaptor to which the MIB is
  198. * bound.
  199. *
  200. * @return The SNMP MIB handler.
  201. */
  202. public SnmpMibHandler getSnmpAdaptor() {
  203. return adaptor;
  204. }
  205. /**
  206. * Sets the reference to the SNMP protocol adaptor through which the MIB
  207. * will be SNMP accessible and add this new MIB in the SNMP MIB handler.
  208. *
  209. * @param stack The SNMP MIB handler.
  210. */
  211. public void setSnmpAdaptor(SnmpMibHandler stack) {
  212. if (adaptor != null) {
  213. adaptor.removeMib(this);
  214. }
  215. adaptor = stack;
  216. if (adaptor != null) {
  217. adaptor.addMib(this);
  218. }
  219. }
  220. /**
  221. * Sets the reference to the SNMP protocol adaptor through which the MIB
  222. * will be SNMP accessible and add this new MIB in the SNMP MIB handler.
  223. * This method is to be called to set a specific agent to a specific OID. This can be useful when dealing with MIB overlapping.
  224. * Some OID can be implemented in more than one MIB. In this case, the OID nearest the agent will be used on SNMP operations.
  225. * @param stack The SNMP MIB handler.
  226. * @param oids The set of OIDs this agent implements.
  227. *
  228. * @since 1.5
  229. */
  230. public void setSnmpAdaptor(SnmpMibHandler stack, SnmpOid[] oids) {
  231. if (adaptor != null) {
  232. adaptor.removeMib(this);
  233. }
  234. adaptor = stack;
  235. if (adaptor != null) {
  236. adaptor.addMib(this, oids);
  237. }
  238. }
  239. /**
  240. * Sets the reference to the SNMP protocol adaptor through which the MIB
  241. * will be SNMP accessible and adds this new MIB in the SNMP MIB handler.
  242. * Adds a new contextualized MIB in the SNMP MIB handler.
  243. *
  244. * @param stack The SNMP MIB handler.
  245. * @param contextName The MIB context name. If null is passed, will be registered in the default context.
  246. *
  247. * @exception IllegalArgumentException If the parameter is null.
  248. *
  249. * @since 1.5
  250. */
  251. public void setSnmpAdaptor(SnmpMibHandler stack, String contextName) {
  252. if (adaptor != null) {
  253. adaptor.removeMib(this, contextName);
  254. }
  255. adaptor = stack;
  256. if (adaptor != null) {
  257. adaptor.addMib(this, contextName);
  258. }
  259. }
  260. /**
  261. * Sets the reference to the SNMP protocol adaptor through which the MIB
  262. * will be SNMP accessible and adds this new MIB in the SNMP MIB handler.
  263. * Adds a new contextualized MIB in the SNMP MIB handler.
  264. *
  265. * @param stack The SNMP MIB handler.
  266. * @param contextName The MIB context name. If null is passed, will be registered in the default context.
  267. * @param oids The set of OIDs this agent implements.
  268. * @exception IllegalArgumentException If the parameter is null.
  269. *
  270. * @since 1.5
  271. */
  272. public void setSnmpAdaptor(SnmpMibHandler stack,
  273. String contextName,
  274. SnmpOid[] oids) {
  275. if (adaptor != null) {
  276. adaptor.removeMib(this, contextName);
  277. }
  278. adaptor = stack;
  279. if (adaptor != null) {
  280. adaptor.addMib(this, contextName, oids);
  281. }
  282. }
  283. /**
  284. * Gets the object name of the SNMP protocol adaptor to which the MIB
  285. * is bound.
  286. *
  287. * @return The name of the SNMP protocol adaptor.
  288. */
  289. public ObjectName getSnmpAdaptorName() {
  290. return adaptorName;
  291. }
  292. /**
  293. * Sets the reference to the SNMP protocol adaptor through which the MIB
  294. * will be SNMP accessible and add this new MIB in the SNMP MIB handler
  295. * associated to the specified <CODE>name</CODE>.
  296. *
  297. * @param name The name of the SNMP protocol adaptor.
  298. *
  299. * @exception InstanceNotFoundException The SNMP protocol adaptor does
  300. * not exist in the MBean server.
  301. *
  302. * @exception ServiceNotFoundException This SNMP MIB is not registered
  303. * in the MBean server or the requested service is not supported.
  304. */
  305. public void setSnmpAdaptorName(ObjectName name)
  306. throws InstanceNotFoundException, ServiceNotFoundException {
  307. if (server == null) {
  308. throw new ServiceNotFoundException(mibName + " is not registered in the MBean server");
  309. }
  310. // First remove the reference on the old adaptor server.
  311. //
  312. if (adaptor != null) {
  313. adaptor.removeMib(this);
  314. }
  315. // Then update the reference to the new adaptor server.
  316. //
  317. Object[] params = {this};
  318. String[] signature = {"com.sun.jmx.snmp.agent.SnmpMibAgent"};
  319. try {
  320. adaptor = (SnmpMibHandler)(server.invoke(name, "addMib", params,
  321. signature));
  322. } catch (InstanceNotFoundException e) {
  323. throw new InstanceNotFoundException(name.toString());
  324. } catch (ReflectionException e) {
  325. throw new ServiceNotFoundException(name.toString());
  326. } catch (MBeanException e) {
  327. // Should never occur...
  328. }
  329. adaptorName = name;
  330. }
  331. /**
  332. * Sets the reference to the SNMP protocol adaptor through which the MIB
  333. * will be SNMP accessible and add this new MIB in the SNMP MIB handler
  334. * associated to the specified <CODE>name</CODE>.
  335. * This method is to be called to set a specific agent to a specific OID. This can be useful when dealing with MIB overlapping.
  336. * Some OID can be implemented in more than one MIB. In this case, the OID nearer agent will be used on SNMP operations.
  337. * @param name The name of the SNMP protocol adaptor.
  338. * @param oids The set of OIDs this agent implements.
  339. * @exception InstanceNotFoundException The SNMP protocol adaptor does
  340. * not exist in the MBean server.
  341. *
  342. * @exception ServiceNotFoundException This SNMP MIB is not registered
  343. * in the MBean server or the requested service is not supported.
  344. *
  345. * @since 1.5
  346. */
  347. public void setSnmpAdaptorName(ObjectName name, SnmpOid[] oids)
  348. throws InstanceNotFoundException, ServiceNotFoundException {
  349. if (server == null) {
  350. throw new ServiceNotFoundException(mibName + " is not registered in the MBean server");
  351. }
  352. // First remove the reference on the old adaptor server.
  353. //
  354. if (adaptor != null) {
  355. adaptor.removeMib(this);
  356. }
  357. // Then update the reference to the new adaptor server.
  358. //
  359. Object[] params = {this, oids};
  360. String[] signature = {"com.sun.jmx.snmp.agent.SnmpMibAgent",
  361. oids.getClass().getName()};
  362. try {
  363. adaptor = (SnmpMibHandler)(server.invoke(name, "addMib", params,
  364. signature));
  365. } catch (InstanceNotFoundException e) {
  366. throw new InstanceNotFoundException(name.toString());
  367. } catch (ReflectionException e) {
  368. throw new ServiceNotFoundException(name.toString());
  369. } catch (MBeanException e) {
  370. // Should never occur...
  371. }
  372. adaptorName = name;
  373. }
  374. /**
  375. * Sets the reference to the SNMP protocol adaptor through which the MIB
  376. * will be SNMP accessible and add this new MIB in the SNMP MIB handler
  377. * associated to the specified <CODE>name</CODE>.
  378. *
  379. * @param name The name of the SNMP protocol adaptor.
  380. * @param contextName The MIB context name. If null is passed, will be registered in the default context.
  381. * @exception InstanceNotFoundException The SNMP protocol adaptor does
  382. * not exist in the MBean server.
  383. *
  384. * @exception ServiceNotFoundException This SNMP MIB is not registered
  385. * in the MBean server or the requested service is not supported.
  386. *
  387. * @since 1.5
  388. */
  389. public void setSnmpAdaptorName(ObjectName name, String contextName)
  390. throws InstanceNotFoundException, ServiceNotFoundException {
  391. if (server == null) {
  392. throw new ServiceNotFoundException(mibName + " is not registered in the MBean server");
  393. }
  394. // First remove the reference on the old adaptor server.
  395. //
  396. if (adaptor != null) {
  397. adaptor.removeMib(this, contextName);
  398. }
  399. // Then update the reference to the new adaptor server.
  400. //
  401. Object[] params = {this, contextName};
  402. String[] signature = {"com.sun.jmx.snmp.agent.SnmpMibAgent", "java.lang.String"};
  403. try {
  404. adaptor = (SnmpMibHandler)(server.invoke(name, "addMib", params,
  405. signature));
  406. } catch (InstanceNotFoundException e) {
  407. throw new InstanceNotFoundException(name.toString());
  408. } catch (ReflectionException e) {
  409. throw new ServiceNotFoundException(name.toString());
  410. } catch (MBeanException e) {
  411. // Should never occur...
  412. }
  413. adaptorName = name;
  414. }
  415. /**
  416. * Sets the reference to the SNMP protocol adaptor through which the MIB
  417. * will be SNMP accessible and add this new MIB in the SNMP MIB handler
  418. * associated to the specified <CODE>name</CODE>.
  419. *
  420. * @param name The name of the SNMP protocol adaptor.
  421. * @param contextName The MIB context name. If null is passed, will be registered in the default context.
  422. * @param oids The set of OIDs this agent implements.
  423. * @exception InstanceNotFoundException The SNMP protocol adaptor does
  424. * not exist in the MBean server.
  425. *
  426. * @exception ServiceNotFoundException This SNMP MIB is not registered
  427. * in the MBean server or the requested service is not supported.
  428. *
  429. * @since 1.5
  430. */
  431. public void setSnmpAdaptorName(ObjectName name,
  432. String contextName, SnmpOid[] oids)
  433. throws InstanceNotFoundException, ServiceNotFoundException {
  434. if (server == null) {
  435. throw new ServiceNotFoundException(mibName + " is not registered in the MBean server");
  436. }
  437. // First remove the reference on the old adaptor server.
  438. //
  439. if (adaptor != null) {
  440. adaptor.removeMib(this, contextName);
  441. }
  442. // Then update the reference to the new adaptor server.
  443. //
  444. Object[] params = {this, contextName, oids};
  445. String[] signature = {"com.sun.jmx.snmp.agent.SnmpMibAgent", "java.lang.String", oids.getClass().getName()};
  446. try {
  447. adaptor = (SnmpMibHandler)(server.invoke(name, "addMib", params,
  448. signature));
  449. } catch (InstanceNotFoundException e) {
  450. throw new InstanceNotFoundException(name.toString());
  451. } catch (ReflectionException e) {
  452. throw new ServiceNotFoundException(name.toString());
  453. } catch (MBeanException e) {
  454. // Should never occur...
  455. }
  456. adaptorName = name;
  457. }
  458. /**
  459. * Indicates whether or not the MIB module is bound to a SNMP protocol
  460. * adaptor.
  461. * As a reminder, only bound MIBs can be accessed through SNMP protocol
  462. * adaptor.
  463. *
  464. * @return <CODE>true</CODE> if the MIB module is bound,
  465. * <CODE>false</CODE> otherwise.
  466. */
  467. public boolean getBindingState() {
  468. if (adaptor == null)
  469. return false;
  470. else
  471. return true;
  472. }
  473. /**
  474. * Gets the MIB name.
  475. *
  476. * @return The MIB name.
  477. */
  478. public String getMibName() {
  479. return mibName;
  480. }
  481. /**
  482. * This is a factory method for creating new SnmpMibRequest objects.
  483. * @param reqPdu The received PDU.
  484. * @param vblist The vector of SnmpVarBind objects in which the
  485. * MIB concerned by this request is involved.
  486. * @param version The protocol version of the SNMP request.
  487. * @param userData User allocated contextual data.
  488. *
  489. * @return A new SnmpMibRequest object.
  490. *
  491. * @since 1.5
  492. **/
  493. public static SnmpMibRequest newMibRequest(SnmpPdu reqPdu,
  494. Vector vblist,
  495. int version,
  496. Object userData)
  497. {
  498. return new SnmpMibRequestImpl(null,
  499. reqPdu,
  500. vblist,
  501. version,
  502. userData,
  503. null,
  504. SnmpDefinitions.noAuthNoPriv,
  505. getSecurityModel(version),
  506. null,null);
  507. }
  508. /**
  509. * This is a factory method for creating new SnmpMibRequest objects.
  510. * @param engine The local engine.
  511. * @param reqPdu The received pdu.
  512. * @param vblist The vector of SnmpVarBind objects in which the
  513. * MIB concerned by this request is involved.
  514. * @param version The protocol version of the SNMP request.
  515. * @param userData User allocated contextual data.
  516. *
  517. * @return A new SnmpMibRequest object.
  518. *
  519. * @since 1.5
  520. **/
  521. public static SnmpMibRequest newMibRequest(SnmpEngine engine,
  522. SnmpPdu reqPdu,
  523. Vector vblist,
  524. int version,
  525. Object userData,
  526. String principal,
  527. int securityLevel,
  528. int securityModel,
  529. byte[] contextName,
  530. byte[] accessContextName) {
  531. return new SnmpMibRequestImpl(engine,
  532. reqPdu,
  533. vblist,
  534. version,
  535. userData,
  536. principal,
  537. securityLevel,
  538. securityModel,
  539. contextName,
  540. accessContextName);
  541. }
  542. // ---------------------------------------------------------------------
  543. // PACKAGE METHODS
  544. // ---------------------------------------------------------------------
  545. /**
  546. * Processes a <CODE>getBulk</CODE> operation using call to
  547. * <CODE>getNext</CODE>.
  548. * The method implements the <CODE>getBulk</CODE> operation by calling
  549. * appropriately the <CODE>getNext</CODE> method.
  550. *
  551. * @param req The SnmpMibRequest containing the variable list to be
  552. * retrieved.
  553. *
  554. * @param nonRepeat The number of variables, starting with the first
  555. * variable in the variable-bindings, for which a single lexicographic
  556. * successor is requested.
  557. *
  558. * @param maxRepeat The number of lexicographic successors
  559. * requested for each of the last R variables. R is the number of
  560. * variables following the first nonRepeat variables for which
  561. * multiple lexicographic successors are requested.
  562. *
  563. * @return The variable list containing returned values.
  564. *
  565. * @exception SnmpStatusException An error occured during the operation.
  566. */
  567. void getBulkWithGetNext(SnmpMibRequest req, int nonRepeat, int maxRepeat)
  568. throws SnmpStatusException {
  569. final Vector list = req.getSubList();
  570. // RFC 1905, Section 4.2.3, p14
  571. final int L = list.size() ;
  572. final int N = Math.max(Math.min(nonRepeat, L), 0) ;
  573. final int M = Math.max(maxRepeat, 0) ;
  574. final int R = L - N ;
  575. // Let's build the varBindList for the response pdu
  576. //
  577. // int errorStatus = SnmpDefinitions.snmpRspNoError ;
  578. // int errorIndex = 0 ;
  579. if (L != 0) {
  580. // Non-repeaters and first row of repeaters
  581. //
  582. getNext(req);
  583. // Now the remaining repeaters
  584. //
  585. Vector repeaters= splitFrom(list, N);
  586. SnmpMibRequestImpl repeatedReq =
  587. new SnmpMibRequestImpl(req.getEngine(),
  588. req.getPdu(),
  589. repeaters,
  590. SnmpDefinitions.snmpVersionTwo,
  591. req.getUserData(),
  592. req.getPrincipal(),
  593. req.getSecurityLevel(),
  594. req.getSecurityModel(),
  595. req.getContextName(),
  596. req.getAccessContextName());
  597. for (int i = 2 ; i <= M ; i++) {
  598. getNext(repeatedReq);
  599. concatVector(req, repeaters);
  600. }
  601. }
  602. }
  603. // ---------------------------------------------------------------------
  604. // PRIVATE METHODS
  605. // ---------------------------------------------------------------------
  606. /**
  607. * This method creates a new Vector which does not contain the first
  608. * element up to the specified limit.
  609. *
  610. * @param original The original vector.
  611. * @param limit The limit.
  612. */
  613. private Vector splitFrom(Vector original, int limit) {
  614. int max= original.size();
  615. Vector result= new Vector(max - limit);
  616. int i= limit;
  617. // Ok the loop looks a bit strange. But in order to improve the
  618. // perf, we try to avoid reference to the limit variable from
  619. // within the loop ...
  620. //
  621. for(Enumeration e= original.elements(); e.hasMoreElements(); --i) {
  622. SnmpVarBind var= (SnmpVarBind) e.nextElement();
  623. if (i >0)
  624. continue;
  625. result.addElement(new SnmpVarBind(var.oid, var.value));
  626. }
  627. return result;
  628. }
  629. private void concatVector(SnmpMibRequest req, Vector source) {
  630. for(Enumeration e= source.elements(); e.hasMoreElements(); ) {
  631. SnmpVarBind var= (SnmpVarBind) e.nextElement();
  632. // We need to duplicate the SnmpVarBind otherwise it is going
  633. // to be overloaded by the next get Next ...
  634. req.addVarBind(new SnmpVarBind(var.oid, var.value));
  635. }
  636. }
  637. private void concatVector(Vector target, Vector source) {
  638. for(Enumeration e= source.elements(); e.hasMoreElements(); ) {
  639. SnmpVarBind var= (SnmpVarBind) e.nextElement();
  640. // We need to duplicate the SnmpVarBind otherwise it is going
  641. // to be overloaded by the next get Next ...
  642. target.addElement(new SnmpVarBind(var.oid, var.value));
  643. }
  644. }
  645. static private Vector vector(Enumeration e) {
  646. if (e == null) return null;
  647. Vector v = new Vector();
  648. while (e.hasMoreElements()) v.addElement(e.nextElement());
  649. return v;
  650. }
  651. private static int getSecurityModel(int version) {
  652. switch(version) {
  653. case SnmpDefinitions.snmpVersionOne:
  654. return SnmpDefinitions.snmpV1SecurityModel;
  655. default:
  656. return SnmpDefinitions.snmpV2SecurityModel;
  657. }
  658. }
  659. // ---------------------------------------------------------------------
  660. // PROTECTED VARIABLES
  661. // ---------------------------------------------------------------------
  662. /**
  663. * The object name of the MIB.
  664. * @serial
  665. */
  666. protected String mibName;
  667. /**
  668. * The reference to the MBean server.
  669. * @serial
  670. */
  671. protected MBeanServer server;
  672. // ---------------------------------------------------------------------
  673. // PRIVATE VARIABLES
  674. // ---------------------------------------------------------------------
  675. /**
  676. * The object name of the SNMP protocol adaptor.
  677. * @serial
  678. */
  679. private ObjectName adaptorName;
  680. /**
  681. * The reference to the SNMP stack.
  682. */
  683. private transient SnmpMibHandler adaptor;
  684. }