diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-12-25 23:58:15 -0800 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-12-25 23:58:15 -0800 |
commit | bfc0cd8da13bcc221e19717d37d9b7e5414e16c3 (patch) | |
tree | 6b5f37aba954a34133df5067b14bc6b02ad571bf /packet/bgp.go | |
parent | cf87cd2b465ca740a8c216131a44b5bda870a8d5 (diff) |
packet: improve PathAttributeCommunities JSON output
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'packet/bgp.go')
-rw-r--r-- | packet/bgp.go | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/packet/bgp.go b/packet/bgp.go index 6369269e..9928ecce 100644 --- a/packet/bgp.go +++ b/packet/bgp.go @@ -1567,12 +1567,36 @@ func (p *PathAttributeCommunities) Serialize() ([]byte, error) { } func (p *PathAttributeCommunities) MarshalJSON() ([]byte, error) { + wellKnown := map[uint32]string{ + 0xffff0000: "planned-shut", + 0xffff0001: "accept-own", + 0xffff0002: "ROUTE_FILTER_TRANSLATED_v4", + 0xffff0003: "ROUTE_FILTER_v4", + 0xffff0004: "ROUTE_FILTER_TRANSLATED_v6", + 0xffff0005: "ROUTE_FILTER_v6", + 0xffff0006: "LLGR_STALE", + 0xffff0007: "NO_LLGR", + 0xFFFFFF01: "NO_EXPORT", + 0xFFFFFF02: "NO_ADVERTISE", + 0xFFFFFF03: "NO_EXPORT_SUBCONFED", + 0xFFFFFF04: "NOPEER"} + + l := make([]string, len(p.Value)) + for i, v := range p.Value { + s, found := wellKnown[v] + if found { + l[i] = s + } else { + l[i] = fmt.Sprintf("%x:%x", (v&0xffff0000)>>16, v&0xffff) + } + } + return json.Marshal(struct { Type string - Value []uint32 + Value []string }{ Type: p.Type.String(), - Value: p.Value, + Value: l, }) } |