summaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/apiutil/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/pkg/apiutil/util.go')
-rw-r--r--internal/pkg/apiutil/util.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/internal/pkg/apiutil/util.go b/internal/pkg/apiutil/util.go
index 45cf1a04..4c18b752 100644
--- a/internal/pkg/apiutil/util.go
+++ b/internal/pkg/apiutil/util.go
@@ -69,7 +69,7 @@ func NewPath(nlri bgp.AddrPrefixInterface, isWithdraw bool, attrs []bgp.PathAttr
AnyPattrs: MarshalPathAttributes(attrs),
Age: age.Unix(),
IsWithdraw: isWithdraw,
- Family: uint32(bgp.AfiSafiToRouteFamily(nlri.AFI(), nlri.SAFI())),
+ Family: ToApiFamily(nlri.AFI(), nlri.SAFI()),
Identifier: nlri.PathIdentifier(),
}
}
@@ -88,9 +88,9 @@ func getNLRI(family bgp.RouteFamily, buf []byte) (bgp.AddrPrefixInterface, error
func GetNativeNlri(p *api.Path) (bgp.AddrPrefixInterface, error) {
if len(p.Nlri) > 0 {
- return getNLRI(bgp.RouteFamily(p.Family), p.Nlri)
+ return getNLRI(ToRouteFamily(p.Family), p.Nlri)
}
- return UnmarshalNLRI(bgp.RouteFamily(p.Family), p.AnyNlri)
+ return UnmarshalNLRI(ToRouteFamily(p.Family), p.AnyNlri)
}
func GetNativePathAttributes(p *api.Path) ([]bgp.PathAttributeInterface, error) {
@@ -112,3 +112,14 @@ func GetNativePathAttributes(p *api.Path) ([]bgp.PathAttributeInterface, error)
}
return UnmarshalPathAttributes(p.AnyPattrs)
}
+
+func ToRouteFamily(f *api.Family) bgp.RouteFamily {
+ return bgp.AfiSafiToRouteFamily(uint16(f.Afi), uint8(f.Safi))
+}
+
+func ToApiFamily(afi uint16, safi uint8) *api.Family {
+ return &api.Family{
+ Afi: api.Family_Afi(afi),
+ Safi: api.Family_Safi(safi),
+ }
+}