OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
origin_vn.h
Go to the documentation of this file.
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;
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 
28  bool IsGlobal() const;
29 
30  as_t as_number() const;
31  int vn_index() const;
32 
33  const bytes_type &GetExtCommunity() const {
34  return data_;
35  }
36 
37  const uint64_t GetExtCommunityValue() const {
38  return get_value(data_.begin(), 8);
39  }
40 
41  bool operator<(const OriginVn &rhs) const {
42  return data_ < rhs.data_;
43  }
44  bool operator==(const OriginVn &rhs) const {
45  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:
54 };
55 
57 public:
58  static const int kSize = 8;
59  static const int kMinGlobalId = 8000000;
61  typedef boost::array<uint8_t, kSize> bytes_type;
62 
64  OriginVn4ByteAs(as_t asn, uint32_t vn_idx);
65  explicit OriginVn4ByteAs(const bytes_type &data);
66 
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:
94 };
95 
96 #endif // SRC_BGP_ORIGIN_VN_ORIGIN_VN_H_
bool IsNull()
Definition: origin_vn.h:27
as_t as_number() const
Definition: origin_vn.cc:110
bool operator<(const OriginVn &rhs) const
Definition: origin_vn.h:41
static const int kMinGlobalId
Definition: origin_vn.h:59
static OriginVn null_originvn
Definition: origin_vn.h:20
const uint64_t GetExtCommunityValue() const
Definition: origin_vn.h:77
bytes_type data_
Definition: origin_vn.h:93
const bytes_type & GetExtCommunity() const
Definition: origin_vn.h:73
static const int kSize
Definition: origin_vn.h:58
bool operator<(const OriginVn4ByteAs &rhs) const
Definition: origin_vn.h:81
static const int kSize
Definition: origin_vn.h:18
bool operator==(const OriginVn4ByteAs &rhs) const
Definition: origin_vn.h:84
bytes_type data_
Definition: origin_vn.h:53
static OriginVn4ByteAs null_originvn
Definition: origin_vn.h:60
uint32_t as_t
Definition: bgp_common.h:21
static uint64_t get_value(const uint8_t *data, int size)
Definition: parse_object.h:39
std::string ToString()
OriginVn()
Definition: origin_vn.cc:18
static OriginVn4ByteAs FromString(const std::string &str, boost::system::error_code *error=NULL)
boost::array< uint8_t, kSize > bytes_type
Definition: origin_vn.h:21
bool IsGlobal() const
Definition: origin_vn.cc:134
as_t as_number() const
int vn_index() const
Definition: origin_vn.cc:122
static const int kMinGlobalId
Definition: origin_vn.h:19
static OriginVn FromString(const std::string &str, boost::system::error_code *error=NULL)
Definition: origin_vn.cc:39
bool IsGlobal() const
boost::array< uint8_t, kSize > bytes_type
Definition: origin_vn.h:61
const bytes_type & GetExtCommunity() const
Definition: origin_vn.h:33
std::string ToString()
Definition: origin_vn.cc:138
bool operator==(const OriginVn &rhs) const
Definition: origin_vn.h:44
const uint64_t GetExtCommunityValue() const
Definition: origin_vn.h:37
int vn_index() const
bool IsNull()
Definition: origin_vn.h:67