diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FDCSendRecieve.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FDCSendRecieve.java index 9c1c9ae3393b89a5622c21cf1628313afe8dbd68..ee9b1ad5a0ee25c2a1e2a7c8c49505a476d45fab 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FDCSendRecieve.java +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FDCSendRecieve.java @@ -6,7 +6,7 @@ import java.util.*; import edu.nps.moves.dis.*; import java.io.IOException; import edu.nps.moves.disutil.PduFactory; -import java.sql.Timestamp; +import edu.nps.moves.disutil.DisTime; public class FDCSendRecieve { @@ -26,11 +26,12 @@ public class FDCSendRecieve { 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 List<long> sentBufferList; - + 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); @@ -42,100 +43,97 @@ public class FDCSendRecieve { } } - public void run(Pdu pdu) { - if(sentBuffer.) + public void run(Pdu... pdupass) throws UnknownHostException, IOException { + + List<Pdu> generatedPdus = new ArrayList<>(); + Pdu aPdu = null; System.out.println("FDC Sender started..."); - short currentPduType = pdu.getPduType(); - System.out.println("in sender, recived PDU type: "+currentPduType); + // 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); // String currentPduTypeName = pdu.getClass().getName(); // short currentProtocolFamilyID = pdu.getProtocolFamily(); // String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName(); - 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. - - Pdu aPdu = null; - 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.* - { + //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: - System.out.println("Case: Enitity_State " + pdu + "\n"); - aPdu = new EntityStatePdu(); - EntityStatePdu espdu = (EntityStatePdu) aPdu; - Marking marking = new Marking(); - marking.setCharactersString("PduSender"); - espdu.setMarking(marking); - Vector3Double espduLocation = new Vector3Double(); - espduLocation.setX(1.0); - espduLocation.setY(2.0); - espduLocation.setZ(3.0); - espdu.setTimestamp(System.currentTimeMillis()); - break; + case 1: //ENTITY_STATE: + aPdu = pdu; + break; // case COMMENT: // aPdu = new CommentPdu(); // break; // -// case FIRE: -// aPdu = new FirePdu(); -// break; + case 2: //FIRE + aPdu = pdu; + break; // // case DETONATION: // aPdu = new DetonationPdu(); // break; // -// case ACKNOWLEDGE: -// aPdu = new AcknowledgePdu(); -// break; + case 15: //AcknowledgePdu + aPdu = pdu; + break; // - case 16: //ACTION_REQUEST: - aPdu = new ActionRequestPdu(); - break; - - default: - //add some shit that makes sense here. - 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()); - } - - - // 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; - - 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(); - System.out.println("Sent PDU of type " + aPdu.getClass().getName()); +// case 16: //ACTION_REQUEST: +// aPdu = new ActionRequestPdu(); +// break; + + case 17: + 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, created or sent "); + System.out.println(); } - } catch (IOException e) { - System.out.println(e); + 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("Sent PDU of type " + aPdu.getClass().getName()); } } - public static void main(String[] args) { - + 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: @@ -148,20 +146,23 @@ public class FDCSendRecieve { // 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(); + // sender.run(); // } - + // // Inital Hello world from entity: // - - FDCSendRecieve sender = new FDCSendRecieve(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); //initalize the sender + FDCSendRecieve sender = new FDCSendRecieve(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); //initalize the sender + EntityStatePdu FDCespdu = new EntityStatePdu(); - FDCespdu.setExerciseID((short)1); - EntityID entityID = FDCespdu.getEntityID(); - entityID.setSite(1); // 0 is apparently not a valid site number, per the spec - entityID.setApplication(1); - entityID.setEntity(1); //change for each person I think??? - JMF + 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 @@ -178,9 +179,11 @@ public class FDCSendRecieve { location.setY(0.0); //TGT = 150 OBS = 75 location.setZ(10.0); //TGT = 20 OBS = 50 FDCespdu.setEntityLocation(location); - FDCespdu.setTimestamp(System.currentTimeMillis()); - //sender.run(FDCespdu); //sends inital here I am and who I am - + int timestamp = disTime.getDisAbsoluteTimestamp(); + FDCespdu.setTimestamp(timestamp); + //FDCespdu.setTimestamp(System.currentTimeMillis()); + sender.run(FDCespdu); //sends inital here I am and who I am + /* BELOW IS THE RECIEVE CODE // // // // // @@ -191,10 +194,9 @@ public class FDCSendRecieve { 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("FDC is alive and ready to recieve fire missions..."); + 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); @@ -211,54 +213,99 @@ public class FDCSendRecieve { // //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) { - currentPduType = pdu.getPduType(); - - String currentPduTypeName = pdu.getClass().getName(); - short currentProtocolFamilyID = pdu.getProtocolFamily(); - String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName(); - - //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(); - PduEntityType.setCountry(225); - if(PduEntityType.getCountry()==222){ - //do something for the OBS as this is a russian asshat. Most likely send the pdu with sender.run(pdu); - System.out.println("got a russian SOB!"); - } + if (sentBufferList.contains(pdu.getTimestamp())) { + pdu = null; } - EntityID OBSEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below - - if(currentPduType == 16) //Action request - { - ActionRequestPdu actionPdu = (ActionRequestPdu) pdu; - if(actionPdu.getOriginatingEntityID() == OBSEntityID) - { - sender.run(pdu); + if (pdu != null) { + + String currentPduTypeName = pdu.getClass().getName(); + short currentProtocolFamilyID = pdu.getProtocolFamily(); + String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName(); + 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) { +//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) { + //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); + System.out.println("got a russian SOB!"); + } + } + 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); + + if (currentPduType == 16) //Action request + { + ActionResponsePdu response = new ActionResponsePdu(); + response.setExerciseID((short) 1); + response.setRequestID((long) 1); + timestamp = disTime.getDisAbsoluteTimestamp(); + response.setTimestamp(timestamp); + FirePdu fire = new FirePdu(); + fire.setExerciseID((short) 1); + fire.setFireMissionIndex(1000); + fire.setFiringEntityID(FDCID); + fire.setTargetEntityID(TGTEntityID); + timestamp = disTime.getDisAbsoluteTimestamp(); + fire.setTimestamp(timestamp); + sender.run(response, 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..."); } - message.append(currentPduType).append(" ").append(currentPduTypeName); - message.append(", protocolFamily ").append(currentProtocolFamilyID); - message.append(" ").append(currentPduFamilyName); - System.out.println(message.toString()); - - } else { - System.out.println("received packet but pdu is null, packet.getData().length=" + packet.getData().length + ", error..."); } } } catch (IOException e) { diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FFTestEspduSender.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FFTestEspduSender.java index c3e1b7a98123bd9f339c4a2bee622ecfbb7f4bf7..2e8812b43aa128f393368269d6698ac65f7242e5 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FFTestEspduSender.java +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FFTestEspduSender.java @@ -230,7 +230,7 @@ public class FFTestEspduSender { espdu.marshal(dos); FirePdu fire = new FirePdu(); - fire.set + //fire.set byte[] fireArray = fire.marshal(); // The byte array here is the packet in DIS format. We put that into a diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FriscoFurrPduSender.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FriscoFurrPduSender.java index 4676bd681dc444db150e020813026ebed8a1d6cb..da1ae8774512d70e3890e0adc25c5cfedceb072f 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FriscoFurrPduSender.java +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FriscoFurrPduSender.java @@ -8,6 +8,7 @@ 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. @@ -57,29 +58,53 @@ public class FriscoFurrPduSender 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("PduSender"); - 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(); -// break; -// +// 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(); // break; @@ -134,6 +159,12 @@ public class FriscoFurrPduSender // // 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: diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/OBSSendRecieve1.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/OBSSendRecieve1.java new file mode 100644 index 0000000000000000000000000000000000000000..dd2075ef3e811c64c8aa040a0ad5d57feb379e3e --- /dev/null +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/OBSSendRecieve1.java @@ -0,0 +1,320 @@ +package MV3500Cohort2018JulySeptember.FinalProject.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(); + + 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; + System.out.println("FDC 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); +// 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 17: + 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, 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("Sent PDU of type " + aPdu.getClass().getName()); + } + } + + 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 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); + //FDCespdu.setTimestamp(System.currentTimeMillis()); + sender.run(FDCespdu); //sends inital here I am and who I am + + /* 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("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); + // + //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(); + short currentProtocolFamilyID = pdu.getProtocolFamily(); + String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName(); + 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) { + //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); + System.out.println("got a russian SOB!"); + } + } + 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); + + if (currentPduType == 16) //Action request + { + ActionResponsePdu response = new ActionResponsePdu(); + response.setExerciseID((short) 1); + response.setRequestID((long) 1); + timestamp = disTime.getDisAbsoluteTimestamp(); + response.setTimestamp(timestamp); + FirePdu fire = new FirePdu(); + fire.setExerciseID((short) 1); + fire.setFireMissionIndex(1000); + fire.setFiringEntityID(FDCID); + fire.setTargetEntityID(TGTEntityID); + timestamp = disTime.getDisAbsoluteTimestamp(); + fire.setTimestamp(timestamp); + sender.run(response, 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/FinalProject/FriscoFurrProject/TGTSendRecieve1.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/TGTSendRecieve1.java new file mode 100644 index 0000000000000000000000000000000000000000..41fd8f020e4e4bc00580c62eaee4dadebe578cca --- /dev/null +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/TGTSendRecieve1.java @@ -0,0 +1,320 @@ +package MV3500Cohort2018JulySeptember.FinalProject.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 TGTSendRecieve1 { + + /** + * 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 TGTSendRecieve1(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("FDC 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); +// 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 17: + 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, 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("Sent PDU of type " + aPdu.getClass().getName()); + } + } + + 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: + // + TGTSendRecieve1 sender = new TGTSendRecieve1(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); + //FDCespdu.setTimestamp(System.currentTimeMillis()); + sender.run(FDCespdu); //sends inital here I am and who I am + + /* 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("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); + // + //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(); + short currentProtocolFamilyID = pdu.getProtocolFamily(); + String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName(); + 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) { + //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); + System.out.println("got a russian SOB!"); + } + } + 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); + + if (currentPduType == 16) //Action request + { + ActionResponsePdu response = new ActionResponsePdu(); + response.setExerciseID((short) 1); + response.setRequestID((long) 1); + timestamp = disTime.getDisAbsoluteTimestamp(); + response.setTimestamp(timestamp); + FirePdu fire = new FirePdu(); + fire.setExerciseID((short) 1); + fire.setFireMissionIndex(1000); + fire.setFiringEntityID(FDCID); + fire.setTargetEntityID(TGTEntityID); + timestamp = disTime.getDisAbsoluteTimestamp(); + fire.setTimestamp(timestamp); + sender.run(response, 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!"); + } + + } + +}