diff options
-rw-r--r-- | packet/bgp.go | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/packet/bgp.go b/packet/bgp.go index bc5940bc..9aa29cbd 100644 --- a/packet/bgp.go +++ b/packet/bgp.go @@ -1249,10 +1249,24 @@ func (esi *EthernetSegmentIdentifier) Serialize() ([]byte, error) { return buf, nil } +func isZeroBuf(buf []byte) bool { + for _, b := range buf { + if b != 0 { + return false + } + } + return true +} + func (esi *EthernetSegmentIdentifier) String() string { s := bytes.NewBuffer(make([]byte, 0, 64)) s.WriteString(fmt.Sprintf("%s | ", esi.Type)) switch esi.Type { + case ESI_ARBITRARY: + if isZeroBuf(esi.Value) { + return "single-homed" + } + s.WriteString(fmt.Sprintf("%s", esi.Value)) case ESI_LACP: s.WriteString(fmt.Sprintf("system mac %s, ", net.HardwareAddr(esi.Value[:6]).String())) s.WriteString(fmt.Sprintf("port key %d", binary.BigEndian.Uint16(esi.Value[6:8]))) @@ -1343,6 +1357,10 @@ func (er *EVPNEthernetAutoDiscoveryRoute) Serialize() ([]byte, error) { return buf, nil } +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) +} + type EVPNMacIPAdvertisementRoute struct { RD RouteDistinguisherInterface ESI EthernetSegmentIdentifier @@ -1423,6 +1441,10 @@ func (er *EVPNMacIPAdvertisementRoute) Serialize() ([]byte, error) { return buf, nil } +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) +} + type EVPNMulticastEthernetTagRoute struct { RD RouteDistinguisherInterface ETag uint32 @@ -1467,6 +1489,10 @@ func (er *EVPNMulticastEthernetTagRoute) Serialize() ([]byte, error) { return buf, nil } +func (er *EVPNMulticastEthernetTagRoute) String() string { + return fmt.Sprintf("[type:multicast][rd:%s][etag:%d][ip:%s]", er.RD, er.ETag, er.IPAddress) +} + type EVPNEthernetSegmentRoute struct { RD RouteDistinguisherInterface ESI EthernetSegmentIdentifier @@ -1514,6 +1540,11 @@ func (er *EVPNEthernetSegmentRoute) Serialize() ([]byte, error) { type EVPNRouteTypeInterface interface { DecodeFromBytes([]byte) error Serialize() ([]byte, error) + String() string +} + +func (er *EVPNEthernetSegmentRoute) String() string { + return fmt.Sprintf("[type:esi][rd:%s][esi:%d][ip:%s]", er.RD, er.ESI, er.IPAddress) } func getEVPNRouteType(t uint8) (EVPNRouteTypeInterface, error) { @@ -1587,32 +1618,8 @@ func (n *EVPNNLRI) Len() int { } func (n *EVPNNLRI) String() string { - - switch n.RouteType { - - case EVPN_ROUTE_TYPE_ETHERNET_AUTO_DISCOVERY: - return fmt.Sprintf("%d:%d", n.RouteType, n.Length) - - case EVPN_ROUTE_TYPE_MAC_IP_ADVERTISEMENT: - m := n.RouteTypeData.(*EVPNMacIPAdvertisementRoute) - var ss []string - switch m.RD.(type) { - case *RouteDistinguisherIPAddressAS: - ss = append(ss, fmt.Sprintf("%s", m.IPAddress.String())) - } - ss = append(ss, m.MacAddress.String()) - return strings.Join(ss, ".") - - case EVPN_INCLUSIVE_MULTICAST_ETHERNET_TAG: - m := n.RouteTypeData.(*EVPNMulticastEthernetTagRoute) - switch m.RD.(type) { - case *RouteDistinguisherIPAddressAS: - return fmt.Sprintf("%s", m.IPAddress.String()) - } - - case EVPN_ETHERNET_SEGMENT_ROUTE: - return fmt.Sprintf("%d:%d", n.RouteType, n.Length) - + if n.RouteTypeData != nil { + return n.RouteTypeData.String() } return fmt.Sprintf("%d:%d", n.RouteType, n.Length) } |