Skip to content
Snippets Groups Projects
Commit c0922722 authored by Brutzman, Don's avatar Brutzman, Don
Browse files

refactor ChannelOpenDis7 for pduFactory and sending PDUs, first simkit process to use OpenDis7

parent b56c7ae7
No related branches found
No related tags found
No related merge requests found
......@@ -4,12 +4,16 @@
*/
package OpenDis7Examples;
import edu.nps.moves.dis7.enumerations.VariableRecordType;
import edu.nps.moves.dis7.pdus.CommentPdu;
import edu.nps.moves.dis7.pdus.Pdu;
import edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface;
import edu.nps.moves.dis7.utilities.DisTime;
import edu.nps.moves.dis7.utilities.PduFactory;
import edu.nps.moves.dis7.utilities.stream.PduRecorder;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
// import jdk.internal.vm.annotation.IntrinsicCandidate;
/**
......@@ -29,7 +33,10 @@ public class ChannelOpenDis7 {
protected boolean verboseComments = true;
String networkAddress = NETWORK_ADDRESS_DEFAULT;
int networkPort = NETWORK_PORT_DEFAULT;
DisTime.TimestampStyle timestampStyle = DisTime.TimestampStyle.IEEE_ABSOLUTE;
static DisTime.TimestampStyle timestampStyle = DisTime.TimestampStyle.IEEE_ABSOLUTE;
/** Creates DIS Protocol Data Unit (PDU) classes for simulation entities */
static PduFactory pduFactory;
// class variables
DisThreadedNetworkInterface disNetworkInterface;
......@@ -40,6 +47,7 @@ public class ChannelOpenDis7 {
public ChannelOpenDis7()
{
DisTime.setTimestampStyle(timestampStyle); // DISTime is a singleton shared class
pduFactory = new PduFactory(timestampStyle);
try
{
......@@ -136,6 +144,8 @@ public class ChannelOpenDis7 {
*/
protected void sendSinglePdu(Pdu pdu)
{
if (disNetworkInterface == null)
setUpNetworkInterface(); // ensure connected
try
{
disNetworkInterface.send(pdu);
......@@ -147,6 +157,45 @@ public class ChannelOpenDis7 {
System.exit(1);
}
}
/**
* Send Comment PDU
* @see <a href="https://docs.oracle.com/javase/tutorial/java/javaOO/arguments.html">Passing Information to a Method or a Constructor</a> Arbitrary Number of Arguments
* @param commentType enumeration value describing purpose of the narrative comment
* @param comments String array of narrative comments
*/
public void sendCommentPdu(VariableRecordType commentType,
// vararg... variable-length set of String comments can optionally follow
String... comments)
{
if ((comments != null) && (comments.length > 0))
{
ArrayList<String> newCommentsList = new ArrayList<>();
for (String comment : comments)
{
if (!comment.isEmpty())
{
newCommentsList.add(comment); // OK found something to send
}
}
if (!newCommentsList.isEmpty())
{
if (disNetworkInterface == null)
setUpNetworkInterface(); // ensure connected
if (commentType == null)
commentType = VariableRecordType.OTHER; // fallback value; TODO consider pushing into pduFactory
// now build the commentPdu from these string inputs, thus constructing a narrative entry
@SuppressWarnings("CollectionsToArray")
CommentPdu commentPdu = pduFactory.makeCommentPdu(commentType, newCommentsList.toArray(new String[0])); // comments);
sendSinglePdu(commentPdu);
if (isVerboseComments())
{
System.out.println("*** [CommentPdu narrative sent: " + commentType.name() + "] " + newCommentsList.toString());
System.out.flush();
}
}
}
}
/**
* test for verboseComments mode
......
......@@ -29,9 +29,6 @@ public class ExampleSimulationProgram extends ChannelOpenDis7
/** current simulation time */
double simulationTime;
/** Creates DIS Protocol Data Unit (PDU) classes for simulation entities */
PduFactory pduFactory = new PduFactory(timestampStyle);
/** EntityID settings for entity 1 */
protected EntityID entityID_1 = new EntityID();
/** EntityID settings for entity 2 */
......@@ -205,7 +202,6 @@ public class ExampleSimulationProgram extends ChannelOpenDis7
VariableRecordType narrativeComment = VariableRecordType.COMPLETE_EVENT_REPORT;
VariableRecordType statusComment = VariableRecordType.APPLICATION_STATUS;
VariableRecordType currentTimeStepComment = VariableRecordType.APPLICATION_TIMESTEP;
VariableRecordType otherComment = VariableRecordType.OTHER;
/**
* Constructor to create an instance of this class.
......@@ -231,20 +227,6 @@ public class ExampleSimulationProgram extends ChannelOpenDis7
setNetworkPort(port);
}
/**
* Send Comment PDU
* @see <a href="https://docs.oracle.com/javase/tutorial/java/javaOO/arguments.html">Passing Information to a Method or a Constructor</a> Arbitrary Number of Arguments
* @param commentType enumeration value describing purpose of the narrative comment
* @param comments String array of narrative comments
*/
public void sendCommentPdu(VariableRecordType commentType,
// vararg... variable-length set of String comments can optionally follow
String... comments)
{
sendAllPdusForLoopTimestep (null, null, commentType, comments);
}
/**
* Send EntityState, Fire, Comment PDUs that got updated for this loop, reflecting state of current simulation timestep.
* @see <a href="https://docs.oracle.com/javase/tutorial/java/javaOO/arguments.html">Passing Information to a Method or a Constructor</a> Arbitrary Number of Arguments
......@@ -264,34 +246,8 @@ public class ExampleSimulationProgram extends ChannelOpenDis7
if (firePdu != null)
sendSinglePdu(firePdu); // bang
if ((comments != null) && (comments.length > 0))
{
ArrayList<String> newCommentsList = new ArrayList<>();
for (String comment : comments)
{
if (!comment.isEmpty())
{
newCommentsList.add(comment); // OK found something to send
}
}
if (!newCommentsList.isEmpty())
{
if (commentType == null)
commentType = otherComment; // fallback value otherComment
// now build the commentPdu from these string inputs, thus constructing a narrative entry
@SuppressWarnings("CollectionsToArray")
CommentPdu commentPdu = pduFactory.makeCommentPdu(commentType, newCommentsList.toArray(new String[0])); // comments);
sendSinglePdu(commentPdu);
if (isVerboseComments())
{
System.out.println("*** [Narrative comment sent: " + commentType.name() + "] " + newCommentsList.toString());
System.out.flush();
}
}
}
sendCommentPdu(commentType, comments);
}
/**
* Initial execution via main() method: handle args array of command-line initialization (CLI) arguments here
......
......@@ -23,19 +23,19 @@ Recorder log file open: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\pduLog\
... My simulation just did something, no really...
... [Pausing for 1.0 seconds]
sending PDUs for simulation step 1, monitor loopback to confirm sent
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 1] DisPduType 01 ENTITY_STATE Entity #1, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 1] DisPduType 01 ENTITY_STATE Entity #1, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 1] DisPduType 01 ENTITY_STATE Entity #1, size 144 bytes)
[DisThreadedNetworkInterface PduRecorder] [receipt 1] DisPduType 01 ENTITY_STATE Entity #1, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 2] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 2] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface PduRecorder] [receipt 2] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 3] DisPduType 22 COMMENT, size 104 bytes)
[DisThreadedNetworkInterface PduRecorder] [receipt 3] DisPduType 22 COMMENT, size 104 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 3] DisPduType 22 COMMENT, size 104 bytes)
*** [Narrative comment sent: APPLICATION_TIMESTEP] [MV3500 ExampleSimulationProgram, runSimulation() loop 1]
[DisThreadedNetworkInterface PduRecorder] [receipt 3] DisPduType 22 COMMENT, size 104 bytes)
*** [CommentPdu narrative sent: APPLICATION_TIMESTEP] [MV3500 ExampleSimulationProgram, runSimulation() loop 1]
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 4] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 4] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
[DisThreadedNetworkInterface PduRecorder] [receipt 4] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 4] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
... [PDUs successfully sent for this loop]
... My simulation just did something, no really...
... [Pausing for 1.0 seconds]
......@@ -49,10 +49,10 @@ sending PDUs for simulation step 2, monitor loopback to confirm sent
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 7] DisPduType 22 COMMENT, size 104 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 7] DisPduType 22 COMMENT, size 104 bytes)
[DisThreadedNetworkInterface PduRecorder] [receipt 7] DisPduType 22 COMMENT, size 104 bytes)
*** [Narrative comment sent: APPLICATION_TIMESTEP] [MV3500 ExampleSimulationProgram, runSimulation() loop 2]
*** [CommentPdu narrative sent: APPLICATION_TIMESTEP] [MV3500 ExampleSimulationProgram, runSimulation() loop 2]
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 8] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
[DisThreadedNetworkInterface PduRecorder] [receipt 8] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 8] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
[DisThreadedNetworkInterface PduRecorder] [receipt 8] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
... [PDUs successfully sent for this loop]
... My simulation just did something, no really...
... [Pausing for 1.0 seconds]
......@@ -66,7 +66,7 @@ sending PDUs for simulation step 3, monitor loopback to confirm sent
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 11] DisPduType 22 COMMENT, size 104 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 11] DisPduType 22 COMMENT, size 104 bytes)
[DisThreadedNetworkInterface PduRecorder] [receipt 11] DisPduType 22 COMMENT, size 104 bytes)
*** [Narrative comment sent: APPLICATION_TIMESTEP] [MV3500 ExampleSimulationProgram, runSimulation() loop 3]
*** [CommentPdu narrative sent: APPLICATION_TIMESTEP] [MV3500 ExampleSimulationProgram, runSimulation() loop 3]
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 12] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 12] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
[DisThreadedNetworkInterface PduRecorder] [receipt 12] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
......@@ -81,9 +81,9 @@ sending PDUs for simulation step 4, monitor loopback to confirm sent
[DisThreadedNetworkInterface PduRecorder] [receipt 14] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 14] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 15] DisPduType 22 COMMENT, size 104 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 15] DisPduType 22 COMMENT, size 104 bytes)
[DisThreadedNetworkInterface PduRecorder] [receipt 15] DisPduType 22 COMMENT, size 104 bytes)
*** [Narrative comment sent: APPLICATION_TIMESTEP] [MV3500 ExampleSimulationProgram, runSimulation() loop 4]
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 15] DisPduType 22 COMMENT, size 104 bytes)
*** [CommentPdu narrative sent: APPLICATION_TIMESTEP] [MV3500 ExampleSimulationProgram, runSimulation() loop 4]
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 16] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 16] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
[DisThreadedNetworkInterface PduRecorder] [receipt 16] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
......@@ -92,24 +92,24 @@ sending PDUs for simulation step 4, monitor loopback to confirm sent
... [Pausing for 1.0 seconds]
sending PDUs for simulation step 5, monitor loopback to confirm sent
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 17] DisPduType 01 ENTITY_STATE Entity #1, size 144 bytes)
[DisThreadedNetworkInterface PduRecorder] [receipt 17] DisPduType 01 ENTITY_STATE Entity #1, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 17] DisPduType 01 ENTITY_STATE Entity #1, size 144 bytes)
[DisThreadedNetworkInterface PduRecorder] [receipt 17] DisPduType 01 ENTITY_STATE Entity #1, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 18] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 18] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface PduRecorder] [receipt 18] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 19] DisPduType 22 COMMENT, size 104 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 19] DisPduType 22 COMMENT, size 104 bytes)
[DisThreadedNetworkInterface PduRecorder] [receipt 19] DisPduType 22 COMMENT, size 104 bytes)
*** [Narrative comment sent: APPLICATION_TIMESTEP] [MV3500 ExampleSimulationProgram, runSimulation() loop 5]
*** [CommentPdu narrative sent: APPLICATION_TIMESTEP] [MV3500 ExampleSimulationProgram, runSimulation() loop 5]
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 20] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 20] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
[DisThreadedNetworkInterface PduRecorder] [receipt 20] DisPduType 01 ENTITY_STATE Entity #2, size 144 bytes)
... [PDUs successfully sent for this loop]
... [loop termination condition met, simulationComplete=true]
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 21] DisPduType 22 COMMENT, size 120 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 21] DisPduType 22 COMMENT, size 120 bytes)
[DisThreadedNetworkInterface PduRecorder] [receipt 21] DisPduType 22 COMMENT, size 120 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 21] DisPduType 22 COMMENT, size 120 bytes)
*** [Narrative comment sent: COMPLETE_EVENT_REPORT] [MV3500 ExampleSimulationProgram, runSimulation() completed successfully]
*** [CommentPdu narrative sent: COMPLETE_EVENT_REPORT] [MV3500 ExampleSimulationProgram, runSimulation() completed successfully]
... [final CommentPdu successfully sent for simulation]
*** setKillSentinelAndInterrupts() killed=true sendingThread.isInterrupted()=true receiveThread.isInterrupted()=true
[DisThreadedNetworkInterface PduRecorder] close(): pdus2send.size()=0 baos.size()=0 dos.size()=0
......
package SimkitOpenDis7Examples;
import OpenDis7Examples.ChannelOpenDis7;
import edu.nps.moves.dis7.enumerations.VariableRecordType;
import edu.nps.moves.dis7.pdus.CommentPdu;
import simkit.SimEntityBase;
import simkit.random.RandomVariate;
......@@ -28,8 +30,11 @@ public class ArrivalProcessOpenDis7 extends SimEntityBase {
/** initialization */
private void initialize()
{
channelOpenDis7.printTRACE ("opendis7.getNetworkAddress()=" + channelOpenDis7.getNetworkAddress());
channelOpenDis7.printlnTRACE (", getNetworkPort()=" + channelOpenDis7.getNetworkPort());
getChannelOpenDis7().setUpNetworkInterface();
getChannelOpenDis7().printlnTRACE ("opendis7.getNetworkAddress()=" + getChannelOpenDis7().getNetworkAddress() +
", getNetworkPort()=" + getChannelOpenDis7().getNetworkPort());
getChannelOpenDis7().sendCommentPdu(VariableRecordType.OTHER, "ArrivalProcessOpenDis7 initialized");
}
/**
......@@ -55,6 +60,7 @@ public class ArrivalProcessOpenDis7 extends SimEntityBase {
/**
* Initialize numberArrivals to 0
*/
@Override
public void reset() {
super.reset();
numberArrivals = 0;
......@@ -103,4 +109,11 @@ public class ArrivalProcessOpenDis7 extends SimEntityBase {
public int getNumberArrivals() {
return numberArrivals;
}
/**
* @return the channelOpenDis7
*/
public ChannelOpenDis7 getChannelOpenDis7() {
return channelOpenDis7;
}
}
......@@ -75,5 +75,9 @@ public class RunSimpleServerOpenDis7 {
System.out.printf("There have been %,d customers served%n", server.getNumberServed());
System.out.printf("Average number in queue\t%.4f%n", numberInQueueStat.getMean());
System.out.printf("Average utilization\t%.4f%n", 1.0 - numberAvailableServersStat.getMean() / server.getTotalNumberServers());
System.out.println("Execution complete.");
arrival.getChannelOpenDis7().tearDownNetworkInterface();
System.exit(0); // normal completion
}
}
ant -f C:\\x-nps-gitlab\\NetworkedGraphicsMV3500\\examples -Dnb.internal.action.name=debug.single -Djavac.includes=SimkitOpenDis7Examples/run/RunSimpleServerOpenDis7.java -Ddebug.class=SimkitOpenDis7Examples.run.RunSimpleServerOpenDis7 debug-single
ant -f C:\\x-nps-gitlab\\NetworkedGraphicsMV3500\\examples -Dnb.internal.action.name=run.single -Djavac.includes=SimkitOpenDis7Examples/run/RunSimpleServerOpenDis7.java -Drun.class=SimkitOpenDis7Examples.run.RunSimpleServerOpenDis7 run-single
init:
Deleting: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\build\built-jar.properties
deps-jar:
Updating property file: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\build\built-jar.properties
Compiling 1 source file to C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\build\classes
compile-single:
run-single:
[OpenDis7]thisHostName=IT160907-UWALPP
[DisThreadedNetworkInterface] using network interface PANGP Virtual Ethernet Adapter
[DisThreadedNetworkInterface] datagramSocket.joinGroup address=239.1.2.3 port=3000 isConnected()=false createDatagramSocket() complete.
[DisThreadedNetworkInterface] createThreads() receiveThread.isAlive()=true
[DisThreadedNetworkInterface] createThreads() sendingThread.isAlive()=true
Network confirmation: address=239.1.2.3 port=3000
Beginning pdu save to directory ./pduLog
Recorder log file open: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\pduLog\PduCaptureLog.dislog
[DisThreadedNetworkInterface] using network interface PANGP Virtual Ethernet Adapter
[DisThreadedNetworkInterface] datagramSocket.joinGroup address=239.1.2.3 port=3000 isConnected()=false createDatagramSocket() complete.
[DisThreadedNetworkInterface] createThreads() receiveThread.isAlive()=true
[DisThreadedNetworkInterface] createThreads() sendingThread.isAlive()=true
[PduRecorder PduRecorder] listening to IP address 239.1.2.3 on port 3000
[OpenDis7]opendis7.getNetworkAddress()=239.1.2.3, getNetworkPort()=3000
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 1] DisPduType 22 COMMENT, size 80 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 1] DisPduType 22 COMMENT, size 80 bytes)
[DisThreadedNetworkInterface PduRecorder] [receipt 1] DisPduType 22 COMMENT, size 80 bytes)
*** [CommentPdu narrative sent: OTHER] [ArrivalProcessOpenDis7 initialized]
ArrivalProcessOpenDis7.1
interarrivalTimeGenerator = Uniform (0.900, 2.200)
SimpleServer.2
......@@ -17,5 +35,13 @@ There have been 64,475 arrivals
There have been 64,472 customers served
Average number in queue 15.9655
Average utilization 0.9819
debug-single:
BUILD SUCCESSFUL (total time: 1 minute 9 seconds)
Execution complete.
*** setKillSentinelAndInterrupts() killed=true sendingThread.isInterrupted()=true receiveThread.isInterrupted()=true
[DisThreadedNetworkInterface PduRecorder] close(): pdus2send.size()=0 baos.size()=0 dos.size()=0
[DisThreadedNetworkInterface PduRecorder] datagramSocket.leaveGroup address=239.1.2.3 port=3000 isClosed()=true close() complete.
*** killThread() status: sendingThread.isAlive()=false sendingThread.isInterrupted()=true
*** killThread() status: receiveThread.isAlive()=false receiveThread.isInterrupted()=true
*** Thread close status: sendingThread.isAlive()=false receiveThread.isAlive()=false
PduRecorder.stop() closing recorder log file: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\pduLog\PduCaptureLog.dislog
BUILD SUCCESSFUL (total time: 5 seconds)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment