diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework2/Furr/FurrTcpClient.java b/assignments/src/MV3500Cohort2018JulySeptember/homework2/Furr/FurrTcpClient.java index 3dcd83e8e577ad6e9d7eb10257948eab7fc32725..9563f2412e7c353c7f7fbaa9494119f28cb2eb8d 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework2/Furr/FurrTcpClient.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework2/Furr/FurrTcpClient.java @@ -13,8 +13,11 @@ import java.util.Scanner; */ public class FurrTcpClient { + /** socket value of shared interest */ public final static String LOCALHOST = "0:0:0:0:0:0:0:1"; // String constant, i.e. 127.0.0.1 + /** run the program + * @param args unused string parameters */ public static void main(String[] args) { boolean openConnection = true; try { diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework2/Furr/FurrTcpServer.java b/assignments/src/MV3500Cohort2018JulySeptember/homework2/Furr/FurrTcpServer.java index bd46de4f22742b7ed62b7258e6bd4ac14a1bc807..4ada54ae29817d015f0da67b2f7bedc7132924f8 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework2/Furr/FurrTcpServer.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework2/Furr/FurrTcpServer.java @@ -20,6 +20,8 @@ import java.net.*; */ public class FurrTcpServer { + /** run the program + * @param args unused string parameters */ public static void main(String[] args) throws IOException { String[] responses = new String[10]; //canned responses for multiple inputs from client diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework3/Furr_Frisco_Homework3/FurrFriscoHw3Receiver.java b/assignments/src/MV3500Cohort2018JulySeptember/homework3/Furr_Frisco_Homework3/FurrFriscoHw3Receiver.java index 090d33d844cf98aaf320cc6056fe48ee2c435e76..5ad03fb94308d775f8e1526d08b3981a8bdfabaa 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework3/Furr_Frisco_Homework3/FurrFriscoHw3Receiver.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework3/Furr_Frisco_Homework3/FurrFriscoHw3Receiver.java @@ -18,11 +18,15 @@ import java.net.MulticastSocket; */ public class FurrFriscoHw3Receiver { + /** socket value of shared interest */ public static final String MULTICAST_ADDRESS = "239.1.2.15"; + /** socket value of shared interest */ public static final int DESTINATION_PORT = 1717; /** How many routers can be crossed */ public static final int TTL = 10; + /** run the program + * @param args unused string parameters */ public static void main(String[] args) { try diff --git a/assignments/src/MV3500Cohort2018JulySeptember/homework3/Furr_Frisco_Homework3/FurrFriscoHw3Sender.java b/assignments/src/MV3500Cohort2018JulySeptember/homework3/Furr_Frisco_Homework3/FurrFriscoHw3Sender.java index ef5371d8982eaac0afea420fcd36a7ae0ab0fff9..f8aa17e06e3d531342dcdc497bb4d07c831ded09 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/homework3/Furr_Frisco_Homework3/FurrFriscoHw3Sender.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/homework3/Furr_Frisco_Homework3/FurrFriscoHw3Sender.java @@ -15,14 +15,19 @@ import java.util.Random; */ public class FurrFriscoHw3Sender { + /** socket value of shared interest */ public static final String MULTICAST_ADDRESS = "239.1.2.15"; + /** socket value of shared interest */ public static final int DESTINATION_PORT = 1717; /** * How many routers can be crossed */ public static final int TTL = 10; - public static void main(String[] args) { + /** run the program + * @param args unused string parameters */ + public static void main(String[] args) + { try { System.setProperty("java.net.preferIPv4Stack", "true"); diff --git a/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/TGTSendRecieve.java b/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/TGTSendReceive.java similarity index 94% rename from assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/TGTSendRecieve.java rename to assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/TGTSendReceive.java index 82eb78be710da7d2ad215f1adaaffe2a9079bd34..881c158c804ecbb5515b56ada141e94836bdf960 100644 --- a/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/TGTSendRecieve.java +++ b/assignments/src/MV3500Cohort2018JulySeptember/projects/FriscoFurr/TGTSendReceive.java @@ -1,261 +1,263 @@ -package MV3500Cohort2018JulySeptember.projects.FriscoFurr; - -import java.net.*; -import java.io.*; -import java.util.*; -import edu.nps.moves.dis.*; // OpenDIS version 4 -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; - - /** - * Constructor just got to construct. - * @param port - * @param multicast - */ - 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); - } - } - - /** - * This would be the sending Run method. Takes in several PDUs and for each one has a switch statement ready for it. - * @param pdupass PDU passed - * @throws UnknownHostException unable to reach host address - * @throws IOException input-output error - */ - 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("Target Sent PDU of type " + aPdu.getClass().getName() + "\n"); - } - } - - /** - * Main function takes no specific arguments, but is the recieving portion of the code. Once it hears a specific type of PDU it creates another and sends it to the Run function - * called sender created on line 135 (2nd statement in the main function) - * @param args command-line arguments - * @throws IOException input-output error - */ - 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); - 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 { - 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); - - 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; - } - 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 == 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!"); - } - - } - -} +package MV3500Cohort2018JulySeptember.projects.FriscoFurr; + +import java.net.*; +import java.io.*; +import java.util.*; +import edu.nps.moves.dis.*; // OpenDIS version 4 +import java.io.IOException; +import edu.nps.moves.disutil.PduFactory; +import edu.nps.moves.disutil.DisTime; + +public class TGTSendReceive +{ + /** + * 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; + + /** socket value of shared interest */ + public static final int MULTICAST_PORT = 3000; + /** socket value of shared interest */ + public static final String MULTICAST_GROUP = "239.1.2.3"; + private static final boolean USE_FAST_ESPDU = false; + private long[] sentBuffer = new long[100]; + private static List sentBufferList; + DisTime disTime = DisTime.getInstance(); + int transmission = 1; + + /** + * Constructor just got to construct. + * @param port + * @param multicast + */ + public TGTSendReceive(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); + } + } + + /** + * This would be the sending Run method. Takes in several PDUs and for each one has a switch statement ready for it. + * @param pdupass PDU passed + * @throws UnknownHostException unable to reach host address + * @throws IOException input-output error + */ + 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("Target Sent PDU of type " + aPdu.getClass().getName() + "\n"); + } + } + + /** + * Main function takes no specific arguments, but is the recieving portion of the code. Once it hears a specific type of PDU it creates another and sends it to the Run function + * called sender created on line 135 (2nd statement in the main function) + * @param args command-line arguments + * @throws IOException input-output error + */ + 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: + // + TGTSendReceive sender = new TGTSendReceive(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); + 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 { + 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); + + 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; + } + 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 == 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!"); + } + + } + +}