1. /*
  2. * @(#)file SnmpPdu.java
  3. * @(#)author Sun Microsystems, Inc.
  4. * @(#)version 1.10
  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;
  12. import java.io.Serializable;
  13. import java.net.InetAddress;
  14. /**
  15. * Is the fully decoded representation of an SNMP packet.
  16. * <P>
  17. * Classes are derived from <CODE>SnmpPdu</CODE> to
  18. * represent the different forms of SNMP packets
  19. * ({@link com.sun.jmx.snmp.SnmpPduPacket SnmpPduPacket},
  20. * {@link com.sun.jmx.snmp.SnmpScopedPduPacket SnmpScopedPduPacket})
  21. * <BR>The <CODE>SnmpPdu</CODE> class defines the attributes
  22. * common to every form of SNMP packets.
  23. *
  24. *
  25. * <p><b>This API is a Sun Microsystems internal API and is subject
  26. * to change without notice.</b></p>
  27. * @see SnmpMessage
  28. * @see SnmpPduFactory
  29. *
  30. * @since 1.5
  31. */
  32. public abstract class SnmpPdu implements SnmpDefinitions, Serializable {
  33. /**
  34. * PDU type. Types are defined in
  35. * {@link com.sun.jmx.snmp.SnmpDefinitions SnmpDefinitions}.
  36. * @serial
  37. */
  38. public int type=0 ;
  39. /**
  40. * Protocol version. Versions are defined in
  41. * {@link com.sun.jmx.snmp.SnmpDefinitions SnmpDefinitions}.
  42. * @serial
  43. */
  44. public int version=0 ;
  45. /**
  46. * List of variables.
  47. * @serial
  48. */
  49. public SnmpVarBind[] varBindList ;
  50. /**
  51. * Request identifier.
  52. * Note that this field is not used by <CODE>SnmpPduTrap</CODE>.
  53. * @serial
  54. */
  55. public int requestId=0 ;
  56. /**
  57. * Source or destination address.
  58. * <P>For an incoming PDU it's the source.
  59. * <BR>For an outgoing PDU it's the destination.
  60. * @serial
  61. */
  62. public InetAddress address ;
  63. /**
  64. * Source or destination port.
  65. * <P>For an incoming PDU it's the source.
  66. * <BR>For an outgoing PDU it's the destination.
  67. * @serial
  68. */
  69. public int port=0 ;
  70. /**
  71. * Returns the <CODE>String</CODE> representation of a PDU type.
  72. * For instance, if the PDU type is <CODE>SnmpDefinitions.pduGetRequestPdu</CODE>,
  73. * the method will return "SnmpGet".
  74. * @param cmd The integer representation of the PDU type.
  75. * @return The <CODE>String</CODE> representation of the PDU type.
  76. */
  77. public static String pduTypeToString(int cmd) {
  78. switch (cmd) {
  79. case pduGetRequestPdu :
  80. return "SnmpGet" ;
  81. case pduGetNextRequestPdu :
  82. return "SnmpGetNext" ;
  83. case pduWalkRequest :
  84. return "SnmpWalk(*)" ;
  85. case pduSetRequestPdu :
  86. return "SnmpSet" ;
  87. case pduGetResponsePdu :
  88. return "SnmpResponse" ;
  89. case pduV1TrapPdu :
  90. return "SnmpV1Trap" ;
  91. case pduV2TrapPdu :
  92. return "SnmpV2Trap" ;
  93. case pduGetBulkRequestPdu :
  94. return "SnmpGetBulk" ;
  95. case pduInformRequestPdu :
  96. return "SnmpInform" ;
  97. }
  98. return "Unknown Command = " + cmd ;
  99. }
  100. }