Line data Source code
1 : /* 2 : * Copyright (c) 2019 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef SRC_BGP_EXTENDED_COMMUNITY_SUB_CLUSTER_H_ 6 : #define SRC_BGP_EXTENDED_COMMUNITY_SUB_CLUSTER_H_ 7 : 8 : #include <boost/array.hpp> 9 : #include <boost/system/error_code.hpp> 10 : 11 : #include <string> 12 : 13 : #include "bgp/bgp_common.h" 14 : #include "bgp/extended-community/types.h" 15 : #include "base/parse_object.h" 16 : 17 : class SubCluster { 18 : public: 19 : static const int kSize = 8; 20 : static SubCluster null_sub_cluster; 21 : typedef boost::array<uint8_t, kSize> bytes_type; 22 : 23 : SubCluster(); 24 : explicit SubCluster(const bytes_type &data); 25 : SubCluster(as_t asn, const uint32_t id); 26 : 27 17 : bool IsNull() const { return operator==(SubCluster::null_sub_cluster); } 28 8 : uint8_t Type() const { return data_[0]; } 29 8 : uint8_t Subtype() const { return data_[1]; } 30 : 31 : bool operator<(const SubCluster &rhs) const { 32 : return data_ < rhs.data_; 33 : } 34 : bool operator>(const SubCluster &rhs) const { 35 : return data_ > rhs.data_; 36 : } 37 17 : bool operator==(const SubCluster &rhs) const { 38 17 : return data_ == rhs.data_; 39 : } 40 : bool operator!=(const SubCluster &rhs) const { 41 : return data_ != rhs.data_; 42 : } 43 : 44 3 : const bytes_type &GetExtCommunity() const { return data_; } 45 1 : const uint64_t GetExtCommunityValue() const { 46 1 : return get_value(data_.begin(), 8); 47 : } 48 : 49 : std::string ToString() const; 50 : static SubCluster FromString(const std::string &str, 51 : boost::system::error_code *error = NULL); 52 : uint32_t GetId() const; 53 : uint32_t GetAsn() const; 54 : 55 : private: 56 : bytes_type data_; 57 : }; 58 : 59 : #endif // SRC_BGP_EXTENDED_COMMUNITY_SUB_CLUSTER_H_