1
0
Fork 0
mirror of https://github.com/pavel-odintsov/fastnetmon synced 2024-06-08 20:56:07 +02:00

Add ability to specify sampling ratio when capturing in netmap mode

This commit is contained in:
Pavel Odintsov 2015-06-23 18:46:17 -04:00
parent 536dd04a47
commit aeb041dbe7
2 changed files with 11 additions and 0 deletions

View File

@ -53,6 +53,9 @@ mirror = off
# Netmap traffic capture (very fast but need patched drivers)
mirror_netmap = off
# Port mirroring could be sampled
netmap_sampling_ratio = 1
# Pcap mode, very slow not suitable for production
pcap = off
# Netflow capture method with v5, v9 and IPFIX suppotr

View File

@ -48,6 +48,8 @@ typedef cpuset_t cpu_set_t;
#include "netmap_collector.h"
uint32_t netmap_sampling_ratio = 1;
/* prototypes */
void netmap_thread(struct nm_desc* netmap_descriptor, int netmap_thread);
void consume_pkt(u_char* buffer, int len);
@ -105,6 +107,8 @@ void consume_pkt(u_char* buffer, int len) {
// We should fill this structure for passing to FastNetMon
simple_packet packet;
packet.sample_ratio = netmap_sampling_ratio;
if (packet_header.extended_hdr.parsed_pkt.ip_version != 4 && packet_header.extended_hdr.parsed_pkt.ip_version != 6) {
total_unparsed_packets++;
return;
@ -326,6 +330,10 @@ void start_netmap_collection(process_packet_pointer func_ptr) {
interfaces_list = configuration_map["interfaces"];
}
if (configuration_map.count("netmap_sampling_ratio") != 0) {
netmap_sampling_ratio = convert_string_to_integer(configuration_map["netmap_sampling_ratio"]);
}
std::vector<std::string> interfaces_for_listen;
boost::split(interfaces_for_listen, interfaces_list, boost::is_any_of(","), boost::token_compress_on);