From cd0d357a553bafa977a86e5fcc78c9f2a301db1a Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Fri, 3 Apr 2015 07:44:32 +0000 Subject: table: support displaying evpn destination through cli evpn nlri key is not expressed in CIDR format. in that case give up sorting. we can think later how to sort evpn nlri after we decided the way to express evpn nlri key(current evpn nlri key is insufficient to keep evpn nlris unique in evpn table). this patch also add a MarshalJSON method to EVPNDestination for displaying evpn routes through cli Signed-off-by: ISHIDA Wataru --- table/destination.go | 25 +++++++++++++++++++++++++ table/table.go | 5 ++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/table/destination.go b/table/destination.go index a79daa2b..23c5c00f 100644 --- a/table/destination.go +++ b/table/destination.go @@ -1005,3 +1005,28 @@ func NewEVPNDestination(nlri bgp.AddrPrefixInterface) *EVPNDestination { //need Processing return EVPNDestination } + +func (evpnd *EVPNDestination) MarshalJSON() ([]byte, error) { + nlri := evpnd.getNlri().(*bgp.EVPNNLRI) + idx := func() int { + for i, p := range evpnd.DestinationDefault.knownPathList { + if p == evpnd.DestinationDefault.getBestPath() { + return i + } + } + log.WithFields(log.Fields{ + "Topic": "Table", + "Key": nlri.String(), + }).Panic("no best path") + return 0 + }() + return json.Marshal(struct { + Prefix string + Paths []Path + BestPathIdx int + }{ + Prefix: nlri.String(), + Paths: evpnd.knownPathList, + BestPathIdx: idx, + }) +} diff --git a/table/table.go b/table/table.go index 656f132c..28799a24 100644 --- a/table/table.go +++ b/table/table.go @@ -56,7 +56,10 @@ func NewTableDefault(scope_id int) *TableDefault { } func cidr2prefix(cidr string) patricia.Prefix { - _, n, _ := net.ParseCIDR(cidr) + _, 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])) -- cgit v1.2.3