Mercurial > stress-tester
changeset 1232:0ca4d4cc31ef
HTTP2 - broadcast in progress
author | Devel 2 |
---|---|
date | Mon, 29 Jun 2020 10:53:53 +0200 |
parents | caea6899e63a |
children | 3cbe1f2437b0 |
files | stress-tester/src/main/java/com/passus/st/client/Timeouts.java stress-tester/src/main/java/com/passus/st/client/http/Http2FlowHandlerDataDecoder.java stress-tester/src/main/java/com/passus/st/client/http/Http2FlowHandlerDataEncoder.java stress-tester/src/main/java/com/passus/st/source/EventSourceConfigurator.java stress-tester/src/test/java/com/passus/st/source/PcapSessionEventSourceTest.java |
diffstat | 5 files changed, 73 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/Timeouts.java Fri Jun 26 15:35:37 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/Timeouts.java Mon Jun 29 10:53:53 2020 +0200 @@ -2,7 +2,7 @@ public class Timeouts { - public static final long DEFAULT_TIMEOUT = 10_000L; + public static final long DEFAULT_TIMEOUT = 20_000L; public static final long DEFAULT_CONNECTION_TIMEOUT = 5_000L; public static final long DEFAULT_READ_TIMEOUT = 20_000L; public static final long DEFAULT_DISCONNECT_TIMEOUT = 5_000L;
--- a/stress-tester/src/main/java/com/passus/st/client/http/Http2FlowHandlerDataDecoder.java Fri Jun 26 15:35:37 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/Http2FlowHandlerDataDecoder.java Mon Jun 29 10:53:53 2020 +0200 @@ -24,7 +24,7 @@ private final Logger LOGGER = LogManager.getLogger(Http2FlowHandlerDataDecoder.class); - private final Http2FrameDecoder frameDecoder = new Http2FrameDecoder(); + private final Http2FrameDecoder decoder = new Http2FrameDecoder(); private HttpResponse resp; @@ -32,7 +32,7 @@ private int state = STATE_DATA_NEEDED; - private String error = ""; + private String error = null; private final FixedSizeLengthPduX pdu; @@ -54,6 +54,14 @@ } @Override + public void clear(FlowContext flowContext) { + state = STATE_DATA_NEEDED; + error = null; + pdu.clear(); + resp = null; + } + + @Override public String getLastError() { return null; } @@ -89,6 +97,24 @@ } break; + case FRAME_RST_STREAM: + Http2Stream stream = context.streams.get(frame.getStreamId()); + if (stream == null) { + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Unable to update remote window size. Unknown stream '" + frame.getStreamId() + "'"); + } + } else { + if (LOGGER.isDebugEnabled()) { + Http2ResetStreamFrame resetStreamFrame = (Http2ResetStreamFrame) frame; + LOGGER.debug("Stream '" + frame.getStreamId() + "' reset. " + + "Code " + resetStreamFrame.getCode() + " (" + Http2Errors.errorToString(resetStreamFrame.getCode()) + ")."); + } + + stream.state = Http2Stream.STATE_CLOSED; + } + + state = STATE_FINISHED; + return; case Http2Utils.FRAME_SETTINGS: Http2SettingsFrame settingsFrame = (Http2SettingsFrame) frame; if (settingsFrame.getStreamId() == 0) { @@ -96,6 +122,7 @@ context.remoteSettings = settingsFrame.getSettings(); context.remoteFlags = Http2FlowContext.FLAG_SETTINGS_SENT; } + } else if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Http2SettingsFrame.streamId != 0"); @@ -180,16 +207,16 @@ @Override public void onNewPdu(byte[] data, int offset, int length) { - frameDecoder.decode(data, offset, length); - if (frameDecoder.state() == DataDecoder.STATE_ERROR) { + decoder.decode(data, offset, length); + if (decoder.state() == DataDecoder.STATE_ERROR) { if (LOGGER.isDebugEnabled()) { - LOGGER.debug("HTTP2 Frame decoder error. " + frameDecoder.getLastError()); + LOGGER.debug("HTTP2 Frame decoder error. " + decoder.getLastError()); } - frameDecoder.clear(); - } else if (frameDecoder.state() == STATE_FINISHED) { - processFrame(frameDecoder.getResult()); - frameDecoder.clear(); + decoder.clear(); + } else if (decoder.state() == STATE_FINISHED) { + processFrame(decoder.getResult()); + decoder.clear(); } } }
--- a/stress-tester/src/main/java/com/passus/st/client/http/Http2FlowHandlerDataEncoder.java Fri Jun 26 15:35:37 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/Http2FlowHandlerDataEncoder.java Mon Jun 29 10:53:53 2020 +0200 @@ -2,6 +2,7 @@ import com.passus.data.ByteBuff; import com.passus.data.HeapByteBuff; +import com.passus.net.http.HttpHeaders; import com.passus.net.http.HttpMessage; import com.passus.net.http.HttpRequest; import com.passus.net.http2.Http2FrameEncoder;
--- a/stress-tester/src/main/java/com/passus/st/source/EventSourceConfigurator.java Fri Jun 26 15:35:37 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/source/EventSourceConfigurator.java Mon Jun 29 10:53:53 2020 +0200 @@ -45,6 +45,7 @@ eventSourceNodeDef.validate(rootNode, errors, context); } + @SuppressWarnings("unchecked") @Override public void configure(Configuration config, Errors errors, ConfigurationContext context) { CCompositeNode rootNode = config.getRootNode();
--- a/stress-tester/src/test/java/com/passus/st/source/PcapSessionEventSourceTest.java Fri Jun 26 15:35:37 2020 +0200 +++ b/stress-tester/src/test/java/com/passus/st/source/PcapSessionEventSourceTest.java Mon Jun 29 10:53:53 2020 +0200 @@ -5,6 +5,7 @@ import com.passus.net.dns.session.DnsUdpSessionAnalyzer; import com.passus.net.http.HttpRequest; import com.passus.net.http.HttpResponse; +import com.passus.net.http2.session.Http2SessionAnalyzer; import com.passus.net.netflow.Netflow5; import com.passus.net.netflow.NetflowUdpSessionAnalyzer; import com.passus.net.pgsql.PgSqlMessage; @@ -21,6 +22,7 @@ import java.util.Iterator; import static org.testng.Assert.assertTrue; +import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertNull; /** @@ -83,6 +85,38 @@ } @Test(enabled = true) + public void testProcessHttp2() throws Exception { + File pcapFile = ResourceUtils.getFile("pcap/http2/http2_h2c_prior.pcap"); + Http2SessionAnalyzer analyzer = new Http2SessionAnalyzer(); + analyzer.getPortsRange().add(8090); + + PcapSessionEventSource src = new PcapSessionEventSource(); + src.addAnalyzer(analyzer); + src.setName("pcapSource"); + src.setLoops(1); + src.setPcapFile(pcapFile.getAbsolutePath()); + + ArrayListEventHandler handler = new ArrayListEventHandler(); + src.setHandler(handler); + + src.start(); + waitForSource(src); + src.stop(); + + SessionPayloadEvent payloadEvent = (SessionPayloadEvent) handler.findFirst(SessionPayloadEvent.TYPE); + + assertTrue(payloadEvent.getRequest() instanceof HttpRequest); + assertTrue(payloadEvent.getResponse() instanceof HttpResponse); + + assertEquals(2, ((HttpRequest) payloadEvent.getRequest()).getVersion()); + assertEquals(2, ((HttpResponse) payloadEvent.getResponse()).getVersion()); + + assertTrue(handler.get(handler.size() - 3) instanceof SessionStatusEvent); + assertTrue(handler.get(handler.size() - 2) instanceof DataLoopEnd); + assertTrue(handler.get(handler.size() - 1) instanceof DataEnd); + } + + @Test(enabled = true) public void testProcessHttpOnlyRequest() throws Exception { File pcapFile = ResourceUtils.getFile("pcap/http/http_req_rst.pcap"); PcapSessionEventSource src = new PcapSessionEventSource();