1
0
mirror of https://github.com/netsampler/goflow2.git synced 2024-05-06 15:54:52 +00:00

82 lines
2.4 KiB
Go
Raw Normal View History

2021-05-22 16:12:26 -07:00
package sflow
2023-08-09 19:47:20 -07:00
import (
"fmt"
"net/netip"
)
2021-05-22 16:12:26 -07:00
type Packet struct {
2023-08-09 19:47:20 -07:00
Version uint32 `json:"version"`
IPVersion uint32 `json:"ip-version"`
AgentIP IPAddress `json:"agent-ip"`
SubAgentId uint32 `json:"sub-agent-id"`
SequenceNumber uint32 `json:"sequence-number"`
Uptime uint32 `json:"uptime"`
SamplesCount uint32 `json:"samples-count"`
Samples []interface{} `json:"samples"`
}
type IPAddress []byte // purely for the formatting purpose
func (s IPAddress) MarshalJSON() ([]byte, error) {
ip, _ := netip.AddrFromSlice([]byte(s))
return []byte(fmt.Sprintf("\"%s\"", ip.String())), nil
2021-05-22 16:12:26 -07:00
}
type SampleHeader struct {
2023-08-09 19:47:20 -07:00
Format uint32 `json:"format"`
Length uint32 `json:"length"`
2021-05-22 16:12:26 -07:00
2023-08-09 19:47:20 -07:00
SampleSequenceNumber uint32 `json:"sample-sequence-number"`
SourceIdType uint32 `json:"source-id-type"`
SourceIdValue uint32 `json:"source-id-value"`
2021-05-22 16:12:26 -07:00
}
type FlowSample struct {
2023-08-09 19:47:20 -07:00
Header SampleHeader `json:"header"`
2021-05-22 16:12:26 -07:00
2023-08-09 19:47:20 -07:00
SamplingRate uint32 `json:"sampling-rate"`
SamplePool uint32 `json:"sample-pool"`
Drops uint32 `json:"drops"`
Input uint32 `json:"input"`
Output uint32 `json:"output"`
FlowRecordsCount uint32 `json:"flow-records-count"`
Records []FlowRecord `json:"records"`
2021-05-22 16:12:26 -07:00
}
type CounterSample struct {
2023-08-09 19:47:20 -07:00
Header SampleHeader `json:"header"`
2021-05-22 16:12:26 -07:00
2023-08-09 19:47:20 -07:00
CounterRecordsCount uint32 `json:"counter-records-count"`
Records []CounterRecord `json:"records"`
2021-05-22 16:12:26 -07:00
}
type ExpandedFlowSample struct {
2023-08-09 19:47:20 -07:00
Header SampleHeader `json:"header"`
2021-05-22 16:12:26 -07:00
2023-08-09 19:47:20 -07:00
SamplingRate uint32 `json:"sampling-rate"`
SamplePool uint32 `json:"sample-pool"`
Drops uint32 `json:"drops"`
InputIfFormat uint32 `json:"input-if-format"`
InputIfValue uint32 `json:"input-if-value"`
OutputIfFormat uint32 `json:"output-if-format"`
OutputIfValue uint32 `json:"output-if-value"`
FlowRecordsCount uint32 `json:"flow-records-count"`
Records []FlowRecord `json:"records"`
2021-05-22 16:12:26 -07:00
}
type RecordHeader struct {
2023-08-09 19:47:20 -07:00
DataFormat uint32 `json:"data-format"`
Length uint32 `json:"length"`
2021-05-22 16:12:26 -07:00
}
type FlowRecord struct {
2023-08-09 19:47:20 -07:00
Header RecordHeader `json:"header"`
Data interface{} `json:"data"`
}
2021-05-22 16:12:26 -07:00
type CounterRecord struct {
2023-08-09 19:47:20 -07:00
Header RecordHeader `json:"header"`
Data interface{} `json:"data"`
2021-05-22 16:12:26 -07:00
}