Commit d58b8195 authored by Ricardo Fonseca's avatar Ricardo Fonseca

Initial commit

parents
*/target
**/*.pyc
network-visualiser/catalina/logs
network-visualiser/catalina/webapps/visualiser
network-visualiser/catalina/work
This diff is collapsed.
## varanus: _A set of applications for providing resilient communications in a Software-Defined Network_
#### Overview
TODO
#### Requisites
For all applications:
- 64-bit Linux-based operating system with a bash shell
For the sdncontroller and collector applications:
- Java (8 or higher) for building and running the applications
- Ant build tool for building the applications
- Libpcap for running the collector application
For the network-manager application:
- Mininet (v.2.2.2 or higher) for running the application
- Open vSwitch (v2.5 or higher) for managing software switches in the local machine
For the network-visualiser application:
- Tomcat (v8.5 or higher) for running the local server
- Java (8 or higher) for running the tomcat server and for building and running the xml-proxy
- Web browser with enabled JavaScript for interacting with the application
#### Demo instructions
Build all Java applications:
<big><pre>
$ cd &lt;repository directory&gt;
$ ant pack-all
</pre></big>
Open a terminal and launch the network manager:
<big><pre>
$ cd &lt;repository directory&gt;
$ ./demo/launch\_network.sh
</pre></big>
Open another terminal and launch the network visualiser:
<big><pre>
$ cd &lt;repository directory&gt;
$ ./demo/launch\_visualiser.sh
</pre></big>
Open a web browser and go to 'localhost:8080/visualiser' (default password is "password").
#### Contributors
Ricardo Fonseca
Eric Vial
Nuno Neves
Fernando Ramos
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="help" basedir="." name="varanus">
<include file="sdncontroller/build.xml" as="sdncontroller" />
<include file="collector/build.xml" as="collector" />
<include file="xml-proxy/build.xml" as="xmlproxy" />
<target name="help">
<echo>Specify one of these targets:
compile-sdncontroller : compiles the SDN Controller application
compile-collector : compiles the Collector application
compile-xmlproxy : compiles the XML Proxy application
compile-all : compiles all applications
pack-sdncontroller : compiles and packs the SDN Controller into a jar file
pack-collector : compiles and packs the Collector into a jar file
pack-xmlproxy : compiles and packs the XML Proxy into a jar file
pack-all : compiles and packs all applications
clean-sdncontroller : cleans SDN Controller built files and directories
clean-collector : cleans Collector built files and directories
clean-xmlproxy : cleans XML Proxy built files and directories
clean-all : cleans all applications
</echo>
</target>
<target name="compile-sdncontroller" depends="sdncontroller.compile" />
<target name="compile-collector" depends="collector.compile" />
<target name="compile-xmlproxy" depends="xmlproxy.compile" />
<target name="compile-all" depends="compile-sdncontroller,compile-collector,compile-xmlproxy" />
<target name="pack-sdncontroller" depends="sdncontroller.pack" />
<target name="pack-collector" depends="collector.pack" />
<target name="pack-xmlproxy" depends="xmlproxy.pack" />
<target name="pack-all" depends="pack-sdncontroller,pack-collector,pack-xmlproxy" />
<target name="clean-sdncontroller" depends="sdncontroller.clean" />
<target name="clean-collector" depends="collector.clean" />
<target name="clean-xmlproxy" depends="xmlproxy.clean" />
<target name="clean-all" depends="clean-sdncontroller,clean-collector,clean-xmlproxy" />
</project>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="pack" basedir="." name="varanus-collector">
<!--
When this file is included the basedir property is ignored, this hack is required to retrieve it.
-->
<dirname property="collector.basedir" file="${ant.file.varanus-collector}" />
<property name="collector.target" location="${collector.basedir}/target" />
<property name="collector.build" location="${collector.target}/bin" />
<property name="collector.src" location="${collector.basedir}/src/main/java" />
<property name="collector.lib" location="${collector.basedir}/lib" />
<property name="collector.jar" location="${collector.target}/varanus-collector.jar" />
<property name="collector.main_class" value="net.varanus.collector.Main" />
<property name="ant.build.javac.source" value="1.8" />
<property name="ant.build.javac.target" value="1.8" />
<include file="${collector.basedir}/../mirroring-protocol/build.xml" as="mirroring" />
<include file="${collector.basedir}/../utils/build.xml" as="utils" />
<include file="${collector.basedir}/../common-lib/build.xml" as="common" />
<patternset id="collector-lib">
<include name="jackson-annotations-2.4.4.jar" />
<include name="jnetpcap-1.4.r1425/jnetpcap.jar" />
<include name="logback-classic-1.0.0.jar" />
<include name="logback-core-1.0.0.jar" />
</patternset>
<path id="collector-classpath">
<fileset dir="${collector.lib}">
<patternset refid="collector-lib" />
</fileset>
<fileset dir="${common.lib}">
<patternset refid="utils-common-lib" />
</fileset>
<pathelement path="${mirroring.build}" />
<pathelement path="${utils.build}" />
</path>
<target name="init" depends="mirroring.init,utils.init">
<mkdir dir="${collector.build}" />
</target>
<target name="compile" depends="init,mirroring.compile,utils.compile">
<javac includeAntRuntime="false"
classpathref="collector-classpath"
debug="true"
srcdir="${collector.src}"
destdir="${collector.build}">
<compilerarg value="-Xlint" />
</javac>
</target>
<target name="clean" depends="mirroring.clean,utils.clean">
<delete dir="${collector.target}" />
</target>
<target name="pack" depends="compile">
<jar destfile="${collector.jar}" filesetmanifest="mergewithoutmain">
<manifest>
<attribute name="Main-Class" value="${collector.main_class}" />
<attribute name="Class-Path" value="." />
</manifest>
<fileset dir="${collector.build}" />
<fileset dir="${mirroring.build}" />
<fileset dir="${utils.build}" />
<zipgroupfileset dir="${collector.lib}" excludes="META-INF/*.SF">
<patternset refid="collector-lib" />
</zipgroupfileset>
<zipgroupfileset dir="${common.lib}" excludes="META-INF/*.SF">
<patternset refid="utils-common-lib" />
</zipgroupfileset>
</jar>
</target>
</project>
# { collector_id : { switch_id : interface } }
switchIfaceMapping={}
# hostname/IP:port
controllerAddress=127.0.0.1:32800
switchAliases={}
# if true, then BSN packets are discarded
ignoreBSNPackets=YES
switchIfaceMapping={"1" : {"0x100000001" : "c1-e1","0x100000002" : "c1-e2","0x100000003" : "c1-e3","0x100000004" : "c1-e4","0x100000005" : "c1-e5","0x100000006" : "c1-e6","0x100000007" : "c1-e7","0x100000008" : "c1-e8","0x100000009" : "c1-e9","0x10000000a" : "c1-e10","0x10000000b" : "c1-e11"}}
controllerAddress=127.0.0.1:32800
switchAliases={"0x100000001" : "Core1","0x100000002" : "A1","0x100000003" : "A2","0x100000004" : "A3","0x100000005" : "Core2","0x100000006" : "Core3","0x100000007" : "B1","0x100000008" : "B2","0x100000009" : "B3","0x10000000a" : "Core4","0x10000000b" : "Core5"}
<configuration scan="true">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date{yyyy-MM-dd HH:mm:ss.S} %-5level [%logger{15}] %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
<logger name="org" level="INFO"/>
<logger name="LogService" level="INFO"/> <!-- Restlet access logging -->
<logger name="net.varanus.collector" level="INFO"/>
<logger name="net.varanus.collector.internal.Collector-sampling" level="INFO"/>
<logger name="net.varanus.collector.internal.Collector-probing" level="INFO"/>
</configuration>
This diff is collapsed.
This diff is collapsed.
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
\ No newline at end of file
This diff is collapsed.
/* Header for analysis_flow utility methods */
#ifndef _Included_analysis_h
#define _Included_analysis_h
#ifdef __cplusplus
extern "C" {
#define EXTERN extern "C"
#endif
#include <stdint.h>
#include <stdint.h>
#include "export.h"
#include <jni.h>
#include "org_jnetpcap_packet_analysis_Analysis.h"
#include "org_jnetpcap_packet_analysis_AnalysisUtils.h"
#define ROOT_TYPE org_jnetpcap_analysis_AnalysisUtils_ROOT_TYPE
/*
* A header for every analysis object
*/
typedef struct analysis_t {
uint16_t type;
uint16_t len; // length so we can walk unknown analysis types
} analysis_t;
/*
* Roots are embeded in packet_state_t and header_state_t objects
*/
typedef struct root_analysis_t {
uint16_t type; // == ROOT_TYPE
uint16_t len; // length so we can walk unknown analysis types
analysis_t *child;
};
typedef void (*native_analyzer_func_t)(packet_state_t *packet);
extern native_analyzer_func_t native_analyzers[];
typedef struct analyzer_t {
native_analyzer_func_t analyzers[64][4];
} analyzer_t;
#ifdef __cplusplus
}
#endif
#endif
// Include this file after jni.h is included. It undefines MS compiler, def for
// gcc specific one.
//
#ifndef Include_export_h
#define Include_export_h
// JNIEXPORT is designed for microsoft compilers, we're using gcc to compile
#ifdef JNIEXPORT
#undef JNIEXPORT
#endif
#undef JNIEXPORT
#define JNIEXPORT extern "C"
#undef __declspec
#define __declspec(a) extern "C"
#ifndef FALSE
#define TRUE 1
#define FALSE !TRUE
#endif
#endif
/* Header for jnetpcap_utils utility methods */
#ifndef _Included_jnetpcap_bpf_h
#define _Included_jnetpcap_bpf_h
#ifdef __cplusplus
extern "C" {
#define EXTERN extern "C"
#endif
#include "export.h"
#include <jni.h>
extern jclass bpfProgramClass;
extern jfieldID bpfProgramPhysicalFID;
// Prototypes
bpf_program *getBpfProgram(JNIEnv *env, jobject obj);
void setBpfProgramPhysical(JNIEnv *env, jobject obj, jlong value);
#ifdef __cplusplus
}
#endif
#endif
#include <jni.h>
/* Header for jnetpcap_dumper methods */
#ifndef _Included_org_jnetpcap_PcapDumper
#define _Included_org_jnetpcap_PcapDumper
#ifdef __cplusplus
extern "C" {
#define EXTERN extern "C"
#endif
extern jclass pcapDumperClass;
extern jclass pcapDumperClass;
extern jmethodID pcapDumperConstructorMID;
extern jfieldID pcapDumperPhysicalFID;
// Prototypes
void setPcapDumper(JNIEnv *env, jobject obj, pcap_dumper_t *dumper);
pcap_dumper_t *getPcapDumper(JNIEnv *env, jobject obj);
jobject newPcapDumper(JNIEnv *env, pcap_dumper_t *dumper);
#ifdef __cplusplus
}
#endif
#endif
/* Header for jnetpcap_utils utility methods */
#ifndef _Included_jnetpcap_ids_h
#define _Included_jnetpcap_ids_h
#include "export.h"
#include <jni.h>
#ifdef __cplusplus
extern "C" {
#define EXTERN extern "C"
#endif
extern jclass pcapClass;
extern jclass byteBufferClass;
extern jclass stringBuilderClass;
extern jclass pcapIfClass;
extern jclass pcapAddrClass;
extern jclass PcapSockAddrClass;
extern jclass pcapIntegerClass;
extern jclass JBufferHandlerClass;
extern jclass ByteBufferHandlerClass;
extern jclass JPacketHandlerClass;
extern jclass PcapPacketHandlerClass;
extern jmethodID byteBufferIsDirectMID;
extern jmethodID bufferGetPositionMID;
extern jmethodID bufferGetLimitMID;
extern jmethodID bufferSetLimitMID;
extern jmethodID bufferSetPositionMID;
extern jmethodID bufferGetPositionMID;
extern jmethodID bufferGetCapacityMID;
extern jmethodID JBufferHandlerNextPacketMID;
extern jmethodID ByteBufferHandlerNextPacketMID;
extern jmethodID JPacketHandlerNextPacketMID;
extern jmethodID PcapPacketHandlerNextPacketMID;
extern jclass msIpAdapterIndexMapClass;
extern jfieldID pcapPhysicalFID;
extern jfieldID pcapIntegerValueFID;
extern jfieldID PcapPktHdrSecondsFID;
extern jfieldID PcapPktHdrUSecondsFID;
extern jfieldID PcapPktHdrCaplenFID;
extern jfieldID PcapPktHdrLenFID;
extern jfieldID PcapPktBufferFID;
extern jfieldID pcapIfNextFID;
extern jfieldID pcapIfNameFID;
extern jfieldID pcapIfDescriptionFID;
extern jfieldID pcapIfAddressesFID;
extern jfieldID pcapIfFlagsFID;
extern jfieldID pcapAddrNextFID;
extern jfieldID pcapAddrAddrFID;
extern jfieldID pcapAddrNetmaskFID;
extern jfieldID pcapAddrBroadaddrFID;
extern jfieldID pcapAddrDstaddrFID;
extern jfieldID PcapSockAddrFamilyFID;
extern jfieldID PcapSockAddrDataFID;
extern jmethodID pcapConstructorMID;
extern jmethodID pcapIfConstructorMID;
extern jmethodID PcapSockAddrConstructorMID;
extern jmethodID pcapAddrConstructorMID;
extern jmethodID msIpAdapterIndexMapMID;
extern jmethodID appendMID;
extern jmethodID setLengthMID;
extern jclass pcapStatClass;
extern jfieldID pcapStatRecvFID;
extern jfieldID pcapStatDropFID;
extern jfieldID pcapStatIfDropFID;
extern jfieldID pcapStatCaptFID;
extern jfieldID pcapStatSentFID;
extern jfieldID pcapStatNetdropFID;
#ifdef __cplusplus
}
#endif
#endif
/* Header for jnetpcap_utils utility methods */
#ifndef _Included_org_jnetpcap_Pcap_utils
#define _Included_org_jnetpcap_Pcap_utils
#ifdef __cplusplus
extern "C" {
#define EXTERN extern "C"
#endif
#include "export.h"
#include <jni.h>
#include "packet_jscanner.h"
/*
* LIBPCAP versions that specify when each feature or function was first
* introduced. The format of the value is a collapsed version number. That is
* Actual libpcap version number 0.9.3 is first collapsed to 093 and then a
* 0x prefixed otherwise compiler complains that its a out-of-range octal value.
* So 0.9.3 becomes 0x093 and for our comparison purposes is sufficient to ensure
* correct libpcap version level.
*/
#define LIBPCAP_PCAP_SENDPACKET 0x093
#define LIBPCAP_PCAP_INJECT 0x097
#define ILLEGAL_STATE_EXCEPTION "java/lang/IllegalStateException"
#define ILLEGAL_ARGUMENT_EXCEPTION "java/lang/IllegalArgumentException"
#define CLASS_NOT_FOUND_EXCEPTION "java/lang/ClassNotFoundException"
#define NO_SUCH_METHOD_EXCEPTION "java/lang/NoSuchMethodException"
#define NO_SUCH_FIELD_EXCEPTION "java/lang/NoSuchFieldException"
#define INDEX_OUT_OF_BOUNDS_EXCEPTION "java/lang/IndexOutOfBoundsException"
#define NULL_PTR_EXCEPTION "java/lang/NullPointerException"
#define UNSUPPORTED_OPERATION_EXCEPTION "java/lang/UnsupportedOperationException"
#define PCAP_CLOSED_EXCEPTION "org/jnetpcap/PcapClosedException"
#define PCAP_EXTENSION_NOT_AVAILABLE_EXCEPTION "org/jnetpcap/PcapExtensionNotAvailableException"
#define OUT_OF_MEMORY_ERROR "java/lang/OutOfMemoryError"
#define BUFFER_OVERFLOW_EXCEPTION "java/nio/BufferOverflowException"
#define BUFFER_UNDERFLOW_EXCEPTION "java/nio/BufferUnderflowException"
#define READ_ONLY_BUFFER_EXCETPION "java/nio/ReadOnlyBufferException"
#define UNREGISTERED_SCANNER_EXCEPTION "org/jnetpcap/packet/UnregisteredHeaderException"
#define IO_EXCEPTION "java/io/IOException"
extern jclass pcapClass;
extern jclass pcapHandlerClass;
extern jclass stringBuilderClass;
extern jfieldID pcapPhysicalFID;
extern jfieldID pcapIfNextFID;
extern jmethodID pcapConstructorMID;
extern jmethodID pcapHandlerMID;
extern jmethodID appendMID;
extern jmethodID setLengthMID;
/* IDs for packet_jpacket.cpp file */
extern jclass pcapPacketClass;
extern jmethodID pcapPacketConstructorMID;
extern jfieldID pcapStateFID;
extern jfieldID pcapHeaderFID;
// GENERIC utilities
const char *toCharArray(JNIEnv *env, jstring jstr, char *buf);
jstring toJavaString(JNIEnv *env, const char *buf);
jlong toLong(void *ptr);
void *toPtr(jlong lp);
jclass getClass(JNIEnv *env, char *clazz);
/*
* PCAP class related utilities
*/
/*
* Structure which holds information for a callback from dispatch and loop.
* Holds enough information so we can callback to Java handler and still return
* the original generic user data object.
*/
typedef struct pcap_user_data_t {
JNIEnv *env;
jobject obj;
jobject pcap;
jobject user;
jclass clazz;
jthrowable exception; // Any exceptions to rethrow
jmethodID mid;
pcap_t *p;
} pcap_user_data_t;
typedef struct cb_byte_buffer_t {
pcap_t *p;
jmethodID mid;
JNIEnv *env; // thread
jobject obj; // ByteBufferHandler
jobject pcap;
jthrowable exception; // Any exceptions to rethrow
jobject user;
jobject header; // PcapHeader
} cb_byte_buffer_t;
typedef struct cb_jbuffer_t {
pcap_t *p;
jmethodID mid;
JNIEnv *env; // thread
jobject obj; // JBufferHandler
jobject pcap;
jthrowable exception; // Any exceptions to rethrow
jobject user;
jobject header; // PcapHeader
jobject buffer; // JBuffer
} cb_jbuffer_t;
#define DEBUG_INJECT_PACKET_BREAK_LOOP 1
typedef struct cb_packet_t {
pcap_t *p;
jmethodID mid;
JNIEnv *env; // thread
jobject obj; // JPacketHandler
jobject pcap;
jthrowable exception; // Any exceptions to rethrow
jobject user;
jobject header; // PcapHeader
jobject packet; // JPacket
jobject state; // JPacket.State
jint id; // Header ID
jobject scanner; // JScanner
int flags; // Flags used when inject packet is used
} cb_jpacket_t;
extern "C"
void pcap_callback(u_char*, const pcap_pkthdr*, const u_char*);
void cb_byte_buffer_dispatch(u_char*, const pcap_pkthdr*, const u_char*);
void cb_jbuffer_dispatch(u_char*, const pcap_pkthdr*, const u_char*);
void cb_pcap_packet_dispatch(u_char*, const pcap_pkthdr*, const u_char*);
void cb_pcap_dumper_handler(u_char*, const pcap_pkthdr*, const u_char*);
pcap_t *getPcap(JNIEnv *env, jobject obj);
jmethodID getPcapHandlerMID(JNIEnv *env);
jfieldID getPcapPhysicalFID(JNIEnv *env, jclass clazz);
jlong getPhysical(JNIEnv *, jobject);
void setPhysical(JNIEnv *, jobject, jlong);
void setString(JNIEnv *env, jobject buffer, const char *);
jmethodID getPcapConstructorMID(JNIEnv *env, jclass clazz);
pcap_pkthdr *getPktHeader(JNIEnv *env, jobject jpkt_header, pcap_pkthdr *pkt_header);
void setPktHeader(JNIEnv *env, jobject jpkt_header, pcap_pkthdr *pkt_header);
void setPktBuffer(JNIEnv *env, jobject jpkt_buffer, jobject jbuffer);
jclass findClass(JNIEnv *env, const char *name);
jmethodID findMethod(JNIEnv *env, jobject obj, const char *name, const char *signature);
jobject newPcapAddr(JNIEnv *env, jobject jlist, jmethodID MID_add, pcap_addr *addr);
jobject newPcapIf(JNIEnv *env, jobject jlist, jmethodID MID_add, pcap_if_t *ifp);
jobject newPcapSockAddr(JNIEnv *env, sockaddr *a);
void setPcapStat(JNIEnv *env, jobject jstats, pcap_stat *stats);
void throwException(JNIEnv *env, const char *exception, const char *message);
void throwVoidException(JNIEnv *env, const char *exception);
/*
* Creates a new PcapPacket object, allocates a new memory block and copies
* header, state and packet data into the buffer. Then peers all the packet
* structures to point at the buffer.
*/
jobject transferToNewBuffer(
JNIEnv *env,
const pcap_pkthdr *pkt_header,
const u_char *pkt_data,
jobject state);
#ifdef __cplusplus
}
#endif
#endif
#ifndef __MAC_ADDR_HDR__
#define __MAC_ADDR_HDR__
extern "C" int mac_addr_dlpi ( char *dev, u_char *addr);
extern "C" int mac_addr_sys ( char *dev, u_char *addr);
#endif
/* Header for jnetpcap_utils utility methods */
#ifndef _Included_nio_jbuffer_h
#define _Included_nio_jbuffer_h
#ifdef __cplusplus
extern "C" {
#define EXTERN extern "C"
#endif
#include "export.h"
#include <jni.h>
/****************************************************************
* **************************************************************
*
* JNI IDs
*
* **************************************************************
****************************************************************/
extern jfieldID jbufferOrderFID;
extern jfieldID jbufferReadonlyFID;
/****************************************************************
* **************************************************************
*
* ENDIAN MACROS - swap bytes for proper endianess
*
* **************************************************************
****************************************************************/
#define ENDIAN16_ATOM_SWAP(data) (\
((((uint16_t)data) >> 8) & 0x00FF) | ((((uint16_t)data) << 8) & 0xFF00))
#define ENDIAN32_ATOM_SWAP(data) (\
( (((uint32_t)data) >> 24) & 0x000000FF) | ((((uint32_t)data) >> 8) & 0x0000FF00) |\
( (((uint32_t)data) << 8) & 0x00FF0000) | ((((uint32_t)data) << 24) & 0xFF000000))
#define ENDIAN64_ATOM_SWAP(data) (\
( (((uint64_t)data) >> 56) & 0x00000000000000FFLLU) | ((((uint64_t)data) >> 40) & 0x000000000000FF00LLU) |\
( (((uint64_t)data) >> 24) & 0x0000000000FF0000LLU) | ((((uint64_t)data) >> 8) & 0x00000000FF000000LLU) |\
( (((uint64_t)data) << 8) & 0x000000FF00000000LLU) | ((((uint64_t)data) << 24) & 0x0000FF0000000000LLU) |\
( (((uint64_t)data) << 40) & 0x00FF000000000000LLU) | ((((uint64_t)data) << 56) & 0xFF00000000000000LLU) \
)
#define ENDIAN16_PTR_SWAP(data) \
((uint16_t)*(data + 0) << 8) | ((uint16_t)*(data + 1))
#define ENDIAN32_PTR_SWAP(data) \
((uint32_t)*(data + 0) << 24) | ((uint32_t)*(data + 3) ) |\
((uint32_t)*(data + 1) << 16) | ((uint32_t)*(data + 2) << 8)
#define ENDIAN64_PTR_SWAP(data) \
((uint64_t)*(data + 0) << 56) | ((uint64_t)*(data + 7) ) |\
((uint64_t)*(data + 1) << 48) | ((uint64_t)*(data + 6) << 8) |\
((uint64_t)*(data + 2) << 40) | ((uint64_t)*(data + 5) << 16) |\
((uint64_t)*(data + 3) << 32) | ((uint64_t)*(data + 4) << 24)
/*
* These macros test for requested BIG ENDIAN condition and appropriately define
* the correct byte swap macro for various CPU ENDIAN platforms.
*
* Usage - if cond is TRUE will ensure that BIG_ENDIAN is returned on both
* LITTLE AND BIG platforms. If cond is FALSE then LITTLE_ENDIAN will be
* returned.
*/
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define ENDIAN16_GET(big, data) ((big == JNI_TRUE)?ENDIAN16_ATOM_SWAP(data):data)
#define ENDIAN32_GET(big, data) ((big == JNI_TRUE)?ENDIAN32_ATOM_SWAP(data):data)
#define ENDIAN64_GET(big, data) ((big == JNI_TRUE)?ENDIAN64_ATOM_SWAP(data):data)
#define BIG_ENDIAN16(data) ENDIAN16_ATOM_SWAP(data)
#define BIG_ENDIAN32(data) ENDIAN32_ATOM_SWAP(data)
#define BIG_ENDIAN64(data) ENDIAN64_ATOM_SWAP(data)
#define LITTLE_ENDIAN16(data) data
#define LITTLE_ENDIAN32(data) data
#define LITTLE_ENDIAN64(data) data
#elif __BYTE_ORDER == __BIG_ENDIAN
#define ENDIAN16_GET(big, data) ((big == JNI_TRUE)?data:ENDIAN16_ATOM_SWAP(data))
#define ENDIAN32_GET(big, data) ((big == JNI_TRUE)?data:ENDIAN32_ATOM_SWAP(data))
#define ENDIAN64_GET(big, data) ((big == JNI_TRUE)?data:ENDIAN64_ATOM_SWAP(data))
#define BIG_ENDIAN16(data) data
#define BIG_ENDIAN32(data) data
#define BIG_ENDIAN64(data) data
#define LITTLE_ENDIAN16(data) ENDIAN16_ATOM_SWAP(data)
#define LITTLE_ENDIAN32(data) ENDIAN32_ATOM_SWAP(data)
#define LITTLE_ENDIAN64(data) ENDIAN64_ATOM_SWAP(data)
#else
# error "ENDIAN MACROS NOT DEFINED :("
#endif
#ifdef __cplusplus
}
#endif
#endif
/* Header for jnetpcap_utils utility methods */
#ifndef _Included_nio_jmemory_h
#define _Included_nio_jmemory_h
#ifdef __cplusplus
extern "C" {
#define EXTERN extern "C"
#endif
#include <stdint.h>
#include "export.h"
#include <jni.h>
typedef struct memory_usage_t {
uint64_t total_allocated;
uint64_t total_deallocated;
uint64_t total_allocate_calls;
uint64_t total_deallocate_calls;
uint64_t seg_0_255_bytes;
uint64_t seg_256_or_above_bytes;
uint64_t max_direct;
uint64_t soft_direct;
uint64_t reserved_direct;
uint64_t available_direct;
} memory_usage_t;
typedef struct jni_global_ref_t {
int count; // Number of references held
jobject reference[]; // array of references held
} jni_global_ref_t;
extern jclass jmemoryClass;
extern jclass jmemoryPoolClass;
extern jclass jmemoryReferenceClass;
extern jmethodID jmemoryToDebugStringMID;
extern jmethodID jmemoryMaxDirectMemoryBreachMID;
extern jmethodID jmemorySoftDirectMemoryBreachMID;
extern jmethodID jmemoryCleanupMID;
extern jmethodID jmemoryPeer0MID;
extern jmethodID jmemoryAllocateMID;
extern jmethodID jmemorySetSize0MID;
extern jfieldID jmemoryPhysicalFID;
extern jfieldID jmemorySizeFID;
extern jfieldID jmemoryOwnerFID;
extern jfieldID jmemoryKeeperFID;
extern jfieldID jmemoryRefFID;
extern jfieldID jmemoryRefAddressFID;
extern jobject jmemoryPOINTER_CONST; // JMemory.POINTER constant reference
extern jmethodID jmemoryPoolAllocateExclusiveMID;
extern jmethodID jmemoryPoolDefaultMemoryPoolMID;
extern jobject defaultMemoryPool;
extern memory_usage_t memory_usage;
// Prototypes
void init_jmemory(JNIEnv *env);
void *getJMemoryPhysical(JNIEnv *env, jobject obj);
void setJMemoryPhysical(JNIEnv *env, jobject obj, jlong value);
void jmemoryCleanup(JNIEnv *env, jobject obj);
jint jmemoryPeer(JNIEnv *env, jobject obj, const void *ptr, size_t length, jobject owner);
char *jmemoryPoolAllocate(JNIEnv *env, size_t size, jobject *obj_ref);
void jmemoryResize(JNIEnv *env, jobject obj, size_t size);
char *jmemoryAllocate(JNIEnv *env, size_t size, jobject obj);
char *jmemoryToDebugString(JNIEnv *env, jobject obj, char *buf);
#ifdef ENABLE_ASSERT
#define TOKEN_TO_STRING(TOK) # TOK
#define ASSERT(cond) if (!(cond)) { fprintf(stderr, "ASSERT FAILED: %s:%d \"%s\"\n", __FILE__, __LINE__, TOKEN_TO_STRING(cond)); fflush(stderr); exit(1);}
#else
#define ASSERT(cond)
#endif
#ifdef __cplusplus
}
#endif
#endif
/* Header for analysis_flow utility methods */
#ifndef _Included_packet_flow_h
#define _Included_packet_flow_h
#ifdef __cplusplus
extern "C" {
#define EXTERN extern "C"
#endif
#include <stdint.h>
#include <stdint.h>
#include "export.h"
#include <jni.h>
#include "org_jnetpcap_packet_JFlowKey.h"
#define FLOW_KEY_PAIR_COUNT org_jnetpcap_packet_JFlowKey_FLOW_KEY_PAIR_COUNT
struct scan_t; // Forward reference
/*
* Flow key is made up of several key pairs. In order for a flow key to be
* equal to another flow key, all the pair values must match. The flow pairs
* can be bi-directional. If uni directional flag is not set, it means that the
* second array of pairs is also in use and the values there are exact pair
* reversal of the first array of pairs.
*/
typedef struct flow_key_t {
uint64_t header_map; // bitmap of header IDs part of this flowkey
uint32_t hash; // Hashcode
#define FLOW_KEY_FLAG_REVERSABLE_PAIRS org_jnetpcap_packet_JFlowKey_FLAG_REVERSABLE
uint16_t flags; // flags
uint16_t pair_count; // number of pairs upto FLOW_KEY_PAIR_COUNT
uint8_t id[FLOW_KEY_PAIR_COUNT];
uint32_t forward_pair[FLOW_KEY_PAIR_COUNT][2];
uint32_t reverse_pair[FLOW_KEY_PAIR_COUNT][2];
} flow_key_t;
/**
* Based on the first part of the key, it sets the second part of the key
* using reversed direction values for each pair. flow_key_t->pair[2] is a
* multi-dimensional array that has 2 sets of key pairs. [0] for forward keys
* and [1] for reverse direction keys.
*/
void flow_key_init(flow_key_t *key, int id);
void process_flow_key(scan_t *scan);
#ifdef __cplusplus
}
#endif
#endif
This diff is collapsed.
This diff is collapsed.
/* crc16.h
* Declaration of CRC-16 routines and table
*
* 2004 Richard van der Hoff <richardv@mxtelecom.com>
*
* $Id: crc16.h 20485 2007-01-18 18:43:30Z guy $
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@xxxxxxxxxxxx>
* Copyright 1998 Gerald Combs
*
* Copied from README.developer
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __CRC16_H_
#define __CRC16_H_
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <stdint.h>
/* Calculate the CCITT/ITU/CRC-16 16-bit CRC
(parameters for this CRC are:
Polynomial: x^16 + x^12 + x^5 + 1 (0x1021);
Start value 0xFFFF;
XOR result with 0xFFFF;
First bit is LSB)
*/
/** Compute CRC16 CCITT checksum of a buffer of data.
@param buf The buffer containing the data.
@param len The number of bytes to include in the computation.
@return The CRC16 CCITT checksum. */
extern uint16_t crc16_ccitt(const uint8_t *buf, uint32_t len);
/** Compute CRC16 X.25 CCITT checksum of a buffer of data.
@param buf The buffer containing the data.
@param len The number of bytes to include in the computation.
@return The CRC16 X.25 CCITT checksum. */
extern uint16_t crc16_x25_ccitt(const uint8_t *buf, uint32_t len);
/** Compute CRC16 CCITT checksum of a buffer of data. If computing the
* checksum over multiple buffers and you want to feed the partial CRC16
* back in, remember to take the 1's complement of the partial CRC16 first.
@param buf The buffer containing the data.
@param len The number of bytes to include in the computation.
@param seed The seed to use.
@return The CRC16 CCITT checksum (using the given seed). */
extern uint16_t crc16_ccitt_seed(const uint8_t *buf, uint32_t len, uint16_t seed);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* crc16.h */
/* crc32.h
* Declaration of CRC-32 routine and table
*
* $Id: crc32.h 24930 2008-04-12 12:31:53Z stig $
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* Copied from README.developer
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __UTIL_CRC32_H_
#define __UTIL_CRC32_H_
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <stdint.h>
#define CRC32C_PRELOAD 0xffffffff
/*
* Byte swap fix contributed by Dave Wysochanski <davidw@netapp.com>.
*/
#define CRC32C_SWAP(crc32c_value) \
(((crc32c_value & 0xff000000) >> 24) | \
((crc32c_value & 0x00ff0000) >> 8) | \
((crc32c_value & 0x0000ff00) << 8) | \
((crc32c_value & 0x000000ff) << 24))
#define CRC32C(c,d) (c=(c>>8)^crc32c_table[(c^(d))&0xFF])
extern const uint32_t crc32c_table[256];
/** Compute CRC32C checksum of a buffer of data.
@param buf The buffer containing the data.
@param len The number of bytes to include in the computation.
@param crc The preload value for the CRC32C computation.
@return The CRC32C checksum. */
extern uint32_t calculate_crc32c(const void *buf, int len, uint32_t crc);
extern const uint32_t crc32_ccitt_table[256];
/** Compute CRC32 CCITT checksum of a buffer of data.
@param buf The buffer containing the data.
@param len The number of bytes to include in the computation.
@return The CRC32 CCITT checksum. */
extern uint32_t crc32_ccitt(const uint8_t *buf, uint32_t len);
/** Compute CRC32 CCITT checksum of a buffer of data. If computing the
* checksum over multiple buffers and you want to feed the partial CRC32
* back in, remember to take the 1's complement of the partial CRC32 first.
@param buf The buffer containing the data.
@param len The number of bytes to include in the computation.
@param seed The seed to use.
@return The CRC32 CCITT checksum (using the given seed). */
extern uint32_t crc32_ccitt_seed(const uint8_t *buf, uint32_t len, uint32_t seed);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* util_crc32.h */
// Include this file after jni.h is included. It undefines MS compiler, def for
// gcc specific one.
//
#ifndef Include_util_debug_h
#define Include_util_debug_h
#define JNIEXPORT extern "C"
#undef __declspec
#define __declspec(a) extern "C"
#include <stdarg.h>
#define DEBUG_MAX_LEVEL 10
#define DEBUG_TRACE 10
#define DEBUG_INFO 8
#define DEBUG_WARN 6
#define DEBUG_ERROR 4
#define DEFAULT_LEVEL DEBUG_TRACE
#define DEFAULT_INDENT_CHAR '.'
extern int debug_get_level();
extern void debug_set_level(int level);
extern void debug_inc();
extern void debug_dec();
extern void debug_reset();
extern void debug_vmsg(const char *type, const char *msg, const char *fmt, va_list ap);
extern void debug_msg(const char *type, const char *msg, const char *fmt, ...);
extern void debug_trace(const char *msg, const char *fmt, ...);
extern void debug_warn(const char *msg, const char *fmt, ...);
extern void debug_error(const char *msg, const char *fmt, ...);
extern void debug_info(const char *msg, const char *fmt, ...);
extern void debug_enter(const char *method);
extern void debug_exit(const char *method);
#define DEBUG_MAX_NAME 256
#define DEBUG_DEFAULT_LEVEL TRACE
/***
******** Temporarily backedout
class Debug {
public:
enum Level {
ALL,
TRACE,
INFO,
WARN,
ERR,
NONE,
UNDEFINED
};
private:
Level level;
int indentation;
char indentBuffer[DEBUG_MAX_LEVEL + 2];
char indentChar;
Debug *parent;
char name[DEBUG_MAX_NAME];
public:
Debug(const char *name, Debug *parent);
Debug(const char *name);
Debug(const char *name, Level defaultLevel);
~Debug() { }
void setLevel(Level level);
Level getLevel();
void inc();
void dec();
void reset();
void msg(Level type, char *msg, char *fmt, ...);
void trace(char *msg, char *fmt, ...);
void info(char *msg, char *fmt, ...);
void warn(char *msg, char *fmt, ...);
void error(char *msg, char *fmt, ...);
void enter(char *method);
void exit(char *method);
private:
void vmsg(Level type, char *msg, char *fgm, va_list ap);
char *indent();
char *getLevelName(Level level);
static char *levelNames[ERR + 1];
static Debug global_logger;
static Debug null_logger;
};
****************/
#endif
/* in_cksum.h
* Declaration of Internet checksum routine.
*
* $Id: in_cksum.h 12117 2004-09-28 00:06:32Z guy $
*/
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <stdio.h>
#include <stdint.h>
#include <jni.h>
typedef struct {
const uint8_t *ptr;
int len;
} vec_t;
extern uint16_t in_cksum(const vec_t *vec, int veclen);
extern uint16_t in_cksum_shouldbe(uint16_t sum, uint16_t computed_sum);
typedef union {
uint8_t c[2];
uint16_t s;
} pad_t;
extern int in_checksum_pad_to_even(
vec_t *vec,
int veclen,
pad_t *pad);
extern int in_checksum_skip_crc16_field(
const uint8_t *buf, // Buffer ptr
vec_t *vec,
int len,
int crc_offset);
extern int in_checksum_add_ip_pseudo_header(
const uint8_t *buf,
vec_t *vec,
int type,
int len,
uint32_t phdr[2]);
extern uint16_t psuedo_ip4_tcp(
JNIEnv *env,
const uint8_t *mem,
size_t size,
jint ip4,
jint tcp);
uint16_t psuedo_ip6_tcp(
JNIEnv *env,
const uint8_t *mem,
size_t size,
jint ip6,
jint tcp);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#include <jni.h>
/* Header for jnetpcap_utils utility methods */
#ifndef _Included_org_jnetpcap_WinPcapExtensions
#define _Included_org_jnetpcap_WinPcapExtensions
#ifdef __cplusplus
extern "C" {
#define EXTERN extern "C"
#endif
extern jclass winPcapClass;
// Prototypes
#ifdef __cplusplus
}
#endif
#endif
/* Header for jnetpcap_utils utility methods */
#ifndef _Included_winpcap_ids_h
#define _Included_winpcap_ids_h
#ifdef __cplusplus
extern "C" {
#define EXTERN extern "C"
#endif
#include "export.h"
#include <jni.h>
// WinPcapSamp
extern jclass winPcapSampClass;
extern jfieldID winPcapSampPhysicalFID;
extern jmethodID winPcapSampConstructorMID;
// WinPcapStat
extern jclass WinPcapStatClass;
extern jmethodID WinPcapStatConstructorMID;
// WinPcapRmtAuth
extern jclass winPcapRmtAuthClass;
extern jfieldID winPcapRmtAuthTypeFID;
extern jfieldID winPcapRmtAuthUsernameFID;
extern jfieldID winPcapRmtAuthPasswordFID;
#ifdef __cplusplus
}
#endif
#endif
#include <jni.h>
/* Header for jnetpcap_utils utility methods */
#ifndef _Included_org_jnetpcap_WinWinPcapStat
#define _Included_org_jnetpcap_WinWinPcapStat
#ifdef __cplusplus
extern "C" {
#define EXTERN extern "C"
#endif
extern jclass winWinPcapStatClass;
// Prototypes
jobject newWinPcapStat(JNIEnv *env);
void setWinPcapStat(JNIEnv *env, jobject jstats, struct pcap_stat *stats,
int size);
#ifdef __cplusplus
}
#endif
#endif
#!/usr/bin/env bash
# Set paths
BASE_DIR="$(readlink -f "$(dirname $0)")"
TARGET_DIR="${BASE_DIR}/target"
LIB_DIR="${BASE_DIR}/lib"
CONFIG_DIR="${BASE_DIR}/config"
COLL_JAR="${TARGET_DIR}/varanus-collector.jar"
JPCAP_LIB="${LIB_DIR}/jnetpcap-1.4.r1425"
LOGBACK_FILE="${CONFIG_DIR}/varanus-collector-logback.xml"
#PROPS_FILE="${CONFIG_DIR}/varanus-collector.properties"
PROPS_FILE="${CONFIG_DIR}/"
# Set JVM options
JVM_OPTS=""
JVM_OPTS="${JVM_OPTS} -server -d64"
#JVM_OPTS="${JVM_OPTS} -Xmx2g -Xms2g -Xmn800m"
JVM_OPTS="${JVM_OPTS} -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
JVM_OPTS="${JVM_OPTS} -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192"
JVM_OPTS="${JVM_OPTS} -XX:CompileThreshold=1500"
# Set JnetPcap options
JVM_OPTS="${JVM_OPTS} -Djava.library.path=${JPCAP_LIB}"
if ! [ -n "${LD_LIBRARY_PATH}" ]; then
LD_LIBRARY_PATH="/usr/lib/x86_64-linux-gnu"
fi
if ! [ -n "${JAVA_HOME}" ]; then
JAVA_HOME="$(dirname "$(dirname "$(dirname "$(readlink -v -e "$(which java)")")")")"
fi
java ${JVM_OPTS} -Dlogback.configurationFile=${LOGBACK_FILE}\
-jar "${COLL_JAR}"\
-cf "${PROPS_FILE}"\
"$@"
package net.varanus.collector;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.varanus.collector.internal.Collector;
/**
*
*/
public final class Main
{
private static final Logger LOG = LoggerFactory.getLogger(Main.class);
public static void main( String[] args )
{
try {
LOG.info("== Loading configuration for varanus-collector ==");
CollectorConfig config = CollectorConfig.getConfig(args);
LOG.info("== Initializing varanus-collector ==");
Collector collector = new Collector(config);
LOG.info("== Starting varanus-collector ==");
collector.start();
collector.waitForShutdown();
LOG.info("== Exiting varanus-collector ==");
}
catch (IllegalArgumentException e) {
LOG.error("!!! {}", e.getMessage(), e);
System.exit(1);
return; // for compiler only
}
catch (IOException e) {
LOG.error("!!! IO error: {}", e.getMessage(), e);
System.exit(1);
return; // for compiler only
}
}
private Main()
{
// not used
}
}
package net.varanus.collector.internal;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.time.Instant;
import org.jnetpcap.PcapHeader;
import net.varanus.util.io.ByteBuffers;
import net.varanus.util.io.ByteBuffers.BufferType;
/**
*
*/
final class CapturedPacket
{
private final byte[] packet;
private final Instant captureTime;
CapturedPacket( PcapHeader header, ByteBuffer buffer )
{
this.packet = getCopyWithoutVLAN(buffer);
this.captureTime = Instant.ofEpochSecond(header.seconds(), header.nanos());
}
byte[] getPacket()
{
return packet;
}
Instant getCaptureTime()
{
return captureTime;
}
private static final int VLAN_TYPE = 0x8100;
private static final int ETHERTYPE_OFFSET = 12;
private static final int VLAN_TAG_SIZE = 32 / Byte.SIZE;
private static final int BEFORE_VLAN_LENGTH = ETHERTYPE_OFFSET;
private static final int AFTER_VLAN_OFFSET = ETHERTYPE_OFFSET + VLAN_TAG_SIZE;
private static byte[] getCopyWithoutVLAN( ByteBuffer buf )
{
int pos = buf.position();
int lim = buf.limit();
int len = lim - pos;
if (len < AFTER_VLAN_OFFSET) {
return ByteBuffers.getArrayCopy(buf);
}
else {
int index = pos + ETHERTYPE_OFFSET;
int ethType = Short.toUnsignedInt(ByteBuffers.getShortAtIndex(index, buf, ByteOrder.BIG_ENDIAN));
if (ethType == VLAN_TYPE) {
ByteBuffer beforeVLAN = ByteBuffers.getSlice(buf, BEFORE_VLAN_LENGTH);
ByteBuffer afterVLAN = ByteBuffers.getSliceAtIndex(AFTER_VLAN_OFFSET, buf);
int newLength = beforeVLAN.remaining() + afterVLAN.remaining();
ByteBuffer copy = ByteBuffers.allocate(newLength, BufferType.ARRAY_BACKED);
ByteBuffers.copy(beforeVLAN, copy);
ByteBuffers.copy(afterVLAN, copy);
return copy.array();
}
else {
return ByteBuffers.getArrayCopy(buf);
}
}
}
}
package net.varanus.collector.internal;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import javax.annotation.CheckForNull;
import javax.annotation.ParametersAreNonnullByDefault;
import net.varanus.util.annotation.FieldsAreNonnullByDefault;
import net.varanus.util.annotation.ReturnValuesAreNonnullByDefault;
import net.varanus.util.openflow.types.BitMatch;
/**
*
*/
@FieldsAreNonnullByDefault
@ParametersAreNonnullByDefault
@ReturnValuesAreNonnullByDefault
final class CollectionHandle
{
private final BitMatch match;
private final BlockingQueue<CapturedPacket> matchedQueue;
private final AtomicLong unmatchedBytes;
private final AtomicLong unmatchedPkts;
CollectionHandle( BitMatch match )
{
this.match = match;
this.matchedQueue = new LinkedBlockingQueue<>();
this.unmatchedBytes = new AtomicLong(0);
this.unmatchedPkts = new AtomicLong(0);
}
BitMatch getMatch()
{
return match;
}
@CheckForNull
CapturedPacket peekMatched()
{
return matchedQueue.peek();
}
@CheckForNull
CapturedPacket pollMatched()
{
return matchedQueue.poll();
}
@CheckForNull
CapturedPacket pollMatched( long timeout, TimeUnit unit ) throws InterruptedException
{
return matchedQueue.poll(timeout, unit);
}
CapturedPacket takeMatched() throws InterruptedException
{
return matchedQueue.take();
}
long getUnmatchedBytes()
{
return unmatchedBytes.get();
}
long getUnmatchedPackets()
{
return unmatchedPkts.get();
}
void collectMatched( CapturedPacket pkt )
{
matchedQueue.add(pkt);
}
void logUnmatched( CapturedPacket pkt )
{
unmatchedBytes.addAndGet(pkt.getPacket().length);
unmatchedPkts.incrementAndGet();
}
}
package net.varanus.collector.internal;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.ParametersAreNonnullByDefault;
import org.projectfloodlight.openflow.protocol.match.MatchField;
import org.projectfloodlight.openflow.types.EthType;
import org.projectfloodlight.openflow.types.IpProtocol;
import org.projectfloodlight.openflow.types.TransportPort;
import org.slf4j.Logger;
import net.varanus.util.annotation.FieldsAreNonnullByDefault;
import net.varanus.util.annotation.ReturnValuesAreNonnullByDefault;
import net.varanus.util.openflow.types.BitMatch;
import net.varanus.util.openflow.types.Flow;
import net.varanus.util.openflow.types.MatchEntry;
/**
*
*/
@FieldsAreNonnullByDefault
@ParametersAreNonnullByDefault
@ReturnValuesAreNonnullByDefault
final class CollectionManager
{
private final Map<BitMatch, CollectionHandle> handleMap;
private final Object mapLock;
CollectionManager()
{
this.handleMap = new HashMap<>();
this.mapLock = new Object();
}
void collectPacket( CapturedPacket packet )
{
synchronized (mapLock) {
handleMap.forEach(( match, handle ) -> {
if (match.matchesPacket(packet.getPacket()))
handle.collectMatched(packet);
else if (!isFiltered(packet))// XXX !!! HACK!!! XXX
handle.logUnmatched(packet);
});
}
}
// XXX !!! HACK!!! XXX
private static final Flow SEC_PROBE_FLOW = Flow.of(MatchEntry.ofExact(MatchField.ETH_TYPE, EthType.of(0x9000)));
private static final Flow LLDP_PROBE_FLOW = Flow.of(MatchEntry.ofExact(MatchField.ETH_TYPE, EthType.LLDP));
private static final Flow BSN_PROBE_FLOW = Flow.of(MatchEntry.ofExact(MatchField.ETH_TYPE, EthType.of(0x8942)));
private static final Flow IPV6_FLOW = Flow.of(MatchEntry.ofExact(MatchField.ETH_TYPE, EthType.IPv6));
private static final Flow DHCP_PROBE_FLOW = Flow.of(
MatchEntry.ofExact(MatchField.ETH_TYPE, EthType.IPv4),
MatchEntry.ofExact(MatchField.IP_PROTO, IpProtocol.UDP),
MatchEntry.ofExact(MatchField.UDP_SRC, TransportPort.of(68)),
MatchEntry.ofExact(MatchField.UDP_DST, TransportPort.of(67)));
private static boolean isFiltered( CapturedPacket packet )
{
return SEC_PROBE_FLOW.getBitMatch().matchesPacket(packet.getPacket())
|| LLDP_PROBE_FLOW.getBitMatch().matchesPacket(packet.getPacket())
|| BSN_PROBE_FLOW.getBitMatch().matchesPacket(packet.getPacket())
|| IPV6_FLOW.getBitMatch().matchesPacket(packet.getPacket())
|| DHCP_PROBE_FLOW.getBitMatch().matchesPacket(packet.getPacket());
}
// XXX !!! HACK!!! XXX
CollectionHandle registerHandle( BitMatch newMatch, Logger log )
{
synchronized (mapLock) {
checkNewMatch(newMatch, log);
return handleMap.computeIfAbsent(newMatch, CollectionHandle::new);
}
}
void unregisterHandle( BitMatch match )
{
synchronized (mapLock) {
handleMap.remove(match);
}
}
private void checkNewMatch( BitMatch newMatch, Logger log )
{
for (BitMatch match : handleMap.keySet()) {
if (newMatch.equals(match))
log.warn("!! Duplicate bit match when requesting new queue: {}", newMatch);
else if (newMatch.matchesAllOf(match))
log.warn(
"!! New bit match matches all of existing match when requesting new queue: {} matches all of {}",
newMatch,
match);
else if (match.matchesAllOf(newMatch))
log.warn(
"!! Existing bit match matches all of new match when requesting new queue: {} matches all of {}",
match,
newMatch);
}
}
}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." name="varanus-common-lib">
<!--
When this file is included the basedir property is ignored, this hack is required to retrieve it.
-->
<dirname property="common.basedir" file="${ant.file.varanus-common-lib}" />
<property name="common.lib" location="${common.basedir}/lib" />
</project>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="compile" basedir="." name="varanus-config-protocol">
<!--
When this file is included the basedir property is ignored, this hack is required to retrieve it.
-->
<dirname property="config.basedir" file="${ant.file.varanus-config-protocol}" />
<property name="config.target" location="${config.basedir}/target" />
<property name="config.build" location="${config.target}/bin" />
<property name="config.src" location="${config.basedir}/src/main/java" />
<property name="ant.build.javac.source" value="1.8" />
<property name="ant.build.javac.target" value="1.8" />
<include file="${config.basedir}/../utils/build.xml" as="utils" />
<include file="${config.basedir}/../common-lib/build.xml" as="common" />
<path id="config.classpath">
<fileset dir="${common.lib}">
<patternset refid="utils-common-lib" />
</fileset>
<pathelement path="${utils.build}" />
</path>
<target name="init" depends="utils.init">
<mkdir dir="${config.build}" />
</target>
<target name="compile" depends="init,utils.compile">
<javac includeAntRuntime="false"
classpathref="config.classpath"
debug="true"
srcdir="${config.src}"
destdir="${config.build}">
<compilerarg value="-Xlint" />
</javac>
</target>
<target name="clean" depends="utils.clean">
<delete dir="${config.target}" />
</target>
</project>
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment