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 390 : BgpPeerKey::BgpPeerKey() { 18 : nil_generator nil; 19 390 : uuid = nil(); 20 390 : } 21 : 22 96 : BgpPeerKey::BgpPeerKey(const BgpNeighborConfig *config) { 23 96 : error_code ec; 24 96 : endpoint.address(config->peer_address()); 25 96 : endpoint.port(config->port()); 26 : 27 96 : if (!config->uuid().empty()) { 28 : #if defined(__EXCEPTIONS) 29 : try { 30 : #endif 31 96 : 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 0 : uuid = nil(); 41 : } 42 96 : } 43 : 44 107 : bool BgpPeerKey::operator<(const BgpPeerKey &rhs) const { 45 107 : if (endpoint != rhs.endpoint) { 46 43 : return (endpoint < rhs.endpoint); 47 : } 48 64 : 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 32 : bool BgpPeerKey::operator==(const BgpPeerKey &rhs) const { 59 32 : return (endpoint == rhs.endpoint && uuid == rhs.uuid); 60 : } 61 : 62 32 : bool BgpPeerKey::operator!=(const BgpPeerKey &rhs) const { 63 32 : return (endpoint != rhs.endpoint || uuid != rhs.uuid); 64 : }