Line data Source code
1 : /* 2 : * Copyright (c) 2017 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef SRC_BGP_EXTENDED_COMMUNITY_VRF_ROUTE_IMPORT_H_ 6 : #define SRC_BGP_EXTENDED_COMMUNITY_VRF_ROUTE_IMPORT_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 : #include "base/address.h" 16 : 17 : class VrfRouteImport { 18 : public: 19 : static const int kSize = 8; 20 : static VrfRouteImport null_rt_import; 21 : typedef boost::array<uint8_t, kSize> bytes_type; 22 : 23 : VrfRouteImport(); 24 : explicit VrfRouteImport(const bytes_type &data); 25 : VrfRouteImport(const uint32_t bgp_id, const uint32_t ri_index); 26 : 27 11 : bool IsNull() const { return operator==(VrfRouteImport::null_rt_import); } 28 8 : uint8_t Type() const { return data_[0]; } 29 8 : uint8_t Subtype() const { return data_[1]; } 30 : Ip4Address GetIPv4Address() const; 31 : uint16_t GetNumber() const; 32 : 33 : bool operator<(const VrfRouteImport &rhs) const { 34 : return data_ < rhs.data_; 35 : } 36 : bool operator>(const VrfRouteImport &rhs) const { 37 : return data_ > rhs.data_; 38 : } 39 11 : bool operator==(const VrfRouteImport &rhs) const { 40 11 : return data_ == rhs.data_; 41 : } 42 : bool operator!=(const VrfRouteImport &rhs) const { 43 : return data_ != rhs.data_; 44 : } 45 : 46 194 : const bytes_type &GetExtCommunity() const { return data_; } 47 : const uint64_t GetExtCommunityValue() const { 48 : return get_value(data_.begin(), 8); 49 : } 50 : 51 : std::string ToString() const; 52 : static VrfRouteImport FromString(const std::string &str, 53 : boost::system::error_code *error = NULL); 54 : 55 : private: 56 : bytes_type data_; 57 : }; 58 : 59 : #endif // SRC_BGP_EXTENDED_COMMUNITY_VRF_ROUTE_IMPORT_H_