diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-08-26 22:04:12 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-08-28 15:36:50 +0900 |
commit | 97ad6b32ee61fd439c2edefbc371f748cdf82046 (patch) | |
tree | 7e06da9270ed2fc826939f462662a75b9e7b1714 /internal/pkg/apiutil/util.go | |
parent | 23ac6ebb861a725273c6b663dc484becef55087c (diff) |
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 <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'internal/pkg/apiutil/util.go')
-rw-r--r-- | internal/pkg/apiutil/util.go | 17 |
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), + } +} |