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