public class TrafficGenerator extends ScheduledTask<java.lang.Void>
A TrafficGenerator sends some number of packets to a host (via a Link) following some sort of distribution pattern (size and spacing). The number of packets for the TrafficGenerator to send must be specified via a setter.
The TrafficGenerator's behavior can be specified further by the user in a number of ways. A TrafficGenerator has the following components:
TrafficGenerator should be run within a thread. When started via the run() method, attempts to connect to its host; upon successful connection, sends the specified number of packets over the link, then ends.
After getting a TrafficGenerator instance via the getInstance() method, the user must specify the desired packet count, PacketTimeDistribution, PacketSizeDistribution, PacketGenerator, and Link via the corresponding setter methods. There are currently no default values for any of the aforementioned parameters. Failure to specify all parameters before running the TrafficGenerator instance will result in unspecified behavior.
To aid in tracking packet distributions, TrafficGenerator has an option to generate logs of packet transmissions using the java.util.logging API. This option is disabled by default and can be toggled using the setLoggingEnabled() method. When logging is enabled, the TrafficGenerator will log its activity to the console if default console logging is enabled (can be disabled), and to any Handlers which are subscribed to the logs. Methods are provided to subscribe/unsubscribe Handlers to/from the logs.
AUTOSTART, IGNORENULL, RUNONCE| Modifier and Type | Method and Description |
|---|---|
static void |
addLoggingHandler(java.util.logging.Handler handler)
Adds a log Handler to receive packet transmission log records from all
TrafficGenerators.
|
static TrafficGenerator |
getInstance() |
boolean |
loggingEnabled() |
int |
prediction()
Generates the next predicted interval.
|
int[] |
prediction(int size)
Generates an array containing predicted packet transmission times, in
terms of number of ms from this instant.
|
static void |
removeLoggingHandler(java.util.logging.Handler handler)
Removes the specified log Handler from TrafficGenerator's Logger, if the
given Handler is currently subscribed to the logger.
|
static void |
setDefaultConsoleLogging(boolean enable)
Toggles future logging of packet transmissions to the default console
handler by all TrafficGenerators.
|
void |
setEventDispatcher(EventDispatcher newDispatcher) |
void |
setLoggingEnabled(boolean enable)
Toggles packet transmission logging.
|
void |
setPacketGenerator(PacketGenerator newPacketGenerator) |
void |
setSizeDistribution(PacketSizeDistribution newSizeDistribution) |
void |
setStreamIdentifier(java.lang.String newStreamIdentifier) |
void |
setTimeDistribution(PacketTimeDistribution newTimeDistribution) |
cancel, startTaskAsync, startTaskLater, startTaskTimerchainTask, getResult, getResult, getResultNow, isCancelled, run, startTaskpublic static TrafficGenerator getInstance()
public void setTimeDistribution(PacketTimeDistribution newTimeDistribution)
public void setSizeDistribution(PacketSizeDistribution newSizeDistribution)
public void setPacketGenerator(PacketGenerator newPacketGenerator)
public void setEventDispatcher(EventDispatcher newDispatcher)
public void setStreamIdentifier(java.lang.String newStreamIdentifier)
public void setLoggingEnabled(boolean enable)
enable - true if logging should be enabled, false if logging should
be disabledpublic boolean loggingEnabled()
public static void addLoggingHandler(java.util.logging.Handler handler)
handler - the logging Handler to add to TrafficGenerator's loggerpublic static void removeLoggingHandler(java.util.logging.Handler handler)
handler - the Handler to remove from TrafficGenerator's Loggerpublic static void setDefaultConsoleLogging(boolean enable)
enable - a boolean indicating whether default console logging should
be enabledpublic int prediction()
public int[] prediction(int size)
size - the number of predictions contained in the returned array