Class DisThreadedNetworkInterface

java.lang.Object
edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface

public class DisThreadedNetworkInterface extends Object
This is a thread-safe, multicast DIS network interface class.
Since:
Jul 29, 2019
Author:
Mike Bailey, jmbailey@nps.edu
  • Field Details

    • DEFAULT_DIS_ADDRESS

      public static String DEFAULT_DIS_ADDRESS
      Default multicast group address 239.1.2.3 for send and receive connections.
      See Also:
      https://en.wikipedia.org/wiki/Multicast_address
    • DEFAULT_DIS_PORT

      public static int DEFAULT_DIS_PORT
      Default socket port 3000, matches Wireshark DIS capture default
      See Also:
      https://en.wikipedia.org/wiki/Port_(computer_networking)
    • MAX_DIS_PDU_SIZE

      public static final int MAX_DIS_PDU_SIZE
      MTU 8192: TODO this has actually been superseded by a larger buffer size, but good enough for now
      See Also:
      Constant Field Values
    • MAX_TRANSMISSION_UNIT_SIZE

      public static final int MAX_TRANSMISSION_UNIT_SIZE
      MTU 1500: size of an Ethernet frame, common value to avoid packet segmentation
      See Also:
      Constant Field Values
  • Constructor Details

    • DisThreadedNetworkInterface

      public DisThreadedNetworkInterface()
      Object constructor using default multicast address and port
    • DisThreadedNetworkInterface

      public DisThreadedNetworkInterface(String address, int port)
      Object constructor using specified multicast address and port
      Parameters:
      address - the multicast group or unicast address to utilize
      port - the multicast port to utilize
  • Method Details

    • main

      public static void main(String[] args)
      Main method for testing.
      Parameters:
      args - command-line arguments are an array of optional String parameters that are passed from execution environment during invocation
      See Also:
      Java Tutorials: A Closer Look at the "Hello World!" Application
    • addListener

      public void addListener(DisThreadedNetworkInterface.PduListener newListener, DisPduType disPduType)
      Add a listener to accept only pdus of a given type
      Parameters:
      newListener - listener instance implementing the RawPduListener interface
      disPduType - Pdu type
    • addListener

      public void addListener(DisThreadedNetworkInterface.PduListener newListener)
      Add a listener to accept all pdu types
      Parameters:
      newListener - listener instance implementing the RawPduListener interface
    • removeListener

      public void removeListener(DisThreadedNetworkInterface.PduListener priorListener)
      Remove previously added listener
      Parameters:
      priorListener - listener instance implementing the RawPduListener interface
    • addRawListener

      public void addRawListener(DisThreadedNetworkInterface.RawPduListener lis)
      Add a listener to accept pdus of all types in the form of a byte array
      Parameters:
      lis - listener instance implementing the RawPduListener interface
    • removeRawListener

      public void removeRawListener(DisThreadedNetworkInterface.RawPduListener lis)
      Remove previously added raw listener
      Parameters:
      lis - listener instance implementing the RawPduListener interface
    • getMulticastGroup

      @Deprecated public String getMulticastGroup()
      Deprecated.
      Deprecated, replaced by getAddress()
      Returns:
      current multicast address value
    • getAddress

      public String getAddress()
      Get current multicast (or unicast) network address for send and receive connections.
      Returns:
      current multicast address value
      See Also:
      https://en.wikipedia.org/wiki/Multicast_address
    • setAddress

      public void setAddress(String newAddress)
      Network address for send and receive connections.
      Parameters:
      newAddress - the new network address to set
      See Also:
      https://en.wikipedia.org/wiki/Multicast_address
    • send

      public void send(Pdu pdu)
      Send the given pdu to the network using the IP address and port given to the constructor
      Parameters:
      pdu - the pdu to send
    • start

      public void start()
      Can be used to restart DisThreadedNetworkInterface if closed. Create datagram socket if not already available; can also be invoked by either sender or receiver thread to ensure datagram socket is open.
    • kill

      @Deprecated public void kill()
      Deprecated.
      Method renamed as close() so use that method instead..
    • finishOperations

      public void finishOperations()
      Finish pending send/receive activity and then close.
    • close

      public void close()
      Terminate the instance after completion of pending send/receive activity. Synchronized to prevent interleaved invocation.
    • findIpv4Interface

      public static NetworkInterface findIpv4Interface()
      Find proper IPV4 interface on this computer for use with the djs address
      Returns:
      a network interface to use to join a multicast group
    • setVerbose

      public void setVerbose(boolean newValue)
      Set whether or not trace statements are provided when packets are sent or received.
      Parameters:
      newValue - the verbose status to set. Also resets verboseReceipt and verboseSending to match.
      See Also:
      verboseReceipt, verboseSending
    • hasVerboseOutput

      public boolean hasVerboseOutput()
      Whether or not trace statements are provided when packets are sent or received.
      Returns:
      the verbose status
      See Also:
      verboseReceipt, verboseSending
    • setVerboseReceipt

      public void setVerboseReceipt(boolean newValue)
      Set whether or not trace statements are provided when packets are received.
      Parameters:
      newValue - the verboseReceipt status to set
      See Also:
      verbose, verboseSending
    • hasVerboseReceipt

      public boolean hasVerboseReceipt()
      Whether or not trace statements are provided when packets are received.
      Returns:
      the verboseReceipt status
    • setVerboseSending

      public void setVerboseSending(boolean newValue)
      Set whether or not trace statements are provided when packets are sent.
      Parameters:
      newValue - the verboseSending status to set
      See Also:
      verbose, verboseReceipt
    • hasVerboseSending

      public boolean hasVerboseSending()
      Whether or not trace statements are provided when packets are sent.
      Returns:
      the verboseSending status
    • hasVerboseOutputIncludesTimestamp

      public boolean hasVerboseOutputIncludesTimestamp()
      Whether or not trace statements include timestamp values.
      Returns:
      the verboseIncludesTimestamp value
    • setVerboseIncludesTimestamp

      public void setVerboseIncludesTimestamp(boolean verboseIncludesTimestamp)
      Set whether or not trace statements include timestamp values.
      Parameters:
      verboseIncludesTimestamp - the value to set
    • getDisPort

      @Deprecated public int getDisPort()
      Deprecated.
      Deprecated, replaced by getPort()
      Returns:
      current port value
    • getPort

      public int getPort()
      Get network port used, multicast or unicast.
      Returns:
      current port value
      See Also:
      https://en.wikipedia.org/wiki/Port_(computer_networking)
    • setPort

      public void setPort(int newPortValue)
      /** Set network port used, multicast or unicast.
      Parameters:
      newPortValue - the disPort value to set
      See Also:
      https://en.wikipedia.org/wiki/Port_(computer_networking)
    • getDescriptor

      public String getDescriptor()
      Get simple descriptor (such as parent class name) for this network interface, used in trace statements
      Returns:
      simple descriptor name
    • setDescriptor

      public void setDescriptor(String newDescriptor)
      Set new simple descriptor (such as parent class name) for this network interface, used in trace statements
      Parameters:
      newDescriptor - simple descriptor name