summaryrefslogtreecommitdiffstats
path: root/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector
diff options
context:
space:
mode:
Diffstat (limited to 'Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector')
-rw-r--r--Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/.gitignore8
-rw-r--r--Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/pom.xml60
-rw-r--r--Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/main/java/de/fhg/fokus/net/ipfix/IpfixCollector.java345
-rw-r--r--Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/main/java/de/fhg/fokus/net/util/EventSupport.java199
-rw-r--r--Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/main/java/de/fhg/fokus/net/util/package.html3
-rw-r--r--Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/main/resources/log4j.properties26
-rw-r--r--Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/test/java/de/fhg/fokus/net/ipfix/IpfixCollectorTest.java71
-rw-r--r--Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/test/java/de/fhg/fokus/net/ipfix/record/IpfixRecordFlow4.java138
-rw-r--r--Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/test/java/de/fhg/fokus/net/ipfix/record/IpfixRecordSourceIpv4PacketDeltaCount.java94
-rw-r--r--Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/test/resources/log4j.properties26
10 files changed, 970 insertions, 0 deletions
diff --git a/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/.gitignore b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/.gitignore
new file mode 100644
index 0000000..a351a86
--- /dev/null
+++ b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/.gitignore
@@ -0,0 +1,8 @@
+.svn
+*.log
+.classpath
+.project
+.settings/*
+target/*
+bin/*
+logs/*
diff --git a/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/pom.xml b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/pom.xml
new file mode 100644
index 0000000..543c74c
--- /dev/null
+++ b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/pom.xml
@@ -0,0 +1,60 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>de.fhg.fokus.net</groupId>
+ <artifactId>ipfix-collector</artifactId>
+ <name>IPFIX Collector</name>
+ <version>0.9-SNAPSHOT</version>
+ <distributionManagement>
+ <repository>
+ <id>pt</id>
+ <url>${pt.releases.repo.url}</url>
+ </repository>
+ <snapshotRepository>
+ <id>pt</id>
+ <url>${pt.snapshots.repo.url}</url>
+ </snapshotRepository>
+ <site>
+ <id>pt-site</id>
+ <url>${pt.sites.deploy.url}</url>
+ </site>
+ </distributionManagement>
+ <dependencies>
+ <dependency>
+ <groupId>de.fhg.fokus.net</groupId>
+ <artifactId>ipfix-api</artifactId>
+ <version>0.9-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.5.6</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.5.6</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.7</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project> \ No newline at end of file
diff --git a/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/main/java/de/fhg/fokus/net/ipfix/IpfixCollector.java b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/main/java/de/fhg/fokus/net/ipfix/IpfixCollector.java
new file mode 100644
index 0000000..2f2879b
--- /dev/null
+++ b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/main/java/de/fhg/fokus/net/ipfix/IpfixCollector.java
@@ -0,0 +1,345 @@
+/**
+*
+* Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project
+* Copyright according to BSD License
+* For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt
+*
+* @author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS
+* @author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin
+* @author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS
+* @author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS
+*
+*/
+
+package de.fhg.fokus.net.ipfix;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import de.fhg.fokus.net.ipfix.api.IpfixCollectorListener;
+import de.fhg.fokus.net.ipfix.api.IpfixConnectionHandler;
+import de.fhg.fokus.net.ipfix.api.IpfixDataRecordReader;
+import de.fhg.fokus.net.ipfix.api.IpfixDefaultTemplateManager;
+import de.fhg.fokus.net.ipfix.api.IpfixHeader;
+import de.fhg.fokus.net.ipfix.api.IpfixMessage;
+import de.fhg.fokus.net.ipfix.api.IpfixSet;
+import de.fhg.fokus.net.ipfix.api.IpfixTemplateManager;
+import de.fhg.fokus.net.ipfix.util.ByteBufferUtil;
+
+/**
+ * <p>
+ * IPFIX Collector
+ * </p>
+ *
+ *
+ * @author FhG-FOKUS NETwork Research
+ *
+ */
+public final class IpfixCollector {
+ // -- sys --
+ private final Logger logger = LoggerFactory.getLogger(getClass());
+ // TODO used multiple tread pools
+ private ExecutorService executor = Executors.newCachedThreadPool();
+
+ // -- ctrl --
+ private final IpfixDefaultTemplateManager templateManager = new IpfixDefaultTemplateManager();
+
+ // -- model --
+ private CopyOnWriteArrayList<IpfixCollectorListener> eventListeners = new CopyOnWriteArrayList<IpfixCollectorListener>();
+ private CopyOnWriteArrayList<ConnectionHandler> clients = new CopyOnWriteArrayList<ConnectionHandler>();
+ private CopyOnWriteArrayList<ServerSocket> servers = new CopyOnWriteArrayList<ServerSocket>();
+ private enum CollectorEvents {
+ CONNECTED,
+ DISCONNECTED,
+ MESSAGE
+ }
+ /**
+ * A helper to dispatch events.
+ *
+ * @param evt
+ * @param handler
+ * @param msg
+ */
+ private void dispatchEvent( CollectorEvents evt, final IpfixConnectionHandler handler, final IpfixMessage msg ){
+ switch (evt) {
+ case CONNECTED:
+ for (final IpfixCollectorListener lsn : eventListeners) {
+ executor.execute(new Runnable() {
+ @Override
+ public void run() {
+ lsn.onConnect(handler);
+ }
+ });
+ }
+ break;
+ case DISCONNECTED:
+ for (final IpfixCollectorListener lsn : eventListeners) {
+ executor.execute(new Runnable() {
+ @Override
+ public void run() {
+ lsn.onDisconnect(handler);
+ }
+ });
+ }
+ break;
+ case MESSAGE:
+ for (final IpfixCollectorListener lsn : eventListeners) {
+ executor.execute(new Runnable() {
+ @Override
+ public void run() {
+ lsn.onMessage(handler, msg);
+ }
+ });
+ }
+ break;
+ default:
+ logger.warn("Unsupported event: {}",evt);
+ break;
+ }
+ }
+ /**
+ * Connection handler
+ *
+ */
+ private class ConnectionHandler implements IpfixConnectionHandler {
+ // -- constants --
+ // -- model --
+ private final Socket socket;
+ private boolean exit = false;
+ private volatile Object attachment;
+ private long totalReceivedMessages=0;
+ // -- aux --
+ private ByteBuffer prevBuffer = null;
+ // save remote address for disconnect event
+ private SocketAddress remoteAddress =null;
+ public ConnectionHandler(Socket socket){
+ this.socket = socket;
+
+ }
+ /**
+ * Starts handler, this will block thread until finished.
+ *
+ * @throws IOException
+ */
+ public void start() throws IOException {
+ if(socket.isConnected()){
+ remoteAddress = socket.getRemoteSocketAddress();
+ dispatchEvent(CollectorEvents.CONNECTED, this, null);
+ }
+ InputStream in = socket.getInputStream();
+ byte[] bbuf = new byte[1024];
+ // ByteBuffer byteBuffer;
+ while (!exit) {
+ int nbytes = in.read(bbuf);
+ if (nbytes > 0) {
+// logger.debug("==> nbytes: {}",nbytes);
+ ByteBuffer byteBuffer = ByteBuffer.allocate(nbytes);
+ byteBuffer.put(bbuf, 0, nbytes).flip();
+
+ // handle previous read
+ if( prevBuffer !=null ){
+ byteBuffer = ByteBufferUtil.concat( prevBuffer, byteBuffer );
+ prevBuffer=null;
+ }
+ if( !IpfixMessage.enoughData(byteBuffer)){
+ prevBuffer=byteBuffer;
+ continue;
+ }
+
+ // Reading IPFIX messages
+ while (IpfixMessage.align(byteBuffer)) {
+ int pos = byteBuffer.position();
+ if(IpfixHeader.getLength(byteBuffer,pos) + pos > byteBuffer.limit() ){
+ // message was still not entirely received
+// logger.debug("message was not entirely received, waiting for more data, buffer.pos:{}",byteBuffer.position());
+// logger.debug("msg len:{}, buffer.limit:{}",IpfixHeader.getLength(byteBuffer,pos),
+// byteBuffer.limit());
+ prevBuffer=byteBuffer;
+ break;
+ }
+
+ final IpfixMessage msg = new IpfixMessage(
+ IpfixCollector.this.templateManager, byteBuffer);
+ totalReceivedMessages++;
+// logger.debug("msg: "+HexDump.toHexString(msg.getMessageBuffer()));
+// dispatch message to listeners
+ dispatchEvent(CollectorEvents.MESSAGE, this, msg);
+ }
+ if(byteBuffer.hasRemaining()){
+ prevBuffer=byteBuffer;
+ }
+ }
+ if (nbytes == -1) {
+ logger.debug("No more data available");
+ break;
+ }
+ }
+ }
+
+ public void shutdown() {
+ logger.debug("-- closing {}", socket);
+ try {
+ socket.close();
+ } catch (IOException e) {
+ logger.error(e + "");
+ }
+ }
+
+ @Override
+ public boolean isConnected() {
+ return socket.isConnected();
+ }
+
+ @Override
+ public Socket getSocket() {
+ return socket;
+ }
+
+ @Override
+ public Object getAttachment() {
+ return attachment;
+ }
+
+ @Override
+ public void setAttachment(Object obj) {
+ this.attachment = obj;
+ }
+
+ @Override
+ public long totalReceivedMessages() {
+ return totalReceivedMessages;
+ }
+
+ }
+
+ public void bind(int port) throws IOException {
+ final ServerSocket serverSocket = new ServerSocket(port);
+ servers.add(serverSocket);
+ while (true) {
+ logger.debug("binding to {}",serverSocket);
+ final Socket socket = serverSocket.accept();
+ executor.execute(new Runnable() {
+ @Override
+ public void run() {
+ ConnectionHandler handler = new ConnectionHandler(socket);
+ clients.add(handler);
+ try {
+ handler.start();
+ logger.debug("handler finished normally: {}",socket);
+ } catch (IOException e) {
+ logger.debug(e + "");
+ } finally {
+ dispatchEvent(CollectorEvents.DISCONNECTED, handler, null);
+ }
+ }
+ });
+ }
+ }
+
+ public void shutdow() {
+ logger.info("Closing client sockets");
+ for (ConnectionHandler handler : clients) {
+ handler.shutdown();
+ }
+ logger.info("Closing server sockets");
+ for (ServerSocket serverSocket : servers) {
+ logger.debug("-- closing {}", serverSocket);
+ try {
+ serverSocket.close();
+ } catch (IOException e) {
+ logger.error(e + "");
+ }
+ }
+ executor.shutdown();
+ }
+
+ /**
+ * see
+ * {@link IpfixTemplateManager#registerDataRecordReader(IpfixDataRecordReader)}
+ *
+ */
+ public void registerDataRecordReader(IpfixDataRecordReader reader) {
+ templateManager.registerDataRecordReader(reader);
+ }
+
+ /**
+ * Register a new IPFIX message listener.
+ *
+ * @param lsn
+ */
+ public void addEventListener(IpfixCollectorListener lsn) {
+ eventListeners.add(lsn);
+ }
+
+ /**
+ * Remove a previous registered IPFIX message listener
+ *
+ * @param lsn
+ */
+ public void removeEventListener(IpfixCollectorListener lsn) {
+ eventListeners.remove(lsn);
+ }
+
+ /**
+ * Remove all message listeners
+ */
+ public void removeAllEventListeners() {
+ eventListeners.clear();
+ }
+
+ public static void main(String[] args) throws IOException,
+ InterruptedException {
+
+ IpfixCollector ic = new IpfixCollector();
+
+ // register record readers used in application
+ // ic.registerDataRecordReader(IpfixRecordImpd4e.getReader());
+
+ // add message listener
+ ic.addEventListener(new IpfixCollectorListener() {
+ @Override
+ public void onMessage(IpfixConnectionHandler handler, IpfixMessage msg) {
+ System.out.println("oid: "
+ + msg.getObservationDomainID());
+ // logger.debug(msg+"");
+ for (IpfixSet set : msg) {
+ for (Object rec : set) {
+ System.out.println(rec + "");
+ }
+ }
+ }
+
+ @Override
+ public void onConnect(IpfixConnectionHandler handler) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void onDisconnect(IpfixConnectionHandler handler) {
+ // TODO Auto-generated method stub
+
+ }
+
+ });
+
+ ic.bind(4739);
+ System.out.println("sleeping");
+ Thread.sleep(10000);
+ }
+
+}
diff --git a/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/main/java/de/fhg/fokus/net/util/EventSupport.java b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/main/java/de/fhg/fokus/net/util/EventSupport.java
new file mode 100644
index 0000000..e63dbdc
--- /dev/null
+++ b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/main/java/de/fhg/fokus/net/util/EventSupport.java
@@ -0,0 +1,199 @@
+/**
+*
+* Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project
+* Copyright according to BSD License
+* For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt
+*
+* @author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS
+* @author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin
+* @author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS
+* @author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS
+*
+*/
+
+package de.fhg.fokus.net.util;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.SynchronousQueue;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+/**
+ * A event support with a user supplied executor (PropertyChangeSupport relies on
+ * AWT-EventQueue which we should avoid to used in case we are not dealing with
+ * ui drawing)
+ * <pre>
+ * E - event type (enum)
+ * O - notification type (class)
+ * </pre>
+ *
+ */
+public final class EventSupport<E,O> {
+ private final Logger logger = LoggerFactory.getLogger(getClass());
+ public static interface EventListener<O> {
+ public void onEvent( O e );
+ }
+ public static interface DispatchFuture {
+ /**
+ * Await all events dispatched.
+ *
+ */
+ public void await();
+ }
+ private final Map<E, List<EventListener<O>>> eventLsnMap = new ConcurrentHashMap<E, List<EventListener<O>>>();
+ private final Map<EventListener<O>, E> lsnTypeMap = new ConcurrentHashMap<EventListener<O>, E>();
+
+ private final ExecutorService executor;
+ public EventSupport(ExecutorService executor) {
+ super();
+ this.executor = executor;
+ }
+ /**
+ * Add event listener. In case evt or lsn were null it does nothing.
+ *
+ * @param evt
+ * @param lsn
+ */
+ public void addEventListener( final E evt, final EventListener<O> lsn ){
+ executor.execute(new Runnable() {
+ @Override
+ public void run() {
+ if(evt==null||lsn==null){
+ return;
+ }
+ List<EventListener<O>> lsnList = eventLsnMap.get(evt);
+ if( lsnList==null){
+ // event not yet registered, allocate a list storing listeners
+ lsnList = new CopyOnWriteArrayList<EventListener<O>>();
+ eventLsnMap.put(evt, lsnList);
+ }
+ lsnTypeMap.put(lsn, evt);
+ if(!lsnList.contains(lsn)){
+ lsnList.add(lsn);
+ } else {
+ logger.warn("Listener {} for event {} already added, ignoring it.",lsn.hashCode(),evt);
+ }
+ }
+ });
+ }
+ /**
+ * Remove event listener. If it's already removed it does nothing.
+ * It has O(n) (time) for each event type. In case you have lots of
+ * event listeners of same type, please consider using
+ * removeAllListeners( E evt )
+ *
+ * @param lsn Listener, in case of null it does nothing
+ */
+ public void removeEventListener( EventListener<O> lsn ){
+ if(lsn==null){
+ return;
+ }
+ E evt = lsnTypeMap.get(lsn);
+ if( evt==null){
+ // probably it were already removed, simply return
+ return;
+ }
+ List<EventListener<O>> lsnList = eventLsnMap.get(evt);
+ if( lsnList == null){
+ return;
+ }
+ lsnList.remove(lsn);
+ // deallocate maps in case no more event of this type exist
+ if(lsnList.size()==0){
+ eventLsnMap.remove(lsnList);
+ lsnTypeMap.remove(evt);
+ }
+ }
+ /**
+ * Remove all listeners of input event type
+ *
+ * @param evt
+ */
+ public void removeAllListeners( E evt){
+ List<EventListener<O>> lsnList = eventLsnMap.get(evt);
+ if( lsnList == null){
+ return;
+ }
+ lsnList.clear();
+ eventLsnMap.remove(lsnList);
+ lsnTypeMap.remove(evt);
+ }
+ /**
+ * Remove all listeners, i.e. reset event support
+ */
+ public void removeAllListeners(){
+ eventLsnMap.clear();
+ lsnTypeMap.clear();
+ }
+ /**
+ * Dispatch events
+ *
+ * @param evt
+ * @param obj
+ */
+ public void dispatch( E evt, final O obj){
+ final List<EventListener<O>> lsnList = eventLsnMap.get(evt);
+ if( lsnList==null){
+ return;
+ }
+ executor.execute( new Runnable() {
+ @Override
+ public void run() {
+ for( EventListener<O> lsn: lsnList ){
+ lsn.onEvent(obj);
+ }
+ }
+ });
+ }
+ /**
+ * Dispatch event passing a notification object. It uses one thread per
+ * event type. The user (the one who adds event listeners) is responsible
+ * for creating new threads if needed.
+ *
+ * @param evt
+ * @param obj
+ * @return DispatchFuture
+ *
+ */
+ public DispatchFuture dispatchFuture(final E evt, final O obj ){
+ final BlockingQueue<Object> await = new SynchronousQueue<Object>();
+ DispatchFuture df = new DispatchFuture() {
+ @Override
+ public void await() {
+ if( eventLsnMap.get(evt)==null){
+ // there's no one awaiting for this event
+ return;
+ }
+ try {
+ await.put(this);
+ } catch (InterruptedException e) {
+ logger.debug(e.getMessage());
+ }
+ }
+ };
+ final List<EventListener<O>> lsnList = eventLsnMap.get(evt);
+ if( lsnList==null){
+ await.poll();
+ return df;
+ }
+ executor.execute( new Runnable() {
+ @Override
+ public void run() {
+ for( EventListener<O> lsn: lsnList ){
+ lsn.onEvent(obj);
+ }
+ await.poll();
+ }
+ });
+ return df;
+ }
+}
diff --git a/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/main/java/de/fhg/fokus/net/util/package.html b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/main/java/de/fhg/fokus/net/util/package.html
new file mode 100644
index 0000000..97691ea
--- /dev/null
+++ b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/main/java/de/fhg/fokus/net/util/package.html
@@ -0,0 +1,3 @@
+<html><head></head><body>
+Utilities
+</body></html> \ No newline at end of file
diff --git a/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/main/resources/log4j.properties b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/main/resources/log4j.properties
new file mode 100644
index 0000000..ca0cf05
--- /dev/null
+++ b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/main/resources/log4j.properties
@@ -0,0 +1,26 @@
+# log4j settings
+#
+# The root logger is assigned priority level DEBUG and an appender
+# named rootAppender
+log4j.rootLogger=debug, rootAppender
+
+# Appenders: {FileAppender, ConsoleAppender, .. }
+log4j.appender.rootAppender=org.apache.log4j.ConsoleAppender
+
+# Layouts: {SimpleLayout, PatternLayout, ..}
+log4j.appender.rootAppender.layout=org.apache.log4j.PatternLayout
+
+# log4j.appender.rootAppender.layout.ConversionPattern=%d{MM-dd@HH:mm:ss} %-5p (%13F:%L) %3x - %m%n
+# Ex: 03-04@16:48:36 DEBUG ( App.java:27) - Test1
+
+#log4j.appender.rootAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %C %p [%t] %m (%F:%L) %n
+
+# Ex: 16:49:30,231 DEBUG [main] Test1 (App.java:27)
+log4j.appender.rootAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %5p [%t] %m (%F:%L) %n
+
+
+#log4j.logger.org.mortbay = INFO
+#log4j.logger.org.apache.cxf = OFF
+#log4j.logger.org.springframework = OFF
+
+
diff --git a/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/test/java/de/fhg/fokus/net/ipfix/IpfixCollectorTest.java b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/test/java/de/fhg/fokus/net/ipfix/IpfixCollectorTest.java
new file mode 100644
index 0000000..ddeb714
--- /dev/null
+++ b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/test/java/de/fhg/fokus/net/ipfix/IpfixCollectorTest.java
@@ -0,0 +1,71 @@
+/**
+*
+* Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project
+* Copyright according to BSD License
+* For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt
+*
+* @author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS
+* @author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin
+* @author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS
+* @author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS
+*
+*/
+
+package de.fhg.fokus.net.ipfix;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import de.fhg.fokus.net.ipfix.api.IpfixCollectorListener;
+import de.fhg.fokus.net.ipfix.api.IpfixConnectionHandler;
+import de.fhg.fokus.net.ipfix.api.IpfixMessage;
+import de.fhg.fokus.net.ipfix.api.IpfixSet;
+import de.fhg.fokus.net.ipfix.record.IpfixRecordSourceIpv4PacketDeltaCount;
+
+/**
+ *
+ * @author FhG-FOKUS NETwork Research
+ */
+public class IpfixCollectorTest {
+ private final static Logger logger = LoggerFactory.getLogger(IpfixCollectorTest.class);
+ @Test
+ public void tcpCollector() throws Exception {
+ int sleep = 50;
+ logger.debug("--- IPFIX Collector test ---");
+ logger.debug("Shutting down in {}s",sleep);
+
+ IpfixCollector ic = new IpfixCollector();
+ ic.registerDataRecordReader(IpfixRecordSourceIpv4PacketDeltaCount.getReader());
+ ic.addEventListener(new IpfixCollectorListener() {
+ @Override
+ public void onMessage( IpfixConnectionHandler handler, IpfixMessage msg) {
+ logger.debug(msg+"");
+ for(IpfixSet set: msg){
+ for(Object rec: set){
+ logger.debug(rec+"");
+ }
+ }
+ }
+ @Override
+ public void onConnect(IpfixConnectionHandler hander) {
+ // TODO Auto-generated method stub
+ }
+ @Override
+ public void onDisconnect(IpfixConnectionHandler hander) {
+ // TODO Auto-generated method stub
+ }
+ });
+
+ //ic.bind(4739);
+ //Thread.sleep(sleep*1000);
+ ic.shutdow();
+
+
+ }
+
+}
diff --git a/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/test/java/de/fhg/fokus/net/ipfix/record/IpfixRecordFlow4.java b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/test/java/de/fhg/fokus/net/ipfix/record/IpfixRecordFlow4.java
new file mode 100644
index 0000000..34636f8
--- /dev/null
+++ b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/test/java/de/fhg/fokus/net/ipfix/record/IpfixRecordFlow4.java
@@ -0,0 +1,138 @@
+/**
+*
+* Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project
+* Copyright according to BSD License
+* For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt
+*
+* @author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS
+* @author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin
+* @author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS
+* @author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS
+*
+*/
+
+package de.fhg.fokus.net.ipfix.record;
+
+import java.math.BigInteger;
+import java.net.Inet4Address;
+import java.nio.ByteBuffer;
+
+import de.fhg.fokus.net.ipfix.api.IpfixDataRecordReader;
+import de.fhg.fokus.net.ipfix.api.IpfixMessage;
+import de.fhg.fokus.net.ipfix.api.IpfixTemplateForDataReader;
+import de.fhg.fokus.net.ipfix.model.ie.IpfixIeDestinationIPv4Address;
+import de.fhg.fokus.net.ipfix.model.ie.IpfixIeDestinationTransportPort;
+import de.fhg.fokus.net.ipfix.model.ie.IpfixIeFlowEndMilliseconds;
+import de.fhg.fokus.net.ipfix.model.ie.IpfixIeFlowStartMilliseconds;
+import de.fhg.fokus.net.ipfix.model.ie.IpfixIeIpClassOfService;
+import de.fhg.fokus.net.ipfix.model.ie.IpfixIeOctetDeltaCount;
+import de.fhg.fokus.net.ipfix.model.ie.IpfixIePacketDeltaCount;
+import de.fhg.fokus.net.ipfix.model.ie.IpfixIeProtocolIdentifier;
+import de.fhg.fokus.net.ipfix.model.ie.IpfixIeSourceIPv4Address;
+import de.fhg.fokus.net.ipfix.model.ie.IpfixIeSourceTransportPort;
+
+/**
+ * Record reader for LibIPFIX probe IPv4 flows
+ *
+ * @author FhG-FOKUS NETwork Research
+ *
+ */
+public final class IpfixRecordFlow4 {
+
+ private final BigInteger flowStartMilliseconds;
+ private final BigInteger flowEndMilliseconds;
+ private final Inet4Address sourceIPv4Address;
+ private final Inet4Address destinationIPv4Address;
+ private final int sourceTransportPort;
+ private final int destinationTransportPort;
+ private final short protocolIdentifier;
+ private final short ipClassOfService;
+ private final long packetDeltaCount;
+ private final long octetDeltaCount;
+
+ public IpfixRecordFlow4(BigInteger flowStartMilliseconds,
+ BigInteger flowEndMilliseconds, Inet4Address sourceIPv4Address,
+ Inet4Address destinationIPv4Address, int sourceTransportPort,
+ int destinationTransportPort, short protocolIdentifier,
+ short ipClassOfService, long packetDeltaCount, long octetDeltaCount) {
+
+ this.flowStartMilliseconds = flowStartMilliseconds;
+ this.flowEndMilliseconds = flowEndMilliseconds;
+ this.sourceIPv4Address = sourceIPv4Address;
+ this.destinationIPv4Address = destinationIPv4Address;
+ this.sourceTransportPort = sourceTransportPort;
+ this.destinationTransportPort = destinationTransportPort;
+ this.protocolIdentifier = protocolIdentifier;
+ this.ipClassOfService = ipClassOfService;
+ this.packetDeltaCount = packetDeltaCount;
+ this.octetDeltaCount = octetDeltaCount;
+ }
+
+ @Override
+ public String toString() {
+
+ return String
+ .format(
+ " {flowStartMilliseconds:%s, flowEndMilliseconds:%s, "
+ + "sourceIPv4Address:%s, destinationIPv4Address:%s, "
+ + "sourceTransportPort:%d, destinationTransportPort:%d, "
+ + "protocolIdentifier:%d, ipClassOfService:%d, "
+ + "packetDeltaCount:%d, octetDeltaCount:%d}",
+ flowStartMilliseconds, flowEndMilliseconds,
+ sourceIPv4Address, destinationIPv4Address,
+ sourceTransportPort, destinationTransportPort,
+ protocolIdentifier, ipClassOfService,
+ packetDeltaCount, octetDeltaCount);
+ }
+
+ private static final IpfixDataRecordReader reader = new IpfixDataRecordReader() {
+ private final IpfixIeFlowStartMilliseconds f0 = new IpfixIeFlowStartMilliseconds(
+ 8);
+ private final IpfixIeFlowEndMilliseconds f1 = new IpfixIeFlowEndMilliseconds(
+ 8);
+ private final IpfixIeSourceIPv4Address f2 = new IpfixIeSourceIPv4Address(
+ 4);
+ private final IpfixIeDestinationIPv4Address f3 = new IpfixIeDestinationIPv4Address(
+ 4);
+ private final IpfixIeSourceTransportPort f4 = new IpfixIeSourceTransportPort(
+ 2);
+ private final IpfixIeDestinationTransportPort f5 = new IpfixIeDestinationTransportPort(
+ 2);
+ private final IpfixIeProtocolIdentifier f6 = new IpfixIeProtocolIdentifier();
+ private final IpfixIeIpClassOfService f7 = new IpfixIeIpClassOfService();
+ private final IpfixIePacketDeltaCount f8 = new IpfixIePacketDeltaCount(
+ 4);
+ private final IpfixIeOctetDeltaCount f9 = new IpfixIeOctetDeltaCount(4);
+
+ private final IpfixTemplateForDataReader template = new IpfixTemplateForDataReader(
+ f0, f1, f2, f3, f4, f5, f6, f7, f8, f9);
+
+ @Override
+ public Object getRecord(IpfixMessage msg, ByteBuffer setBuffer) {
+ if (!setBuffer.hasRemaining()) {
+ return null;
+ }
+ return new IpfixRecordFlow4(f0.getBigInteger(setBuffer), f1
+ .getBigInteger(setBuffer), f2.getAddress(setBuffer), f3
+ .getAddress(setBuffer), f4.getInt(setBuffer), f5
+ .getInt(setBuffer), f6.getShort(setBuffer), f7
+ .getShort(setBuffer), f8.getLong(setBuffer), f9
+ .getLong(setBuffer));
+ }
+ public String toString() {
+ return "DRR(record flow 4)";
+ }
+ @Override
+ public IpfixTemplateForDataReader getTemplate() {
+ return template;
+ }
+ };
+ public final static IpfixDataRecordReader getReader(){
+ return reader;
+ }
+
+}
diff --git a/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/test/java/de/fhg/fokus/net/ipfix/record/IpfixRecordSourceIpv4PacketDeltaCount.java b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/test/java/de/fhg/fokus/net/ipfix/record/IpfixRecordSourceIpv4PacketDeltaCount.java
new file mode 100644
index 0000000..7639ee2
--- /dev/null
+++ b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/test/java/de/fhg/fokus/net/ipfix/record/IpfixRecordSourceIpv4PacketDeltaCount.java
@@ -0,0 +1,94 @@
+/**
+*
+* Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project
+* Copyright according to BSD License
+* For full text of the license see: ./novi/Software/Monitoring/MonitoringTool/PacketTracking/license.txt
+*
+* @author <a href="mailto:ramon.masek@fokus.fraunhofer.de">Ramon Masek</a>, Fraunhofer FOKUS
+* @author <a href="mailto:c.henke@tu-berlin.de">Christian Henke</a>, Technical University Berlin
+* @author <a href="mailto:carsten.schmoll@fokus.fraunhofer.de">Carsten Schmoll</a>, Fraunhofer FOKUS
+* @author <a href="mailto:Julian.Vetter@campus.tu-berlin.de">Julian Vetter</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Jens Krenzin</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Michael Gehring</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Tacio Grespan Santos</a>, Fraunhofer FOKUS
+* @author <a href="mailto:">Fabian Wolff</a>, Fraunhofer FOKUS
+*
+*/
+
+package de.fhg.fokus.net.ipfix.record;
+
+import java.math.BigInteger;
+import java.net.Inet4Address;
+import java.nio.ByteBuffer;
+
+import de.fhg.fokus.net.ipfix.api.IpfixDataRecordReader;
+import de.fhg.fokus.net.ipfix.api.IpfixMessage;
+import de.fhg.fokus.net.ipfix.api.IpfixTemplateForDataReader;
+import de.fhg.fokus.net.ipfix.model.ie.IpfixIePacketDeltaCount;
+import de.fhg.fokus.net.ipfix.model.ie.IpfixIeSourceIPv4Address;
+
+/**
+ *
+ * @author FhG-FOKUS NETwork Research
+ *
+ */
+public class IpfixRecordSourceIpv4PacketDeltaCount {
+ private final Inet4Address sourceIpv4Address;
+ private final BigInteger packetDeltaCount;
+
+ public IpfixRecordSourceIpv4PacketDeltaCount(
+ Inet4Address sourceIpv4Address, BigInteger packetDeltaCount) {
+ super();
+ this.sourceIpv4Address = sourceIpv4Address;
+ this.packetDeltaCount = packetDeltaCount;
+ }
+
+ public Inet4Address getSourceIpv4Address() {
+ return sourceIpv4Address;
+ }
+
+ public BigInteger getPacketDeltaCount() {
+ return packetDeltaCount;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("{sourceIpv4Address:%s, packetDeltaCount:%d}",
+ sourceIpv4Address, packetDeltaCount);
+ }
+
+ /**
+ * IPFIX data record reader for
+ * {@link IpfixRecordSourceIpv4PacketDeltaCount }
+ */
+ private static final IpfixDataRecordReader reader = new IpfixDataRecordReader() {
+ private final IpfixIeSourceIPv4Address sourceIpv4Address = new IpfixIeSourceIPv4Address();
+ private final IpfixIePacketDeltaCount packetDeltaCount = new IpfixIePacketDeltaCount(4);
+ private final IpfixTemplateForDataReader template = new IpfixTemplateForDataReader(
+ sourceIpv4Address, packetDeltaCount);
+
+ @Override
+ public IpfixRecordSourceIpv4PacketDeltaCount getRecord( IpfixMessage msg,
+ ByteBuffer setBuffer) {
+
+ if (!setBuffer.hasRemaining()) {
+ return null;
+ }
+ return new IpfixRecordSourceIpv4PacketDeltaCount(
+ sourceIpv4Address.getAddress(setBuffer),
+ packetDeltaCount.getBigInteger(setBuffer));
+
+ }
+ public String toString() {
+ return "DRR(sourceIPv4_packetDeltaCount)";
+ }
+ @Override
+ public IpfixTemplateForDataReader getTemplate() {
+ return template;
+ }
+ };
+ public final static IpfixDataRecordReader getReader(){
+ return reader;
+ }
+
+}
diff --git a/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/test/resources/log4j.properties b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/test/resources/log4j.properties
new file mode 100644
index 0000000..ca0cf05
--- /dev/null
+++ b/Monitoring/MonitoringTool/PacketTracking/ipfix4java/ipfix-collector/src/test/resources/log4j.properties
@@ -0,0 +1,26 @@
+# log4j settings
+#
+# The root logger is assigned priority level DEBUG and an appender
+# named rootAppender
+log4j.rootLogger=debug, rootAppender
+
+# Appenders: {FileAppender, ConsoleAppender, .. }
+log4j.appender.rootAppender=org.apache.log4j.ConsoleAppender
+
+# Layouts: {SimpleLayout, PatternLayout, ..}
+log4j.appender.rootAppender.layout=org.apache.log4j.PatternLayout
+
+# log4j.appender.rootAppender.layout.ConversionPattern=%d{MM-dd@HH:mm:ss} %-5p (%13F:%L) %3x - %m%n
+# Ex: 03-04@16:48:36 DEBUG ( App.java:27) - Test1
+
+#log4j.appender.rootAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %C %p [%t] %m (%F:%L) %n
+
+# Ex: 16:49:30,231 DEBUG [main] Test1 (App.java:27)
+log4j.appender.rootAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %5p [%t] %m (%F:%L) %n
+
+
+#log4j.logger.org.mortbay = INFO
+#log4j.logger.org.apache.cxf = OFF
+#log4j.logger.org.springframework = OFF
+
+