summaryrefslogtreecommitdiffhomepage
path: root/table/table.go
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-12-25 02:00:20 -0800
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-12-25 02:00:20 -0800
commit35145891c55f7468ff9ae464d3edfe475cdda985 (patch)
tree4fd45b8e0e7958e2482fdd9128d6413cc7b0235a /table/table.go
parent037bc0169ca6e90cda1c52347c66d74198109a5c (diff)
table: add MarshalJSON to Destination and Table
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'table/table.go')
-rw-r--r--table/table.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/table/table.go b/table/table.go
index 1215d51d..df55947b 100644
--- a/table/table.go
+++ b/table/table.go
@@ -16,6 +16,7 @@
package table
import (
+ "encoding/json"
log "github.com/Sirupsen/logrus"
"github.com/osrg/gobgp/packet"
"net"
@@ -32,6 +33,7 @@ type Table interface {
validatePath(path Path)
validateNlri(nlri bgp.AddrPrefixInterface)
DeleteDestByPeer(*PeerInfo) []Destination
+ MarshalJSON() ([]byte, error)
}
type TableDefault struct {
@@ -48,6 +50,20 @@ func NewTableDefault(scope_id int) *TableDefault {
}
+func (td *TableDefault) MarshalJSON() ([]byte, error) {
+ destList := make([]Destination, 0)
+ for _, dest := range td.destinations {
+ destList = append(destList, dest)
+ }
+ j, _ := json.Marshal(destList)
+
+ return json.Marshal(struct {
+ Destinations string
+ }{
+ Destinations: string(j),
+ })
+}
+
func (td *TableDefault) getRoutefamily() RouteFamily {
return td.ROUTE_FAMILY
}