1 22 23 package org.snmp4j.agent.agentx; 24 25 import java.io.*; 26 import java.nio.*; 27 28 import org.snmp4j.smi.*; 29 30 public class AgentXOpenPDU extends AgentXPDU { 31 32 protected byte timeout; 33 protected OID subagentID; 34 protected OctetString subagentDescr; 35 36 AgentXOpenPDU(AgentXMessageHeader header) { 37 super(header); 38 if (header.getType() != AGENTX_OPEN_PDU) { 39 throw new IllegalArgumentException ("Incompatible PDU type"); 40 } 41 } 42 43 public AgentXOpenPDU(int sessionID, int transactionID, int packetID, 44 byte timeout, 45 OID subagentID, OctetString subagentDescr) { 46 super(AGENTX_OPEN_PDU, (byte)0, sessionID, transactionID, packetID); 47 this.timeout = timeout; 48 this.subagentID = subagentID; 49 this.subagentDescr = subagentDescr; 50 } 51 52 public void decodePayload(ByteBuffer buf, int length) throws IOException { 53 timeout = buf.get(); 54 buf.get(); 56 buf.get(); 57 buf.get(); 58 59 subagentID = new OID(); 60 AgentXProtocol.decodeOID(buf, subagentID); 61 subagentDescr = AgentXProtocol.decodeOctetString(buf); 62 } 63 64 public OctetString getSubagentDescr() { 65 return subagentDescr; 66 } 67 68 public OID getSubagentID() { 69 return subagentID; 70 } 71 72 public byte getTimeout() { 73 return timeout; 74 } 75 76 public void setSubagentDescr(OctetString subagentDescr) { 77 this.subagentDescr = subagentDescr; 78 } 79 80 public void setSubagentID(OID subagentID) { 81 this.subagentID = subagentID; 82 } 83 84 public void setTimeout(byte timeout) { 85 this.timeout = timeout; 86 } 87 88 public int getPayloadLength() { 89 return AgentXProtocol.AGENTX_INT_SIZE + 90 AgentXProtocol.getOIDLength(subagentID) + 91 AgentXProtocol.getOctetStringLength(subagentDescr); 92 } 93 94 public void encodePayload(ByteBuffer buf) { 95 buf.put(timeout); 96 buf.put(new byte[] { 0,0,0 }); AgentXProtocol.encodeOID(buf, subagentID, false); 98 AgentXProtocol.encodeOctetString(buf, subagentDescr); 99 } 100 101 protected void beforeEncode() { 102 } 103 } 104 | Popular Tags |