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