diff --git a/CourseExamples/nbproject/genfiles.properties b/CourseExamples/nbproject/genfiles.properties index 6bfdbedf4d07e3d4c841ae90be62147217121909..47cc2bb96ce7b73637ab2a3cd11fc847dc7e4026 100644 --- a/CourseExamples/nbproject/genfiles.properties +++ b/CourseExamples/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=ba18aca8 +build.xml.data.CRC32=3397fc52 build.xml.script.CRC32=f4fc0484 build.xml.stylesheet.CRC32=8064a381@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=ba18aca8 +nbproject/build-impl.xml.data.CRC32=3397fc52 nbproject/build-impl.xml.script.CRC32=6a5b91f6 nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 diff --git a/CourseExamples/src/DisExamples/PduSender.java b/CourseExamples/src/DisExamples/PduSender.java index 9462fec0e2f784052727a3be19abe68cf2fdd9ef..9d92a3b353df8bf6bfd93dc287d8fd601e2902d9 100644 --- a/CourseExamples/src/DisExamples/PduSender.java +++ b/CourseExamples/src/DisExamples/PduSender.java @@ -73,6 +73,9 @@ public class PduSender case COMMENT: aPdu = new CommentPdu(); + CommentPdu newCommentPdu = (CommentPdu)aPdu; + VariableDatum newVariableDatum = new VariableDatum(); + // etc. see Garrett and Pete's code break; case FIRE: diff --git a/CourseExamples/src/TcpExamples/TcpExample3Server.java b/CourseExamples/src/TcpExamples/TcpExample3Server.java index 1ed761bf53c8fbfe9c8b88158921e4f0b4f795cc..eeccda6f4bb813ebb8c1296b6424a9837832bd9d 100644 --- a/CourseExamples/src/TcpExamples/TcpExample3Server.java +++ b/CourseExamples/src/TcpExamples/TcpExample3Server.java @@ -31,7 +31,7 @@ public class TcpExample3Server { // Notice that it is outside the loop; ServerSocket // needs to be made only once. - System.out.println("TcpExample3Server has started..."); // it helps debugging to put this on console first + System.out.println("TcpExample3Server has really started..."); // it helps debugging to put this on console first ServerSocket serverSocket = new ServerSocket(2317); // Server is up and waiting (i.e. "blocked" or paused) @@ -62,7 +62,7 @@ public class TcpExample3Server { // // Why is the first IP/port the same, while the second set has // different ports? - System.out.println("Socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " + System.out.println("TcpExample3Server socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " + remoteAddress.toString() + ", " + remotePort + " ))"); // Notice the use of flush() and close(). Without diff --git a/CourseExamples/src/TcpExamples/TcpExample3TerminalLog.txt b/CourseExamples/src/TcpExamples/TcpExample3TerminalLog.txt index 1b670fe80f2ab8948257202532c5f7cc5d1b4a0c..af6c6b8bec360baec1855ac17bf99dc7aab4da7d 100644 --- a/CourseExamples/src/TcpExamples/TcpExample3TerminalLog.txt +++ b/CourseExamples/src/TcpExamples/TcpExample3TerminalLog.txt @@ -7,9 +7,9 @@ Program responses: =================================================== run: TcpExample3Server has started... -Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 49239 )) -Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 49240 )) -Socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 49241 )) +TcpExample3Server socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 49239 )) +TcpExample3Server socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 49240 )) +TcpExample3Server socket pair: (( /0:0:0:0:0:0:0:1, 2317 ), ( /0:0:0:0:0:0:0:1, 49241 )) [etc.] [kill process to exit] @@ -30,3 +30,7 @@ The message the server sent was This was written by the server TcpExample3Client creating socket... ================================================== [etc.] + +You must kill this process to get it to stop, each is in an infinite loop. + +If you kill the server, that will kill the client automatically when the connection drops. diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/CainThomersonFinal/CTnewRecSendB.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/CainThomersonFinal/CTnewRecSendB.java deleted file mode 100644 index 05cd493af782f2bbafa5567d7aae13a42bf5a199..0000000000000000000000000000000000000000 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/CainThomersonFinal/CTnewRecSendB.java +++ /dev/null @@ -1,97 +0,0 @@ - -package MV3500Cohort2018JulySeptember.FinalProject.CainThomersonFinal; - -import java.net.*; -import java.util.*; -import edu.nps.moves.disutil.*; -import edu.nps.moves.dis.*; -import java.io.IOException; - -/** - * - * @author danielcain - */ -public class CTnewRecSendB { - - /** Max size of a PDU in binary format that we can receive. This is actually - * somewhat outdated--PDUs can be larger--but this is a reasonable starting point. - */ - public static final int MAX_PDU_SIZE = 8192; - - /** Default multicast group address we send on. */ - public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.9"; - - /** Default multicast port used, matches Wireshark DIS capture default */ - public static final int DEFAULT_MULTICAST_PORT = 2800; - - public static void main(String args[]) - { - System.out.println("DisExamples.EspduReceiver started..."); - - MulticastSocket socket; - DatagramPacket packet; - InetAddress address; - PduFactory pduFactory = new PduFactory(); - - try { - // Specify the socket to receive data - socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); - socket.setBroadcast(true); - - while (true) // Loop infinitely, receiving datagrams - { - byte buffer[] = new byte[MAX_PDU_SIZE]; - packet = new DatagramPacket(buffer, buffer.length); - - socket.receive(packet); - - List<Pdu> pduBundle = pduFactory.getPdusFromBundle(packet.getData()); - System.out.println("\nBundle size is " + pduBundle.size()); - - Iterator iterator = pduBundle.iterator(); - - while(iterator.hasNext()) - { - Pdu aPdu = (Pdu)iterator.next(); - - System.out.print("Recieved PDU of type: " + aPdu.getClass().getName()); - if(aPdu instanceof EntityStatePdu) - { - EntityID eid = ((EntityStatePdu)aPdu).getEntityID(); - Vector3Double position = ((EntityStatePdu)aPdu).getEntityLocation(); - System.out.print("\nEID: [" + eid.getSite() + ", " + eid.getApplication() + ", " + eid.getEntity() + "] "); - System.out.printf("\nResupply source location for x,y,z coordinates: %.2f " , position.getX() ); - System.out.printf(" %.2f " , position.getY() ); - System.out.printf(" %.2f " , position.getZ() ); - //System.out.print(" FARP WTF recieving location: [" + newPos.getX() + ", " + newPos.getY() + ", " + newPos.getZ() + "]"); - } - - if(aPdu instanceof ServiceRequestPdu) - { - EntityID eid = ((ServiceRequestPdu)aPdu).getRequestingEntityID(); - short serviceType = ((ServiceRequestPdu)aPdu).getServiceTypeRequested(); - String serviceReqestTypeString = "null"; - if (serviceType == 0) - serviceReqestTypeString = "Other"; - if (serviceType == 1) - serviceReqestTypeString = "Resupply"; - if (serviceType == 2) - serviceReqestTypeString = "Repair"; - - List<SupplyQuantity> supplies = ((ServiceRequestPdu)aPdu).getSupplies(); - - System.out.println(" EID:[" + eid.getSite() + ", " + eid.getApplication() + ", " + eid.getEntity() + "] "); - System.out.println(" Service Type Requested: [" + serviceType + ", " + serviceReqestTypeString + "]"); - System.out.println(" Supply Quantity: [" + supplies.toString() + "]\n\n"); - } - } // end trop through PDU bundle - } // end while - } // End try - catch (IOException e) - { - System.out.println("Problem with DisExamples.EspduReceiver, see exception trace:"); - System.out.println(e); - } - } // end main -} // end class - diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/CainThomersonFinal/CTnewSendRecA.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/CainThomersonFinal/CTnewSendRecA.java deleted file mode 100644 index 563e260c9de04ac41d0744e05319be4525272754..0000000000000000000000000000000000000000 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/CainThomersonFinal/CTnewSendRecA.java +++ /dev/null @@ -1,272 +0,0 @@ - -package MV3500Cohort2018JulySeptember.FinalProject.CainThomersonFinal; - -import java.io.*; -import java.net.*; -import java.util.*; - -import edu.nps.moves.dis.*; -import edu.nps.moves.disutil.CoordinateConversions; -import edu.nps.moves.disutil.DisTime; - -/** - * - * @author danielcain - */ -public class CTnewSendRecA { - - public static final int NUMBER_TO_SEND = 100; - - public enum NetworkMode { - UNICAST, MULTICAST, BROADCAST - }; - - /** - * Default multicast group address we send on. - */ - public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.9"; - - /** - * Default multicast port used, matches Wireshark DIS capture default - */ - public static final int DEFAULT_MULTICAST_PORT = 2800; - - /** - * @param args - */ - public static void main(String args[]) - { - System.out.println("DisExamples.EspduSender started... send " + NUMBER_TO_SEND + " ESPDUs, initial index=0"); - - //Establish the Requesting Unit EnityState PDU - EntityStatePdu requestingUnitEsPdu = new EntityStatePdu(); - - //Initialize the MulticastSocket to null - MulticastSocket socket = null; - - //Initialize the DIS time (this will be used later in the code - DisTime disTime = DisTime.getInstance(); // TODO explain - //int alternator = -1; - - // Lat and Long Coordinates that will be used for the location of the Requesting Unit - double lat = 36.59; - double lon = -121.87; - - // Initialize the Port, Mode, and Destination IP - int port = DEFAULT_MULTICAST_PORT; - NetworkMode mode = NetworkMode.BROADCAST; - InetAddress destinationIp = null; - - //Use a try/catch to ensure the you can connect to the Destination IP - try { - destinationIp = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); - } catch (UnknownHostException e) { - System.out.println(e + " Cannot create multicast address"); - System.exit(0); - } - - // All system properties, passed in on the command line via -Dattribute=value - Properties systemProperties = System.getProperties(); - // IP address we send to - String destinationIpString = systemProperties.getProperty("destinationIp"); - // Port we send to, and local port we open the socket on - String portString = systemProperties.getProperty("port"); - // Network mode: unicast, multicast, broadcast - String networkModeString = systemProperties.getProperty("networkMode"); // unicast or multicast or broadcast - - // Set up a socket to send information - try { - // Port we send to - if (portString != null) - { - port = Integer.parseInt(portString); - } - - socket = new MulticastSocket(port); - - // Where we send packets to, the destination IP address - if (destinationIpString != null) - { - destinationIp = InetAddress.getByName(destinationIpString); - } - - // Type of transport: unicast, broadcast, or multicast - if (networkModeString != null) { - if (networkModeString.equalsIgnoreCase("unicast")) - { - mode = NetworkMode.UNICAST; - } - else if (networkModeString.equalsIgnoreCase("broadcast")) { - mode = NetworkMode.BROADCAST; - } - else if (networkModeString.equalsIgnoreCase("multicast")) { - mode = NetworkMode.MULTICAST; - if (!destinationIp.isMulticastAddress()) - { - throw new RuntimeException("Sending to multicast address, but destination address " + destinationIp.toString() + "is not multicast"); - } - socket.joinGroup(destinationIp); - } - } - } - catch (IOException | RuntimeException e) - { - System.out.println("Unable to initialize networking. Exiting."); - System.out.println(e); - System.exit(-1); - } - - // Initialize values in the Entity State PDU object. - //The exercise ID is a way to differentiate between different virtual worlds on one network. - requestingUnitEsPdu.setExerciseID((short) 1); - - // The EID is the unique identifier for objects in the world. - EntityID entityID = requestingUnitEsPdu.getEntityID(); - entityID.setSite(1); // 0 is apparently not a valid site number, per the spec - entityID.setApplication(1); - entityID.setEntity(2); - - // Set the entity type. (Check SISO for a list of enumerations) - EntityType entityType = requestingUnitEsPdu.getEntityType(); - entityType.setEntityKind((short) 1); // Platform (vs lifeform, munition, sensor, etc.) - entityType.setCountry(222); // USA - entityType.setDomain((short) 1); // Land (vs air, surface, subsurface, space) - entityType.setCategory((short) 1); // Tank - entityType.setSubcategory((short) 1); // M1 Abrams - entityType.setSpec((short) 3); // M1A2 Abrams - - Set<InetAddress> broadcastAddresses; - // Loop through sending N ESPDUs - try - { - System.out.println("Sending " + NUMBER_TO_SEND + " ESPDU packets to " + destinationIp.toString()); - - for (int index = 0; index < NUMBER_TO_SEND; index++) { - //DIS Time must be used for this because DIS requires it. - int timestamp = disTime.getDisAbsoluteTimestamp(); - requestingUnitEsPdu.setTimestamp(timestamp); - - //Set up longitude to be changing throughout the running of the program - double direction = Math.pow((double) (-1.0), (double) (index)); - lon = lon + (direction * 0.00006); - - //Convert the lat and long coordinates to cartisian coordinates required by DIS - double disCoordinates[] = CoordinateConversions.getXYZfromLatLonDegrees(lat, lon, 1.0); - Vector3Double location = requestingUnitEsPdu.getEntityLocation(); - location.setX(disCoordinates[0]); - location.setY(disCoordinates[1]); - location.setZ(disCoordinates[2]); - - // You can set other ESPDU values here, such as the velocity, acceleration, - // and so on. - // Marshal out the espdu object to a byte array, then send a datagram - // packet with that data in it. - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - requestingUnitEsPdu.marshal(dos); - - //SERVICE_REQUEST - ServiceRequestPdu serviceRequest = new ServiceRequestPdu(); - serviceRequest.setRequestingEntityID(entityID); - serviceRequest.setServiceTypeRequested((short) 1); //Resupply - List<SupplyQuantity> pSupplies = new ArrayList<SupplyQuantity>(); - pSupplies.add(new SupplyQuantity()); - serviceRequest.setSupplies(pSupplies); - - //RESUPPLY_OFFER - ResupplyOfferPdu resupplyOffer = new ResupplyOfferPdu(); - - byte[] serviceRequestArray = serviceRequest.marshal(); - //FirePdu fire = new FirePdu(); - //byte[] fireArray = fire.marshal(); - - // The byte array here is the packet in DIS format. We put that into a - // datagram and send it. - byte[] data = baos.toByteArray(); - - broadcastAddresses = getBroadcastAddresses(); - Iterator iterator = broadcastAddresses.iterator(); - while (iterator.hasNext()) - { - InetAddress broadcast = (InetAddress) iterator.next(); - System.out.println("\nSending broadcast datagram packet to " + broadcast); - DatagramPacket packet = new DatagramPacket(data, data.length, broadcast, port); - socket.send(packet); - // TODO experiment with these! 8) - //packet = new DatagramPacket(fireArray, fireArray.length, broadcast, port); // alternate - packet = new DatagramPacket(serviceRequestArray, serviceRequestArray.length, broadcast, port); // alternate - socket.send(packet); - } - - // Send every 1 sec. Otherwise all this will be all over in a fraction of a second. - Thread.sleep(1000); // msec - - location = requestingUnitEsPdu.getEntityLocation(); - - System.out.println("Espdu #" + index + " EID=[" + entityID.getSite() + "," + entityID.getApplication() + "," + entityID.getEntity() + "]"); - System.out.printf("DIS coordinates location: %.2f" , location.getX()); - System.out.printf(" %.2f" , location.getY() ); - System.out.printf(" %.2f" , location.getZ()); - } - } - catch (IOException | InterruptedException e) - { - System.out.println("Problem with DisExamples.EspduSender, see exception trace:"); - System.out.println(e); - } - } - - /** - * A number of sites get all snippy about using 255.255.255.255 for a - * broadcast address; it trips their security software and they kick you off - * their network. (Comcast, NPS.) This determines the broadcast address for - * all connected interfaces, based on the IP and subnet mask. If you have a - * dual-homed host it will return a broadcast address for both. If you have - * some VMs running on your host this will pick up the addresses for those - * as well--e.g. running VMWare on your laptop with a local IP this will also - * pick up a 192.168 address assigned to the VM by the host OS. - * - * @return set of all broadcast addresses - */ - public static Set<InetAddress> getBroadcastAddresses() - { - Set<InetAddress> broadcastAddresses = new HashSet<>(); - Enumeration interfaces; - - try { - interfaces = NetworkInterface.getNetworkInterfaces(); - - while (interfaces.hasMoreElements()) - { - NetworkInterface anInterface = (NetworkInterface) interfaces.nextElement(); - - if (anInterface.isUp()) - { - Iterator iterator = anInterface.getInterfaceAddresses().iterator(); - while (iterator.hasNext()) - { - InterfaceAddress anAddress = (InterfaceAddress) iterator.next(); - if ((anAddress == null || anAddress.getAddress().isLinkLocalAddress())) - { - continue; - } - - //System.out.println("Getting broadcast address for " + anAddress); - InetAddress broadcastAddress = anAddress.getBroadcast(); - if (broadcastAddress != null) - { - broadcastAddresses.add(broadcastAddress); - } - } - } - } - } - catch (SocketException e) - { - System.out.println("Problem with DisExamples.EspduSender.getBroadcastAddresses(), see exception trace:"); - System.out.println(e); - } - return broadcastAddresses; - } -} - diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/CainThomersonFinal/C_T_EspduReceiverA.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/CainThomersonFinal/C_T_EspduReceiverA.java deleted file mode 100644 index d9f2fb3e882cdcd50480258ab716ae4ae3b80dc4..0000000000000000000000000000000000000000 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/CainThomersonFinal/C_T_EspduReceiverA.java +++ /dev/null @@ -1,96 +0,0 @@ -package MV3500Cohort2018JulySeptember.FinalProject.CainThomersonFinal; - -import java.net.*; -import java.util.*; -import edu.nps.moves.disutil.*; -import edu.nps.moves.dis.*; -import java.io.IOException; - -/** - * Receives PDUs from the network in IEEE DIS format. - * Adapted from OpenDIS library example package edu.nps.moves.examples - * - * @author DMcG - */ -public class C_T_EspduReceiverA -{ - public static final int NUMBER_TO_SEND = 5000; - /** Max size of a PDU in binary format that we can receive. This is actually - * somewhat outdated--PDUs can be larger--but this is a reasonable starting point. - */ - public static final int MAX_PDU_SIZE = 8192; - - /** 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; - - public static void main(String args[]) - { - System.out.println("DisExamples.EspduReceiver started..."); - - MulticastSocket socket; - DatagramPacket packet; - InetAddress address; - PduFactory pduFactory = new PduFactory(); - - try { - // Specify the socket to receive data - socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); - socket.setBroadcast(true); - - while (true) // Loop infinitely, receiving datagrams - { - byte buffer[] = new byte[MAX_PDU_SIZE]; - packet = new DatagramPacket(buffer, buffer.length); - - socket.receive(packet); - - List<Pdu> pduBundle = pduFactory.getPdusFromBundle(packet.getData()); - System.out.println("Bundle size is " + pduBundle.size()); - - Iterator iterator = pduBundle.iterator(); - - while(iterator.hasNext()) - { - Pdu aPdu = (Pdu)iterator.next(); - - System.out.print("Recieved PDU of type: " + aPdu.getClass().getName()); - if(aPdu instanceof EntityStatePdu) - { - EntityID eid = ((EntityStatePdu)aPdu).getEntityID(); - Vector3Double position = ((EntityStatePdu)aPdu).getEntityLocation(); - System.out.print("\nEID: [" + eid.getSite() + ", " + eid.getApplication() + ", " + eid.getEntity() + "] "); - System.out.print("\nResupply source location: [" + position.getX() + ", " + position.getY() + ", " + position.getZ() + "]\n\n"); - //System.out.print(" FARP WTF recieving location: [" + newPos.getX() + ", " + newPos.getY() + ", " + newPos.getZ() + "]"); - } - - if(aPdu instanceof ServiceRequestPdu) - { - EntityID eid = ((ServiceRequestPdu)aPdu).getRequestingEntityID(); - short serviceType = ((ServiceRequestPdu)aPdu).getServiceTypeRequested(); - String serviceReqestTypeString = "null"; - if (serviceType == 0) - serviceReqestTypeString = "Other"; - if (serviceType == 1) - serviceReqestTypeString = "Resupply"; - if (serviceType == 2) - serviceReqestTypeString = "Repair"; - - List<SupplyQuantity> supplies = ((ServiceRequestPdu)aPdu).getSupplies(); - - System.out.println(" EID:[" + eid.getSite() + ", " + eid.getApplication() + ", " + eid.getEntity() + "] "); - System.out.println(" Service Type Requested: [" + serviceType + ", " + serviceReqestTypeString + "]"); - System.out.println(" Supply Quantity: [" + supplies.toString() + "]\n\n"); - } - } // end trop through PDU bundle - } // end while - } // End try - catch (IOException e) - { - System.out.println("Problem with DisExamples.EspduReceiver, see exception trace:"); - System.out.println(e); - } - } // end main -} // end class diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/CainThomersonFinal/C_T_EspduSenderA.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/CainThomersonFinal/C_T_EspduSenderA.java deleted file mode 100644 index 4e5a0cdcd105fb6e88f0f43f461b7fbe3e4d4840..0000000000000000000000000000000000000000 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/CainThomersonFinal/C_T_EspduSenderA.java +++ /dev/null @@ -1,245 +0,0 @@ -package MV3500Cohort2018JulySeptember.FinalProject.CainThomersonFinal; - -import java.io.*; -import java.net.*; -import java.util.*; - -import edu.nps.moves.dis.*; -import edu.nps.moves.disutil.CoordinateConversions; -import edu.nps.moves.disutil.DisTime; - -/** - * Creates and sends ESPDUs in IEEE binary format. Adapted from OpenDIS library - * example package edu.nps.moves.examples - * - * @author DMcG - */ -public class C_T_EspduSenderA { - - public static final int NUMBER_TO_SEND = 5000; - - public enum NetworkMode { - UNICAST, MULTICAST, BROADCAST - }; - - public static final int MAX_PDU_SIZE = 8192; - - public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3"; - - public static final int DEFAULT_MULTICAST_PORT = 3000; - - public static void main(String args[]) { - - System.out.println("\nREQUESTING UNIT:\n\tProgram started\n"); - - // Lat and Long Coordinates that will be used for the location of the Requesting Unit - double lat = 36.59; - double lon = -121.87; - - //Initialize the DIS time (this will be used later in the code - DisTime disTime = DisTime.getInstance(); - - - - // Initialize the Port, Mode, and Destination IP - int port = DEFAULT_MULTICAST_PORT; - NetworkMode mode = NetworkMode.BROADCAST; - InetAddress destinationIp = null; - - //Use a try/catch to ensure the you can connect to the Destination IP - try { - destinationIp = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); - } catch (UnknownHostException e) { - System.out.println(e + " Cannot create multicast address"); - System.exit(0); - } - - // All system properties, passed in on the command line via -Dattribute=value - Properties systemProperties = System.getProperties(); - // IP address we send to - String destinationIpString = systemProperties.getProperty("destinationIp"); - // Port we send to, and local port we open the socket on - String portString = systemProperties.getProperty("port"); - // Network mode: unicast, multicast, broadcast - String networkModeString = systemProperties.getProperty("networkMode"); // unicast or multicast or broadcast - - // Set up a socket to send information - try { - // Port we send to - if (portString != null) { - port = Integer.parseInt(portString); - } - - socket = new MulticastSocket(port); - - // Where we send packets to, the destination IP address - if (destinationIpString != null) { - destinationIp = InetAddress.getByName(destinationIpString); - } - - // Type of transport: unicast, broadcast, or multicast - if (networkModeString != null) { - if (networkModeString.equalsIgnoreCase("unicast")) { - mode = NetworkMode.UNICAST; - } else if (networkModeString.equalsIgnoreCase("broadcast")) { - mode = NetworkMode.BROADCAST; - } else if (networkModeString.equalsIgnoreCase("multicast")) { - mode = NetworkMode.MULTICAST; - if (!destinationIp.isMulticastAddress()) { - throw new RuntimeException("Sending to multicast address, but destination address " + destinationIp.toString() + "is not multicast"); - } - socket.joinGroup(destinationIp); - } - } - } catch (IOException | RuntimeException e) { - System.out.println("Unable to initialize networking. Exiting."); - System.out.println(e); - System.exit(-1); - } - - //Establish the Requesting Unit EnityState PDU - EntityStatePdu requestingUnitEsPdu = new EntityStatePdu(); - - // Initialize values in the Entity State PDU object. - //The exercise ID is a way to differentiate between different virtual worlds on one network. - requestingUnitEsPdu.setExerciseID((short) 1); - - // The EID is the unique identifier for objects in the world. - EntityID entityID = requestingUnitEsPdu.getEntityID(); - entityID.setSite(1); // 0 is apparently not a valid site number, per the spec - entityID.setApplication(1); - entityID.setEntity(2); - - // Set the entity type. (Check SISO for a list of enumerations) - EntityType entityType = requestingUnitEsPdu.getEntityType(); - entityType.setEntityKind((short) 1); // Platform (vs lifeform, munition, sensor, etc.) - entityType.setCountry(225); // USA - entityType.setDomain((short) 1); // Land (vs air, surface, subsurface, space) - entityType.setCategory((short) 1); // Tank - entityType.setSubcategory((short) 1); // M1 Abrams - entityType.setSpec((short) 3); // M1A2 Abrams - - // Lat and Long Coordinates that will be used for the location of the Requesting Unit - double lat = 36.595517; - double lon = -121.877000; - - Set<InetAddress> broadcastAddresses; - // Loop through sending N ESPDUs - try { - System.out.println("Sending " + NUMBER_TO_SEND + " ESPDU packets to " + destinationIp.toString()); - - for (int index = 0; index < NUMBER_TO_SEND; index++) { - //DIS Time must be used for this because DIS requires it. - int timestamp = disTime.getDisAbsoluteTimestamp(); - requestingUnitEsPdu.setTimestamp(timestamp); - - //Set up longitude to be changing throughout the running of the program - double direction = Math.pow((double) (-1.0), (double) (index)); - lon = lon + (direction * 0.00006); - - //Convert the lat and long coordinates to cartisian coordinates required by DIS - double disCoordinates[] = CoordinateConversions.getXYZfromLatLonDegrees(lat, lon, 1.0); - Vector3Double location = requestingUnitEsPdu.getEntityLocation(); - location.setX(disCoordinates[0]); - location.setY(disCoordinates[1]); - location.setZ(disCoordinates[2]); - - // You can set other ESPDU values here, such as the velocity, acceleration, - // and so on. - // Marshal out the espdu object to a byte array, then send a datagram - // packet with that data in it. - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - requestingUnitEsPdu.marshal(dos); - - //SERVICE_REQUEST - ServiceRequestPdu serviceRequest = new ServiceRequestPdu(); - serviceRequest.setRequestingEntityID(entityID); - serviceRequest.setServiceTypeRequested((short) 1); //Resupply - List<SupplyQuantity> pSupplies = new ArrayList<SupplyQuantity>(); - pSupplies.add(new SupplyQuantity()); - serviceRequest.setSupplies(pSupplies); - - //RESUPPLY_OFFER - ResupplyOfferPdu resupplyOffer = new ResupplyOfferPdu(); - - byte[] serviceRequestArray = serviceRequest.marshal(); - //FirePdu fire = new FirePdu(); - //byte[] fireArray = fire.marshal(); - - // The byte array here is the packet in DIS format. We put that into a - // datagram and send it. - byte[] data = baos.toByteArray(); - - broadcastAddresses = getBroadcastAddresses(); - Iterator iterator = broadcastAddresses.iterator(); - while (iterator.hasNext()) { - InetAddress broadcast = (InetAddress) iterator.next(); - System.out.println("Sending broadcast datagram packet to " + broadcast); - DatagramPacket packet = new DatagramPacket(data, data.length, broadcast, port); - socket.send(packet); - // TODO experiment with these! 8) - //packet = new DatagramPacket(fireArray, fireArray.length, broadcast, port); // alternate - packet = new DatagramPacket(serviceRequestArray, serviceRequestArray.length, broadcast, port); // alternate - socket.send(packet); - } - - // Send every 1 sec. Otherwise all this will be all over in a fraction of a second. - Thread.sleep(1000); // msec - - location = requestingUnitEsPdu.getEntityLocation(); - - System.out.println("Espdu #" + index + " EID=[" + entityID.getSite() + "," + entityID.getApplication() + "," + entityID.getEntity() + "]"); - System.out.println(" DIS coordinates location=[" + location.getX() + "," + location.getY() + "," + location.getZ() + "]"); - } - } catch (IOException | InterruptedException e) { - System.out.println("Problem with DisExamples.EspduSender, see exception trace:"); - System.out.println(e); - } - } - - /** - * A number of sites get all snippy about using 255.255.255.255 for a - * broadcast address; it trips their security software and they kick you off - * their network. (Comcast, NPS.) This determines the broadcast address for - * all connected interfaces, based on the IP and subnet mask. If you have a - * dual-homed host it will return a broadcast address for both. If you have - * some VMs running on your host this will pick up the addresses for those - * as well--e.g. running VMWare on your laptop with a local IP this will - * also pick up a 192.168 address assigned to the VM by the host OS. - * - * @return set of all broadcast addresses - */ - public static Set<InetAddress> getBroadcastAddresses() { - Set<InetAddress> broadcastAddresses = new HashSet<>(); - Enumeration interfaces; - - try { - interfaces = NetworkInterface.getNetworkInterfaces(); - - while (interfaces.hasMoreElements()) { - NetworkInterface anInterface = (NetworkInterface) interfaces.nextElement(); - - if (anInterface.isUp()) { - Iterator iterator = anInterface.getInterfaceAddresses().iterator(); - while (iterator.hasNext()) { - InterfaceAddress anAddress = (InterfaceAddress) iterator.next(); - if ((anAddress == null || anAddress.getAddress().isLinkLocalAddress())) { - continue; - } - - //System.out.println("Getting broadcast address for " + anAddress); - InetAddress broadcastAddress = anAddress.getBroadcast(); - if (broadcastAddress != null) { - broadcastAddresses.add(broadcastAddress); - } - } - } - } - } catch (SocketException e) { - System.out.println("Problem with DisExamples.EspduSender.getBroadcastAddresses(), see exception trace:"); - System.out.println(e); - } - return broadcastAddresses; - } -} diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FDCSendRecieve.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FDCSendRecieve.java index 4282aba1e86866926ee18b40a08bd31f8cfa8ebe..4dadb6ee76c47aba0fcf67c8eee08e1e1b5f4140 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FDCSendRecieve.java +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FDCSendRecieve.java @@ -61,14 +61,7 @@ public class FDCSendRecieve { short currentPduType = pdu.getPduType(); System.out.println("in sender, recived PDU type: " + currentPduType); -// String currentPduTypeName = pdu.getClass().getName(); -// short currentProtocolFamilyID = pdu.getProtocolFamily(); -// String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName(); - - // Loop through all the enumerated PDU types, create a PDU for each type, - // and add that PDU to a list. - //System.out.println(pdu); - //Change the switch statement to the currentPduType from the recieve portion, then when a packet we want comes in, send the CASE file. + switch (currentPduType) // using enumeration values from edu.nps.moves.disenum.* { @@ -76,25 +69,13 @@ public class FDCSendRecieve { aPdu = pdu; break; -// case COMMENT: -// aPdu = new CommentPdu(); -// break; -// case 2: //FIRE aPdu = pdu; break; -// -// case DETONATION: -// aPdu = new DetonationPdu(); -// break; // case 15: //AcknowledgePdu aPdu = pdu; break; -// -// case 16: //ACTION_REQUEST: -// aPdu = new ActionRequestPdu(); -// break; case 17: aPdu = pdu; @@ -105,7 +86,6 @@ public class FDCSendRecieve { break; default: - //add some shit that makes sense here. System.out.print("PDU of type " + pdu + " not supported, created or sent "); System.out.println(); } @@ -126,7 +106,6 @@ public class FDCSendRecieve { buffer = baos.toByteArray(); DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); socket.send(packet); - //sentBuffer[sentBuffer.length] = aPdu.getTimestamp(); sentBufferList.add(aPdu.getTimestamp()); System.out.println("Sent PDU of type " + aPdu.getClass().getName()+ "\n"); } @@ -134,24 +113,7 @@ public class FDCSendRecieve { public static void main(String[] args) throws IOException, InterruptedException { DisTime disTime = DisTime.getInstance(); - //turns on the sender code - might need to move around down into the recieve with the if statements... - // - // ORIGINAL SENDING CODE MAIN CLASS: - // - // -// if (args.length == 2) { -// FDCSendRecieve sender = new FDCSendRecieve(Integer.parseInt(args[0]), args[1]); -// // sender.run(); //needs to be sender.run(pdu) -// } else { -// System.out.println("Usage: PduSender <port> <multicast group>"); -// System.out.println("Default: PduSender " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS); -// FDCSendRecieve sender = new FDCSendRecieve(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); - // sender.run(); -// } - // - // Inital Hello world from entity: - // FDCSendRecieve sender = new FDCSendRecieve(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); //initalize the sender EntityStatePdu FDCespdu = new EntityStatePdu(); @@ -181,7 +143,7 @@ public class FDCSendRecieve { FDCespdu.setEntityLocation(location); int timestamp = disTime.getDisAbsoluteTimestamp(); FDCespdu.setTimestamp(timestamp); - //FDCespdu.setTimestamp(System.currentTimeMillis()); + sender.run(FDCespdu); //sends inital here I am and who I am //Set up other players to look for: @@ -206,7 +168,6 @@ public class FDCSendRecieve { short currentPduType = 0; //will use the curentPduType as the check for sending other packets. try { - // TODO: Change the line below to make sense for each class System.out.println("FDC is alive and ready to recieve fire missions...\n\n"); socket = new MulticastSocket(MULTICAST_PORT); address = InetAddress.getByName(MULTICAST_GROUP); @@ -221,9 +182,6 @@ public class FDCSendRecieve { packet = new DatagramPacket(buffer, buffer.length); // reset socket.receive(packet); - // - //TODO: NEED IF STATEMENT IF THE SENDER IS THIS CLASS TO DELETE. - // String marking2 = new String(); Pdu pdu = factory.createPdu(packet.getData()); @@ -246,7 +204,6 @@ public class FDCSendRecieve { EntityStatePdu pdu2 = (EntityStatePdu) pdu; marking2 = pdu2.getMarking().getCharactersString(); } -//Keep adding any if statements as needed for the class you are building. StringBuilder message = new StringBuilder(); message.append("received DIS PDU: "); message.append("pduType "); @@ -266,9 +223,6 @@ public class FDCSendRecieve { EntityStatePdu entityPDU = (EntityStatePdu) pdu; EntityType PduEntityType = entityPDU.getEntityType(); if (PduEntityType.getCountry() == 225) { - //do something for the OBS as this is a russian asshat. Most likely send the pdu with sender.run(pdu); - //create Action Request PDU - //sender.run(actionPDU); Thread.sleep((long) 200); timestamp = disTime.getDisAbsoluteTimestamp(); FDCespdu.setTimestamp(timestamp); @@ -284,14 +238,7 @@ public class FDCSendRecieve { ack.setRequestID((long) 1); timestamp = disTime.getDisAbsoluteTimestamp(); ack.setTimestamp(timestamp); -// ActionResponsePdu response = new ActionResponsePdu(); -// response.setExerciseID((short) 1); -// response.setRequestID((long) 1); -// response.setOriginatingEntityID(FDCID); -// response.setReceivingEntityID(OBSEntityID); -// timestamp = disTime.getDisAbsoluteTimestamp(); -// response.setTimestamp(timestamp); -// + FirePdu fire = new FirePdu(); fire.setExerciseID((short) 1); fire.setFireMissionIndex(1000); @@ -301,7 +248,6 @@ public class FDCSendRecieve { timestamp = disTime.getDisAbsoluteTimestamp(); fire.setTimestamp(timestamp); sender.run(ack, fire); -// sender.run(fire,fire); } if (currentPduType == 22) //Comment PDU diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/FDCSendRecieve.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/FDCSendRecieve.java new file mode 100644 index 0000000000000000000000000000000000000000..0e9bcfc12f7e11c1d9a480e51882962093500872 --- /dev/null +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/FDCSendRecieve.java @@ -0,0 +1,281 @@ +package MV3500Cohort2018JulySeptember.FinalProjects.FriscoFurrProject; + +import java.net.*; +import java.io.*; +import java.util.*; +import edu.nps.moves.dis.*; +import java.io.IOException; +import edu.nps.moves.disutil.PduFactory; +import edu.nps.moves.disutil.DisTime; + +public class FDCSendRecieve { + + /** + * 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 static final int MULTICAST_PORT = 3000; + public static final String MULTICAST_GROUP = "239.1.2.3"; + public static final boolean USE_FAST_ESPDU = false; + public long[] sentBuffer = new long[100]; + public static List sentBufferList; + DisTime disTime = DisTime.getInstance(); + + public FDCSendRecieve(int port, String multicast) { + this.sentBufferList = new ArrayList<>(); + 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(Pdu... pdupass) throws UnknownHostException, IOException { + + List<Pdu> generatedPdus = new ArrayList<>(); + Pdu aPdu = null; + System.out.println("\nFDC Sender started..."); + // Send the PDUs we created + InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); + MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); + socket.joinGroup(localMulticastAddress); + + for (Pdu i : pdupass) { + Pdu pdu = i; + if (sentBufferList.contains(pdu.getTimestamp())) { + break; + } + + short currentPduType = pdu.getPduType(); + System.out.println("in sender, recived PDU type: " + currentPduType); + + switch (currentPduType) // using enumeration values from edu.nps.moves.disenum.* + { + + case 1: //ENTITY_STATE: + aPdu = pdu; + break; + + case 2: //FIRE + aPdu = pdu; + break; +// + case 15: //AcknowledgePdu + aPdu = pdu; + break; + + case 17: + aPdu = pdu; + break; + + case 14: + aPdu = pdu; + break; + + default: + System.out.print("PDU of type " + pdu + " not supported, created or sent "); + System.out.println(); + } + if (aPdu != null) { + generatedPdus.add(aPdu); + System.out.println("APDU container count " + generatedPdus.size()); + } + + } + for (int idx = 0; idx < generatedPdus.size(); idx++) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + byte[] buffer; + + aPdu = generatedPdus.get(idx); + aPdu.marshal(dos); + + buffer = baos.toByteArray(); + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); + socket.send(packet); + sentBufferList.add(aPdu.getTimestamp()); + System.out.println("Sent PDU of type " + aPdu.getClass().getName()+ "\n"); + } + } + + public static void main(String[] args) throws IOException, InterruptedException { + DisTime disTime = DisTime.getInstance(); + + FDCSendRecieve sender = new FDCSendRecieve(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); //initalize the sender + + EntityStatePdu FDCespdu = new EntityStatePdu(); + Marking marking = new Marking(); + marking.setCharactersString("FDC"); + FDCespdu.setMarking(marking); + FDCespdu.setExerciseID((short) 1); + EntityID FDCID = FDCespdu.getEntityID(); + FDCID.setSite(1); // 0 is apparently not a valid site number, per the spec + FDCID.setApplication(1); + FDCID.setEntity(1); //change for each person I think??? - JMF + EntityType entityType = FDCespdu.getEntityType(); + // + //Need to update the info below to match the unit type IAW SISO-REF-010-2015 V.21 + // https://www.sisostds.org/DesktopModules/Bring2mind/DMX/Download.aspx?Command=Core_Download&EntryId=42916&PortalId=0&TabId=105 + // + entityType.setEntityKind((short) 1); // Platform (vs lifeform, munition, sensor, etc.) TGT=1, OBS = 1 + entityType.setCountry(225); // USA TGT = 222 (Russia), OBS = 225 + entityType.setDomain((short) 1); // Land (vs air, surface, subsurface, space) both TGT and OBS are 1 + entityType.setCategory((short) 3); // FDC TGT = 1, Tank OBS=40 OP + entityType.setSubcategory((short) 12); // M1068 TGT = 2, T72 tank NONE FOR OP + entityType.setSpec((short) 1); // M1068 w/ SICUP Tent NONE FOR TGT OR OP + Vector3Double location = new Vector3Double(); + location.setX(0.0); //TGT = 150 OBS = 75 + location.setY(0.0); //TGT = 150 OBS = 75 + location.setZ(10.0); //TGT = 20 OBS = 50 + FDCespdu.setEntityLocation(location); + int timestamp = disTime.getDisAbsoluteTimestamp(); + FDCespdu.setTimestamp(timestamp); + + sender.run(FDCespdu); //sends inital here I am and who I am + + //Set up other players to look for: + EntityID OBSEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below + OBSEntityID.setEntity(2); + OBSEntityID.setApplication(1); + OBSEntityID.setSite(1); + + EntityID TGTEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below + TGTEntityID.setEntity(3); + TGTEntityID.setApplication(1); + TGTEntityID.setSite(1); + + /* BELOW IS THE RECIEVE CODE // + // // + // // + */ // + PduFactory factory; + MulticastSocket socket = null; + InetAddress address = null; + DatagramPacket packet; + short currentPduType = 0; //will use the curentPduType as the check for sending other packets. + + try { + System.out.println("FDC is alive and ready to recieve fire missions...\n\n"); + socket = new MulticastSocket(MULTICAST_PORT); + address = InetAddress.getByName(MULTICAST_GROUP); + 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); + + String marking2 = new String(); + Pdu pdu = factory.createPdu(packet.getData()); + currentPduType = pdu.getPduType(); + if (currentPduType == 14) //stop/freeze PDU + { + System.out.println("recieved Stop/Freeze packet..."); + return; + } +// pdu.setExerciseID((short)5); + if (pdu != null) { + if (sentBufferList.contains(pdu.getTimestamp())) { + pdu = null; + } + if (pdu != null) { + + String currentPduTypeName = pdu.getClass().getName(); + + if (currentPduType == 1) { + EntityStatePdu pdu2 = (EntityStatePdu) pdu; + marking2 = pdu2.getMarking().getCharactersString(); + } + StringBuilder message = new StringBuilder(); + message.append("received DIS PDU: "); + message.append("pduType "); + if (currentPduType < 10) { + message.append(" "); + } + message.append(currentPduType).append(" ").append(currentPduTypeName); + message.append(" "); + message.append(marking2); + System.out.println(message.toString()); + //Reference for PDU Types: + // http://faculty.nps.edu/brutzman/vrtp/mil/navy/nps/disEnumerations/JdbeHtmlFiles/pdu/8.htm + // + + if (currentPduType == 1) //EntityState + { + EntityStatePdu entityPDU = (EntityStatePdu) pdu; + EntityType PduEntityType = entityPDU.getEntityType(); + if (PduEntityType.getCountry() == 225) { + Thread.sleep((long) 200); + timestamp = disTime.getDisAbsoluteTimestamp(); + FDCespdu.setTimestamp(timestamp); + System.out.println("Talking to the Observer, sending a radio check "); + sender.run(FDCespdu); + } + } + if (currentPduType == 16) //Action request + { + // Action response is sending a Null PDU, not sure why... + AcknowledgePdu ack = new AcknowledgePdu(); + ack.setExerciseID((short) 1); + ack.setRequestID((long) 1); + timestamp = disTime.getDisAbsoluteTimestamp(); + ack.setTimestamp(timestamp); + + FirePdu fire = new FirePdu(); + fire.setExerciseID((short) 1); + fire.setFireMissionIndex(1000); + fire.setRangeToTarget((float) Math.sqrt(Math.pow(150, 2) + Math.pow(150, 2))); //would pass in target info, but here we know location of tgt is (150,150) and FDC (0,0) + fire.setFiringEntityID(FDCID); + fire.setTargetEntityID(TGTEntityID); + timestamp = disTime.getDisAbsoluteTimestamp(); + fire.setTimestamp(timestamp); + sender.run(ack, fire); + } + + if (currentPduType == 22) //Comment PDU + { + AcknowledgePdu ack = new AcknowledgePdu(); + ack.setExerciseID((short) 1); + ack.setRequestID((long) 1); + timestamp = disTime.getDisAbsoluteTimestamp(); + ack.setTimestamp(timestamp); + + StopFreezePdu stop = new StopFreezePdu(); + stop.setExerciseID((short) 1); + stop.setRequestID((long) 1); + sender.run(ack, stop); + } + + } else { + System.out.println("received packet but pdu is null and originated from FDC. Still standing by..."); + } + } + } + } catch (IOException e) { + System.out.println("Problem with FDC.PduReceiver, see exception trace:"); + System.out.println(e); + } finally { + System.out.println("FDC.PduReceiver complete. - OUT!"); + } + + } + +} diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/FriscoFurrPduSender.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/FriscoFurrPduSender.java new file mode 100644 index 0000000000000000000000000000000000000000..c550fc87e10d016dd95c79dac9e1683c5470522b --- /dev/null +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/FriscoFurrPduSender.java @@ -0,0 +1,226 @@ +package MV3500Cohort2018JulySeptember.FinalProjects.FriscoFurrProject; + +import java.io.*; +import java.net.*; +import java.util.*; + +import edu.nps.moves.dis.*; +import edu.nps.moves.disenum.*; +import edu.nps.moves.examples.ClassNameComparator; + + +/** + * 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 FriscoFurrPduSender +{ + /** 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 FriscoFurrPduSender(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("DisExamples.PduSender started..."); + try { + List<Pdu> generatedPdus = new ArrayList<>(); + + // Loop through all the enumerated PDU types, create a PDU for each type, + // and add that PDU to a list. + System.out.println("number of PDU types in pduType is " + PduType.values().length); + for (PduType pdu : PduType.values()) { + Pdu aPdu = null; + System.out.println(pdu); + switch (pdu) // using enumeration values from edu.nps.moves.disenum.* + { +// +// case ENTITY_STATE: +// System.out.println("Case: Enitity_State "+pdu+"\n"); +// aPdu = new EntityStatePdu(); +// EntityStatePdu espdu = (EntityStatePdu) aPdu; +// Marking marking = new Marking(); +// marking.setCharactersString("TEST DUDE"); +// espdu.setMarking(marking); +// Vector3Double espduLocation = new Vector3Double(); +// espduLocation.setX(1.0); +// espduLocation.setY(2.0); +// espduLocation.setZ(3.0); +// EntityType entityType = espdu.getEntityType(); +// entityType.setCountry(222); +// +// break; + +// case COMMENT: +// aPdu = new CommentPdu(); +// CommentPdu comment = (CommentPdu) aPdu; +// EntityID OBSEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below +// OBSEntityID.setEntity(2); +// OBSEntityID.setApplication(1); +// OBSEntityID.setSite(1); +// comment.setOriginatingEntityID(OBSEntityID); +// +// long number = 1; +// //comment.setNumberOfFixedDatumRecords(number); +// +// comment.setNumberOfVariableDatumRecords(number); +// List datum = new ArrayList<FixedDatum>(); +// FixedDatum superDatum = new FixedDatum(); +// superDatum.setFixedDatumID((long)5); +// superDatum.setFixedDatumValue((long) 54321); +// datum.add(10); +// datum.add(superDatum); +// comment.setFixedDatums(datum); +// List Vdatum = new ArrayList<VariableDatum>(); +// VariableDatum testBitch = new VariableDatum(); +// testBitch.setVariableDatumID(1); +// Vdatum.add(15); +// comment.setVariableDatums(Vdatum); +// break; + +// case FIRE: +// aPdu = new FirePdu(); +// break; + + case DETONATION: + aPdu = new DetonationPdu(); + System.out.println("detonationPdu type " + aPdu.getPduType()); + break; +// +// case COLLISION: +// aPdu = new CollisionPdu(); +// break; +// +// case SERVICE_REQUEST: +// aPdu = new ServiceRequestPdu(); +// break; +// +// case RESUPPLY_OFFER: +// aPdu = new ResupplyOfferPdu(); +// break; +// +// case RESUPPLY_RECEIVED: +// aPdu = new ResupplyReceivedPdu(); +// break; +// +// case RESUPPLY_CANCEL: +// aPdu = new ResupplyCancelPdu(); +// break; +// +// case REPAIR_COMPLETE: +// aPdu = new RepairCompletePdu(); +// break; +// +// case REPAIR_RESPONSE: +// aPdu = new RepairResponsePdu(); +// break; +// +// case CREATE_ENTITY: +// aPdu = new CreateEntityPdu(); +// break; +// +// case REMOVE_ENTITY: +// aPdu = new RemoveEntityPdu(); +// break; +// +// case START_RESUME: +// aPdu = new StartResumePdu(); +// break; +// +// case STOP_FREEZE: +// aPdu = new StopFreezePdu(); +// break; +// +// case ACKNOWLEDGE: +// aPdu = new AcknowledgePdu(); +// break; +// +// case ACTION_REQUEST: +// aPdu = new ActionRequestPdu(); +// ActionRequestPdu action = (ActionRequestPdu) aPdu; +// EntityID OBSEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below +// OBSEntityID.setEntity(2); +// OBSEntityID.setApplication(1); +// OBSEntityID.setSite(1); +// action.setOriginatingEntityID(OBSEntityID); +// break; + + default: + System.out.print("PDU of type " + pdu + " not supported, created or sent "); + System.out.println(); + } + if (aPdu != null) + { + generatedPdus.add(aPdu); + System.out.println("APDU container count "+generatedPdus.size()); + } + } + + // Sort the created PDUs by class name + Collections.sort(generatedPdus, new ClassNameComparator()); + + // Send the 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 < generatedPdus.size(); idx++) + { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + byte[] buffer; + + Pdu aPdu = generatedPdus.get(idx); + aPdu.marshal(dos); + + buffer = baos.toByteArray(); + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); + socket.send(packet); + System.out.println("Sent PDU 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) { + FriscoFurrPduSender sender = new FriscoFurrPduSender(Integer.parseInt(args[0]), args[1]); + sender.run(); + } else { + System.out.println("Usage: PduSender <port> <multicast group>"); + System.out.println("Default: PduSender " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS); + FriscoFurrPduSender sender = new FriscoFurrPduSender(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); + sender.run(); + } + } +} diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/OBSSendRecieve1.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/OBSSendRecieve1.java new file mode 100644 index 0000000000000000000000000000000000000000..ca45cda575f52b27114b1f3b462ad0a4f76bf7e9 --- /dev/null +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/OBSSendRecieve1.java @@ -0,0 +1,310 @@ +package MV3500Cohort2018JulySeptember.FinalProjects.FriscoFurrProject; + +import java.net.*; +import java.io.*; +import java.util.*; +import edu.nps.moves.dis.*; +import java.io.IOException; +import edu.nps.moves.disutil.PduFactory; +import edu.nps.moves.disutil.DisTime; + +public class OBSSendRecieve1 { + + /** + * 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 static final int MULTICAST_PORT = 3000; + public static final String MULTICAST_GROUP = "239.1.2.3"; + public static final boolean USE_FAST_ESPDU = false; + public long[] sentBuffer = new long[100]; + public static List sentBufferList; + DisTime disTime = DisTime.getInstance(); + int transmission =1; + + public OBSSendRecieve1(int port, String multicast) { + this.sentBufferList = new ArrayList<>(); + 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(Pdu... pdupass) throws UnknownHostException, IOException { + + List<Pdu> generatedPdus = new ArrayList<>(); + Pdu aPdu = null; + if(transmission ==1){ + System.out.println("\nInitalizing OP coms..."); + transmission++; + } + if(transmission>1){ + System.out.println("\nObserver Sending traffic..."); + } + // Send the PDUs we created + InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); + MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); + socket.joinGroup(localMulticastAddress); + + for (Pdu i : pdupass) { + Pdu pdu = i; + if (sentBufferList.contains(pdu.getTimestamp())) { + break; + } + + short currentPduType = pdu.getPduType(); + System.out.println("in observer sender, processing PDU type: " + currentPduType); +// String currentPduTypeName = pdu.getClass().getName(); +// short currentProtocolFamilyID = pdu.getProtocolFamily(); +// String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName(); + + // Loop through all the enumerated PDU types, create a PDU for each type, + // and add that PDU to a list. + //System.out.println(pdu); + //Change the switch statement to the currentPduType from the recieve portion, then when a packet we want comes in, send the CASE file. + switch (currentPduType) // using enumeration values from edu.nps.moves.disenum.* + { + + case 1: //ENTITY_STATE: + aPdu = pdu; + break; + +// case COMMENT: +// aPdu = new CommentPdu(); +// break; +// +// case 2: //FIRE +// aPdu = pdu; +// break; +// +// case DETONATION: +// aPdu = new DetonationPdu(); +// break; +// +// case 15: //AcknowledgePdu +// aPdu = pdu; +// break; +//// + case 16: //ACTION_REQUEST: + aPdu = new ActionRequestPdu(); + break; + + case 22: //CommentPdu + aPdu = pdu; + break; + +// case 14: +// aPdu = pdu; +// break; + default: + //add some shit that makes sense here. + System.out.print("PDU of type " + pdu + " not supported by Observer, created or sent "); + System.out.println(); + } + if (aPdu != null) { + generatedPdus.add(aPdu); + System.out.println("APDU container count " + generatedPdus.size()); + } + + } + for (int idx = 0; idx < generatedPdus.size(); idx++) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + byte[] buffer; + + aPdu = generatedPdus.get(idx); + aPdu.marshal(dos); + + buffer = baos.toByteArray(); + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); + socket.send(packet); + //sentBuffer[sentBuffer.length] = aPdu.getTimestamp(); + sentBufferList.add(aPdu.getTimestamp()); + System.out.println("Observer Sent PDU of type " + aPdu.getClass().getName()+"/n"); + } + } + + public static void main(String[] args) throws IOException { + DisTime disTime = DisTime.getInstance(); + //turns on the sender code - might need to move around down into the recieve with the if statements... + // + // ORIGINAL SENDING CODE MAIN CLASS: + // + // +// if (args.length == 2) { +// FDCSendRecieve sender = new FDCSendRecieve(Integer.parseInt(args[0]), args[1]); +// // sender.run(); //needs to be sender.run(pdu) +// } else { +// System.out.println("Usage: PduSender <port> <multicast group>"); +// System.out.println("Default: PduSender " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS); +// FDCSendRecieve sender = new FDCSendRecieve(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); + // sender.run(); +// } + + // + // Inital Hello world from entity: + // + OBSSendRecieve1 sender = new OBSSendRecieve1(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); //initalize the sender + + EntityStatePdu OBSespdu = new EntityStatePdu(); + Marking marking = new Marking(); + marking.setCharactersString("Observer"); + OBSespdu.setMarking(marking); + OBSespdu.setExerciseID((short) 1); + EntityID OBSID = OBSespdu.getEntityID(); + OBSID.setSite(1); // 0 is apparently not a valid site number, per the spec + OBSID.setApplication(1); + OBSID.setEntity(2); //change for each person I think??? - JMF + EntityType entityType = OBSespdu.getEntityType(); + // + //Need to update the info below to match the unit type IAW SISO-REF-010-2015 V.21 + // https://www.sisostds.org/DesktopModules/Bring2mind/DMX/Download.aspx?Command=Core_Download&EntryId=42916&PortalId=0&TabId=105 + // + entityType.setEntityKind((short) 1); // Platform (vs lifeform, munition, sensor, etc.) TGT=1, OBS = 1 + entityType.setCountry(225); // USA TGT = 222 (Russia), OBS = 225 + entityType.setDomain((short) 1); // Land (vs air, surface, subsurface, space) both TGT and OBS are 1 + entityType.setCategory((short) 40); // FDC TGT = 1, Tank OBS=40 OP +// entityType.setSubcategory((short) 12); // M1068 TGT = 2, T72 tank NONE FOR OP +// entityType.setSpec((short) 1); // M1068 w/ SICUP Tent NONE FOR TGT OR OP + Vector3Double location = new Vector3Double(); + location.setX(75.0); //TGT = 150 OBS = 75 + location.setY(75.0); //TGT = 150 OBS = 75 + location.setZ(50.0); //TGT = 20 OBS = 50 + OBSespdu.setEntityLocation(location); + int timestamp = disTime.getDisAbsoluteTimestamp(); + OBSespdu.setTimestamp(timestamp); + //FDCespdu.setTimestamp(System.currentTimeMillis()); + sender.run(OBSespdu); //sends inital here I am and who I am + + //other player to look out for: + EntityID FDCEntityID = new EntityID(); + FDCEntityID.setEntity(1); + FDCEntityID.setApplication(1); + FDCEntityID.setSite(1); + + EntityID TGTEntityID = new EntityID(); + TGTEntityID.setEntity(3); + TGTEntityID.setApplication(1); + TGTEntityID.setSite(1); + + /* BELOW IS THE RECIEVE CODE // + // // + // // + */ // + PduFactory factory; + MulticastSocket socket = null; + InetAddress address = null; + DatagramPacket packet; + short currentPduType; //will use the curentPduType as the check for sending other packets. + + try { + // TODO: Change the line below to make sense for each class + System.out.println("Observer is in the OP and looking for targets...\n\n"); + socket = new MulticastSocket(MULTICAST_PORT); + address = InetAddress.getByName(MULTICAST_GROUP); + 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); + // + //TODO: NEED IF STATEMENT IF THE SENDER IS THIS CLASS TO DELETE. + // + + String marking2 = new String(); + Pdu pdu = factory.createPdu(packet.getData()); + currentPduType = pdu.getPduType(); + if (currentPduType == 14) //stop/freeze PDU + { + System.out.println("recieved Stop/Freeze packet..."); + return; + } +// pdu.setExerciseID((short)5); + if (pdu != null) { + if (sentBufferList.contains(pdu.getTimestamp())) { + pdu = null; + } + if (pdu != null) { + + String currentPduTypeName = pdu.getClass().getName(); + if (currentPduType == 1) { + EntityStatePdu pdu2 = (EntityStatePdu) pdu; + marking2 = pdu2.getMarking().getCharactersString(); + } +//Keep adding any if statements as needed for the class you are building. + StringBuilder message = new StringBuilder(); + message.append("received DIS PDU: "); + message.append("pduType "); + if (currentPduType < 10) { + message.append(" "); + } + message.append(currentPduType).append(" ").append(currentPduTypeName); + message.append(" "); + message.append(marking2); + System.out.println(message.toString()); + //Reference for PDU Types: + // http://faculty.nps.edu/brutzman/vrtp/mil/navy/nps/disEnumerations/JdbeHtmlFiles/pdu/8.htm + // + + if (currentPduType == 1) //EntityState + { + EntityStatePdu entityPDU = (EntityStatePdu) pdu; + EntityType PduEntityType = entityPDU.getEntityType(); + if (PduEntityType.getCountry() == 222) { + ActionRequestPdu action = new ActionRequestPdu(); + action.setExerciseID((short) 1); + action.setRequestID((long) 2); + action.setOriginatingEntityID(OBSID); + action.setReceivingEntityID(FDCEntityID); + timestamp = disTime.getDisAbsoluteTimestamp(); + action.setTimestamp(timestamp); + System.out.println("\n Got a Russian SOB! Preparing CFF to send."); + sender.run(action); + } + } + + if (currentPduType == 3) //Detination + { + CommentPdu comment = new CommentPdu(); + comment.setExerciseID((short) 1); + comment.setOriginatingEntityID(TGTEntityID); + timestamp = disTime.getDisAbsoluteTimestamp(); + comment.setTimestamp(timestamp); + sender.run(comment); + } + + } else { + System.out.println("received packet but pdu is null and originated from Observer. Still searching for other Targets..."); + } + } + } + } catch (IOException e) { + System.out.println("Problem with Observer.PduReceiver, see exception trace:"); + System.out.println(e); + } finally { + System.out.println("Observer.PduReceiver complete. - OUT!"); + } + + } + +} diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/TGTSendRecieve.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/TGTSendRecieve.java new file mode 100644 index 0000000000000000000000000000000000000000..2ea1d4de3e028a3fd0e61e8b4c2b3a73fb9d2274 --- /dev/null +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/TGTSendRecieve.java @@ -0,0 +1,250 @@ +package MV3500Cohort2018JulySeptember.FinalProjects.FriscoFurrProject; + +import java.net.*; +import java.io.*; +import java.util.*; +import edu.nps.moves.dis.*; +import java.io.IOException; +import edu.nps.moves.disutil.PduFactory; +import edu.nps.moves.disutil.DisTime; + +public class TGTSendRecieve { + + /** + * 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 static final int MULTICAST_PORT = 3000; + public static final String MULTICAST_GROUP = "239.1.2.3"; + public static final boolean USE_FAST_ESPDU = false; + public long[] sentBuffer = new long[100]; + public static List sentBufferList; + DisTime disTime = DisTime.getInstance(); + int transmission = 1; + + public TGTSendRecieve(int port, String multicast) { + this.sentBufferList = new ArrayList<>(); + 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(Pdu... pdupass) throws UnknownHostException, IOException { + + List<Pdu> generatedPdus = new ArrayList<>(); + Pdu aPdu = null; + if (transmission == 1) { + System.out.println("\nTarget is rolling out..."); + transmission++; + } + if (transmission > 1) { + System.out.println("\nDeath from above everywhere! (sending function started)..."); + } + // Send the PDUs we created + InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); + MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); + socket.joinGroup(localMulticastAddress); + + for (Pdu i : pdupass) { + Pdu pdu = i; + if (sentBufferList.contains(pdu.getTimestamp())) { + break; + } + + short currentPduType = pdu.getPduType(); + System.out.println("in Target sender, processing PDU type: " + currentPduType); +// + switch (currentPduType) // using enumeration values from edu.nps.moves.disenum.* + { + + case 1: //ENTITY_STATE: + aPdu = pdu; + break; + + case 3: //detination PDU + aPdu = pdu; + break; + + default: + //add some shit that makes sense here. + System.out.print("PDU of type " + pdu + " not supported by Observer, created or sent "); + System.out.println(); + } + if (aPdu != null) { + generatedPdus.add(aPdu); + System.out.println("APDU container count " + generatedPdus.size()); + } + + } + for (int idx = 0; idx < generatedPdus.size(); idx++) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + byte[] buffer; + + aPdu = generatedPdus.get(idx); + aPdu.marshal(dos); + + buffer = baos.toByteArray(); + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); + socket.send(packet); + //sentBuffer[sentBuffer.length] = aPdu.getTimestamp(); + sentBufferList.add(aPdu.getTimestamp()); + System.out.println("Observer Sent PDU of type " + aPdu.getClass().getName() + "/n"); + } + } + + public static void main(String[] args) throws IOException { + DisTime disTime = DisTime.getInstance(); + //turns on the sender code - might need to move around down into the recieve with the if statements... + + // + // Inital Hello world from entity: + // + TGTSendRecieve sender = new TGTSendRecieve(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); //initalize the sender + + EntityStatePdu TGTespdu = new EntityStatePdu(); + Marking marking = new Marking(); + marking.setCharactersString("Target"); + TGTespdu.setMarking(marking); + TGTespdu.setExerciseID((short) 1); + EntityID OBSID = TGTespdu.getEntityID(); + OBSID.setSite(1); // 0 is apparently not a valid site number, per the spec + OBSID.setApplication(1); + OBSID.setEntity(3); //change for each person I think??? - JMF + EntityType entityType = TGTespdu.getEntityType(); + // + //Need to update the info below to match the unit type IAW SISO-REF-010-2015 V.21 + // https://www.sisostds.org/DesktopModules/Bring2mind/DMX/Download.aspx?Command=Core_Download&EntryId=42916&PortalId=0&TabId=105 + // + entityType.setEntityKind((short) 1); // Platform (vs lifeform, munition, sensor, etc.) TGT=1, OBS = 1 + entityType.setCountry(222); // USA TGT = 222 (Russia), OBS = 225 + entityType.setDomain((short) 1); // Land (vs air, surface, subsurface, space) both TGT and OBS are 1 + entityType.setCategory((short) 1); // FDC TGT = 1, Tank OBS=40 OP + entityType.setSubcategory((short) 2); // M1068 TGT = 2, T72 tank NONE FOR OP + + Vector3Double location = new Vector3Double(); + location.setX(150.0); //TGT = 150 OBS = 75 + location.setY(150.0); //TGT = 150 OBS = 75 + location.setZ(20.0); //TGT = 20 OBS = 50 + TGTespdu.setEntityLocation(location); + int timestamp = disTime.getDisAbsoluteTimestamp(); + TGTespdu.setTimestamp(timestamp); + sender.run(TGTespdu); //sends inital here I am and who I am + + //other player to look out for: + EntityID FDCEntityID = new EntityID(); + FDCEntityID.setEntity(1); + FDCEntityID.setApplication(1); + FDCEntityID.setSite(1); + + EntityID OBSEntityID = new EntityID(); + OBSEntityID.setEntity(2); + OBSEntityID.setApplication(1); + OBSEntityID.setSite(1); + + /* BELOW IS THE RECIEVE CODE // + // // + // // + */ // + PduFactory factory; + MulticastSocket socket = null; + InetAddress address = null; + DatagramPacket packet; + short currentPduType; //will use the curentPduType as the check for sending other packets. + + try { + // TODO: Change the line below to make sense for each class + System.out.println("Russian T72 out on the prowl...\n\n"); + socket = new MulticastSocket(MULTICAST_PORT); + address = InetAddress.getByName(MULTICAST_GROUP); + 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); + // + //TODO: NEED IF STATEMENT IF THE SENDER IS THIS CLASS TO DELETE. + // + + String marking2 = new String(); + Pdu pdu = factory.createPdu(packet.getData()); + currentPduType = pdu.getPduType(); + if (currentPduType == 14) //stop/freeze PDU + { + System.out.println("recieved Stop/Freeze packet..."); + return; + } +// pdu.setExerciseID((short)5); + if (pdu != null) { + if (sentBufferList.contains(pdu.getTimestamp())) { + pdu = null; + } + if (pdu != null) { + + String currentPduTypeName = pdu.getClass().getName(); + if (currentPduType == 1) { + EntityStatePdu pdu2 = (EntityStatePdu) pdu; + marking2 = pdu2.getMarking().getCharactersString(); + } +//Keep adding any if statements as needed for the class you are building. + StringBuilder message = new StringBuilder(); + message.append("received DIS PDU: "); + message.append("pduType "); + if (currentPduType < 10) { + message.append(" "); + } + message.append(currentPduType).append(" ").append(currentPduTypeName); + message.append(" "); + message.append(marking2); + System.out.println(message.toString()); + //Reference for PDU Types: + // http://faculty.nps.edu/brutzman/vrtp/mil/navy/nps/disEnumerations/JdbeHtmlFiles/pdu/8.htm + // + + + if (currentPduType == 2) //FirePDU + { + DetonationPdu det = new DetonationPdu(); + det.setExerciseID((short) 1); + det.setDetonationResult((short)1); + timestamp = disTime.getDisAbsoluteTimestamp(); + det.setTimestamp(timestamp); + sender.run(det); + } + + } else { + System.out.println("received packet but pdu is null and originated from Target. Still doing sketchy Russian things..."); + } + } + } + } catch (IOException e) { + System.out.println("Problem with Target.PduReceiver, see exception trace:"); + System.out.println(e); + } finally { + System.out.println("Target.PduReceiver complete. - T-72 DESTROYED!"); + } + + } + +} diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Demchko/DemchkoServer.java b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Demchko/DemchkoServer.java index 8cf008e867d34268c2891a008fad2a9faab8ef7f..7e2fcbbe2c330b535efaaeae4c7a089b2ae4414c 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Demchko/DemchkoServer.java +++ b/deliverables/src/MV3500Cohort2018JulySeptember/homework2/Demchko/DemchkoServer.java @@ -55,7 +55,7 @@ public class DemchkoServer { // // Why is the first IP/port the same, while the second set has // different ports? - System.out.println("Socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " + System.out.println("Socket pair: (( " + localAddress.toString().trim() + ", " + localPort + " ), ( " + remoteAddress.toString() + ", " + remotePort + " ))"); InputStream is = clientConnection.getInputStream(); diff --git a/nbproject/project.xml b/nbproject/project.xml index 31f5e6a0c33e82537c0c0fecf00a562224caea20..02ebbf617cd659e035e70e2c2bdeab7f956b8a9f 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -1,61 +1,61 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://www.netbeans.org/ns/project/1"> - <type>org.netbeans.modules.ant.freeform</type> - <configuration> - <general-data xmlns="http://www.netbeans.org/ns/freeform-project/1"> - <name>Networked Graphics MV3500</name> - </general-data> - <general-data xmlns="http://www.netbeans.org/ns/freeform-project/2"> +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://www.netbeans.org/ns/project/1"> + <type>org.netbeans.modules.ant.freeform</type> + <configuration> + <general-data xmlns="http://www.netbeans.org/ns/freeform-project/1"> + <name>Networked Graphics MV3500</name> + </general-data> + <general-data xmlns="http://www.netbeans.org/ns/freeform-project/2"> <!-- Do not use Project Properties customizer when editing this file manually. To prevent the customizer from showing, create nbproject/project.properties file and enter auxiliary.show.customizer=false property there. Adding auxiliary.show.customizer.message=<message> - will show your customized message when someone attempts to open the customizer. --> - <name>Networked Graphics MV3500</name> - <properties/> - <folders> - <source-folder> - <label>Networked Graphics MV3500</label> - <location>.</location> - <encoding>windows-1252</encoding> - </source-folder> - <source-folder> - <label>lib</label> - <type>java</type> - <location>lib</location> - <encoding>windows-1252</encoding> - </source-folder> - </folders> - <ide-actions/> - <view> - <items> - <source-folder style="packages"> - <label>lib</label> - <location>lib</location> - </source-folder> - <source-file> - <location>build.xml</location> - </source-file> - </items> - <context-menu/> - </view> - <subprojects/> - </general-data> - <java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/1"> - <compilation-unit> - <package-root>lib</package-root> - <source-level>1.5</source-level> - </compilation-unit> - </java-data> - <spellchecker-wordlist xmlns="http://www.netbeans.org/ns/spellchecker-wordlist/1"> - <word>codebases</word> - <word>DIS</word> - <word>integrators</word> - <word>interoperability</word> - <word>interoperable</word> - <word>TENA</word> - <word>Wikipedia</word> - </spellchecker-wordlist> - </configuration> -</project> + will show your customized message when someone attempts to open the customizer. --> + <name>Networked Graphics MV3500</name> + <properties/> + <folders> + <source-folder> + <label>Networked Graphics MV3500</label> + <location>.</location> + <encoding>windows-1252</encoding> + </source-folder> + <source-folder> + <label>lib</label> + <type>java</type> + <location>lib</location> + <encoding>windows-1252</encoding> + </source-folder> + </folders> + <ide-actions/> + <view> + <items> + <source-folder style="packages"> + <label>lib</label> + <location>lib</location> + </source-folder> + <source-file> + <location>build.xml</location> + </source-file> + </items> + <context-menu/> + </view> + <subprojects/> + </general-data> + <java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/1"> + <compilation-unit> + <package-root>lib</package-root> + <source-level>1.5</source-level> + </compilation-unit> + </java-data> + <spellchecker-wordlist xmlns="http://www.netbeans.org/ns/spellchecker-wordlist/1"> + <word>codebases</word> + <word>DIS</word> + <word>integrators</word> + <word>interoperability</word> + <word>interoperable</word> + <word>TENA</word> + <word>Wikipedia</word> + </spellchecker-wordlist> + </configuration> +</project>