com.ibm.as400.util.commtrace

Class Format

  • java.lang.Object
    • com.ibm.as400.util.commtrace.Format


  • public class Format
    extends java.lang.Object
    The Format object is an interface between the raw trace file and the records the trace file contains.
    A example program:
     Format f = new Format("/path/to/file");
     f.setFilterProperties(fmtprop); // Sets the filtering properties for this format
     f.formatProlog(); // Format the prolog
     Prolog pro = f.getProlog();    
     System.out.println(pro.toString());
     if(!pro.invalidData()) { // The is not a valid trace
             Frame rec; 
             while((rec=f.getNextRecord())!=null) { // Get the records
                    System.out.print(rec.getRecNum()); // Print out the Frame Number
                    System.out.println(rec.getTime()); // Print out the time
                    IPPacket p = rec.getPacket(); // Get this records packet
                    Header h = p.getHeader(); // Get the first header
                    if(p.getType()==IPPacket.IP6) { // If IP6 IPPacket
                            if(h.getType()==Header.IP6) { // If IP6 Header
                                    IP6Header ip6 = (IP6Header) h; // Cast to IP6 so we can access methods
                                    System.out.println(h.getName()); // Print the name
                                    System.out.println("IP6 src:"+ip6.getSrcAddr() + " dst:" + ip6.getDstAddr());
                                    System.out.println(ip6.printHexHeader()); // Print the header as hex 
                                    // Print a string representation of the header.
                                    System.out.println(ip6.toString(prop)); 
                                    while((h=h.getNextHeader())!=null) { // Get the rest of the headers
                                            if(h.getType()==Header.TCP) { // If its a TCP header
                                                    TCPHeader tcp = (TCPHeader) h; // Cast so we can access methods
                                                    System.out.println("TCP src:" + tcp.getSrcPort() + " dst:" + tcp.getDstPort()); 
                                                    System.out.println(tcp.toString(prop));
                                            } else if(h.getType()==Header.UDP) { // If its a UDP header
                                                    UDPHeader udp = (UDPHeader) h; // Cast so we can access methods
                                                    System.out.println("UDP src:" + udp.getSrcPort() + " dst:" + udp.getDstPort()); 
                                                    System.out.println(udp.toString(prop));
                                            }
                                    }
                            }
                    }
             } 
     }
    
    Format can be run as a program as follows:
     java com.ibm.as400.commtrace.Format [ options ]
    Options:
    First argument
    System to connect to
    -u/-userID
    The userID for the system
    -p/-password
    The password for the system
    -t/-trace
    The trace to parse
    -o/-outfile
    The file to store the output in
    -c/-current
    Will connect to localhost with the current userID and password
    -v/-verbose [true|false]
    -logfile
    The file to store the Trace.log to
    -ip/-ipaddress
    The IP address to filter by
    -ip2/-ipaddress2
    The second IP address to filter by
    -port
    The port number to filter by
    -broadcast [*YES|*NO]
    Print broadcast frames
    -starttime
    The start of the display range in MMddyyyykkmmssSSS notation(see java.text.SimpleDateFormat)
    -endtime
    The end of the display range in MMddyyyykkmmssSSS notation(see java.text.SimpleDateFormat)
    -starttimelong
    The start of the display range in milliseconds since the epoc
    -endtimelong
    The end of the display range in milliseconds since the epoc
    • Constructor Summary

      Constructors 
      Constructor and Description
      Format()
      Default constructor.
      Format(AS400 sys)
      Creates a new Format.
      Format(FormatProperties prop, java.lang.String outfile, java.lang.String infile)
      Constructs a new Format object.
      Format(IFSFileInputStream file)
      Creates a Format object on the given IFSFileInputStream.
      Format(java.lang.String filename)
      Creates a Format object on the given local file.
      Format(java.lang.String[] args)
      Creates a Format object on the given binary trace.
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      java.lang.String addBanner()
      Return a String containing the banner.
      int close()
      Closes this format object.
      boolean formatProlog()
      Formats the prolog.
      int getIntFromFile()
      Reads in an int from the input stream.
      Frame getNextRecord()
      Retrieves the next record from the given trace.
      int getNumberOfTCPRecords()
      Returns the number of tcp records in this trace.
      Prolog getProlog()
      Returns the prolog of this trace.
      java.lang.String getRecFromFile()
      Reads a Frame from the input stream.
      int getRecsProcessed()
      Returns the number of records that have been formatted.
      static void main(java.lang.String[] args)
      Called by the JVM to Format a file.
      int openIFSFile()
      Opens an ObjectInputStream and IFSFileInputStream on the file specified earlier.
      int openIFSFile(java.lang.String outfile)
      Opens an ObjectInputStream and IFSFileInputStream on the outfile.
      int openLclFile()
      Opens an ObjectInputStream and FileInputStream on the file specified on the command line.
      int openLclFile(java.lang.String outfile)
      Opens an ObjectInputStream and FileInputStream on the outfile.
      void setFilterProperties(FormatProperties prop)
      Sets the Properties for this Format.
      void setInFileStream(java.io.InputStream infile)
      Sets the input stream to read the data from.
      void setOutFile(java.lang.String outfile)
      Sets the output file to open a OutputStream on.
      void setSystem(AS400 system)
      Sets the system to use for all IBM i connections.
      int toIFSBinFile()
      Format the trace and write the results to a binary IFS file on the system we are connected to.
      int toIFSTxtFile()
      Formats the trace and sends the output to an IFS text file on the system we are bound to.
      int toLclBinFile()
      Format the trace and write the results to a binary file on the local PC.
      int toLclTxtFile()
      Formats the trace and sends the output to an IFS text file on the system we are bound to.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Format

        public Format()
        Default constructor.
      • Format

        public Format(AS400 sys)
        Creates a new Format.
        Initializes the MRI.
        Takes an AS400 object as an argument which will be used for all IBM i operations.
        Parameters:
        sys - The system that this object should connect to.
      • Format

        public Format(FormatProperties prop,
              java.lang.String outfile,
              java.lang.String infile)
        Constructs a new Format object.
        Initializes the MRI.
        Formats the Prolog.
        Sets up the Filters.
        Parameters:
        prop - The FormatProperties object to filter by.
        outfile - The file to write the formatted trace data to.
        infile - The name of the file to read from.
      • Format

        public Format(java.lang.String[] args)
        Creates a Format object on the given binary trace.
        Initializes the MRI.
        Formats the Prolog.
        Sets up the Filters.
        Parameters:
        args - The command line arguments to be used to format the file.
      • Format

        public Format(java.lang.String filename)
        Creates a Format object on the given local file.
        Parameters:
        filename - The file to format.
      • Format

        public Format(IFSFileInputStream file)
        Creates a Format object on the given IFSFileInputStream.
        Initializes the MRI.
        Formats the Prolog.
        Sets up the Filters.
        Parameters:
        file - The input stream to read the data off of.
    • Method Detail

      • setFilterProperties

        public void setFilterProperties(FormatProperties prop)
        Sets the Properties for this Format.
        Parameters:
        prop - Properties for this Format.
      • setOutFile

        public void setOutFile(java.lang.String outfile)
        Sets the output file to open a OutputStream on.
        Parameters:
        outfile - The file to open a OutputStream on.
      • setInFileStream

        public void setInFileStream(java.io.InputStream infile)
        Sets the input stream to read the data from.
        Parameters:
        infile - The open InputStream to read from.
      • setSystem

        public void setSystem(AS400 system)
        Sets the system to use for all IBM i connections.
        Parameters:
        system - The system to connect to.
      • toIFSTxtFile

        public int toIFSTxtFile()
        Formats the trace and sends the output to an IFS text file on the system we are bound to.
        Returns:
        A error code if any.
      • toLclTxtFile

        public int toLclTxtFile()
        Formats the trace and sends the output to an IFS text file on the system we are bound to.
        Returns:
        A error code if any.
      • toIFSBinFile

        public int toIFSBinFile()
        Format the trace and write the results to a binary IFS file on the system we are connected to.
        Returns:
        A error code if any.
      • toLclBinFile

        public int toLclBinFile()
        Format the trace and write the results to a binary file on the local PC.
        Returns:
        A error code if any.
      • openIFSFile

        public int openIFSFile()
        Opens an ObjectInputStream and IFSFileInputStream on the file specified earlier. Used for displaying previously formatted traces.
        Returns:
        An error code if any.
      • openIFSFile

        public int openIFSFile(java.lang.String outfile)
        Opens an ObjectInputStream and IFSFileInputStream on the outfile. Used for displaying previously formatted traces.
        Parameters:
        outfile -
        Returns:
        An error code if any.
      • openLclFile

        public int openLclFile()
        Opens an ObjectInputStream and FileInputStream on the file specified on the command line. Used for displaying previously formatted traces.
        Returns:
        An error code if any.
      • openLclFile

        public int openLclFile(java.lang.String outfile)
        Opens an ObjectInputStream and FileInputStream on the outfile. Used for displaying previously formatted traces.
        Parameters:
        outfile - The file to read in.
        Returns:
        int An error code if any.
      • close

        public int close()
        Closes this format object.
        Returns:
        An error code if any.
      • getRecFromFile

        public java.lang.String getRecFromFile()
        Reads a Frame from the input stream. Records are stored as Strings.
        Returns:
        String
      • getIntFromFile

        public int getIntFromFile()
        Reads in an int from the input stream.
        Returns:
        int
      • formatProlog

        public boolean formatProlog()
        Formats the prolog.
        Sets the length of the first record.
        Sets the total number of records.
        Returns:
        true if this trace contains invalid data.
      • getNextRecord

        public Frame getNextRecord()
        Retrieves the next record from the given trace.
        This method discards all non TCP records.
        Returns:
        Frame
      • addBanner

        public java.lang.String addBanner()
        Return a String containing the banner.
        Returns:
        String containing the banner.
      • getRecsProcessed

        public int getRecsProcessed()
        Returns the number of records that have been formatted.
        Returns:
        number of formatted records
      • getProlog

        public Prolog getProlog()
        Returns the prolog of this trace.
        Returns:
        Prolog
      • getNumberOfTCPRecords

        public int getNumberOfTCPRecords()
        Returns the number of tcp records in this trace.
        Returns:
        The number of tcp records in this trace.
      • main

        public static void main(java.lang.String[] args)
        Called by the JVM to Format a file.
        Parameters:
        args - The arguments from the command line.