mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-12 06:24:10 +01:00
At first, there was a tentative to use BMP collector implementation from bio-rd. However, this current implementation is using GoBGP instead: - BMP is very simple from a protocol point of view. The hard work is mostly around decoding. Both bio-rd and GoBGP can decode, but for testing, GoBGP is able to generate messages as well (this is its primary purpose, I suppose parsing was done for testing purpose). Using only one library is always better. An alternative would be GoBMP, but it also only do parsing. - Logging and metrics can be customized easily (but the work was done for bio-rd, so not a real argument). - bio-rd is an application and there is no API stability (and I did that too) - GoBGP supports FlowSpec, which may be useful in the future for the DDoS part. Again, one library for everything is better (but honestly, GoBGP as a lib is not the best part of it, maybe github.com/jwhited/corebgp would be a better fit while keeping GoBGP for decoding/encoding). There was a huge effort around having a RIB which is efficient memory-wise (data are interned to save memory), performant during reads, while being decent during insertions. We rely on a patched version of Kentik's Patricia trees to be able to apply mutations to the tree. There was several tentatives to implement some kind of graceful restart, but ultimetaly, the design is kept simple: when a BMP connection goes down, routes will be removed after a configurable time. If the connection comes back up, then it is just considered new. It would have been ideal to rely on EoR markers, but the RFC is unclear about them, and they are likely to be per peer, making it difficult to know what to do if one peer is back, but not the other. Remaining tasks: - [ ] Confirm support for LocRIB - [ ] Import data in ClickHouse - [ ] Make data available in the frontend Fix #52
136 lines
3.9 KiB
Go
136 lines
3.9 KiB
Go
// SPDX-FileCopyrightText: 2022 Free Mobile
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"akvorado/common/daemon"
|
|
"akvorado/common/http"
|
|
"akvorado/common/reporter"
|
|
"akvorado/demoexporter"
|
|
"akvorado/demoexporter/bmp"
|
|
"akvorado/demoexporter/flows"
|
|
"akvorado/demoexporter/snmp"
|
|
)
|
|
|
|
// DemoExporterConfiguration represents the configuration file for the demo exporter command.
|
|
type DemoExporterConfiguration struct {
|
|
Reporting reporter.Configuration
|
|
HTTP http.Configuration
|
|
DemoExporter demoexporter.Configuration `mapstructure:",squash" yaml:",inline"`
|
|
SNMP snmp.Configuration
|
|
BMP bmp.Configuration
|
|
Flows flows.Configuration
|
|
}
|
|
|
|
// Reset sets the default configuration for the demo exporter command.
|
|
func (c *DemoExporterConfiguration) Reset() {
|
|
*c = DemoExporterConfiguration{
|
|
HTTP: http.DefaultConfiguration(),
|
|
Reporting: reporter.DefaultConfiguration(),
|
|
DemoExporter: demoexporter.DefaultConfiguration(),
|
|
SNMP: snmp.DefaultConfiguration(),
|
|
BMP: bmp.DefaultConfiguration(),
|
|
Flows: flows.DefaultConfiguration(),
|
|
}
|
|
}
|
|
|
|
type demoExporterOptions struct {
|
|
ConfigRelatedOptions
|
|
CheckMode bool
|
|
}
|
|
|
|
// DemoExporterOptions stores the command-line option values for the
|
|
// demo exporter command.
|
|
var DemoExporterOptions demoExporterOptions
|
|
|
|
var demoExporterCmd = &cobra.Command{
|
|
Use: "demo-exporter",
|
|
Short: "Start a synthetic exporter",
|
|
Long: `For demo and testing purpose, this service exports synthetic flows
|
|
and answers SNMP requests.`,
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
config := DemoExporterConfiguration{}
|
|
DemoExporterOptions.Path = args[0]
|
|
if err := DemoExporterOptions.Parse(cmd.OutOrStdout(), "demo-exporter", &config); err != nil {
|
|
return err
|
|
}
|
|
|
|
r, err := reporter.New(config.Reporting)
|
|
if err != nil {
|
|
return fmt.Errorf("unable to initialize reporter: %w", err)
|
|
}
|
|
return demoExporterStart(r, config, DemoExporterOptions.CheckMode)
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
RootCmd.AddCommand(demoExporterCmd)
|
|
demoExporterCmd.Flags().BoolVarP(&DemoExporterOptions.ConfigRelatedOptions.Dump, "dump", "D", false,
|
|
"Dump configuration before starting")
|
|
demoExporterCmd.Flags().BoolVarP(&DemoExporterOptions.CheckMode, "check", "C", false,
|
|
"Check configuration, but does not start")
|
|
}
|
|
|
|
func demoExporterStart(r *reporter.Reporter, config DemoExporterConfiguration, checkOnly bool) error {
|
|
daemonComponent, err := daemon.New(r)
|
|
if err != nil {
|
|
return fmt.Errorf("unable to initialize daemon component: %w", err)
|
|
}
|
|
httpComponent, err := http.New(r, config.HTTP, http.Dependencies{
|
|
Daemon: daemonComponent,
|
|
})
|
|
if err != nil {
|
|
return fmt.Errorf("unable to initialize HTTP component: %w", err)
|
|
}
|
|
snmpComponent, err := snmp.New(r, config.SNMP, snmp.Dependencies{
|
|
Daemon: daemonComponent,
|
|
})
|
|
if err != nil {
|
|
return fmt.Errorf("unable to initialize SNMP component: %w", err)
|
|
}
|
|
bmpComponent, err := bmp.New(r, config.BMP, bmp.Dependencies{
|
|
Daemon: daemonComponent,
|
|
})
|
|
if err != nil {
|
|
return fmt.Errorf("unable to initialize BMP component: %w", err)
|
|
}
|
|
flowsComponent, err := flows.New(r, config.Flows, flows.Dependencies{
|
|
Daemon: daemonComponent,
|
|
})
|
|
if err != nil {
|
|
return fmt.Errorf("unable to initialize flows component: %w", err)
|
|
}
|
|
demoExporterComponent, err := demoexporter.New(r, config.DemoExporter, demoexporter.Dependencies{
|
|
SNMP: snmpComponent,
|
|
Flows: flowsComponent,
|
|
})
|
|
if err != nil {
|
|
return fmt.Errorf("unable to initialize exporter component: %w", err)
|
|
}
|
|
|
|
// Expose some informations and metrics
|
|
addCommonHTTPHandlers(r, "demo-exporter", httpComponent)
|
|
versionMetrics(r)
|
|
|
|
// If we only asked for a check, stop here.
|
|
if checkOnly {
|
|
return nil
|
|
}
|
|
|
|
// Start all the components.
|
|
components := []interface{}{
|
|
httpComponent,
|
|
snmpComponent,
|
|
bmpComponent,
|
|
flowsComponent,
|
|
demoExporterComponent,
|
|
}
|
|
return StartStopComponents(r, daemonComponent, components)
|
|
}
|