net.sourceforge.jpcap.simulator
Class PacketCaptureSimulator

java.lang.Object
  |
  +--net.sourceforge.jpcap.capture.PacketDispatcher
        |
        +--net.sourceforge.jpcap.capture.PacketCaptureBase
              |
              +--net.sourceforge.jpcap.simulator.PacketCaptureSimulator
All Implemented Interfaces:
PacketCaptureCapable, PacketDispatchCapable, net.sourceforge.jpcap.capture.PacketHandler

public class PacketCaptureSimulator
extends PacketCaptureBase
implements PacketCaptureCapable

This class has the same external interface as PacketCapture.

Instead of capturing and dispatching packets from a physical network device, however, this class generates fake packets. The type and frequency of the packets is set by policies configured in the simulator property file.

Instances of this class are used mostly by developers working on applications that utilize jpcap in environments where a real network device isn't available or when the type of packets arriving needs to be carefully controlled.

For more documentation on this class's methods, see PacketCaptureCapable; Javadoc is 'inherited' from this interface.


Fields inherited from class net.sourceforge.jpcap.capture.PacketCaptureBase
droppedCount, linkType, receivedCount
 
Fields inherited from interface net.sourceforge.jpcap.capture.PacketCaptureCapable
DEFAULT_SNAPLEN, DEFAULT_TIMEOUT
 
Constructor Summary
PacketCaptureSimulator()
           
 
Method Summary
 void capture(int count)
          The simulator's implementation of capture causes packets to be randomly generated.
 void close()
          Close the capture device.
 java.lang.String findDevice()
          Detect a network device suitable for packet capture.
 int getLinkLayerType()
          Fetch the link layer type for the specified device.
 int getNetmask(java.lang.String device)
          Fetch the network mask for the specified device.
 int getNetwork(java.lang.String device)
          Fetch the network number for the specified device.
 CaptureStatistics getStatistics()
          Fetch statistics on captured packets.
 void open(java.lang.String device, boolean promiscuous)
          Open a network device for data capture.
 void open(java.lang.String device, int snaplen, boolean promiscuous, int timeout)
          Open a network device for data capture.
 void setFilter(java.lang.String filterExpression, boolean optimize)
          Create, compile and activate a filter from a filter expression.
 
Methods inherited from class net.sourceforge.jpcap.capture.PacketCaptureBase
handlePacket
 
Methods inherited from class net.sourceforge.jpcap.capture.PacketDispatcher
addPacketListener, addRawPacketListener, dispatchPacket, dispatchRawPacket, removePacketListener, removeRawPacketListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sourceforge.jpcap.capture.PacketCaptureCapable
addPacketListener, addRawPacketListener, removePacketListener, removeRawPacketListener
 

Constructor Detail

PacketCaptureSimulator

public PacketCaptureSimulator()
Method Detail

open

public void open(java.lang.String device,
                 boolean promiscuous)
          throws CaptureDeviceOpenException
Description copied from interface: PacketCaptureCapable
Open a network device for data capture. Throws an exception if the device name specified is invalid. Uses default values for the capture timeout and snaplen.
Specified by:
open in interface PacketCaptureCapable
Following copied from interface: net.sourceforge.jpcap.capture.PacketCaptureCapable
Parameters:
device - the name of the network device. Examples of valid network devices on linux are 'eth0' and 'ppp0'.
promiscuous - whether or not the device should be opened in promiscuous mode.
Returns:
a string describing the network device. if no device can be found, null is returned.

open

public void open(java.lang.String device,
                 int snaplen,
                 boolean promiscuous,
                 int timeout)
Description copied from interface: PacketCaptureCapable
Open a network device for data capture.
Specified by:
open in interface PacketCaptureCapable
Following copied from interface: net.sourceforge.jpcap.capture.PacketCaptureCapable
Parameters:
device - the name of the network device. Examples of valid network devices on linux are 'eth0' and 'ppp0'.
snaplen - the 'snapshot' length. Defines the maximum number of bytes to save from each captured packet.
promiscuous - whether or not the device should be opened in promiscuous mode.
timeout - the packet capture timeout in milliseconds.
Returns:
a string describing the network device. if no device can be found, null is returned.

setFilter

public void setFilter(java.lang.String filterExpression,
                      boolean optimize)
               throws InvalidFilterException
Description copied from interface: PacketCaptureCapable
Create, compile and activate a filter from a filter expression.
Specified by:
setFilter in interface PacketCaptureCapable
Following copied from interface: net.sourceforge.jpcap.capture.PacketCaptureCapable
Parameters:
filterExpression - the filter expression. For example, the expression "host techno" would filter only packets sent or arriving at the host named techno.

capture

public void capture(int count)
             throws CapturePacketException
The simulator's implementation of capture causes packets to be randomly generated. The packet frequency and type is not yet configurable.
Specified by:
capture in interface PacketCaptureCapable
Following copied from interface: net.sourceforge.jpcap.capture.PacketCaptureCapable
Parameters:
count - the number of packets to capture. If count is negative, capture will block forever, unless an exception is thrown.

getStatistics

public CaptureStatistics getStatistics()
Description copied from interface: PacketCaptureCapable
Fetch statistics on captured packets. This method should not be called unless capture() was previously called.
Specified by:
getStatistics in interface PacketCaptureCapable
Following copied from interface: net.sourceforge.jpcap.capture.PacketCaptureCapable
Returns:
packet capture statistics.

close

public void close()
Description copied from interface: PacketCaptureCapable
Close the capture device.
Specified by:
close in interface PacketCaptureCapable

findDevice

public java.lang.String findDevice()
                            throws CaptureDeviceNotFoundException
Description copied from interface: PacketCaptureCapable
Detect a network device suitable for packet capture.
Specified by:
findDevice in interface PacketCaptureCapable
Following copied from interface: net.sourceforge.jpcap.capture.PacketCaptureCapable
Returns:
a string describing the network device. if no device can be found, null is returned.

getNetwork

public int getNetwork(java.lang.String device)
               throws CaptureConfigurationException
Description copied from interface: PacketCaptureCapable
Fetch the network number for the specified device.
Specified by:
getNetwork in interface PacketCaptureCapable
Following copied from interface: net.sourceforge.jpcap.capture.PacketCaptureCapable
Parameters:
device - the name of the network device.
Returns:
the network address

getNetmask

public int getNetmask(java.lang.String device)
               throws CaptureConfigurationException
Description copied from interface: PacketCaptureCapable
Fetch the network mask for the specified device.
Specified by:
getNetmask in interface PacketCaptureCapable
Following copied from interface: net.sourceforge.jpcap.capture.PacketCaptureCapable
Parameters:
device - the name of the network device.
Returns:
the netmask address

getLinkLayerType

public int getLinkLayerType()
                     throws CaptureConfigurationException
Description copied from interface: PacketCaptureCapable
Fetch the link layer type for the specified device.
Specified by:
getLinkLayerType in interface PacketCaptureCapable
Following copied from interface: net.sourceforge.jpcap.capture.PacketCaptureCapable
Returns:
the link layer type code.