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