AutoScopedParser

Struct AutoScopedParser 

Source
pub struct AutoScopedParser { /* private fields */ }
Expand description

Automatically scoped parser that handles RFC-compliant template isolation.

This parser automatically extracts scoping identifiers from NetFlow packet headers and maintains separate template caches per source according to RFC specifications:

  • NetFlow v9: Uses (source_addr, source_id) per RFC 3954
  • IPFIX: Uses (source_addr, observation_domain_id) per RFC 7011
  • NetFlow v5/v7: Uses source_addr only (these versions have no scoping IDs)

This is the recommended parser for production deployments as it automatically handles the complexity of RFC-compliant scoping without requiring manual key management.

§Examples

use netflow_parser::scoped_parser::AutoScopedParser;
use std::net::SocketAddr;

let mut parser = AutoScopedParser::new();

let source: SocketAddr = "192.168.1.1:2055".parse().unwrap();

// Parser automatically uses RFC-compliant scoping
let packets = parser.parse_from_source(source, &data);

§Thread Safety

Like NetflowParser, AutoScopedParser is not thread-safe. Use external synchronization (e.g., Arc<Mutex<AutoScopedParser>>) when sharing across threads.

Implementations§

Source§

impl AutoScopedParser

Source

pub fn new() -> Self

Create a new auto-scoped parser with default configuration.

Each new source will get a parser with default settings.

Source

pub fn with_builder(builder: NetflowParserBuilder) -> Self

Create a new auto-scoped parser with a custom parser builder.

The builder will be used to create new parser instances for each source.

§Examples
use netflow_parser::scoped_parser::AutoScopedParser;
use netflow_parser::NetflowParser;
use netflow_parser::variable_versions::ttl::TtlConfig;
use std::time::Duration;

let builder = NetflowParser::builder()
    .with_cache_size(5000)
    .with_ttl(TtlConfig::new(Duration::from_secs(3600)));

let parser = AutoScopedParser::with_builder(builder);
Source

pub fn parse_from_source( &mut self, source: SocketAddr, data: &[u8], ) -> Result<Vec<NetflowPacket>, NetflowError>

Parse NetFlow data from a source with automatic RFC-compliant scoping.

This method automatically:

  1. Extracts the scoping identifier from the packet header
  2. Routes to the appropriate scoped parser
  3. Creates new parser instances as needed
§Arguments
  • source - The network address of the exporter
  • data - The raw NetFlow packet data
§Returns

A vector of parsed NetFlow packets from the given data.

§Examples
use netflow_parser::scoped_parser::AutoScopedParser;
use std::net::SocketAddr;

let mut parser = AutoScopedParser::new();
let source: SocketAddr = "192.168.1.1:2055".parse().unwrap();

let packets = parser.parse_from_source(source, &data);
Source

pub fn iter_packets_from_source<'a>( &'a mut self, source: SocketAddr, data: &'a [u8], ) -> impl Iterator<Item = Result<NetflowPacket, NetflowError>> + 'a

Parse NetFlow data from a source using the iterator API.

This is more efficient than parse_from_source when you don’t need all packets in a Vec.

§Arguments
  • source - The network address of the exporter
  • data - The raw NetFlow packet data
§Returns

An iterator over parsed NetFlow packets.

Source

pub fn source_count(&self) -> usize

Get the total number of registered sources across all scoping types.

Source

pub fn ipfix_source_count(&self) -> usize

Get the number of IPFIX sources.

Source

pub fn v9_source_count(&self) -> usize

Get the number of NetFlow v9 sources.

Source

pub fn legacy_source_count(&self) -> usize

Get the number of legacy (v5/v7) sources.

Source

pub fn clear_all_templates(&mut self)

Clear templates for all sources.

Source

pub fn ipfix_stats(&self) -> Vec<(&IpfixSourceKey, CacheStats, CacheStats)>

Get statistics for all IPFIX sources.

Returns a vector of tuples: (source_key, v9_stats, ipfix_stats)

Source

pub fn v9_stats(&self) -> Vec<(&V9SourceKey, CacheStats, CacheStats)>

Get statistics for all NetFlow v9 sources.

Returns a vector of tuples: (source_key, v9_stats, ipfix_stats)

Source

pub fn legacy_stats(&self) -> Vec<(&SocketAddr, CacheStats, CacheStats)>

Get statistics for all legacy sources.

Returns a vector of tuples: (addr, v9_stats, ipfix_stats)

Trait Implementations§

Source§

impl Debug for AutoScopedParser

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AutoScopedParser

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.