-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathioam-agent.go
More file actions
43 lines (34 loc) · 1.1 KB
/
ioam-agent.go
File metadata and controls
43 lines (34 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//go:build !afpacket
// +build !afpacket
package main
import (
"log"
ioamAPI "github.com/Advanced-Observability/ioam-api"
"github.com/google/gopacket"
"github.com/Advanced-Observability/ioam-agent/internal/capture"
"github.com/Advanced-Observability/ioam-agent/internal/config"
"github.com/Advanced-Observability/ioam-agent/internal/parser"
"github.com/Advanced-Observability/ioam-agent/internal/reporter"
"github.com/Advanced-Observability/ioam-agent/internal/stats"
)
func main() {
cfg := config.ParseFlags()
source, err := capture.InitializeCapture(cfg.Interface)
if err != nil {
log.Fatalf("Failed to initialize capture: %v", err)
}
reportFunc := reporter.SetupReporting(cfg)
go stats.WriteStats(cfg.Statfile, cfg.Interface, cfg.Interval)
packets := make(chan gopacket.Packet, cfg.Workers)
for w := uint(1); w <= cfg.Workers; w++ {
go worker(w, packets, reportFunc)
}
for packet := range source.Packets() {
packets <- packet
}
}
func worker(id uint, packets <-chan gopacket.Packet, report func(*ioamAPI.IOAMTrace)) {
for packet := range packets {
parser.ParsePacket(packet, report)
}
}