From e01fbc14fa3e46e8de1c00ee19f5f4b48d74de0f Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Mon, 11 Sep 2023 15:12:46 -0600 Subject: [PATCH] Moved string manipulation & VariableBinding instantiation into snmp protocol classes. --- .../java/us/dot/its/jpo/ode/pdm/PdmUtil.java | 115 +----- .../jpo/ode/snmp/SnmpFourDot1Protocol.java | 384 ++++++++++++++++-- .../jpo/ode/snmp/SnmpNTCIP1218Protocol.java | 147 ++++++- .../us/dot/its/jpo/ode/snmp/SnmpSession.java | 123 +----- .../jpo/ode/traveler/TimDeleteController.java | 4 +- .../jpo/ode/traveler/TimQueryController.java | 8 +- 6 files changed, 524 insertions(+), 257 deletions(-) diff --git a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/pdm/PdmUtil.java b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/pdm/PdmUtil.java index acb09bc82..f22a2e366 100644 --- a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/pdm/PdmUtil.java +++ b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/pdm/PdmUtil.java @@ -17,8 +17,6 @@ import org.snmp4j.PDU; import org.snmp4j.ScopedPDU; -import org.snmp4j.smi.Integer32; -import org.snmp4j.smi.OID; import org.snmp4j.smi.VariableBinding; import us.dot.its.jpo.ode.plugin.j2735.J2735ProbeDataManagment; @@ -39,75 +37,20 @@ public static ScopedPDU createPDU(J2735ProbeDataManagment params) { pdu.setType(PDU.SET); // Add singular items to PDU - VariableBinding rsuPDMSampleStart = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_pdm_sample_start_oid), - new Integer32(params.getSampleStart()) - ); - - VariableBinding rsuPDMSampleEnd = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_pdm_sample_end_oid), - new Integer32(params.getSampleEnd()) - ); - - VariableBinding rsuPDMDirections = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_pdm_directions_oid), - new Integer32(params.getDirections()) - ); - - VariableBinding rsuPDMTermChoice = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_pdm_term_choice_oid), - new Integer32(params.getTermChoice()) - ); - - VariableBinding rsuPDMTermTime = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_pdm_term_time_oid), - new Integer32(params.getTermTime()) - ); - - VariableBinding rsuPDMTermDistance = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_pdm_term_distance_oid), - new Integer32(params.getTermDistance()) - ); - - VariableBinding rsuPDMSnapshotChoice = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_pdm_snapshot_choice_oid), - new Integer32(params.getSnapshotChoice()) - ); - - VariableBinding rsuPDMMinSnapshotTime = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_pdm_min_snapshot_time_oid), - new Integer32(params.getMinSnapshotTime()) - ); - - VariableBinding rsuPDMMaxSnapshotTime = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_pdm_max_snapshot_time_oid), - new Integer32(params.getMaxSnapshotTime()) - ); - - VariableBinding rsuPDMMinSnapshotDistance = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_pdm_min_snapshot_distance_oid), - new Integer32(params.getMinSnapshotDistance()) - ); - - VariableBinding rsuPDMMaxSnapshotDistance = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_pdm_max_snapshot_distance_oid), - new Integer32(params.getMaxSnapshotDistance()) - ); - - VariableBinding rsuPDMSnapshotMinSpeed = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_pdm_snapshot_min_speed_oid), - new Integer32(params.getSnapshotMinSpeed()) - ); - - VariableBinding rsuPDMSnapshotMaxSpeed = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_pdm_snapshot_max_speed_oid), - new Integer32(params.getSnapshotMaxSpeed()) - ); - - VariableBinding rsuPDMTxInterval = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_pdm_tx_interval_oid), - new Integer32(params.getTxInterval()) - ); + VariableBinding rsuPDMSampleStart = SnmpFourDot1Protocol.getVbRsuPdmSampleStart(params.getSampleStart()); + VariableBinding rsuPDMSampleEnd = SnmpFourDot1Protocol.getVbRsuPdmSampleEnd(params.getSampleEnd()); + VariableBinding rsuPDMDirections = SnmpFourDot1Protocol.getVbRsuPdmDirections(params.getDirections()); + VariableBinding rsuPDMTermChoice = SnmpFourDot1Protocol.getVbRsuPdmTermChoice(params.getTermChoice()); + VariableBinding rsuPDMTermTime = SnmpFourDot1Protocol.getVbRsuPdmTermTime(params.getTermTime()); + VariableBinding rsuPDMTermDistance = SnmpFourDot1Protocol.getVbRsuPdmTermDistance(params.getTermDistance()); + VariableBinding rsuPDMSnapshotChoice = SnmpFourDot1Protocol.getVbRsuPdmSnapshotChoice(params.getSnapshotChoice()); + VariableBinding rsuPDMMinSnapshotTime = SnmpFourDot1Protocol.getVbRsuPdmMinSnapshotTime(params.getMinSnapshotTime()); + VariableBinding rsuPDMMaxSnapshotTime = SnmpFourDot1Protocol.getVbRsuPdmMaxSnapshotTime(params.getMaxSnapshotTime()); + VariableBinding rsuPDMMinSnapshotDistance = SnmpFourDot1Protocol.getVbRsuPdmMinSnapshotDistance(params.getMinSnapshotDistance()); + VariableBinding rsuPDMMaxSnapshotDistance = SnmpFourDot1Protocol.getVbRsuPdmMaxSnapshotDistance(params.getMaxSnapshotDistance()); + VariableBinding rsuPDMSnapshotMinSpeed = SnmpFourDot1Protocol.getVbRsuPdmSnapshotMinSpeed(params.getSnapshotMinSpeed()); + VariableBinding rsuPDMSnapshotMaxSpeed = SnmpFourDot1Protocol.getVbRsuPdmSnapshotMaxSpeed(params.getSnapshotMaxSpeed()); + VariableBinding rsuPDMTxInterval = SnmpFourDot1Protocol.getVbRsuPdmTxInterval(params.getTxInterval()); pdu.add(rsuPDMSampleStart); pdu.add(rsuPDMSampleEnd); @@ -128,30 +71,12 @@ public static ScopedPDU createPDU(J2735ProbeDataManagment params) { for (int index = 0; index < params.getVehicleStatusRequestList().length; index++) { - VariableBinding rsuPDMVSReqTag = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_pdm_vs_req_tag_oid.replace("{}", String.valueOf(index))), - new Integer32(params.getVehicleStatusRequestList()[index].getTag()) - ); - VariableBinding rsuPDMVSReqSubTag = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_pdm_vs_req_sub_tag_oid.replace("{}", String.valueOf(index))), - new Integer32(params.getVehicleStatusRequestList()[index].getSubTag()) - ); - VariableBinding rsuPDMVSReqLessThenValue = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_pdm_vs_req_less_then_oid.replace("{}", String.valueOf(index))), - new Integer32(params.getVehicleStatusRequestList()[index].getLessThenValue()) - ); - VariableBinding rsuPDMVSReqMoreThenValue = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_pdm_vs_req_more_then_oid.replace("{}", String.valueOf(index))), - new Integer32(params.getVehicleStatusRequestList()[index].getMoreThenValue()) - ); - VariableBinding rsuPDMVSReqSendAll = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_pdm_vs_req_send_all_oid.replace("{}", String.valueOf(index))), - new Integer32(params.getVehicleStatusRequestList()[index].getSendAll()) - ); - VariableBinding rsuPDMVSReqStatus = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_pdm_vs_req_status_oid.replace("{}", String.valueOf(index))), - new Integer32(params.getVehicleStatusRequestList()[index].getStatus()) - ); + VariableBinding rsuPDMVSReqTag = SnmpFourDot1Protocol.getVbRsuPdmVsReqTag(index, params.getVehicleStatusRequestList()[index].getTag()); + VariableBinding rsuPDMVSReqSubTag = SnmpFourDot1Protocol.getVbRsuPdmVsReqSubTag(index, params.getVehicleStatusRequestList()[index].getSubTag()); + VariableBinding rsuPDMVSReqLessThenValue = SnmpFourDot1Protocol.getVbRsuPdmVsReqLessThen(index, params.getVehicleStatusRequestList()[index].getLessThenValue()); + VariableBinding rsuPDMVSReqMoreThenValue = SnmpFourDot1Protocol.getVbRsuPdmVsReqMoreThen(index, params.getVehicleStatusRequestList()[index].getMoreThenValue()); + VariableBinding rsuPDMVSReqSendAll = SnmpFourDot1Protocol.getVbRsuPdmVsReqSendAll(index, params.getVehicleStatusRequestList()[index].getSendAll()); + VariableBinding rsuPDMVSReqStatus = SnmpFourDot1Protocol.getVbRsuPdmVsReqStatus(index, params.getVehicleStatusRequestList()[index].getStatus()); pdu.add(rsuPDMVSReqTag); pdu.add(rsuPDMVSReqSubTag); diff --git a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/snmp/SnmpFourDot1Protocol.java b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/snmp/SnmpFourDot1Protocol.java index 8fd29f87a..039a49067 100644 --- a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/snmp/SnmpFourDot1Protocol.java +++ b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/snmp/SnmpFourDot1Protocol.java @@ -1,48 +1,358 @@ package us.dot.its.jpo.ode.snmp; +import java.text.ParseException; + +import javax.xml.bind.DatatypeConverter; + +import org.snmp4j.smi.Integer32; +import org.snmp4j.smi.OID; +import org.snmp4j.smi.OctetString; +import org.snmp4j.smi.VariableBinding; + +import us.dot.its.jpo.ode.plugin.SNMP; + public class SnmpFourDot1Protocol { - // 4.1 prefix private static String fourdot1prefix = "1.0.15628.4."; - - // srm private static String srm_prefix = "1.4.1."; - - public static String rsu_srm_psid_oid = fourdot1prefix + srm_prefix + "2"; - public static String rsu_srm_dsrc_msg_id_oid = fourdot1prefix + srm_prefix + "3"; - public static String rsu_srm_tx_mode_oid = fourdot1prefix + srm_prefix + "4"; - public static String rsu_srm_tx_channel_oid = fourdot1prefix + srm_prefix + "5"; - public static String rsu_srm_tx_interval_oid = fourdot1prefix + srm_prefix + "6"; - public static String rsu_srm_delivery_start_oid = fourdot1prefix + srm_prefix + "7"; - public static String rsu_srm_delivery_stop_oid = fourdot1prefix + srm_prefix + "8"; - public static String rsu_srm_payload_oid = fourdot1prefix + srm_prefix + "9"; - public static String rsu_srm_enable_oid = fourdot1prefix + srm_prefix + "10"; - public static String rsu_srm_status_oid = fourdot1prefix + srm_prefix + "11"; - - // pdm private static String pdm_prefix = "1.200."; + private static String pdm_vs_req_prefix = pdm_prefix + "15."; - public static String rsu_pdm_sample_start_oid = fourdot1prefix + pdm_prefix + "1"; - public static String rsu_pdm_sample_end_oid = fourdot1prefix + pdm_prefix + "2"; - public static String rsu_pdm_directions_oid = fourdot1prefix + pdm_prefix + "3"; - public static String rsu_pdm_term_choice_oid = fourdot1prefix + pdm_prefix + "4"; - public static String rsu_pdm_term_time_oid = fourdot1prefix + pdm_prefix + "5"; - public static String rsu_pdm_term_distance_oid = fourdot1prefix + pdm_prefix + "6"; - public static String rsu_pdm_snapshot_choice_oid = fourdot1prefix + pdm_prefix + "7"; - public static String rsu_pdm_min_snapshot_time_oid = fourdot1prefix + pdm_prefix + "9"; - public static String rsu_pdm_max_snapshot_time_oid = fourdot1prefix + pdm_prefix + "10"; - public static String rsu_pdm_min_snapshot_distance_oid = fourdot1prefix + pdm_prefix + "11"; - public static String rsu_pdm_max_snapshot_distance_oid = fourdot1prefix + pdm_prefix + "12"; - public static String rsu_pdm_snapshot_min_speed_oid = fourdot1prefix + pdm_prefix + "13"; - public static String rsu_pdm_snapshot_max_speed_oid = fourdot1prefix + pdm_prefix + "14"; - public static String rsu_pdm_tx_interval_oid = fourdot1prefix + pdm_prefix + "15"; + // variable bindings + public static VariableBinding getVbRsuSrmPsid(int index, String rsuId) { + return SnmpSession.getPEncodedVariableBinding( + rsu_srm_psid_oid().concat(".").concat(Integer.toString(index)), + rsuId + ); + } - private static String pdm_vs_req_prefix = pdm_prefix + "15."; + public static VariableBinding getVbRsuSrmDsrcMsgId(int index, int msgId) { + return new VariableBinding( + new OID(rsu_srm_dsrc_msg_id_oid().concat(".").concat(Integer.toString(index))), + new Integer32(msgId) + ); + } + + public static VariableBinding getVbRsuSrmTxMode(int index, int mode) { + return new VariableBinding( + new OID(rsu_srm_tx_mode_oid().concat(".").concat(Integer.toString(index))), + new Integer32(mode) + ); + } + + public static VariableBinding getVbRsuSrmTxChannel(int index, int channel) { + return new VariableBinding( + new OID(rsu_srm_tx_channel_oid().concat(".").concat(Integer.toString(index))), + new Integer32(channel) + ); + } + + public static VariableBinding getVbRsuSrmTxInterval(int index, int interval) { + return new VariableBinding( + new OID(rsu_srm_tx_interval_oid().concat(".").concat(Integer.toString(index))), + new Integer32(interval) + ); + } + + public static VariableBinding getVbRsuSrmDeliveryStart(int index, String deliveryStart) throws ParseException { + return new VariableBinding( + new OID(rsu_srm_delivery_start_oid().concat(".").concat(Integer.toString(index))), + new OctetString(DatatypeConverter.parseHexBinary(SNMP.snmpTimestampFromIso(deliveryStart))) + ); + } + + public static VariableBinding getVbRsuSrmDeliveryStop(int index, String deliveryStop) throws ParseException { + return new VariableBinding( + new OID(rsu_srm_delivery_stop_oid().concat(".").concat(Integer.toString(index))), + new OctetString(DatatypeConverter.parseHexBinary(SNMP.snmpTimestampFromIso(deliveryStop))) + ); + } + + public static VariableBinding getVbRsuSrmPayload(int index, String payload) { + return new VariableBinding( + new OID(rsu_srm_payload_oid().concat(".").concat(Integer.toString(index))), + new OctetString(DatatypeConverter.parseHexBinary(payload)) + ); + } + + public static VariableBinding getVbRsuSrmEnable(int index, int enable) { + return new VariableBinding( + new OID(rsu_srm_enable_oid().concat(".").concat(Integer.toString(index))), + new Integer32(enable) + ); + } + + public static VariableBinding getVbRsuSrmStatus(int index, int status) { + return new VariableBinding( + new OID(rsu_srm_status_oid().concat(".").concat(Integer.toString(index))), + new Integer32(status) + ); + } + + public static VariableBinding getVbRsuSrmStatus(int index) { + return new VariableBinding( + new OID(rsu_srm_status_oid().concat(".").concat(Integer.toString(index)) + ) + ); + } + + public static VariableBinding getVbRsuPdmSampleStart(int sampleStart) { + return new VariableBinding( + new OID(rsu_pdm_sample_start_oid()), + new Integer32(sampleStart) + ); + } + + public static VariableBinding getVbRsuPdmSampleEnd(int sampleEnd) { + return new VariableBinding( + new OID(rsu_pdm_sample_end_oid()), + new Integer32(sampleEnd) + ); + } + + public static VariableBinding getVbRsuPdmDirections(int directions) { + return new VariableBinding( + new OID(rsu_pdm_directions_oid()), + new Integer32(directions) + ); + } + + public static VariableBinding getVbRsuPdmTermChoice(int termChoice) { + return new VariableBinding( + new OID(rsu_pdm_term_choice_oid()), + new Integer32(termChoice) + ); + } + + public static VariableBinding getVbRsuPdmTermTime(int termTime) { + return new VariableBinding( + new OID(rsu_pdm_term_time_oid()), + new Integer32(termTime) + ); + } + + public static VariableBinding getVbRsuPdmTermDistance(int termDistance) { + return new VariableBinding( + new OID(rsu_pdm_term_distance_oid()), + new Integer32(termDistance) + ); + } + + public static VariableBinding getVbRsuPdmSnapshotChoice(int snapshotChoice) { + return new VariableBinding( + new OID(rsu_pdm_snapshot_choice_oid()), + new Integer32(snapshotChoice) + ); + } + + public static VariableBinding getVbRsuPdmMinSnapshotTime(int minSnapshotTime) { + return new VariableBinding( + new OID(rsu_pdm_min_snapshot_time_oid()), + new Integer32(minSnapshotTime) + ); + } + + public static VariableBinding getVbRsuPdmMaxSnapshotTime(int maxSnapshotTime) { + return new VariableBinding( + new OID(rsu_pdm_max_snapshot_time_oid()), + new Integer32(maxSnapshotTime) + ); + } + + public static VariableBinding getVbRsuPdmMinSnapshotDistance(int minSnapshotDistance) { + return new VariableBinding( + new OID(rsu_pdm_min_snapshot_distance_oid()), + new Integer32(minSnapshotDistance) + ); + } + + public static VariableBinding getVbRsuPdmMaxSnapshotDistance(int maxSnapshotDistance) { + return new VariableBinding( + new OID(rsu_pdm_max_snapshot_distance_oid()), + new Integer32(maxSnapshotDistance) + ); + } + + public static VariableBinding getVbRsuPdmSnapshotMinSpeed(int snapshotMinSpeed) { + return new VariableBinding( + new OID(rsu_pdm_snapshot_min_speed_oid()), + new Integer32(snapshotMinSpeed) + ); + } + + public static VariableBinding getVbRsuPdmSnapshotMaxSpeed(int snapshotMaxSpeed) { + return new VariableBinding( + new OID(rsu_pdm_snapshot_max_speed_oid()), + new Integer32(snapshotMaxSpeed) + ); + } + + public static VariableBinding getVbRsuPdmTxInterval(int txInterval) { + return new VariableBinding( + new OID(rsu_pdm_tx_interval_oid()), + new Integer32(txInterval) + ); + } + + public static VariableBinding getVbRsuPdmVsReqTag(int index, int tag) { + return new VariableBinding( + new OID(rsu_pdm_vs_req_tag_oid().replace("{}", String.valueOf(index))), + new Integer32(tag) + ); + } + + public static VariableBinding getVbRsuPdmVsReqSubTag(int index, int subTag) { + return new VariableBinding( + new OID(rsu_pdm_vs_req_sub_tag_oid().replace("{}", String.valueOf(index))), + new Integer32(subTag) + ); + } + + public static VariableBinding getVbRsuPdmVsReqLessThen(int index, int lessThen) { + return new VariableBinding( + new OID(rsu_pdm_vs_req_less_then_oid().replace("{}", String.valueOf(index))), + new Integer32(lessThen) + ); + } + + public static VariableBinding getVbRsuPdmVsReqMoreThen(int index, int moreThen) { + return new VariableBinding( + new OID(rsu_pdm_vs_req_more_then_oid().replace("{}", String.valueOf(index))), + new Integer32(moreThen) + ); + } + + public static VariableBinding getVbRsuPdmVsReqSendAll(int index, int sendAll) { + return new VariableBinding( + new OID(rsu_pdm_vs_req_send_all_oid().replace("{}", String.valueOf(index))), + new Integer32(sendAll) + ); + } + + public static VariableBinding getVbRsuPdmVsReqStatus(int index, int status) { + return new VariableBinding( + new OID(rsu_pdm_vs_req_status_oid().replace("{}", String.valueOf(index))), + new Integer32(status) + ); + } + + // oids + private static String rsu_srm_psid_oid() { + return fourdot1prefix + srm_prefix + "2"; + } + + private static String rsu_srm_dsrc_msg_id_oid() { + return fourdot1prefix + srm_prefix + "3"; + } + + private static String rsu_srm_tx_mode_oid() { + return fourdot1prefix + srm_prefix + "4"; + } + + private static String rsu_srm_tx_channel_oid() { + return fourdot1prefix + srm_prefix + "5"; + } + + private static String rsu_srm_tx_interval_oid() { + return fourdot1prefix + srm_prefix + "6"; + } + + private static String rsu_srm_delivery_start_oid() { + return fourdot1prefix + srm_prefix + "7"; + } + + private static String rsu_srm_delivery_stop_oid() { + return fourdot1prefix + srm_prefix + "8"; + } + + private static String rsu_srm_payload_oid() { + return fourdot1prefix + srm_prefix + "9"; + } + + private static String rsu_srm_enable_oid() { + return fourdot1prefix + srm_prefix + "10"; + } + + private static String rsu_srm_status_oid() { + return fourdot1prefix + srm_prefix + "11"; + } + + private static String rsu_pdm_sample_start_oid() { + return fourdot1prefix + pdm_prefix + "1"; + } + + private static String rsu_pdm_sample_end_oid() { + return fourdot1prefix + pdm_prefix + "2"; + } + + private static String rsu_pdm_directions_oid() { + return fourdot1prefix + pdm_prefix + "3"; + } + + private static String rsu_pdm_term_choice_oid() { + return fourdot1prefix + pdm_prefix + "4"; + } + + private static String rsu_pdm_term_time_oid() { + return fourdot1prefix + pdm_prefix + "5"; + } + + private static String rsu_pdm_term_distance_oid() { + return fourdot1prefix + pdm_prefix + "6"; + } + + private static String rsu_pdm_snapshot_choice_oid() { + return fourdot1prefix + pdm_prefix + "7"; + } + + private static String rsu_pdm_min_snapshot_time_oid() { + return fourdot1prefix + pdm_prefix + "9"; + } + + private static String rsu_pdm_max_snapshot_time_oid() { + return fourdot1prefix + pdm_prefix + "10"; + } + + private static String rsu_pdm_min_snapshot_distance_oid() { + return fourdot1prefix + pdm_prefix + "11"; + } + + private static String rsu_pdm_max_snapshot_distance_oid() { + return fourdot1prefix + pdm_prefix + "12"; + } + + private static String rsu_pdm_snapshot_min_speed_oid() { + return fourdot1prefix + pdm_prefix + "13"; + } + + private static String rsu_pdm_snapshot_max_speed_oid() { + return fourdot1prefix + pdm_prefix + "14"; + } + + private static String rsu_pdm_tx_interval_oid() { + return fourdot1prefix + pdm_prefix + "15"; + } + + private static String rsu_pdm_vs_req_tag_oid() { + return fourdot1prefix + pdm_vs_req_prefix + "{}" + "." + "1"; + } + + private static String rsu_pdm_vs_req_sub_tag_oid() { + return fourdot1prefix + pdm_vs_req_prefix + "{}" + "." + "2"; + } + + private static String rsu_pdm_vs_req_less_then_oid() { + return fourdot1prefix + pdm_vs_req_prefix + "{}" + "." + "3"; + } + + private static String rsu_pdm_vs_req_more_then_oid() { + return fourdot1prefix + pdm_vs_req_prefix + "{}" + "." + "4"; + } - public static String rsu_pdm_vs_req_tag_oid = fourdot1prefix + pdm_vs_req_prefix + "{}" + "." + "1"; - public static String rsu_pdm_vs_req_sub_tag_oid = fourdot1prefix + pdm_vs_req_prefix + "{}" + "." + "2"; - public static String rsu_pdm_vs_req_less_then_oid = fourdot1prefix + pdm_vs_req_prefix + "{}" + "." + "3"; - public static String rsu_pdm_vs_req_more_then_oid = fourdot1prefix + pdm_vs_req_prefix + "{}" + "." + "4"; - public static String rsu_pdm_vs_req_send_all_oid = fourdot1prefix + pdm_vs_req_prefix + "{}" + "." + "5"; - public static String rsu_pdm_vs_req_status_oid = fourdot1prefix + pdm_vs_req_prefix + "{}" + "." + "6"; + private static String rsu_pdm_vs_req_send_all_oid() { + return fourdot1prefix + pdm_vs_req_prefix + "{}" + "." + "5"; + } + private static String rsu_pdm_vs_req_status_oid() { + return fourdot1prefix + pdm_vs_req_prefix + "{}" + "." + "6"; + } } diff --git a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/snmp/SnmpNTCIP1218Protocol.java b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/snmp/SnmpNTCIP1218Protocol.java index 546d6ef74..e72eb72cb 100644 --- a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/snmp/SnmpNTCIP1218Protocol.java +++ b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/snmp/SnmpNTCIP1218Protocol.java @@ -1,22 +1,137 @@ package us.dot.its.jpo.ode.snmp; +import java.text.ParseException; + +import javax.xml.bind.DatatypeConverter; + +import org.snmp4j.smi.Integer32; +import org.snmp4j.smi.OID; +import org.snmp4j.smi.OctetString; +import org.snmp4j.smi.VariableBinding; + +import us.dot.its.jpo.ode.plugin.SNMP; + public class SnmpNTCIP1218Protocol { - // ntcip1218 prefix private static String ntcip1218prefix = "1.3.6.1.4.1.1206.4.2.18."; + private static String srm_prefix = "3.2.1"; // srm (defined in NTCIP1218 Section 5.4.2) + + // variable bindings + public static VariableBinding getVbRsuMsgRepeatPsid(int index, String rsuId) { + return SnmpSession.getPEncodedVariableBinding( + rsu_msg_repeat_psid_oid().concat(".").concat(Integer.toString(index)), + rsuId + ); + } + + public static VariableBinding getVbRsuMsgRepeatTxChannel(int index, int channel) { + return new VariableBinding( + new OID(rsu_msg_repeat_tx_channel_oid().concat(".").concat(Integer.toString(index))), + new Integer32(channel) + ); + } + + public static VariableBinding getVbRsuMsgRepeatTxInterval(int index, int interval) { + return new VariableBinding( + new OID(rsu_msg_repeat_tx_interval_oid().concat(".").concat(Integer.toString(index))), + new Integer32(interval) + ); + } + + public static VariableBinding getVbRsuMsgRepeatDeliveryStart(int index, String deliveryStart) throws ParseException { + return new VariableBinding( + new OID(rsu_msg_repeat_delivery_start_oid().concat(".").concat(Integer.toString(index))), + new OctetString(DatatypeConverter.parseHexBinary(SNMP.snmpTimestampFromIso(deliveryStart))) + ); + } + + public static VariableBinding getVbRsuMsgRepeatDeliveryStop(int index, String deliveryStop) throws ParseException { + return new VariableBinding( + new OID(rsu_msg_repeat_delivery_stop_oid().concat(".").concat(Integer.toString(index))), + new OctetString(DatatypeConverter.parseHexBinary(SNMP.snmpTimestampFromIso(deliveryStop))) + ); + } + + public static VariableBinding getVbRsuMsgRepeatPayload(int index, String payload) { + return new VariableBinding( + new OID(rsu_msg_repeat_payload_oid().concat(".").concat(Integer.toString(index))), + new OctetString(DatatypeConverter.parseHexBinary(payload)) + ); + } + + public static VariableBinding getVbRsuMsgRepeatEnable(int index, int enable) { + return new VariableBinding( + new OID(rsu_msg_repeat_enable_oid().concat(".").concat(Integer.toString(index))), + new Integer32(enable) + ); + } + + public static VariableBinding getVbRsuMsgRepeatStatus(int index, int status) { + return new VariableBinding( + new OID(rsu_msg_repeat_status_oid().concat(".").concat(Integer.toString(index))), + new Integer32(status) + ); + } + + public static VariableBinding getVbRsuMsgRepeatStatus(int index) { + return new VariableBinding( + new OID(rsu_msg_repeat_status_oid().concat(".").concat(Integer.toString(index))) + ); + } + + public static VariableBinding getVbRsuMsgRepeatPriority(int index) { + return new VariableBinding( + new OID(rsu_msg_repeat_priority_oid().concat(".").concat(Integer.toString(index))), + new Integer32(6) + ); + } + + public static VariableBinding getVbRsuMsgRepeatOptions(int index) { + return new VariableBinding( + new OID(rsu_msg_repeat_options_oid().concat(".").concat(Integer.toString(index))), + new OctetString("C0") + ); + } + + // oids + private static String rsu_msg_repeat_psid_oid() { + return ntcip1218prefix + srm_prefix + ".2"; + } + + private static String rsu_msg_repeat_tx_channel_oid() { + return ntcip1218prefix + srm_prefix + ".3"; + } + + private static String rsu_msg_repeat_tx_interval_oid() { + return ntcip1218prefix + srm_prefix + ".4"; + } + + private static String rsu_msg_repeat_delivery_start_oid() { + return ntcip1218prefix + srm_prefix + ".5"; + } + + private static String rsu_msg_repeat_delivery_stop_oid() { + return ntcip1218prefix + srm_prefix + ".6"; + } + + private static String rsu_msg_repeat_payload_oid() { + return ntcip1218prefix + srm_prefix + ".7"; + } + + private static String rsu_msg_repeat_enable_oid() { + return ntcip1218prefix + srm_prefix + ".8"; + } + + private static String rsu_msg_repeat_status_oid() { + return ntcip1218prefix + srm_prefix + ".9"; + } + + private static String rsu_msg_repeat_priority_oid() { + return ntcip1218prefix + srm_prefix + ".10"; + } + + private static String rsu_msg_repeat_options_oid() { + return ntcip1218prefix + srm_prefix + ".11"; + } - // srm (defined in NTCIP1218 Section 5.4.2) - private static String srm_prefix = "3.2.1"; - - public static String rsu_msg_repeat_psid_oid = ntcip1218prefix + srm_prefix + ".2"; // Section 5.4.2.2 - public static String rsu_msg_repeat_tx_channel_oid = ntcip1218prefix + srm_prefix + ".3"; // Section 5.4.2.3 - public static String rsu_msg_repeat_tx_interval_oid = ntcip1218prefix + srm_prefix + ".4"; // Section 5.4.2.4 - public static String rsu_msg_repeat_delivery_start_oid = ntcip1218prefix + srm_prefix + ".5"; // Section 5.4.2.4 - public static String rsu_msg_repeat_delivery_stop_oid = ntcip1218prefix + srm_prefix + ".6"; // Section 5.4.2.6 - public static String rsu_msg_repeat_payload_oid = ntcip1218prefix + srm_prefix + ".7"; // Section 5.4.2.7 - public static String rsu_msg_repeat_enable_oid = ntcip1218prefix + srm_prefix + ".8"; // Section 5.4.2.8 - public static String rsu_msg_repeat_status_oid = ntcip1218prefix + srm_prefix + ".9"; // Section 5.4.2.9 - public static String rsu_msg_repeat_priority_oid = ntcip1218prefix + srm_prefix + ".10"; // Section 5.4.2.10 - public static String rsu_msg_repeat_options_oid = ntcip1218prefix + srm_prefix + ".11"; // Section 5.4.2.11 - - // pdm is not defined in NTCIP1218 + // note: pdm is not defined in NTCIP1218 } diff --git a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/snmp/SnmpSession.java b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/snmp/SnmpSession.java index 4c6f06435..c32eb2fa4 100644 --- a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/snmp/SnmpSession.java +++ b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/snmp/SnmpSession.java @@ -18,8 +18,6 @@ import java.io.IOException; import java.text.ParseException; -import javax.xml.bind.DatatypeConverter; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.snmp4j.PDU; @@ -38,7 +36,6 @@ import org.snmp4j.security.UsmUser; import org.snmp4j.smi.Address; import org.snmp4j.smi.GenericAddress; -import org.snmp4j.smi.Integer32; import org.snmp4j.smi.OID; import org.snmp4j.smi.OctetString; import org.snmp4j.smi.VariableBinding; @@ -319,55 +316,16 @@ private static ScopedPDU createPDUWithFourDot1Protocol(SNMP snmp, String payload // --> 1.4.1.10.3 = 1 ////////////////////////////// - VariableBinding rsuSRMPsid = SnmpSession.getPEncodedVariableBinding( - SnmpFourDot1Protocol.rsu_srm_psid_oid.concat(".").concat(Integer.toString(index)), - snmp.getRsuid() - ); - - VariableBinding rsuSRMDsrcMsgId = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_srm_dsrc_msg_id_oid.concat(".").concat(Integer.toString(index))), - new Integer32(snmp.getMsgid()) - ); - - VariableBinding rsuSRMTxMode = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_srm_tx_mode_oid.concat(".").concat(Integer.toString(index))), - new Integer32(snmp.getMode()) - ); - - VariableBinding rsuSRMTxChannel = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_srm_tx_channel_oid.concat(".").concat(Integer.toString(index))), - new Integer32(snmp.getChannel()) - ); - - VariableBinding rsuSRMTxInterval = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_srm_tx_interval_oid.concat(".").concat(Integer.toString(index))), - new Integer32(snmp.getInterval()) - ); - - VariableBinding rsuSRMDeliveryStart = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_srm_delivery_start_oid.concat(".").concat(Integer.toString(index))), - new OctetString(DatatypeConverter.parseHexBinary(SNMP.snmpTimestampFromIso(snmp.getDeliverystart()))) - ); - - VariableBinding rsuSRMDeliveryStop = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_srm_delivery_stop_oid.concat(".").concat(Integer.toString(index))), - new OctetString(DatatypeConverter.parseHexBinary(SNMP.snmpTimestampFromIso(snmp.getDeliverystop()))) - ); - - VariableBinding rsuSRMPayload = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_srm_payload_oid.concat(".").concat(Integer.toString(index))), - new OctetString(DatatypeConverter.parseHexBinary(payload)) - ); - - VariableBinding rsuSRMEnable = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_srm_enable_oid.concat(".").concat(Integer.toString(index))), - new Integer32(snmp.getEnable()) - ); - - VariableBinding rsuSRMStatus = new VariableBinding( - new OID(SnmpFourDot1Protocol.rsu_srm_status_oid.concat(".").concat(Integer.toString(index))), - new Integer32(snmp.getStatus()) - ); + VariableBinding rsuSRMPsid = SnmpFourDot1Protocol.getVbRsuSrmPsid(index, snmp.getRsuid()); + VariableBinding rsuSRMDsrcMsgId = SnmpFourDot1Protocol.getVbRsuSrmDsrcMsgId(index, snmp.getMsgid()); + VariableBinding rsuSRMTxMode = SnmpFourDot1Protocol.getVbRsuSrmTxMode(index, snmp.getMode()); + VariableBinding rsuSRMTxChannel = SnmpFourDot1Protocol.getVbRsuSrmTxChannel(index, snmp.getChannel()); + VariableBinding rsuSRMTxInterval = SnmpFourDot1Protocol.getVbRsuSrmTxInterval(index, snmp.getInterval()); + VariableBinding rsuSRMDeliveryStart = SnmpFourDot1Protocol.getVbRsuSrmDeliveryStart(index, snmp.getDeliverystart()); + VariableBinding rsuSRMDeliveryStop = SnmpFourDot1Protocol.getVbRsuSrmDeliveryStop(index, snmp.getDeliverystop()); + VariableBinding rsuSRMPayload = SnmpFourDot1Protocol.getVbRsuSrmPayload(index, payload); + VariableBinding rsuSRMEnable = SnmpFourDot1Protocol.getVbRsuSrmEnable(index, snmp.getEnable()); + VariableBinding rsuSRMStatus = SnmpFourDot1Protocol.getVbRsuSrmStatus(index, snmp.getStatus()); ScopedPDU pdu = new ScopedPDU(); pdu.add(rsuSRMPsid); @@ -413,59 +371,18 @@ private static ScopedPDU createPDUWithNTCIP1218Protocol(SNMP snmp, String payloa // --> 1.3.6.1.4.1.1206.4.2.18.3.2.1.11.3 = "C0" ////////////////////////////// - VariableBinding rsuMsgRepeatPsid = SnmpSession.getPEncodedVariableBinding( - SnmpNTCIP1218Protocol.rsu_msg_repeat_psid_oid.concat(".").concat(Integer.toString(index)), - snmp.getRsuid() - ); - + VariableBinding rsuMsgRepeatPsid = SnmpNTCIP1218Protocol.getVbRsuMsgRepeatPsid(index, snmp.getRsuid()); // note: dsrc_msg_id is not in NTCIP 1218 - // note: tx_mode is not in NTCIP 1218 - - VariableBinding rsuMsgRepeatTxChannel = new VariableBinding( - new OID(SnmpNTCIP1218Protocol.rsu_msg_repeat_tx_channel_oid.concat(".").concat(Integer.toString(index))), - new Integer32(snmp.getChannel()) - ); - - VariableBinding rsuMsgRepeatTxInterval = new VariableBinding( - new OID(SnmpNTCIP1218Protocol.rsu_msg_repeat_tx_interval_oid.concat(".").concat(Integer.toString(index))), - new Integer32(snmp.getInterval()) - ); - - VariableBinding rsuMsgRepeatDeliveryStart = new VariableBinding( - new OID(SnmpNTCIP1218Protocol.rsu_msg_repeat_delivery_start_oid.concat(".").concat(Integer.toString(index))), - new OctetString(DatatypeConverter.parseHexBinary(SNMP.snmpTimestampFromIso(snmp.getDeliverystart()))) - ); - - VariableBinding rsuMsgRepeatDeliveryStop = new VariableBinding( - new OID(SnmpNTCIP1218Protocol.rsu_msg_repeat_delivery_stop_oid.concat(".").concat(Integer.toString(index))), - new OctetString(DatatypeConverter.parseHexBinary(SNMP.snmpTimestampFromIso(snmp.getDeliverystop()))) - ); - - VariableBinding rsuMsgRepeatPayload = new VariableBinding( - new OID(SnmpNTCIP1218Protocol.rsu_msg_repeat_payload_oid.concat(".").concat(Integer.toString(index))), - new OctetString(DatatypeConverter.parseHexBinary(payload)) - ); - - VariableBinding rsuMsgRepeatEnable = new VariableBinding( - new OID(SnmpNTCIP1218Protocol.rsu_msg_repeat_enable_oid.concat(".").concat(Integer.toString(index))), - new Integer32(snmp.getEnable()) - ); - - VariableBinding rsuMsgRepeatStatus = new VariableBinding( - new OID(SnmpNTCIP1218Protocol.rsu_msg_repeat_status_oid.concat(".").concat(Integer.toString(index))), - new Integer32(snmp.getStatus()) - ); - - VariableBinding rsuMsgRepeatPriority = new VariableBinding( - new OID(SnmpNTCIP1218Protocol.rsu_msg_repeat_priority_oid.concat(".").concat(Integer.toString(index))), - new Integer32(6) - ); - - VariableBinding rsuMsgRepeatOptions = new VariableBinding( - new OID(SnmpNTCIP1218Protocol.rsu_msg_repeat_options_oid.concat(".").concat(Integer.toString(index))), - new OctetString("C0") - ); + VariableBinding rsuMsgRepeatTxChannel = SnmpNTCIP1218Protocol.getVbRsuMsgRepeatTxChannel(index, snmp.getChannel()); + VariableBinding rsuMsgRepeatTxInterval = SnmpNTCIP1218Protocol.getVbRsuMsgRepeatTxInterval(index, snmp.getInterval()); + VariableBinding rsuMsgRepeatDeliveryStart = SnmpNTCIP1218Protocol.getVbRsuMsgRepeatDeliveryStart(index, snmp.getDeliverystart()); + VariableBinding rsuMsgRepeatDeliveryStop = SnmpNTCIP1218Protocol.getVbRsuMsgRepeatDeliveryStop(index, snmp.getDeliverystop()); + VariableBinding rsuMsgRepeatPayload = SnmpNTCIP1218Protocol.getVbRsuMsgRepeatPayload(index, payload); + VariableBinding rsuMsgRepeatEnable = SnmpNTCIP1218Protocol.getVbRsuMsgRepeatEnable(index, snmp.getEnable()); + VariableBinding rsuMsgRepeatStatus = SnmpNTCIP1218Protocol.getVbRsuMsgRepeatStatus(index, snmp.getStatus()); + VariableBinding rsuMsgRepeatPriority = SnmpNTCIP1218Protocol.getVbRsuMsgRepeatPriority(index); + VariableBinding rsuMsgRepeatOptions = SnmpNTCIP1218Protocol.getVbRsuMsgRepeatOptions(index); ScopedPDU pdu = new ScopedPDU(); pdu.add(rsuMsgRepeatPsid); diff --git a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/traveler/TimDeleteController.java b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/traveler/TimDeleteController.java index 3efd3e58e..2111a113f 100644 --- a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/traveler/TimDeleteController.java +++ b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/traveler/TimDeleteController.java @@ -95,12 +95,12 @@ public ResponseEntity deleteTim(@RequestBody String jsonString, PDU pdu = null; if (snmpProtocol.equals(SnmpProtocol.FOURDOT1)) { pdu = new ScopedPDU(); - pdu.add(new VariableBinding(new OID(SnmpFourDot1Protocol.rsu_srm_status_oid.concat(".").concat(Integer.toString(index))), new Integer32(6))); + pdu.add(SnmpFourDot1Protocol.getVbRsuSrmStatus(index, 6)); pdu.setType(PDU.SET); } else if (snmpProtocol.equals(SnmpProtocol.NTCIP1218)) { pdu = new ScopedPDU(); - pdu.add(new VariableBinding(new OID(SnmpNTCIP1218Protocol.rsu_msg_repeat_status_oid.concat(".").concat(Integer.toString(index))), new Integer32(6))); + pdu.add(SnmpNTCIP1218Protocol.getVbRsuMsgRepeatStatus(index, 6)); pdu.setType(PDU.SET); } else { diff --git a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/traveler/TimQueryController.java b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/traveler/TimQueryController.java index 27db4cc5e..73ef59562 100644 --- a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/traveler/TimQueryController.java +++ b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/traveler/TimQueryController.java @@ -109,20 +109,20 @@ public synchronized ResponseEntity bulkQuery(@RequestBody String jsonStr if (snmpProtocol == SnmpProtocol.FOURDOT1) { for (int i = 0; i < odeProperties.getRsuSrmSlots() - 50; i++) { - pdu0.add(new VariableBinding(new OID(SnmpFourDot1Protocol.rsu_srm_status_oid.concat(".").concat(Integer.toString(i))))); + pdu0.add(SnmpFourDot1Protocol.getVbRsuSrmStatus(i)); } for (int i = 50; i < odeProperties.getRsuSrmSlots(); i++) { - pdu1.add(new VariableBinding(new OID(SnmpFourDot1Protocol.rsu_srm_status_oid.concat(".").concat(Integer.toString(i))))); + pdu1.add(SnmpFourDot1Protocol.getVbRsuSrmStatus(i)); } } else if (snmpProtocol == SnmpProtocol.NTCIP1218) { for (int i = 0; i < odeProperties.getRsuSrmSlots() - 50; i++) { - pdu0.add(new VariableBinding(new OID(SnmpNTCIP1218Protocol.rsu_msg_repeat_status_oid.concat(".").concat(Integer.toString(i))))); + pdu0.add(SnmpNTCIP1218Protocol.getVbRsuMsgRepeatStatus(i)); } for (int i = 50; i < odeProperties.getRsuSrmSlots(); i++) { - pdu1.add(new VariableBinding(new OID(SnmpNTCIP1218Protocol.rsu_msg_repeat_status_oid.concat(".").concat(Integer.toString(i))))); + pdu1.add(SnmpNTCIP1218Protocol.getVbRsuMsgRepeatStatus(i)); } } else {