@Test public void shouldCreatePDU() throws ParseException { String expectedResult = "[1.0.15628.4.1.4.1.2.3 = 80:03, 1.0.15628.4.1.4.1.3.3 = 2, 1.0.15628.4.1.4.1.4.3 = 3, 1.0.15628.4.1.4.1.5.3 = 4, 1.0.15628.4.1.4.1.6.3 = 5, 1.0.15628.4.1.4.1.7.3 = 07:e1:0c:02:11:2f, 1.0.15628.4.1.4.1.8.3 = 07:e1:0c:02:11:2f, 1.0.15628.4.1.4.1.9.3 = 88, 1.0.15628.4.1.4.1.10.3 = 9, 1.0.15628.4.1.4.1.11.3 = 10]"; String expectedResult2 = "[1.0.15628.4.1.4.1.2.3 = 80:03, 1.0.15628.4.1.4.1.3.3 = 2, 1.0.15628.4.1.4.1.4.3 = 3, 1.0.15628.4.1.4.1.5.3 = 4, 1.0.15628.4.1.4.1.6.3 = 5, 1.0.15628.4.1.4.1.7.3 = 07:e1:0c:02:11:2f, 1.0.15628.4.1.4.1.8.3 = 07:e1:0c:02:11:2f, 1.0.15628.4.1.4.1.9.3 = 88, 1.0.15628.4.1.4.1.10.3 = 9]"; String rsuSRMPsid = "00000083"; int rsuSRMDsrcMsgId = 2; int rsuSRMTxMode = 3; int rsuSRMTxChannel = 4; int rsuSRMTxInterval = 5; String rsuSRMPayload = "88"; int rsuSRMEnable = 9; int rsuSRMStatus = 10; SNMP testParams = new SNMP(rsuSRMPsid, rsuSRMDsrcMsgId, rsuSRMTxMode, rsuSRMTxChannel, rsuSRMTxInterval, "2017-12-02T17:47:11-05:00", "2017-12-02T17:47:11-05:00", rsuSRMEnable, rsuSRMStatus); ScopedPDU result = SnmpSession.createPDU(testParams, rsuSRMPayload, 3, RequestVerb.POST); assertEquals("Incorrect type, expected PDU.SET (-93)", -93, result.getType()); assertEquals(expectedResult, result.getVariableBindings().toString()); ScopedPDU result2 = SnmpSession.createPDU(testParams, rsuSRMPayload, 3, RequestVerb.GET); assertEquals("Incorrect type, expected PDU.SET (-93)", -93, result2.getType()); assertEquals(expectedResult2, result2.getVariableBindings().toString()); }
public static ScopedPDU createPDU(SNMP snmp, String payload, int index, RequestVerb verb) throws ParseException { VariableBinding rsuSRMPsid = SnmpSession.getPEncodedVariableBinding("1.0.15628.4.1.4.1.2.".concat(Integer.toString(index)), snmp.getRsuid()); VariableBinding rsuSRMDsrcMsgId = new VariableBinding( new OID("1.0.15628.4.1.4.1.3.".concat(Integer.toString(index))), new Integer32(snmp.getMsgid())); VariableBinding rsuSRMTxMode = new VariableBinding( new OID("1.0.15628.4.1.4.1.4.".concat(Integer.toString(index))), new Integer32(snmp.getMode())); VariableBinding rsuSRMTxChannel = new VariableBinding( new OID("1.0.15628.4.1.4.1.5.".concat(Integer.toString(index))), new Integer32(snmp.getChannel())); VariableBinding rsuSRMTxInterval = new VariableBinding( new OID("1.0.15628.4.1.4.1.6.".concat(Integer.toString(index))), new Integer32(snmp.getInterval())); VariableBinding rsuSRMDeliveryStart = new VariableBinding( new OID("1.0.15628.4.1.4.1.7.".concat(Integer.toString(index))), new OctetString(DatatypeConverter.parseHexBinary(SNMP.snmpTimestampFromIso(snmp.getDeliverystart())))); VariableBinding rsuSRMDeliveryStop = new VariableBinding( new OID("1.0.15628.4.1.4.1.8.".concat(Integer.toString(index))), new OctetString(DatatypeConverter.parseHexBinary(SNMP.snmpTimestampFromIso(snmp.getDeliverystop())))); VariableBinding rsuSRMPayload = new VariableBinding( new OID("1.0.15628.4.1.4.1.9.".concat(Integer.toString(index))), new OctetString(DatatypeConverter.parseHexBinary(payload))); VariableBinding rsuSRMEnable = new VariableBinding( new OID("1.0.15628.4.1.4.1.10.".concat(Integer.toString(index))), new Integer32(snmp.getEnable())); VariableBinding rsuSRMStatus = new VariableBinding( new OID("1.0.15628.4.1.4.1.11.".concat(Integer.toString(index))), new Integer32(snmp.getStatus())); ScopedPDU pdu = new ScopedPDU(); pdu.add(rsuSRMPsid); pdu.add(rsuSRMDsrcMsgId); pdu.add(rsuSRMTxMode); pdu.add(rsuSRMTxChannel); pdu.add(rsuSRMTxInterval); pdu.add(rsuSRMDeliveryStart); pdu.add(rsuSRMDeliveryStop); pdu.add(rsuSRMPayload); pdu.add(rsuSRMEnable); if (verb == ServiceRequest.OdeInternal.RequestVerb.POST) { pdu.add(rsuSRMStatus); } pdu.setType(PDU.SET); return pdu; }
SnmpSession { public static ScopedPDU createPDU(SNMP snmp, String payload, int index, RequestVerb verb) throws ParseException { VariableBinding rsuSRMPsid = SnmpSession.getPEncodedVariableBinding("1.0.15628.4.1.4.1.2.".concat(Integer.toString(index)), snmp.getRsuid()); VariableBinding rsuSRMDsrcMsgId = new VariableBinding( new OID("1.0.15628.4.1.4.1.3.".concat(Integer.toString(index))), new Integer32(snmp.getMsgid())); VariableBinding rsuSRMTxMode = new VariableBinding( new OID("1.0.15628.4.1.4.1.4.".concat(Integer.toString(index))), new Integer32(snmp.getMode())); VariableBinding rsuSRMTxChannel = new VariableBinding( new OID("1.0.15628.4.1.4.1.5.".concat(Integer.toString(index))), new Integer32(snmp.getChannel())); VariableBinding rsuSRMTxInterval = new VariableBinding( new OID("1.0.15628.4.1.4.1.6.".concat(Integer.toString(index))), new Integer32(snmp.getInterval())); VariableBinding rsuSRMDeliveryStart = new VariableBinding( new OID("1.0.15628.4.1.4.1.7.".concat(Integer.toString(index))), new OctetString(DatatypeConverter.parseHexBinary(SNMP.snmpTimestampFromIso(snmp.getDeliverystart())))); VariableBinding rsuSRMDeliveryStop = new VariableBinding( new OID("1.0.15628.4.1.4.1.8.".concat(Integer.toString(index))), new OctetString(DatatypeConverter.parseHexBinary(SNMP.snmpTimestampFromIso(snmp.getDeliverystop())))); VariableBinding rsuSRMPayload = new VariableBinding( new OID("1.0.15628.4.1.4.1.9.".concat(Integer.toString(index))), new OctetString(DatatypeConverter.parseHexBinary(payload))); VariableBinding rsuSRMEnable = new VariableBinding( new OID("1.0.15628.4.1.4.1.10.".concat(Integer.toString(index))), new Integer32(snmp.getEnable())); VariableBinding rsuSRMStatus = new VariableBinding( new OID("1.0.15628.4.1.4.1.11.".concat(Integer.toString(index))), new Integer32(snmp.getStatus())); ScopedPDU pdu = new ScopedPDU(); pdu.add(rsuSRMPsid); pdu.add(rsuSRMDsrcMsgId); pdu.add(rsuSRMTxMode); pdu.add(rsuSRMTxChannel); pdu.add(rsuSRMTxInterval); pdu.add(rsuSRMDeliveryStart); pdu.add(rsuSRMDeliveryStop); pdu.add(rsuSRMPayload); pdu.add(rsuSRMEnable); if (verb == ServiceRequest.OdeInternal.RequestVerb.POST) { pdu.add(rsuSRMStatus); } pdu.setType(PDU.SET); return pdu; } }
SnmpSession { public static ScopedPDU createPDU(SNMP snmp, String payload, int index, RequestVerb verb) throws ParseException { VariableBinding rsuSRMPsid = SnmpSession.getPEncodedVariableBinding("1.0.15628.4.1.4.1.2.".concat(Integer.toString(index)), snmp.getRsuid()); VariableBinding rsuSRMDsrcMsgId = new VariableBinding( new OID("1.0.15628.4.1.4.1.3.".concat(Integer.toString(index))), new Integer32(snmp.getMsgid())); VariableBinding rsuSRMTxMode = new VariableBinding( new OID("1.0.15628.4.1.4.1.4.".concat(Integer.toString(index))), new Integer32(snmp.getMode())); VariableBinding rsuSRMTxChannel = new VariableBinding( new OID("1.0.15628.4.1.4.1.5.".concat(Integer.toString(index))), new Integer32(snmp.getChannel())); VariableBinding rsuSRMTxInterval = new VariableBinding( new OID("1.0.15628.4.1.4.1.6.".concat(Integer.toString(index))), new Integer32(snmp.getInterval())); VariableBinding rsuSRMDeliveryStart = new VariableBinding( new OID("1.0.15628.4.1.4.1.7.".concat(Integer.toString(index))), new OctetString(DatatypeConverter.parseHexBinary(SNMP.snmpTimestampFromIso(snmp.getDeliverystart())))); VariableBinding rsuSRMDeliveryStop = new VariableBinding( new OID("1.0.15628.4.1.4.1.8.".concat(Integer.toString(index))), new OctetString(DatatypeConverter.parseHexBinary(SNMP.snmpTimestampFromIso(snmp.getDeliverystop())))); VariableBinding rsuSRMPayload = new VariableBinding( new OID("1.0.15628.4.1.4.1.9.".concat(Integer.toString(index))), new OctetString(DatatypeConverter.parseHexBinary(payload))); VariableBinding rsuSRMEnable = new VariableBinding( new OID("1.0.15628.4.1.4.1.10.".concat(Integer.toString(index))), new Integer32(snmp.getEnable())); VariableBinding rsuSRMStatus = new VariableBinding( new OID("1.0.15628.4.1.4.1.11.".concat(Integer.toString(index))), new Integer32(snmp.getStatus())); ScopedPDU pdu = new ScopedPDU(); pdu.add(rsuSRMPsid); pdu.add(rsuSRMDsrcMsgId); pdu.add(rsuSRMTxMode); pdu.add(rsuSRMTxChannel); pdu.add(rsuSRMTxInterval); pdu.add(rsuSRMDeliveryStart); pdu.add(rsuSRMDeliveryStop); pdu.add(rsuSRMPayload); pdu.add(rsuSRMEnable); if (verb == ServiceRequest.OdeInternal.RequestVerb.POST) { pdu.add(rsuSRMStatus); } pdu.setType(PDU.SET); return pdu; } SnmpSession(RSU rsu); }
SnmpSession { public static ScopedPDU createPDU(SNMP snmp, String payload, int index, RequestVerb verb) throws ParseException { VariableBinding rsuSRMPsid = SnmpSession.getPEncodedVariableBinding("1.0.15628.4.1.4.1.2.".concat(Integer.toString(index)), snmp.getRsuid()); VariableBinding rsuSRMDsrcMsgId = new VariableBinding( new OID("1.0.15628.4.1.4.1.3.".concat(Integer.toString(index))), new Integer32(snmp.getMsgid())); VariableBinding rsuSRMTxMode = new VariableBinding( new OID("1.0.15628.4.1.4.1.4.".concat(Integer.toString(index))), new Integer32(snmp.getMode())); VariableBinding rsuSRMTxChannel = new VariableBinding( new OID("1.0.15628.4.1.4.1.5.".concat(Integer.toString(index))), new Integer32(snmp.getChannel())); VariableBinding rsuSRMTxInterval = new VariableBinding( new OID("1.0.15628.4.1.4.1.6.".concat(Integer.toString(index))), new Integer32(snmp.getInterval())); VariableBinding rsuSRMDeliveryStart = new VariableBinding( new OID("1.0.15628.4.1.4.1.7.".concat(Integer.toString(index))), new OctetString(DatatypeConverter.parseHexBinary(SNMP.snmpTimestampFromIso(snmp.getDeliverystart())))); VariableBinding rsuSRMDeliveryStop = new VariableBinding( new OID("1.0.15628.4.1.4.1.8.".concat(Integer.toString(index))), new OctetString(DatatypeConverter.parseHexBinary(SNMP.snmpTimestampFromIso(snmp.getDeliverystop())))); VariableBinding rsuSRMPayload = new VariableBinding( new OID("1.0.15628.4.1.4.1.9.".concat(Integer.toString(index))), new OctetString(DatatypeConverter.parseHexBinary(payload))); VariableBinding rsuSRMEnable = new VariableBinding( new OID("1.0.15628.4.1.4.1.10.".concat(Integer.toString(index))), new Integer32(snmp.getEnable())); VariableBinding rsuSRMStatus = new VariableBinding( new OID("1.0.15628.4.1.4.1.11.".concat(Integer.toString(index))), new Integer32(snmp.getStatus())); ScopedPDU pdu = new ScopedPDU(); pdu.add(rsuSRMPsid); pdu.add(rsuSRMDsrcMsgId); pdu.add(rsuSRMTxMode); pdu.add(rsuSRMTxChannel); pdu.add(rsuSRMTxInterval); pdu.add(rsuSRMDeliveryStart); pdu.add(rsuSRMDeliveryStop); pdu.add(rsuSRMPayload); pdu.add(rsuSRMEnable); if (verb == ServiceRequest.OdeInternal.RequestVerb.POST) { pdu.add(rsuSRMStatus); } pdu.setType(PDU.SET); return pdu; } 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 ScopedPDU createPDU(SNMP snmp, String payload, int index, RequestVerb verb) throws ParseException { VariableBinding rsuSRMPsid = SnmpSession.getPEncodedVariableBinding("1.0.15628.4.1.4.1.2.".concat(Integer.toString(index)), snmp.getRsuid()); VariableBinding rsuSRMDsrcMsgId = new VariableBinding( new OID("1.0.15628.4.1.4.1.3.".concat(Integer.toString(index))), new Integer32(snmp.getMsgid())); VariableBinding rsuSRMTxMode = new VariableBinding( new OID("1.0.15628.4.1.4.1.4.".concat(Integer.toString(index))), new Integer32(snmp.getMode())); VariableBinding rsuSRMTxChannel = new VariableBinding( new OID("1.0.15628.4.1.4.1.5.".concat(Integer.toString(index))), new Integer32(snmp.getChannel())); VariableBinding rsuSRMTxInterval = new VariableBinding( new OID("1.0.15628.4.1.4.1.6.".concat(Integer.toString(index))), new Integer32(snmp.getInterval())); VariableBinding rsuSRMDeliveryStart = new VariableBinding( new OID("1.0.15628.4.1.4.1.7.".concat(Integer.toString(index))), new OctetString(DatatypeConverter.parseHexBinary(SNMP.snmpTimestampFromIso(snmp.getDeliverystart())))); VariableBinding rsuSRMDeliveryStop = new VariableBinding( new OID("1.0.15628.4.1.4.1.8.".concat(Integer.toString(index))), new OctetString(DatatypeConverter.parseHexBinary(SNMP.snmpTimestampFromIso(snmp.getDeliverystop())))); VariableBinding rsuSRMPayload = new VariableBinding( new OID("1.0.15628.4.1.4.1.9.".concat(Integer.toString(index))), new OctetString(DatatypeConverter.parseHexBinary(payload))); VariableBinding rsuSRMEnable = new VariableBinding( new OID("1.0.15628.4.1.4.1.10.".concat(Integer.toString(index))), new Integer32(snmp.getEnable())); VariableBinding rsuSRMStatus = new VariableBinding( new OID("1.0.15628.4.1.4.1.11.".concat(Integer.toString(index))), new Integer32(snmp.getStatus())); ScopedPDU pdu = new ScopedPDU(); pdu.add(rsuSRMPsid); pdu.add(rsuSRMDsrcMsgId); pdu.add(rsuSRMTxMode); pdu.add(rsuSRMTxChannel); pdu.add(rsuSRMTxInterval); pdu.add(rsuSRMDeliveryStart); pdu.add(rsuSRMDeliveryStop); pdu.add(rsuSRMPayload); pdu.add(rsuSRMEnable); if (verb == ServiceRequest.OdeInternal.RequestVerb.POST) { pdu.add(rsuSRMStatus); } pdu.setType(PDU.SET); return pdu; } 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);  }