Line data Source code
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 : 14 : class EthernetSegmentId { 15 : public: 16 : static const int kSize = 10; 17 : static const EthernetSegmentId kZeroEsi; 18 : static const EthernetSegmentId kMaxEsi; 19 : 20 : enum EsiType { 21 : CONFIGURED = 0, 22 : LACP_BASED = 1, 23 : STP_BASED = 2, 24 : MAC_BASED = 3, 25 : IP_BASED = 4, 26 : AS_BASED = 5 27 : }; 28 : 29 : EthernetSegmentId(); 30 : EthernetSegmentId(const uint8_t *data); 31 3894497 : EthernetSegmentId(const EthernetSegmentId &rhs) { 32 3894497 : memcpy(data_, rhs.data_, kSize); 33 3894497 : } 34 : 35 : std::string ToString() const; 36 : static EthernetSegmentId FromString(const std::string &str, 37 : boost::system::error_code *errorp = NULL); 38 : 39 38381 : EthernetSegmentId &operator=(const EthernetSegmentId &rhs) { 40 38381 : memcpy(data_, rhs.data_, kSize); 41 38381 : return *this; 42 : } 43 : 44 8704 : bool IsZero() const { return CompareTo(EthernetSegmentId::kZeroEsi) == 0; } 45 3243 : uint8_t Type() const { return data_[0]; } 46 : 47 : int CompareTo(const EthernetSegmentId &rhs) const; 48 56 : bool operator==(const EthernetSegmentId &rhs) const { 49 56 : return CompareTo(rhs) == 0; 50 : } 51 34 : bool operator!=(const EthernetSegmentId &rhs) const { 52 34 : return CompareTo(rhs) != 0; 53 : } 54 29097524 : bool operator<(const EthernetSegmentId &rhs) const { 55 29097524 : return CompareTo(rhs) < 0; 56 : } 57 2 : bool operator>(const EthernetSegmentId &rhs) const { 58 2 : return CompareTo(rhs) > 0; 59 : } 60 : 61 37359 : const uint8_t *GetData() const { return data_; } 62 : 63 : private: 64 : uint8_t data_[kSize]; 65 : }; 66 : 67 : #endif // SRC_NET_ESI_H_