Skip to content
Snippets Groups Projects
Commit 7ec1c0da authored by terry-norbraten's avatar terry-norbraten
Browse files

specify one authoritative source for default mcast addr, port and max pdu size

parent 285fd416
No related branches found
No related tags found
No related merge requests found
Showing
with 45 additions and 83 deletions
......@@ -9,6 +9,7 @@ import edu.nps.moves.dis7.EntityID;
import edu.nps.moves.dis7.EntityStatePdu;
import edu.nps.moves.dis7.Pdu;
import edu.nps.moves.dis7.Vector3Double;
import edu.nps.moves.dis7.utilities.DisThreadedNetIF;
import edu.nps.moves.dis7.utilities.PduFactory;
import java.io.IOException;
import java.net.DatagramPacket;
......@@ -26,16 +27,10 @@ import java.util.List;
*/
public class EspduReceiver
{
/**
* 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;
public static void main(String args[])
{
MulticastSocket socket;
byte buffer[] = new byte[MAX_PDU_SIZE];
byte buffer[] = new byte[DisThreadedNetIF.MAX_DIS_PDU_SIZE];
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
PduFactory pduFactory = new PduFactory();
List<Pdu> pduBundle;
......
......@@ -21,30 +21,22 @@ import java.net.MulticastSocket;
*/
public class EspduReceiverNIO
{
/**
* 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
* <p>
* This is legacy code ported to the edu.nps.moves.dis7 package
*/
public static final int MAX_PDU_SIZE = 8192; // This has actually been superceded by a larger buffer size, but good enough for now
public static void main(String args[])
{
MulticastSocket socket;
InetAddress maddr;
InetSocketAddress group;
PduFactory pduFactory = new PduFactory();
byte buffer[] = new byte[MAX_PDU_SIZE];
byte buffer[] = new byte[DisThreadedNetIF.MAX_DIS_PDU_SIZE];
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
Pdu pdu;
try {
// Specify the socket to receive data
socket = new MulticastSocket(EspduSenderNIO.PORT);
maddr = InetAddress.getByName(EspduSenderNIO.MULTICAST_GROUP);
group = new InetSocketAddress(maddr, EspduSenderNIO.PORT);
socket = new MulticastSocket(DisThreadedNetIF.DEFAULT_DIS_PORT);
maddr = InetAddress.getByName(DisThreadedNetIF.DEFAULT_MCAST_GROUP);
group = new InetSocketAddress(maddr, DisThreadedNetIF.DEFAULT_DIS_PORT);
socket.joinGroup(group, DisThreadedNetIF.findIp4Interface());
// Loop infinitely, receiving datagrams
......
......@@ -29,16 +29,6 @@ public class EspduSender
UNICAST, MULTICAST, BROADCAST
};
/**
* Default multicast group address we send on
*/
public static final String DEFAULT_MULTICAST_GROUP = "239.1.2.3";
/**
* Default port we send on
*/
public static final int DIS_DESTINATION_PORT = 3000;
/**
* Possible system properties, passed in via -Dattr=val
* networkMode: unicast, broadcast, multicast
......@@ -65,16 +55,16 @@ public class EspduSender
// Default settings. These are used if no system properties are set.
// If system properties are passed in, these are over ridden.
int port = DIS_DESTINATION_PORT;
int port = DisThreadedNetIF.DEFAULT_DIS_PORT;
NetworkMode mode;
InetAddress destinationIp = null; // must be initialized, even if null
try {
destinationIp = InetAddress.getByName(DEFAULT_MULTICAST_GROUP);
destinationIp = InetAddress.getByName(DisThreadedNetIF.DEFAULT_MCAST_GROUP);
}
catch (UnknownHostException e) {
System.err.println(e + " Cannot create multicast address");
System.exit(0);
System.exit(1);
}
// All system properties, passed in on the command line via -Dattribute=value
......@@ -121,8 +111,8 @@ public class EspduSender
} // end networkModeString
}
catch (IOException | RuntimeException e) {
System.out.println("Unable to initialize networking. Exiting.");
System.out.println(e);
System.err.println("Unable to initialize networking. Exiting.");
System.err.println(e);
System.exit(-1);
}
......
......@@ -24,16 +24,6 @@ import java.net.MulticastSocket;
*/
public class EspduSenderNIO
{
/**
* multicast group we send on
*/
public static final String MULTICAST_GROUP = "239.1.2.3";
/**
* Port we send on
*/
public static final int PORT = 3000;
public static void main(String args[])
{
MulticastSocket socket;
......@@ -52,16 +42,16 @@ public class EspduSenderNIO
eid.setEntityID((short) 2);
try {
socket = new MulticastSocket(PORT);
maddr = InetAddress.getByName(MULTICAST_GROUP);
group = new InetSocketAddress(maddr, PORT);
socket = new MulticastSocket(DisThreadedNetIF.DEFAULT_DIS_PORT);
maddr = InetAddress.getByName(DisThreadedNetIF.DEFAULT_MCAST_GROUP);
group = new InetSocketAddress(maddr, DisThreadedNetIF.DEFAULT_DIS_PORT);
socket.joinGroup(group, DisThreadedNetIF.findIp4Interface());
Vector3Double location;
EulerAngles orientation;
float psi;
byte[] data = new byte[144];
DatagramPacket packet = new DatagramPacket(data, data.length, maddr, PORT);
DatagramPacket packet = new DatagramPacket(data, data.length, maddr, DisThreadedNetIF.DEFAULT_DIS_PORT);
while (true) {
for (int idx = 0; idx < 100; idx++) {
......
......@@ -4,6 +4,7 @@
*/
package edu.nps.moves.dis7.examples;
import edu.nps.moves.dis7.utilities.DisThreadedNetIF;
import edu.nps.moves.dis7.utilities.stream.PduRecorder;
import java.io.IOException;
import java.util.Scanner;
......@@ -20,8 +21,6 @@ import java.util.Scanner;
public class PduListenerSaver
{
private final static String DEFAULT_OUTPUTDIR = "./pduLog";
private final static String MCAST_ADDR = "239.1.2.3";
private final static int DIS_PORT = 3000;
private enum mystate
{
......@@ -32,8 +31,8 @@ public class PduListenerSaver
public static void main(String[] args)
{
String outDir = DEFAULT_OUTPUTDIR;
String mcast = MCAST_ADDR;
int port = DIS_PORT;
String mcast = DisThreadedNetIF.DEFAULT_MCAST_GROUP;
int port = DisThreadedNetIF.DEFAULT_DIS_PORT;
switch (args.length) {
case 0:
......@@ -53,8 +52,7 @@ public class PduListenerSaver
System.out.println("Beginning pdu save to directory " + outDir);
try {
PduRecorder recorder = new PduRecorder(outDir, mcast, port);
recorder.startResume();
PduRecorder recorder = new PduRecorder(outDir, mcast, port); // assumes save
mystate state = mystate.RUNNING;
Scanner scan = new Scanner(System.in);
......
......@@ -4,6 +4,7 @@
*/
package edu.nps.moves.dis7.examples;
import edu.nps.moves.dis7.utilities.DisThreadedNetIF;
import edu.nps.moves.dis7.utilities.stream.PduPlayer;
import java.io.File;
import java.io.IOException;
......@@ -21,8 +22,6 @@ import java.util.Scanner;
public class PduReaderPlayer
{
private final static String DEFAULT_OUTPUTDIR = "./pduLog";
private final static String MCAST_ADDR = "239.1.2.3";
private final static int DIS_PORT = 3000;
private enum mystate
{
......@@ -33,8 +32,8 @@ public class PduReaderPlayer
public static void main(String[] args)
{
String outDir = DEFAULT_OUTPUTDIR;
String mcast = MCAST_ADDR;
int port = DIS_PORT;
String mcast = DisThreadedNetIF.DEFAULT_MCAST_GROUP;
int port = DisThreadedNetIF.DEFAULT_DIS_PORT;
boolean sendToNet = false;
switch (args.length) {
......
......@@ -28,8 +28,6 @@ import java.util.List;
public class PduSender
{
public static final int PORT = 3000;
public static final String MULTICAST_ADDRESS = "239.1.2.3";
private int port;
InetAddress multicastAddress;
......@@ -291,7 +289,7 @@ public class PduSender
// Send the PDUs we created
DatagramPacket packet;
InetAddress localMulticastAddress = InetAddress.getByName(MULTICAST_ADDRESS);
InetAddress localMulticastAddress = InetAddress.getByName(DisThreadedNetIF.DEFAULT_MCAST_GROUP);
MulticastSocket socket = new MulticastSocket(port);
InetSocketAddress group = new InetSocketAddress(localMulticastAddress, port);
socket.joinGroup(group, DisThreadedNetIF.findIp4Interface());
......@@ -329,8 +327,8 @@ public class PduSender
}
else {
System.out.println("Usage: PduSender <port> <multicast group>");
System.out.println("Default: PduSender " + PORT + " " + MULTICAST_ADDRESS);
sender = new PduSender(PORT, MULTICAST_ADDRESS);
System.out.println("Default: PduSender " + DisThreadedNetIF.DEFAULT_DIS_PORT + " " + DisThreadedNetIF.DEFAULT_MCAST_GROUP);
sender = new PduSender(DisThreadedNetIF.DEFAULT_DIS_PORT, DisThreadedNetIF.DEFAULT_MCAST_GROUP);
}
sender.run();
}
......
......@@ -36,9 +36,8 @@ public class DisNetworking
}
}
private int DIS_PORT = 3000;
private String MCAST_GROUP = "230.0.0.0";
private static final int MAX_DIS_PDU_SIZE = 8192;
private int DIS_PORT;
private String MCAST_GROUP;
private ByteArrayOutputStream baos;
private DataOutputStream dos;
......@@ -49,7 +48,7 @@ public class DisNetworking
public DisNetworking()
{
this(3000, "230.0.0.0");
this(DisThreadedNetIF.DEFAULT_DIS_PORT, DisThreadedNetIF.DEFAULT_MCAST_GROUP);
}
public DisNetworking(int port, String mcastgroup)
......@@ -104,7 +103,7 @@ public class DisNetworking
{
rsocket = new MulticastSocket(DIS_PORT);
rsocket.joinGroup(group, ni);
buffer = new byte[MAX_DIS_PDU_SIZE];
buffer = new byte[DisThreadedNetIF.MAX_DIS_PDU_SIZE];
packet = new DatagramPacket(buffer, buffer.length);
//System.out.println("Listening on " + MCAST_GROUP + ":" + DIS_PORT + " if:" + socket.getNetworkInterface().getDisplayName());
......
......@@ -63,7 +63,9 @@ public class DisThreadedNetIF
public static int DEFAULT_DIS_PORT = 3000;
public static String DEFAULT_MCAST_GROUP = "225.4.5.6";
private static final int MAX_DIS_PDU_SIZE = 8192;
/** 8192: This has actually been superseded by a larger buffer size, but good enough for now */
public static final int MAX_DIS_PDU_SIZE = 8192;
private int disPort;
private String mcastGroup;
......
......@@ -1790,11 +1790,13 @@ public class PduFactory
aPdu.unmarshal(buff);
} catch (Exception ex) {
// TODO: trouble shoot. there is an issue when unmarshalling the
// special cases of SIGNAL and INTERCOM_SIGNAL pdus from a log
// file during play back
// special cases of SIGNAL and INTERCOM_SIGNAL pdus during play back
// of the AllPduRoundTripTest log file. However, there is no such
// failure during the concise SignalPduTest of the same special case
// PDUs only
// Logger.getLogger(PduFactory.class.getName()).log(Level.SEVERE, null, ex);
System.err.println("error unmarshalling " + pduType);
System.err.println(ex);
System.err.println("From: " + PduFactory.class.getName());
System.err.println("Error unmarshalling " + pduType + ": " + ex);
}
}
}
......
......@@ -28,17 +28,14 @@ import org.apache.commons.io.FilenameUtils;
*/
public class PduRecorder implements PduReceiver
{
public static final String COMMENT_MARKER = "#";
static String DEFAULT_OUTDIR = "./pdulog";
static String DEFAULT_FILEPREFIX = "Pdusave"; // TODO better name
static String DISLOG_FILE_EXTENSION = ".dislog";
static String DEFAULT_MCAST = "230.0.0.0";
static int DEFAULT_PORT = 3000;
public static final String COMMENT_MARKER = "#";
static String START_COMMENT_MARKER = COMMENT_MARKER + " Start, ";
static String FINISH_COMMENT_MARKER = COMMENT_MARKER + " Finish, ";
static final String START_COMMENT_MARKER = COMMENT_MARKER + " Start, ";
static final String FINISH_COMMENT_MARKER = COMMENT_MARKER + " Finish, ";
static final String ENCODING_BASE64 = "ENCODING_BASE64";
static final String ENCODING_PLAINTEXT = "ENCODING_PLAINTEXT";
static final String ENCODING_BINARY = "ENCODING_BINARY"; // TODO likely requires different code path
......@@ -49,7 +46,7 @@ public class PduRecorder implements PduReceiver
static final String ENCODING_WIRESHARK_DATA_LOGGER = "ENCODING_WIRESHARK_DATA_LOGGER"; //
static final String ENCODING_CDIS = "ENCODING_CDIS"; // future work based on new SISO standard
private static String pduLogEncoding = ENCODING_PLAINTEXT; // TODO use Java enumerations, generalize/share across library
private static String pduLogEncoding = ENCODING_PLAINTEXT; // TODO use Java enumerations, generalize/share across library
/**
* TODO change this to enumeration type for strictness
......@@ -79,7 +76,7 @@ public class PduRecorder implements PduReceiver
*/
public PduRecorder() throws IOException
{
this(DEFAULT_OUTDIR, DEFAULT_MCAST, DEFAULT_PORT);
this(DEFAULT_OUTDIR, DisThreadedNetIF.DEFAULT_MCAST_GROUP, DisThreadedNetIF.DEFAULT_DIS_PORT);
}
/**
......@@ -92,7 +89,7 @@ public class PduRecorder implements PduReceiver
*/
public PduRecorder(String dir) throws IOException
{
this(dir, DEFAULT_MCAST, DEFAULT_PORT);
this(dir, DisThreadedNetIF.DEFAULT_MCAST_GROUP, DisThreadedNetIF.DEFAULT_DIS_PORT);
}
/** Constructor to let the user specify all required parameters
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment