2004-09-08 22:03:05 +04:00
|
|
|
/*
|
2004-11-22 04:38:40 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University.
|
|
|
|
* All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
|
|
|
|
* All rights reserved.
|
2004-11-28 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-09-08 22:03:05 +04:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
2004-10-20 05:03:09 +04:00
|
|
|
#include "ompi_config.h"
|
2005-05-05 20:31:40 +04:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <fcntl.h>
|
|
|
|
#ifdef HAVE_SYS_UIO_H
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
#include "include/ompi_socket_errno.h"
|
|
|
|
#ifdef HAVE_NETINET_IN_H
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ARPA_INET_H
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_NETINET_TCP_H
|
|
|
|
#include <netinet/tcp.h>
|
|
|
|
#endif
|
2005-03-14 23:57:21 +03:00
|
|
|
#include "mca/ns/ns_types.h"
|
2004-09-08 22:03:05 +04:00
|
|
|
#include "mca/oob/tcp/oob_tcp.h"
|
|
|
|
|
2005-05-05 20:31:40 +04:00
|
|
|
|
2004-09-08 22:03:05 +04:00
|
|
|
/*
|
|
|
|
* Ping a peer to see if it is alive.
|
|
|
|
*
|
|
|
|
* @param peer (IN) Opaque name of peer process.
|
|
|
|
* @param tv (IN) Timeout to wait for a response.
|
|
|
|
* @return OMPI error code (<0) on error number of bytes actually sent.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int mca_oob_tcp_ping(
|
2005-05-05 20:31:40 +04:00
|
|
|
const orte_process_name_t* name,
|
|
|
|
const char* uri,
|
2004-09-08 22:03:05 +04:00
|
|
|
const struct timeval *timeout)
|
|
|
|
{
|
2005-05-05 20:31:40 +04:00
|
|
|
int sd, flags, rc;
|
|
|
|
struct sockaddr_in inaddr;
|
|
|
|
fd_set fdset;
|
|
|
|
mca_oob_tcp_hdr_t hdr;
|
2004-09-08 22:03:05 +04:00
|
|
|
struct timeval tv;
|
|
|
|
|
2005-05-05 20:31:40 +04:00
|
|
|
/* parse uri string */
|
|
|
|
if(OMPI_SUCCESS != (rc = mca_oob_tcp_parse_uri(uri, &inaddr))) {
|
2005-07-04 03:31:27 +04:00
|
|
|
opal_output(0,
|
2005-05-08 17:22:55 +04:00
|
|
|
"[%lu,%lu,%lu]-[%lu,%lu,%lu] mca_oob_tcp_ping: invalid uri: %s\n",
|
2005-03-14 23:57:21 +03:00
|
|
|
ORTE_NAME_ARGS(orte_process_info.my_name),
|
2005-05-05 20:31:40 +04:00
|
|
|
ORTE_NAME_ARGS(name),
|
|
|
|
uri);
|
|
|
|
return rc;
|
2004-09-08 22:03:05 +04:00
|
|
|
}
|
|
|
|
|
2005-05-05 20:31:40 +04:00
|
|
|
/* create socket */
|
|
|
|
sd = socket(AF_INET, SOCK_STREAM, 0);
|
|
|
|
if (sd < 0) {
|
2005-07-04 03:31:27 +04:00
|
|
|
opal_output(0,
|
2005-05-08 17:22:55 +04:00
|
|
|
"[%lu,%lu,%lu]-[%lu,%lu,%lu] mca_oob_tcp_ping: socket() failed with errno=%d\n",
|
2005-05-05 20:31:40 +04:00
|
|
|
ORTE_NAME_ARGS(orte_process_info.my_name),
|
|
|
|
ORTE_NAME_ARGS(name),
|
|
|
|
ompi_socket_errno);
|
|
|
|
return OMPI_ERR_UNREACH;
|
|
|
|
}
|
2004-09-08 22:03:05 +04:00
|
|
|
|
2005-05-05 20:31:40 +04:00
|
|
|
/* setup the socket as non-blocking */
|
|
|
|
if((flags = fcntl(sd, F_GETFL, 0)) < 0) {
|
2005-07-04 03:31:27 +04:00
|
|
|
opal_output(0, "[%lu,%lu,%lu]-[%lu,%lu,%lu] mca_oob_tcp_ping: fcntl(F_GETFL) failed with errno=%d\n",
|
2005-05-05 20:31:40 +04:00
|
|
|
ORTE_NAME_ARGS(orte_process_info.my_name),
|
|
|
|
ORTE_NAME_ARGS(name),
|
|
|
|
ompi_socket_errno);
|
2005-03-14 23:57:21 +03:00
|
|
|
} else {
|
2005-05-05 20:31:40 +04:00
|
|
|
flags |= O_NONBLOCK;
|
|
|
|
if(fcntl(sd, F_SETFL, flags) < 0) {
|
2005-07-04 03:31:27 +04:00
|
|
|
opal_output(0, "[%lu,%lu,%lu]-[%lu,%lu,%lu] mca_oob_tcp_ping: fcntl(F_SETFL) failed with errno=%d\n",
|
2005-05-05 20:31:40 +04:00
|
|
|
ORTE_NAME_ARGS(orte_process_info.my_name),
|
|
|
|
ORTE_NAME_ARGS(name),
|
|
|
|
ompi_socket_errno);
|
|
|
|
}
|
2005-03-14 23:57:21 +03:00
|
|
|
}
|
2004-09-08 22:03:05 +04:00
|
|
|
|
2005-05-05 20:31:40 +04:00
|
|
|
/* start the connect - will likely fail with EINPROGRESS */
|
|
|
|
FD_ZERO(&fdset);
|
|
|
|
if(connect(sd, (struct sockaddr*)&inaddr, sizeof(inaddr)) < 0) {
|
|
|
|
/* connect failed? */
|
|
|
|
if(ompi_socket_errno != EINPROGRESS && ompi_socket_errno != EWOULDBLOCK) {
|
|
|
|
close(sd);
|
|
|
|
return OMPI_ERR_UNREACH;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* select with timeout to wait for connect to complete */
|
|
|
|
FD_SET(sd, &fdset);
|
|
|
|
tv = *timeout;
|
|
|
|
rc = select(sd+1, NULL, &fdset, NULL, &tv);
|
|
|
|
if(rc <= 0) {
|
|
|
|
close(sd);
|
|
|
|
return OMPI_ERR_UNREACH;
|
|
|
|
}
|
2004-09-08 22:03:05 +04:00
|
|
|
}
|
|
|
|
|
2005-05-05 20:31:40 +04:00
|
|
|
/* set socket back to blocking */
|
|
|
|
flags &= ~O_NONBLOCK;
|
|
|
|
if(fcntl(sd, F_SETFL, flags) < 0) {
|
2005-07-04 03:31:27 +04:00
|
|
|
opal_output(0, "[%lu,%lu,%lu]-[%lu,%lu,%lu] mca_oob_tcp_ping: fcntl(F_SETFL) failed with errno=%d\n",
|
2005-05-05 20:31:40 +04:00
|
|
|
ORTE_NAME_ARGS(orte_process_info.my_name),
|
|
|
|
ORTE_NAME_ARGS(name),
|
|
|
|
ompi_socket_errno);
|
2004-09-08 22:03:05 +04:00
|
|
|
}
|
2005-05-05 20:31:40 +04:00
|
|
|
|
|
|
|
/* send a probe message */
|
|
|
|
memset(&hdr, 0, sizeof(hdr));
|
|
|
|
if(orte_process_info.my_name != NULL) {
|
|
|
|
hdr.msg_src = *orte_process_info.my_name;
|
|
|
|
} else {
|
|
|
|
hdr.msg_src = mca_oob_name_any;
|
|
|
|
}
|
|
|
|
hdr.msg_dst = *name;
|
|
|
|
hdr.msg_type = MCA_OOB_TCP_PROBE;
|
2005-05-18 19:12:04 +04:00
|
|
|
|
2005-05-18 19:31:23 +04:00
|
|
|
MCA_OOB_TCP_HDR_HTON(&hdr);
|
2005-05-05 20:31:40 +04:00
|
|
|
if((rc = write(sd, &hdr, sizeof(hdr))) != sizeof(hdr)) {
|
|
|
|
close(sd);
|
|
|
|
return OMPI_ERR_UNREACH;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* select with timeout to wait for response */
|
|
|
|
FD_SET(sd, &fdset);
|
|
|
|
tv = *timeout;
|
|
|
|
rc = select(sd+1, &fdset, NULL, NULL, &tv);
|
|
|
|
if(rc <= 0) {
|
|
|
|
close(sd);
|
|
|
|
return OMPI_ERR_UNREACH;
|
|
|
|
}
|
|
|
|
if((rc = read(sd, &hdr, sizeof(hdr))) != sizeof(hdr)) {
|
|
|
|
close(sd);
|
|
|
|
return OMPI_ERR_UNREACH;
|
|
|
|
}
|
2005-05-18 19:31:23 +04:00
|
|
|
MCA_OOB_TCP_HDR_NTOH(&hdr);
|
2005-05-18 19:32:05 +04:00
|
|
|
if(hdr.msg_type != MCA_OOB_TCP_PROBE) {
|
2005-05-18 19:31:23 +04:00
|
|
|
close(sd);
|
|
|
|
return OMPI_ERR_UNREACH;
|
|
|
|
}
|
2005-05-05 20:31:40 +04:00
|
|
|
close(sd);
|
|
|
|
return OMPI_SUCCESS;
|
2004-09-08 22:03:05 +04:00
|
|
|
}
|
|
|
|
|
2005-05-05 20:31:40 +04:00
|
|
|
|