summaryrefslogtreecommitdiffhomepage
path: root/api/util.go
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2018-05-09 15:14:25 +0900
committerIWASE Yusuke <iwase.yusuke0@gmail.com>2018-06-13 10:54:00 +0900
commit417f8ba6f54c4010b746d6262eb77683851f1db5 (patch)
treec546ea896f4488511832867165febdec3d995fa4 /api/util.go
parent84987fb8732b6d2cce89e4cbc4009f6341592ec9 (diff)
api: Use api/attribute.proto structure in gRPC API
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'api/util.go')
-rw-r--r--api/util.go43
1 files changed, 29 insertions, 14 deletions
diff --git a/api/util.go b/api/util.go
index 69fdc788..90aa5384 100644
--- a/api/util.go
+++ b/api/util.go
@@ -61,7 +61,7 @@ func (d *Destination) ToNativeDestination(option ...ToNativeOption) (*table.Dest
if len(d.Paths) == 0 {
return nil, fmt.Errorf("no path in destination")
}
- nlri, err := getNLRI(bgp.RouteFamily(d.Paths[0].Family), d.Paths[0].Nlri)
+ nlri, err := d.Paths[0].GetNativeNlri()
if err != nil {
return nil, err
}
@@ -86,7 +86,30 @@ func (d *Destination) ToNativeDestination(option ...ToNativeOption) (*table.Dest
}
func (p *Path) GetNativeNlri() (bgp.AddrPrefixInterface, error) {
- return getNLRI(bgp.RouteFamily(p.Family), p.Nlri)
+ if len(p.Nlri) > 0 {
+ return getNLRI(bgp.RouteFamily(p.Family), p.Nlri)
+ }
+ return UnmarshalNLRI(bgp.RouteFamily(p.Family), p.AnyNlri)
+}
+
+func (p *Path) GetNativePathAttributes() ([]bgp.PathAttributeInterface, error) {
+ pattrsLen := len(p.Pattrs)
+ if pattrsLen > 0 {
+ pattrs := make([]bgp.PathAttributeInterface, 0, pattrsLen)
+ for _, attr := range p.Pattrs {
+ a, err := bgp.GetPathAttribute(attr)
+ if err != nil {
+ return nil, err
+ }
+ err = a.DecodeFromBytes(attr)
+ if err != nil {
+ return nil, err
+ }
+ pattrs = append(pattrs, a)
+ }
+ return pattrs, nil
+ }
+ return UnmarshalPathAttributes(p.AnyPattrs)
}
func (p *Path) ToNativePath(option ...ToNativeOption) (*table.Path, error) {
@@ -105,22 +128,14 @@ func (p *Path) ToNativePath(option ...ToNativeOption) (*table.Path, error) {
}
if nlri == nil {
var err error
- nlri, err = getNLRI(bgp.RouteFamily(p.Family), p.Nlri)
+ nlri, err = p.GetNativeNlri()
if err != nil {
return nil, err
}
}
- pattr := make([]bgp.PathAttributeInterface, 0, len(p.Pattrs))
- for _, attr := range p.Pattrs {
- p, err := bgp.GetPathAttribute(attr)
- if err != nil {
- return nil, err
- }
- err = p.DecodeFromBytes(attr)
- if err != nil {
- return nil, err
- }
- pattr = append(pattr, p)
+ pattr, err := p.GetNativePathAttributes()
+ if err != nil {
+ return nil, err
}
t := time.Unix(p.Age, 0)
nlri.SetPathIdentifier(p.Identifier)