~ubuntu-branches/ubuntu/utopic/ibsim/utopic

« back to all changes in this revision

Viewing changes to umad2sim/sim_client.c

  • Committer: Package Import Robot
  • Author(s): Ana Beatriz Guerrero Lopez
  • Date: 2014-07-04 10:22:12 UTC
  • mfrom: (3.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20140704102212-oyip9ymzav2vp6ur
Tags: 0.6-3
* Upload to unstable
* Add a watch file.
* Add fields Vcs-Browser/Vcs-Git.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
#include <arpa/inet.h>
46
46
#include <netdb.h>
47
47
 
48
 
#include <infiniband/common.h>
49
48
#include <infiniband/mad.h>
50
49
 
51
50
#include <ibsim.h>
60
59
#endif
61
60
 
62
61
static unsigned int remote_mode = 0;
 
62
static char* socket_basename;
63
63
 
64
64
static int sim_ctl(struct sim_client *sc, int type, void *data, int len)
65
65
{
143
143
 
144
144
static char *get_name(union name_t *name)
145
145
{
146
 
        if (remote_mode) {
 
146
        if (remote_mode)
147
147
                return inet_ntoa(name->name_i.sin_addr);
148
 
        } else {
 
148
        else
149
149
                return name->name_u.sun_path + 1;
150
 
        }
151
150
}
152
151
 
153
152
static int sim_attach(int fd, union name_t *name, size_t size)
159
158
                DEBUG("attempt to connect to %s (attempt %d)",
160
159
                      get_name(name), retries);
161
160
 
162
 
                if ((r =
163
 
                     connect(fd, (struct sockaddr *)name, size)) >= 0)
 
161
                if ((r = connect(fd, (struct sockaddr *)name, size)) >= 0)
164
162
                        break;
165
163
 
166
164
                if (r < 0 && errno == ECONNREFUSED) {
175
173
        return 0;
176
174
}
177
175
 
178
 
static int sim_connect(struct sim_client *sc, int id, int qp, char *nodeid)
 
176
static int sim_connect(struct sim_client *sc, int id, int qp, char *nodeid,
 
177
                       char *issm)
179
178
{
180
179
        struct sim_client_info info = { 0 };
181
180
 
182
181
        info.id = id;
183
 
        info.issm = 0;
 
182
        if (issm)
 
183
                info.issm = 1;
 
184
        else
 
185
                info.issm = 0;
184
186
        info.qp = qp;
185
187
 
186
188
        if (nodeid)
202
204
        return sim_ctl(sc, SIM_CTL_DISCONNECT, 0, 0);
203
205
}
204
206
 
205
 
static int sim_init(struct sim_client *sc, int qp, char *nodeid)
 
207
static int sim_init(struct sim_client *sc, char *nodeid, char *issm)
206
208
{
207
209
        union name_t name;
208
210
        socklen_t size;
214
216
 
215
217
        connect_port = getenv("IBSIM_SERVER_PORT");
216
218
        connect_host = getenv("IBSIM_SERVER_NAME");
 
219
        socket_basename = getenv("IBSIM_SOCKNAME");
 
220
 
 
221
        if(!socket_basename)
 
222
                socket_basename = SIM_BASENAME;
217
223
 
218
224
        if (connect_host && *connect_host)
219
225
                remote_mode = 1;
220
226
 
221
 
        DEBUG("init client pid=%d, qp=%d nodeid=%s",
222
 
              pid, qp, nodeid ? nodeid : "none");
 
227
        DEBUG("init client pid=%d, nodeid=%s", pid, nodeid ? nodeid : "none");
223
228
 
224
229
        if ((fd = socket(remote_mode ? PF_INET : PF_LOCAL, SOCK_DGRAM, 0)) < 0)
225
230
                IBPANIC("can't get socket (fd)");
227
232
        if ((ctlfd = socket(remote_mode ? PF_INET : PF_LOCAL, SOCK_DGRAM, 0)) < 0)
228
233
                IBPANIC("can't get socket (ctlfd)");
229
234
 
230
 
        size = make_name(&name, NULL, 0, "%s:ctl%d", SIM_BASENAME, pid);
 
235
        size = make_name(&name, NULL, 0, "%s:ctl%d", socket_basename, pid);
231
236
 
232
237
        if (bind(ctlfd, (struct sockaddr *)&name, size) < 0)
233
238
                IBPANIC("can't bind ctl socket");
236
241
              pid, ctlfd, get_name(&name));
237
242
 
238
243
        port = connect_port ? atoi(connect_port) : IBSIM_DEFAULT_SERVER_PORT;
239
 
        size = make_name(&name, connect_host, port, "%s:ctl", SIM_BASENAME);
 
244
        size = make_name(&name, connect_host, port, "%s:ctl", socket_basename);
240
245
 
241
246
        sim_attach(ctlfd, &name, size);
242
247
 
243
248
        sc->fd_ctl = ctlfd;
244
249
 
245
 
        size = make_name(&name, NULL, 0, "%s:in%d", SIM_BASENAME, pid);
 
250
        size = make_name(&name, NULL, 0, "%s:in%d", socket_basename, pid);
246
251
 
247
252
        if (bind(fd, (struct sockaddr *)&name, size) < 0)
248
253
                IBPANIC("can't bind input socket");
253
258
                IBPANIC("can't read data from bound socket");
254
259
        port = ntohs(name.name_i.sin_port);
255
260
 
256
 
        sc->clientid = sim_connect(sc, remote_mode ? port : pid, qp, nodeid);
 
261
        sc->clientid = sim_connect(sc, remote_mode ? port : pid, 0, nodeid, issm);
257
262
        if (sc->clientid < 0)
258
263
                IBPANIC("connect failed");
259
264
 
260
265
        port = connect_port ? atoi(connect_port) : IBSIM_DEFAULT_SERVER_PORT;
261
266
        size = make_name(&name, connect_host, port + sc->clientid + 1,
262
 
                         "%s:out%d", SIM_BASENAME, sc->clientid);
 
267
                         "%s:out%d", socket_basename, sc->clientid);
263
268
 
264
269
        sim_attach(fd, &name, size);
265
270
 
280
285
        return sim_ctl(sc, SIM_CTL_SET_ISSM, &issm, sizeof(int));
281
286
}
282
287
 
283
 
int sim_client_init(struct sim_client *sc, char *nodeid)
 
288
int sim_client_init(struct sim_client *sc)
284
289
{
285
 
        if (!nodeid)
286
 
                nodeid = getenv("SIM_HOST");
287
 
        if (sim_init(sc, 0, nodeid) < 0)
 
290
        char *nodeid;
 
291
        char *issm;
 
292
 
 
293
        nodeid = getenv("SIM_HOST");
 
294
        issm = getenv("SIM_SET_ISSM");
 
295
        if (sim_init(sc, nodeid, issm) < 0)
288
296
                return -1;
289
 
        if (sim_ctl(sc, SIM_CTL_GET_VENDOR, &sc->vendor, sizeof(sc->vendor)) <
290
 
            0)
 
297
        if (sim_ctl(sc, SIM_CTL_GET_VENDOR, &sc->vendor,
 
298
                    sizeof(sc->vendor)) < 0)
291
299
                goto _exit;
292
300
        if (sim_ctl(sc, SIM_CTL_GET_NODEINFO, sc->nodeinfo,
293
301
                    sizeof(sc->nodeinfo)) < 0)
294
302
                goto _exit;
295
 
        sc->portinfo[0] = 0;
 
303
 
 
304
        sc->portinfo[0] = 0;    // portno requested
296
305
        if (sim_ctl(sc, SIM_CTL_GET_PORTINFO, sc->portinfo,
297
306
                    sizeof(sc->portinfo)) < 0)
298
307
                goto _exit;
299
308
        if (sim_ctl(sc, SIM_CTL_GET_PKEYS, sc->pkeys, sizeof(sc->pkeys)) < 0)
300
309
                goto _exit;
301
 
        if (getenv("SIM_SET_ISSM"))
 
310
        if (issm)
302
311
                sim_client_set_sm(sc, 1);
303
312
        return 0;
304
313
  _exit:
305
314
        sim_disconnect(sc);
306
315
        sc->fd_ctl = sc->fd_pktin = sc->fd_pktout = -1;
307
 
        return 0;
 
316
        return -1;
308
317
}
309
318
 
310
319
void sim_client_exit(struct sim_client *sc)