From 3d89b9245a6ccaa160de2e10c3ec57f966d62e2c Mon Sep 17 00:00:00 2001 From: Antoine Eiche Date: Wed, 8 Jun 2016 14:00:41 +0000 Subject: 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. --- packet/bgp/bgp.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'packet/bgp/bgp.go') 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{} +} -- cgit v1.2.3