Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #include "bgp/extended-community/esi_label.h" 6 : 7 : #include <stdio.h> 8 : 9 : #include <algorithm> 10 : #include <string> 11 : 12 : #include "base/parse_object.h" 13 : 14 : using std::copy; 15 : using std::fill; 16 : using std::string; 17 : 18 64 : EsiLabel::EsiLabel(const bytes_type &data) { 19 64 : copy(data.begin(), data.end(), data_.begin()); 20 64 : } 21 : 22 48 : EsiLabel::EsiLabel(bool single_active) { 23 48 : fill(data_.begin(), data_.end(), 0); 24 48 : data_[0] = BgpExtendedCommunityType::Evpn; 25 48 : data_[1] = BgpExtendedCommunityEvpnSubType::EsiMplsLabel; 26 48 : if (single_active) { 27 8 : data_[2] |= 0x01; 28 : } 29 48 : } 30 : 31 6 : string EsiLabel::flags() const { 32 6 : return (data_[2] & 0x01) ? string("sa") : string("aa"); 33 : } 34 : 35 6 : int EsiLabel::label() const { 36 12 : if (data_[0] == BgpExtendedCommunityType::Evpn && 37 6 : data_[1] == BgpExtendedCommunityEvpnSubType::EsiMplsLabel) { 38 6 : int value = get_value(&data_[5], 3); 39 6 : return value >> 4; 40 : } 41 0 : return 0; 42 : } 43 : 44 6 : string EsiLabel::ToString() const { 45 : char temp[50]; 46 6 : snprintf(temp, sizeof(temp), "esilabel:%s:%d", flags().c_str(), label()); 47 6 : return string(temp); 48 : }