From 97ad6b32ee61fd439c2edefbc371f748cdf82046 Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Sun, 26 Aug 2018 22:04:12 +0900 Subject: api: change Family fixes #1812 Avoid the cast and use strightforward data strcuture; two variables for afi and safi instead of squashing two into one variable. Signed-off-by: FUJITA Tomonori --- internal/pkg/apiutil/util.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'internal/pkg/apiutil/util.go') 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), + } +} -- cgit v1.2.3