Refactor vpp.go to have the connection mgmt and vpp_*.go to have one Manager each

This commit is contained in:
Pim van Pelt
2025-06-24 07:00:52 +02:00
parent 96b9dd501d
commit bdaa2e366b
4 changed files with 364 additions and 206 deletions

View File

@@ -45,11 +45,19 @@ func main() {
log.Fatalf("Failed to start AgentX: %v", err)
}
// Set up interface event callback to update interface details
vpp.SetInterfaceEventCallback(interfaceMIB.UpdateInterfaceDetails)
// Create VPP client and managers
vppClient := vpp.NewVPPClient()
interfaceManager := vpp.NewInterfaceManager(vppClient)
statsManager := vpp.NewStatsManager(vppClient, interfaceManager)
// Start VPP stats routine with callback to update MIB
vpp.StartStatsRoutine(interfaceMIB.UpdateStats)
// Set up interface event callback to update interface details
interfaceManager.SetEventCallback(interfaceMIB.UpdateInterfaceDetails)
// Set up stats callback to update MIB
statsManager.SetStatsCallback(interfaceMIB.UpdateStats)
// Start VPP stats routine
statsManager.StartStatsRoutine()
// Set up signal handling for graceful shutdown
sigChan := make(chan os.Signal, 1)
@@ -59,6 +67,10 @@ func main() {
<-sigChan
logger.Printf("Shutting down...")
// Stop stats routine and disconnect
statsManager.StopStatsRoutine()
vppClient.Disconnect()
// Flush any buffered log entries
logger.Sync()
}