Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef SRC_BGP_RTARGET_RTARGET_ADDRESS_H_ 6 : #define SRC_BGP_RTARGET_RTARGET_ADDRESS_H_ 7 : 8 : #include <boost/array.hpp> 9 : #include <boost/system/error_code.hpp> 10 : 11 : #include <set> 12 : #include <string> 13 : 14 : #include <base/address.h> 15 : 16 : class RouteTarget { 17 : public: 18 : static const int kSize = 8; 19 : static RouteTarget null_rtarget; 20 : typedef boost::array<uint8_t, kSize> bytes_type; 21 : typedef std::set<RouteTarget> List; 22 : 23 : RouteTarget(); 24 : explicit RouteTarget(const bytes_type &data); 25 : RouteTarget(const Ip4Address &address, uint16_t num); 26 : 27 : std::string ToString() const; 28 : 29 187059 : bool IsNull() const { return operator==(RouteTarget::null_rtarget); } 30 23 : uint8_t Type() { return data_[0]; } 31 23 : uint8_t Subtype() { return data_[1]; } 32 : 33 119152020 : bool operator<(const RouteTarget &rhs) const { 34 119152020 : return data_ < rhs.data_; 35 : } 36 4032659 : bool operator>(const RouteTarget &rhs) const { 37 4032659 : return data_ > rhs.data_; 38 : } 39 3557205 : bool operator==(const RouteTarget &rhs) const { 40 3557205 : return data_ == rhs.data_; 41 : } 42 : 43 : static RouteTarget FromString(const std::string &str, 44 : boost::system::error_code *error = NULL); 45 : 46 2588447 : const bytes_type &GetExtCommunity() const { 47 2588447 : return data_; 48 : } 49 : 50 : const uint64_t GetExtCommunityValue() const; 51 : 52 : private: 53 : bytes_type data_; 54 : }; 55 : 56 : #endif // SRC_BGP_RTARGET_RTARGET_ADDRESS_H_