OpenSDN source code
esi.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_NET_ESI_H_
7 #define SRC_NET_ESI_H_
8 
9 #include <boost/system/error_code.hpp>
10 #include <string>
11 
12 #include "base/util.h"
13 
15 public:
16  static const int kSize = 10;
18  static const EthernetSegmentId kMaxEsi;
19 
20  enum EsiType {
23  STP_BASED = 2,
24  MAC_BASED = 3,
25  IP_BASED = 4,
26  AS_BASED = 5
27  };
28 
30  EthernetSegmentId(const uint8_t *data);
32  memcpy(data_, rhs.data_, kSize);
33  }
34 
35  std::string ToString() const;
36  static EthernetSegmentId FromString(const std::string &str,
37  boost::system::error_code *errorp = NULL);
38 
40  memcpy(data_, rhs.data_, kSize);
41  return *this;
42  }
43 
44  bool IsZero() const { return CompareTo(EthernetSegmentId::kZeroEsi) == 0; }
45  uint8_t Type() const { return data_[0]; }
46 
47  int CompareTo(const EthernetSegmentId &rhs) const;
48  bool operator==(const EthernetSegmentId &rhs) const {
49  return CompareTo(rhs) == 0;
50  }
51  bool operator!=(const EthernetSegmentId &rhs) const {
52  return CompareTo(rhs) != 0;
53  }
54  bool operator<(const EthernetSegmentId &rhs) const {
55  return CompareTo(rhs) < 0;
56  }
57  bool operator>(const EthernetSegmentId &rhs) const {
58  return CompareTo(rhs) > 0;
59  }
60 
61  const uint8_t *GetData() const { return data_; }
62 
63 private:
64  uint8_t data_[kSize];
65 };
66 
67 #endif // SRC_NET_ESI_H_
std::string ToString() const
Definition: esi.cc:121
static const int kSize
Definition: esi.h:16
bool operator<(const EthernetSegmentId &rhs) const
Definition: esi.h:54
uint8_t data_[kSize]
Definition: esi.h:64
bool IsZero() const
Definition: esi.h:44
bool operator!=(const EthernetSegmentId &rhs) const
Definition: esi.h:51
EthernetSegmentId()
Definition: esi.cc:22
int CompareTo(const EthernetSegmentId &rhs) const
Definition: esi.cc:157
bool operator==(const EthernetSegmentId &rhs) const
Definition: esi.h:48
EthernetSegmentId & operator=(const EthernetSegmentId &rhs)
Definition: esi.h:39
bool operator>(const EthernetSegmentId &rhs) const
Definition: esi.h:57
const uint8_t * GetData() const
Definition: esi.h:61
EthernetSegmentId(const EthernetSegmentId &rhs)
Definition: esi.h:31
static const EthernetSegmentId kZeroEsi
Definition: esi.h:17
static EthernetSegmentId FromString(const std::string &str, boost::system::error_code *errorp=NULL)
Definition: esi.cc:30
static const EthernetSegmentId kMaxEsi
Definition: esi.h:18
uint8_t Type() const
Definition: esi.h:45