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