summaryrefslogtreecommitdiffhomepage
path: root/table/table.go
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-04-10 15:38:46 +0000
committerISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-04-15 05:31:40 +0000
commitd405c203ad8070298f256856605edb6d5480ba04 (patch)
treedccd1bf4ba74abf95d9606dcafb8f3422979e708 /table/table.go
parenta6efaf6ed6baf26050090b400310196464bab06f (diff)
table: sort peers/routes at client side instead of bgpd side
peer/route sorting is for pretty priting. do it at the client side. Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'table/table.go')
-rw-r--r--table/table.go90
1 files changed, 0 insertions, 90 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])
-}