Mercurial > stress-tester
changeset 970:b0e26fb79c3a
PcapSessionEventSource - Netflow integration
author | Devel 2 |
---|---|
date | Fri, 19 Jul 2019 14:56:06 +0200 |
parents | 7b4dfce62a6b |
children | b429501707ca |
files | stress-tester/src/main/java/com/passus/st/source/PcapNetflowSessionAnalyzerHook.java stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java stress-tester/src/main/java/com/passus/st/source/PcapUnidirectionalAnalyzerListener.java stress-tester/src/test/java/com/passus/st/source/PcapSessionEventSourceTest.java stress-tester/src/test/resources/pcap/netflow/netflow_v5.pcap stress-tester/src/test/resources/pcap/netflow/netflow_v9_template_data.pcap |
diffstat | 6 files changed, 78 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/main/java/com/passus/st/source/PcapNetflowSessionAnalyzerHook.java Fri Jul 19 14:56:06 2019 +0200 @@ -0,0 +1,29 @@ +package com.passus.st.source; + +import com.passus.net.netflow.NetflowUdpSessionAnalyzer; +import com.passus.net.session.SessionAnalyzer; + +public class PcapNetflowSessionAnalyzerHook extends PcapSessionAnalyzerHook { + + @Override + public boolean supports(Class<? extends SessionAnalyzer> clazz) { + return NetflowUdpSessionAnalyzer.class.isAssignableFrom(clazz); + } + + @Override + protected void doAttach(SessionAnalyzer analyzer, PcapSessionAnalyzerHookContext context) { + PcapUnidirectionalAnalyzerListener listener = new PcapUnidirectionalAnalyzerListener(context.getSourceName(), + context.getEventHandler(), + context.isCollectMetric(), + context.getMetric()); + analyzer.setListener(listener); + + context.getUdpProcessor().addAnalyzer(analyzer); + } + + @Override + protected void doDetach(SessionAnalyzer analyzer, PcapSessionAnalyzerHookContext context) { + analyzer.setListener(null); + context.getUdpProcessor().removeAnalyzer(analyzer); + } +} \ No newline at end of file
--- a/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java Fri Jul 19 13:22:22 2019 +0200 +++ b/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java Fri Jul 19 14:56:06 2019 +0200 @@ -91,6 +91,7 @@ hooks.add(new PcapHttpSessionAnalyzerHook()); hooks.add(new PcapDnsSessionAnalyzerHook()); + hooks.add(new PcapNetflowSessionAnalyzerHook()); analyzers.add(new HttpSessionAnalyzer()); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/main/java/com/passus/st/source/PcapUnidirectionalAnalyzerListener.java Fri Jul 19 14:56:06 2019 +0200 @@ -0,0 +1,17 @@ +package com.passus.st.source; + +import com.passus.net.session.SessionContext; +import com.passus.st.client.EventHandler; + +public class PcapUnidirectionalAnalyzerListener<T> extends BaseSessionAnalyzerListener<T> { + + public PcapUnidirectionalAnalyzerListener(String sourceName, EventHandler eventHandler, + boolean collectMetric, PcapSessionEventSourceMetric metric) { + super(sourceName, eventHandler, collectMetric, metric); + } + + @Override + public void onMessageReceived(SessionContext context, T packet, long timestamp) { + firePayloadEvent(packet, null, context, timestamp); + } +}
--- a/stress-tester/src/test/java/com/passus/st/source/PcapSessionEventSourceTest.java Fri Jul 19 13:22:22 2019 +0200 +++ b/stress-tester/src/test/java/com/passus/st/source/PcapSessionEventSourceTest.java Fri Jul 19 14:56:06 2019 +0200 @@ -5,6 +5,8 @@ import com.passus.net.dns.session.DnsUdpSessionAnalyzer; import com.passus.net.http.HttpRequest; import com.passus.net.http.HttpResponse; +import com.passus.net.netflow.Netflow5; +import com.passus.net.netflow.NetflowUdpSessionAnalyzer; import com.passus.st.client.ArrayListEventHandler; import com.passus.st.client.DataEvents.DataEnd; import com.passus.st.client.DataEvents.DataLoopEnd; @@ -16,6 +18,7 @@ import java.io.File; import static org.testng.Assert.assertTrue; +import static org.testng.AssertJUnit.assertNull; /** * @author Mirosław Hawrot @@ -46,7 +49,7 @@ } @Test(enabled = true) - public void testProcess_TimeOrder() throws Exception { + public void testProcessTimeOrder() throws Exception { doAssetsOrder("pcap/http/amb.new.pcap"); doAssetsOrder("pcap/http/ndiag-login-fresh.pcap"); } @@ -100,6 +103,33 @@ assertTrue(handler.get(handler.size() - 1) instanceof DataEnd); } + @Test(enabled = true) + public void testProcessNetflow5Udp() throws Exception { + NetflowUdpSessionAnalyzer analyzer = new NetflowUdpSessionAnalyzer(); + analyzer.getPortsRange().add(2055); + + File pcapFile = ResourceUtils.getFile("pcap/netflow/netflow_v5.pcap"); + 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 Netflow5); + assertNull(payloadEvent.getResponse()); + + assertTrue(handler.get(handler.size() - 1) instanceof DataEnd); + } + public static void waitForSource(PcapSessionEventSource src) { try { Thread.sleep(200);