1 // NAME 2 // $RCSfile: GetBulkPdu.java,v $ 3 // DESCRIPTION 4 // [given below in javadoc format] 5 // DELTA 6 // $Revision: 3.17 $ 7 // CREATED 8 // $Date: 2006/02/09 14:30:19 $ 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.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 * This class represents the SNMP GetBulk Pdu. This request has been 53 * added in SNMPv2c, hence is not supported by SNMPv1 agents. 54 * 55 * <p> 56 * The request is processed on the agent side in the following way: 57 * <pre> 58 * // getNext (once) on the non_repeaters 59 * for (n=0; n<N; n++) 60 * { 61 * getNext(var[n]); 62 * } 63 * // getNext (max_repetitions times) on the repeaters 64 * for (m=1; m<M; m++) 65 * { 66 * for (r=1; r<R; r++) 67 * { 68 * getNext(var[N+r]); 69 * } 70 * } 71 * </pre> 72 * 73 * <p> 74 * Where:<br> 75 * <ul> 76 * <li><code>L</code> is the number of vars in the request </li> 77 * <li><code>N = Max(Min(non_repeaters, L), 0)</code></li> 78 * <li><code>M = Max(max_repetitions, 0)</code></li> 79 * <li><code>R = L-N</code></li> 80 * </ul> 81 * 82 * @author <a href="mailto:snmp@westhawk.co.uk">Birgit Arkesteijn</a> 83 * @version $Revision: 3.17 $ $Date: 2006/02/09 14:30:19 $ 84 */ 85 public class GetBulkPdu extends Pdu { 86 private static final String version_id = "@(#)$Id: GetBulkPdu.java,v 3.17 2006/02/09 14:30:19 birgit Exp $ Copyright Westhawk Ltd"; 87 88 /** 89 * The value of the non_repeaters. 90 */ 91 protected int non_repeaters = 0; 92 /** 93 * The value of the max_repetitions. 94 */ 95 protected int max_repetitions = 0; 96 97 /** 98 * Constructor. 99 * The GetBulkRequest has been added in SNMPv2. Its purpose is to 100 * retrieve a large amount of information with one request. 101 * 102 * @param con The context (v2c or v3) of the Pdu 103 */ 104 public GetBulkPdu(SnmpContextBasisFace con) { 105 super(con); 106 setMsgType(AsnObject.GETBULK_REQ_MSG); 107 } 108 109 /** 110 * Sets the non_repeaters. The non_repeaters specifies the number of 111 * variables in the varbind list for which a single lexicographic 112 * successor is to be returned. 113 * If they are not set, the value will be 0 (zero). 114 */ 115 public void setNonRepeaters(int no) { 116 // same field as error status in any other PDU. 117 non_repeaters = no; 118 } 119 120 /** 121 * Returns the non_repeaters. 122 */ 123 public int getNonRepeaters() { 124 return non_repeaters; 125 } 126 127 /** 128 * Sets the max_repetitions. The max_repetitions specifies the number of 129 * lexicographic successors to be returned for the remaining variables 130 * in the varbind list. 131 * If they are not set, the value will be 0 (zero). 132 */ 133 public void setMaxRepetitions(int no) { 134 // same field as error index in any other PDU. 135 max_repetitions = no; 136 } 137 138 /** 139 * Old method to set the max_repetitions. Was a spelling mistake, 140 * it is still in here for backwards compatibility. 141 * 142 * @deprecated Use {@link #setMaxRepetitions(int no)}. 143 * @see #setMaxRepetitions 144 */ 145 public void setMaxRepititions(int no) { 146 setMaxRepetitions(no); 147 } 148 149 /** 150 * Returns the max_repetitions. 151 */ 152 public int getMaxRepetitions() { 153 return max_repetitions; 154 } 155 156 /** 157 * Sends the Pdu. 158 * 159 * <p> 160 * The GetBulk request has the same format as any other request, except 161 * that the error_status field is replaced by non_repeaters and the 162 * error_index field is replaces by max_repetitions. 163 * </p> 164 * 165 * @see Pdu#send(int, int) 166 */ 167 public boolean send() throws java.io.IOException, PduException { 168 return send(non_repeaters, max_repetitions); 169 } 170 171 /** 172 * Returns a string representation of the object. 173 * 174 * @return The string 175 */ 176 public String toString() { 177 StringBuffer buffer = new StringBuffer(super.toString()); 178 int l = buffer.length(); 179 buffer.setLength(l - 1); 180 181 buffer.append(", non_rep=").append(getNonRepeaters()); 182 buffer.append(", max_rep=").append(getMaxRepetitions()); 183 buffer.append("]"); 184 return buffer.toString(); 185 } 186 187 }