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 18402 : BgpPeerKey::BgpPeerKey() { 17 : nil_generator nil; 18 18397 : uuid = nil(); 19 18398 : } 20 : 21 30791 : BgpPeerKey::BgpPeerKey(const BgpNeighborConfig *config) { 22 30791 : error_code ec; 23 30791 : endpoint.address(config->peer_address()); 24 30791 : endpoint.port(config->port()); 25 : 26 30791 : if (!config->uuid().empty()) { 27 : #if defined(__EXCEPTIONS) 28 : try { 29 : #endif 30 29428 : 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 1363 : uuid = nil(); 40 : } 41 30791 : } 42 : 43 53668 : bool BgpPeerKey::operator<(const BgpPeerKey &rhs) const { 44 53668 : if (endpoint != rhs.endpoint) { 45 3863 : return (endpoint < rhs.endpoint); 46 : } 47 49805 : 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 17144 : bool BgpPeerKey::operator==(const BgpPeerKey &rhs) const { 58 17144 : return (endpoint == rhs.endpoint && uuid == rhs.uuid); 59 : } 60 : 61 10085 : bool BgpPeerKey::operator!=(const BgpPeerKey &rhs) const { 62 10085 : return (endpoint != rhs.endpoint || uuid != rhs.uuid); 63 : }