diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-06-17 22:25:44 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-07-06 11:08:15 +0900 |
commit | cc92e7e3476f416b533de3f1a68de71c5af476c5 (patch) | |
tree | 48ae3d75fa92f33cb54c102c0b03dabb4086b8e3 /api | |
parent | 00e9610df02e3a9227a8a9324faed5fddfb7a87d (diff) |
gobgp: fix client.AddPath to use api.Path instead of table.Path
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'api')
-rw-r--r-- | api/grpc_server.go | 17 | ||||
-rw-r--r-- | api/util.go | 23 |
2 files changed, 21 insertions, 19 deletions
diff --git a/api/grpc_server.go b/api/grpc_server.go index 3fa65ee5..f6f5913f 100644 --- a/api/grpc_server.go +++ b/api/grpc_server.go @@ -473,23 +473,6 @@ func toPathAPI(binNlri []byte, binPattrs [][]byte, anyNlri *any.Any, anyPattrs [ return p } -func ToPathApiInBin(path *table.Path, v *table.Validation) *Path { - nlri := path.GetNlri() - binNlri, _ := nlri.Serialize() - if path.IsWithdraw { - return toPathAPI(binNlri, nil, nil, nil, path, v) - } - binPattrs := func(attrs []bgp.PathAttributeInterface) [][]byte { - bufList := make([][]byte, 0, len(attrs)) - for _, a := range attrs { - buf, _ := a.Serialize() - bufList = append(bufList, buf) - } - return bufList - }(path.GetPathAttrs()) - return toPathAPI(binNlri, binPattrs, nil, nil, path, v) -} - func ToPathApi(path *table.Path, v *table.Validation) *Path { nlri := path.GetNlri() anyNlri := MarshalNLRI(nlri) diff --git a/api/util.go b/api/util.go index 721909c5..9b7a389e 100644 --- a/api/util.go +++ b/api/util.go @@ -18,6 +18,7 @@ package gobgpapi import ( "encoding/json" "net" + "time" "github.com/osrg/gobgp/config" "github.com/osrg/gobgp/packet/bgp" @@ -39,9 +40,27 @@ func (d *Destination) MarshalJSON() ([]byte, error) { return json.Marshal(d.Paths) } +func NewPath(nlri bgp.AddrPrefixInterface, isWithdraw bool, attrs []bgp.PathAttributeInterface, age time.Time) *Path { + return &Path{ + AnyNlri: MarshalNLRI(nlri), + AnyPattrs: MarshalPathAttributes(attrs), + Age: age.Unix(), + IsWithdraw: isWithdraw, + Family: uint32(bgp.AfiSafiToRouteFamily(nlri.AFI(), nlri.SAFI())), + Identifier: nlri.PathIdentifier(), + } +} + func (p *Path) MarshalJSON() ([]byte, error) { - nlri, _ := p.GetNativeNlri() - attrs, _ := p.GetNativePathAttributes() + nlri, err := p.GetNativeNlri() + if err != nil { + return nil, err + } + attrs, err := p.GetNativePathAttributes() + if err != nil { + return nil, err + } + return json.Marshal(struct { Nlri bgp.AddrPrefixInterface `json:"nlri"` Age int64 `json:"age"` |