summaryrefslogtreecommitdiffhomepage
path: root/packet
diff options
context:
space:
mode:
Diffstat (limited to 'packet')
-rw-r--r--packet/bgp/bgp.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go
index a1f94c7d..49a276b1 100644
--- a/packet/bgp/bgp.go
+++ b/packet/bgp/bgp.go
@@ -151,6 +151,7 @@ const (
EC_SUBTYPE_MAC_MOBILITY ExtendedCommunityAttrSubType = 0x00 // EC_TYPE: 0x06
EC_SUBTYPE_ESI_LABEL ExtendedCommunityAttrSubType = 0x01 // EC_TYPE: 0x06
EC_SUBTYPE_ES_IMPORT ExtendedCommunityAttrSubType = 0x02 // EC_TYPE: 0x06
+ EC_SUBTYPE_ROUTER_MAC ExtendedCommunityAttrSubType = 0x03 // EC_TYPE: 0x06
EC_SUBTYPE_UUID_BASED_RT ExtendedCommunityAttrSubType = 0x11
)
@@ -6646,6 +6647,49 @@ func NewMacMobilityExtended(seq uint32, isSticky bool) *MacMobilityExtended {
}
}
+type RouterMacExtended struct {
+ Mac net.HardwareAddr
+}
+
+func (e *RouterMacExtended) Serialize() ([]byte, error) {
+ buf := make([]byte, 2, 8)
+ buf[0] = byte(EC_TYPE_EVPN)
+ buf[1] = byte(EC_SUBTYPE_ROUTER_MAC)
+ buf = append(buf, e.Mac...)
+ return buf, nil
+}
+
+func (e *RouterMacExtended) String() string {
+ return fmt.Sprintf("router's mac: %s", e.Mac.String())
+}
+
+func (e *RouterMacExtended) MarshalJSON() ([]byte, error) {
+ t, s := e.GetTypes()
+ return json.Marshal(struct {
+ Type ExtendedCommunityAttrType `json:"type"`
+ Subtype ExtendedCommunityAttrSubType `json:"subtype"`
+ Mac string `json:"mac"`
+ }{
+ Type: t,
+ Subtype: s,
+ Mac: e.Mac.String(),
+ })
+}
+
+func (e *RouterMacExtended) GetTypes() (ExtendedCommunityAttrType, ExtendedCommunityAttrSubType) {
+ return EC_TYPE_EVPN, EC_SUBTYPE_ROUTER_MAC
+}
+
+func NewRoutersMacExtended(mac string) *RouterMacExtended {
+ hw, err := net.ParseMAC(mac)
+ if err != nil {
+ return nil
+ }
+ return &RouterMacExtended{
+ Mac: hw,
+ }
+}
+
func parseEvpnExtended(data []byte) (ExtendedCommunityInterface, error) {
if ExtendedCommunityAttrType(data[0]) != EC_TYPE_EVPN {
return nil, NewMessageError(BGP_ERROR_UPDATE_MESSAGE_ERROR, BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST, nil, fmt.Sprintf("ext comm type is not EC_TYPE_EVPN: %d", data[0]))
@@ -6676,6 +6720,10 @@ func parseEvpnExtended(data []byte) (ExtendedCommunityInterface, error) {
Sequence: seq,
IsSticky: isSticky,
}, nil
+ case EC_SUBTYPE_ROUTER_MAC:
+ return &RouterMacExtended{
+ Mac: net.HardwareAddr(data[2:8]),
+ }, nil
}
return nil, NewMessageError(BGP_ERROR_UPDATE_MESSAGE_ERROR, BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST, nil, fmt.Sprintf("unknown evpn subtype: %d", subType))
}
@@ -8578,6 +8626,10 @@ func (e *MacMobilityExtended) Flat() map[string]string {
return map[string]string{}
}
+func (e *RouterMacExtended) Flat() map[string]string {
+ return map[string]string{}
+}
+
func (e *TrafficRateExtended) Flat() map[string]string {
return map[string]string{}
}