Mercurial > stress-tester
changeset 711:de7f825fdde4
ReaderMain - pcap file support
author | Devel 2 |
---|---|
date | Wed, 29 Nov 2017 12:13:10 +0100 |
parents | da8f7d56a505 |
children | d243915067e7 |
files | stress-tester/src/main/java/com/passus/st/ReaderMain.java |
diffstat | 1 files changed, 42 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/ReaderMain.java Wed Nov 29 11:49:09 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/ReaderMain.java Wed Nov 29 12:13:10 2017 +0100 @@ -1,11 +1,13 @@ package com.passus.st; -import com.passus.net.http.HttpMessageHelper; +import com.passus.net.PortRangeSet; import com.passus.st.client.Event; import com.passus.st.client.SessionStatusEvent; import com.passus.st.client.http.HttpSessionPayloadEvent; import com.passus.st.emitter.SessionInfo; import com.passus.st.source.NcEventSource; +import com.passus.st.source.PcapSessionEventSource; +import static com.passus.st.utils.CliUtils.option; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.HelpFormatter; @@ -18,8 +20,6 @@ */ public class ReaderMain { - private final HttpMessageHelper helper = HttpMessageHelper.get(); - private void printHelp(Options options) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("[options] <file>", "description", options, ""); @@ -28,6 +28,16 @@ private Options createOptions() { final Options options = new Options(); + options.addOption(option("ps", "allowPartialSession").desc("Allow partial sessions. Only pcap file.") + .hasArg(false) + .build() + ); + + options.addOption(option("hp", "httpPorts").desc("Specify HTTP ports in input file (default: 80, 8080). Only pcap file.") + .hasArg().argName("ports") + .build() + ); + return options; } @@ -60,15 +70,13 @@ if (payloadEvent.getResponse() != null) { System.out.println(payloadEvent.getResponse()); System.out.println(""); - } + } } } private void readNcFile(String filename) throws Exception { NcEventSource src = new NcEventSource(filename); - src.setHandler((event) -> { - printEvent(event); - }); + src.setHandler((event) -> printEvent(event)); try { src.start(); @@ -78,6 +86,31 @@ } } + private void readPcapFile(String filename, CommandLine cl) throws Exception { + PcapSessionEventSource eventSrc = new PcapSessionEventSource(); + eventSrc.setPcapFile(filename); + eventSrc.setAllowPartialSession(cl.hasOption("ps")); + eventSrc.setCollectMetrics(true); + + if (cl.hasOption("hp")) { + PortRangeSet portsRanges = eventSrc.getPortsRange(); + portsRanges.clear(); + + String[] ports = cl.getOptionValues("hp"); + for (String port : ports) { + portsRanges.add(port); + } + } + + eventSrc.setHandler((event) -> printEvent(event)); + try { + eventSrc.start(); + eventSrc.join(); + } finally { + eventSrc.stop(); + } + } + public void start(String[] args) { AppUtils.registerAll(); Options options = createOptions(); @@ -95,6 +128,8 @@ String ext = FilenameUtils.getExtension(filename); if ("nc".equals(ext)) { readNcFile(filename); + } else if ("pcap".equals(ext)) { + readPcapFile(filename, cl); } else { printError("Not supported file extension '" + ext + "'."); }