From 8d101c566767890de86e5deaee9b0f439cd31985 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Fri, 3 May 2024 16:07:02 -0600 Subject: [PATCH] Set NTCIP1218 msgRepeatOptions value based on whether ODE signs messages for RSUs --- .../us/dot/its/jpo/ode/rsu/RsuDepositor.java | 6 ++- .../jpo/ode/snmp/SnmpNTCIP1218Protocol.java | 4 +- .../us/dot/its/jpo/ode/snmp/SnmpSession.java | 23 ++++++---- .../dot/its/jpo/ode/snmp/SnmpSessionTest.java | 45 ++++++++++++++++--- 4 files changed, 61 insertions(+), 17 deletions(-) diff --git a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/rsu/RsuDepositor.java b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/rsu/RsuDepositor.java index 773bc213a..0f7377c57 100644 --- a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/rsu/RsuDepositor.java +++ b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/rsu/RsuDepositor.java @@ -38,7 +38,9 @@ public class RsuDepositor extends Thread { private OdeProperties odeProperties; private ArrayList depositorEntries = new ArrayList(); - + private static boolean dataSigningEnabledRSU = System.getenv("DATA_SIGNING_ENABLED_RSU") != null && !System.getenv("DATA_SIGNING_ENABLED_RSU").isEmpty() + ? Boolean.parseBoolean(System.getenv("DATA_SIGNING_ENABLED_RSU")) + : false; class RsuDepositorEntry{ public RsuDepositorEntry(ServiceRequest request, String encodedMsg) { @@ -92,7 +94,7 @@ public void run() { String httpResponseStatus; try { - rsuResponse = SnmpSession.createAndSend(entry.request.getSnmp(), curRsu, entry.encodedMsg, entry.request.getOde().getVerb()); + rsuResponse = SnmpSession.createAndSend(entry.request.getSnmp(), curRsu, entry.encodedMsg, entry.request.getOde().getVerb(), dataSigningEnabledRSU); if (null == rsuResponse || null == rsuResponse.getResponse()) { // Timeout httpResponseStatus = "Timeout"; 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 70cc03e5e..c4f166d47 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 @@ -85,8 +85,8 @@ public static VariableBinding getVbRsuMsgRepeatPriority(int index) { ); } - public static VariableBinding getVbRsuMsgRepeatOptions(int index) { - byte[] val = {(byte) 0x00}; + public static VariableBinding getVbRsuMsgRepeatOptions(int index, int options) { + byte[] val = {(byte) options}; return new VariableBinding( new OID(rsu_msg_repeat_options_oid().concat(".").concat(Integer.toString(index))), new OctetString(val) 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 fdf9cbab9..44fc0cf58 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 @@ -206,14 +206,14 @@ public void startListen() throws IOException { * @throws IOException * @throws ParseException */ - public static ResponseEvent createAndSend(SNMP snmp, RSU rsu, String payload, RequestVerb requestVerb) + public static ResponseEvent createAndSend(SNMP snmp, RSU rsu, String payload, RequestVerb requestVerb, boolean dataSigningEnabledRSU) throws ParseException, IOException { SnmpSession session = new SnmpSession(rsu); // Send the PDU ResponseEvent response = null; - ScopedPDU pdu = SnmpSession.createPDU(snmp, payload, rsu.getRsuIndex(), requestVerb, rsu.getSnmpProtocol()); + ScopedPDU pdu = SnmpSession.createPDU(snmp, payload, rsu.getRsuIndex(), requestVerb, rsu.getSnmpProtocol(), dataSigningEnabledRSU); response = session.set(pdu, session.getSnmp(), session.getTarget(), false); String msg = "Message Sent to {}, index {}: {}"; EventLogger.logger.debug(msg, rsu.getRsuTarget(), rsu.getRsuIndex(), payload); @@ -258,12 +258,12 @@ public void endSession() throws IOException { * @return PDU * @throws ParseException */ - public static ScopedPDU createPDU(SNMP snmp, String payload, int index, RequestVerb verb, SnmpProtocol snmpProtocol) throws ParseException { + public static ScopedPDU createPDU(SNMP snmp, String payload, int index, RequestVerb verb, SnmpProtocol snmpProtocol, boolean dataSigningEnabledRSU) throws ParseException { switch (snmpProtocol) { case FOURDOT1: return createPDUWithFourDot1Protocol(snmp, payload, index, verb); case NTCIP1218: - return createPDUWithNTCIP1218Protocol(snmp, payload, index, verb); + return createPDUWithNTCIP1218Protocol(snmp, payload, index, verb, dataSigningEnabledRSU); default: logger.error("Unknown SNMP protocol: {}", snmpProtocol); return null; @@ -354,7 +354,7 @@ private static ScopedPDU createPDUWithFourDot1Protocol(SNMP snmp, String payload return pdu; } - private static ScopedPDU createPDUWithNTCIP1218Protocol(SNMP snmp, String payload, int index, RequestVerb verb) throws ParseException { + private static ScopedPDU createPDUWithNTCIP1218Protocol(SNMP snmp, String payload, int index, RequestVerb verb, boolean dataSigningEnabledRSU) throws ParseException { ////////////////////////////// // - OID examples - // ////////////////////////////// @@ -376,8 +376,8 @@ private static ScopedPDU createPDUWithNTCIP1218Protocol(SNMP snmp, String payloa // --> 1.3.6.1.4.1.1206.4.2.18.3.2.1.9.3 = 4 // rsuMsgRepeatPriority.3 = 6 // --> 1.3.6.1.4.1.1206.4.2.18.3.2.1.10.3 = 6 - // rsuMsgRepeatOptions.3 = "C0" - // --> 1.3.6.1.4.1.1206.4.2.18.3.2.1.11.3 = "C0" + // rsuMsgRepeatOptions.3 = "00" + // --> 1.3.6.1.4.1.1206.4.2.18.3.2.1.11.3 = "00" ////////////////////////////// VariableBinding rsuMsgRepeatPsid = SnmpNTCIP1218Protocol.getVbRsuMsgRepeatPsid(index, snmp.getRsuid()); @@ -391,7 +391,14 @@ private static ScopedPDU createPDUWithNTCIP1218Protocol(SNMP snmp, String payloa VariableBinding rsuMsgRepeatEnable = SnmpNTCIP1218Protocol.getVbRsuMsgRepeatEnable(index, snmp.getEnable()); VariableBinding rsuMsgRepeatStatus = SnmpNTCIP1218Protocol.getVbRsuMsgRepeatStatus(index, snmp.getStatus()); VariableBinding rsuMsgRepeatPriority = SnmpNTCIP1218Protocol.getVbRsuMsgRepeatPriority(index); - VariableBinding rsuMsgRepeatOptions = SnmpNTCIP1218Protocol.getVbRsuMsgRepeatOptions(index); + VariableBinding rsuMsgRepeatOptions; + if (dataSigningEnabledRSU) { + // set options to 0x00 to tell RSU to broadcast message without signing or attaching a 1609.2 header + rsuMsgRepeatOptions = SnmpNTCIP1218Protocol.getVbRsuMsgRepeatOptions(index, 0x00); + } else { + // set options to 0x80 to tell RSU to sign & attach a 1609.2 header before broadcasting + rsuMsgRepeatOptions = SnmpNTCIP1218Protocol.getVbRsuMsgRepeatOptions(index, 0x80); + } ScopedPDU pdu = new ScopedPDU(); pdu.add(rsuMsgRepeatPsid); diff --git a/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/snmp/SnmpSessionTest.java b/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/snmp/SnmpSessionTest.java index 8e2eacce3..16624faa9 100644 --- a/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/snmp/SnmpSessionTest.java +++ b/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/snmp/SnmpSessionTest.java @@ -155,19 +155,22 @@ public void shouldCreatePDUWithFourDot1Protocol() throws ParseException { 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, SnmpProtocol.FOURDOT1); + boolean rsuDataSigningEnabled = true; + + ScopedPDU result = SnmpSession.createPDU(testParams, rsuSRMPayload, 3, RequestVerb.POST, SnmpProtocol.FOURDOT1, rsuDataSigningEnabled); assertEquals("Incorrect type, expected PDU.SET (-93)", -93, result.getType()); assertEquals(expectedResult, result.getVariableBindings().toString()); - ScopedPDU result2 = SnmpSession.createPDU(testParams, rsuSRMPayload, 3, RequestVerb.GET, SnmpProtocol.FOURDOT1); + ScopedPDU result2 = SnmpSession.createPDU(testParams, rsuSRMPayload, 3, RequestVerb.GET, SnmpProtocol.FOURDOT1, rsuDataSigningEnabled); assertEquals("Incorrect type, expected PDU.SET (-93)", -93, result2.getType()); assertEquals(expectedResult2, result2.getVariableBindings().toString()); } @Test - public void shouldCreatePDUWithNTCIP1218Protocol() throws ParseException { + public void shouldCreatePDUWithNTCIP1218Protocol_dataSigningEnabledRsu_True() throws ParseException { + // prepare String expectedResult = "[1.3.6.1.4.1.1206.4.2.18.3.2.1.2.3 = 80:03, 1.3.6.1.4.1.1206.4.2.18.3.2.1.3.3 = 4, 1.3.6.1.4.1.1206.4.2.18.3.2.1.4.3 = 5, 1.3.6.1.4.1.1206.4.2.18.3.2.1.5.3 = 07:e1:0c:02:11:2f:0b:00, 1.3.6.1.4.1.1206.4.2.18.3.2.1.6.3 = 07:e1:0c:02:11:2f:0b:00, 1.3.6.1.4.1.1206.4.2.18.3.2.1.7.3 = 88, 1.3.6.1.4.1.1206.4.2.18.3.2.1.8.3 = 9, 1.3.6.1.4.1.1206.4.2.18.3.2.1.9.3 = 10, 1.3.6.1.4.1.1206.4.2.18.3.2.1.10.3 = 6, 1.3.6.1.4.1.1206.4.2.18.3.2.1.11.3 = 00]"; String expectedResult2 = "[1.3.6.1.4.1.1206.4.2.18.3.2.1.2.3 = 80:03, 1.3.6.1.4.1.1206.4.2.18.3.2.1.3.3 = 4, 1.3.6.1.4.1.1206.4.2.18.3.2.1.4.3 = 5, 1.3.6.1.4.1.1206.4.2.18.3.2.1.5.3 = 07:e1:0c:02:11:2f:0b:00, 1.3.6.1.4.1.1206.4.2.18.3.2.1.6.3 = 07:e1:0c:02:11:2f:0b:00, 1.3.6.1.4.1.1206.4.2.18.3.2.1.7.3 = 88, 1.3.6.1.4.1.1206.4.2.18.3.2.1.8.3 = 9, 1.3.6.1.4.1.1206.4.2.18.3.2.1.10.3 = 6, 1.3.6.1.4.1.1206.4.2.18.3.2.1.11.3 = 00]"; String rsuSRMPsid = "00000083"; @@ -180,13 +183,45 @@ public void shouldCreatePDUWithNTCIP1218Protocol() throws ParseException { SNMP testParams = new SNMP(rsuSRMPsid, 0, 0, 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, SnmpProtocol.NTCIP1218); + boolean rsuDataSigningEnabled = true; + + // execute + ScopedPDU result = SnmpSession.createPDU(testParams, rsuSRMPayload, 3, RequestVerb.POST, SnmpProtocol.NTCIP1218, true); + ScopedPDU result2 = SnmpSession.createPDU(testParams, rsuSRMPayload, 3, RequestVerb.GET, SnmpProtocol.NTCIP1218, true); + // verify assertEquals("Incorrect type, expected PDU.SET (-93)", -93, result.getType()); assertEquals(expectedResult, result.getVariableBindings().toString()); + assertEquals("Incorrect type, expected PDU.SET (-93)", -93, result2.getType()); + assertEquals(expectedResult2, result2.getVariableBindings().toString()); + } + + @Test + public void shouldCreatePDUWithNTCIP1218Protocol_dataSigningEnabledRsu_False() throws ParseException { + // prepare + String expectedResult = "[1.3.6.1.4.1.1206.4.2.18.3.2.1.2.3 = 80:03, 1.3.6.1.4.1.1206.4.2.18.3.2.1.3.3 = 4, 1.3.6.1.4.1.1206.4.2.18.3.2.1.4.3 = 5, 1.3.6.1.4.1.1206.4.2.18.3.2.1.5.3 = 07:e1:0c:02:11:2f:0b:00, 1.3.6.1.4.1.1206.4.2.18.3.2.1.6.3 = 07:e1:0c:02:11:2f:0b:00, 1.3.6.1.4.1.1206.4.2.18.3.2.1.7.3 = 88, 1.3.6.1.4.1.1206.4.2.18.3.2.1.8.3 = 9, 1.3.6.1.4.1.1206.4.2.18.3.2.1.9.3 = 10, 1.3.6.1.4.1.1206.4.2.18.3.2.1.10.3 = 6, 1.3.6.1.4.1.1206.4.2.18.3.2.1.11.3 = 80]"; + String expectedResult2 = "[1.3.6.1.4.1.1206.4.2.18.3.2.1.2.3 = 80:03, 1.3.6.1.4.1.1206.4.2.18.3.2.1.3.3 = 4, 1.3.6.1.4.1.1206.4.2.18.3.2.1.4.3 = 5, 1.3.6.1.4.1.1206.4.2.18.3.2.1.5.3 = 07:e1:0c:02:11:2f:0b:00, 1.3.6.1.4.1.1206.4.2.18.3.2.1.6.3 = 07:e1:0c:02:11:2f:0b:00, 1.3.6.1.4.1.1206.4.2.18.3.2.1.7.3 = 88, 1.3.6.1.4.1.1206.4.2.18.3.2.1.8.3 = 9, 1.3.6.1.4.1.1206.4.2.18.3.2.1.10.3 = 6, 1.3.6.1.4.1.1206.4.2.18.3.2.1.11.3 = 80]"; + String rsuSRMPsid = "00000083"; + int rsuSRMTxChannel = 4; + int rsuSRMTxInterval = 5; + String rsuSRMPayload = "88"; + int rsuSRMEnable = 9; + int rsuSRMStatus = 10; + + SNMP testParams = new SNMP(rsuSRMPsid, 0, 0, rsuSRMTxChannel, rsuSRMTxInterval, "2017-12-02T17:47:11-05:00", + "2017-12-02T17:47:11-05:00", rsuSRMEnable, rsuSRMStatus); + + System.setProperty("DATA_SIGNING_ENABLED_RSU", "false"); + + boolean rsuDataSigningEnabled = false; - ScopedPDU result2 = SnmpSession.createPDU(testParams, rsuSRMPayload, 3, RequestVerb.GET, SnmpProtocol.NTCIP1218); + // execute + ScopedPDU result = SnmpSession.createPDU(testParams, rsuSRMPayload, 3, RequestVerb.POST, SnmpProtocol.NTCIP1218, rsuDataSigningEnabled); + ScopedPDU result2 = SnmpSession.createPDU(testParams, rsuSRMPayload, 3, RequestVerb.GET, SnmpProtocol.NTCIP1218, rsuDataSigningEnabled); + // verify + assertEquals("Incorrect type, expected PDU.SET (-93)", -93, result.getType()); + assertEquals(expectedResult, result.getVariableBindings().toString()); assertEquals("Incorrect type, expected PDU.SET (-93)", -93, result2.getType()); assertEquals(expectedResult2, result2.getVariableBindings().toString()); }