1 29 30 31 package snmp; 32 33 import java.math.BigInteger ; 34 import java.util.Vector ; 35 36 37 38 39 131 132 133 public class SNMPv2BulkRequestPDU extends SNMPSequence 134 { 135 136 137 141 142 public SNMPv2BulkRequestPDU(int requestID, int nonRepeaters, int maxRepetitions, SNMPSequence varList) 143 throws SNMPBadValueException 144 { 145 super(); 146 Vector contents = new Vector (); 147 tag = SNMPBERCodec.SNMPv2BULKREQUEST; 148 contents.insertElementAt(new SNMPInteger(requestID), 0); 149 contents.insertElementAt(new SNMPInteger(nonRepeaters), 1); 150 contents.insertElementAt(new SNMPInteger(maxRepetitions), 2); 151 contents.insertElementAt(varList, 3); 152 this.setValue(contents); 153 } 154 155 156 157 158 162 163 protected SNMPv2BulkRequestPDU(byte[] enc, byte pduType) 164 throws SNMPBadValueException 165 { 166 tag = pduType; 167 extractFromBEREncoding(enc); 168 169 Vector contents = (Vector )(this.getValue()); 171 172 if (contents.size() != 4) 173 { 174 throw new SNMPBadValueException("Bad Bulk Request PDU"); 175 } 176 177 if (!(contents.elementAt(0) instanceof SNMPInteger)) 178 { 179 throw new SNMPBadValueException("Bad Bulk Request PDU: bad request ID"); 180 } 181 182 if (!(contents.elementAt(1) instanceof SNMPInteger)) 183 { 184 throw new SNMPBadValueException("Bad Bulk Request PDU: bad non-repeaters field"); 185 } 186 187 if (!(contents.elementAt(2) instanceof SNMPInteger)) 188 { 189 throw new SNMPBadValueException("Bad Bulk Request PDU: bad max-repetitions field"); 190 } 191 192 if (!(contents.elementAt(3) instanceof SNMPSequence)) 193 { 194 throw new SNMPBadValueException("Bad Bulk Request PDU: bad variable binding list"); 195 } 196 197 SNMPSequence varBindList = this.getVarBindList(); 200 for (int i = 0; i < varBindList.size(); i++) 201 { 202 SNMPObject element = varBindList.getSNMPObjectAt(i); 203 204 if (!(element instanceof SNMPSequence)) 206 { 207 throw new SNMPBadValueException("Bad Bulk Request PDU: bad variable binding at index" + i); 208 } 209 210 SNMPSequence varBind = (SNMPSequence)element; 212 if ((varBind.size() != 2) || !(varBind.getSNMPObjectAt(0) instanceof SNMPObjectIdentifier)) 213 { 214 throw new SNMPBadValueException("Bad Bulk Request PDU: bad variable binding at index" + i); 215 } 216 } 217 218 219 } 220 221 222 223 224 230 231 public SNMPSequence getVarBindList() 232 { 233 Vector contents = (Vector )(this.getValue()); 234 return (SNMPSequence)(contents.elementAt(3)); 235 } 236 237 238 239 242 243 public int getRequestID() 244 { 245 Vector contents = (Vector )(this.getValue()); 246 return ((BigInteger )((SNMPInteger)(contents.elementAt(0))).getValue()).intValue(); 247 } 248 249 250 251 254 255 public int getNonRepeaters() 256 { 257 Vector contents = (Vector )(this.getValue()); 258 return ((BigInteger )((SNMPInteger)(contents.elementAt(1))).getValue()).intValue(); 259 } 260 261 262 263 266 267 public int getMaxRepetitions() 268 { 269 Vector contents = (Vector )(this.getValue()); 270 return ((BigInteger )((SNMPInteger)(contents.elementAt(2))).getValue()).intValue(); 271 } 272 273 274 275 278 279 public byte getPDUType() 280 { 281 return tag; 282 } 283 284 285 } | Popular Tags |