diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-07-08 00:00:47 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-07-08 21:32:32 +0900 |
commit | 07f47b7d370e4a2197cf34e3847b2f867b97a40a (patch) | |
tree | ae89ab07ea53d9bc34c443efcb5a980d7f3ac625 /cmd | |
parent | 26aed14b48dc8afce6a3d2faa20f5a8ce95494b6 (diff) |
remove package dependency except for grpc in api/
Nothing except for protobuf IDL files and files generated by protobuf in api/.
Try to make the APIs portable to any languages.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/gobgp/cmd/global.go | 3 | ||||
-rw-r--r-- | cmd/gobgp/cmd/global_test.go | 3 | ||||
-rw-r--r-- | cmd/gobgp/cmd/monitor.go | 7 | ||||
-rw-r--r-- | cmd/gobgp/cmd/mrt.go | 3 | ||||
-rw-r--r-- | cmd/gobgp/cmd/neighbor.go | 13 | ||||
-rw-r--r-- | cmd/gobgp/cmd/vrf.go | 6 | ||||
-rw-r--r-- | cmd/gobgp/lib/path.go | 5 | ||||
-rw-r--r-- | cmd/gobgpd/main.go | 5 |
8 files changed, 26 insertions, 19 deletions
diff --git a/cmd/gobgp/cmd/global.go b/cmd/gobgp/cmd/global.go index 4559f4ac..b71deba9 100644 --- a/cmd/gobgp/cmd/global.go +++ b/cmd/gobgp/cmd/global.go @@ -28,6 +28,7 @@ import ( "github.com/spf13/cobra" api "github.com/osrg/gobgp/api" + "github.com/osrg/gobgp/internal/pkg/apiutil" "github.com/osrg/gobgp/internal/pkg/config" "github.com/osrg/gobgp/internal/pkg/table" @@ -1265,7 +1266,7 @@ func ParsePath(rf bgp.RouteFamily, args []string) (*api.Path, error) { } sort.Slice(attrs, func(i, j int) bool { return attrs[i].GetType() < attrs[j].GetType() }) - return api.NewPath(nlri, false, attrs, time.Now()), nil + return apiutil.NewPath(nlri, false, attrs, time.Now()), nil } func showGlobalRib(args []string) error { diff --git a/cmd/gobgp/cmd/global_test.go b/cmd/gobgp/cmd/global_test.go index 7aecb904..c00db1df 100644 --- a/cmd/gobgp/cmd/global_test.go +++ b/cmd/gobgp/cmd/global_test.go @@ -19,6 +19,7 @@ import ( "strings" "testing" + "github.com/osrg/gobgp/internal/pkg/apiutil" "github.com/osrg/gobgp/pkg/packet/bgp" "github.com/stretchr/testify/assert" ) @@ -30,7 +31,7 @@ func Test_ParsePath(t *testing.T) { path, err := ParsePath(bgp.RF_IPv4_UC, strings.Split(buf, " ")) assert.Nil(err) i := 0 - attrs, _ := path.GetNativePathAttributes() + attrs, _ := apiutil.GetNativePathAttributes(path) for _, a := range attrs { assert.True(i < int(a.GetType())) i = int(a.GetType()) diff --git a/cmd/gobgp/cmd/monitor.go b/cmd/gobgp/cmd/monitor.go index 6b07eb2d..9055ecf5 100644 --- a/cmd/gobgp/cmd/monitor.go +++ b/cmd/gobgp/cmd/monitor.go @@ -24,6 +24,7 @@ import ( "github.com/spf13/cobra" api "github.com/osrg/gobgp/api" + "github.com/osrg/gobgp/internal/pkg/apiutil" "github.com/osrg/gobgp/pkg/packet/bgp" ) @@ -39,13 +40,13 @@ func makeMonitorRouteArgs(p *api.Path, showIdentifier bgp.BGPAddPathMode) []inte // NLRI // If Add-Path required, append Path Identifier. - nlri, _ := p.GetNativeNlri() + nlri, _ := apiutil.GetNativeNlri(p) if showIdentifier != bgp.BGP_ADD_PATH_NONE { pathStr = append(pathStr, p.GetIdentifier()) } pathStr = append(pathStr, nlri) - attrs, _ := p.GetNativePathAttributes() + attrs, _ := apiutil.GetNativePathAttributes(p) // Next Hop nexthop := "fictitious" if n := getNextHopFromPathAttributes(attrs); n != nil { @@ -102,7 +103,7 @@ func NewMonitorCmd() *cobra.Command { exitWithError(err) } if globalOpts.Json { - j, _ := json.Marshal(dst.Paths) + j, _ := json.Marshal(apiutil.NewDestination(dst)) fmt.Println(string(j)) } else { monitorRoute(dst.Paths, showIdentifier) diff --git a/cmd/gobgp/cmd/mrt.go b/cmd/gobgp/cmd/mrt.go index 32c4fc9b..58b4381d 100644 --- a/cmd/gobgp/cmd/mrt.go +++ b/cmd/gobgp/cmd/mrt.go @@ -25,6 +25,7 @@ import ( "github.com/spf13/cobra" api "github.com/osrg/gobgp/api" + "github.com/osrg/gobgp/internal/pkg/apiutil" "github.com/osrg/gobgp/pkg/packet/bgp" "github.com/osrg/gobgp/pkg/packet/mrt" ) @@ -143,7 +144,7 @@ func injectMrt() error { } } - path := api.NewPath(nlri, false, attrs, time.Unix(int64(e.OriginatedTime), 0)) + path := apiutil.NewPath(nlri, false, attrs, time.Unix(int64(e.OriginatedTime), 0)) path.SourceAsn = peers[e.PeerIndex].AS path.SourceId = peers[e.PeerIndex].BgpId.String() diff --git a/cmd/gobgp/cmd/neighbor.go b/cmd/gobgp/cmd/neighbor.go index c6dd8be6..ad946e5b 100644 --- a/cmd/gobgp/cmd/neighbor.go +++ b/cmd/gobgp/cmd/neighbor.go @@ -28,6 +28,7 @@ import ( "github.com/spf13/cobra" api "github.com/osrg/gobgp/api" + "github.com/osrg/gobgp/internal/pkg/apiutil" "github.com/osrg/gobgp/internal/pkg/config" "github.com/osrg/gobgp/pkg/packet/bgp" ) @@ -478,7 +479,7 @@ func getPathAttributeString(nlri bgp.AddrPrefixInterface, attrs []bgp.PathAttrib } func makeShowRouteArgs(p *api.Path, idx int, now time.Time, showAge, showBest, showLabel bool, showIdentifier bgp.BGPAddPathMode) []interface{} { - nlri, _ := p.GetNativeNlri() + nlri, _ := apiutil.GetNativeNlri(p) // Path Symbols (e.g. "*>") args := []interface{}{getPathSymbolString(p, idx, showBest)} @@ -501,7 +502,7 @@ func makeShowRouteArgs(p *api.Path, idx int, now time.Time, showAge, showBest, s args = append(args, label) } - attrs, _ := p.GetNativePathAttributes() + attrs, _ := apiutil.GetNativePathAttributes(p) // Next Hop nexthop := "fictitious" if n := getNextHopFromPathAttributes(attrs); n != nil { @@ -591,14 +592,14 @@ func checkOriginAsWasNotShown(p *api.Path, asPath []bgp.AsPathParamInterface, sh func showValidationInfo(p *api.Path, shownAs map[uint32]struct{}) error { var asPath []bgp.AsPathParamInterface - attrs, _ := p.GetNativePathAttributes() + attrs, _ := apiutil.GetNativePathAttributes(p) for _, attr := range attrs { if attr.GetType() == bgp.BGP_ATTR_TYPE_AS_PATH { asPath = attr.(*bgp.PathAttributeAsPath).Value } } - nlri, _ := p.GetNativeNlri() + nlri, _ := apiutil.GetNativeNlri(p) if len(asPath) == 0 { return fmt.Errorf("The path to %s was locally generated.\n", nlri.String()) } else if !checkOriginAsWasNotShown(p, asPath, shownAs) { @@ -802,9 +803,9 @@ func showNeighborRib(r string, name string, args []string) error { } if globalOpts.Json { - d := make(map[string]*api.Destination) + d := make(map[string]*apiutil.Destination) for _, dst := range rib.GetDestinations() { - d[dst.Prefix] = dst + d[dst.Prefix] = apiutil.NewDestination(dst) } j, _ := json.Marshal(d) fmt.Println(string(j)) diff --git a/cmd/gobgp/cmd/vrf.go b/cmd/gobgp/cmd/vrf.go index fd55dc0a..a8c2fcd8 100644 --- a/cmd/gobgp/cmd/vrf.go +++ b/cmd/gobgp/cmd/vrf.go @@ -22,7 +22,7 @@ import ( "strconv" "strings" - api "github.com/osrg/gobgp/api" + "github.com/osrg/gobgp/internal/pkg/apiutil" "github.com/osrg/gobgp/pkg/packet/bgp" "github.com/golang/protobuf/ptypes/any" @@ -58,7 +58,7 @@ func showVrfs() error { lines := make([][]string, 0, len(vrfs)) for _, v := range vrfs { name := v.Name - rd, err := api.UnmarshalRD(v.Rd) + rd, err := apiutil.UnmarshalRD(v.Rd) if err != nil { return err } @@ -67,7 +67,7 @@ func showVrfs() error { f := func(rts []*any.Any) (string, error) { ret := make([]string, 0, len(rts)) for _, an := range rts { - rt, err := api.UnmarshalRT(an) + rt, err := apiutil.UnmarshalRT(an) if err != nil { return "", err } diff --git a/cmd/gobgp/lib/path.go b/cmd/gobgp/lib/path.go index 130f5444..8554b061 100644 --- a/cmd/gobgp/lib/path.go +++ b/cmd/gobgp/lib/path.go @@ -37,6 +37,7 @@ import ( "strings" "github.com/osrg/gobgp/cmd/gobgp/cmd" + "github.com/osrg/gobgp/internal/pkg/apiutil" "github.com/osrg/gobgp/pkg/packet/bgp" ) @@ -57,14 +58,14 @@ func serialize_path(rf C.int, input *C.char) *C.path { return nil } path := C.new_path() - if nlri, err := p.GetNativeNlri(); err != nil { + if nlri, err := apiutil.GetNativeNlri(p); err != nil { return nil } else { buf, _ := nlri.Serialize() path.nlri.len = C.int(len(buf)) path.nlri.value = C.CString(string(buf)) } - attrs, err := p.GetNativePathAttributes() + attrs, err := apiutil.GetNativePathAttributes(p) if err != nil { return nil } diff --git a/cmd/gobgpd/main.go b/cmd/gobgpd/main.go index 6f1a364d..31af0f67 100644 --- a/cmd/gobgpd/main.go +++ b/cmd/gobgpd/main.go @@ -35,6 +35,7 @@ import ( "google.golang.org/grpc/credentials" api "github.com/osrg/gobgp/api" + "github.com/osrg/gobgp/internal/pkg/apiutil" "github.com/osrg/gobgp/internal/pkg/config" "github.com/osrg/gobgp/internal/pkg/table" "github.com/osrg/gobgp/pkg/packet/bgp" @@ -50,7 +51,7 @@ func marshalRouteTargets(l []string) ([]*any.Any, error) { if err != nil { return nil, err } - rtList = append(rtList, api.MarshalRT(rt)) + rtList = append(rtList, apiutil.MarshalRT(rt)) } return rtList, nil } @@ -252,7 +253,7 @@ func main() { if _, err := apiServer.AddVrf(context.Background(), &api.AddVrfRequest{ Vrf: &api.Vrf{ Name: vrf.Config.Name, - Rd: api.MarshalRD(rd), + Rd: apiutil.MarshalRD(rd), Id: uint32(vrf.Config.Id), ImportRt: importRtList, ExportRt: exportRtList, |