OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sub_cluster.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef SRC_BGP_EXTENDED_COMMUNITY_SUB_CLUSTER_H_
6 #define SRC_BGP_EXTENDED_COMMUNITY_SUB_CLUSTER_H_
7 
8 #include <boost/array.hpp>
9 #include <boost/system/error_code.hpp>
10 
11 #include <string>
12 
13 #include "bgp/bgp_common.h"
15 #include "base/parse_object.h"
16 
17 class SubCluster {
18 public:
19  static const int kSize = 8;
21  typedef boost::array<uint8_t, kSize> bytes_type;
22 
23  SubCluster();
24  explicit SubCluster(const bytes_type &data);
25  SubCluster(as_t asn, const uint32_t id);
26 
28  uint8_t Type() const { return data_[0]; }
29  uint8_t Subtype() const { return data_[1]; }
30 
31  bool operator<(const SubCluster &rhs) const {
32  return data_ < rhs.data_;
33  }
34  bool operator>(const SubCluster &rhs) const {
35  return data_ > rhs.data_;
36  }
37  bool operator==(const SubCluster &rhs) const {
38  return data_ == rhs.data_;
39  }
40  bool operator!=(const SubCluster &rhs) const {
41  return data_ != rhs.data_;
42  }
43 
44  const bytes_type &GetExtCommunity() const { return data_; }
45  const uint64_t GetExtCommunityValue() const {
46  return get_value(data_.begin(), 8);
47  }
48 
49  std::string ToString() const;
50  static SubCluster FromString(const std::string &str,
51  boost::system::error_code *error = NULL);
52  uint32_t GetId() const;
53  uint32_t GetAsn() const;
54 
55 private:
57 };
58 
59 #endif // SRC_BGP_EXTENDED_COMMUNITY_SUB_CLUSTER_H_
static SubCluster null_sub_cluster
Definition: sub_cluster.h:20
const uint64_t GetExtCommunityValue() const
Definition: sub_cluster.h:45
uint8_t Subtype() const
Definition: sub_cluster.h:29
bool operator>(const SubCluster &rhs) const
Definition: sub_cluster.h:34
static const int kSize
Definition: sub_cluster.h:19
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
uint32_t GetId() const
Definition: sub_cluster.cc:37
bool operator!=(const SubCluster &rhs) const
Definition: sub_cluster.h:40
boost::array< uint8_t, kSize > bytes_type
Definition: sub_cluster.h:21
uint32_t GetAsn() const
Definition: sub_cluster.cc:48
static SubCluster FromString(const std::string &str, boost::system::error_code *error=NULL)
Definition: sub_cluster.cc:80
bool operator==(const SubCluster &rhs) const
Definition: sub_cluster.h:37
bool operator<(const SubCluster &rhs) const
Definition: sub_cluster.h:31
const bytes_type & GetExtCommunity() const
Definition: sub_cluster.h:44
uint8_t Type() const
Definition: sub_cluster.h:28
std::string ToString() const
Definition: sub_cluster.cc:59
bool IsNull() const
Definition: sub_cluster.h:27
bytes_type data_
Definition: sub_cluster.h:56