1 // NAME
2 // $RCSfile: TrapPduv2.java,v $
3 // DESCRIPTION
4 // [given below in javadoc format]
5 // DELTA
6 // $Revision: 3.11 $
7 // CREATED
8 // $Date: 2006/03/23 14:54:10 $
9 // COPYRIGHT
10 // Westhawk Ltd
11 // TO DO
12 //
13
14 /*
15 * Copyright (C) 2001 - 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.stack;
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
52 /**
53 * This class represents the ASN SNMP v2c (and higher) Trap PDU object.
54 * This PDU is not supported in SNMPv1.
55 *
56 * <p>
57 * See <a href="http://www.ietf.org/rfc/rfc3416.txt">SNMPv2-PDU</a>;<br/>
58 * The variable bindings list contains the following pairs of object
59 * names and values:
60 <ul>
61 <li>sysUpTime.0
62 (<a href="http://www.ietf.org/rfc/rfc3418.txt">SNMPv2-MIB</a>)
63 </li>
64 <li>snmpTrapOID.0: part of the trap group in the SNMPv2 MIB
65 (<a href="http://www.ietf.org/rfc/rfc3418.txt">SNMPv2-MIB</a>)
66 </li>
67 <li>If the OBJECTS clause is present in the corresponding
68 invocation of the macro NOTIFICATION-TYPE, then each corresponding
69 variable and its value are copied to the variable-bindings field.
70 </li>
71 <li>Additional variables may be included at the option of the agent.
72 </li>
73 </ul>
74 *
75 * <p>
76 * For SNMPv3: The sender of a trap PDU acts as the authoritative engine.
77 * </p>
78 *
79 * @see TrapPduv1
80 * @author <a href="mailto:snmp@westhawk.co.uk">Birgit Arkesteijn</a>
81 * @version $Revision: 3.11 $ $Date: 2006/03/23 14:54:10 $
82 */
83 public class TrapPduv2 extends Pdu {
84 private static final String version_id = "@(#)$Id: TrapPduv2.java,v 3.11 2006/03/23 14:54:10 birgit Exp $ Copyright Westhawk Ltd";
85
86 /**
87 * Constructor.
88 *
89 * @param con The context (v2c or v3) of the PDU
90 * @throws IllegalArgumentException if the context version is
91 * SNMPv1
92 */
93 public TrapPduv2(SnmpContextBasisFace con) {
94 super(con);
95 setMsgType(AsnObject.TRPV2_REQ_MSG);
96
97 if (con.getVersion() == SnmpConstants.SNMP_VERSION_1) {
98 throw new IllegalArgumentException("A TrapPduv2"
99 + " can only be sent with an SNMPv2c or SNMPv3 context."
100 + " NOT with an SNMPv1 context!");
101 }
102 }
103
104 /**
105 * The trap PDU does not get a response back. So it should be sent once.
106 *
107 */
108 void transmit() {
109 transmit(false);
110 }
111
112 /**
113 * Returns the string representation of this object.
114 *
115 * @return The string of the PDU
116 */
117 public String toString() {
118 return super.toString(true);
119 }
120
121 /**
122 * Has no meaning, since there is not response.
123 */
124 protected void new_value(int n, varbind res) {
125 }
126
127 /**
128 * Has no meaning, since there is not response.
129 */
130 protected void tell_them() {
131 }
132
133 /**
134 * Returns that this type of PDU is <em>not</em> expecting a response.
135 * This method is used in AbstractSnmpContext to help determine whether
136 * or not to start a thread that listens for a response when sending this
137 * PDU.
138 * The default is <em>false</em>.
139 *
140 * @return true if a response is expected, false if not.
141 * @since 4_14
142 */
143 protected boolean isExpectingResponse() {
144 return false;
145 }
146
147 }