diff options
author | Antoine Eiche <antoine.eiche@cloudwatt.com> | 2016-06-08 14:00:41 +0000 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-06-09 13:13:06 +0900 |
commit | 3d89b9245a6ccaa160de2e10c3ec57f966d62e2c (patch) | |
tree | d0a5e7bfe002a0e2d87da757d6d870c37cd153a2 /packet/bgp/bgp.go | |
parent | d218ff032a590a7bbb493b97996e9d02fd5c2d57 (diff) |
bgp: add Flat method on AddrPrefixInterface
This method returns a map[string]string which can be used to create
structured outputs, specialized by implemented types.
Diffstat (limited to 'packet/bgp/bgp.go')
-rw-r--r-- | packet/bgp/bgp.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go index f89f547e..c01859fe 100644 --- a/packet/bgp/bgp.go +++ b/packet/bgp/bgp.go @@ -726,6 +726,10 @@ type AddrPrefixInterface interface { Len() int String() string MarshalJSON() ([]byte, error) + + // Create a flat map to describe attributes and their + // values. This can be used to create structured outputs. + Flat() map[string]string } type IPAddrPrefixDefault struct { @@ -7075,3 +7079,45 @@ func NewMessageError(typeCode, subTypeCode uint8, data []byte, msg string) error func (e *MessageError) Error() string { return e.Message } + +func (l *LabeledVPNIPAddrPrefix) Flat() map[string]string { + return map[string]string{ + "Prefix": l.IPAddrPrefixDefault.Prefix.String(), + "PrefixLen": string(l.IPAddrPrefixDefault.Length - uint8(8*(l.Labels.Len()+l.RD.Len())))} +} + +func (p *IPAddrPrefixDefault) Flat() map[string]string { + l := strings.Split(p.String(), "/") + if len(l) == 2 { + return map[string]string{ + "Prefix": l[0], + "PrefixLen": l[1], + } + } + return map[string]string{} +} + +func (l *EVPNNLRI) Flat() map[string]string { + return map[string]string{} +} +func (l *RouteTargetMembershipNLRI) Flat() map[string]string { + return map[string]string{} +} +func (l *FlowSpecIPv4Unicast) Flat() map[string]string { + return map[string]string{} +} +func (l *FlowSpecIPv4VPN) Flat() map[string]string { + return map[string]string{} +} +func (l *FlowSpecIPv6Unicast) Flat() map[string]string { + return map[string]string{} +} +func (l *FlowSpecIPv6VPN) Flat() map[string]string { + return map[string]string{} +} +func (l *FlowSpecL2VPN) Flat() map[string]string { + return map[string]string{} +} +func (l *OpaqueNLRI) Flat() map[string]string { + return map[string]string{} +} |