From 03d74ff10e17acc77e4decee022d6f2e02cb8a9d Mon Sep 17 00:00:00 2001 From: Sean Hefty Date: Wed, 29 Aug 2012 15:02:54 -0700 Subject: [PATCH] cmatose: Allow user to specify address format Provide an option for the user to indicate the type of addresses used as input. Support hostname, IPv4, IPv6, and GIDs. Signed-off-by: Sean Hefty --- examples/cmatose.c | 29 +++++++++++++++++++---------- examples/common.c | 4 ++-- examples/common.h | 3 ++- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/examples/cmatose.c b/examples/cmatose.c index ba4fc723..ec3a4cea 100644 --- a/examples/cmatose.c +++ b/examples/cmatose.c @@ -81,6 +81,7 @@ static uint8_t tos; static uint8_t migrate = 0; static char *dst_addr; static char *src_addr; +static struct rdma_addrinfo hints; static int create_message(struct cmatest_node *node) { @@ -501,7 +502,6 @@ static int migrate_channel(struct rdma_cm_id *listen_id) static int run_server(void) { struct rdma_cm_id *listen_id; - struct rdma_addrinfo hints; int i, ret; printf("cmatose: starting server\n"); @@ -511,9 +511,6 @@ static int run_server(void) return ret; } - memset(&hints, 0, sizeof hints); - hints.ai_flags = RAI_PASSIVE; - hints.ai_port_space = RDMA_PS_TCP; ret = get_rdma_addr(src_addr, dst_addr, port, &hints, &test.rai); if (ret) { perror("cmatose: getrdmaaddr error"); @@ -583,13 +580,10 @@ out: static int run_client(void) { - struct rdma_addrinfo hints; int i, ret, ret2; printf("cmatose: starting client\n"); - memset(&hints, 0, sizeof hints); - hints.ai_port_space = RDMA_PS_TCP; ret = get_rdma_addr(src_addr, dst_addr, port, &hints, &test.rai); if (ret) { perror("cmatose: getaddrinfo error"); @@ -646,7 +640,7 @@ int main(int argc, char **argv) { int op, ret; - while ((op = getopt(argc, argv, "s:b:c:C:S:t:p:m")) != -1) { + while ((op = getopt(argc, argv, "s:b:f:c:C:S:t:p:m")) != -1) { switch (op) { case 's': dst_addr = optarg; @@ -654,6 +648,16 @@ int main(int argc, char **argv) case 'b': src_addr = optarg; break; + case 'f': + if (!strncasecmp("ip", optarg, 2)) { + hints.ai_flags = RAI_NUMERICHOST; + } else if (!strncasecmp("gid", optarg, 3)) { + hints.ai_flags = RAI_NUMERICHOST | RAI_FAMILY; + hints.ai_family = AF_IB; + } else if (strncasecmp("name", optarg, 4)) { + fprintf(stderr, "Warning: unknown address format\n"); + } + break; case 'c': connections = atoi(optarg); break; @@ -677,6 +681,8 @@ int main(int argc, char **argv) printf("usage: %s\n", argv[0]); printf("\t[-s server_address]\n"); printf("\t[-b bind_address]\n"); + printf("\t[-f address_format]\n"); + printf("\t name, ip, ipv6, or gid\n"); printf("\t[-c connections]\n"); printf("\t[-C message_count]\n"); printf("\t[-S message_size]\n"); @@ -699,10 +705,13 @@ int main(int argc, char **argv) if (alloc_nodes()) exit(1); - if (dst_addr) + hints.ai_port_space = RDMA_PS_TCP; + if (dst_addr) { ret = run_client(); - else + } else { + hints.ai_flags |= RAI_PASSIVE; ret = run_server(); + } printf("test complete\n"); destroy_nodes(); diff --git a/examples/common.c b/examples/common.c index 3eeb1e9b..89e76f9d 100644 --- a/examples/common.c +++ b/examples/common.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005-2006 Intel Corporation. All rights reserved. + * Copyright (c) 2005-2006,2012 Intel Corporation. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU @@ -56,7 +56,7 @@ int get_rdma_addr(char *src, char *dst, char *port, rai_hints = *hints; if (src) { - rai_hints.ai_flags = RAI_PASSIVE; + rai_hints.ai_flags |= RAI_PASSIVE; ret = rdma_getaddrinfo(src, NULL, &rai_hints, &res); if (ret) return ret; diff --git a/examples/common.h b/examples/common.h index 8d9fea02..25d881fd 100644 --- a/examples/common.h +++ b/examples/common.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005-2011 Intel Corporation. All rights reserved. + * Copyright (c) 2005-2012 Intel Corporation. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU @@ -37,6 +37,7 @@ #include #include +#include #if __BYTE_ORDER == __BIG_ENDIAN static inline uint64_t cpu_to_be64(uint64_t x) { return x; } -- 2.45.2