Adding test for dynamic packet dumper plugin.

This commit is contained in:
Robin Sommer 2014-09-04 20:30:28 -07:00
parent b813b6f83b
commit 6e33c92cf0
7 changed files with 127 additions and 0 deletions

View file

@ -0,0 +1,12 @@
Demo::Foo - A Foo packet dumper (dynamic, version 1.0)
[Packet Dumper] FooPktDumper (dumper prefix: foo)
===
Dumping to XXX: 1373858797.646968 len 94
Dumping to XXX: 1373858797.646998 len 94
Dumping to XXX: 1373858797.647041 len 86
Dumping to XXX: 1373858797.647147 len 98
Dumping to XXX: 1373858797.647186 len 86
Dumping to XXX: 1373858797.647250 len 86
Dumping to XXX: 1373858797.647317 len 86
Dumping to XXX: 1373858797.647350 len 86

View file

@ -0,0 +1,17 @@
project(Bro-Plugin-Demo-Foo)
cmake_minimum_required(VERSION 2.6.3)
if ( NOT BRO_DIST )
message(FATAL_ERROR "BRO_DIST not set")
endif ()
set(CMAKE_MODULE_PATH ${BRO_DIST}/cmake)
include(BroPlugin)
bro_plugin_begin(Demo Foo)
bro_plugin_cc(src/Plugin.cc)
bro_plugin_cc(src/Foo.cc)
bro_plugin_end()

View file

@ -0,0 +1,40 @@
#include <fcntl.h>
#include <stdio.h>
#include "Foo.h"
using namespace plugin::Demo_Foo;
Foo::Foo(const std::string& path, bool is_live)
{
props.path = path;
}
Foo::~Foo()
{
}
void Foo::Open()
{
props.open_time = network_time;
props.hdr_size = 0;
Opened(props);
}
void Foo::Close()
{
Closed();
}
bool Foo::Dump(const Packet* pkt)
{
double t = double(pkt->hdr->ts.tv_sec) + double(pkt->hdr->ts.tv_usec) / 1e6;
fprintf(stdout, "Dumping to %s: %.6f len %u\n", props.path.c_str(), t, (unsigned int)pkt->hdr->len);
return true;
}
iosource::PktDumper* Foo::Instantiate(const std::string& path, bool append)
{
return new Foo(path, append);
}

View file

@ -0,0 +1,30 @@
#ifndef BRO_PLUGIN_DEMO_FOO_H
#define BRO_PLUGIN_DEMO_FOO_H
#include <Val.h>
#include <iosource/PktDumper.h>
namespace plugin {
namespace Demo_Foo {
class Foo : public iosource::PktDumper {
public:
Foo(const std::string& path, bool is_live);
virtual ~Foo();
static PktDumper* Instantiate(const std::string& path, bool append);
protected:
virtual void Open();
virtual void Close();
virtual bool Dump(const Packet* pkt);
private:
Properties props;
};
}
}
#endif

View file

@ -0,0 +1,20 @@
#include "Plugin.h"
#include "Foo.h"
namespace plugin { namespace Demo_Foo { Plugin plugin; } }
using namespace plugin::Demo_Foo;
plugin::Configuration Plugin::Configure()
{
AddComponent(new ::iosource::PktDumperComponent("FooPktDumper", "foo", ::plugin::Demo_Foo::Foo::Instantiate));
plugin::Configuration config;
config.name = "Demo::Foo";
config.description = "A Foo packet dumper";
config.version.major = 1;
config.version.minor = 0;
return config;
}

View file

@ -0,0 +1,8 @@
# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin Demo Foo
# @TEST-EXEC: cp -r %DIR/pktdumper-plugin/* .
# @TEST-EXEC: ./configure --bro-dist=${DIST} && make
# @TEST-EXEC: BRO_PLUGIN_PATH=`pwd` bro -NN Demo::Foo >>output
# @TEST-EXEC: echo === >>output
# @TEST-EXEC: BRO_PLUGIN_PATH=`pwd` bro -r $TRACES/port4242.trace -w foo:XXX %INPUT FilteredTraceDetection::enable=F >>output
# @TEST-EXEC: btest-diff output