Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef SRC_BGP_EXTENDED_COMMUNITY_SITE_OF_ORIGIN_H_ 6 : #define SRC_BGP_EXTENDED_COMMUNITY_SITE_OF_ORIGIN_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 SiteOfOrigin { 17 : public: 18 : static const int kSize = 8; 19 : static SiteOfOrigin null_soo; 20 : typedef boost::array<uint8_t, kSize> bytes_type; 21 : 22 : SiteOfOrigin(); 23 : explicit SiteOfOrigin(const bytes_type &data); 24 : 25 39850 : bool IsNull() const { return operator==(SiteOfOrigin::null_soo); } 26 24 : uint8_t Type() const { return data_[0]; } 27 24 : uint8_t Subtype() const { return data_[1]; } 28 : 29 : bool operator<(const SiteOfOrigin &rhs) const { 30 : return data_ < rhs.data_; 31 : } 32 : bool operator>(const SiteOfOrigin &rhs) const { 33 : return data_ > rhs.data_; 34 : } 35 39850 : bool operator==(const SiteOfOrigin &rhs) const { 36 39850 : return data_ == rhs.data_; 37 : } 38 192 : bool operator!=(const SiteOfOrigin &rhs) const { 39 192 : return data_ != rhs.data_; 40 : } 41 : 42 204 : const bytes_type &GetExtCommunity() const { return data_; } 43 48 : const uint64_t GetExtCommunityValue() const { 44 48 : return get_value(data_.begin(), 8); 45 : } 46 : 47 : std::string ToString() const; 48 : static SiteOfOrigin FromString(const std::string &str, 49 : boost::system::error_code *error = NULL); 50 : 51 : private: 52 : bytes_type data_; 53 : }; 54 : 55 : #endif // SRC_BGP_EXTENDED_COMMUNITY_SITE_OF_ORIGIN_H_