Mercurial > stress-tester
changeset 987:3ad47c7456b4
PcapSessionEventSource configuration bugfix
author | Devel 2 |
---|---|
date | Mon, 02 Sep 2019 13:35:00 +0200 |
parents | 2fc3f6154913 |
children | 1e51ad474197 |
files | stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java stress-tester/src/test/java/com/passus/st/config/TestJobConfiguratorTest.java stress-tester/src/test/resources/com/passus/st/config/test_job_custom_pcap_source_analyzers.yml |
diffstat | 3 files changed, 64 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java Mon Aug 19 12:25:05 2019 +0200 +++ b/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java Mon Sep 02 13:35:00 2019 +0200 @@ -2,6 +2,7 @@ import com.passus.commons.Assert; import com.passus.commons.annotations.Plugin; +import com.passus.commons.plugin.PluginFactory; import com.passus.commons.service.Service; import com.passus.commons.service.ServiceException; import com.passus.commons.time.CustomTimeGenerator; @@ -17,7 +18,10 @@ import com.passus.net.MemoryFrame; import com.passus.net.dns.session.DnsUdpSessionAnalyzer; import com.passus.net.http.session.HttpSessionAnalyzer; +import com.passus.net.mysql.MySqlTcpSessionAnalyzer; +import com.passus.net.netflow.NetflowUdpSessionAnalyzer; import com.passus.net.packet.*; +import com.passus.net.pgsql.PgSqlTcpSessionAnalyzer; import com.passus.net.session.SessionAnalyzer; import com.passus.net.session.TcpSessionProcessor; import com.passus.net.session.UdpSessionProcessor; @@ -506,9 +510,12 @@ @Override public NodeDefinition create() { - Map<String, NodeDefinitionCreator> analyzersNodeDefs = new HashMap<>(); - analyzersNodeDefs.put("http", new HttpSessionAnalyzer.HttpSessionAnalyzerNodeDefCreator()); - analyzersNodeDefs.put("dns", new DnsUdpSessionAnalyzer.DnsUdpSessionAnalyzerNodeDefCreator()); + PluginFactory<SessionAnalyzer> pf = new PluginFactory<>(); + pf.add("http", HttpSessionAnalyzer.class); + pf.add("dns", DnsUdpSessionAnalyzer.class); + pf.add("netflow", NetflowUdpSessionAnalyzer.class); + pf.add("pgsql", PgSqlTcpSessionAnalyzer.class); + pf.add("mysql", MySqlTcpSessionAnalyzer.class); MapNodeDefinition sessionProcDef = mapDef( tupleDef("tcp", mapDef( @@ -522,7 +529,9 @@ tupleDef("loopDelay", valueDefLong().addValidator(LongValidator.GREATER_EQUAL_ZERO)).setRequired(false), tupleDef("sessionProc", sessionProcDef).setRequired(false), tupleDef("collectMetrics", valueDefBool()).setRequired(false), - tupleDef("analyzers", dynaKeyValueVaryListDef("type", analyzersNodeDefs).setTransformToPluginObject(true)).setRequired(false) + tupleDef("analyzers", + dynaKeyValueVaryListDef("type", pf).setTransformToPluginObject(true) + ).setRequired(false) ); } }
--- a/stress-tester/src/test/java/com/passus/st/config/TestJobConfiguratorTest.java Mon Aug 19 12:25:05 2019 +0200 +++ b/stress-tester/src/test/java/com/passus/st/config/TestJobConfiguratorTest.java Mon Sep 02 13:35:00 2019 +0200 @@ -8,11 +8,18 @@ import com.passus.config.validation.Errors; import com.passus.filter.UnmutableValueExtractor; import com.passus.filter.ValueExtractor; +import com.passus.net.PortRangeSet; +import com.passus.net.dns.session.DnsUdpSessionAnalyzer; +import com.passus.net.http.session.HttpSessionAnalyzer; +import com.passus.net.session.SessionAnalyzer; +import com.passus.net.type.NetType; import com.passus.st.client.FlowExecutor; import com.passus.st.source.EventSource; import com.passus.st.source.NcEventSource; import com.passus.st.source.PcapSessionEventSource; import com.passus.st.utils.ConfigurationContextConsts; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import java.io.File; @@ -25,6 +32,16 @@ private Errors errors = new Errors(); + @BeforeClass + public void beforeClass() { + NetType.registerAll(); + } + + @AfterClass + public void afterClass() { + NetType.unregisterAll(); + } + @Test public void testConfigure() throws Exception { File configFile = ResourceUtils.getFile("com/passus/st/config/test_job_config.yml"); @@ -49,4 +66,28 @@ UnmutableValueExtractor value = (UnmutableValueExtractor) vars.get("varName"); assertEquals("varValue", value.getValue()); } + + @Test + public void testConfigure_CustomPcapSourceAnalyzers() throws Exception { + File configFile = ResourceUtils.getFile("com/passus/st/config/test_job_custom_pcap_source_analyzers.yml"); + Configuration config = YamlConfigurationReader.readFromFile(configFile); + + TestJobConfigurator configurator = new TestJobConfigurator(); + ConfigurationContext context = new ConfigurationContextImpl(); + configurator.configure(config, errors, context); + assertFalse(errors.hasError()); + + List<EventSource> sources = context.get(ConfigurationContextConsts.EVENT_SOURCE_SOURCES); + assertEquals(1, sources.size()); + PcapSessionEventSource source = (PcapSessionEventSource) sources.get(0); + + List<SessionAnalyzer> analyzers = source.getAnalyzers(); + HttpSessionAnalyzer httpAnalyzer = (HttpSessionAnalyzer) analyzers.get(0); + PortRangeSet portRanges = new PortRangeSet(); + portRanges.add(801); + portRanges.add(8081); + assertEquals(portRanges, httpAnalyzer.getPortsRange()); + + assertTrue(analyzers.get(1) instanceof DnsUdpSessionAnalyzer); + } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/test/resources/com/passus/st/config/test_job_custom_pcap_source_analyzers.yml Mon Sep 02 13:35:00 2019 +0200 @@ -0,0 +1,10 @@ +eventSource: + sources: + - type: pcap + fileName: /test.pcap + loops: 1 + analyzers: + - type: http + ports: [801, 8081] + + - type: dns