Skip to content

Commit

Permalink
Merge pull request #47 from CDOT-CV/update/snmp-1218
Browse files Browse the repository at this point in the history
1218 updates for TIM deposit
  • Loading branch information
payneBrandon authored Dec 26, 2023
2 parents 03a9c91 + 3f3eb65 commit 87ca65d
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ public void testGettersAndSetters() {
@Test
public void testSnmpTimestampFromIso() throws ParseException {
String snmpTS = SNMP.snmpTimestampFromIso("2017-05-04T21:55:00-05:00");
assertEquals("07E105041537", snmpTS);
assertEquals("07E1050415370000", snmpTS);
}
}
15 changes: 15 additions & 0 deletions jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/SNMP.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@ public void setStatus(int status) {
public static String snmpTimestampFromIso(String isoTimestamp) throws ParseException {
ZonedDateTime zdt = DateTimeUtils.isoDateTime(isoTimestamp);


StringBuilder sb = new StringBuilder();

sb.append(String.format("%04X", zdt.getYear()));
sb.append(String.format("%02X", zdt.getMonthValue()));
sb.append(String.format("%02X", zdt.getDayOfMonth()));
sb.append(String.format("%02X", zdt.getHour()));
sb.append(String.format("%02X", zdt.getMinute()));
sb.append(String.format("%02X", zdt.getSecond()));
sb.append(String.format("%02X", zdt.getNano()));
return sb.toString();
}

public static String fourOneSnmpTimestampFromIso(String isoTimestamp) throws ParseException {
ZonedDateTime zdt = DateTimeUtils.isoDateTime(isoTimestamp);
StringBuilder sb = new StringBuilder();

sb.append(String.format("%04X", zdt.getYear()));
Expand Down
2 changes: 1 addition & 1 deletion jpo-ode-svcs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
<dependency>
<groupId>org.snmp4j</groupId>
<artifactId>snmp4j</artifactId>
<version>3.4.4</version>
<version>3.7.7</version>
</dependency>

</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@

import org.snmp4j.security.AuthMD5;
import org.snmp4j.security.AuthSHA;
import org.snmp4j.security.AuthHMAC128SHA224;
import org.snmp4j.security.AuthHMAC192SHA256;
import org.snmp4j.security.AuthHMAC256SHA384;
import org.snmp4j.security.AuthHMAC384SHA512;
import org.snmp4j.security.PrivAES128;

import org.snmp4j.security.SecurityProtocols;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
Expand All @@ -50,7 +56,13 @@ public static void main(String[] args) throws MalformedObjectNameException, Inte
mbs.registerMBean(mBean, name);

SecurityProtocols.getInstance().addAuthenticationProtocol(new AuthSHA());
SecurityProtocols.getInstance().addAuthenticationProtocol(new AuthHMAC128SHA224());
SecurityProtocols.getInstance().addAuthenticationProtocol(new AuthHMAC192SHA256());
SecurityProtocols.getInstance().addAuthenticationProtocol(new AuthHMAC256SHA384());
SecurityProtocols.getInstance().addAuthenticationProtocol(new AuthHMAC384SHA512());
SecurityProtocols.getInstance().addAuthenticationProtocol(new AuthMD5());
SecurityProtocols.getInstance().addPrivacyProtocol(new PrivAES128());

}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ public static VariableBinding getVbRsuSrmTxInterval(int index, int 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)))
new OctetString(DatatypeConverter.parseHexBinary(SNMP.fourOneSnmpTimestampFromIso(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)))
new OctetString(DatatypeConverter.parseHexBinary(SNMP.fourOneSnmpTimestampFromIso(deliveryStop)))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ public static VariableBinding getVbRsuMsgRepeatPriority(int index) {
}

public static VariableBinding getVbRsuMsgRepeatOptions(int index) {
byte[] val = {(byte) 0xc0};
return new VariableBinding(
new OID(rsu_msg_repeat_options_oid().concat(".").concat(Integer.toString(index))),
new OctetString("C0")
new OctetString(val)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.snmp4j.mp.MPv3;
import org.snmp4j.mp.SnmpConstants;
import org.snmp4j.security.AuthSHA;
import org.snmp4j.security.PrivAES128;
import org.snmp4j.security.SecurityLevel;
import org.snmp4j.security.SecurityModels;
import org.snmp4j.security.SecurityProtocols;
Expand Down Expand Up @@ -83,7 +84,7 @@ public SnmpSession(RSU rsu) throws IOException {
target.setTimeout(rsu.getRsuTimeout());
target.setVersion(SnmpConstants.version3);
if (rsu.getRsuUsername() != null) {
target.setSecurityLevel(SecurityLevel.AUTH_NOPRIV);
target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
target.setSecurityName(new OctetString(rsu.getRsuUsername()));
} else {
target.setSecurityLevel(SecurityLevel.NOAUTH_NOPRIV);
Expand All @@ -105,7 +106,7 @@ public SnmpSession(RSU rsu) throws IOException {
SecurityModels.getInstance().addSecurityModel(usm);
if (rsu.getRsuUsername() != null) {
snmp.getUSM().addUser(new OctetString(rsu.getRsuUsername()), new UsmUser(new OctetString(rsu.getRsuUsername()),
AuthSHA.ID, new OctetString(rsu.getRsuPassword()), null, null));
AuthSHA.ID, new OctetString(rsu.getRsuPassword()), PrivAES128.ID, new OctetString(rsu.getRsuPassword())));
}

// Assert the ready flag so the user can begin sending messages
Expand Down Expand Up @@ -133,9 +134,17 @@ public ResponseEvent set(PDU pdu, Snmp snmpob, UserTarget targetob, Boolean keep
// Try to send the SNMP request (synchronously)
ResponseEvent responseEvent = null;
try {
responseEvent = snmpob.set(pdu, targetob);
if (!keepOpen) {
snmpob.close();
byte[] authEngineID = snmpob.discoverAuthoritativeEngineID(targetob.getAddress(), 1000);
if (authEngineID != null && authEngineID.length > 0) {
targetob.setAuthoritativeEngineID(authEngineID);
}
if (authEngineID != null) {
responseEvent = snmpob.set(pdu, targetob);
if (!keepOpen) {
snmpob.close();
}
} else {
logger.error("Unable to send TIM to RSU {}: authEngineID is null", targetob.getAddress());
}
} catch (IOException e) {
throw new IOException("Failed to send SNMP request: " + e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ public void shouldCreatePDUWithFourDot1Protocol() throws ParseException {

@Test
public void shouldCreatePDUWithNTCIP1218Protocol() throws ParseException {
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, 1.3.6.1.4.1.1206.4.2.18.3.2.1.6.3 = 07:e1:0c:02:11:2f, 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 = C0]";
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, 1.3.6.1.4.1.1206.4.2.18.3.2.1.6.3 = 07:e1:0c:02:11:2f, 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 = C0]";
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 = c0]";
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 = c0]";

String rsuSRMPsid = "00000083";
int rsuSRMTxChannel = 4;
Expand Down

0 comments on commit 87ca65d

Please sign in to comment.