OpenSDN source code
source_as.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #ifndef SRC_BGP_EXTENDED_COMMUNITY_SOURCE_AS_H_
7 #define SRC_BGP_EXTENDED_COMMUNITY_SOURCE_AS_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"
16 
17 class SourceAs {
18 public:
19  static const int kSize = 8;
21  typedef boost::array<uint8_t, kSize> bytes_type;
22 
23  SourceAs();
24  explicit SourceAs(const bytes_type &data);
25  SourceAs(const uint32_t asn, const uint32_t ri_index);
26 
27  uint32_t GetAsn() const;
28  bool IsNull() const { return operator==(SourceAs::null_sas); }
29  uint8_t Type() const { return data_[0]; }
30  uint8_t Subtype() const { return data_[1]; }
31 
32  bool operator<(const SourceAs &rhs) const {
33  return data_ < rhs.data_;
34  }
35  bool operator>(const SourceAs &rhs) const {
36  return data_ > rhs.data_;
37  }
38  bool operator==(const SourceAs &rhs) const {
39  return data_ == rhs.data_;
40  }
41  bool operator!=(const SourceAs &rhs) const {
42  return data_ != rhs.data_;
43  }
44 
45  const bytes_type &GetExtCommunity() const { return data_; }
46  const uint64_t GetExtCommunityValue() const {
47  return get_value(data_.begin(), 8);
48  }
49 
50  std::string ToString() const;
51  static SourceAs FromString(const std::string &str,
52  boost::system::error_code *error = NULL);
53 
54 private:
56 };
57 
58 #endif // SRC_BGP_EXTENDED_COMMUNITY_SOURCE_AS_H_
SourceAs()
Definition: source_as.cc:18
bool operator>(const SourceAs &rhs) const
Definition: source_as.h:35
bool operator<(const SourceAs &rhs) const
Definition: source_as.h:32
bytes_type data_
Definition: source_as.h:55
uint8_t Type() const
Definition: source_as.h:29
std::string ToString() const
Definition: source_as.cc:51
uint8_t Subtype() const
Definition: source_as.h:30
const uint64_t GetExtCommunityValue() const
Definition: source_as.h:46
static SourceAs FromString(const std::string &str, boost::system::error_code *error=NULL)
Definition: source_as.cc:69
bool operator==(const SourceAs &rhs) const
Definition: source_as.h:38
bool IsNull() const
Definition: source_as.h:28
static SourceAs null_sas
Definition: source_as.h:20
bool operator!=(const SourceAs &rhs) const
Definition: source_as.h:41
static const int kSize
Definition: source_as.h:19
boost::array< uint8_t, kSize > bytes_type
Definition: source_as.h:21
const bytes_type & GetExtCommunity() const
Definition: source_as.h:45
uint32_t GetAsn() const
Definition: source_as.cc:26
static uint64_t get_value(const uint8_t *data, int size)
Definition: parse_object.h:40