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