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