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