From d405c203ad8070298f256856605edb6d5480ba04 Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Fri, 10 Apr 2015 15:38:46 +0000 Subject: 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 --- table/table.go | 90 ---------------------------------------------------------- 1 file changed, 90 deletions(-) (limited to 'table/table.go') 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]) -} -- cgit v1.2.3