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_addronly (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
impl AutoScopedParser
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new auto-scoped parser with default configuration.
Each new source will get a parser with default settings.
Sourcepub fn with_builder(builder: NetflowParserBuilder) -> Self
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);Sourcepub fn parse_from_source(
&mut self,
source: SocketAddr,
data: &[u8],
) -> Result<Vec<NetflowPacket>, NetflowError>
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:
- Extracts the scoping identifier from the packet header
- Routes to the appropriate scoped parser
- Creates new parser instances as needed
§Arguments
source- The network address of the exporterdata- 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);Sourcepub fn iter_packets_from_source<'a>(
&'a mut self,
source: SocketAddr,
data: &'a [u8],
) -> impl Iterator<Item = Result<NetflowPacket, NetflowError>> + 'a
pub fn iter_packets_from_source<'a>( &'a mut self, source: SocketAddr, data: &'a [u8], ) -> impl Iterator<Item = Result<NetflowPacket, NetflowError>> + 'a
Sourcepub fn source_count(&self) -> usize
pub fn source_count(&self) -> usize
Get the total number of registered sources across all scoping types.
Sourcepub fn ipfix_source_count(&self) -> usize
pub fn ipfix_source_count(&self) -> usize
Get the number of IPFIX sources.
Sourcepub fn v9_source_count(&self) -> usize
pub fn v9_source_count(&self) -> usize
Get the number of NetFlow v9 sources.
Sourcepub fn legacy_source_count(&self) -> usize
pub fn legacy_source_count(&self) -> usize
Get the number of legacy (v5/v7) sources.
Sourcepub fn clear_all_templates(&mut self)
pub fn clear_all_templates(&mut self)
Clear templates for all sources.
Sourcepub fn ipfix_stats(&self) -> Vec<(&IpfixSourceKey, CacheStats, CacheStats)>
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)
Sourcepub fn v9_stats(&self) -> Vec<(&V9SourceKey, CacheStats, CacheStats)>
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)
Sourcepub fn legacy_stats(&self) -> Vec<(&SocketAddr, CacheStats, CacheStats)>
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)