Skip to content

Commit

Permalink
renaming and reducing code complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
Cellebyte committed Jan 18, 2024
1 parent ab6f52e commit 7a679c0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
17 changes: 7 additions & 10 deletions pkg/frr/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"github.com/telekom/das-schiff-network-operator/pkg/nl"
"github.com/telekom/das-schiff-network-operator/pkg/route"
"github.com/vishvananda/netlink"
"golang.org/x/exp/maps"
)

func getQuantity(routeSummaries RouteSummaries, addressFamily int, vrf, table string) ([]route.Information, error) {
// _ is the cidr and is ignored.
routeSummaryList := []route.Information{}
routeSummaryMap := map[route.Key]route.Information{}
routeSummaryInfos := map[route.Key]route.Information{}
for _, routeSummary := range routeSummaries.Routes {
routeProtocol := netlink.RouteProtocol(nl.GetProtocolNumber(routeSummary.Type, true))
family, err := nl.GetAddressFamily(addressFamily)
Expand All @@ -24,9 +24,9 @@ func getQuantity(routeSummaries RouteSummaries, addressFamily int, vrf, table st
return nil, fmt.Errorf("error converting string to integer [%s]: %w", table, err)
}
routeKey := route.Key{TableID: tableID, RouteProtocol: int(routeProtocol), AddressFamily: addressFamily}
routeInformation, ok := routeSummaryMap[routeKey]
routeInformation, ok := routeSummaryInfos[routeKey]
if !ok {
routeSummaryMap[routeKey] = route.Information{
routeSummaryInfos[routeKey] = route.Information{
TableID: tableID,
VrfName: vrf,
RouteProtocol: routeProtocol,
Expand All @@ -38,13 +38,10 @@ func getQuantity(routeSummaries RouteSummaries, addressFamily int, vrf, table st
// if we have ibgp and ebgp they both.
routeInformation.Rib += routeSummary.Rib
routeInformation.Fib += routeSummary.Fib
routeSummaryMap[routeKey] = routeInformation
routeSummaryInfos[routeKey] = routeInformation
}
}
for _, routeSummary := range routeSummaryMap {
routeSummaryList = append(routeSummaryList, routeSummary)
}
return routeSummaryList, nil
return maps.Values(routeSummaryInfos), nil
}

func (m *Manager) ListVrfs() ([]VrfVniSpec, error) {
Expand Down Expand Up @@ -81,7 +78,7 @@ func (m *Manager) ListRouteSummary(vrf string) ([]route.Information, error) {
return routeList, nil
}

func (m *Manager) ListNeighbors(vrf string) (bgpSummary BGPVrfSummary, err error) {
func (m *Manager) ListBGPNeighbors(vrf string) (bgpSummary BGPVrfSummary, err error) {
bgpSummary, err = m.Cli.ShowBGPSummary(vrf)
if err != nil {
return bgpSummary, fmt.Errorf("cannot get BGPSummary for vrf %s: %w", vrf, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/monitoring/frr.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (c *frrCollector) UpdateRoutes(ch chan<- prometheus.Metric) {
}

func (c *frrCollector) UpdateBGPNeighbors(ch chan<- prometheus.Metric) {
bgpNeighbors, err := c.frr.ListNeighbors("")
bgpNeighbors, err := c.frr.ListBGPNeighbors("")
if err != nil {
c.logger.Error(err, "can't get bgpNeighbors from frr: %w")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/monitoring/nl.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewNetlinkCollector() (Collector, error) {
collector := netlinkCollector{
routesFibDesc: typedFactoryDesc{
desc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "netlink", "routes"),
prometheus.BuildFQName(namespace, "netlink", "routes_fib"),
"The number of routes currently in the Linux Dataplane.",
[]string{"table", "vrf", "protocol", "address_family"},
nil,
Expand Down
5 changes: 0 additions & 5 deletions pkg/nl/layer2.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,6 @@ func (n *NetlinkManager) ListNeighborInformation() ([]NeighborInformation, error
return nil, fmt.Errorf("error getting link by index: %w", err)
}
interfaceName := linkInfo.Attrs().Name
// If NOARP is set on neighbor we skip it here
// We also want the vxlan neighbors probably.
// if netlinkNeighbors[index].State == netlink.NUD_NOARP {
// continue
// }
// This ensures that only neighbors of secondary interfaces are imported
// or hardware interfaces which support VFs
if strings.HasPrefix(interfaceName, vethL2Prefix) ||
Expand Down

0 comments on commit 7a679c0

Please sign in to comment.