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 17354 : BgpPeerKey::BgpPeerKey() { 17 : nil_generator nil; 18 17350 : uuid = nil(); 19 17350 : } 20 : 21 30772 : BgpPeerKey::BgpPeerKey(const BgpNeighborConfig *config) { 22 30772 : error_code ec; 23 30772 : endpoint.address(config->peer_address()); 24 30772 : endpoint.port(config->port()); 25 : 26 30772 : if (!config->uuid().empty()) { 27 : #if defined(__EXCEPTIONS) 28 : try { 29 : #endif 30 29410 : 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 1362 : uuid = nil(); 40 : } 41 30772 : } 42 : 43 53512 : bool BgpPeerKey::operator<(const BgpPeerKey &rhs) const { 44 53512 : if (endpoint != rhs.endpoint) { 45 3773 : return (endpoint < rhs.endpoint); 46 : } 47 49739 : 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 17043 : bool BgpPeerKey::operator==(const BgpPeerKey &rhs) const { 58 17043 : return (endpoint == rhs.endpoint && uuid == rhs.uuid); 59 : } 60 : 61 10072 : bool BgpPeerKey::operator!=(const BgpPeerKey &rhs) const { 62 10072 : return (endpoint != rhs.endpoint || uuid != rhs.uuid); 63 : }