Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RIS-Mirror: Refactoring #434

Merged
merged 1 commit into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions cmd/ris-mirror/rismirror/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rismirror

import (
"net"
"sync"

"github.com/bio-routing/bio-rd/risclient"
"github.com/bio-routing/bio-rd/routingtable/vrf"
Expand All @@ -14,16 +15,17 @@ import (
type Router struct {
name string
address net.IP
vrfRegistry *vrf.VRFRegistry
vrfs map[uint64]*_vrf
vrfs map[uint64]*vrfWithMergedLocRIBs // this is the authoritative data store for VRFs
vrfsMu sync.RWMutex
vrfRegistry *vrf.VRFRegistry // this is only there so that the metrics functionality of the vrf package can be used
BarbarossaTM marked this conversation as resolved.
Show resolved Hide resolved
}

func newRouter(name string, address net.IP) *Router {
return &Router{
name: name,
address: address,
vrfs: make(map[uint64]*vrfWithMergedLocRIBs),
vrfRegistry: vrf.NewVRFRegistry(),
vrfs: make(map[uint64]*_vrf),
}
}

Expand All @@ -43,18 +45,36 @@ func (r *Router) Ready(vrf uint64, afi uint16) (bool, error) {

// GetVRF gets a VRF by its RD
func (r *Router) GetVRF(rd uint64) *vrf.VRF {
return r.vrfRegistry.GetVRFByName(vrf.RouteDistinguisherHumanReadable(rd))
r.vrfsMu.RLock()
defer r.vrfsMu.RUnlock()

_vrf := r.vrfs[rd]
if _vrf == nil {
return nil
}

return _vrf.vrf
}

// GetVRFs gets all VRFs
func (r *Router) GetVRFs() []*vrf.VRF {
return r.vrfRegistry.List()
r.vrfsMu.RLock()
defer r.vrfsMu.RUnlock()

ret := make([]*vrf.VRF, 0, len(r.vrfs))
for _, v := range r.vrfs {
ret = append(ret, v.vrf)
}

return ret
}

func (r *Router) addVRF(rd uint64, sources []*grpc.ClientConn) {
v := r.vrfRegistry.CreateVRFIfNotExists(vrf.RouteDistinguisherHumanReadable(rd), rd)
r.vrfsMu.Lock()
defer r.vrfsMu.Unlock()

r.vrfs[rd] = newVRF(v.IPv4UnicastRIB(), v.IPv6UnicastRIB())
v := r.vrfRegistry.CreateVRFIfNotExists(vrf.RouteDistinguisherHumanReadable(rd), rd)
r.vrfs[rd] = newVRFWithMergedLocRIBs(v.IPv4UnicastRIB(), v.IPv6UnicastRIB())

for _, src := range sources {
r.connectVRF(rd, src, 4)
Expand Down
10 changes: 6 additions & 4 deletions cmd/ris-mirror/rismirror/vrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@ package rismirror
import (
"github.com/bio-routing/bio-rd/routingtable/locRIB"
"github.com/bio-routing/bio-rd/routingtable/mergedlocrib"
"github.com/bio-routing/bio-rd/routingtable/vrf"
)

type _vrf struct {
type vrfWithMergedLocRIBs struct {
vrf *vrf.VRF
BarbarossaTM marked this conversation as resolved.
Show resolved Hide resolved
ipv4Unicast *mergedlocrib.MergedLocRIB
ipv6Unicast *mergedlocrib.MergedLocRIB
}

func newVRF(locRIBIPv4Unicast, locRIBIPv6Unicast *locRIB.LocRIB) *_vrf {
return &_vrf{
func newVRFWithMergedLocRIBs(locRIBIPv4Unicast, locRIBIPv6Unicast *locRIB.LocRIB) *vrfWithMergedLocRIBs {
return &vrfWithMergedLocRIBs{
ipv4Unicast: mergedlocrib.New(locRIBIPv4Unicast),
ipv6Unicast: mergedlocrib.New(locRIBIPv6Unicast),
}
}

func (v *_vrf) getRIB(afi uint8) *mergedlocrib.MergedLocRIB {
func (v *vrfWithMergedLocRIBs) getRIB(afi uint8) *mergedlocrib.MergedLocRIB {
if afi == 6 {
return v.ipv6Unicast
}
Expand Down