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 : #include "bgp/bgp_peer_key.h" 7 : 8 : 9 : #include "base/string_util.h" 10 : #include "bgp/bgp_config.h" 11 : 12 : using boost::asio::ip::address; 13 : using boost::system::error_code; 14 : using boost::uuids::nil_generator; 15 : using std::exception; 16 : 17 17843 : BgpPeerKey::BgpPeerKey() { 18 : nil_generator nil; 19 17833 : uuid = nil(); 20 17832 : } 21 : 22 30750 : BgpPeerKey::BgpPeerKey(const BgpNeighborConfig *config) { 23 30750 : error_code ec; 24 30750 : endpoint.address(config->peer_address()); 25 30750 : endpoint.port(config->port()); 26 : 27 30750 : if (!config->uuid().empty()) { 28 : #if defined(__EXCEPTIONS) 29 : try { 30 : #endif 31 29388 : uuid = StringToUuid(config->uuid()); 32 : #if defined(__EXCEPTIONS) 33 0 : } catch (exception &ex) { 34 : nil_generator nil; 35 0 : uuid = nil(); 36 0 : } 37 : #endif 38 : } else { 39 : boost::uuids::nil_generator nil; 40 1362 : uuid = nil(); 41 : } 42 30750 : } 43 : 44 53433 : bool BgpPeerKey::operator<(const BgpPeerKey &rhs) const { 45 53433 : if (endpoint != rhs.endpoint) { 46 3787 : return (endpoint < rhs.endpoint); 47 : } 48 49646 : return uuid < rhs.uuid; 49 : } 50 : 51 0 : bool BgpPeerKey::operator>(const BgpPeerKey &rhs) const { 52 0 : if (endpoint != rhs.endpoint) { 53 0 : return (endpoint > rhs.endpoint); 54 : } 55 0 : return uuid > rhs.uuid; 56 : } 57 : 58 16979 : bool BgpPeerKey::operator==(const BgpPeerKey &rhs) const { 59 16979 : return (endpoint == rhs.endpoint && uuid == rhs.uuid); 60 : } 61 : 62 10060 : bool BgpPeerKey::operator!=(const BgpPeerKey &rhs) const { 63 10060 : return (endpoint != rhs.endpoint || uuid != rhs.uuid); 64 : }