Skip to content

Commit

Permalink
fix(evpn): netlink review update
Browse files Browse the repository at this point in the history
Signed-off-by: Saikumar, Banoth <[email protected]>
  • Loading branch information
Inbanoth committed Aug 8, 2024
1 parent bb3e67f commit 574dd59
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 55 deletions.
2 changes: 1 addition & 1 deletion pkg/netlink/fdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func checkFdbType(fdbtype int) bool {
}

// installFilterFDB install fdb filer
func (fdb *FdbEntryStruct) installFilterFDB() bool {
func (fdb *FdbEntryStruct) filter() bool {
// Drop entries w/o VLAN ID or associated LogicalBridge ...
// ... other than with L2 nexthops of type VXLAN and BridgePort ...
// ... and VXLAN entries with unresolved underlay nextop.
Expand Down
2 changes: 1 addition & 1 deletion pkg/netlink/l2nexthop.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (l2n *L2NexthopStruct) annotate() {
}

// installFilterL2N install the l2 filter
func (l2n *L2NexthopStruct) installFilterL2N() bool {
func (l2n *L2NexthopStruct) filter() bool {
keep := !(l2n.Type == 0 && l2n.Resolved && len(l2n.FdbRefs) == 0)
return keep
}
Expand Down
90 changes: 39 additions & 51 deletions pkg/netlink/netlink_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,67 +35,57 @@ func notifyDBChanges() {
notifyDBCompChanges[L2NexthopKey, *L2NexthopStruct](latestL2Nexthop, l2Nexthops, L2NEXTHOP, l2NexthopOperations)
}

// Filterable method for each type
type Filterable interface {
ShouldFilter() bool
// dboperations interface
type dboperations interface {
annotate()
filter() bool
}

// applyInstallFilters install the filters
func applyInstallFilters() {
filterMap(latestRoutes, func(r *RouteStruct) bool { return r.installFilterRoute() })
filterMap(latestNexthop, func(n *NexthopStruct) bool { return n.installFilterNH() })
filterMap(latestFDB, func(f *FdbEntryStruct) bool { return f.installFilterFDB() })
filterMap(latestL2Nexthop, func(l *L2NexthopStruct) bool { return l.installFilterL2N() })
type genericDB[K comparable, V dboperations] struct {
compDB map[K]V
}

// filterMap install the filters
func filterMap[K comparable, V Filterable](m map[K]V, shouldFilter func(V) bool) {
for key, value := range m {
if !shouldFilter(value) {
delete(m, key)
}
}
func newGenericDB[K comparable, V dboperations](data map[K]V) *genericDB[K, V] {
return &genericDB[K, V]{compDB: data}
}

// ShouldFilter method for each type
func (route *RouteStruct) ShouldFilter() bool {
return route.installFilterRoute()
func (db *genericDB[K, V]) annotate() {
for key, value := range db.compDB {
value.annotate()
db.compDB[key] = value
}
}

// ShouldFilter method for each type
func (nexthop *NexthopStruct) ShouldFilter() bool {
return nexthop.installFilterNH()
func (db *genericDB[K, V]) filter() {
for key, value := range db.compDB {
if !value.filter() {
delete(db.compDB, key)
}
}
}

// ShouldFilter method for each type
func (fdb *FdbEntryStruct) ShouldFilter() bool {
return fdb.installFilterFDB()
}
// annotateAndFilterDB annonates and filters the latest db updates
func annotateAndFilterDB() {
latestNexthopDB := newGenericDB(latestNexthop)
latestNexthopDB.annotate()
latestNexthopDB.filter()

// ShouldFilter method for each type
func (l *L2NexthopStruct) ShouldFilter() bool {
return l.installFilterL2N()
}
latestRoutesDB := newGenericDB(latestRoutes)
latestRoutesDB.annotate()
latestRoutesDB.filter()

// Annotatable interface
type Annotatable interface {
annotate()
}
latestFdbDB := newGenericDB(latestFDB)
latestFdbDB.annotate()
latestFdbDB.filter()

// annotateMap annonates the latest db map updates
func annotateMap[K comparable, V Annotatable](m map[K]V) {
for key, value := range m {
value.annotate()
m[key] = value
}
}
latestL2NexthopDB := newGenericDB(latestL2Nexthop)
latestL2NexthopDB.annotate()
latestL2NexthopDB.filter()

// annotateDBEntries annonates the latest db updates
func annotateDBEntries() {
annotateMap(latestNexthop)
annotateMap(latestRoutes)
annotateMap(latestFDB)
annotateMap(latestL2Nexthop)
latestNexthop = latestNexthopDB.compDB
latestRoutes = latestRoutesDB.compDB
latestFDB = latestFdbDB.compDB
latestL2Nexthop = latestL2NexthopDB.compDB
}

// readLatestNetlinkState reads the latest netlink state
Expand All @@ -116,10 +106,8 @@ func readLatestNetlinkState() {
func resyncWithKernel() {
// Build a new DB snapshot from netlink and other sources
readLatestNetlinkState()
// Annotate the latest DB entries
annotateDBEntries()
// Filter the latest DB to retain only entries to be installed
applyInstallFilters()
// Annotate and filter the latest DB entries
annotateAndFilterDB()
// Compute changes between current and latest DB versions and inform subscribers about the changes
notifyDBChanges()
routes = latestRoutes
Expand Down
2 changes: 1 addition & 1 deletion pkg/netlink/nexthop.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func checkNhType(nType int) bool {
}

// installFilterNH install the neighbor filter
func (nexthop *NexthopStruct) installFilterNH() bool {
func (nexthop *NexthopStruct) filter() bool {
check := checkNhType(nexthop.NhType)
keep := check && nexthop.Resolved && len(nexthop.RouteRefs) != 0
return keep
Expand Down
2 changes: 1 addition & 1 deletion pkg/netlink/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ func checkRtype(rType string) bool {
}

// installFilterRoute install the route filter
func (route *RouteStruct) installFilterRoute() bool {
func (route *RouteStruct) filter() bool {
var nh []*NexthopStruct
for _, n := range route.Nexthops {
if n.Resolved {
Expand Down

0 comments on commit 574dd59

Please sign in to comment.