Skip to content

Commit

Permalink
Merge pull request #464 from usdot-jpo-ode/release/1.2.4
Browse files Browse the repository at this point in the history
Release/1.2.4
  • Loading branch information
dan-du-car authored Dec 17, 2021
2 parents c33e5b8 + 10e84bc commit a93c507
Show file tree
Hide file tree
Showing 45 changed files with 1,459 additions and 1,317 deletions.
3 changes: 1 addition & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ RUN apt-get update \
# Verify git, needed tools installed
&& apt-get -y install git openssh-client less iproute2 procps curl lsb-release zip unzip sed kafkacat telnet

#-------------------Install SDKMan and Java 8----------------------------------
#-------------------Install SDKMan----------------------------------
RUN curl -s https://get.sdkman.io | bash
RUN chmod a+x "$HOME/.sdkman/bin/sdkman-init.sh"
RUN /bin/bash -c "source $HOME/.sdkman/bin/sdkman-init.sh && sdk install java 8.0.275.hs-adpt;"
#-------------------------------------------------------------------------------------------------------------

#-------------------Install Maven CLI Tools----------------------------------
Expand Down
25 changes: 14 additions & 11 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.154.0/containers/java-8
{
"name": "Java 8",
"name": "Java 11",
"dockerFile": "Dockerfile",
"overrideCommand": false,
"shutdownAction": "stopContainer",
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
"java.configuration.runtimes": [
{
"default": true,
"name": "JavaSE-1.8",
"path": "/root/.sdkman/candidates/java/current"
}
]
"terminal.integrated.shell.linux": "/bin/bash"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"vscjava.vscode-java-pack",
"vscjava.vscode-java-debug",
"vscjava.vscode-maven",
"vscjava.vscode-java-dependency",
"vscjava.vscode-java-test",
"hbenl.vscode-test-explorer",
"ms-vscode.test-adapter-converter",
"esbenp.prettier-vscode",
"mhutchie.git-graph",
"tabnine.tabnine-vscode"
"tabnine.tabnine-vscode",
"redhat.java",
"redhat.vscode-commons"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [8080, 9090, 46753, 46800, 5555, 6666, 8090, 2181, 9092],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "bash .devcontainer/post-create.sh",
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
// "remoteUser": "vscode"
"runArgs": ["--network=host"]
"runArgs": [
"--network=host"
]
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"java.configuration.updateBuildConfiguration": "automatic",
"java.test.config": {
"name": "testConfig",
"vmArgs": ["-javaagent:/root/.m2/repository/org/jmockit/jmockit/1.49/jmockit-1.49.jar"]
},
"java.test.defaultConfig": "testConfig"
}
4 changes: 0 additions & 4 deletions jpo-ode-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
<artifactId>json</artifactId>
<version>20210307</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,128 +20,141 @@
import java.net.DatagramSocket;
import java.net.SocketException;

import org.apache.log4j.Logger;
import us.dot.its.jpo.ode.eventlog.EventLogger;

/**
* Sender/Forwarder helper class for use by Forwarder, Transport, and Data Sink that need to send packets around
* Sender/Forwarder helper class for use by Forwarder, Transport, and Data Sink
* that need to send packets around
*/
public class InetPacketSender {

private static final String INVALID_PARAMETERS_MSG = "Invalid Parameters. Parameters destination point and payload can not be null";

private static final Logger log = Logger.getLogger(InetPacketSender.class);
private static final String INVALID_PARAMETERS_MSG = "Invalid Parameters. Parameters destination point and payload can not be null";

/**
* Inet address and port to forward packets to
*/
private InetPoint frwdPoint;

/**
* Specifies whether outbound IPv4 messages should be send directly or forwarded. Default is send directly.
* Specifies whether outbound IPv4 messages should be send directly or
* forwarded. Default is send directly.
* To force forwarding IPv4 messages, set this variable to true.
*/
private boolean forwardAll;

public InetPacketSender() {}

public InetPacketSender() {
}

/**
* Creates an instance of the forwarder/sender helper class.
*
* @param frwdPoint is the destination to use for forwarding
*/
public InetPacketSender(InetPoint frwdPoint) {
this.frwdPoint = frwdPoint;
}

/**
* Forward packet. Intended client is the forwarder that received a packet
*
* @param inbound UDP packet
* @throws InetPacketException
* @throws InetPacketException
*/
public void forward(DatagramPacket packet) throws InetPacketException {
if ( packet == null ) {
log.warn("Ignoring forward request for null packet");
if (packet == null) {
EventLogger.logger.warn("Ignoring forward request for null packet");
return;
}
if ( frwdPoint == null )
if (frwdPoint == null)
throw new InetPacketException("Couldn't forward packet. Reason: Forwarding destination is not defined.");
send(frwdPoint, new InetPacket(packet).getBundle());
}

/**
* Send packet. Intended client is the forwarder that sends outbound packet
*
* @param packet outbound packet that contains destination+payload bundle
* @throws InetPacketException
* @throws InetPacketException
*/
public void send(DatagramPacket packet) throws InetPacketException {
if ( packet == null ) {
log.warn("Ignoring send request for null packet");
if (packet == null) {
EventLogger.logger.warn("Ignoring send request for null packet");
return;
}
InetPacket p = new InetPacket(packet);
InetPoint point = p.getPoint();
if ( point == null )
throw new InetPacketException("Couldn't send packet. Reason: Destination is not defined in the packet (not a bundle?)");
if (point == null)
throw new InetPacketException(
"Couldn't send packet. Reason: Destination is not defined in the packet (not a bundle?)");
send(point, p.getPayload());
}

/**
* Forward payload to be sent to dstPoint. Intended clients are Transport or Data Sink sending via forwarder
* Forward payload to be sent to dstPoint. Intended clients are Transport or
* Data Sink sending via forwarder
*
* @param dstPoint destination address and port for forwarder to forward to
* @param payload data to forward
* @param payload data to forward
* @throws InetPacketException
*/
public void forward(InetPoint dstPoint, byte[] payload) throws InetPacketException {
if ( dstPoint == null || payload == null )
if (dstPoint == null || payload == null)
throw new InetPacketException(INVALID_PARAMETERS_MSG);
if ( frwdPoint == null )
log.warn("Couldn't forward packet. Reason: Forwarding destination is not defined.");
if ( frwdPoint != null && (dstPoint.isIPv6Address() || isForwardAll()) ) {
if (frwdPoint == null)
EventLogger.logger.warn("Couldn't forward packet. Reason: Forwarding destination is not defined.");
if (frwdPoint != null && (dstPoint.isIPv6Address() || isForwardAll())) {
send(frwdPoint, new InetPacket(dstPoint, payload).getBundle());
} else {
log.debug("Using direct send instead of forwarding");
EventLogger.logger.debug("Using direct send instead of forwarding");
send(dstPoint, payload);
}
}

/**
* Forward payload to be sent to dstPoint. Intended clients are Transport or Data Sink sending via forwarder or direct
* @param dstPoint destination address and port of the final destination
* @param payload data to forward or send
* Forward payload to be sent to dstPoint. Intended clients are Transport or
* Data Sink sending via forwarder or direct
*
* @param dstPoint destination address and port of the final destination
* @param payload data to forward or send
* @param fromForwarder whether the original request came through a forwarder
* @throws InetPacketException
*/
public void forward(InetPoint dstPoint, byte[] payload, boolean fromForwarder) throws InetPacketException {
if ( dstPoint == null || payload == null )
if (dstPoint == null || payload == null)
throw new InetPacketException(INVALID_PARAMETERS_MSG);
if ( frwdPoint != null && (dstPoint.isIPv6Address() || isForwardAll() || fromForwarder) ) {
if (frwdPoint != null && (dstPoint.isIPv6Address() || isForwardAll() || fromForwarder)) {
send(frwdPoint, new InetPacket(dstPoint, payload).getBundle());
} else {
log.debug("Using direct send instead of forwarding");
EventLogger.logger.debug("Using direct send instead of forwarding");
send(dstPoint, payload);
}
}

/**
* Send payload to the destination specified. Intended clients are Transport or Data Sink sending directly to the client
* Send payload to the destination specified. Intended clients are Transport or
* Data Sink sending directly to the client
*
* @param dstPoint destination address and port to send to
* @param payload data to send
* @param payload data to send
* @throws InetPacketException
*/
public void send(InetPoint dstPoint, byte[] payload) throws InetPacketException {
if ( dstPoint == null || payload == null )
if (dstPoint == null || payload == null)
throw new InetPacketException(INVALID_PARAMETERS_MSG);
try(DatagramSocket sock = new DatagramSocket()) {
DatagramPacket packet = new DatagramPacket(payload, payload.length, dstPoint.getInetAddress(), dstPoint.port);
sock.send(packet);
} catch (SocketException ex) {
throw new InetPacketException("Couldn't send packet because socket closed.", ex);
} catch (IOException ex) {
throw new InetPacketException("Couldn't send packet due to IO exception.", ex);
}
try (DatagramSocket sock = new DatagramSocket()) {
DatagramPacket packet = new DatagramPacket(payload, payload.length, dstPoint.getInetAddress(),
dstPoint.port);
sock.send(packet);
} catch (SocketException ex) {
throw new InetPacketException("Couldn't send packet because socket closed.", ex);
} catch (IOException ex) {
throw new InetPacketException("Couldn't send packet due to IO exception.", ex);
}
}

/**
* Reports whether outbound IPv4 messages should be send directly or forwarded.
* Reports whether outbound IPv4 messages should be send directly or forwarded.
*
* @return true if IPv4 packets are forwarded in addition to IPv6 packets
*/
public boolean isForwardAll() {
Expand All @@ -150,11 +163,12 @@ public boolean isForwardAll() {

/**
*
* @param forwardAll Directs how to handle IPv4 messages.
* Specify true to force forwarding IPv4 messages, and false to always send them directly.
* @param forwardAll Directs how to handle IPv4 messages.
* Specify true to force forwarding IPv4 messages, and false
* to always send them directly.
*/
public void setForwardAll(boolean forwardAll) {
this.forwardAll = forwardAll;
}

}
Loading

0 comments on commit a93c507

Please sign in to comment.