@Test public void shouldProperlyPEncode(){ String oid = "1.0.15628.4.1.4.1.2.3"; String tim_hex="00000083"; String bsm_hex="00000020"; String data_log_transfer_hex="0020408E"; String ota_update_hex = "0020408F"; VariableBinding vb1 = SnmpSession.getPEncodedVariableBinding(oid, tim_hex); VariableBinding vb2 = SnmpSession.getPEncodedVariableBinding(oid, bsm_hex); VariableBinding vb3 = SnmpSession.getPEncodedVariableBinding(oid, data_log_transfer_hex); VariableBinding vb4 = SnmpSession.getPEncodedVariableBinding(oid, ota_update_hex); assertEquals("P-Encoding failed for " + tim_hex,"80:03", vb1.toValueString()); assertEquals("P-Encoding failed for " + bsm_hex,"20", vb2.toValueString()); assertEquals("P-Encoding failed for " + data_log_transfer_hex,"e0:00:00:0e", vb3.toValueString()); assertEquals("P-Encoding failed for " + ota_update_hex,"e0:00:00:0f", vb4.toValueString()); }
public static VariableBinding getPEncodedVariableBinding(String oid, String val) { Integer intVal = Integer.parseInt(val, 16); Integer additionValue = null; if (intVal >= 0 && intVal <= 127) { return new VariableBinding(new OID(oid), new OctetString(Integer.toHexString(intVal))); } else if (intVal >= 128 && intVal <= 16511) { additionValue = 0x7F80; } else if (intVal >= 016512 && intVal <= 2113663) { additionValue = 0xBFBF80; } else if (intVal >= 2113664 && intVal <= 270549119) { additionValue = 0xDFDFBF80; } if (additionValue != null) { return new VariableBinding(new OID(oid), OctetString.fromString(Integer.toHexString(intVal + additionValue), 16)); } return null; }
SnmpSession { public static VariableBinding getPEncodedVariableBinding(String oid, String val) { Integer intVal = Integer.parseInt(val, 16); Integer additionValue = null; if (intVal >= 0 && intVal <= 127) { return new VariableBinding(new OID(oid), new OctetString(Integer.toHexString(intVal))); } else if (intVal >= 128 && intVal <= 16511) { additionValue = 0x7F80; } else if (intVal >= 016512 && intVal <= 2113663) { additionValue = 0xBFBF80; } else if (intVal >= 2113664 && intVal <= 270549119) { additionValue = 0xDFDFBF80; } if (additionValue != null) { return new VariableBinding(new OID(oid), OctetString.fromString(Integer.toHexString(intVal + additionValue), 16)); } return null; } }
SnmpSession { public static VariableBinding getPEncodedVariableBinding(String oid, String val) { Integer intVal = Integer.parseInt(val, 16); Integer additionValue = null; if (intVal >= 0 && intVal <= 127) { return new VariableBinding(new OID(oid), new OctetString(Integer.toHexString(intVal))); } else if (intVal >= 128 && intVal <= 16511) { additionValue = 0x7F80; } else if (intVal >= 016512 && intVal <= 2113663) { additionValue = 0xBFBF80; } else if (intVal >= 2113664 && intVal <= 270549119) { additionValue = 0xDFDFBF80; } if (additionValue != null) { return new VariableBinding(new OID(oid), OctetString.fromString(Integer.toHexString(intVal + additionValue), 16)); } return null; } SnmpSession(RSU rsu); }
SnmpSession { public static VariableBinding getPEncodedVariableBinding(String oid, String val) { Integer intVal = Integer.parseInt(val, 16); Integer additionValue = null; if (intVal >= 0 && intVal <= 127) { return new VariableBinding(new OID(oid), new OctetString(Integer.toHexString(intVal))); } else if (intVal >= 128 && intVal <= 16511) { additionValue = 0x7F80; } else if (intVal >= 016512 && intVal <= 2113663) { additionValue = 0xBFBF80; } else if (intVal >= 2113664 && intVal <= 270549119) { additionValue = 0xDFDFBF80; } if (additionValue != null) { return new VariableBinding(new OID(oid), OctetString.fromString(Integer.toHexString(intVal + additionValue), 16)); } return null; } SnmpSession(RSU rsu); ResponseEvent set(PDU pdu, Snmp snmpob, UserTarget targetob, Boolean keepOpen); ResponseEvent get(PDU pdu, Snmp snmpob, UserTarget targetob, Boolean keepOpen); void startListen(); static ResponseEvent createAndSend(SNMP snmp, RSU rsu, String payload, RequestVerb requestVerb); Snmp getSnmp(); void setSnmp(Snmp snmp); TransportMapping getTransport(); void setTransport(TransportMapping transport); UserTarget getTarget(); void setTarget(UserTarget target); void endSession(); static ScopedPDU createPDU(SNMP snmp, String payload, int index, RequestVerb verb); static VariableBinding getPEncodedVariableBinding(String oid, String val); }
SnmpSession { public static VariableBinding getPEncodedVariableBinding(String oid, String val) { Integer intVal = Integer.parseInt(val, 16); Integer additionValue = null; if (intVal >= 0 && intVal <= 127) { return new VariableBinding(new OID(oid), new OctetString(Integer.toHexString(intVal))); } else if (intVal >= 128 && intVal <= 16511) { additionValue = 0x7F80; } else if (intVal >= 016512 && intVal <= 2113663) { additionValue = 0xBFBF80; } else if (intVal >= 2113664 && intVal <= 270549119) { additionValue = 0xDFDFBF80; } if (additionValue != null) { return new VariableBinding(new OID(oid), OctetString.fromString(Integer.toHexString(intVal + additionValue), 16)); } return null; } SnmpSession(RSU rsu); ResponseEvent set(PDU pdu, Snmp snmpob, UserTarget targetob, Boolean keepOpen); ResponseEvent get(PDU pdu, Snmp snmpob, UserTarget targetob, Boolean keepOpen); void startListen(); static ResponseEvent createAndSend(SNMP snmp, RSU rsu, String payload, RequestVerb requestVerb); Snmp getSnmp(); void setSnmp(Snmp snmp); TransportMapping getTransport(); void setTransport(TransportMapping transport); UserTarget getTarget(); void setTarget(UserTarget target); void endSession(); static ScopedPDU createPDU(SNMP snmp, String payload, int index, RequestVerb verb); static VariableBinding getPEncodedVariableBinding(String oid, String val);  }