Line data Source code
1 : /* 2 : * Copyright (c) 2017 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #include "bgp/large-community/tag.h" 6 : 7 : #include <stdio.h> 8 : 9 : #include <algorithm> 10 : #include <string> 11 : 12 : #include "base/parse_object.h" 13 : #include "bgp/large-community/types.h" 14 : 15 : using std::copy; 16 : using std::string; 17 : 18 115 : TagLC::TagLC(const bytes_type &data) { 19 115 : copy(data.begin(), data.end(), data_.begin()); 20 115 : } 21 : 22 81 : TagLC::TagLC(as_t asn, uint64_t tag) { 23 81 : put_value(&data_[0], 4, asn); // ASN 24 81 : data_[4] = BgpLargeCommunityType::TagLC; 25 81 : put_value(&data_[5], 7, tag); // TagLC value 26 81 : } 27 : 28 36 : as_t TagLC::as_number() const { 29 36 : if (data_[4] == BgpLargeCommunityType::TagLC) { 30 36 : as_t as_number = get_value(data_.data(), 4); 31 36 : return as_number; 32 : } 33 0 : return 0; 34 : } 35 : 36 118 : uint64_t TagLC::tag() const { 37 118 : if (data_[4] == BgpLargeCommunityType::TagLC) { 38 118 : uint64_t value = get_value(&data_[5], 7); 39 118 : return value; 40 : } 41 0 : return 0; 42 : } 43 : 44 4 : bool TagLC::IsGlobal() const { 45 4 : return (tag() >= kMinGlobalId); 46 : } 47 : 48 4 : string TagLC::ToString() const { 49 : char temp[50]; 50 4 : snprintf(temp, sizeof(temp), "tagLC:%u:%lu", as_number(), tag()); 51 4 : return string(temp); 52 : }