Line data Source code
1 : /* 2 : * Copyright (c) 2017 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef SRC_BGP_LARGE_COMMUNITY_TAG_H_ 6 : #define SRC_BGP_LARGE_COMMUNITY_TAG_H_ 7 : 8 : #include <boost/array.hpp> 9 : #include <stdint.h> 10 : #include <string> 11 : 12 : #include "base/parse_object.h" 13 : #include "bgp/bgp_common.h" 14 : 15 : /// @brief Represents a single BGP Large Community tag. 16 : class TagLC { 17 : public: 18 : /// Fixed size (in bytes) of a BGP Large Community value. 19 : static const int kSize = 12; 20 : /// Minimum tag id to belong to a global community. 21 : static const int kMinGlobalId = 8000000; 22 : /// Raw 12-byte type representing the community on the wire. 23 : typedef boost::array<uint8_t, kSize> bytes_type; 24 : 25 : /// Construct from a raw 12-byte value. 26 : explicit TagLC(const bytes_type &data); 27 : /// Construct from AS number and tag value. 28 : explicit TagLC(as_t asn, uint64_t tag); 29 : /// Returns a string representation. 30 : std::string ToString() const; 31 : 32 : /// Returns true if this tag belongs to a global community. 33 : bool IsGlobal() const; 34 : /// Returns the AS number. 35 : as_t as_number() const; 36 : /// Returns the tag id. 37 : uint64_t tag() const; 38 : 39 : /// Returns the community value as a vector of 3 32-bit integers. 40 80 : const std::vector<uint32_t> GetLargeCommunityValue() const { 41 80 : std::vector<uint32_t> lc_val; 42 320 : for (int i =0; i < 3; i++) { 43 240 : uint32_t value = get_value(data_.begin() + 4*i, 4); 44 240 : lc_val.push_back(value); 45 : } 46 80 : return lc_val; 47 0 : } 48 : 49 : private: 50 : /// Raw 12-byte encoded Large Community value. 51 : bytes_type data_; 52 : }; 53 : 54 : #endif // SRC_BGP_LARGE_COMMUNITY_TAG_H_