diff options
Diffstat (limited to 'table/path.go')
-rw-r--r-- | table/path.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/table/path.go b/table/path.go index c75ca579..0aab6004 100644 --- a/table/path.go +++ b/table/path.go @@ -17,6 +17,7 @@ package table import ( "bytes" + "encoding/json" "fmt" "math" "net" @@ -845,6 +846,30 @@ func (lhs *Path) Equal(rhs *Path) bool { return bytes.Equal(pattrs(lhs.GetPathAttrs()), pattrs(rhs.GetPathAttrs())) } +func (path *Path) MarshalJSON() ([]byte, error) { + return json.Marshal(struct { + Nlri bgp.AddrPrefixInterface `json:"nlri"` + PathAttrs []bgp.PathAttributeInterface `json:"attrs"` + Age int64 `json:"age"` + Withdrawal bool `json:"withdrawal,omitempty"` + Validation string `json:"validation,omitempty"` + SourceID net.IP `json:"source-id,omitempty"` + NeighborIP net.IP `json:"neighbor-ip,omitempty"` + Stale bool `json:"stale,omitempty"` + Filtered bool `json:"filtered,omitempty"` + }{ + Nlri: path.GetNlri(), + PathAttrs: path.GetPathAttrs(), + Age: path.GetTimestamp().Unix(), + Withdrawal: path.IsWithdraw, + Validation: string(path.Validation()), + SourceID: path.GetSource().ID, + NeighborIP: path.GetSource().Address, + Stale: path.IsStale(), + Filtered: path.Filtered("") > POLICY_DIRECTION_NONE, + }) +} + func (lhs *Path) Compare(rhs *Path) int { if lhs.IsLocal() && !rhs.IsLocal() { return 1 |