changeset 825:a8fbdb409d7c

PcapEventSource configuration, EventSourceNodeDefCreator
author Devel 2
date Thu, 18 Jan 2018 15:51:15 +0100
parents 28ec5d69ea33
children 25efe989a99f
files stress-tester/src/main/java/com/passus/st/source/EventSourceNodeDefCreator.java stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java
diffstat 2 files changed, 48 insertions(+), 11 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/EventSourceNodeDefCreator.java	Thu Jan 18 15:51:15 2018 +0100
@@ -0,0 +1,22 @@
+package com.passus.st.source;
+
+import com.passus.config.schema.DynaKeyValueVaryListNodeDefinition;
+import com.passus.config.schema.NodeDefinition;
+import com.passus.config.schema.NodeDefinitionCreator;
+
+public class EventSourceNodeDefCreator implements NodeDefinitionCreator {
+
+    public static NodeDefinition createDef() {
+        return createDef(false);
+    }
+
+    public static NodeDefinition createDef(boolean transformToObject) {
+        return new DynaKeyValueVaryListNodeDefinition("type", EventSourceFactory.getInstance())
+                .setTransformToPluginObject(transformToObject);
+    }
+    
+    @Override
+    public NodeDefinition create() {
+        return createDef();
+    }
+}
--- a/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java	Thu Jan 18 13:21:36 2018 +0100
+++ b/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java	Thu Jan 18 15:51:15 2018 +0100
@@ -6,6 +6,10 @@
 import com.passus.commons.time.CustomTimeGenerator;
 import com.passus.commons.utils.UniqueIdGenerator;
 import com.passus.config.Configuration;
+import com.passus.config.annotations.NodeDefinitionCreate;
+import com.passus.config.schema.NodeDefinition;
+import com.passus.config.schema.NodeDefinitionCreator;
+import com.passus.config.validation.LongValidator;
 import com.passus.net.Frame;
 import com.passus.net.MemoryFrame;
 import com.passus.net.PortRangeSet;
@@ -14,15 +18,10 @@
 import com.passus.net.http.HttpResponse;
 import com.passus.net.http.session.HttpSessionAnalyzer;
 import com.passus.net.http.session.HttpSessionListener;
-import com.passus.net.packet.Ethernet;
-import com.passus.net.packet.FrameDecoder;
-import com.passus.net.packet.Ip;
-import com.passus.net.packet.Ip4;
-import com.passus.net.packet.Packet;
+import com.passus.net.packet.*;
 import com.passus.net.session.SessionContext;
 import com.passus.net.session.SessionKey;
 import com.passus.net.session.TcpSessionProcessor;
-import static com.passus.net.session.TcpSessionProcessorConstants.*;
 import com.passus.net.source.pcap.FrameDecoderImpl;
 import com.passus.st.client.AbstractEvent;
 import com.passus.st.client.DataEvents.DataEnd;
@@ -37,19 +36,24 @@
 import com.passus.st.plugin.PluginConstants;
 import com.passus.st.reader.pcap.PcapDataBlock;
 import com.passus.st.reader.pcap.PcapDataBlockReader;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.TimeUnit;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
+
+import static com.passus.config.schema.ConfigurationSchemaBuilder.*;
+import static com.passus.net.session.TcpSessionProcessorConstants.STATUS_CLOSE;
+import static com.passus.net.session.TcpSessionProcessorConstants.STATUS_ESTABLISHED;
 
 /**
- *
  * @author Mirosław Hawrot
  */
+@NodeDefinitionCreate(PcapSessionEventSource.PcapSessionEventSourceNodeDefCreator.class)
 @Plugin(name = PcapSessionEventSource.TYPE, category = PluginConstants.CATEGORY_EVENT_SOURCE)
 public class PcapSessionEventSource implements EventSource, MetricSource {
 
@@ -255,7 +259,7 @@
     }
 
     public void waitForEmptyQueue() throws InterruptedException {
-        while (queue.isEmpty() == false) {
+        while (!queue.isEmpty()) {
             Thread.sleep(100);
         }
     }
@@ -575,7 +579,7 @@
                 sessionInfoStatus = SessionStatusEvent.STATUS_OPENING;
             } else if (status == STATUS_ESTABLISHED) {
                 sessionInfoStatus = SessionStatusEvent.STATUS_ESTABLISHED;
-            } else if (status > STATUS_ESTABLISHED && status != STATUS_CLOSE) {
+            } else if (status != STATUS_CLOSE) {
                 sessionInfoStatus = SessionStatusEvent.STATUS_CLOSING;
             } else {
                 sessionInfoStatus = SessionStatusEvent.STATUS_CLOSED;
@@ -611,4 +615,15 @@
 
     }
 
+    public static class PcapSessionEventSourceNodeDefCreator implements NodeDefinitionCreator {
+
+        @Override
+        public NodeDefinition create() {
+            return mapDef(
+                    tupleDef("pcapFileName", valueDef()),
+                    tupleDef("loops", valueDefInteger().addValidator(LongValidator.GREATER_EQUAL_ZERO)),
+                    tupleDef("loopDelay", valueDefInteger().addValidator(LongValidator.GREATER_EQUAL_ZERO))
+            );
+        }
+    }
 }