1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2002 Cray Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * this file provides functions to aquire the IP address of the node
24 * and translate them into a NID/PID pair which supports a static
25 * mapping of virtual nodes into the port range of an IP socket.
32 #include <portals/p30.h>
37 /* Function: get_node_id
38 * Returns: a 32 bit id for this node, actually a big-endian IP address
40 * get_node_id() determines the host name and uses the resolver to
41 * find out its ip address. This is fairly fragile and inflexible, but
42 * explicitly asking about interfaces and their addresses is very
43 * complicated and nonportable.
45 static unsigned int get_node_id(void)
52 if (!(host_envp = getenv("PTL_HOSTID")))
54 gethostname(buffer,sizeof(buffer));
55 he=gethostbyname(buffer);
57 x=*(unsigned int *)he->h_addr_list[0];
64 if (host_envp[1] != 'x')
67 sscanf(host_envp, "%d.%d.%d.%d", &a, &b, &c, &d);
68 return ((a<<24) | (b<<16) | (c<<8) | d);
72 long long hostid = strtoll(host_envp, 0, 0);
73 return((unsigned int) hostid);
79 /* Function: set_address
80 * Arugments: t: a procnal structure to populate with the request
82 * set_address performs the bit manipulations to set the nid, pid, and
83 * iptop8 fields of the procnal structures.
85 * TODO: fix pidrequest to try to do dynamic binding if PTL_ID_ANY
89 void set_address(bridge t,ptl_pid_t pidrequest)
92 if (pidrequest==(unsigned short)PTL_PID_ANY) port = 0;
94 t->nal_cb->ni.nid=get_node_id();
95 t->nal_cb->ni.pid=port;
99 void set_address(bridge t,ptl_pid_t pidrequest)
101 int virtnode, in_addr, port;
104 /* get and remember my node id*/
105 if (!getenv("PTL_VIRTNODE"))
109 int maxvnode = PNAL_VNODE_MASK - (PNAL_BASE_PORT
110 >> PNAL_VNODE_SHIFT);
111 virtnode = atoi(getenv("PTL_VIRTNODE"));
112 if (virtnode > maxvnode)
114 fprintf(stderr, "PTL_VIRTNODE of %d is too large - max %d\n",
120 in_addr = get_node_id();
122 t->iptop8 = in_addr >> PNAL_HOSTID_SHIFT;/* for making new connections */
123 t->nal_cb->ni.nid = ((in_addr & PNAL_HOSTID_MASK)
128 /* TODO: Support of pid PTL_ID_ANY with virtual nodes needs more work. */
130 if (pid==(unsigned short)PTL_PID_ANY) port = 0;
132 if (pid==(unsigned short)PTL_PID_ANY)
134 fprintf(stderr, "portal pid PTL_ID_ANY is not currently supported\n");
137 else if (pid > PNAL_PID_MASK)
139 fprintf(stderr, "portal pid of %d is too large - max %d\n",
143 else port = ((virtnode << PNAL_VNODE_SHIFT) + pid) + PNAL_BASE_PORT;
144 t->nal_cb->ni.pid=pid;