/* * @(#)file SnmpParameters.java * @(#)author Sun Microsystems, Inc. * @(#)version 4.17 * @(#)date 06/05/03 * * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * */ // Copyright (c) 1995-96 by Cisco Systems, Inc. package com.sun.jmx.snmp ; import java.io.Serializable; import java.io.UnsupportedEncodingException; import com.sun.jmx.snmp.SnmpDefinitions; import com.sun.jmx.snmp.SnmpStatusException; /** * Contains a set of resources that are used by while sending or receiving * packets to and from an SnmpPeer. An SnmpPeer can * be configured explicitly to use a specific SnmpParameter. * A number of SnmpPeer objects can share a single parameter * object. *

* Note: Changing values for an SnmpParameter object * affects all SnmpPeer objects that share the parameter object. * * @version 4.17 12/19/03 * @author Sun Microsystems, Inc * @author Cisco Systems, Inc. * @see com.sun.jmx.snmp.SnmpPeer * *

This API is a Sun Microsystems internal API and is subject * to change without notice.

*/ public class SnmpParameters extends SnmpParams implements Cloneable, Serializable { /** * Creates an SnmpParameters object with defaults set up. * By default, set operations are not allowed, the read community and * the inform community strings to use is "public" and the SNMP version is V1. */ public SnmpParameters() { _readCommunity = defaultRdCommunity ; _informCommunity = defaultRdCommunity ; } /** * Creates an SnmpParameters object. * This constructor allows the specification of the read/write community strings. * The inform community string to use is "public". * * @param rdc community string to use for get operations. * @param wrc community string to use for set operations. */ public SnmpParameters(String rdc, String wrc) { _readCommunity = rdc ; _writeCommunity = wrc ; _informCommunity = defaultRdCommunity ; } /** * Creates an SnmpParameters object. * This constructor allows the specification of the read/write/inform community strings. * * @param rdc community string to use for get operations. * @param wrc community string to use for set operations. * @param inform community string to use for inform requests. */ public SnmpParameters(String rdc, String wrc, String inform) { _readCommunity = rdc ; _writeCommunity = wrc ; _informCommunity = inform ; } /** * Gets the community to be used when issuing get operations. * @return The community string. */ public String getRdCommunity() { return _readCommunity ; } /** * Sets the community string to use when performing get operations. * @param read The community string. */ public synchronized void setRdCommunity(String read) { if (read == null) _readCommunity = defaultRdCommunity ; else _readCommunity = read ; } /** * Gets the community to be used when issuing set operations. * @return The community string. */ public String getWrCommunity() { return _writeCommunity ; } /** * Sets the community to be used when issuing set operations. * @param write The community string. */ public void setWrCommunity(String write) { _writeCommunity = write; } /** * Gets the community to be used when issuing inform requests. * @return The community string. */ public String getInformCommunity() { return _informCommunity ; } /** * Sets the community string to use when performing inform requests. * @param inform The community string. */ public void setInformCommunity(String inform) { if (inform == null) _informCommunity = defaultRdCommunity ; else _informCommunity = inform ; } /** * Checks whether parameters are in place for an SNMP set operation. * @return true if parameters are in place, false otherwise. */ public boolean allowSnmpSets() { return _writeCommunity != null ; } /** * Compares two objects. * Two SnmpParameters are equal if they correspond to the same protocol version, * read community and write community. * @param obj The object to compare this with. * @return true if this and the specified object are equal, false otherwise. */ public synchronized boolean equals(Object obj) { if (!( obj instanceof SnmpParameters)) return false; if (this == obj) return true ; SnmpParameters param = (SnmpParameters) obj ; if (_protocolVersion == param._protocolVersion) if (_readCommunity.equals(param._readCommunity)) return true ; return false ; } /** * Clones the object and its content. * @return The object clone. */ public synchronized Object clone() { SnmpParameters par = null ; try { par = (SnmpParameters) super.clone() ; //par._retryPolicy = _retryPolicy ; par._readCommunity = _readCommunity ; par._writeCommunity = _writeCommunity ; par._informCommunity = _informCommunity ; } catch (CloneNotSupportedException e) { throw new InternalError() ; // VM bug. } return par ; } /** * For SNMP Runtime internal use only. */ public byte[] encodeAuthentication(int snmpCmd) throws SnmpStatusException { // // Returns the community string associated to the specified command. // try { if (snmpCmd == pduSetRequestPdu) return _writeCommunity.getBytes("8859_1"); else if (snmpCmd == pduInformRequestPdu) return _informCommunity.getBytes("8859_1") ; else return _readCommunity.getBytes("8859_1") ; }catch(UnsupportedEncodingException e) { throw new SnmpStatusException(e.getMessage()); } } /** * Specify the default community string to use for get operations. * By default, the value is "public". */ final static String defaultRdCommunity = "public" ; /** * The protocol version. * By default, the value is SNMP version 1. * @serial */ private int _protocolVersion = snmpVersionOne ; /** * The community to be used when issuing get operations. * @serial */ private String _readCommunity ; /** * The community to be used when issuing set operations. * @serial */ private String _writeCommunity ; /** * The community to be used when issuing inform requests. * @serial */ private String _informCommunity ; /** */ //private int _retryPolicy ; // not implemented as yet. }