-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add Sensor/Detector Registration to Infrastructure Ambassador #152
Changes from 41 commits
69a8ca8
2f201f4
be88743
a5d58ec
364fcae
c699981
d552372
b6811ec
ebeb5b2
8337c64
bbd2003
4c88de3
1cec564
8a78b85
0dc36d8
70dbb62
beef07d
da3bf45
5b7cf1b
e0b789a
a1b82d4
4bb37a4
f94bf76
07799c0
5d347d7
8d0c6ea
f2c5463
0f9e37c
8fb2676
b444173
483fc99
7c9b453
35c45a5
0eaef9e
90675be
522233f
e6ad177
cee7b84
cd0f635
9a0fe43
a837403
d3276a9
99038aa
66769eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,17 +16,19 @@ | |
|
||
package org.eclipse.mosaic.fed.infrastructure.ambassador; | ||
|
||
import org.eclipse.mosaic.lib.geo.CartesianPoint; | ||
|
||
import java.io.IOException; | ||
import java.net.DatagramPacket; | ||
import java.net.DatagramSocket; | ||
import java.net.InetAddress; | ||
import java.util.List; | ||
|
||
import org.eclipse.mosaic.lib.geo.CartesianPoint; | ||
import org.eclipse.mosaic.lib.objects.detector.Detector; | ||
|
||
/** | ||
* InfrastructureInstance class represents a physical instance of an | ||
* infrastructure node in the simulated environment. | ||
* It contains information about the infrastructure node such as its ID, | ||
* infrastructure instance in the simulated environment. | ||
* It contains information about the infrastructure instance such as its ID, | ||
* location, target address, and ports. | ||
dan-du-car marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
public class InfrastructureInstance { | ||
|
@@ -35,40 +37,48 @@ public class InfrastructureInstance { | |
private InetAddress targetAddress; | ||
private int rxMessagePort; | ||
private int timeSyncPort; | ||
private int simulatedInteractionPort; | ||
dan-du-car marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private CartesianPoint location = null; | ||
private DatagramSocket rxMsgsSocket = null; | ||
private DatagramSocket socket = null; | ||
private List<Detector> sensors; | ||
|
||
/** | ||
* Constructor for InfrastructureInstance | ||
* | ||
* @param infrastructureId the ID of the infrastructure node | ||
* @param targetAddress the target IP address of the infrastructure node | ||
* @param rxMessagePort the receive message port of the infrastructure node | ||
* @param timeSyncPort the time synchronization port of the infrastructure | ||
* node | ||
* @param location the location of the infrastructure node in the | ||
* simulated environment | ||
*/ | ||
public InfrastructureInstance(String infrastructureId, InetAddress targetAddress, | ||
int rxMessagePort, int timeSyncPort, CartesianPoint location) { | ||
* @param infrastructureId the ID of the infrastructure instance. | ||
* @param targetAddress the target IP address of the infrastructure instance. | ||
* @param rxMessagePort the receive V2X message port of the infrastructure instance. | ||
dan-du-car marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @param timeSyncPort the receive time synchronization message port of the infrastructure. | ||
* | ||
* @param simulatedInteractionPort the receive simulated interaction message port of the infrastructure | ||
* instance. | ||
* @param location the location of the infrastructure instance in the | ||
* simulated environment | ||
*/ | ||
public InfrastructureInstance(String infrastructureId, InetAddress targetAddress, int rxMessagePort, | ||
int timeSyncPort, int simulatedInteractionPort, CartesianPoint location, List<Detector> sensors) { | ||
this.infrastructureId = infrastructureId; | ||
this.targetAddress = targetAddress; | ||
this.rxMessagePort = rxMessagePort; | ||
this.timeSyncPort = timeSyncPort; | ||
this.simulatedInteractionPort = simulatedInteractionPort; | ||
this.location = location; | ||
this.sensors = sensors; | ||
} | ||
|
||
|
||
|
||
/** | ||
* Returns the target IP address of the infrastructure node | ||
* Returns the target IP address of the infrastructure instance | ||
* | ||
* @return InetAddress the target IP address of the infrastructure node | ||
* @return InetAddress the target IP address of the infrastructure instance | ||
*/ | ||
public InetAddress getTargetAddress() { | ||
return targetAddress; | ||
} | ||
|
||
/** | ||
* Sets the target IP address of the infrastructure node | ||
* Sets the target IP address of the infrastructure instance | ||
* | ||
* @param targetAddress the target IP address to set | ||
*/ | ||
|
@@ -77,16 +87,16 @@ public void setTargetAddress(InetAddress targetAddress) { | |
} | ||
|
||
/** | ||
* Returns the location of the infrastructure node in the simulated environment | ||
* Returns the location of the infrastructure instance in the simulated environment | ||
* | ||
* @return CartesianPoint the location of the infrastructure node | ||
* @return CartesianPoint the location of the infrastructure instance | ||
*/ | ||
public CartesianPoint getLocation() { | ||
return this.location; | ||
} | ||
|
||
/** | ||
* Sets the location of the infrastructure node in the simulated environment | ||
* Sets the location of the infrastructure instance in the simulated environment | ||
* | ||
* @param location the location to set | ||
*/ | ||
|
@@ -95,16 +105,16 @@ public void setLocation(CartesianPoint location) { | |
} | ||
|
||
/** | ||
* Returns the ID of the infrastructure node | ||
* Returns the ID of the infrastructure instance | ||
* | ||
* @return String the ID of the infrastructure node | ||
* @return String the ID of the infrastructure instance | ||
*/ | ||
public String getInfrastructureId() { | ||
return infrastructureId; | ||
} | ||
|
||
/** | ||
* Sets the ID of the infrastructure node | ||
* Sets the ID of the infrastructure instance | ||
* | ||
* @param infrastructureId the ID to set | ||
*/ | ||
|
@@ -113,16 +123,16 @@ public void setInfrastructureId(String infrastructureId) { | |
} | ||
|
||
/** | ||
* Returns the receive message port of the infrastructure node | ||
* Returns the receive message port of the infrastructure instance | ||
* | ||
* @return int the receive message port of the infrastructure node | ||
* @return int the receive message port of the infrastructure instance | ||
*/ | ||
public int getRxMessagePort() { | ||
return rxMessagePort; | ||
} | ||
|
||
/** | ||
* Sets the receive message port of the infrastructure node | ||
* Sets the receive message port of the infrastructure instance | ||
* | ||
* @param rxMessagePort the port to set | ||
*/ | ||
|
@@ -131,22 +141,79 @@ public void setRxMessagePort(int rxMessagePort) { | |
} | ||
|
||
/** | ||
* Returns the time synchronization port of the infrastructure node | ||
* Returns the time synchronization port of the infrastructure instance | ||
* | ||
* @return int the time synchronization port of the infrastructure node | ||
* @return int the time synchronization port of the infrastructure instance | ||
*/ | ||
public int getTimeSyncPort() { | ||
return timeSyncPort; | ||
} | ||
|
||
/** | ||
* Sets the time synchronization port of the infrastructure node | ||
* Sets the time synchronization port of the infrastructure instance | ||
* | ||
* @param timeSyncPort the port to set | ||
*/ | ||
public void setTimeSyncPort(int timeSyncPort) { | ||
this.timeSyncPort = timeSyncPort; | ||
} | ||
|
||
/** | ||
* Returns the simulated interaction port of the infrastructure instance. | ||
* | ||
* @return int simulated interaction port of the infrastructure instance. | ||
*/ | ||
public int getSimulatedInteractionPort() { | ||
return simulatedInteractionPort; | ||
} | ||
|
||
|
||
/** | ||
* Sets the simulated interaction port of the infrastructure instance. | ||
* | ||
* @param simulatedInteractionPort int simulated interaction port of the infrastructure | ||
* instance. | ||
*/ | ||
public void setSimulatedInteractionPort(int simulatedInteractionPort) { | ||
dan-du-car marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.simulatedInteractionPort = simulatedInteractionPort; | ||
} | ||
|
||
|
||
/** | ||
* Returns list of Sensor/Detectors registered to this infrastructure instance. | ||
* | ||
* @return list of detectors registered to infrastructure instance. | ||
*/ | ||
public List<Detector> getSensors() { | ||
return sensors; | ||
} | ||
|
||
|
||
/** | ||
* Sets list of Sensors/Detectors registered to infrastructure instance. | ||
* | ||
* @param sensors list of detectors registered to infrastructure instance. | ||
*/ | ||
public void setSensors(List<Detector> sensors) { | ||
this.sensors = sensors; | ||
} | ||
|
||
|
||
/** | ||
* Method that returns boolean value based on whether any registered Sensor/Detector | ||
* in the sensor list has a sensorId equivalent to the passed parameter. | ||
* | ||
* @param sensorId sensor ID to search for | ||
* @return true if sensor with sensor ID exists in sensor list. False otherwise. | ||
*/ | ||
public boolean containsSensor(String sensorId) { | ||
for (Detector sensor : sensors) { | ||
if (sensor.getSensorId().equals(sensorId) ) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Creates a DatagramSocket object and binds it to this infrastructure | ||
|
@@ -156,7 +223,7 @@ public void setTimeSyncPort(int timeSyncPort) { | |
* methods | ||
*/ | ||
public void bind() throws IOException { | ||
rxMsgsSocket = new DatagramSocket(); | ||
socket = new DatagramSocket(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. renamed to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The bind() gives the vibe that we are creating a UDP server socket and trying to bind it to a particular port. But this infrastructure instance in fact acts as a series of UDP clients and send packet to the remote infrastructure identified by the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not really part of the scope for this PR but I can look into a better naming convention for this method. It is a single client though, just different ports which can be assigned at the datagrampacket level not the socket level. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed to connect |
||
} | ||
|
||
/** | ||
|
@@ -167,27 +234,40 @@ public void bind() throws IOException { | |
* @throws IOException If there is an issue with the underlying socket object or | ||
* methods | ||
*/ | ||
public void sendMsgs(byte[] data) throws IOException { | ||
if (rxMsgsSocket == null) { | ||
throw new IllegalStateException("Attempted to send data before opening socket"); | ||
} | ||
DatagramPacket packet = new DatagramPacket(data, data.length, targetAddress, rxMessagePort); | ||
rxMsgsSocket.send(packet); | ||
|
||
public void sendV2xMsg(byte[] data) throws IOException { | ||
sendPacket(data, rxMessagePort); | ||
} | ||
|
||
/** | ||
* Sends time sync data to the Infrastructure Device communications interface configured at construction time. | ||
* Sends time sync data to the Infrastrucutre Instance Time Sync port. | ||
* | ||
* @param data The binary data to transmit | ||
* @throws IOException If there is an issue with the underlying socket object or methods | ||
*/ | ||
public void sendTimeSyncMsg(byte[] data) throws IOException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have we defined a class for the Time Sync message? I feel like it might be cleaner to have this (and the interaction one below) take in some type more meaningful than a byte[]. I think it make sense in the v2x message case because byte[] is actually the real type of a V2XMessage, but the time data and (I imagine) the interaction data are more higher-level than that. |
||
sendPacket(data, timeSyncPort); | ||
} | ||
/** | ||
* Sends time sync data to the Infrastrucutre Instance Simulated Interaction port. | ||
* | ||
* @param data The binary data to transmit | ||
* @throws IOException If there is an issue with the underlying socket object or methods | ||
*/ | ||
public void sendTimeSyncMsgs(byte[] data) throws IOException { | ||
if (rxMsgsSocket == null) { | ||
public void sendInteraction(byte[] data) throws IOException { | ||
sendPacket(data, simulatedInteractionPort); | ||
} | ||
/** | ||
* Method to send byte data to specified port using the infrastructure instance Datagramsocket. | ||
* | ||
* @param data byte data to send using Datagramsocket. | ||
* @param port in integer format to send Datagram to. | ||
* @throws IOException | ||
*/ | ||
public void sendPacket(byte[] data, int port) throws IOException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New method created to avoid code duplication between sendTimeSyncMsg sendV2xMsg and sendInteraction |
||
if (socket == null) { | ||
dan-du-car marked this conversation as resolved.
Show resolved
Hide resolved
|
||
throw new IllegalStateException("Attempted to send data before opening socket"); | ||
} | ||
|
||
DatagramPacket packet = new DatagramPacket(data, data.length, targetAddress, timeSyncPort); | ||
rxMsgsSocket.send(packet); | ||
|
||
DatagramPacket packet = new DatagramPacket(data, data.length, targetAddress, port); | ||
socket.send(packet); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This package is already included in the infrastructure ambassador pom as a dependency but I had to add the test-jar to gain access to Rules used to initialize singletons for unit testing. See GeoProjectionRule and IpResolverRule in the InfrastructureMessageAdapterTest.