Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef SRC_BGP_ORIGIN_VN_ORIGIN_VN_H_ 6 : #define SRC_BGP_ORIGIN_VN_ORIGIN_VN_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/bgp_common.h" 15 : 16 : class OriginVn { 17 : public: 18 : static const int kSize = 8; 19 : static const int kMinGlobalId = 8000000; 20 : static OriginVn null_originvn; 21 : typedef boost::array<uint8_t, kSize> bytes_type; 22 : 23 : OriginVn(); 24 : OriginVn(as_t asn, uint32_t vn_idx); 25 : explicit OriginVn(const bytes_type &data); 26 : 27 19 : bool IsNull() { return operator==(OriginVn::null_originvn); } 28 : bool IsGlobal() const; 29 : 30 : as_t as_number() const; 31 : int vn_index() const; 32 : 33 204817 : const bytes_type &GetExtCommunity() const { 34 204817 : return data_; 35 : } 36 : 37 6390 : const uint64_t GetExtCommunityValue() const { 38 6390 : return get_value(data_.begin(), 8); 39 : } 40 : 41 : bool operator<(const OriginVn &rhs) const { 42 : return data_ < rhs.data_; 43 : } 44 19 : bool operator==(const OriginVn &rhs) const { 45 19 : return data_ == rhs.data_; 46 : } 47 : 48 : std::string ToString(); 49 : static OriginVn FromString(const std::string &str, 50 : boost::system::error_code *error = NULL); 51 : 52 : private: 53 : bytes_type data_; 54 : }; 55 : 56 : class OriginVn4ByteAs { 57 : public: 58 : static const int kSize = 8; 59 : static const int kMinGlobalId = 8000000; 60 : static OriginVn4ByteAs null_originvn; 61 : typedef boost::array<uint8_t, kSize> bytes_type; 62 : 63 : OriginVn4ByteAs(); 64 : OriginVn4ByteAs(as_t asn, uint32_t vn_idx); 65 : explicit OriginVn4ByteAs(const bytes_type &data); 66 : 67 : bool IsNull() { return operator==(OriginVn4ByteAs::null_originvn); } 68 : bool IsGlobal() const; 69 : 70 : as_t as_number() const; 71 : int vn_index() const; 72 : 73 : const bytes_type &GetExtCommunity() const { 74 : return data_; 75 : } 76 : 77 : const uint64_t GetExtCommunityValue() const { 78 : return get_value(data_.begin(), 8); 79 : } 80 : 81 : bool operator<(const OriginVn4ByteAs &rhs) const { 82 : return data_ < rhs.data_; 83 : } 84 : bool operator==(const OriginVn4ByteAs &rhs) const { 85 : return data_ == rhs.data_; 86 : } 87 : 88 : std::string ToString(); 89 : static OriginVn4ByteAs FromString(const std::string &str, 90 : boost::system::error_code *error = NULL); 91 : 92 : private: 93 : bytes_type data_; 94 : }; 95 : 96 : #endif // SRC_BGP_ORIGIN_VN_ORIGIN_VN_H_