diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-12-25 02:00:20 -0800 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-12-25 02:00:20 -0800 |
commit | 35145891c55f7468ff9ae464d3edfe475cdda985 (patch) | |
tree | 4fd45b8e0e7958e2482fdd9128d6413cc7b0235a /table | |
parent | 037bc0169ca6e90cda1c52347c66d74198109a5c (diff) |
table: add MarshalJSON to Destination and Table
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'table')
-rw-r--r-- | table/destination.go | 14 | ||||
-rw-r--r-- | table/table.go | 16 |
2 files changed, 30 insertions, 0 deletions
diff --git a/table/destination.go b/table/destination.go index 0d16a0db..f90a53fa 100644 --- a/table/destination.go +++ b/table/destination.go @@ -17,6 +17,7 @@ package table import ( "encoding/binary" + "encoding/json" "fmt" log "github.com/Sirupsen/logrus" "github.com/osrg/gobgp/packet" @@ -65,6 +66,7 @@ type Destination interface { addNewPath(newPath Path) constructWithdrawPath() Path removeOldPathsFromSource(source *PeerInfo) []Path + MarshalJSON() ([]byte, error) } type DestinationDefault struct { @@ -91,6 +93,18 @@ func NewDestinationDefault(nlri bgp.AddrPrefixInterface) *DestinationDefault { return destination } +func (dd *DestinationDefault) MarshalJSON() ([]byte, error) { + prefix := dd.getNlri().(*bgp.NLRInfo).Prefix + paths, _ := json.Marshal(dd.knownPathList) + return json.Marshal(struct { + Prefix string + Paths string + }{ + Prefix: prefix.String(), + Paths: string(paths), + }) +} + func (dd *DestinationDefault) getRouteFamily() RouteFamily { return dd.ROUTE_FAMILY } 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 } |