diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-09-22 23:01:59 +0900 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-09-22 23:01:59 +0900 |
commit | 19ca5ae906d509c516e0038866a88e09ca269568 (patch) | |
tree | 56ce18dada5013fabe9ce91b355d00e2ecc8dcf1 /packet/bgp.go | |
parent | e986668fc8de9b2e140601cbddc89a0c110cc269 (diff) |
packet: add missing MarshalJSON() to VPN nlris
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'packet/bgp.go')
-rw-r--r-- | packet/bgp.go | 123 |
1 files changed, 121 insertions, 2 deletions
diff --git a/packet/bgp.go b/packet/bgp.go index 5cc6d33e..60c1b645 100644 --- a/packet/bgp.go +++ b/packet/bgp.go @@ -814,6 +814,7 @@ type RouteDistinguisherInterface interface { Serialize() ([]byte, error) Len() int String() string + MarshalJSON() ([]byte, error) } type DefaultRouteDistinguisher struct { @@ -838,6 +839,16 @@ func (rd *DefaultRouteDistinguisher) String() string { return fmt.Sprintf("%v", rd.Value) } +func (rd *DefaultRouteDistinguisher) MarshalJSON() ([]byte, error) { + return json.Marshal(struct { + Type uint16 `json:"type"` + Value []byte `json:"value"` + }{ + Type: rd.Type, + Value: rd.Value, + }) +} + func (rd *DefaultRouteDistinguisher) Len() int { return 8 } type RouteDistinguisherTwoOctetAS struct { @@ -858,6 +869,18 @@ func (rd *RouteDistinguisherTwoOctetAS) String() string { return fmt.Sprintf("%d:%d", rd.Admin, rd.Assigned) } +func (rd *RouteDistinguisherTwoOctetAS) MarshalJSON() ([]byte, error) { + return json.Marshal(struct { + Type uint16 `json:"type"` + Admin uint16 `json:"admin"` + Assigned uint32 `json:"assigned"` + }{ + Type: rd.Type, + Admin: rd.Admin, + Assigned: rd.Assigned, + }) +} + func NewRouteDistinguisherTwoOctetAS(admin uint16, assigned uint32) *RouteDistinguisherTwoOctetAS { return &RouteDistinguisherTwoOctetAS{ DefaultRouteDistinguisher: DefaultRouteDistinguisher{ @@ -886,6 +909,18 @@ func (rd *RouteDistinguisherIPAddressAS) String() string { return fmt.Sprintf("%s:%d", rd.Admin.String(), rd.Assigned) } +func (rd *RouteDistinguisherIPAddressAS) MarshalJSON() ([]byte, error) { + return json.Marshal(struct { + Type uint16 `json:"type"` + Admin string `json:"admin"` + Assigned uint16 `json:"assigned"` + }{ + Type: rd.Type, + Admin: rd.Admin.String(), + Assigned: rd.Assigned, + }) +} + func NewRouteDistinguisherIPAddressAS(admin string, assigned uint16) *RouteDistinguisherIPAddressAS { return &RouteDistinguisherIPAddressAS{ DefaultRouteDistinguisher: DefaultRouteDistinguisher{ @@ -916,6 +951,18 @@ func (rd *RouteDistinguisherFourOctetAS) String() string { return fmt.Sprintf("%d.%d:%d", fst, snd, rd.Assigned) } +func (rd *RouteDistinguisherFourOctetAS) MarshalJSON() ([]byte, error) { + return json.Marshal(struct { + Type uint16 `json:"type"` + Admin uint32 `json:"admin"` + Assigned uint16 `json:"assigned"` + }{ + Type: rd.Type, + Admin: rd.Admin, + Assigned: rd.Assigned, + }) +} + func NewRouteDistinguisherFourOctetAS(admin uint32, assigned uint16) *RouteDistinguisherFourOctetAS { return &RouteDistinguisherFourOctetAS{ DefaultRouteDistinguisher: DefaultRouteDistinguisher{ @@ -1139,6 +1186,19 @@ func (l *LabeledVPNIPAddrPrefix) String() string { return fmt.Sprintf("%s:%s/%d", l.RD, l.IPAddrPrefixDefault.Prefix, masklen) } +func (l *LabeledVPNIPAddrPrefix) MarshalJSON() ([]byte, error) { + masklen := l.IPAddrPrefixDefault.Length - uint8(8*(l.Labels.Len()+l.RD.Len())) + return json.Marshal(struct { + Prefix string `json:"prefix"` + Labels []uint32 `json:"labels"` + RD RouteDistinguisherInterface `json:"rd"` + }{ + Prefix: fmt.Sprintf("%s/%d", l.IPAddrPrefixDefault.Prefix, masklen), + Labels: l.Labels.Labels, + RD: l.RD, + }) +} + func NewLabeledVPNIPAddrPrefix(length uint8, prefix string, label MPLSLabelStack, rd RouteDistinguisherInterface) *LabeledVPNIPAddrPrefix { rdlen := 0 if rd != nil { @@ -1474,6 +1534,20 @@ func (er *EVPNEthernetAutoDiscoveryRoute) String() string { return fmt.Sprintf("[type:A-D][rd:%s][esi:%s][etag:%d][label:%d]", er.RD, er.ESI, er.ETag, er.Label) } +func (er *EVPNEthernetAutoDiscoveryRoute) MarshalJSON() ([]byte, error) { + return json.Marshal(struct { + RD RouteDistinguisherInterface `json:"rd"` + ESI string `json:"esi"` + Etag uint32 `json:"etag"` + Label uint32 `json:"label"` + }{ + RD: er.RD, + ESI: er.ESI.String(), + Etag: er.ETag, + Label: er.Label, + }) +} + func (er *EVPNEthernetAutoDiscoveryRoute) rd() RouteDistinguisherInterface { return er.RD } @@ -1570,6 +1644,24 @@ func (er *EVPNMacIPAdvertisementRoute) String() string { return fmt.Sprintf("[type:macadv][rd:%s][esi:%s][etag:%d][mac:%s][ip:%s][labels:%v]", er.RD, er.ESI.String(), er.ETag, er.MacAddress, er.IPAddress, er.Labels) } +func (er *EVPNMacIPAdvertisementRoute) MarshalJSON() ([]byte, error) { + return json.Marshal(struct { + RD RouteDistinguisherInterface `json:"rd"` + ESI string `json:"esi"` + Etag uint32 `json:"etag"` + MacAddress string `json:"mac"` + IPAddress string `json:"ip"` + Labels []uint32 `json:"labels"` + }{ + RD: er.RD, + ESI: er.ESI.String(), + Etag: er.ETag, + MacAddress: er.MacAddress.String(), + IPAddress: er.IPAddress.String(), + Labels: er.Labels, + }) +} + func (er *EVPNMacIPAdvertisementRoute) rd() RouteDistinguisherInterface { return er.RD } @@ -1628,6 +1720,18 @@ func (er *EVPNMulticastEthernetTagRoute) String() string { return fmt.Sprintf("[type:multicast][rd:%s][etag:%d][ip:%s]", er.RD, er.ETag, er.IPAddress) } +func (er *EVPNMulticastEthernetTagRoute) MarshalJSON() ([]byte, error) { + return json.Marshal(struct { + RD RouteDistinguisherInterface `json:"rd"` + Etag uint32 `json:"etag"` + IPAddress string `json:"ip"` + }{ + RD: er.RD, + Etag: er.ETag, + IPAddress: er.IPAddress.String(), + }) +} + func (er *EVPNMulticastEthernetTagRoute) rd() RouteDistinguisherInterface { return er.RD } @@ -1687,12 +1791,25 @@ type EVPNRouteTypeInterface interface { Serialize() ([]byte, error) String() string rd() RouteDistinguisherInterface + MarshalJSON() ([]byte, error) } func (er *EVPNEthernetSegmentRoute) String() string { return fmt.Sprintf("[type:esi][rd:%s][esi:%d][ip:%s]", er.RD, er.ESI, er.IPAddress) } +func (er *EVPNEthernetSegmentRoute) MarshalJSON() ([]byte, error) { + return json.Marshal(struct { + RD RouteDistinguisherInterface `json:"rd"` + ESI string `json:"esi"` + IPAddress string `json:"ip"` + }{ + RD: er.RD, + ESI: er.ESI.String(), + IPAddress: er.IPAddress.String(), + }) +} + func (er *EVPNEthernetSegmentRoute) rd() RouteDistinguisherInterface { return er.RD } @@ -1776,9 +1893,11 @@ func (n *EVPNNLRI) String() string { func (n *EVPNNLRI) MarshalJSON() ([]byte, error) { return json.Marshal(struct { - Prefix string `json:"prefix"` + Type uint8 `json:"type"` + Value EVPNRouteTypeInterface `json:"value"` }{ - Prefix: n.String(), + Type: n.RouteType, + Value: n.RouteTypeData, }) } |