Skip to content

Commit

Permalink
Merge pull request #75 from CDOT-CV/feature/set-msgRepeatOptions-base…
Browse files Browse the repository at this point in the history
…d-on-context

Set NTCIP1218 msgRepeatOption value based on context
  • Loading branch information
dmccoystephenson authored May 21, 2024
2 parents 833ffc4 + b490753 commit ff3eaa9
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public class RsuDepositor extends Thread {
private OdeProperties odeProperties;
private ArrayList<RsuDepositorEntry> depositorEntries = new ArrayList<RsuDepositorEntry>();


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) {
Expand Down Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,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);
Expand Down Expand Up @@ -264,12 +264,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;
Expand Down Expand Up @@ -360,7 +360,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 - //
//////////////////////////////
Expand All @@ -382,8 +382,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());
Expand All @@ -397,7 +397,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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());
}
Expand Down

0 comments on commit ff3eaa9

Please sign in to comment.