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