-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSnmpOperator.java
More file actions
executable file
·71 lines (63 loc) · 1.87 KB
/
SnmpOperator.java
File metadata and controls
executable file
·71 lines (63 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*Prepares SNMP packets (get, getnext, bulk ....)
* and returns the response PDU
*/
import com.adventnet.snmp.snmp2.*;
public class SnmpOperator {
private SnmpPDU responsePDU = null;
//GET
public SnmpPDU get(SnmpPDU pdu, SnmpSession session, SnmpOID oid){
pdu.setCommand( SnmpAPI.GET_REQ_MSG);
pdu.removeVariableBinding(0);
pdu.addNull(oid);
try {
responsePDU = session.syncSend(pdu);
} catch (SnmpException e) {
System.out.println("SNMPOperator get");
e.printStackTrace();
}
return responsePDU;
}
//GETNEXT
public SnmpPDU getnext(SnmpPDU pdu, SnmpSession session,SnmpOID oid){
pdu.setCommand(SnmpAPI.GETNEXT_REQ_MSG);
pdu.removeVariableBinding(0);
pdu.addNull(oid);
try{
responsePDU = session.syncSend(pdu);
} catch (SnmpException e) {
System.out.println("SNMPOperator getnext");
e.printStackTrace();
}
return responsePDU;
}
//GETBULK
public SnmpPDU getbulk(SnmpPDU pdu, SnmpSession session,SnmpOID oid, int repetitions){
pdu.setCommand( SnmpAPI.GETBULK_REQ_MSG);
pdu.setMaxRepetitions(repetitions);
pdu.removeVariableBinding(0);
pdu.addNull(oid);
try{
responsePDU = session.syncSend(pdu);
} catch (SnmpException e) {
System.out.println("SNMPOperator getbulk");
e.printStackTrace();
}
return responsePDU;
}
//Extended GETBULK
public SnmpPDU getSeveralBulk(SnmpPDU pdu, SnmpSession session,SnmpOID oidSingle,SnmpOID oidBulk, int repetitions){
pdu.setCommand(SnmpAPI.GETBULK_REQ_MSG);
pdu.setNonRepeaters(1);//which one is executed only once
pdu.setMaxRepetitions(repetitions);
pdu.removeVariableBinding(0);
pdu.addNull(oidSingle);
pdu.addNull(oidBulk);
try{
responsePDU = session.syncSend(pdu);
} catch (SnmpException e) {
System.out.println("SNMPOperator getbulk");
e.printStackTrace();
}
return responsePDU;
}
}