diff --git a/projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/ABEspduReceiverAtoTCP.java b/projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/ABEspduReceiverAtoTCP.java deleted file mode 100644 index 4e16f4c5a5ba326843c1e52725bcacf99c7d009b..0000000000000000000000000000000000000000 --- a/projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/ABEspduReceiverAtoTCP.java +++ /dev/null @@ -1,103 +0,0 @@ - -import java.net.*; -import java.util.*; - -import edu.nps.moves.disutil.*; -import edu.nps.moves.dis.*; -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.OutputStream; -import java.io.PrintStream; - -/** - * Receives PDUs from the network in IEEE format. - * - * @author Angelopoulos/Blankenbeker - * @version 8 MAR 2018 - */ -public class ABEspduReceiverAtoTCP { - - public static final String TCP_DESTINATION_IP = "172.20.146.111"; - public static final int DIS_DESTINATION_PORT = 3000; - public static final int TCP_DESTINATION_PORT = 2999; - public static final int MAX_PDU_SIZE = 8192; - public static final String GROUP = "239.1.2.4"; - - public static void main(String args[]) { - MulticastSocket socket; - DatagramPacket packet; - InetAddress address; - PduFactory pduFactory = new PduFactory(); - try { - // Specify the socket to receive data - socket = new MulticastSocket(DIS_DESTINATION_PORT); - socket.setBroadcast(true); - - address = InetAddress.getByName(GROUP); - socket.joinGroup(address); - - //System.out.println("Joined Group."); - // Loop infinitely, receiving datagrams - while (true) { - try - { - - byte buffer[] = new byte[MAX_PDU_SIZE]; - packet = new DatagramPacket(buffer, buffer.length); - - socket.receive(packet); - //System.out.println("Packet Received"); - - List<Pdu> pduBundle = pduFactory.getPdusFromBundle(packet.getData()); - //System.out.println("Bundle size is " + pduBundle.size()); - - Iterator it = pduBundle.iterator(); - - while(it.hasNext()) - { - Pdu aPdu = (Pdu)it.next(); - - // System.out.print("got PDU of type: " + aPdu.getClass().getName()); - if(aPdu instanceof EntityStatePdu) - { - - EntityID eid = ((EntityStatePdu)aPdu).getEntityID(); - if (eid.getSite() == 100) - { - // Create TCP Bridge - Socket clientConnection = new Socket(TCP_DESTINATION_IP, TCP_DESTINATION_PORT); - OutputStream os = clientConnection.getOutputStream(); - PrintStream ps = new PrintStream(os); - System.out.println("Alpha Bridging Complete to: " + TCP_DESTINATION_IP); - EntityType entityType = ((EntityStatePdu)aPdu).getEntityType(); - ps.println(eid.getSite()); - ps.println(eid.getApplication()); - ps.println(eid.getEntity()); - ps.println(entityType.getEntityKind()); // Platform (vs lifeform, munition, sensor, etc.) - ps.println(entityType.getCountry()); // USA - ps.println(entityType.getDomain()); // Land (vs air, surface, subsurface, space) - ps.println(entityType.getCategory()); // Tank - ps.println(entityType.getSubcategory()); // M1 Abrams - ps.println(entityType.getSpec()); // M1A2 Abrams - - } - Vector3Double location = ((EntityStatePdu)aPdu).getEntityLocation(); - System.out.print(" EID:[" + eid.getSite() + ", " + eid.getApplication() + ", " + eid.getEntity() + "] "); - //System.out.print(" Location in DIS coordinates: [" + location.getX() + ", " + location.getY() + ", " + location.getZ() + "]"); - double c[] = {location.getX(), location.getY(), location.getZ()}; - double lla[] = CoordinateConversions.xyzToLatLonDegrees(c); - System.out.println(" Location (lat/lon/alt): [" + lla[0] + ", " + lla[1] + ", " + lla[2] + "]"); - } - System.out.println(); - } // end trop through PDU bundle - } - catch (Exception e) { - System.out.println(e); - } - } // end while - } // End try - catch (Exception e) { - System.out.println(e); - } - } // end main -} // end class diff --git a/projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/ABEspduReceiverBtoTCP.java b/projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/ABEspduReceiverBtoTCP.java deleted file mode 100644 index 4004eb38d27d97e17315aac10e3b73c9041b5a90..0000000000000000000000000000000000000000 --- a/projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/ABEspduReceiverBtoTCP.java +++ /dev/null @@ -1,95 +0,0 @@ - -import java.net.*; -import java.util.*; - -import edu.nps.moves.disutil.*; -import edu.nps.moves.dis.*; -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.OutputStream; -import java.io.PrintStream; - -/** - * Receives PDUs from the network in IEEE format. - * - * @author Angelopoulos/Blankenbeker - * @version 8 MAR 2018 - */ -public class ABEspduReceiverBtoTCP { - - public static final String TCP_DESTINATION_IP = "172.20.144.187"; - public static final int DIS_DESTINATION_PORT = 2800; - public static final int TCP_DESTINATION_PORT = 2998; - public static final int MAX_PDU_SIZE = 8192; - public static final String GROUP = "239.1.2.3"; - public static void main(String args[]) { - MulticastSocket socket; - DatagramPacket packet; - InetAddress address; - PduFactory pduFactory = new PduFactory(); - - try { - - // Specify the socket to receive data - socket = new MulticastSocket(DIS_DESTINATION_PORT); - socket.setBroadcast(true); - address = InetAddress.getByName(GROUP); - socket.joinGroup(address); - //System.out.println("Joined Group."); - // Loop infinitely, receiving datagrams - while (true) { - try{ - byte buffer[] = new byte[MAX_PDU_SIZE]; - packet = new DatagramPacket(buffer, buffer.length); - socket.receive(packet); - //System.out.println("Packet Received"); - List<Pdu> pduBundle = pduFactory.getPdusFromBundle(packet.getData()); - //System.out.println("Bundle size is " + pduBundle.size()); - Iterator it = pduBundle.iterator(); - - while(it.hasNext()){ - Pdu aPdu = (Pdu)it.next(); - //System.out.print("got PDU of type: " + aPdu.getClass().getName()); - if(aPdu instanceof EntityStatePdu){ - EntityID eid = ((EntityStatePdu)aPdu).getEntityID(); - if (eid.getSite() == 200){ - // Create TCP Bridge - Socket clientConnection = new Socket(TCP_DESTINATION_IP, TCP_DESTINATION_PORT); - OutputStream os = clientConnection.getOutputStream(); - PrintStream ps = new PrintStream(os); - - System.out.println("Bravo briding complete to: "+ TCP_DESTINATION_IP); - EntityType entityType = ((EntityStatePdu)aPdu).getEntityType(); - ps.println(eid.getSite()); - ps.println(eid.getApplication()); - ps.println(eid.getEntity()); - ps.println(entityType.getEntityKind()); // Platform (vs lifeform, munition, sensor, etc.) - ps.println(entityType.getCountry()); // USA - ps.println(entityType.getDomain()); // Land (vs air, surface, subsurface, space) - ps.println(entityType.getCategory()); // Tank - ps.println(entityType.getSubcategory()); // M1 Abrams - ps.println(entityType.getSpec()); // M1A2 Abrams - - - } - Vector3Double location = ((EntityStatePdu)aPdu).getEntityLocation(); - System.out.print(" EID:[" + eid.getSite() + ", " + eid.getApplication() + ", " + eid.getEntity() + "] "); - //System.out.print(" Location in DIS coordinates: [" + location.getX() + ", " + location.getY() + ", " + position.getZ() + "]"); - double c[] = {location.getX(), location.getY(), location.getZ()}; - double lla[] = CoordinateConversions.xyzToLatLonDegrees(c); - System.out.println(" Location (lat/lon/alt): [" + lla[0] + ", " + lla[1] + ", " + lla[2] + "]"); - } - System.out.println(); - } // end trop through PDU bundle - } - catch (Exception e) { - System.out.println(e); - } - } // end while - } // End try - catch (Exception e) { - System.out.println(e); - } - - } // end main -} // end class diff --git a/projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/AngelBlankEspduReceiverAtoTCP.java b/projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/AngelBlankEspduReceiverAtoTCP.java deleted file mode 100644 index bd5488fadfb731d1d15c754e4b108d890454925c..0000000000000000000000000000000000000000 --- a/projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/AngelBlankEspduReceiverAtoTCP.java +++ /dev/null @@ -1,104 +0,0 @@ - -import java.net.*; -import java.util.*; - -import edu.nps.moves.disutil.*; -import edu.nps.moves.dis.*; -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.OutputStream; -import java.io.PrintStream; - -/** - * Receives PDUs from the network creates a TCP connection, then - * sends information to through the connection. - * - * @author Angelopoulos/Blankenbeker - * @version 8 MAR 2018 - */ -public class AngelBlankEspduReceiverAtoTCP { - - public static final String TCP_DESTINATION_IP = "172.20.146.111"; - public static final int DIS_DESTINATION_PORT = 3000; - public static final int TCP_DESTINATION_PORT = 2999; - public static final int MAX_PDU_SIZE = 8192; - public static final String GROUP = "239.1.2.4"; - - public static void main(String args[]) { - MulticastSocket socket; - DatagramPacket packet; - InetAddress address; - PduFactory pduFactory = new PduFactory(); - try { - // Specify the socket to receive data - socket = new MulticastSocket(DIS_DESTINATION_PORT); - socket.setBroadcast(true); - - address = InetAddress.getByName(GROUP); - socket.joinGroup(address); - - //System.out.println("Joined Group."); - // Loop infinitely, receiving datagrams - while (true) { - try - { - - byte buffer[] = new byte[MAX_PDU_SIZE]; - packet = new DatagramPacket(buffer, buffer.length); - - socket.receive(packet); - //System.out.println("Packet Received"); - - List<Pdu> pduBundle = pduFactory.getPdusFromBundle(packet.getData()); - //System.out.println("Bundle size is " + pduBundle.size()); - - Iterator it = pduBundle.iterator(); - - while(it.hasNext()) - { - Pdu aPdu = (Pdu)it.next(); - - // System.out.print("got PDU of type: " + aPdu.getClass().getName()); - if(aPdu instanceof EntityStatePdu) - { - - EntityID eid = ((EntityStatePdu)aPdu).getEntityID(); - if (eid.getSite() == 100) - { - // Create TCP Bridge - Socket clientConnection = new Socket(TCP_DESTINATION_IP, TCP_DESTINATION_PORT); - OutputStream os = clientConnection.getOutputStream(); - PrintStream ps = new PrintStream(os); - System.out.println("Alpha Bridging Complete to: " + TCP_DESTINATION_IP); - EntityType entityType = ((EntityStatePdu)aPdu).getEntityType(); - ps.println(eid.getSite()); - ps.println(eid.getApplication()); - ps.println(eid.getEntity()); - ps.println(entityType.getEntityKind()); // Platform (vs lifeform, munition, sensor, etc.) - ps.println(entityType.getCountry()); // USA - ps.println(entityType.getDomain()); // Land (vs air, surface, subsurface, space) - ps.println(entityType.getCategory()); // Tank - ps.println(entityType.getSubcategory()); // M1 Abrams - ps.println(entityType.getSpec()); // M1A2 Abrams - - } - Vector3Double location = ((EntityStatePdu)aPdu).getEntityLocation(); - System.out.print(" EID:[" + eid.getSite() + ", " + eid.getApplication() + ", " + eid.getEntity() + "] "); - //System.out.print(" Location in DIS coordinates: [" + location.getX() + ", " + location.getY() + ", " + location.getZ() + "]"); - double c[] = {location.getX(), location.getY(), location.getZ()}; - double lla[] = CoordinateConversions.xyzToLatLonDegrees(c); - System.out.println(" Location (lat/lon/alt): [" + lla[0] + ", " + lla[1] + ", " + lla[2] + "]"); - } - System.out.println(); - } // end trop through PDU bundle - } - catch (Exception e) { - System.out.println(e); - } - } // end while - } // End try - catch (Exception e) { - System.out.println(e); - } - } // end main -} // end class diff --git a/projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/AngelBlankEspduReceiverBtoTCP.java b/projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/AngelBlankEspduReceiverBtoTCP.java deleted file mode 100644 index 9c700b09436193b25bcf49c4da4b283a44c7a0e8..0000000000000000000000000000000000000000 --- a/projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/AngelBlankEspduReceiverBtoTCP.java +++ /dev/null @@ -1,96 +0,0 @@ - -import java.net.*; -import java.util.*; - -import edu.nps.moves.disutil.*; -import edu.nps.moves.dis.*; -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.OutputStream; -import java.io.PrintStream; - -/** - * Receives PDUs from the network in IEEE format and creates a TCP connection, - * then sends information through the connection. - * - * @author Angelopoulos/Blankenbeker - * @version 8 MAR 2018 - */ -public class AngelBlankEspduReceiverBtoTCP { - - public static final String TCP_DESTINATION_IP = "172.20.144.187"; - public static final int DIS_DESTINATION_PORT = 2800; - public static final int TCP_DESTINATION_PORT = 2998; - public static final int MAX_PDU_SIZE = 8192; - public static final String GROUP = "239.1.2.3"; - public static void main(String args[]) { - MulticastSocket socket; - DatagramPacket packet; - InetAddress address; - PduFactory pduFactory = new PduFactory(); - - try { - - // Specify the socket to receive data - socket = new MulticastSocket(DIS_DESTINATION_PORT); - socket.setBroadcast(true); - address = InetAddress.getByName(GROUP); - socket.joinGroup(address); - //System.out.println("Joined Group."); - // Loop infinitely, receiving datagrams - while (true) { - try{ - byte buffer[] = new byte[MAX_PDU_SIZE]; - packet = new DatagramPacket(buffer, buffer.length); - socket.receive(packet); - //System.out.println("Packet Received"); - List<Pdu> pduBundle = pduFactory.getPdusFromBundle(packet.getData()); - //System.out.println("Bundle size is " + pduBundle.size()); - Iterator it = pduBundle.iterator(); - - while(it.hasNext()){ - Pdu aPdu = (Pdu)it.next(); - //System.out.print("got PDU of type: " + aPdu.getClass().getName()); - if(aPdu instanceof EntityStatePdu){ - EntityID eid = ((EntityStatePdu)aPdu).getEntityID(); - if (eid.getSite() == 200){ - // Create TCP Bridge - Socket clientConnection = new Socket(TCP_DESTINATION_IP, TCP_DESTINATION_PORT); - OutputStream os = clientConnection.getOutputStream(); - PrintStream ps = new PrintStream(os); - - System.out.println("Bravo briding complete to: "+ TCP_DESTINATION_IP); - EntityType entityType = ((EntityStatePdu)aPdu).getEntityType(); - ps.println(eid.getSite()); - ps.println(eid.getApplication()); - ps.println(eid.getEntity()); - ps.println(entityType.getEntityKind()); // Platform (vs lifeform, munition, sensor, etc.) - ps.println(entityType.getCountry()); // USA - ps.println(entityType.getDomain()); // Land (vs air, surface, subsurface, space) - ps.println(entityType.getCategory()); // Tank - ps.println(entityType.getSubcategory()); // M1 Abrams - ps.println(entityType.getSpec()); // M1A2 Abrams - - - } - Vector3Double location = ((EntityStatePdu)aPdu).getEntityLocation(); - System.out.print(" EID:[" + eid.getSite() + ", " + eid.getApplication() + ", " + eid.getEntity() + "] "); - //System.out.print(" Location in DIS coordinates: [" + location.getX() + ", " + location.getY() + ", " + position.getZ() + "]"); - double c[] = {location.getX(), location.getY(), location.getZ()}; - double lla[] = CoordinateConversions.xyzToLatLonDegrees(c); - System.out.println(" Location (lat/lon/alt): [" + lla[0] + ", " + lla[1] + ", " + lla[2] + "]"); - } - System.out.println(); - } // end trop through PDU bundle - } - catch (Exception e) { - System.out.println(e); - } - } // end while - } // End try - catch (Exception e) { - System.out.println(e); - } - - } // end main -} // end class diff --git a/projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/AngelBlankEspduTCPReceiverASenderB.java b/projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/AngelBlankEspduTCPReceiverASenderB.java deleted file mode 100644 index cfee4baaf40da0d0fe962482482738094972853a..0000000000000000000000000000000000000000 --- a/projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/AngelBlankEspduTCPReceiverASenderB.java +++ /dev/null @@ -1,203 +0,0 @@ - -import java.io.*; -import java.net.*; -import java.util.*; - -import edu.nps.moves.dis.*; -import edu.nps.moves.disutil.DisTime; - -/** - * Listens for TCP connection from AngelBlankReciverBToTCP and sends ESPDU. - * - * @author Angelopoulos/Blankenbeker - * 8 MAR 2018 - */ -public class AngelBlankEspduTCPReceiverASenderB -{ - public static final int NUMBER_TO_SEND = 5000; - public enum NetworkMode{UNICAST, MULTICAST, BROADCAST}; - /** default multicast group we send on */ - public static final String DEFAULT_MULTICAST_GROUP="239.1.2.3"; - public static final int TCP_DESTINATION_PORT = 2999; - /** Port we send on */ - public static final int DIS_DESTINATION_PORT = 2800; -/** Possible system properties, passed in via -Dattr=val - * networkMode: unicast, broadcast, multicast - * destinationIp: where to send the packet. If in multicast mode, this can be mcast. - * To determine bcast destination IP, use an online bcast address - * caclulator, for example http://www.remotemonitoringsystems.ca/broadcast.php - * If in mcast mode, a join() will be done on the mcast address. - * port: port used for both source and destination. - * @param args - */ -public static void main(String args[]) -{ - /** an entity state pdu */ - EntityStatePdu espdu = new EntityStatePdu(); - MulticastSocket socket = null; - DisTime disTime = DisTime.getInstance(); - int alternator = -1; - int port = DIS_DESTINATION_PORT; - NetworkMode mode = NetworkMode.MULTICAST; - InetAddress destinationIp = null; - try - { - destinationIp = InetAddress.getByName(DEFAULT_MULTICAST_GROUP); - } - catch(Exception e) - { - System.out.println(e + " Cannot create multicast address"); - System.exit(0); - } - Properties systemProperties = System.getProperties(); - String destinationIpString = systemProperties.getProperty("destinationIp"); - String portString = systemProperties.getProperty("port"); - String networkModeString = systemProperties.getProperty("networkMode"); // unicast or multicast or broadcast - try - { - - // Port we send to - if(portString != null) - port = Integer.parseInt(portString); - - socket = new MulticastSocket(DIS_DESTINATION_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); - - } - } // end networkModeString - } - catch(Exception e) - { - System.out.println("Unable to initialize networking. Exiting."); - System.out.println(e); - System.exit(-1); - } - - try - { - int connectionCount = 0; - ServerSocket serverSocket = new ServerSocket(TCP_DESTINATION_PORT); - - while(true){ - try - { - Socket clientConnection = serverSocket.accept(); - connectionCount++; - System.out.println("Current PDUs transferred over TCP: "+ connectionCount); - //System.out.println("RA SB received TCP connection."); - InputStream is = clientConnection.getInputStream(); - InputStreamReader isr = new InputStreamReader(is); - BufferedReader br = new BufferedReader(isr); - //System.out.println("RA SB waiting to readline."); - int entitySite = Integer.parseInt(br.readLine()); - int entityApplication = Integer.parseInt(br.readLine()); - int entityEntity = Integer.parseInt(br.readLine()); - short entityEntityKind = Short.parseShort(br.readLine()); - int entityCountry = Integer.parseInt(br.readLine()); - short entityDomain = Short.parseShort(br.readLine()); - short entityCategory = Short.parseShort(br.readLine()); - short entitySubcategory = Short.parseShort(br.readLine()); - short entitySpec = Short.parseShort(br.readLine()); - //System.out.println("RA SB reading complete."); - espdu.setExerciseID((short)1); - EntityID eid = espdu.getEntityID(); - eid.setSite(entitySite); // 0 is apparently not a valid site number, per the spec - eid.setApplication(entityApplication); - eid.setEntity(entityEntity); - EntityType entityType = espdu.getEntityType(); - entityType.setEntityKind(entityEntityKind); // Platform (vs lifeform, munition, sensor, etc.) - entityType.setCountry(entityCountry); // USA - entityType.setDomain(entityDomain); // AIR (vs air, surface, subsurface, space) - entityType.setCategory(entityCategory); // Tank - entityType.setSubcategory(entitySubcategory); // M1 Abrams - entityType.setSpec(entitySpec); // M1A2 Abrams - int ts = disTime.getDisAbsoluteTimestamp(); - espdu.setTimestamp(ts); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - espdu.marshal(dos); - // The byte array here is the packet in DIS format. We put that into a - // datagram and send it. - byte[] data = baos.toByteArray(); - DatagramPacket packet = new DatagramPacket(data, data.length, InetAddress.getByName(DEFAULT_MULTICAST_GROUP), DIS_DESTINATION_PORT); - socket.send(packet); - System.out.println(" EID=[" + eid.getSite() + "," + eid.getApplication() + "," + eid.getEntity() + "]"); - clientConnection.close(); - } - catch(Exception e) - { - System.out.println(e); - } - } - } - catch(Exception e) - { - System.out.println(e); - } - -} - - - public static Set<InetAddress> getBroadcastAddresses() - { - Set<InetAddress> bcastAddresses = new HashSet<InetAddress>(); - Enumeration interfaces; - - try - { - interfaces = NetworkInterface.getNetworkInterfaces(); - - while(interfaces.hasMoreElements()) - { - NetworkInterface anInterface = (NetworkInterface)interfaces.nextElement(); - - if(anInterface.isUp()) - { - Iterator it = anInterface.getInterfaceAddresses().iterator(); - while(it.hasNext()) - { - InterfaceAddress anAddress = (InterfaceAddress)it.next(); - if((anAddress == null || anAddress.getAddress().isLinkLocalAddress())) - continue; - - //System.out.println("Getting bcast address for " + anAddress); - InetAddress abcast = anAddress.getBroadcast(); - if(abcast != null) - bcastAddresses.add(abcast); - } - } - } - - } - catch(Exception e) - { - e.printStackTrace(); - System.out.println(e); - } - - return bcastAddresses; - } - -} diff --git a/projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/AngelBlankEspduTCPReceiverBSenderA.java b/projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/AngelBlankEspduTCPReceiverBSenderA.java deleted file mode 100644 index d984017af24cc1c8ce17a6dc231629fcf584a703..0000000000000000000000000000000000000000 --- a/projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/AngelBlankEspduTCPReceiverBSenderA.java +++ /dev/null @@ -1,220 +0,0 @@ - -import java.io.*; -import java.net.*; -import java.util.*; - -import edu.nps.moves.dis.*; -import edu.nps.moves.disutil.DisTime; - -/** - * listens for TCP connection from AngelBlankReceiverAtoTCP and sends ESPDU in IEEE binary format. - * - * @author Angelopoulos/Blankenbeker - * @version 8 MAR 2018 - */ -public class AngelBlankEspduTCPReceiverBSenderA -{ - public static final int NUMBER_TO_SEND = 5000; - - public enum NetworkMode{UNICAST, MULTICAST, BROADCAST}; - - /** default multicast group we send on */ - public static final String DEFAULT_MULTICAST_GROUP="239.1.2.4"; - public static final int TCP_DESTINATION_PORT = 2998; - /** Port we send on */ - public static final int DIS_DESTINATION_PORT = 3000; - -public static void main(String args[]) -{ - /** an entity state pdu */ - EntityStatePdu espdu = new EntityStatePdu(); - MulticastSocket socket = null; - DisTime disTime = DisTime.getInstance(); - int alternator = -1; - - int port = DIS_DESTINATION_PORT; - NetworkMode mode = NetworkMode.MULTICAST; - InetAddress destinationIp = null; - - try - { - destinationIp = InetAddress.getByName(DEFAULT_MULTICAST_GROUP); - } - catch(Exception 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(DIS_DESTINATION_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); - - } - } // end networkModeString - } - catch(Exception e) - { - System.out.println("Unable to initialize networking. Exiting."); - System.out.println(e); - System.exit(-1); - } - - try - { - int connectionCount = 0; - ServerSocket serverSocket = new ServerSocket(TCP_DESTINATION_PORT); - - while(true){ - try - { - Socket clientConnection = serverSocket.accept(); - connectionCount++; - System.out.println("Current PDUs transferred over TCP: " + connectionCount); - //System.out.println("RB SA received TCP connection."); - InputStream is = clientConnection.getInputStream(); - InputStreamReader isr = new InputStreamReader(is); - BufferedReader br = new BufferedReader(isr); - //System.out.println("RB SA waiting to readline."); - int entitySite = Integer.parseInt(br.readLine()); - int entityApplication = Integer.parseInt(br.readLine()); - int entityEntity = Integer.parseInt(br.readLine()); - short entityEntityKind = Short.parseShort(br.readLine()); - int entityCountry = Integer.parseInt(br.readLine()); - short entityDomain = Short.parseShort(br.readLine()); - short entityCategory = Short.parseShort(br.readLine()); - short entitySubcategory = Short.parseShort(br.readLine()); - short entitySpec = Short.parseShort(br.readLine()); - //System.out.println("RB SA reading complete."); - espdu.setExerciseID((short)1); - EntityID eid = espdu.getEntityID(); - eid.setSite(entitySite); // 0 is apparently not a valid site number, per the spec - eid.setApplication(entityApplication); - eid.setEntity(entityEntity); - EntityType entityType = espdu.getEntityType(); - entityType.setEntityKind(entityEntityKind); // Platform (vs lifeform, munition, sensor, etc.) - entityType.setCountry(entityCountry); // USA - entityType.setDomain(entityDomain); // AIR (vs air, surface, subsurface, space) - entityType.setCategory(entityCategory); // Tank - entityType.setSubcategory(entitySubcategory); // M1 Abrams - entityType.setSpec(entitySpec); // M1A2 Abrams - int ts = disTime.getDisAbsoluteTimestamp(); - espdu.setTimestamp(ts); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - espdu.marshal(dos); - - // The byte array here is the packet in DIS format. We put that into a - // datagram and send it. - byte[] data = baos.toByteArray(); - DatagramPacket packet = new DatagramPacket(data, data.length, InetAddress.getByName(DEFAULT_MULTICAST_GROUP), DIS_DESTINATION_PORT); - socket.send(packet); - System.out.println(" EID=[" + eid.getSite() + "," + eid.getApplication() + "," + eid.getEntity() + "]"); - clientConnection.close(); - } - catch(Exception e) - { - System.out.println(e); - } - } - } - catch(Exception e) - { - System.out.println(e); - } - -} - - /** - * A number of sites get all snippy about using 255.255.255.255 for a bcast - * address; it trips their security software and they kick you off their - * network. (Comcast, NPS.) This determines the bcast address for all - * connected interfaces, based on the IP and subnet mask. If you have - * a dual-homed host it will return a bcast address for both. If you have - * some VMs running on your host this will pick up the addresses for those - * as well--eg 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 bcast addresses - - public static Set<InetAddress> getBroadcastAddresses() - { - Set<InetAddress> bcastAddresses = new HashSet<InetAddress>(); - Enumeration interfaces; - - try - { - interfaces = NetworkInterface.getNetworkInterfaces(); - - while(interfaces.hasMoreElements()) - { - NetworkInterface anInterface = (NetworkInterface)interfaces.nextElement(); - - if(anInterface.isUp()) - { - Iterator it = anInterface.getInterfaceAddresses().iterator(); - while(it.hasNext()) - { - InterfaceAddress anAddress = (InterfaceAddress)it.next(); - if((anAddress == null || anAddress.getAddress().isLinkLocalAddress())) - continue; - - //System.out.println("Getting bcast address for " + anAddress); - InetAddress abcast = anAddress.getBroadcast(); - if(abcast != null) - bcastAddresses.add(abcast); - } - } - } - - } - catch(Exception e) - { - e.printStackTrace(); - System.out.println(e); - } - - return bcastAddresses; - } -**/ -}