jdk/src/share/classes/com/sun/jmx/snmp/SnmpPdu.java
author alanb
Fri, 02 Nov 2012 15:50:11 +0000
changeset 14342 8435a30053c1
parent 5506 202f599c92aa
child 23711 95fb268275e3
permissions -rw-r--r--
7197491: update copyright year to match last edit in jdk8 jdk repository Reviewed-by: chegar, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2001, 2003, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package com.sun.jmx.snmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.net.InetAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * Is the fully decoded representation of an SNMP packet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * Classes are derived from <CODE>SnmpPdu</CODE> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * represent the different forms of SNMP packets
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * ({@link com.sun.jmx.snmp.SnmpPduPacket SnmpPduPacket},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * {@link com.sun.jmx.snmp.SnmpScopedPduPacket SnmpScopedPduPacket})
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <BR>The <CODE>SnmpPdu</CODE> class defines the attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * common to every form of SNMP packets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p><b>This API is a Sun Microsystems internal API  and is subject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * to change without notice.</b></p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @see SnmpMessage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @see SnmpPduFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
public abstract class SnmpPdu implements SnmpDefinitions, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * PDU type. Types are defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * {@link com.sun.jmx.snmp.SnmpDefinitions SnmpDefinitions}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public int type=0 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * Protocol version. Versions are defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * {@link com.sun.jmx.snmp.SnmpDefinitions SnmpDefinitions}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public int version=0 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * List of variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public SnmpVarBind[] varBindList ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * Request identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Note that this field is not used by <CODE>SnmpPduTrap</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public int requestId=0 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * Source or destination address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * <P>For an incoming PDU it's the source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * <BR>For an outgoing PDU it's the destination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public InetAddress address ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Source or destination port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * <P>For an incoming PDU it's the source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * <BR>For an outgoing PDU it's the destination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public int port=0 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * Returns the <CODE>String</CODE> representation of a PDU type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * For instance, if the PDU type is <CODE>SnmpDefinitions.pduGetRequestPdu</CODE>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * the method will return "SnmpGet".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @param cmd The integer representation of the PDU type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @return The <CODE>String</CODE> representation of the PDU type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public static String pduTypeToString(int cmd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        switch (cmd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        case pduGetRequestPdu :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            return "SnmpGet" ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        case pduGetNextRequestPdu :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            return "SnmpGetNext" ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        case pduWalkRequest :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            return "SnmpWalk(*)" ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        case pduSetRequestPdu :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            return "SnmpSet" ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        case pduGetResponsePdu :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            return "SnmpResponse" ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        case pduV1TrapPdu :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            return "SnmpV1Trap" ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        case pduV2TrapPdu :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            return "SnmpV2Trap" ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        case pduGetBulkRequestPdu :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            return "SnmpGetBulk" ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        case pduInformRequestPdu :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            return "SnmpInform" ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        return "Unknown Command = " + cmd ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
}