diff --git a/assignments/nbproject/genfiles.properties b/assignments/nbproject/genfiles.properties index 8db6e92d16272035af6f8a5e7dfdeadb03984180..81515a0c3dec1f6ab1d66241d0881f2f5426139c 100644 --- a/assignments/nbproject/genfiles.properties +++ b/assignments/nbproject/genfiles.properties @@ -1,5 +1,5 @@ -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=5eaf4250 -nbproject/build-impl.xml.script.CRC32=013963da -nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=5eaf4250 +nbproject/build-impl.xml.script.CRC32=013963da +nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC1_MCAST_PduReceiver.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC1_MCAST_PduReceiver.java new file mode 100644 index 0000000000000000000000000000000000000000..a07ab479d855a9231c6f29a5da7afb4886477501 --- /dev/null +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC1_MCAST_PduReceiver.java @@ -0,0 +1,80 @@ +package MV3500Cohort2019JulySeptember.homework2.Brennenstuhl.BRE_KNO_MCC; + +import java.net.*; +import java.io.*; + +import edu.nps.moves.dis7.*; +import edu.nps.moves.dis7.enumerations.*; +import edu.nps.moves.dis7.util.*; + +public class BRE_KNO_MCC_PC1_MCAST_PduReceiver +{ + public static final int DEFAULT_MULTICAST_PORT = BRE_KNO_MCC_PC1_MCAST_PduSender.DEFAULT_MULTICAST_PORT; + public static final String DEFAULT_MULTICAST_ADDRESS = BRE_KNO_MCC_PC1_MCAST_PduSender.DEFAULT_MULTICAST_ADDRESS; + public static final boolean USE_FAST_ESPDU = false; + + public static void main(String args[]) + { + PduFactory factory; + MulticastSocket socket; + InetAddress address; + DatagramPacket packet; + + try { + System.out.println("Knobeloch_PduReceiver started..."); + if (args.length == 2) { + socket = new MulticastSocket(Integer.parseInt(args[0])); + address = InetAddress.getByName(args[1]); + } + else { + System.out.println("Usage: AllPduReceiver <port> <multicast group>"); + System.out.println("Default: AllPduReceiver " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS); + socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); + address = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); + } + socket.joinGroup(address); + + factory = new PduFactory(); + + while (true) // Loop infinitely, receiving datagrams + { + byte buffer[] = new byte[1500]; // typical MTU size + + packet = new DatagramPacket(buffer, buffer.length); // reset + + socket.receive(packet); + + Pdu pdu = factory.createPdu(packet.getData()); + if (pdu != null) { + DISPDUType currentPduType = pdu.getPduType(); //short currentPduType = pdu.getPduType(); + String currentPduTypeName = pdu.getClass().getName(); + DISProtocolFamily currentProtocolFamilyID = pdu.getProtocolFamily(); //short currentProtocolFamilyID = pdu.getProtocolFamily(); + //String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName(); + + StringBuilder message = new StringBuilder(); + message.append("received DIS PDU "); + if (currentPduType.getValue() < 10) + message.append(" "); + message.append(currentPduType.getValue()); + String currentPduTypePadded = String.format("%-34s", currentPduType); // - indicates right padding of whitespace + message.append(" " ).append(currentPduTypePadded); + String currentPduTypeNamePadded = String.format("%-49s", currentPduTypeName); // - indicates right padding of whitespace + message.append(" of type ").append(currentPduTypeNamePadded); // package.class name + message.append(" (protocolFamily ").append(currentProtocolFamilyID); +// message.append(" ").append(currentPduFamilyName); // class name is also available + message.append(")"); + System.out.println(message.toString()); + } + else + System.out.println("received packet but pdu is null, packet.getData().length=" + packet.getData().length + ", error..."); + } + } + catch (IOException e) { + System.out.println("Problem with BRE_KNO_MCC_PC1_MCAST_PduReceiver, see exception trace:"); + System.out.println(e); + } + finally { + System.out.println("BRE_KNO_MCC_PC1_MCAST_PduReceiver complete."); + } + } +} diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC1_MCAST_PduSender.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC1_MCAST_PduSender.java new file mode 100755 index 0000000000000000000000000000000000000000..8cb5ac2f80c54ee687461dfccc2181477ed887f1 --- /dev/null +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC1_MCAST_PduSender.java @@ -0,0 +1,178 @@ +package MV3500Cohort2019JulySeptember.homework2.Brennenstuhl.BRE_KNO_MCC; + +import java.io.*; +import java.net.*; +import java.util.*; + +import edu.nps.moves.dis7.*; +import edu.nps.moves.dis7.enumerations.*; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * This is an example that sends many/most types of PDUs. Useful for testing standards + * compliance or getting a full set of PDUs. It also writes the generated PDUs to an XML file. + * Adapted from OpenDIS library example package edu.nps.moves.examples + * + * @author DMcG + * @version $Id:$ + */ +public class BRE_KNO_MCC_PC1_MCAST_PduSender +{ + /** Default multicast group address we send on. */ + public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3"; + + /** Default multicast port used, matches Wireshark DIS capture default */ + public static final int DEFAULT_MULTICAST_PORT = 2342; + + private int port; + InetAddress multicastAddress; + + public BRE_KNO_MCC_PC1_MCAST_PduSender(int port, String multicast) { + try + { + this.port = port; + multicastAddress = InetAddress.getByName(multicast); + if (!multicastAddress.isMulticastAddress()) + { + System.out.println("Not a multicast address: " + multicast); + } + } + catch (UnknownHostException e) { + System.out.println("Unable to open socket: " + e); + } + } + + public void run(int numbOfPDUS) + { + System.out.println("BRE_KNO_MCC_PC1_MCAST_PduSender started..."); + System.out.println("Generate PDUs and note issues, if any..."); + + List<Pdu> generatedPdusList = createPDU(numbOfPDUS); + + // Send the PDUs we created + System.out.println("Send the " + generatedPdusList.size() + " PDUs we created..."); + + try + { + InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); + MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); + socket.joinGroup(localMulticastAddress); + + for (int idx = 0; idx < generatedPdusList.size(); idx++) + { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + byte[] buffer; + + Pdu aPdu = generatedPdusList.get(idx); + try { + aPdu.marshal(dos); + } catch (Exception ex) { + Logger.getLogger(BRE_KNO_MCC_PC1_MCAST_PduSender.class.getName()).log(Level.SEVERE, null, ex); + } + + buffer = baos.toByteArray(); + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); + socket.send(packet); + try { + Thread.sleep(100L); + } catch (InterruptedException ex) { + } + String currentPduTypeValuePadded = String.format("%2s", aPdu.getPduType().getValue()); + String currentPduTypePadded = String.format("%-34s", aPdu.getPduType()); // - indicates right padding of whitespace + System.out.print ("Sent DIS PDU " + currentPduTypeValuePadded + " " + currentPduTypePadded ); + System.out.println(" of type " + aPdu.getClass().getName()); + } + } + catch (IOException e) + { + System.out.println(e); + } + } + + public static void main(String args[]) + { + if (args.length == 2) + { + BRE_KNO_MCC_PC1_MCAST_PduSender sender = new BRE_KNO_MCC_PC1_MCAST_PduSender(Integer.parseInt(args[0]), args[1]); + sender.run(5); + } + else + { + System.out.println("Usage: BRE_KNO_MCC_PC1_MCAST_PduSender <port> <multicast group>"); + System.out.println("Default: BRE_KNO_MCC_PC1_MCAST_PduSender " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS); + BRE_KNO_MCC_PC1_MCAST_PduSender sender = new BRE_KNO_MCC_PC1_MCAST_PduSender(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); + sender.run(5); + } + System.out.println("BRE_KNO_MCC_PC1_MCAST_PduSender complete."); + } + + private List<Pdu> createPDU(int numbOfPDUs) + { + List<Pdu> list = new ArrayList<>(); + List<Short> entityIDs = new ArrayList<>(); + Random r = new Random(); + + //generate Entity ID (no douplications) + for (int i = 0; i < numbOfPDUs; i++) + { + short temp = (short) r.nextInt(); + while (entityIDs.contains(temp)) + { + temp = (short) r.nextInt(); + } + entityIDs.add(temp); + } + + // + for (int i = 0; i < numbOfPDUs; i++){ + EntityStatePdu myPdu = new EntityStatePdu(); + + //ID + EntityID tempID = new EntityID(); + tempID.setEntityID(entityIDs.get(i)); + myPdu.setEntityID(tempID); + + //Enemy or Friend + myPdu.setForceId(ForceID.FRIENDLY); + + //location + Vector3Double tempLoc = new Vector3Double(); + tempLoc.setX(r.nextInt(1000) + r.nextDouble()); + tempLoc.setY(r.nextInt(1000) + r.nextDouble()); + tempLoc.setZ(r.nextInt(1000) + r.nextDouble()); + + myPdu.setEntityLocation(tempLoc); + + //orientation + EulerAngles tempOri = new EulerAngles(); + tempOri.setPhi(r.nextFloat()); + tempOri.setPsi(r.nextFloat()); + tempOri.setTheta(r.nextFloat()); + + myPdu.setEntityOrientation(tempOri); + + + //velocity + Vector3Double tempVel = new Vector3Double(); + tempVel.setX(r.nextDouble()); + tempVel.setY(r.nextDouble()); + tempVel.setZ(r.nextDouble()); + + myPdu.setEntityLocation(tempVel); + + +// Category? Country? Domain?... +// EntityType tempType = new EntityType(); +// tempType.set +// myPdu.setEntityType(tempType) + + list.add(myPdu); + } + + + return list; + } +} + diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC2_MCAST_MessageList.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC2_MCAST_MessageList.java new file mode 100644 index 0000000000000000000000000000000000000000..c323c0aaf28c923f18832b9502be631483978039 --- /dev/null +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC2_MCAST_MessageList.java @@ -0,0 +1,18 @@ +package MV3500Cohort2019JulySeptember.homework2.Brennenstuhl.BRE_KNO_MCC; + +import java.util.HashSet; + + +public class BRE_KNO_MCC_PC2_MCAST_MessageList { + + HashSet<String> savedMCASTMessages = new HashSet(); + + public void addMassage(String str){ + savedMCASTMessages.add(str); + } + + public HashSet<String> getSavedMCASTMessages(){ + HashSet<String> temp = new HashSet(savedMCASTMessages); + return temp; + } +} diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC2_MCAST_PduReceiver.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC2_MCAST_PduReceiver.java new file mode 100644 index 0000000000000000000000000000000000000000..e392871b1835bc928ae6fd407c8ecad0345a8e4a --- /dev/null +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC2_MCAST_PduReceiver.java @@ -0,0 +1,82 @@ +package MV3500Cohort2019JulySeptember.homework2.Brennenstuhl.BRE_KNO_MCC; + +import java.net.*; +import java.io.*; + +import edu.nps.moves.dis7.*; +import edu.nps.moves.dis7.enumerations.*; +import edu.nps.moves.dis7.util.*; + +public class BRE_KNO_MCC_PC2_MCAST_PduReceiver +{ + public static final int DEFAULT_MULTICAST_PORT = BRE_KNO_MCC_PC2_MCAST_PduSender.DEFAULT_MULTICAST_PORT; + public static final String DEFAULT_MULTICAST_ADDRESS = BRE_KNO_MCC_PC2_MCAST_PduSender.DEFAULT_MULTICAST_ADDRESS; + public static final boolean USE_FAST_ESPDU = false; + + + public static void main(String args[]) + { + PduFactory factory; + MulticastSocket socket; + InetAddress address; + DatagramPacket packet; + + try { + + System.out.println("BRE_KNO_MCC_PC2_MCAST_PduReceiver started..."); + if (args.length == 2) { + socket = new MulticastSocket(Integer.parseInt(args[0])); + address = InetAddress.getByName(args[1]); + } + else { + System.out.println("Usage: BRE_KNO_MCC_PC2_MCAST_PduReceiver <port> <multicast group>"); + System.out.println("Default: BRE_KNO_MCC_PC2_MCAST_PduReceiver " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS); + socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); + address = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); + } + socket.joinGroup(address); + + factory = new PduFactory(); + + while (true) // Loop infinitely, receiving datagrams + { + byte buffer[] = new byte[1500]; // typical MTU size + + packet = new DatagramPacket(buffer, buffer.length); // reset + + socket.receive(packet); + + Pdu pdu = factory.createPdu(packet.getData()); + if (pdu != null) { + DISPDUType currentPduType = pdu.getPduType(); //short currentPduType = pdu.getPduType(); + String currentPduTypeName = pdu.getClass().getName(); + DISProtocolFamily currentProtocolFamilyID = pdu.getProtocolFamily(); //short currentProtocolFamilyID = pdu.getProtocolFamily(); + //String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName(); + + StringBuilder message = new StringBuilder(); + message.append("received DIS PDU "); + if (currentPduType.getValue() < 10) + message.append(" "); + message.append(currentPduType.getValue()); + String currentPduTypePadded = String.format("%-34s", currentPduType); // - indicates right padding of whitespace + message.append(" " ).append(currentPduTypePadded); + String currentPduTypeNamePadded = String.format("%-49s", currentPduTypeName); // - indicates right padding of whitespace + message.append(" of type ").append(currentPduTypeNamePadded); // package.class name + message.append(" (protocolFamily ").append(currentProtocolFamilyID); +// message.append(" ").append(currentPduFamilyName); // class name is also available + message.append(")"); + System.out.println(message.toString()); + } + else + System.out.println("received packet but pdu is null, packet.getData().length=" + packet.getData().length + ", error..."); + } + } + catch (IOException e) { + System.out.println("Problem with BRE_KNO_MCC_PC2_MCAST_PduReceiver, see exception trace:"); + System.out.println(e); + } + finally { + System.out.println("BRE_KNO_MCC_PC2_MCAST_PduReceiver complete."); + } + } +} diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC2_MCAST_PduSender.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC2_MCAST_PduSender.java new file mode 100755 index 0000000000000000000000000000000000000000..e7b704fe6e2ed66dffae4c4a2c23570c23ab40aa --- /dev/null +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC2_MCAST_PduSender.java @@ -0,0 +1,178 @@ +package MV3500Cohort2019JulySeptember.homework2.Brennenstuhl.BRE_KNO_MCC; + +import java.io.*; +import java.net.*; +import java.util.*; + +import edu.nps.moves.dis7.*; +import edu.nps.moves.dis7.enumerations.*; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * This is an example that sends many/most types of PDUs. Useful for testing standards + * compliance or getting a full set of PDUs. It also writes the generated PDUs to an XML file. + * Adapted from OpenDIS library example package edu.nps.moves.examples + * + * @author DMcG + * @version $Id:$ + */ +public class BRE_KNO_MCC_PC2_MCAST_PduSender +{ + /** Default multicast group address we send on. */ + public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3"; + + /** Default multicast port used, matches Wireshark DIS capture default */ + public static final int DEFAULT_MULTICAST_PORT = 2342; + + private int port; + InetAddress multicastAddress; + + public BRE_KNO_MCC_PC2_MCAST_PduSender(int port, String multicast) { + try + { + this.port = port; + multicastAddress = InetAddress.getByName(multicast); + if (!multicastAddress.isMulticastAddress()) + { + System.out.println("Not a multicast address: " + multicast); + } + } + catch (UnknownHostException e) { + System.out.println("Unable to open socket: " + e); + } + } + + public void run(int numbOfPDUS) + { + System.out.println("BRE_KNO_MCC_PC2_MCAST_PduSender started..."); + System.out.println("Generate PDUs and note issues, if any..."); + + List<Pdu> generatedPdusList = createPDU(numbOfPDUS); + + // Send the PDUs we created + System.out.println("Send the " + generatedPdusList.size() + " PDUs we created..."); + + try + { + InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); + MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); + socket.joinGroup(localMulticastAddress); + + for (int idx = 0; idx < generatedPdusList.size(); idx++) + { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + byte[] buffer; + + Pdu aPdu = generatedPdusList.get(idx); + try { + aPdu.marshal(dos); + } catch (Exception ex) { + Logger.getLogger(BRE_KNO_MCC_PC2_MCAST_PduSender.class.getName()).log(Level.SEVERE, null, ex); + } + + buffer = baos.toByteArray(); + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); + socket.send(packet); + try { + Thread.sleep(100L); + } catch (InterruptedException ex) { + } + String currentPduTypeValuePadded = String.format("%2s", aPdu.getPduType().getValue()); + String currentPduTypePadded = String.format("%-34s", aPdu.getPduType()); // - indicates right padding of whitespace + System.out.print ("Sent DIS PDU " + currentPduTypeValuePadded + " " + currentPduTypePadded ); + System.out.println(" of type " + aPdu.getClass().getName()); + } + } + catch (IOException e) + { + System.out.println(e); + } + } + + public static void main(String args[]) + { + if (args.length == 2) + { + BRE_KNO_MCC_PC2_MCAST_PduSender sender = new BRE_KNO_MCC_PC2_MCAST_PduSender(Integer.parseInt(args[0]), args[1]); + sender.run(5); + } + else + { + System.out.println("Usage: BRE_KNO_MCC_PC2_MCAST_PduSender <port> <multicast group>"); + System.out.println("Default: BRE_KNO_MCC_PC2_MCAST_PduSender " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS); + BRE_KNO_MCC_PC2_MCAST_PduSender sender = new BRE_KNO_MCC_PC2_MCAST_PduSender(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); + sender.run(5); + } + System.out.println("BRE_KNO_MCC_PC2_MCAST_PduSender complete."); + } + + private List<Pdu> createPDU(int numbOfPDUs) + { + List<Pdu> list = new ArrayList<>(); + List<Short> entityIDs = new ArrayList<>(); + Random r = new Random(); + + //generate Entity ID (no douplications) + for (int i = 0; i < numbOfPDUs; i++) + { + short temp = (short) r.nextInt(); + while (entityIDs.contains(temp)) + { + temp = (short) r.nextInt(); + } + entityIDs.add(temp); + } + + // + for (int i = 0; i < numbOfPDUs; i++){ + EntityStatePdu myPdu = new EntityStatePdu(); + + //ID + EntityID tempID = new EntityID(); + tempID.setEntityID(entityIDs.get(i)); + myPdu.setEntityID(tempID); + + //Enemy or Friend + myPdu.setForceId(ForceID.FRIENDLY); + + //location + Vector3Double tempLoc = new Vector3Double(); + tempLoc.setX(r.nextInt(1000) + r.nextDouble()); + tempLoc.setY(r.nextInt(1000) + r.nextDouble()); + tempLoc.setZ(r.nextInt(1000) + r.nextDouble()); + + myPdu.setEntityLocation(tempLoc); + + //orientation + EulerAngles tempOri = new EulerAngles(); + tempOri.setPhi(r.nextFloat()); + tempOri.setPsi(r.nextFloat()); + tempOri.setTheta(r.nextFloat()); + + myPdu.setEntityOrientation(tempOri); + + + //velocity + Vector3Double tempVel = new Vector3Double(); + tempVel.setX(r.nextDouble()); + tempVel.setY(r.nextDouble()); + tempVel.setZ(r.nextDouble()); + + myPdu.setEntityLocation(tempVel); + + +// Category? Country? Domain?... +// EntityType tempType = new EntityType(); +// tempType.set +// myPdu.setEntityType(tempType) + + list.add(myPdu); + } + + + return list; + } +} + diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC2_UNICAST_MessageList.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC2_UNICAST_MessageList.java new file mode 100644 index 0000000000000000000000000000000000000000..7893cbe8c5ebc5aadc23d6fef8af45376be5ce88 --- /dev/null +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC2_UNICAST_MessageList.java @@ -0,0 +1,18 @@ +package MV3500Cohort2019JulySeptember.homework2.Brennenstuhl.BRE_KNO_MCC; + +import java.util.HashSet; + + +public class BRE_KNO_MCC_PC2_UNICAST_MessageList { + + HashSet<String> savedUNICASTMessages = new HashSet(); + + public void addMassage(String str){ + savedUNICASTMessages.add(str); + } + + public HashSet<String> getSavedUNICASTMessages(){ + HashSet<String> temp = new HashSet(savedUNICASTMessages); + return temp; + } +} diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC2_UNICAST_PduReceiver.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC2_UNICAST_PduReceiver.java new file mode 100644 index 0000000000000000000000000000000000000000..ddd25ac2dd90351d8179037a53d0520abdf4342a --- /dev/null +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC2_UNICAST_PduReceiver.java @@ -0,0 +1,81 @@ +package MV3500Cohort2019JulySeptember.homework2.Brennenstuhl.BRE_KNO_MCC; + +import MV3500Cohort2019JulySeptember.homework4.Knobeloch.*; +import java.net.*; +import java.io.*; + +import edu.nps.moves.dis7.*; +import edu.nps.moves.dis7.enumerations.*; +import edu.nps.moves.dis7.util.*; + +public class BRE_KNO_MCC_PC2_UNICAST_PduReceiver +{ + public static final int DEFAULT_MULTICAST_PORT = BRE_KNO_MCC_PC2_UNICAST_PduSender.DEFAULT_MULTICAST_PORT; + public static final String DEFAULT_MULTICAST_ADDRESS = BRE_KNO_MCC_PC2_UNICAST_PduSender.DEFAULT_MULTICAST_ADDRESS; + public static final boolean USE_FAST_ESPDU = false; + + public static void main(String args[]) + { + PduFactory factory; + MulticastSocket socket; + InetAddress address; + DatagramPacket packet; + + try { + System.out.println("BRE_KNO_MCC_PC2_UNICAST_PduReceiver started..."); + if (args.length == 2) { + socket = new MulticastSocket(Integer.parseInt(args[0])); + address = InetAddress.getByName(args[1]); + } + else { + System.out.println("Usage: BRE_KNO_MCC_PC2_UNICAST_PduReceiver <port> <multicast group>"); + System.out.println("Default: BRE_KNO_MCC_PC2_UNICAST_PduReceiver " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS); + socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); + address = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); + } + socket.joinGroup(address); + + factory = new PduFactory(); + + while (true) // Loop infinitely, receiving datagrams + { + byte buffer[] = new byte[1500]; // typical MTU size + + packet = new DatagramPacket(buffer, buffer.length); // reset + + socket.receive(packet); + + Pdu pdu = factory.createPdu(packet.getData()); + if (pdu != null) { + DISPDUType currentPduType = pdu.getPduType(); //short currentPduType = pdu.getPduType(); + String currentPduTypeName = pdu.getClass().getName(); + DISProtocolFamily currentProtocolFamilyID = pdu.getProtocolFamily(); //short currentProtocolFamilyID = pdu.getProtocolFamily(); + //String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName(); + + StringBuilder message = new StringBuilder(); + message.append("received DIS PDU "); + if (currentPduType.getValue() < 10) + message.append(" "); + message.append(currentPduType.getValue()); + String currentPduTypePadded = String.format("%-34s", currentPduType); // - indicates right padding of whitespace + message.append(" " ).append(currentPduTypePadded); + String currentPduTypeNamePadded = String.format("%-49s", currentPduTypeName); // - indicates right padding of whitespace + message.append(" of type ").append(currentPduTypeNamePadded); // package.class name + message.append(" (protocolFamily ").append(currentProtocolFamilyID); +// message.append(" ").append(currentPduFamilyName); // class name is also available + message.append(")"); + System.out.println(message.toString()); + } + else + System.out.println("received packet but pdu is null, packet.getData().length=" + packet.getData().length + ", error..."); + } + } + catch (IOException e) { + System.out.println("Problem with BRE_KNO_MCC_PC2_UNICAST_PduReceiver, see exception trace:"); + System.out.println(e); + } + finally { + System.out.println("BRE_KNO_MCC_PC2_UNICAST_PduReceiver complete."); + } + } +} diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC2_UNICAST_PduSender.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC2_UNICAST_PduSender.java new file mode 100755 index 0000000000000000000000000000000000000000..1b57b522bc168a47df788ef924048e8bdeda862b --- /dev/null +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC2_UNICAST_PduSender.java @@ -0,0 +1,178 @@ +package MV3500Cohort2019JulySeptember.homework2.Brennenstuhl.BRE_KNO_MCC; + +import java.io.*; +import java.net.*; +import java.util.*; + +import edu.nps.moves.dis7.*; +import edu.nps.moves.dis7.enumerations.*; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * This is an example that sends many/most types of PDUs. Useful for testing standards + * compliance or getting a full set of PDUs. It also writes the generated PDUs to an XML file. + * Adapted from OpenDIS library example package edu.nps.moves.examples + * + * @author DMcG + * @version $Id:$ + */ +public class BRE_KNO_MCC_PC2_UNICAST_PduSender +{ + /** Default multicast group address we send on. */ + public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3"; + + /** Default multicast port used, matches Wireshark DIS capture default */ + public static final int DEFAULT_MULTICAST_PORT = 2343; + + private int port; + InetAddress multicastAddress; + + public BRE_KNO_MCC_PC2_UNICAST_PduSender(int port, String multicast) { + try + { + this.port = port; + multicastAddress = InetAddress.getByName(multicast); + if (!multicastAddress.isMulticastAddress()) + { + System.out.println("Not a multicast address: " + multicast); + } + } + catch (UnknownHostException e) { + System.out.println("Unable to open socket: " + e); + } + } + + public void run(int numbOfPDUS) + { + System.out.println("BRE_KNO_MCC_PC2_UNICAST_PduSender started..."); + System.out.println("Generate PDUs and note issues, if any..."); + + List<Pdu> generatedPdusList = createPDU(numbOfPDUS); + + // Send the PDUs we created + System.out.println("Send the " + generatedPdusList.size() + " PDUs we created..."); + + try + { + InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); + MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); + socket.joinGroup(localMulticastAddress); + + for (int idx = 0; idx < generatedPdusList.size(); idx++) + { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + byte[] buffer; + + Pdu aPdu = generatedPdusList.get(idx); + try { + aPdu.marshal(dos); + } catch (Exception ex) { + Logger.getLogger(BRE_KNO_MCC_PC2_UNICAST_PduSender.class.getName()).log(Level.SEVERE, null, ex); + } + + buffer = baos.toByteArray(); + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); + socket.send(packet); + try { + Thread.sleep(100L); + } catch (InterruptedException ex) { + } + String currentPduTypeValuePadded = String.format("%2s", aPdu.getPduType().getValue()); + String currentPduTypePadded = String.format("%-34s", aPdu.getPduType()); // - indicates right padding of whitespace + System.out.print ("Sent DIS PDU " + currentPduTypeValuePadded + " " + currentPduTypePadded ); + System.out.println(" of type " + aPdu.getClass().getName()); + } + } + catch (IOException e) + { + System.out.println(e); + } + } + + public static void main(String args[]) + { + if (args.length == 2) + { + BRE_KNO_MCC_PC2_UNICAST_PduSender sender = new BRE_KNO_MCC_PC2_UNICAST_PduSender(Integer.parseInt(args[0]), args[1]); + sender.run(5); + } + else + { + System.out.println("Usage: BRE_KNO_MCC_PC2_UNICAST_PduSender <port> <multicast group>"); + System.out.println("Default: BRE_KNO_MCC_PC2_UNICAST_PduSender " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS); + BRE_KNO_MCC_PC2_UNICAST_PduSender sender = new BRE_KNO_MCC_PC2_UNICAST_PduSender(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); + sender.run(5); + } + System.out.println("BRE_KNO_MCC_PC2_UNICAST_PduSender complete."); + } + + private List<Pdu> createPDU(int numbOfPDUs) + { + List<Pdu> list = new ArrayList<>(); + List<Short> entityIDs = new ArrayList<>(); + Random r = new Random(); + + //generate Entity ID (no douplications) + for (int i = 0; i < numbOfPDUs; i++) + { + short temp = (short) r.nextInt(); + while (entityIDs.contains(temp)) + { + temp = (short) r.nextInt(); + } + entityIDs.add(temp); + } + + // + for (int i = 0; i < numbOfPDUs; i++){ + EntityStatePdu myPdu = new EntityStatePdu(); + + //ID + EntityID tempID = new EntityID(); + tempID.setEntityID(entityIDs.get(i)); + myPdu.setEntityID(tempID); + + //Enemy or Friend + myPdu.setForceId(ForceID.FRIENDLY); + + //location + Vector3Double tempLoc = new Vector3Double(); + tempLoc.setX(r.nextInt(1000) + r.nextDouble()); + tempLoc.setY(r.nextInt(1000) + r.nextDouble()); + tempLoc.setZ(r.nextInt(1000) + r.nextDouble()); + + myPdu.setEntityLocation(tempLoc); + + //orientation + EulerAngles tempOri = new EulerAngles(); + tempOri.setPhi(r.nextFloat()); + tempOri.setPsi(r.nextFloat()); + tempOri.setTheta(r.nextFloat()); + + myPdu.setEntityOrientation(tempOri); + + + //velocity + Vector3Double tempVel = new Vector3Double(); + tempVel.setX(r.nextDouble()); + tempVel.setY(r.nextDouble()); + tempVel.setZ(r.nextDouble()); + + myPdu.setEntityLocation(tempVel); + + +// Category? Country? Domain?... +// EntityType tempType = new EntityType(); +// tempType.set +// myPdu.setEntityType(tempType) + + list.add(myPdu); + } + + + return list; + } +} + diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC3_UNICAST_PduReceiver.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC3_UNICAST_PduReceiver.java new file mode 100644 index 0000000000000000000000000000000000000000..21cdae780eab9582a7e979cda1f0193d1bd8be8e --- /dev/null +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC3_UNICAST_PduReceiver.java @@ -0,0 +1,80 @@ +package MV3500Cohort2019JulySeptember.homework2.Brennenstuhl.BRE_KNO_MCC; + +import java.net.*; +import java.io.*; + +import edu.nps.moves.dis7.*; +import edu.nps.moves.dis7.enumerations.*; +import edu.nps.moves.dis7.util.*; + +public class BRE_KNO_MCC_PC3_UNICAST_PduReceiver +{ + public static final int DEFAULT_MULTICAST_PORT = BRE_KNO_MCC_PC3_UNICAST_PduSender.DEFAULT_MULTICAST_PORT; + public static final String DEFAULT_MULTICAST_ADDRESS = BRE_KNO_MCC_PC3_UNICAST_PduSender.DEFAULT_MULTICAST_ADDRESS; + public static final boolean USE_FAST_ESPDU = false; + + public static void main(String args[]) + { + PduFactory factory; + MulticastSocket socket; + InetAddress address; + DatagramPacket packet; + + try { + System.out.println("BRE_KNO_MCC_PC3_UNICAST_PduReceiver started..."); + if (args.length == 2) { + socket = new MulticastSocket(Integer.parseInt(args[0])); + address = InetAddress.getByName(args[1]); + } + else { + System.out.println("Usage: BRE_KNO_MCC_PC3_UNICAST_PduReceiver <port> <multicast group>"); + System.out.println("Default: BRE_KNO_MCC_PC3_UNICAST_PduReceiver " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS); + socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); + address = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); + } + socket.joinGroup(address); + + factory = new PduFactory(); + + while (true) // Loop infinitely, receiving datagrams + { + byte buffer[] = new byte[1500]; // typical MTU size + + packet = new DatagramPacket(buffer, buffer.length); // reset + + socket.receive(packet); + + Pdu pdu = factory.createPdu(packet.getData()); + if (pdu != null) { + DISPDUType currentPduType = pdu.getPduType(); //short currentPduType = pdu.getPduType(); + String currentPduTypeName = pdu.getClass().getName(); + DISProtocolFamily currentProtocolFamilyID = pdu.getProtocolFamily(); //short currentProtocolFamilyID = pdu.getProtocolFamily(); + //String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName(); + + StringBuilder message = new StringBuilder(); + message.append("received DIS PDU "); + if (currentPduType.getValue() < 10) + message.append(" "); + message.append(currentPduType.getValue()); + String currentPduTypePadded = String.format("%-34s", currentPduType); // - indicates right padding of whitespace + message.append(" " ).append(currentPduTypePadded); + String currentPduTypeNamePadded = String.format("%-49s", currentPduTypeName); // - indicates right padding of whitespace + message.append(" of type ").append(currentPduTypeNamePadded); // package.class name + message.append(" (protocolFamily ").append(currentProtocolFamilyID); +// message.append(" ").append(currentPduFamilyName); // class name is also available + message.append(")"); + System.out.println(message.toString()); + } + else + System.out.println("received packet but pdu is null, packet.getData().length=" + packet.getData().length + ", error..."); + } + } + catch (IOException e) { + System.out.println("Problem with BRE_KNO_MCC_PC3_UNICAST_PduReceiver, see exception trace:"); + System.out.println(e); + } + finally { + System.out.println("BRE_KNO_MCC_PC3_UNICAST_PduReceiver complete."); + } + } +} diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC3_UNICAST_PduSender.java b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC3_UNICAST_PduSender.java new file mode 100755 index 0000000000000000000000000000000000000000..34d19cefd81e7bec5a9d62c68cb80c12f9a0051b --- /dev/null +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework2/Brennenstuhl/BRE_KNO_MCC/BRE_KNO_MCC_PC3_UNICAST_PduSender.java @@ -0,0 +1,178 @@ +package MV3500Cohort2019JulySeptember.homework2.Brennenstuhl.BRE_KNO_MCC; + +import java.io.*; +import java.net.*; +import java.util.*; + +import edu.nps.moves.dis7.*; +import edu.nps.moves.dis7.enumerations.*; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * This is an example that sends many/most types of PDUs. Useful for testing standards + * compliance or getting a full set of PDUs. It also writes the generated PDUs to an XML file. + * Adapted from OpenDIS library example package edu.nps.moves.examples + * + * @author DMcG + * @version $Id:$ + */ +public class BRE_KNO_MCC_PC3_UNICAST_PduSender +{ + /** Default multicast group address we send on. */ + public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3"; + + /** Default multicast port used, matches Wireshark DIS capture default */ + public static final int DEFAULT_MULTICAST_PORT = 2343; + + private int port; + InetAddress multicastAddress; + + public BRE_KNO_MCC_PC3_UNICAST_PduSender(int port, String multicast) { + try + { + this.port = port; + multicastAddress = InetAddress.getByName(multicast); + if (!multicastAddress.isMulticastAddress()) + { + System.out.println("Not a multicast address: " + multicast); + } + } + catch (UnknownHostException e) { + System.out.println("Unable to open socket: " + e); + } + } + + public void run(int numbOfPDUS) + { + System.out.println("BRE_KNO_MCC_PC3_UNICAST_PduSender started..."); + System.out.println("Generate PDUs and note issues, if any..."); + + List<Pdu> generatedPdusList = createPDU(numbOfPDUS); + + // Send the PDUs we created + System.out.println("Send the " + generatedPdusList.size() + " PDUs we created..."); + + try + { + InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); + MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); + socket.joinGroup(localMulticastAddress); + + for (int idx = 0; idx < generatedPdusList.size(); idx++) + { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + byte[] buffer; + + Pdu aPdu = generatedPdusList.get(idx); + try { + aPdu.marshal(dos); + } catch (Exception ex) { + Logger.getLogger(BRE_KNO_MCC_PC3_UNICAST_PduSender.class.getName()).log(Level.SEVERE, null, ex); + } + + buffer = baos.toByteArray(); + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); + socket.send(packet); + try { + Thread.sleep(100L); + } catch (InterruptedException ex) { + } + String currentPduTypeValuePadded = String.format("%2s", aPdu.getPduType().getValue()); + String currentPduTypePadded = String.format("%-34s", aPdu.getPduType()); // - indicates right padding of whitespace + System.out.print ("Sent DIS PDU " + currentPduTypeValuePadded + " " + currentPduTypePadded ); + System.out.println(" of type " + aPdu.getClass().getName()); + } + } + catch (IOException e) + { + System.out.println(e); + } + } + + public static void main(String args[]) + { + if (args.length == 2) + { + BRE_KNO_MCC_PC3_UNICAST_PduSender sender = new BRE_KNO_MCC_PC3_UNICAST_PduSender(Integer.parseInt(args[0]), args[1]); + sender.run(5); + } + else + { + System.out.println("Usage: BRE_KNO_MCC_PC3_UNICAST_PduSender <port> <multicast group>"); + System.out.println("Default: BRE_KNO_MCC_PC3_UNICAST_PduSender " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS); + BRE_KNO_MCC_PC3_UNICAST_PduSender sender = new BRE_KNO_MCC_PC3_UNICAST_PduSender(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); + sender.run(5); + } + System.out.println("BRE_KNO_MCC_PC3_UNICAST_PduSender complete."); + } + + private List<Pdu> createPDU(int numbOfPDUs) + { + List<Pdu> list = new ArrayList<>(); + List<Short> entityIDs = new ArrayList<>(); + Random r = new Random(); + + //generate Entity ID (no douplications) + for (int i = 0; i < numbOfPDUs; i++) + { + short temp = (short) r.nextInt(); + while (entityIDs.contains(temp)) + { + temp = (short) r.nextInt(); + } + entityIDs.add(temp); + } + + // + for (int i = 0; i < numbOfPDUs; i++){ + EntityStatePdu myPdu = new EntityStatePdu(); + + //ID + EntityID tempID = new EntityID(); + tempID.setEntityID(entityIDs.get(i)); + myPdu.setEntityID(tempID); + + //Enemy or Friend + myPdu.setForceId(ForceID.FRIENDLY); + + //location + Vector3Double tempLoc = new Vector3Double(); + tempLoc.setX(r.nextInt(1000) + r.nextDouble()); + tempLoc.setY(r.nextInt(1000) + r.nextDouble()); + tempLoc.setZ(r.nextInt(1000) + r.nextDouble()); + + myPdu.setEntityLocation(tempLoc); + + //orientation + EulerAngles tempOri = new EulerAngles(); + tempOri.setPhi(r.nextFloat()); + tempOri.setPsi(r.nextFloat()); + tempOri.setTheta(r.nextFloat()); + + myPdu.setEntityOrientation(tempOri); + + + //velocity + Vector3Double tempVel = new Vector3Double(); + tempVel.setX(r.nextDouble()); + tempVel.setY(r.nextDouble()); + tempVel.setZ(r.nextDouble()); + + myPdu.setEntityLocation(tempVel); + + +// Category? Country? Domain?... +// EntityType tempType = new EntityType(); +// tempType.set +// myPdu.setEntityType(tempType) + + list.add(myPdu); + } + + + return list; + } +} + diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework3/MV3500 Group Excercise.pdf b/assignments/src/MV3500Cohort2019JulySeptember/homework3/MV3500 Group Excercise.pdf new file mode 100644 index 0000000000000000000000000000000000000000..bed3c7ad844ccf2bf375293a938ba6d3eebed77a Binary files /dev/null and b/assignments/src/MV3500Cohort2019JulySeptember/homework3/MV3500 Group Excercise.pdf differ diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Brennenstuhl/BrennenstuhlPduReceiver.java b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Brennenstuhl/BrennenstuhlPduReceiver.java new file mode 100644 index 0000000000000000000000000000000000000000..971d8620a5bcb79578b6c321f16b3f61305ca459 --- /dev/null +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Brennenstuhl/BrennenstuhlPduReceiver.java @@ -0,0 +1,80 @@ +package MV3500Cohort2019JulySeptember.homework4.Brennenstuhl; + +import java.net.*; +import java.io.*; + +import edu.nps.moves.dis7.*; +import edu.nps.moves.dis7.enumerations.*; +import edu.nps.moves.dis7.util.*; + +public class BrennenstuhlPduReceiver +{ + public static final int DEFAULT_MULTICAST_PORT = BrennenstuhlPduSender.DEFAULT_MULTICAST_PORT; + public static final String DEFAULT_MULTICAST_ADDRESS = BrennenstuhlPduSender.DEFAULT_MULTICAST_ADDRESS; + public static final boolean USE_FAST_ESPDU = false; + + public static void main(String args[]) + { + PduFactory factory; + MulticastSocket socket; + InetAddress address; + DatagramPacket packet; + + try { + System.out.println("DisExamplesOpenDis7.AllPduReceiver started..."); + if (args.length == 2) { + socket = new MulticastSocket(Integer.parseInt(args[0])); + address = InetAddress.getByName(args[1]); + } + else { + System.out.println("Usage: AllPduReceiver <port> <multicast group>"); + System.out.println("Default: AllPduReceiver " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS); + socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); + address = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); + } + socket.joinGroup(address); + + factory = new PduFactory(); + + while (true) // Loop infinitely, receiving datagrams + { + byte buffer[] = new byte[1500]; // typical MTU size + + packet = new DatagramPacket(buffer, buffer.length); // reset + + socket.receive(packet); + + Pdu pdu = factory.createPdu(packet.getData()); + if (pdu != null) { + DISPDUType currentPduType = pdu.getPduType(); //short currentPduType = pdu.getPduType(); + String currentPduTypeName = pdu.getClass().getName(); + DISProtocolFamily currentProtocolFamilyID = pdu.getProtocolFamily(); //short currentProtocolFamilyID = pdu.getProtocolFamily(); + String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName(); + + StringBuilder message = new StringBuilder(); + message.append("received DIS PDU "); + if (currentPduType.getValue() < 10) + message.append(" "); + message.append(currentPduType.getValue()); + String currentPduTypePadded = String.format("%-34s", currentPduType); // - indicates right padding of whitespace + message.append(" " ).append(currentPduTypePadded); + String currentPduTypeNamePadded = String.format("%-49s", currentPduTypeName); // - indicates right padding of whitespace + message.append(" of type ").append(currentPduTypeNamePadded); // package.class name + message.append(" (protocolFamily ").append(currentProtocolFamilyID); +// message.append(" ").append(currentPduFamilyName); // class name is also available + message.append(")"); + System.out.println(message.toString()); + } + else + System.out.println("received packet but pdu is null, packet.getData().length=" + packet.getData().length + ", error..."); + } + } + catch (IOException e) { + System.out.println("Problem with DisExamplesOpenDis7.AllPduReceiver, see exception trace:"); + System.out.println(e); + } + finally { + System.out.println("DisExamplesOpenDis7.AllPduReceiver complete."); + } + } +} diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Brennenstuhl/BrennenstuhlPduSender.java b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Brennenstuhl/BrennenstuhlPduSender.java new file mode 100644 index 0000000000000000000000000000000000000000..0240bd2b9de0a52e317764af02fe240d01f7966e --- /dev/null +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Brennenstuhl/BrennenstuhlPduSender.java @@ -0,0 +1,449 @@ +package MV3500Cohort2019JulySeptember.homework4.Brennenstuhl; + +import java.io.*; +import java.net.*; +import java.util.*; + +import edu.nps.moves.dis7.*; +import edu.nps.moves.dis7.enumerations.*; + +/** + * This is an example that sends many/most types of PDUs. Useful for testing standards + * compliance or getting a full set of PDUs. It also writes the generated PDUs to an XML file. + * Adapted from OpenDIS library example package edu.nps.moves.examples + * + * @author DMcG + * @version $Id:$ + */ +public class BrennenstuhlPduSender +{ + /** Default multicast group address we send on. */ + public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3"; + + /** Default multicast port used, matches Wireshark DIS capture default */ + public static final int DEFAULT_MULTICAST_PORT = 3000; + + private int port; + InetAddress multicastAddress; + + public BrennenstuhlPduSender(int port, String multicast) { + try + { + this.port = port; + multicastAddress = InetAddress.getByName(multicast); + if (!multicastAddress.isMulticastAddress()) + { + System.out.println("Not a multicast address: " + multicast); + } + } + catch (UnknownHostException e) { + System.out.println("Unable to open socket: " + e); + } + } + + public void run() + { + System.out.println("DisExamplesOpenDis7.AllPduSender started..."); + try + { + System.out.println("Generate PDUs and note issues, if any..."); + List<Pdu> generatedPdusList = new ArrayList<>(); + + // Loop through all the enumerated PDU types, create a PDU for each type, + // add that PDU to generatedPdusList, and send each one + for (DISPDUType pdu : DISPDUType.values()) + { +// System.out.println("PDU " + pdu.getValue() + " " + pdu.name() + " " + pdu.getDescription()); // diagnostic + + Pdu aPdu = null; // edu.​nps.​moves7.​dis.PDU superclass for all PDUs, in preparation for custom assignment + + try { + switch (pdu) // using enumeration values from edu.​nps.​moves.​dis7.​enumerations.​DISPDUType + { + case OTHER: // 0 + System.out.println ("*** Note: DISPDUType." + pdu.name() + " not supported"); // TODO why was this received? + // nothing to send + break; + + case ENTITY_STATE: // 1 + aPdu = new EntityStatePdu(); + + EntityStatePdu espdu = (EntityStatePdu) aPdu; + EntityMarking entityMarking = new EntityMarking (); + entityMarking.setCharacters("AllPduSender".getBytes()); //entityMarking.setCharacters(Byte.valueOf("0")); // 11 characters max? + + espdu.setMarking(entityMarking); + Vector3Double espduLocation = new Vector3Double(); + espduLocation.setX(1.0); + espduLocation.setY(2.0); + espduLocation.setZ(3.0); + espdu.setEntityLocation(espduLocation); + // it is important to identify questions as you think of them + // TODO how to set azimuth, i.e. course direction over ground? + break; + + case FIRE: // 2 + aPdu = new FirePdu(); + break; + + case DETONATION: // 3 + aPdu = new DetonationPdu(); + break; + + case COLLISION: // 4 + aPdu = new CollisionPdu(); + break; + + case SERVICE_REQUEST: // 5 + aPdu = new ServiceRequestPdu(); + break; + + case RESUPPLY_OFFER: // 6 + aPdu = new ResupplyOfferPdu(); + break; + + case RESUPPLY_RECEIVED: // 7 + aPdu = new ResupplyReceivedPdu(); + break; + + case RESUPPLY_CANCEL: //8 + aPdu = new ResupplyCancelPdu(); + break; + + case REPAIR_COMPLETE: // 9 + aPdu = new RepairCompletePdu(); + break; + + case REPAIR_RESPONSE: // 10 + aPdu = new RepairResponsePdu(); + break; + + case CREATE_ENTITY: // 11 + aPdu = new CreateEntityPdu(); + break; + + case REMOVE_ENTITY: // 12 + aPdu = new RemoveEntityPdu(); + break; + + case START_RESUME: // 13 + aPdu = new StartResumePdu(); + break; + + case STOP_FREEZE: // 14 + aPdu = new StopFreezePdu(); + break; + + case ACKNOWLEDGE: // 15 + aPdu = new AcknowledgePdu(); + break; + + case ACTION_REQUEST: // 16 + aPdu = new ActionRequestPdu(); + break; + + case ACTION_RESPONSE: // 17 + aPdu = new ActionResponsePdu(); + break; + + case DATA_QUERY: // 18 + aPdu = new DataQueryPdu(); + break; + + case SET_DATA: // 19 + aPdu = new SetDataPdu(); + break; + + case DATA: // 20 + aPdu = new DataPdu(); + break; + + case EVENT_REPORT: // 21 + aPdu = new EventReportPdu(); + break; + + case ELECTROMAGNETIC_EMISSION: // 23 + aPdu = new ElectromagneticEmissionPdu(); + break; + + case DESIGNATOR: // 24 + aPdu = new DesignatorPdu(); + break; + + case TRANSMITTER: // 25 + aPdu = new TransmitterPdu(); + break; + + case SIGNAL: // 26 + aPdu = new SignalPdu(); + break; + + case RECEIVER: // 27 + aPdu = new ReceiverPdu(); + break; + + case IDENTIFICATION_FRIEND_OR_FOE: // 28 + aPdu = new IdentificationFriendOrFoePdu(); + break; + + case UNDERWATER_ACOUSTIC: // 29 + aPdu = new UnderwaterAcousticPdu(); + break; + + case SUPPLEMENTAL_EMISSION_ENTITY_STATE: // 30 + aPdu = new SupplementalEmissionEntityStatePdu(); + break; + + case INTERCOM_SIGNAL: // 31 + aPdu = new IntercomSignalPdu(); + break; + + case INTERCOM_CONTROL: // 32 + aPdu = new IntercomControlPdu(); + break; + + case AGGREGATE_STATE: // 33 + aPdu = new AggregateStatePdu(); + break; + + case ISGROUPOF: // 34 + aPdu = new IsGroupOfPdu(); + break; + + case TRANSFER_OWNERSHIP: // 35 + aPdu = new TransferOwnershipPdu(); + break; + + case ISPARTOF: // 36 + aPdu = new IsPartOfPdu(); + break; + + case MINEFIELD_STATE: // 37 + aPdu = new MinefieldStatePdu(); + break; + + case MINEFIELD_QUERY: // 38 + aPdu = new MinefieldQueryPdu(); + break; + + case MINEFIELD_DATA: // 39 + aPdu = new MinefieldDataPdu(); + break; + + case MINEFIELD_RESPONSE_NACK: // 40 + aPdu = new MinefieldResponseNACKPdu(); + break; + + case ENVIRONMENTAL_PROCESS: // 41 + aPdu = new EnvironmentalProcessPdu(); + break; + + case GRIDDED_DATA: // 42 + aPdu = new GriddedDataPdu(); + break; + + case POINT_OBJECT_STATE: // 43 + aPdu = new PointObjectStatePdu(); + break; + + case LINEAR_OBJECT_STATE: // 44 + aPdu = new LinearObjectStatePdu(); + break; + + case AREAL_OBJECT_STATE: // 45 + aPdu = new ArealObjectStatePdu(); + break; + + case TIME_SPACE_POSITION_INFORMATION: // 46 + aPdu = new TimeSpacePositionInformationPdu(); + break; + + case APPEARANCE: // 47 + aPdu = new AppearancePdu(); + break; + + case ARTICULATED_PARTS: // 48 + aPdu = new ArticulatedPartsPdu(); + break; + + case LIVE_ENTITY_FIRE: // 49 + aPdu = new LiveEntityFirePdu(); + break; + + case LIVE_ENTITY_DETONATION: // 50 + aPdu = new LiveEntityDetonationPdu(); + break; + + case CREATE_ENTITY_RELIABLE: // 51 + aPdu = new CreateEntityReliablePdu(); + break; + + case REMOVE_ENTITY_RELIABLE: // 52 + aPdu = new RemoveEntityReliablePdu(); + break; + + case START_RESUME_RELIABLE: // 53 + aPdu = new StartResumeReliablePdu(); + break; + + case STOP_FREEZE_RELIABLE: // 54 + aPdu = new StopFreezeReliablePdu(); + break; + + case ACKNOWLEDGE_RELIABLE: // 55 + aPdu = new AcknowledgeReliablePdu(); + break; + + case ACTION_REQUEST_RELIABLE: // 56 + aPdu = new ActionRequestReliablePdu(); + break; + + case ACTION_RESPONSE_RELIABLE: // 57 + aPdu = new ActionResponseReliablePdu(); + break; + + case DATA_QUERY_RELIABLE: // 58 + aPdu = new DataQueryReliablePdu(); + break; + + case SET_DATA_RELIABLE: // 59 + aPdu = new SetDataReliablePdu(); + break; + + case DATA_RELIABLE: // 60 + aPdu = new DataReliablePdu(); + break; + + case EVENT_REPORT_RELIABLE: // 61 + aPdu = new EventReportReliablePdu(); + break; + + case COMMENT_RELIABLE: // 62 + aPdu = new CommentReliablePdu(); + break; + + case RECORD_RELIABLE: // 63 + aPdu = new RecordReliablePdu(); + break; + + case SET_RECORD_RELIABLE: // 64 + aPdu = new SetRecordReliablePdu(); + break; + + case RECORD_QUERY_RELIABLE: // 65 + aPdu = new RecordQueryReliablePdu(); + break; + + case COLLISION_ELASTIC: // 66 + aPdu = new CollisionElasticPdu(); + break; + + case ENTITY_STATE_UPDATE: // 67 + aPdu = new EntityStateUpdatePdu(); + break; + + case DIRECTED_ENERGY_FIRE: // 68 + aPdu = new DirectedEnergyFirePdu(); + break; + + case ENTITY_DAMAGE_STATUS: // 69 + aPdu = new EntityDamageStatusPdu(); + break; + + case INFORMATION_OPERATIONS_ACTION: // 70 + aPdu = new InformationOperationsActionPdu(); + break; + + case INFORMATION_OPERATIONS_REPORT: // 71 + aPdu = new InformationOperationsReportPdu(); + break; + + case ATTRIBUTE: // 72 + aPdu = new AttributePdu(); + break; + + case COMMENT: + aPdu = new CommentPdu(); + CommentPdu newCommentPdu = (CommentPdu)aPdu; + VariableDatum newVariableDatum = new VariableDatum(); + // etc. see Garrett and Pete's code + break; + + default: + System.out.println("*** Warning: PDU " + pdu.getValue() + " " + pdu + " not supported, created or sent "); + + // code generation block for this class follows: +// System.out.println(" case " + pdu + ": // " + pdu.getValue()); +// System.out.println(" aPdu = new " + pdu.getDescription().replace(" ","").replace("-","").replace("/","") + +// "Pdu();"); +// System.out.println(" break;"); +// System.out.println(); + } + if (aPdu != null) + { + generatedPdusList.add(aPdu); + } + } + catch (Exception e) + { + System.out.print("Exception thrown for PDU " + pdu.getValue() + " " + pdu); + System.out.print(Arrays.toString(e.getStackTrace())); + // continue looping + } + } + // Send the PDUs we created + System.out.println("Send the " + generatedPdusList.size() + " PDUs we created..."); + + InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); + MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); + socket.joinGroup(localMulticastAddress); + + for (int idx = 0; idx < generatedPdusList.size(); idx++) + { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + byte[] buffer; + + Pdu aPdu = generatedPdusList.get(idx); + aPdu.marshal(dos); + + buffer = baos.toByteArray(); + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); + socket.send(packet); + try { + Thread.sleep(100L); + } catch (InterruptedException ex) { + } + String currentPduTypeValuePadded = String.format("%2s", aPdu.getPduType().getValue()); + String currentPduTypePadded = String.format("%-34s", aPdu.getPduType()); // - indicates right padding of whitespace + System.out.print ("Sent DIS PDU " + currentPduTypeValuePadded + " " + currentPduTypePadded ); + System.out.println(" of type " + aPdu.getClass().getName()); + } + // write the PDUs out to an XML file. + //PduContainer container = new PduContainer(); + //container.setPdus(generatedPdus); + //container.marshallToXml("examplePdus.xml"); + } + catch (IOException e) + { + System.out.println(e); + } + } + + public static void main(String args[]) + { + if (args.length == 2) + { + BrennenstuhlPduSender sender = new BrennenstuhlPduSender(Integer.parseInt(args[0]), args[1]); + sender.run(); + } + else + { + System.out.println("Usage: AllPduSender <port> <multicast group>"); + System.out.println("Default: AllPduSender " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS); + BrennenstuhlPduSender sender = new BrennenstuhlPduSender(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); + sender.run(); + } + System.out.println("DisExamplesOpenDis7.AllPduSender complete."); + } +} diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Knobeloch/Knobeloch_PduReceiver.java b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Knobeloch/Knobeloch_PduReceiver.java index d23bef63de7d55beaca0e06896cfbb937025ba40..8dafea51049ef7360d17fecdd8d2dbd49a6f9d48 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Knobeloch/Knobeloch_PduReceiver.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Knobeloch/Knobeloch_PduReceiver.java @@ -1,5 +1,6 @@ package MV3500Cohort2019JulySeptember.homework4.Knobeloch; +import MV3500Cohort2019JulySeptember.homework2.Brennenstuhl.BRE_KNO_MCC.*; import java.net.*; import java.io.*; diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Knobeloch/Knobeloch_PduSender.java b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Knobeloch/Knobeloch_PduSender.java index 7294c95f1cce104089c272deb54e0cf0efc9d468..ad0139b5dec0f91c10c5a012aa629e03794a9ff1 100755 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Knobeloch/Knobeloch_PduSender.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Knobeloch/Knobeloch_PduSender.java @@ -6,6 +6,8 @@ import java.util.*; import edu.nps.moves.dis7.*; import edu.nps.moves.dis7.enumerations.*; +import java.util.logging.Level; +import java.util.logging.Logger; /** * This is an example that sends many/most types of PDUs. Useful for testing standards @@ -21,7 +23,7 @@ public class Knobeloch_PduSender public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3"; /** Default multicast port used, matches Wireshark DIS capture default */ - public static final int DEFAULT_MULTICAST_PORT = 3000; + public static final int DEFAULT_MULTICAST_PORT = 1718; private int port; InetAddress multicastAddress; @@ -64,7 +66,11 @@ public class Knobeloch_PduSender byte[] buffer; Pdu aPdu = generatedPdusList.get(idx); - aPdu.marshal(dos); + try { + aPdu.marshal(dos); + } catch (Exception ex) { + Logger.getLogger(Knobeloch_PduSender.class.getName()).log(Level.SEVERE, null, ex); + } buffer = baos.toByteArray(); DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); diff --git a/examples/pduLog/Pdusave1.dislog b/examples/pduLog/Pdusave1.dislog new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391