Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef SRC_NET_ESI_H_ 6 : #define SRC_NET_ESI_H_ 7 : 8 : #include <boost/system/error_code.hpp> 9 : #include <string> 10 : 11 : #include "base/util.h" 12 : 13 : class EthernetSegmentId { 14 : public: 15 : static const int kSize = 10; 16 : static const EthernetSegmentId kZeroEsi; 17 : static const EthernetSegmentId kMaxEsi; 18 : 19 : enum EsiType { 20 : CONFIGURED = 0, 21 : LACP_BASED = 1, 22 : STP_BASED = 2, 23 : MAC_BASED = 3, 24 : IP_BASED = 4, 25 : AS_BASED = 5 26 : }; 27 : 28 : EthernetSegmentId(); 29 : EthernetSegmentId(const uint8_t *data); 30 3871142 : EthernetSegmentId(const EthernetSegmentId &rhs) { 31 3871142 : memcpy(data_, rhs.data_, kSize); 32 3871142 : } 33 : 34 : std::string ToString() const; 35 : static EthernetSegmentId FromString(const std::string &str, 36 : boost::system::error_code *errorp = NULL); 37 : 38 38385 : EthernetSegmentId &operator=(const EthernetSegmentId &rhs) { 39 38385 : memcpy(data_, rhs.data_, kSize); 40 38385 : return *this; 41 : } 42 : 43 8419 : bool IsZero() const { return CompareTo(EthernetSegmentId::kZeroEsi) == 0; } 44 3243 : uint8_t Type() const { return data_[0]; } 45 : 46 : int CompareTo(const EthernetSegmentId &rhs) const; 47 56 : bool operator==(const EthernetSegmentId &rhs) const { 48 56 : return CompareTo(rhs) == 0; 49 : } 50 34 : bool operator!=(const EthernetSegmentId &rhs) const { 51 34 : return CompareTo(rhs) != 0; 52 : } 53 28530477 : bool operator<(const EthernetSegmentId &rhs) const { 54 28530477 : return CompareTo(rhs) < 0; 55 : } 56 2 : bool operator>(const EthernetSegmentId &rhs) const { 57 2 : return CompareTo(rhs) > 0; 58 : } 59 : 60 36720 : const uint8_t *GetData() const { return data_; } 61 : 62 : private: 63 : uint8_t data_[kSize]; 64 : }; 65 : 66 : #endif // SRC_NET_ESI_H_