mirror of
https://github.com/pavel-odintsov/fastnetmon
synced 2024-11-23 17:32:59 +01:00
Add SnabbSwitch support
This commit is contained in:
parent
1ca6262a04
commit
21ccb93440
@ -129,6 +129,15 @@ add_library(ipfix_rfc STATIC ipfix_rfc.cpp)
|
||||
# Our packet parser
|
||||
add_library(fastnetmon_packet_parser STATIC fastnetmon_packet_parser.c)
|
||||
|
||||
# -DENABLE_SNABBSWITCH_SUPPORT=ON ..
|
||||
if (ENABLE_SNABBSWITCH_SUPPORT)
|
||||
add_definitions(-DSNABB_SWITCH)
|
||||
add_library(snabbswitch_plugin STATIC snabbswitch_plugin/snabbswitch_collector.cpp)
|
||||
|
||||
link_directories(/usr/src/snabbswitch/src)
|
||||
target_link_libraries(snabbswitch_plugin snabb)
|
||||
endif()
|
||||
|
||||
# sFLOW plugin
|
||||
add_library(sflow_plugin STATIC sflow_plugin/sflow_collector.cpp)
|
||||
|
||||
@ -315,6 +324,10 @@ target_link_libraries(fastnetmon sflow_plugin netflow_plugin pcap_plugin example
|
||||
if (BUILD_PLUGIN_RUNNER)
|
||||
add_executable(fastnetmon_plugin_runner plugin_runner.cpp)
|
||||
|
||||
if (ENABLE_SNABBSWITCH_SUPPORT)
|
||||
target_link_libraries(fastnetmon_plugin_runner snabbswitch_plugin)
|
||||
endif()
|
||||
|
||||
target_link_libraries(fastnetmon_plugin_runner ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(fastnetmon_plugin_runner patricia)
|
||||
target_link_libraries(fastnetmon_plugin_runner fastnetmon_pcap_format)
|
||||
|
@ -21,6 +21,10 @@
|
||||
#include "pfring_plugin/pfring_collector.h"
|
||||
#endif
|
||||
|
||||
#ifdef SNABB_SWITCH
|
||||
#include "snabbswitch_plugin/snabbswitch_collector.h"
|
||||
#endif
|
||||
|
||||
#include "netmap_plugin/netmap_collector.h"
|
||||
|
||||
// log4cpp logging facility
|
||||
@ -127,6 +131,14 @@ int main(int argc, char* argv[]) {
|
||||
} else if (strstr(argv[1], "pcap") != NULL) {
|
||||
std::cout << "Starting pcap" << std::endl;
|
||||
start_pcap_collection(process_packet);
|
||||
} else if (strstr(argv[1], "snabbswitch") != NULL) {
|
||||
std::cout << "Starting snabbswitch" << std::endl;
|
||||
|
||||
#ifdef SNABB_SWITCH
|
||||
start_snabbswitch_collection(process_packet);
|
||||
#else
|
||||
printf("SnabbSwitch support is not compiled here\n");
|
||||
#endif
|
||||
} else if (strstr(argv[1], "pfring") != NULL) {
|
||||
#ifdef PF_RING
|
||||
std::cout << "Starting pf_ring" << std::endl;
|
||||
|
142
src/snabbswitch_plugin/snabbswitch_collector.cpp
Normal file
142
src/snabbswitch_plugin/snabbswitch_collector.cpp
Normal file
@ -0,0 +1,142 @@
|
||||
// log4cpp logging facility
|
||||
#include "log4cpp/Category.hh"
|
||||
#include "log4cpp/Appender.hh"
|
||||
#include "log4cpp/FileAppender.hh"
|
||||
#include "log4cpp/OstreamAppender.hh"
|
||||
#include "log4cpp/Layout.hh"
|
||||
#include "log4cpp/BasicLayout.hh"
|
||||
#include "log4cpp/PatternLayout.hh"
|
||||
#include "log4cpp/Priority.hh"
|
||||
|
||||
#include <boost/version.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include "../fast_library.h"
|
||||
|
||||
// For support uint32_t, uint16_t
|
||||
#include <sys/types.h>
|
||||
|
||||
// For config map operations
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "../fastnetmon_packet_parser.h"
|
||||
|
||||
// For support: IPPROTO_TCP, IPPROTO_ICMP, IPPROTO_UDP
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include "snabbswitch_collector.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// This code defined in SnabbSwitch
|
||||
int start_snabb_switch(int snabb_argc, char **snabb_argv);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
// Get log4cpp logger from main programm
|
||||
extern log4cpp::Category& logger;
|
||||
|
||||
// Pass unparsed packets number to main programm
|
||||
extern uint64_t total_unparsed_packets;
|
||||
|
||||
// Global configuration map
|
||||
extern std::map<std::string, std::string> configuration_map;
|
||||
|
||||
// This variable name should be uniq for every plugin!
|
||||
process_packet_pointer snabbswitch_process_func_ptr = NULL;
|
||||
|
||||
inline void firehose_packet(const char *pciaddr, char *data, int length);
|
||||
|
||||
/* Intel 82599 "Legacy" receive descriptor format.
|
||||
* See Intel 82599 data sheet section 7.1.5.
|
||||
* http://www.intel.com/content/dam/www/public/us/en/documents/datasheets/82599-10-gbe-controller-datasheet.pdf
|
||||
*/
|
||||
struct firehose_rdesc {
|
||||
uint64_t address;
|
||||
uint16_t length;
|
||||
uint16_t cksum;
|
||||
uint8_t status;
|
||||
uint8_t errors;
|
||||
uint16_t vlan;
|
||||
} __attribute__((packed));
|
||||
|
||||
// We will use this code from Global Symbols table (originally it's defined in netmap collector.cpp)
|
||||
bool parse_raw_packet_to_simple_packet(u_char* buffer, int len, simple_packet& packet);
|
||||
|
||||
void firehose_packet(const char *pciaddr, char *data, int length) {
|
||||
//__sync_fetch_and_add(&received_packets, 1);
|
||||
simple_packet packet;
|
||||
|
||||
if (!parse_raw_packet_to_simple_packet((u_char*)data, length, packet)) {
|
||||
total_unparsed_packets++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
snabbswitch_process_func_ptr(packet);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int firehose_callback_v1(const char *pciaddr, char **packets, struct firehose_rdesc *rxring, int ring_size, int index);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
int firehose_callback_v1(const char *pciaddr, char **packets, struct firehose_rdesc *rxring, int ring_size, int index) {
|
||||
while (rxring[index].status & 1) {
|
||||
int next_index = (index + 1) & (ring_size-1);
|
||||
__builtin_prefetch(packets[next_index]);
|
||||
firehose_packet(pciaddr, packets[index], rxring[index].length);
|
||||
rxring[index].status = 0; /* reset descriptor for reuse */
|
||||
index = next_index;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
void start_snabbswitch_collection(process_packet_pointer func_ptr) {
|
||||
logger << log4cpp::Priority::INFO << "SnabbSwitch plugin started";
|
||||
snabbswitch_process_func_ptr = func_ptr;
|
||||
|
||||
std::string interfaces_list = "";
|
||||
|
||||
if (configuration_map.count("interfaces_snabbswitch") != 0) {
|
||||
interfaces_list = configuration_map["interfaces_snabbswitch"];
|
||||
}
|
||||
|
||||
std::vector<std::string> interfaces_for_capture;
|
||||
boost::split(interfaces_for_capture, interfaces_list, boost::is_any_of(","), boost::token_compress_on);
|
||||
|
||||
logger << log4cpp::Priority::INFO << "SnabbSwitch will listen on " << interfaces_for_capture.size() << " interfaces";
|
||||
|
||||
// TODO read this from configureation!
|
||||
char* cli_arguments[] = {
|
||||
"snabb", // emulate call of standard application
|
||||
"firehose",
|
||||
"--input",
|
||||
"0000:03:00.0",
|
||||
"--input",
|
||||
"0000:03:00.1",
|
||||
"weird_data"
|
||||
};
|
||||
|
||||
int cli_number_of_arguments = sizeof(cli_arguments) / sizeof(char*);
|
||||
|
||||
start_snabb_switch(cli_number_of_arguments, cli_arguments);
|
||||
}
|
||||
|
8
src/snabbswitch_plugin/snabbswitch_collector.h
Normal file
8
src/snabbswitch_plugin/snabbswitch_collector.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef SNABBSWITCH_PLUGIN_H
|
||||
#define SNABBSWITCH_PLUGIN_H
|
||||
|
||||
#include "../fastnetmon_types.h"
|
||||
|
||||
void start_snabbswitch_collection(process_packet_pointer func_ptr);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user