summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--client/client.go28
-rw-r--r--gobgp/cmd/common.go7
-rw-r--r--gobgp/cmd/vrf.go31
3 files changed, 29 insertions, 37 deletions
diff --git a/client/client.go b/client/client.go
index 3bdef91d..05877198 100644
--- a/client/client.go
+++ b/client/client.go
@@ -461,36 +461,12 @@ func (cli *Client) DeletePathByFamily(family bgp.RouteFamily) error {
return cli.deletePath(nil, family, "", nil)
}
-func (cli *Client) GetVRF() ([]*table.Vrf, error) {
+func (cli *Client) GetVRF() ([]*api.Vrf, error) {
ret, err := cli.cli.GetVrf(context.Background(), &api.GetVrfRequest{})
if err != nil {
return nil, err
}
- var vrfs []*table.Vrf
-
- for _, vrf := range ret.Vrfs {
- rd, err := api.UnmarshalRD(vrf.Rd)
- if err != nil {
- return nil, err
- }
- importRT, err := api.UnmarshalRTs(vrf.ImportRt)
- if err != nil {
- return nil, err
- }
- exportRT, err := api.UnmarshalRTs(vrf.ExportRt)
- if err != nil {
- return nil, err
- }
- vrfs = append(vrfs, &table.Vrf{
- Name: vrf.Name,
- Id: vrf.Id,
- Rd: rd,
- ImportRt: importRT,
- ExportRt: exportRT,
- })
- }
-
- return vrfs, nil
+ return ret.Vrfs, nil
}
func (cli *Client) AddVRF(name string, id int, rd bgp.RouteDistinguisherInterface, im, ex []bgp.ExtendedCommunityInterface) error {
diff --git a/gobgp/cmd/common.go b/gobgp/cmd/common.go
index 267cc7d5..c2cfeaa7 100644
--- a/gobgp/cmd/common.go
+++ b/gobgp/cmd/common.go
@@ -29,10 +29,10 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
+ api "github.com/osrg/gobgp/api"
cli "github.com/osrg/gobgp/client"
"github.com/osrg/gobgp/config"
"github.com/osrg/gobgp/packet/bgp"
- "github.com/osrg/gobgp/table"
)
const (
@@ -142,9 +142,8 @@ func formatTimedelta(d int64) string {
if days == 0 {
return fmt.Sprintf("%02d:%02d:%02d", hours, mins, secs)
- } else {
- return fmt.Sprintf("%dd ", days) + fmt.Sprintf("%02d:%02d:%02d", hours, mins, secs)
}
+ return fmt.Sprintf("%dd ", days) + fmt.Sprintf("%02d:%02d:%02d", hours, mins, secs)
}
func cidr2prefix(cidr string) string {
@@ -245,7 +244,7 @@ func (c capabilities) Less(i, j int) bool {
return c[i].Code() < c[j].Code()
}
-type vrfs []*table.Vrf
+type vrfs []*api.Vrf
func (v vrfs) Len() int {
return len(v)
diff --git a/gobgp/cmd/vrf.go b/gobgp/cmd/vrf.go
index 32e73882..188cec44 100644
--- a/gobgp/cmd/vrf.go
+++ b/gobgp/cmd/vrf.go
@@ -22,8 +22,11 @@ import (
"strconv"
"strings"
+ "github.com/golang/protobuf/ptypes/any"
+
"github.com/spf13/cobra"
+ api "github.com/osrg/gobgp/api"
"github.com/osrg/gobgp/packet/bgp"
)
@@ -56,21 +59,35 @@ func showVrfs() error {
lines := make([][]string, 0, len(vrfs))
for _, v := range vrfs {
name := v.Name
- rd := v.Rd.String()
+ rd, err := api.UnmarshalRD(v.Rd)
+ if err != nil {
+ return err
+ }
+ rdStr := rd.String()
- f := func(rts []bgp.ExtendedCommunityInterface) (string, error) {
+ f := func(rts []*any.Any) (string, error) {
ret := make([]string, 0, len(rts))
- for _, rt := range rts {
+ for _, an := range rts {
+ rt, err := api.UnmarshalRT(an)
+ if err != nil {
+ return "", err
+ }
ret = append(ret, rt.String())
}
return strings.Join(ret, ", "), nil
}
- importRts, _ := f(v.ImportRt)
- exportRts, _ := f(v.ExportRt)
- lines = append(lines, []string{name, rd, importRts, exportRts, fmt.Sprintf("%d", v.Id)})
+ importRts, err := f(v.ImportRt)
+ if err != nil {
+ return err
+ }
+ exportRts, err := f(v.ExportRt)
+ if err != nil {
+ return err
+ }
+ lines = append(lines, []string{name, rdStr, importRts, exportRts, fmt.Sprintf("%d", v.Id)})
- for i, v := range []int{len(name), len(rd), len(importRts), len(exportRts)} {
+ for i, v := range []int{len(name), len(rdStr), len(importRts), len(exportRts)} {
if v > maxLens[i] {
maxLens[i] = v + 4
}