summaryrefslogtreecommitdiffhomepage
path: root/table
diff options
context:
space:
mode:
Diffstat (limited to 'table')
-rw-r--r--table/table.go90
-rw-r--r--table/table_manager.go13
2 files changed, 2 insertions, 101 deletions
diff --git a/table/table.go b/table/table.go
index d9c14144..4739b292 100644
--- a/table/table.go
+++ b/table/table.go
@@ -16,16 +16,9 @@
package table
import (
- "bytes"
- "encoding/json"
- "fmt"
log "github.com/Sirupsen/logrus"
"github.com/osrg/gobgp/packet"
- "github.com/tchap/go-patricia/patricia"
- "net"
"reflect"
- "strconv"
- "strings"
)
type Table interface {
@@ -38,7 +31,6 @@ type Table interface {
validatePath(path Path)
validateNlri(nlri bgp.AddrPrefixInterface)
DeleteDestByPeer(*PeerInfo) []Destination
- MarshalJSON() ([]byte, error)
}
type TableDefault struct {
@@ -55,39 +47,6 @@ func NewTableDefault(scope_id int) *TableDefault {
}
-func cidr2prefix(cidr string) patricia.Prefix {
- _, n, err := net.ParseCIDR(cidr)
- if err != nil {
- return patricia.Prefix(cidr)
- }
- var buffer bytes.Buffer
- for i := 0; i < len(n.IP); i++ {
- buffer.WriteString(fmt.Sprintf("%08b", n.IP[i]))
- }
- ones, _ := n.Mask.Size()
- return patricia.Prefix(buffer.String()[:ones])
-}
-
-func (td *TableDefault) MarshalJSON() ([]byte, error) {
- trie := patricia.NewTrie()
- for key, dest := range td.destinations {
- trie.Insert(cidr2prefix(key), dest)
- }
-
- destList := make([]Destination, 0)
- trie.Visit(func(prefix patricia.Prefix, item patricia.Item) error {
- dest, _ := item.(Destination)
- destList = append(destList, dest)
- return nil
- })
-
- return json.Marshal(struct {
- Destinations []Destination
- }{
- Destinations: destList,
- })
-}
-
func (td *TableDefault) GetRoutefamily() bgp.RouteFamily {
return td.ROUTE_FAMILY
}
@@ -349,42 +308,6 @@ func (ipv4vpnt *IPv4VPNTable) tableKey(nlri bgp.AddrPrefixInterface) string {
}
-func ParseLabbelledVpnPrefix(key string) patricia.Prefix {
- vpnaddrprefix := strings.Split(key, "/")
- length, _ := strconv.ParseInt(vpnaddrprefix[1], 10, 0)
- _, n, _ := net.ParseCIDR(vpnaddrprefix[0] + "/" + strconv.FormatInt((int64(length)-88), 10))
-
- var buffer bytes.Buffer
- for i := 0; i < len(n.IP); i++ {
- buffer.WriteString(fmt.Sprintf("%08b", n.IP[i]))
- }
- ones, _ := n.Mask.Size()
- return patricia.Prefix(buffer.String()[:ones])
-
-}
-
-func (ipv4vpnt *IPv4VPNTable) MarshalJSON() ([]byte, error) {
-
- trie := patricia.NewTrie()
- for key, dest := range ipv4vpnt.destinations {
- trie.Insert(ParseLabbelledVpnPrefix(key), dest)
- }
-
- destList := make([]Destination, 0)
- trie.Visit(func(prefix patricia.Prefix, item patricia.Item) error {
- dest, _ := item.(Destination)
- destList = append(destList, dest)
- return nil
- })
-
- return json.Marshal(struct {
- Destinations []Destination
- }{
- Destinations: destList,
- })
-
-}
-
type EVPNTable struct {
*TableDefault
//need structure
@@ -411,16 +334,3 @@ func (ipv4vpnt *EVPNTable) tableKey(nlri bgp.AddrPrefixInterface) string {
addrPrefix := nlri.(*bgp.EVPNNLRI)
return addrPrefix.String()
}
-
-func ParseEVPNPrefix(key string) patricia.Prefix {
- vpnaddrprefix := strings.Split(key, "/")
- length, _ := strconv.ParseInt(vpnaddrprefix[1], 10, 0)
- _, n, _ := net.ParseCIDR(vpnaddrprefix[0] + "/" + strconv.FormatInt((int64(length)-88), 10))
-
- var buffer bytes.Buffer
- for i := 0; i < len(n.IP); i++ {
- buffer.WriteString(fmt.Sprintf("%08b", n.IP[i]))
- }
- ones, _ := n.Mask.Size()
- return patricia.Prefix(buffer.String()[:ones])
-}
diff --git a/table/table_manager.go b/table/table_manager.go
index 679b684c..df89a2eb 100644
--- a/table/table_manager.go
+++ b/table/table_manager.go
@@ -18,7 +18,6 @@ package table
import (
log "github.com/Sirupsen/logrus"
"github.com/osrg/gobgp/packet"
- "github.com/tchap/go-patricia/patricia"
"reflect"
"time"
)
@@ -341,18 +340,10 @@ func (adj *AdjRib) UpdateOut(pathList []Path) {
}
func (adj *AdjRib) getPathList(rib map[string]*ReceivedRoute) []Path {
- trie := patricia.NewTrie()
+ pathList := make([]Path, 0, len(rib))
for _, rr := range rib {
- key := rr.path.GetNlri().String()
- trie.Insert(cidr2prefix(key), rr.path)
+ pathList = append(pathList, rr.path)
}
-
- pathList := []Path{}
- trie.Visit(func(prefix patricia.Prefix, item patricia.Item) error {
- path, _ := item.(Path)
- pathList = append(pathList, path)
- return nil
- })
return pathList
}