Skip to content

Commit

Permalink
Make RIBIn/RIBOut of BMP neighbors accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
sebageek committed May 24, 2020
1 parent bfe8627 commit ff689d7
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions protocols/bgp/server/bmp_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/bio-routing/bio-rd/protocols/bgp/packet"
bmppkt "github.com/bio-routing/bio-rd/protocols/bmp/packet"
"github.com/bio-routing/bio-rd/routingtable"
"github.com/bio-routing/bio-rd/routingtable/adjRIBIn"
"github.com/bio-routing/bio-rd/routingtable/adjRIBOut"
"github.com/bio-routing/bio-rd/routingtable/filter"
"github.com/bio-routing/bio-rd/routingtable/vrf"
"github.com/bio-routing/tflow2/convert"
Expand Down Expand Up @@ -197,6 +199,48 @@ func (r *Router) processInitiationMsg(msg *bmppkt.InitiationMessage) {
r.logger.Info(logMsg)
}

func (r *Router) getNeighborAddressFamily(addr *bnet.IP, afi uint16, safi uint8) (*fsmAddressFamily, error) {
if safi != packet.UnicastSAFI {
return nil, fmt.Errorf("Unsupported safi, only unicast is supported")
}

for _, neigh := range r.neighborManager.list() {
if *neigh.fsm.peer.addr == *addr {
af := neigh.fsm.addressFamily(afi, safi)
if af == nil {
return nil, fmt.Errorf("Address family not available")
}
return af, nil
}
}

return nil, fmt.Errorf("Could not find neighbor with ip %s", addr.String())
}

// GetNeighborRIBIn returns the AdjRIBIn of a BMP neighbor
func (r *Router) GetNeighborRIBIn(addr *bnet.IP, afi uint16, safi uint8) (*adjRIBIn.AdjRIBIn, error) {
neighAF, err := r.getNeighborAddressFamily(addr, afi, safi)
if err != nil {
return nil, errors.Wrap(err, "Could not get RIBIn")
}
if neighAF.adjRIBIn == nil {
return nil, fmt.Errorf("RIBIn not available")
}
return neighAF.adjRIBIn.(*adjRIBIn.AdjRIBIn), nil
}

// GetNeighborRIBOut returns the AdjRIBOut of a BMP neighbor
func (r *Router) GetNeighborRIBOut(addr *bnet.IP, afi uint16, safi uint8) (*adjRIBOut.AdjRIBOut, error) {
neighAF, err := r.getNeighborAddressFamily(addr, afi, safi)
if err != nil {
return nil, errors.Wrap(err, "Could not get RIBIn")
}
if neighAF.adjRIBOut == nil {
return nil, fmt.Errorf("RIBOut not available")
}
return neighAF.adjRIBOut.(*adjRIBOut.AdjRIBOut), nil
}

func (r *Router) processTerminationMsg(msg *bmppkt.TerminationMessage) {
const (
stringType = 0
Expand Down

0 comments on commit ff689d7

Please sign in to comment.