Line data Source code
1 : /* 2 : * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #include "bgp/extended-community/router_mac.h" 6 : 7 : #include <algorithm> 8 : #include <string> 9 : 10 : using std::copy; 11 : using std::string; 12 : 13 13 : RouterMac::RouterMac(const MacAddress &mac_addr) { 14 13 : data_[0] = BgpExtendedCommunityType::Evpn; 15 13 : data_[1] = BgpExtendedCommunityEvpnSubType::RouterMac; 16 13 : copy(mac_addr.GetData(), mac_addr.GetData() + 6, data_.begin() + 2); 17 13 : } 18 : 19 26 : RouterMac::RouterMac(const bytes_type &data) { 20 26 : copy(data.begin(), data.end(), data_.begin()); 21 26 : } 22 : 23 28 : MacAddress RouterMac::mac_address() const { 24 : uint8_t data[RouterMac::kSize]; 25 28 : copy(data_.begin(), data_.end(), &data[0]); 26 28 : if (data[0] == BgpExtendedCommunityType::Evpn && 27 28 : data[1] == BgpExtendedCommunityEvpnSubType::RouterMac) { 28 28 : return MacAddress(&data[2]); 29 : } 30 0 : return MacAddress::kZeroMac; 31 : } 32 : 33 4 : string RouterMac::ToString() { 34 8 : return string("rtrmac:") + mac_address().ToString(); 35 : }