Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1218 updates for TIM deposit #47

Merged
merged 4 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
dmccoystephenson marked this conversation as resolved.
Show resolved Hide resolved
}
}
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 {
payneBrandon marked this conversation as resolved.
Show resolved Hide resolved
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());
dmccoystephenson marked this conversation as resolved.
Show resolved Hide resolved

}

@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};
dmccoystephenson marked this conversation as resolved.
Show resolved Hide resolved
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);
dmccoystephenson marked this conversation as resolved.
Show resolved Hide resolved
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