diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2017-11-13 15:17:21 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-11-21 10:56:23 +0900 |
commit | 1196e65af8b1fa9fc54b45fa9ba768f0c220d557 (patch) | |
tree | bf752548092dd0c0a8b20b1a58a44c2a2c55e189 /packet/bgp | |
parent | e3cadd768d891b3915fbdeda3e9c460ae6cba313 (diff) |
packet/bgp: Support EVPN Router's MAC Extended Community
This patch supports EVPN Router's MAC Extended Community which described
on "draft-ietf-bess-evpn-inter-subnet-forwarding".
According to "draft-ietf-bess-evpn-prefix-advertisement" This extended
community might be carried with EVPN IP Prefix Route NLRI.
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'packet/bgp')
-rw-r--r-- | packet/bgp/bgp.go | 52 |
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{} } |