mirror of
https://github.com/calmh/ipfix.git
synced 2026-07-17 01:25:03 +00:00
IPFIX parser package for Go
- Go 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| etc | ||
| .gitignore | ||
| benchmark_test.go | ||
| build.sh | ||
| builtin-dictionary.go | ||
| debug.go | ||
| doc.go | ||
| examples_test.go | ||
| interpreter.go | ||
| interpreter_test.go | ||
| Jenkinsfile | ||
| LICENSE | ||
| parser.go | ||
| parser_fuzz.go | ||
| parser_test.go | ||
| read.go | ||
| README.md | ||
| rfc5103.go | ||
| rfc5103_test.go | ||
| slice.go | ||
| slice_test.go | ||
ipfix
Package ipfix implements an IPFIX (RFC 5101) parser and interpreter.
Input data from an io.Reader or a []byte is parsed and chunked into
messages. Template management and the standard IPFIX types are implemented
so a fully parsed data set can be produced. Vendor fields can be added at
runtime.
Example
To read an IPFIX stream, create a Session and then use ParseBuffer to parse data coming from a single UDP packet or similar.
var conn net.PacketConn // from somewhere
buf := make([]byte, 65507) // maximum UDP payload length
s := ipfix.NewSession()
for {
n, _, err := conn.ReadFrom(buf)
// handle err
msg, err := s.ParseBuffer(buf[:n])
// handle msg and err
}
To interpret records for correct data types and field names, use an interpreter:
i := ipfix.NewInterpreter(s)
var fieldList []ipfix.InterpretedField
for _, rec := range msg.DataRecords {
fieldList = i.InterpretInto(rec, fieldList[:cap(fieldList)])
// handle the field list
}
To add a vendor field to the dictionary so that it will be resolved by Interpret, create a DictionaryEntry and call AddDictionaryEntry.
e := ipfix.DictionaryEntry{
Name: "someVendorField",
FieldId: 42,
EnterpriseId: 123456,
Type: ipfix.Int32
}
i.AddDictionaryEntry(e)
License
The MIT license.
Usage
See the documentation.