001: /*_############################################################################
002: _##
003: _## SNMP4J-AgentX - AgentXOpenPDU.java
004: _##
005: _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
006: _##
007: _## This program is free software; you can redistribute it and/or modify
008: _## it under the terms of the GNU General Public License version 2 as
009: _## published by the Free Software Foundation.
010: _##
011: _## This program is distributed in the hope that it will be useful,
012: _## but WITHOUT ANY WARRANTY; without even the implied warranty of
013: _## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: _## GNU General Public License for more details.
015: _##
016: _## You should have received a copy of the GNU General Public License
017: _## along with this program; if not, write to the Free Software
018: _## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
019: _## MA 02110-1301 USA
020: _##
021: _##########################################################################*/
022:
023: package org.snmp4j.agent.agentx;
024:
025: import java.io.*;
026: import java.nio.*;
027:
028: import org.snmp4j.smi.*;
029:
030: public class AgentXOpenPDU extends AgentXPDU {
031:
032: protected byte timeout;
033: protected OID subagentID;
034: protected OctetString subagentDescr;
035:
036: AgentXOpenPDU(AgentXMessageHeader header) {
037: super (header);
038: if (header.getType() != AGENTX_OPEN_PDU) {
039: throw new IllegalArgumentException("Incompatible PDU type");
040: }
041: }
042:
043: public AgentXOpenPDU(int sessionID, int transactionID,
044: int packetID, byte timeout, OID subagentID,
045: OctetString subagentDescr) {
046: super (AGENTX_OPEN_PDU, (byte) 0, sessionID, transactionID,
047: packetID);
048: this .timeout = timeout;
049: this .subagentID = subagentID;
050: this .subagentDescr = subagentDescr;
051: }
052:
053: public void decodePayload(ByteBuffer buf, int length)
054: throws IOException {
055: timeout = buf.get();
056: // reserved
057: buf.get();
058: buf.get();
059: buf.get();
060:
061: subagentID = new OID();
062: AgentXProtocol.decodeOID(buf, subagentID);
063: subagentDescr = AgentXProtocol.decodeOctetString(buf);
064: }
065:
066: public OctetString getSubagentDescr() {
067: return subagentDescr;
068: }
069:
070: public OID getSubagentID() {
071: return subagentID;
072: }
073:
074: public byte getTimeout() {
075: return timeout;
076: }
077:
078: public void setSubagentDescr(OctetString subagentDescr) {
079: this .subagentDescr = subagentDescr;
080: }
081:
082: public void setSubagentID(OID subagentID) {
083: this .subagentID = subagentID;
084: }
085:
086: public void setTimeout(byte timeout) {
087: this .timeout = timeout;
088: }
089:
090: public int getPayloadLength() {
091: return AgentXProtocol.AGENTX_INT_SIZE
092: + AgentXProtocol.getOIDLength(subagentID)
093: + AgentXProtocol.getOctetStringLength(subagentDescr);
094: }
095:
096: public void encodePayload(ByteBuffer buf) {
097: buf.put(timeout);
098: buf.put(new byte[] { 0, 0, 0 }); // reserved
099: AgentXProtocol.encodeOID(buf, subagentID, false);
100: AgentXProtocol.encodeOctetString(buf, subagentDescr);
101: }
102:
103: protected void beforeEncode() {
104: }
105: }
|