Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #include "bgp/bgp_peer_key.h" 6 : 7 : 8 : #include "base/string_util.h" 9 : #include "bgp/bgp_config.h" 10 : 11 : using boost::asio::ip::address; 12 : using boost::system::error_code; 13 : using boost::uuids::nil_generator; 14 : using std::exception; 15 : 16 123 : BgpPeerKey::BgpPeerKey() { 17 : nil_generator nil; 18 123 : uuid = nil(); 19 123 : } 20 : 21 192 : BgpPeerKey::BgpPeerKey(const BgpNeighborConfig *config) { 22 192 : error_code ec; 23 192 : endpoint.address(config->peer_address()); 24 192 : endpoint.port(config->port()); 25 : 26 192 : if (!config->uuid().empty()) { 27 : #if defined(__EXCEPTIONS) 28 : try { 29 : #endif 30 0 : uuid = StringToUuid(config->uuid()); 31 : #if defined(__EXCEPTIONS) 32 0 : } catch (exception &ex) { 33 : nil_generator nil; 34 0 : uuid = nil(); 35 0 : } 36 : #endif 37 : } else { 38 : boost::uuids::nil_generator nil; 39 192 : uuid = nil(); 40 : } 41 192 : } 42 : 43 192 : bool BgpPeerKey::operator<(const BgpPeerKey &rhs) const { 44 192 : if (endpoint != rhs.endpoint) { 45 32 : return (endpoint < rhs.endpoint); 46 : } 47 160 : return uuid < rhs.uuid; 48 : } 49 : 50 0 : bool BgpPeerKey::operator>(const BgpPeerKey &rhs) const { 51 0 : if (endpoint != rhs.endpoint) { 52 0 : return (endpoint > rhs.endpoint); 53 : } 54 0 : return uuid > rhs.uuid; 55 : } 56 : 57 80 : bool BgpPeerKey::operator==(const BgpPeerKey &rhs) const { 58 80 : return (endpoint == rhs.endpoint && uuid == rhs.uuid); 59 : } 60 : 61 32 : bool BgpPeerKey::operator!=(const BgpPeerKey &rhs) const { 62 32 : return (endpoint != rhs.endpoint || uuid != rhs.uuid); 63 : }