1 // NAME
2 // $RCSfile: DiscoveryPdu.java,v $
3 // DESCRIPTION
4 // [given below in javadoc format]
5 // DELTA
6 // $Revision: 3.15 $
7 // CREATED
8 // $Date: 2006/11/29 16:12:50 $
9 // COPYRIGHT
10 // Westhawk Ltd
11 // TO DO
12 //
13
14 /*
15 * Copyright (C) 2000 - 2006 by Westhawk Ltd
16 * <a href="www.westhawk.co.uk">www.westhawk.co.uk</a>
17 *
18 * Permission to use, copy, modify, and distribute this software
19 * for any purpose and without fee is hereby granted, provided
20 * that the above copyright notices appear in all copies and that
21 * both the copyright notice and this permission notice appear in
22 * supporting documentation.
23 * This software is provided "as is" without express or implied
24 * warranty.
25 * author <a href="mailto:snmp@westhawk.co.uk">Tim Panton</a>
26 */
27
28 package uk.co.westhawk.snmp.pdu;
29
30 /*-
31 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
32 * SNMP Java Client
33 * ჻჻჻჻჻჻
34 * Copyright 2023 MetricsHub, Westhawk
35 * ჻჻჻჻჻჻
36 * This program is free software: you can redistribute it and/or modify
37 * it under the terms of the GNU Lesser General Public License as
38 * published by the Free Software Foundation, either version 3 of the
39 * License, or (at your option) any later version.
40 *
41 * This program is distributed in the hope that it will be useful,
42 * but WITHOUT ANY WARRANTY; without even the implied warranty of
43 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 * GNU General Lesser Public License for more details.
45 *
46 * You should have received a copy of the GNU General Lesser Public
47 * License along with this program. If not, see
48 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
49 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
50 */
51 import uk.co.westhawk.snmp.stack.*;
52 import java.util.*;
53
54 /**
55 * This class is used to perform the SNMPv3 USM discovery.
56 * This PDU cannot have any OIDs.
57 *
58 * <p>
59 * See <a href="http://www.ietf.org/rfc/rfc3414.txt">SNMP-USER-BASED-SM-MIB</a>.
60 * </p>
61 * @author <a href="mailto:snmp@westhawk.co.uk">Birgit Arkesteijn</a>
62 * @version $Revision: 3.15 $ $Date: 2006/11/29 16:12:50 $
63 */
64 public class DiscoveryPdu extends GetPdu {
65 private static final String version_id = "@(#)$Id: DiscoveryPdu.java,v 3.15 2006/11/29 16:12:50 birgit Exp $ Copyright Westhawk Ltd";
66
67 private SnmpContextv3Face context;
68
69 /**
70 * Constructor.
71 *
72 * @param cntxt The v3 context of the PDU
73 */
74 public DiscoveryPdu(SnmpContextv3Face cntxt) {
75 super(cntxt);
76 context = cntxt;
77 }
78
79 /**
80 * Cannot add any OID. This method is overwritten to prevent users from
81 * adding any OID.
82 *
83 * @exception IllegalArgumentException A discovery PDU cannot have any
84 * OID.
85 */
86 public void addOid(String oid)
87 throws IllegalArgumentException {
88 throw new IllegalArgumentException("DiscoveryPdu cannot have OID");
89 }
90
91 /**
92 * Cannot add any OID. This method is overwritten to prevent users from
93 * adding any OID.
94 *
95 * @exception IllegalArgumentException A discovery PDU cannot have any
96 * OID.
97 * @since 4_12
98 */
99 public void addOid(String oid, AsnObject val) {
100 throw new IllegalArgumentException("DiscoveryPdu cannot have OID");
101 }
102
103 /**
104 * Cannot add any OID. This method is overwritten to prevent users from
105 * adding any OID.
106 *
107 * @exception IllegalArgumentException A discovery PDU cannot have any
108 * OID.
109 * @since 4_12
110 */
111 public void addOid(AsnObjectId oid, AsnObject val) {
112 throw new IllegalArgumentException("DiscoveryPdu cannot have OID");
113 }
114
115 /**
116 * Cannot add any OID. This method is overwritten to prevent users from
117 * adding any OID.
118 *
119 * @exception IllegalArgumentException A discovery PDU cannot have any
120 * OID.
121 */
122 public void addOid(varbind var)
123 throws IllegalArgumentException {
124 throw new IllegalArgumentException("DiscoveryPdu cannot have OID");
125 }
126
127 /**
128 * Cannot add any OID. This method is overwritten to prevent users from
129 * adding any OID.
130 *
131 * @exception IllegalArgumentException A discovery PDU cannot have any
132 * OID.
133 * @since 4_12
134 */
135 public void addOid(AsnObjectId oid) {
136 throw new IllegalArgumentException("DiscoveryPdu cannot have OID");
137 }
138
139 /**
140 * Sends the PDU.
141 * Note that all properties of the context have to be set before this
142 * point.
143 */
144 public boolean send() throws java.io.IOException, PduException {
145 if (added == false) {
146 // Moved this statement from the constructor because it
147 // conflicts with the way the SnmpContextXPool works.
148 added = context.addDiscoveryPdu(this);
149 }
150 Enumeration vbs = reqVarbinds.elements();
151 encodedPacket = context.encodeDiscoveryPacket(msg_type, getReqId(),
152 getErrorStatus(), getErrorIndex(), vbs, snmpv3MsgId);
153 addToTrans();
154 return added;
155 }
156
157 }