summaryrefslogtreecommitdiffhomepage
path: root/cmd
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-11-06 20:58:19 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-11-06 20:58:19 +0900
commite82327118a96629d2bcd95acc3b65282828604e9 (patch)
tree2a12b6af92544a094262e1176fd2873ab4e5ddc4 /cmd
parenta88d5611d2dd6dfb49aff0b77b7725d4b62b9937 (diff)
gobgp: delete c-shared-lib
Now the gRPC API doesn't require the binary wire-format for path attributes. No need for the library for C. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/gobgp/lib/lib.go78
-rw-r--r--cmd/gobgp/lib/path.go144
2 files changed, 0 insertions, 222 deletions
diff --git a/cmd/gobgp/lib/lib.go b/cmd/gobgp/lib/lib.go
deleted file mode 100644
index ee71a859..00000000
--- a/cmd/gobgp/lib/lib.go
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright (C) 2015 Nippon Telegraph and Telephone Corporation.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-// implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package main
-
-// #include <stdio.h>
-// #include <stdlib.h>
-// #include <string.h>
-// typedef struct {
-// char *value;
-// int len;
-// } buf;
-//
-// typedef struct path_t {
-// buf nlri;
-// buf** path_attributes;
-// int path_attributes_len;
-// int path_attributes_cap;
-// } path;
-//
-// path* new_path() {
-// path* p;
-// int cap = 32;
-// p = (path*)malloc(sizeof(path));
-// memset(p, 0, sizeof(path));
-// p->nlri.len = 0;
-// p->path_attributes_len = 0;
-// p->path_attributes_cap = cap;
-// p->path_attributes = (buf**)malloc(sizeof(buf)*cap);
-// return p;
-// }
-//
-// void free_path(path* p) {
-// int i;
-// if (p->nlri.value != NULL) {
-// free(p->nlri.value);
-// }
-// for (i = 0; i < p->path_attributes_len; i++) {
-// buf* b;
-// b = p->path_attributes[i];
-// free(b->value);
-// free(b);
-// }
-// free(p->path_attributes);
-// free(p);
-// }
-//
-// int append_path_attribute(path* p, int len, char* value) {
-// buf* b;
-// if (p->path_attributes_len >= p->path_attributes_cap) {
-// return -1;
-// }
-// b = (buf*)malloc(sizeof(buf));
-// b->value = value;
-// b->len = len;
-// p->path_attributes[p->path_attributes_len] = b;
-// p->path_attributes_len++;
-// return 0;
-// }
-// buf* get_path_attribute(path* p, int idx) {
-// if (idx < 0 || idx >= p->path_attributes_len) {
-// return NULL;
-// }
-// return p->path_attributes[idx];
-// }
-import "C"
diff --git a/cmd/gobgp/lib/path.go b/cmd/gobgp/lib/path.go
deleted file mode 100644
index 8554b061..00000000
--- a/cmd/gobgp/lib/path.go
+++ /dev/null
@@ -1,144 +0,0 @@
-// Copyright (C) 2015 Nippon Telegraph and Telephone Corporation.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-// implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package main
-
-// typedef struct {
-// char *value;
-// int len;
-// } buf;
-//
-// typedef struct path_t {
-// buf nlri;
-// buf** path_attributes;
-// int path_attributes_len;
-// int path_attributes_cap;
-// } path;
-// extern path* new_path();
-// extern void free_path(path*);
-// extern int append_path_attribute(path*, int, char*);
-// extern buf* get_path_attribute(path*, int);
-import "C"
-
-import (
- "encoding/json"
- "strings"
-
- "github.com/osrg/gobgp/cmd/gobgp/cmd"
- "github.com/osrg/gobgp/internal/pkg/apiutil"
- "github.com/osrg/gobgp/pkg/packet/bgp"
-)
-
-//export get_route_family
-func get_route_family(input *C.char) C.int {
- rf, err := bgp.GetRouteFamily(C.GoString(input))
- if err != nil {
- return C.int(-1)
- }
- return C.int(rf)
-}
-
-//export serialize_path
-func serialize_path(rf C.int, input *C.char) *C.path {
- args := strings.Split(C.GoString(input), " ")
- p, err := cmd.ParsePath(bgp.RouteFamily(rf), args)
- if err != nil {
- return nil
- }
- path := C.new_path()
- 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 := apiutil.GetNativePathAttributes(p)
- if err != nil {
- return nil
- }
- for _, attr := range attrs {
- buf, err := attr.Serialize()
- if err != nil {
- return nil
- }
- C.append_path_attribute(path, C.int(len(buf)), C.CString(string(buf)))
- }
- return path
-}
-
-//export decode_path
-func decode_path(p *C.path) *C.char {
- var buf []byte
- var nlri bgp.AddrPrefixInterface
- if p.nlri.len > 0 {
- buf = []byte(C.GoStringN(p.nlri.value, p.nlri.len))
- nlri = &bgp.IPAddrPrefix{}
- err := nlri.DecodeFromBytes(buf)
- if err != nil {
- return nil
- }
- }
- pattrs := make([]bgp.PathAttributeInterface, 0, int(p.path_attributes_len))
- for i := 0; i < int(p.path_attributes_len); i++ {
- b := C.get_path_attribute(p, C.int(i))
- buf = []byte(C.GoStringN(b.value, b.len))
- pattr, err := bgp.GetPathAttribute(buf)
- if err != nil {
- return nil
- }
-
- err = pattr.DecodeFromBytes(buf)
- if err != nil {
- return nil
- }
-
- switch pattr.GetType() {
- case bgp.BGP_ATTR_TYPE_MP_REACH_NLRI:
- mpreach := pattr.(*bgp.PathAttributeMpReachNLRI)
- if len(mpreach.Value) != 1 {
- return nil
- }
- nlri = mpreach.Value[0]
- }
-
- pattrs = append(pattrs, pattr)
- }
- j, _ := json.Marshal(struct {
- Nlri bgp.AddrPrefixInterface `json:"nlri"`
- PathAttrs []bgp.PathAttributeInterface `json:"attrs"`
- }{
- Nlri: nlri,
- PathAttrs: pattrs,
- })
- return C.CString(string(j))
-}
-
-//export decode_capabilities
-func decode_capabilities(p *C.buf) *C.char {
- buf := []byte(C.GoStringN(p.value, p.len))
- c, err := bgp.DecodeCapability(buf)
- if err != nil {
- return nil
- }
- j, _ := json.Marshal(c)
- return C.CString(string(j))
-
-}
-
-func main() {
- // We need the main function to make possible
- // CGO compiler to compile the package as C shared library
-}