mod information_elements;
pub use information_elements::INFORMATION_ELEMENTS;
pub const IPFIX_VERSION: u16 = 10;
pub const TEMPLATE_SET_ID: u16 = 2;
pub const OPTIONS_TEMPLATE_SET_ID: u16 = 3;
pub const MIN_DATA_SET_ID: u16 = 256;
pub const REVERSE_INFORMATION_ELEMENT_PEN: u32 = 29305;
pub mod type_records {
pub const INFORMATION_ELEMENT_ID: u16 = 303;
pub const PRIVATE_ENTERPRISE_NUMBER: u16 = 346;
pub const INFORMATION_ELEMENT_DATA_TYPE: u16 = 339;
pub const INFORMATION_ELEMENT_DESCRIPTION: u16 = 340;
pub const INFORMATION_ELEMENT_NAME: u16 = 341;
pub const INFORMATION_ELEMENT_RANGE_BEGIN: u16 = 342;
pub const INFORMATION_ELEMENT_RANGE_END: u16 = 343;
pub const INFORMATION_ELEMENT_SEMANTICS: u16 = 344;
pub const INFORMATION_ELEMENT_UNITS: u16 = 345;
pub const SCOPE_ELEMENTS: [u16; 2] = [INFORMATION_ELEMENT_ID, PRIVATE_ENTERPRISE_NUMBER];
pub const ELEMENTS: [u16; 9] = [
INFORMATION_ELEMENT_ID,
PRIVATE_ENTERPRISE_NUMBER,
INFORMATION_ELEMENT_DATA_TYPE,
INFORMATION_ELEMENT_SEMANTICS,
INFORMATION_ELEMENT_UNITS,
INFORMATION_ELEMENT_RANGE_BEGIN,
INFORMATION_ELEMENT_RANGE_END,
INFORMATION_ELEMENT_NAME,
INFORMATION_ELEMENT_DESCRIPTION,
];
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u8)]
pub enum DataType {
OctetArray = 0,
Unsigned8 = 1,
Unsigned16 = 2,
Unsigned32 = 3,
Unsigned64 = 4,
Signed8 = 5,
Signed16 = 6,
Signed32 = 7,
Signed64 = 8,
Float32 = 9,
Float64 = 10,
Boolean = 11,
MacAddress = 12,
String = 13,
DateTimeSeconds = 14,
DateTimeMilliseconds = 15,
DateTimeMicroseconds = 16,
DateTimeNanoseconds = 17,
Ipv4Address = 18,
Ipv6Address = 19,
BasicList = 20,
SubTemplateList = 21,
SubTemplateMultiList = 22,
Unsigned256 = 23,
}
impl DataType {
pub const ALL: [DataType; 24] = [
DataType::OctetArray,
DataType::Unsigned8,
DataType::Unsigned16,
DataType::Unsigned32,
DataType::Unsigned64,
DataType::Signed8,
DataType::Signed16,
DataType::Signed32,
DataType::Signed64,
DataType::Float32,
DataType::Float64,
DataType::Boolean,
DataType::MacAddress,
DataType::String,
DataType::DateTimeSeconds,
DataType::DateTimeMilliseconds,
DataType::DateTimeMicroseconds,
DataType::DateTimeNanoseconds,
DataType::Ipv4Address,
DataType::Ipv6Address,
DataType::BasicList,
DataType::SubTemplateList,
DataType::SubTemplateMultiList,
DataType::Unsigned256,
];
pub fn from_value(value: u8) -> Option<DataType> {
DataType::ALL.get(value as usize).copied()
}
pub fn name(&self) -> &'static str {
match self {
DataType::OctetArray => "octetArray",
DataType::Unsigned8 => "unsigned8",
DataType::Unsigned16 => "unsigned16",
DataType::Unsigned32 => "unsigned32",
DataType::Unsigned64 => "unsigned64",
DataType::Signed8 => "signed8",
DataType::Signed16 => "signed16",
DataType::Signed32 => "signed32",
DataType::Signed64 => "signed64",
DataType::Float32 => "float32",
DataType::Float64 => "float64",
DataType::Boolean => "boolean",
DataType::MacAddress => "macAddress",
DataType::String => "string",
DataType::DateTimeSeconds => "dateTimeSeconds",
DataType::DateTimeMilliseconds => "dateTimeMilliseconds",
DataType::DateTimeMicroseconds => "dateTimeMicroseconds",
DataType::DateTimeNanoseconds => "dateTimeNanoseconds",
DataType::Ipv4Address => "ipv4Address",
DataType::Ipv6Address => "ipv6Address",
DataType::BasicList => "basicList",
DataType::SubTemplateList => "subTemplateList",
DataType::SubTemplateMultiList => "subTemplateMultiList",
DataType::Unsigned256 => "unsigned256",
}
}
pub fn default_length(&self) -> Option<u16> {
match self {
DataType::Unsigned8 | DataType::Signed8 | DataType::Boolean => Some(1),
DataType::Unsigned16 | DataType::Signed16 => Some(2),
DataType::Unsigned32
| DataType::Signed32
| DataType::Float32
| DataType::DateTimeSeconds
| DataType::Ipv4Address => Some(4),
DataType::MacAddress => Some(6),
DataType::Unsigned64
| DataType::Signed64
| DataType::Float64
| DataType::DateTimeMilliseconds
| DataType::DateTimeMicroseconds
| DataType::DateTimeNanoseconds => Some(8),
DataType::Ipv6Address => Some(16),
DataType::Unsigned256 => Some(32),
DataType::OctetArray
| DataType::String
| DataType::BasicList
| DataType::SubTemplateList
| DataType::SubTemplateMultiList => None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u8)]
pub enum DataTypeSemantics {
Default = 0,
Quantity = 1,
TotalCounter = 2,
DeltaCounter = 3,
Identifier = 4,
Flags = 5,
List = 6,
SnmpCounter = 7,
SnmpGauge = 8,
}
impl DataTypeSemantics {
pub const ALL: [DataTypeSemantics; 9] = [
DataTypeSemantics::Default,
DataTypeSemantics::Quantity,
DataTypeSemantics::TotalCounter,
DataTypeSemantics::DeltaCounter,
DataTypeSemantics::Identifier,
DataTypeSemantics::Flags,
DataTypeSemantics::List,
DataTypeSemantics::SnmpCounter,
DataTypeSemantics::SnmpGauge,
];
pub fn from_value(value: u8) -> Option<DataTypeSemantics> {
DataTypeSemantics::ALL.get(value as usize).copied()
}
pub fn name(&self) -> &'static str {
match self {
DataTypeSemantics::Default => "default",
DataTypeSemantics::Quantity => "quantity",
DataTypeSemantics::TotalCounter => "totalCounter",
DataTypeSemantics::DeltaCounter => "deltaCounter",
DataTypeSemantics::Identifier => "identifier",
DataTypeSemantics::Flags => "flags",
DataTypeSemantics::List => "list",
DataTypeSemantics::SnmpCounter => "snmpCounter",
DataTypeSemantics::SnmpGauge => "snmpGauge",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Status {
Current,
Deprecated,
Obsolete,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct InformationElement {
pub id: u16,
pub name: &'static str,
pub data_type: DataType,
pub semantics: Option<DataTypeSemantics>,
pub status: Status,
pub units: Option<&'static str>,
}
pub fn lookup(id: u16) -> Option<&'static InformationElement> {
INFORMATION_ELEMENTS
.binary_search_by_key(&id, |ie| ie.id)
.ok()
.map(|idx| &INFORMATION_ELEMENTS[idx])
}
pub fn lookup_by_name(name: &str) -> Option<&'static InformationElement> {
INFORMATION_ELEMENTS.iter().find(|ie| ie.name == name)
}