diff --git a/CoTreceiver/build.xml b/CoTreceiver/build.xml index 12be71fe8f25e333e1d5c272be27883d5b4c6b69..a601d899b3201082bff99c873311ec933aa524be 100644 --- a/CoTreceiver/build.xml +++ b/CoTreceiver/build.xml @@ -71,6 +71,16 @@ --> + <!-- TODO fix --> + <target name="run.default"> + <echo message="run.classpath=${run.classpath}"/> + <java classname="edu.nps.moves.cot.dis.CotMsgReceiver" + classpath=".;${run.classpath}"> + <arg line="--performanceTestSendCoT udp localhost 9999 1 1"/> + <jvmarg value="-Djava.net.preferIPv4Stack=true"/> + </java> + </target> + <target name="validate-cot-msg" description="Validate the CoT msg template"> <schemavalidate file="CoT Test TX/src/main/resources/cotMsgTemplate.xml" nonamespaceFile="lib/xsd/CoT Base-Event Schema (PUBLIC RELEASE).xsd"> <xmlcatalog> diff --git a/CoTreceiver/src/edu/nps/moves/cot/main/CoTMsgReceiver.java b/CoTreceiver/src/edu/nps/moves/cot/main/CoTMsgReceiver.java index a4c3b6c6fea29ffbeb2b564cd300664dd56dc977..6eddf2e4228ddbb1814e940f284783bb0b603120 100644 --- a/CoTreceiver/src/edu/nps/moves/cot/main/CoTMsgReceiver.java +++ b/CoTreceiver/src/edu/nps/moves/cot/main/CoTMsgReceiver.java @@ -1,138 +1,145 @@ -/* -Copyright (c) 1995-2024 held by the author(s). All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer - in the documentation and/or other materials provided with the - distribution. - * Neither the names of the Naval Postgraduate School (NPS) - Modeling, Virtual Environments and Simulation (MOVES) Institute - (http://www.nps.edu and https://my.nps.edu/web/moves) - nor the names of its contributors may be used to endorse or - promote products derived from this software without specific - prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. -*/ -package edu.nps.moves.cot.main; - -import edu.nps.moves.cot.dis.CoTMsgParserDisRunner; -import java.io.IOException; -import java.io.PipedInputStream; -import java.io.PipedOutputStream; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; -import mil.army.usareur.g3.mcsd.CoTUtils.*; -import mil.army.usareur.g3.mcsd.CoTExample.CustomCoTparser; - -/** CoT message receiver (UPD, TCP) main entry class. - * Based off of mil.army.usareur.g3.mcsd.CoTExample.CoTreceiver - * - * System.in simulation based on: https://stackoverflow.com/questions/1647907/junit-how-to-simulate-system-in-testing - * - * @author <a href="mailto:tdnorbra@nps.edu?subject=edu.nps.moves.main.CoTMsgReceiver">Terry Norbraten, NPS MOVES</a> - */ -public class CoTMsgReceiver { - - /** - * Utility method that sleeps for a period of time - * - * @param seconds integer that defines how many seconds to sleep - */ - private static void sleep(long seconds) { - try { - TimeUnit.SECONDS.sleep(seconds); - } catch (InterruptedException ex) { - Logger.getLogger(CoTMsgReceiver.class.getName()).log(Level.SEVERE, null, ex); - } - }//sleep - - /** - * @param args the command line arguments - */ - public static void main(String[] args) { - - boolean isTcp = args[1].equalsIgnoreCase("tcp"); - - // - Create a custom CoTparser class. See CustomCoTparser.java. - // - Override the coTeventHandler() to add your custom CoT data handling. - // - Invoke the customized parser: - CustomCoTparser cp = new CustomCoTparser(); - CoTMsgParserDisRunner disr = new CoTMsgParserDisRunner("CoT PLI data DIS transmitter"); - - // Manage several UDP and TCP listeners - // - Create a CoT connector - CoTconnectors connectors = new CoTconnectors(); - - // - Assign custom parsers to be used by the listeners. Note that the - // CoT custom parser must be assigned before the listeners are started - connectors.addCoTparser(cp); - connectors.addCoTparser(disr); - - // - Common usage example: - System.out.println("\n\nStarting listener pool\n"); - - if (isTcp) { - connectors.addTcpListener(9998); - connectors.startListener(9998); - } else { - connectors.addUdpListener(9999); // default packet size 1024 - connectors.startListener(9999); - } - - PipedOutputStream out = null; - - // Redirect an output stream to be read by an input stream in order to - // stop the TCP listener - try { - out = new PipedOutputStream(); - System.setIn(new PipedInputStream(out)); - } catch (IOException ex) {} - - // Start the CoT message generator/server - Runnable r = () -> { - com.aciedge.cotplitool.Main.main(args); - }; - Thread t = new Thread(r); - t.setDaemon(true); - t.start(); - - sleep(5L); - - System.out.println("\n\nStopping listener pool\n"); - - if (isTcp) - connectors.stopListener(9998); - else - connectors.stopListener(9999); - - // Issue the CoT message generator/server quit/exit command - try { - if (out != null) - out.write("quit\n".getBytes("utf-8")); - } catch (IOException ex) {} - - // Shutdown the DIS listerner - disr.getDisChannel().tearDownNetworkInterface(); - - }// main - -} // end class CoTMsgReceiver +/* +Copyright (c) 1995-2024 held by the author(s). All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + * Neither the names of the Naval Postgraduate School (NPS) + Modeling, Virtual Environments and Simulation (MOVES) Institute + (http://www.nps.edu and https://my.nps.edu/web/moves) + nor the names of its contributors may be used to endorse or + promote products derived from this software without specific + prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +*/ +package edu.nps.moves.cot.main; + +import edu.nps.moves.cot.dis.CoTMsgParserDisRunner; +import java.io.IOException; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; +import java.util.concurrent.TimeUnit; +import java.util.logging.Level; +import java.util.logging.Logger; +import mil.army.usareur.g3.mcsd.CoTUtils.*; +import mil.army.usareur.g3.mcsd.CoTExample.CustomCoTparser; + +/** CoT message receiver (UPD, TCP) main entry class. + * Based off of mil.army.usareur.g3.mcsd.CoTExample.CoTreceiver + * + * System.in simulation based on: https://stackoverflow.com/questions/1647907/junit-how-to-simulate-system-in-testing + * + * @author <a href="mailto:tdnorbra@nps.edu?subject=edu.nps.moves.main.CoTMsgReceiver">Terry Norbraten, NPS MOVES</a> + */ +public class CoTMsgReceiver { + + /** + * Utility method that sleeps for a period of time + * + * @param seconds integer that defines how many seconds to sleep + */ + private static void sleep(long seconds) { + try { + TimeUnit.SECONDS.sleep(seconds); + } catch (InterruptedException ex) { + Logger.getLogger(CoTMsgReceiver.class.getName()).log(Level.SEVERE, null, ex); + } + }//sleep + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + + System.out.print ("CoTMsgReceiver"); + for (String arg:args) + { + System.out.print (" " + arg); + } + System.out.println(); + + boolean isTcp = args[1].equalsIgnoreCase("tcp"); + + // - Create a custom CoTparser class. See CustomCoTparser.java. + // - Override the coTeventHandler() to add your custom CoT data handling. + // - Invoke the customized parser: + CustomCoTparser cp = new CustomCoTparser(); + CoTMsgParserDisRunner disr = new CoTMsgParserDisRunner("CoT PLI data DIS transmitter"); + + // Manage several UDP and TCP listeners + // - Create a CoT connector + CoTconnectors connectors = new CoTconnectors(); + + // - Assign custom parsers to be used by the listeners. Note that the + // CoT custom parser must be assigned before the listeners are started + connectors.addCoTparser(cp); + connectors.addCoTparser(disr); + + // - Common usage example: + System.out.println("\n\nStarting listener pool\n"); + + if (isTcp) { + connectors.addTcpListener(9998); + connectors.startListener(9998); + } else { + connectors.addUdpListener(9999); // default packet size 1024 + connectors.startListener(9999); + } + + PipedOutputStream out = null; + + // Redirect an output stream to be read by an input stream in order to + // stop the TCP listener + try { + out = new PipedOutputStream(); + System.setIn(new PipedInputStream(out)); + } catch (IOException ex) {} + + // Start the CoT message generator/server + Runnable r = () -> { + com.aciedge.cotplitool.Main.main(args); + }; + Thread t = new Thread(r); + t.setDaemon(true); + t.start(); + + sleep(5L); + + System.out.println("\n\nStopping listener pool\n"); + + if (isTcp) + connectors.stopListener(9998); + else + connectors.stopListener(9999); + + // Issue the CoT message generator/server quit/exit command + try { + if (out != null) + out.write("quit\n".getBytes("utf-8")); + } catch (IOException ex) {} + + // Shutdown the DIS listerner + disr.getDisChannel().tearDownNetworkInterface(); + + }// main + +} // end class CoTMsgReceiver diff --git a/CoTreceiver/test/.gitikeep b/CoTreceiver/test/.gitikeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391