KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > agent > agentx > AgentXOpenPDU


1 /*_############################################################################
2   _##
3   _## SNMP4J-AgentX - AgentXOpenPDU.java
4   _##
5   _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
6   _##
7   _## This program is free software; you can redistribute it and/or modify
8   _## it under the terms of the GNU General Public License version 2 as
9   _## published by the Free Software Foundation.
10   _##
11   _## This program is distributed in the hope that it will be useful,
12   _## but WITHOUT ANY WARRANTY; without even the implied warranty of
13   _## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14   _## GNU General Public License for more details.
15   _##
16   _## You should have received a copy of the GNU General Public License
17   _## along with this program; if not, write to the Free Software
18   _## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19   _## MA 02110-1301 USA
20   _##
21   _##########################################################################*/

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 JavaDoc("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     // reserved
55
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 }); // reserved
97
AgentXProtocol.encodeOID(buf, subagentID, false);
98     AgentXProtocol.encodeOctetString(buf, subagentDescr);
99   }
100
101   protected void beforeEncode() {
102   }
103 }
104
Popular Tags