|
Packit |
857059 |
/* BEGIN_ICS_COPYRIGHT7 ****************************************
|
|
Packit |
857059 |
|
|
Packit |
857059 |
Copyright (c) 2015, Intel Corporation
|
|
Packit |
857059 |
|
|
Packit |
857059 |
Redistribution and use in source and binary forms, with or without
|
|
Packit |
857059 |
modification, are permitted provided that the following conditions are met:
|
|
Packit |
857059 |
|
|
Packit |
857059 |
* Redistributions of source code must retain the above copyright notice,
|
|
Packit |
857059 |
this list of conditions and the following disclaimer.
|
|
Packit |
857059 |
* Redistributions in binary form must reproduce the above copyright
|
|
Packit |
857059 |
notice, this list of conditions and the following disclaimer in the
|
|
Packit |
857059 |
documentation and/or other materials provided with the distribution.
|
|
Packit |
857059 |
* Neither the name of Intel Corporation nor the names of its contributors
|
|
Packit |
857059 |
may be used to endorse or promote products derived from this software
|
|
Packit |
857059 |
without specific prior written permission.
|
|
Packit |
857059 |
|
|
Packit |
857059 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
Packit |
857059 |
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Packit |
857059 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
Packit |
857059 |
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
|
Packit |
857059 |
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
Packit |
857059 |
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
Packit |
857059 |
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
Packit |
857059 |
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
Packit |
857059 |
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
Packit |
857059 |
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
857059 |
|
|
Packit |
857059 |
** END_ICS_COPYRIGHT7 ****************************************/
|
|
Packit |
857059 |
|
|
Packit |
857059 |
/* [ICS VERSION STRING: unknown] */
|
|
Packit |
857059 |
|
|
Packit |
857059 |
#include <stdio.h>
|
|
Packit |
857059 |
#include <stdlib.h>
|
|
Packit |
857059 |
#include <signal.h>
|
|
Packit |
857059 |
#include <string.h>
|
|
Packit |
857059 |
#include <linux/types.h>
|
|
Packit |
857059 |
#include <endian.h>
|
|
Packit |
857059 |
#include <getopt.h>
|
|
Packit |
857059 |
#include <opasadb_path_private.h>
|
|
Packit |
857059 |
#include <opasadb_debug.h>
|
|
Packit |
857059 |
#include <arpa/inet.h>
|
|
Packit |
857059 |
#include <sys/mman.h>
|
|
Packit |
857059 |
#include "dumppath.h"
|
|
Packit |
857059 |
|
|
Packit |
857059 |
#define SLEEPTIME 1
|
|
Packit |
857059 |
#define QUERIESPERPASS 100000
|
|
Packit |
857059 |
#define DEFAULTPASSES 10
|
|
Packit |
857059 |
|
|
Packit |
857059 |
#define MAXPATHS 32768
|
|
Packit |
857059 |
#define MAXPKEYS 32
|
|
Packit |
857059 |
|
|
Packit |
857059 |
#define HFINAME "qib0"
|
|
Packit |
857059 |
#define PORTNO 1
|
|
Packit |
857059 |
|
|
Packit |
857059 |
static IB_PATH_RECORD_NO record[MAXPATHS];
|
|
Packit |
857059 |
static uint16 pkey[MAXPKEYS];
|
|
Packit |
857059 |
static int numrecs, numkeys;
|
|
Packit |
857059 |
|
|
Packit |
857059 |
static char hfi_name[64] = HFINAME;
|
|
Packit |
857059 |
static uint16 port_no = PORTNO;
|
|
Packit |
857059 |
|
|
Packit |
857059 |
static int done=0;
|
|
Packit |
857059 |
|
|
Packit |
857059 |
static uint64_t build_comp_mask(IB_PATH_RECORD_NO path)
|
|
Packit |
857059 |
{
|
|
Packit |
857059 |
uint64_t mask = 0;
|
|
Packit |
857059 |
|
|
Packit |
857059 |
if (path.ServiceID)
|
|
Packit |
857059 |
mask |= IB_PATH_RECORD_COMP_SERVICEID;
|
|
Packit |
857059 |
if (path.DGID.Type.Global.InterfaceID | path.DGID.Type.Global.SubnetPrefix)
|
|
Packit |
857059 |
mask |= IB_PATH_RECORD_COMP_DGID;
|
|
Packit |
857059 |
if (path.SGID.Type.Global.InterfaceID | path.SGID.Type.Global.SubnetPrefix)
|
|
Packit |
857059 |
mask |= IB_PATH_RECORD_COMP_SGID;
|
|
Packit |
857059 |
if (path.DLID)
|
|
Packit |
857059 |
mask |= IB_PATH_RECORD_COMP_DLID;
|
|
Packit |
857059 |
if (path.SLID)
|
|
Packit |
857059 |
mask |= IB_PATH_RECORD_COMP_SLID;
|
|
Packit |
857059 |
if (path.P_Key) mask |= IB_PATH_RECORD_COMP_PKEY;
|
|
Packit |
857059 |
|
|
Packit |
857059 |
return mask;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
static void my_sig(int signo)
|
|
Packit |
857059 |
{
|
|
Packit |
857059 |
done=1;
|
|
Packit |
857059 |
return;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
static void sigalarm(int signo)
|
|
Packit |
857059 |
{
|
|
Packit |
857059 |
return;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
static int my_sleep(unsigned int secs)
|
|
Packit |
857059 |
{
|
|
Packit |
857059 |
if (signal(SIGALRM, sigalarm) == SIG_ERR) return -1;
|
|
Packit |
857059 |
|
|
Packit |
857059 |
alarm(secs);
|
|
Packit |
857059 |
pause();
|
|
Packit |
857059 |
return alarm(0);
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
static int readline(FILE *f, char *s, int max)
|
|
Packit |
857059 |
{
|
|
Packit |
857059 |
int i, c;
|
|
Packit |
857059 |
memset(s,0,max);
|
|
Packit |
857059 |
|
|
Packit |
857059 |
i=0;
|
|
Packit |
857059 |
c=fgetc(f);
|
|
Packit |
857059 |
|
|
Packit |
857059 |
while (c !='\n' && !feof(f) && i < max) {
|
|
Packit |
857059 |
s[i++]=c;
|
|
Packit |
857059 |
c=fgetc(f);
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
return i;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
#define asciitohex(c) ((((c)>='0') & ((c)<='9'))?((c)-'0'):((c)-'a'+10))
|
|
Packit |
857059 |
|
|
Packit |
857059 |
static void getraw(IB_GID_NO *gid, char *p)
|
|
Packit |
857059 |
{
|
|
Packit |
857059 |
char *p2;
|
|
Packit |
857059 |
|
|
Packit |
857059 |
gid->Type.Global.SubnetPrefix = hton64(strtoul(p,&p2,16));
|
|
Packit |
857059 |
gid->Type.Global.InterfaceID = hton64(strtoul(p2,NULL,16));
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
int readrecord(FILE *f, IB_PATH_RECORD_NO *record)
|
|
Packit |
857059 |
{
|
|
Packit |
857059 |
char *p, *l;
|
|
Packit |
857059 |
|
|
Packit |
857059 |
char buffer[1024];
|
|
Packit |
857059 |
|
|
Packit |
857059 |
memset(record, 0, sizeof(IB_PATH_RECORD_NO));
|
|
Packit |
857059 |
|
|
Packit |
857059 |
if (readline(f,buffer,1024)<=0) {
|
|
Packit |
857059 |
return -1;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
p=strtok_r(buffer,":", &l);
|
|
Packit |
857059 |
if (!p)
|
|
Packit |
857059 |
return -1;
|
|
Packit |
857059 |
getraw(&record->SGID,p);
|
|
Packit |
857059 |
p=strtok_r(NULL,":", &l);
|
|
Packit |
857059 |
if (!p)
|
|
Packit |
857059 |
return -1;
|
|
Packit |
857059 |
getraw(&record->DGID,p);
|
|
Packit |
857059 |
p=strtok_r(NULL,":", &l);
|
|
Packit |
857059 |
if (!p)
|
|
Packit |
857059 |
return -1;
|
|
Packit |
857059 |
record->SLID = htons(strtol(p,NULL,0));
|
|
Packit |
857059 |
p=strtok_r(NULL,":", &l);
|
|
Packit |
857059 |
if (!p)
|
|
Packit |
857059 |
return -1;
|
|
Packit |
857059 |
record->DLID = htons(strtol(p,NULL,0));
|
|
Packit |
857059 |
p=strtok_r(NULL,":", &l);
|
|
Packit |
857059 |
if (!p)
|
|
Packit |
857059 |
return -1;
|
|
Packit |
857059 |
record->P_Key = htons(strtol(p,NULL,0));
|
|
Packit |
857059 |
|
|
Packit |
857059 |
// We dummy up a SID that matches the pkey.
|
|
Packit |
857059 |
if (record->P_Key == 0xffff) {
|
|
Packit |
857059 |
record->ServiceID=0;
|
|
Packit |
857059 |
} else {
|
|
Packit |
857059 |
record->ServiceID=record->P_Key;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
return 0;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
static int load_records(char *fname)
|
|
Packit |
857059 |
{
|
|
Packit |
857059 |
FILE *f;
|
|
Packit |
857059 |
|
|
Packit |
857059 |
f=fopen(fname,"r");
|
|
Packit |
857059 |
if (f == NULL) {
|
|
Packit |
857059 |
_DBG_ERROR("Failed to open %s\n",fname);
|
|
Packit |
857059 |
return -1;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
printf("Loading %s.\n", fname);
|
|
Packit |
857059 |
numrecs = 0;
|
|
Packit |
857059 |
|
|
Packit |
857059 |
do {
|
|
Packit |
857059 |
if (readrecord(f,&record[numrecs])) break;
|
|
Packit |
857059 |
numrecs++;
|
|
Packit |
857059 |
} while (numrecs < MAXPATHS);
|
|
Packit |
857059 |
fclose(f);
|
|
Packit |
857059 |
|
|
Packit |
857059 |
return numrecs;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
static int find_pkeys(void)
|
|
Packit |
857059 |
{
|
|
Packit |
857059 |
int i;
|
|
Packit |
857059 |
|
|
Packit |
857059 |
for (numkeys=0, i=0; i
|
|
Packit |
857059 |
int k;
|
|
Packit |
857059 |
for (k=0; k
|
|
Packit |
857059 |
if (pkey[k] == record[i].P_Key) break;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
if (k>=numkeys) {
|
|
Packit |
857059 |
pkey[numkeys]=record[i].P_Key;
|
|
Packit |
857059 |
numkeys++;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
return numkeys;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
/*
|
|
Packit |
857059 |
* Creates the shared memory tables. Uses the info from the supplied file,
|
|
Packit |
857059 |
* to create one or more virtual fabrics. NOTE: Only supports a single
|
|
Packit |
857059 |
* active port.
|
|
Packit |
857059 |
*/
|
|
Packit |
857059 |
int server(char *fname, int n)
|
|
Packit |
857059 |
{
|
|
Packit |
857059 |
int i, err, pass;
|
|
Packit |
857059 |
op_ppath_writer_t w;
|
|
Packit |
857059 |
op_ppath_port_record_t port;
|
|
Packit |
857059 |
|
|
Packit |
857059 |
_DBG_FUNC_ENTRY;
|
|
Packit |
857059 |
|
|
Packit |
857059 |
if (load_records(fname) <= 0) {
|
|
Packit |
857059 |
return -1;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
if (find_pkeys() <= 0) {
|
|
Packit |
857059 |
_DBG_ERROR("No pkeys?!?\n");
|
|
Packit |
857059 |
return -1;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
_DBG_NOTICE("Creating the shared memory table.\n");
|
|
Packit |
857059 |
err = op_ppath_create_writer(&w);
|
|
Packit |
857059 |
if (err) {
|
|
Packit |
857059 |
_DBG_ERROR("Failed to create shared memory table: %s\n",
|
|
Packit |
857059 |
strerror(err));
|
|
Packit |
857059 |
return err;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
_DBG_NOTICE("Creating the shared port table.\n");
|
|
Packit |
857059 |
err = op_ppath_initialize_ports(&w, 1);
|
|
Packit |
857059 |
if (err) {
|
|
Packit |
857059 |
_DBG_ERROR( "Failed to create port table: %s\n",
|
|
Packit |
857059 |
strerror(err));
|
|
Packit |
857059 |
goto error;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
_DBG_NOTICE("Creating the subnet table.\n");
|
|
Packit |
857059 |
err = op_ppath_initialize_subnets(&w, 1, numkeys);
|
|
Packit |
857059 |
if (err) {
|
|
Packit |
857059 |
_DBG_ERROR( "Failed to create subnet table: %s\n",
|
|
Packit |
857059 |
strerror(err));
|
|
Packit |
857059 |
goto error;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
_DBG_NOTICE("Creating the vfabric table.\n");
|
|
Packit |
857059 |
err = op_ppath_initialize_vfabrics(&w, numkeys);
|
|
Packit |
857059 |
if (err) {
|
|
Packit |
857059 |
_DBG_ERROR( "Failed to create vfab table: %s\n",
|
|
Packit |
857059 |
strerror(err));
|
|
Packit |
857059 |
goto error;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
_DBG_NOTICE("Adding the subnet.\n");
|
|
Packit |
857059 |
err = op_ppath_add_subnet(&w, record[0].SGID.Type.Global.SubnetPrefix);
|
|
Packit |
857059 |
if (err) {
|
|
Packit |
857059 |
_DBG_ERROR( "Failed to add subnet: %s\n",
|
|
Packit |
857059 |
strerror(err));
|
|
Packit |
857059 |
goto error;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
_DBG_NOTICE("Adding the vfabrics.\n");
|
|
Packit |
857059 |
for (i=0; i
|
|
Packit |
857059 |
uint64 sid;
|
|
Packit |
857059 |
char buffer[VFAB_NAME_LENGTH];
|
|
Packit |
857059 |
sprintf(buffer,"VF%04x",(unsigned int)pkey[i]);
|
|
Packit |
857059 |
err = op_ppath_add_vfab(&w,
|
|
Packit |
857059 |
buffer,
|
|
Packit |
857059 |
record[0].SGID.Type.Global.SubnetPrefix,
|
|
Packit |
857059 |
pkey[i],
|
|
Packit |
857059 |
0);
|
|
Packit |
857059 |
if (err) {
|
|
Packit |
857059 |
_DBG_ERROR( "Failed to add vfab: %s\n",
|
|
Packit |
857059 |
strerror(err));
|
|
Packit |
857059 |
goto error;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
sid=(pkey[i] == 0xffff)?0:pkey[i];
|
|
Packit |
857059 |
|
|
Packit |
857059 |
// NOTE THAT WE ARE SETTING THE SID TO MATCH THE PKEY!
|
|
Packit |
857059 |
err = op_ppath_add_sid(&w,
|
|
Packit |
857059 |
record[0].SGID.Type.Global.SubnetPrefix,
|
|
Packit |
857059 |
sid,0,
|
|
Packit |
857059 |
buffer);
|
|
Packit |
857059 |
if (err) {
|
|
Packit |
857059 |
_DBG_ERROR( "Failed to add sid: %s\n",
|
|
Packit |
857059 |
strerror(err));
|
|
Packit |
857059 |
goto error;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
memset(&port,0, sizeof(op_ppath_port_record_t));
|
|
Packit |
857059 |
|
|
Packit |
857059 |
port.source_prefix = record[0].SGID.Type.Global.SubnetPrefix;
|
|
Packit |
857059 |
port.source_guid = record[0].SGID.Type.Global.InterfaceID;
|
|
Packit |
857059 |
strcpy(port.hfi_name,hfi_name);
|
|
Packit |
857059 |
|
|
Packit |
857059 |
port.port = port_no;
|
|
Packit |
857059 |
|
|
Packit |
857059 |
_DBG_NOTICE("Adding the port.\n");
|
|
Packit |
857059 |
err = op_ppath_add_port(&w,port);
|
|
Packit |
857059 |
if (err) {
|
|
Packit |
857059 |
_DBG_ERROR( "Failed to add port: %s\n",
|
|
Packit |
857059 |
strerror(err));
|
|
Packit |
857059 |
goto error;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
for(pass = 0; pass < n && !done; pass++) {
|
|
Packit |
857059 |
|
|
Packit |
857059 |
if (pass>0) my_sleep(SLEEPTIME);
|
|
Packit |
857059 |
|
|
Packit |
857059 |
_DBG_NOTICE("Pass %d: Inserting records.\n", pass);
|
|
Packit |
857059 |
|
|
Packit |
857059 |
_DBG_NOTICE("Creating the path table.\n");
|
|
Packit |
857059 |
err = op_ppath_initialize_paths(&w, MAXPATHS);
|
|
Packit |
857059 |
if (err) {
|
|
Packit |
857059 |
_DBG_ERROR( "Failed to create path table: %s\n",
|
|
Packit |
857059 |
strerror(err));
|
|
Packit |
857059 |
goto error;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
for (i=0;i
|
|
Packit |
857059 |
if (op_ppath_add_path(&w, &record[i])) {
|
|
Packit |
857059 |
_DBG_ERROR( "Failed to add records.\n");
|
|
Packit |
857059 |
err = -1;
|
|
Packit |
857059 |
goto error;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
_DBG_NOTICE("Done inserting records.\n");
|
|
Packit |
857059 |
op_ppath_publish(&w);
|
|
Packit |
857059 |
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
printf("Press 'q' to close and delete the shared tables.\n");
|
|
Packit |
857059 |
fflush(stdin);
|
|
Packit |
857059 |
do {
|
|
Packit |
857059 |
err=getchar();
|
|
Packit |
857059 |
} while(err != 'q');
|
|
Packit |
857059 |
|
|
Packit |
857059 |
error:
|
|
Packit |
857059 |
|
|
Packit |
857059 |
op_ppath_close_writer(&w);
|
|
Packit |
857059 |
|
|
Packit |
857059 |
_DBG_FUNC_EXIT;
|
|
Packit |
857059 |
return 0;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
int client(char *fname, int n)
|
|
Packit |
857059 |
{
|
|
Packit |
857059 |
op_ppath_reader_t r;
|
|
Packit |
857059 |
int pass, count, err;
|
|
Packit |
857059 |
int ret = 0;
|
|
Packit |
857059 |
|
|
Packit |
857059 |
srand((unsigned)time(NULL));
|
|
Packit |
857059 |
|
|
Packit |
857059 |
if (load_records(fname) <= 0) {
|
|
Packit |
857059 |
return -1;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
err = op_ppath_create_reader(&r);
|
|
Packit |
857059 |
if (err) {
|
|
Packit |
857059 |
_DBG_ERROR( "Failed to access shared memory tables: %s\n",
|
|
Packit |
857059 |
strerror(err));
|
|
Packit |
857059 |
return err;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
_DBG_INFO("Tables are open.\n");
|
|
Packit |
857059 |
|
|
Packit |
857059 |
count = 0;
|
|
Packit |
857059 |
pass = 0;
|
|
Packit |
857059 |
|
|
Packit |
857059 |
do {
|
|
Packit |
857059 |
IB_PATH_RECORD_NO query;
|
|
Packit |
857059 |
int i = rand() % numrecs;
|
|
Packit |
857059 |
int j = rand() % 6;
|
|
Packit |
857059 |
|
|
Packit |
857059 |
IB_PATH_RECORD_NO result;
|
|
Packit |
857059 |
|
|
Packit |
857059 |
query = record[i];
|
|
Packit |
857059 |
|
|
Packit |
857059 |
switch (j) {
|
|
Packit |
857059 |
case 0:
|
|
Packit |
857059 |
/* Query by SID and LIDs. */
|
|
Packit |
857059 |
query.P_Key = 0;
|
|
Packit |
857059 |
memset(&query.SGID,0,sizeof(IB_GID_NO));
|
|
Packit |
857059 |
memset(&query.DGID,0,sizeof(IB_GID_NO));
|
|
Packit |
857059 |
break;
|
|
Packit |
857059 |
case 1:
|
|
Packit |
857059 |
/* Query by PKEY and LIDs. */
|
|
Packit |
857059 |
query.ServiceID = 0;
|
|
Packit |
857059 |
memset(&query.SGID,0,sizeof(IB_GID_NO));
|
|
Packit |
857059 |
memset(&query.DGID,0,sizeof(IB_GID_NO));
|
|
Packit |
857059 |
break;
|
|
Packit |
857059 |
case 2:
|
|
Packit |
857059 |
/* No SID, no pkey, just LIDs. */
|
|
Packit |
857059 |
query.ServiceID = 0;
|
|
Packit |
857059 |
query.P_Key = 0;
|
|
Packit |
857059 |
memset(&query.SGID,0,sizeof(IB_GID_NO));
|
|
Packit |
857059 |
memset(&query.DGID,0,sizeof(IB_GID_NO));
|
|
Packit |
857059 |
break;
|
|
Packit |
857059 |
case 3:
|
|
Packit |
857059 |
/* Query by PKEY and GIDs. */
|
|
Packit |
857059 |
query.ServiceID = 0;
|
|
Packit |
857059 |
query.DLID = 0;
|
|
Packit |
857059 |
query.SLID = 0;
|
|
Packit |
857059 |
break;
|
|
Packit |
857059 |
case 4:
|
|
Packit |
857059 |
/* Query by SID and GIDs. */
|
|
Packit |
857059 |
query.P_Key = 0;
|
|
Packit |
857059 |
query.DLID = 0;
|
|
Packit |
857059 |
query.SLID = 0;
|
|
Packit |
857059 |
break;
|
|
Packit |
857059 |
case 5:
|
|
Packit |
857059 |
/* Query by just GIDs. */
|
|
Packit |
857059 |
query.P_Key = 0;
|
|
Packit |
857059 |
query.ServiceID = 0;
|
|
Packit |
857059 |
query.DLID = 0;
|
|
Packit |
857059 |
query.SLID = 0;
|
|
Packit |
857059 |
break;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
err = op_ppath_find_path(&r,
|
|
Packit |
857059 |
hfi_name,
|
|
Packit |
857059 |
port_no,
|
|
Packit |
857059 |
build_comp_mask(query),
|
|
Packit |
857059 |
&query,
|
|
Packit |
857059 |
&result);
|
|
Packit |
857059 |
if (err) {
|
|
Packit |
857059 |
_DBG_ERROR("op_ppath_find_path() failed: %s\n",
|
|
Packit |
857059 |
strerror(err));
|
|
Packit |
857059 |
fprint_path_record(stderr, "Looking for",
|
|
Packit |
857059 |
(op_path_rec_t*)&query);
|
|
Packit |
857059 |
ret = -1;
|
|
Packit |
857059 |
goto client_exit;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
if (j==0 && ((result.DLID != record[i].DLID) ||
|
|
Packit |
857059 |
(result.SLID != record[i].SLID))) {
|
|
Packit |
857059 |
_DBG_ERROR( "Returned the wrong record.\n");
|
|
Packit |
857059 |
fprint_path_record(stderr,"Looking for",
|
|
Packit |
857059 |
(op_path_rec_t *) & record[i]);
|
|
Packit |
857059 |
fprint_path_record(stderr,"Found", (op_path_rec_t *) & result);
|
|
Packit |
857059 |
ret = -1;
|
|
Packit |
857059 |
goto client_exit;
|
|
Packit |
857059 |
} else if (j != 0 && (memcmp((void*)&(result.DGID), (void*)&(record[i].DGID),
|
|
Packit |
857059 |
sizeof(result.DGID)) ||
|
|
Packit |
857059 |
memcmp((void*)&(result.SGID), (void*)&(record[i].SGID),
|
|
Packit |
857059 |
sizeof(result.SGID)))) {
|
|
Packit |
857059 |
_DBG_ERROR( "Returned the wrong record.\n");
|
|
Packit |
857059 |
fprint_path_record(stderr,"Looking for",
|
|
Packit |
857059 |
(op_path_rec_t *) & record[i]);
|
|
Packit |
857059 |
fprint_path_record(stderr,"Found", (op_path_rec_t *) & result);
|
|
Packit |
857059 |
ret = -1;
|
|
Packit |
857059 |
goto client_exit;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
count++;
|
|
Packit |
857059 |
if (count >= QUERIESPERPASS) {
|
|
Packit |
857059 |
pass++;
|
|
Packit |
857059 |
count=0;
|
|
Packit |
857059 |
printf("Pass %d complete.\n", pass);
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
} while (!done && pass < n);
|
|
Packit |
857059 |
|
|
Packit |
857059 |
client_exit:
|
|
Packit |
857059 |
op_ppath_close_reader(&r);
|
|
Packit |
857059 |
return ret;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
int dump(char *fname)
|
|
Packit |
857059 |
{
|
|
Packit |
857059 |
op_ppath_reader_t r;
|
|
Packit |
857059 |
int err;
|
|
Packit |
857059 |
unsigned i;
|
|
Packit |
857059 |
FILE *f = fopen(fname,"w");
|
|
Packit |
857059 |
|
|
Packit |
857059 |
if (!f) {
|
|
Packit |
857059 |
_DBG_ERROR("Can't open %s for writing.\n",fname);
|
|
Packit |
857059 |
return -1;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
err = op_ppath_create_reader(&r);
|
|
Packit |
857059 |
if (err) {
|
|
Packit |
857059 |
_DBG_ERROR( "Failed to access shared memory tables: %s\n",
|
|
Packit |
857059 |
strerror(err));
|
|
Packit |
857059 |
fclose(f);
|
|
Packit |
857059 |
return err;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
fprintf(f,"Shared Table:\n");
|
|
Packit |
857059 |
fprintf(f,"\tABI Version: %u\n", r.shared_table->abi_version);
|
|
Packit |
857059 |
fprintf(f,"\tSubnet Name: %s\n", r.shared_table->subnet_table_name);
|
|
Packit |
857059 |
fprintf(f,"\tSubnet Update Count: %u\n",
|
|
Packit |
857059 |
r.shared_table->subnet_update_count);
|
|
Packit |
857059 |
fprintf(f,"\tPort Name: %s\n", r.shared_table->port_table_name);
|
|
Packit |
857059 |
fprintf(f,"\tPort Update Count: %u\n", r.shared_table->port_update_count);
|
|
Packit |
857059 |
fprintf(f,"\tVFab Name: %s\n", r.shared_table->vfab_table_name);
|
|
Packit |
857059 |
fprintf(f,"\tVFab Update Count: %u\n", r.shared_table->vfab_update_count);
|
|
Packit |
857059 |
fprintf(f,"\tPath Name: %s\n", r.shared_table->path_table_name);
|
|
Packit |
857059 |
fprintf(f,"Path Update Count: %u\n", r.shared_table->path_update_count);
|
|
Packit |
857059 |
|
|
Packit |
857059 |
fprintf(f,"\n\nSubnet Table:\n");
|
|
Packit |
857059 |
fprintf(f,"\tSubnet Size: %u\n", r.subnet_table->subnet_size);
|
|
Packit |
857059 |
fprintf(f,"\tSubnet Count: %u\n", r.subnet_table->subnet_count);
|
|
Packit |
857059 |
fprintf(f,"\tSID Size: %u\n", r.subnet_table->sid_size);
|
|
Packit |
857059 |
fprintf(f,"\tSID Count: %u\n", r.subnet_table->sid_count);
|
|
Packit |
857059 |
for (i = 1; i <= r.subnet_table->subnet_count ; i++) {
|
|
Packit |
857059 |
fprintf(f,"\tSubnet[%u]:\n",i);
|
|
Packit |
857059 |
fprintf(f,"\t\tPrefix: 0x%016lx\n",
|
|
Packit |
857059 |
hton64(r.subnet_table->subnet[i].source_prefix));
|
|
Packit |
857059 |
fprintf(f,"\t\tFirst SID: %u\n",
|
|
Packit |
857059 |
r.subnet_table->subnet[i].first_sid);
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
for (i = 1; i <= r.subnet_table->sid_count ; i++) {
|
|
Packit |
857059 |
fprintf(f,"\tSID[%u]:\n",i);
|
|
Packit |
857059 |
fprintf(f,"\t\tVFab ID: %u\n",r.sid_table[i].vfab_id);
|
|
Packit |
857059 |
fprintf(f,"\t\tLower: 0x%016lx\n",
|
|
Packit |
857059 |
hton64(r.sid_table[i].lower_sid));
|
|
Packit |
857059 |
fprintf(f,"\t\tUpper: 0x%016lx\n",
|
|
Packit |
857059 |
hton64(r.sid_table[i].upper_sid));
|
|
Packit |
857059 |
fprintf(f,"\t\tNext: %u\n",
|
|
Packit |
857059 |
r.sid_table[i].next);
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
fprintf(f,"\n\nPort Table:\n");
|
|
Packit |
857059 |
fprintf(f,"\tSize: %u\n", r.port_table->size);
|
|
Packit |
857059 |
fprintf(f,"\tCount: %u\n", r.port_table->count);
|
|
Packit |
857059 |
for (i = 1; i <= r.port_table->count ; i++) {
|
|
Packit |
857059 |
int j;
|
|
Packit |
857059 |
fprintf(f,"\tPort[%u]: %s/%u\n", i,
|
|
Packit |
857059 |
r.port_table->port[i].hfi_name,
|
|
Packit |
857059 |
r.port_table->port[i].port);
|
|
Packit |
857059 |
fprintf(f,"\t\tSubnet ID: %u\n",
|
|
Packit |
857059 |
r.port_table->port[i].subnet_id);
|
|
Packit |
857059 |
fprintf(f,"\t\tPrefix: 0x%016lx\n",
|
|
Packit |
857059 |
hton64(r.port_table->port[i].source_prefix));
|
|
Packit |
857059 |
fprintf(f,"\t\tGuid: 0x%016lx\n",
|
|
Packit |
857059 |
hton64(r.port_table->port[i].source_guid));
|
|
Packit |
857059 |
fprintf(f,"\t\tBase Lid: 0x%04x\n",
|
|
Packit |
857059 |
r.port_table->port[i].base_lid);
|
|
Packit |
857059 |
fprintf(f,"\t\tLMC: 0x%04x\n",
|
|
Packit |
857059 |
r.port_table->port[i].lmc);
|
|
Packit |
857059 |
fprintf(f,"\t\tPkeys:\n");
|
|
Packit |
857059 |
for (j=0; j<PKEY_TABLE_LENGTH && r.port_table->port[i].pkey[j]!=0; j++)
|
|
Packit |
857059 |
fprintf(f,"\t\t\t0x%04x\n", ntohs(r.port_table->port[i].pkey[j]));
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
fprintf(f,"\n\nVFab Table:\n");
|
|
Packit |
857059 |
fprintf(f,"\tSize: %u\n", r.vfab_table->size);
|
|
Packit |
857059 |
fprintf(f,"\tCount: %u\n", r.vfab_table->count);
|
|
Packit |
857059 |
for (i = 1; i <= r.vfab_table->count ; i++) {
|
|
Packit |
857059 |
int j;
|
|
Packit |
857059 |
fprintf(f,"\tVFab[%u]: %s\n", i,
|
|
Packit |
857059 |
r.vfab_table->vfab[i].vfab_name);
|
|
Packit |
857059 |
fprintf(f,"\t\tPrefix: 0x%16lx\n",
|
|
Packit |
857059 |
hton64(r.vfab_table->vfab[i].source_prefix));
|
|
Packit |
857059 |
fprintf(f,"\t\tPKey: 0x%04x\n",
|
|
Packit |
857059 |
hton16(r.vfab_table->vfab[i].pkey));
|
|
Packit |
857059 |
fprintf(f,"\t\tService Level: 0x%04x\n",
|
|
Packit |
857059 |
hton16(r.vfab_table->vfab[i].sl));
|
|
Packit |
857059 |
|
|
Packit |
857059 |
fprintf(f,"\n\t\tDLID Hash Table:\n");
|
|
Packit |
857059 |
for (j=0;j
|
|
Packit |
857059 |
fprintf(f,"\t\t\tRecord[%u] = %u\n",
|
|
Packit |
857059 |
j,r.vfab_table->vfab[i].first_dlid[j]);
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
fprintf(f,"\n\t\tDGUID Hash Table:\n");
|
|
Packit |
857059 |
for (j=0;j
|
|
Packit |
857059 |
fprintf(f,"\t\t\tRecord[%u] = %u\n",
|
|
Packit |
857059 |
j,r.vfab_table->vfab[i].first_dguid[j]);
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
fprintf(f,"\n\nPath Table\n");
|
|
Packit |
857059 |
fprintf(f,"\tSize: %u\n", r.path_table->size);
|
|
Packit |
857059 |
fprintf(f,"\tCount: %u\n", r.path_table->count);
|
|
Packit |
857059 |
for (i=1; i<= r.path_table->count; i++) {
|
|
Packit |
857059 |
char s[128];
|
|
Packit |
857059 |
sprintf(s,"Record[%u] (%s) Lid->%u, Guid->%u",i,
|
|
Packit |
857059 |
r.path_table->table[i].flags?"Used":"Unused",
|
|
Packit |
857059 |
r.path_table->table[i].next_lid,
|
|
Packit |
857059 |
r.path_table->table[i].next_guid);
|
|
Packit |
857059 |
fprint_path_record(f,s,(op_path_rec_t*)&(r.path_table->table[i].path));
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
op_ppath_close_reader(&r);
|
|
Packit |
857059 |
fclose(f);
|
|
Packit |
857059 |
return 0;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
int main(int argc, char *argv[])
|
|
Packit |
857059 |
{
|
|
Packit |
857059 |
int mode = 's';
|
|
Packit |
857059 |
int i;
|
|
Packit |
857059 |
int n=DEFAULTPASSES;
|
|
Packit |
857059 |
char filename[512];
|
|
Packit |
857059 |
int debug = _DBG_LVL_NOTICE;
|
|
Packit |
857059 |
|
|
Packit |
857059 |
memset(filename, 0, 512);
|
|
Packit |
857059 |
|
|
Packit |
857059 |
do {
|
|
Packit |
857059 |
int c;
|
|
Packit |
857059 |
|
|
Packit |
857059 |
static char *short_options = "sdcf:n:v:";
|
|
Packit |
857059 |
static struct option long_options[] = {
|
|
Packit |
857059 |
{.name = "server",.has_arg = 0,.val = 's'},
|
|
Packit |
857059 |
{.name = "client",.has_arg = 0,.val = 'c'},
|
|
Packit |
857059 |
{.name = "dump",.has_arg = 0,.val = 'd'},
|
|
Packit |
857059 |
{.name = "file",.has_arg = 1,.val = 'f'},
|
|
Packit |
857059 |
{.name = "num",.has_arg = 1,.val = 'n'},
|
|
Packit |
857059 |
{.name = "hfi",.has_arg = 1,.val = 'H'},
|
|
Packit |
857059 |
{.name = "port",.has_arg = 1,.val = 'p'},
|
|
Packit |
857059 |
{.name = "verbose",.has_arg = 1,.val = 'v'},
|
|
Packit |
857059 |
{0}
|
|
Packit |
857059 |
};
|
|
Packit |
857059 |
|
|
Packit |
857059 |
static char *usage[] = {
|
|
Packit |
857059 |
"Server mode: loads the specified file and emulates dsap",
|
|
Packit |
857059 |
"Client mode: loads the specified file and emulates a client",
|
|
Packit |
857059 |
"Dumps the current contents of the discovery tables to the file.",
|
|
Packit |
857059 |
"the file containing the node table (required)",
|
|
Packit |
857059 |
"the number of passes to make",
|
|
Packit |
857059 |
"the default hfi. (Defaults to "HFINAME".)",
|
|
Packit |
857059 |
"the default port. (Defaults to 1.)",
|
|
Packit |
857059 |
"the level of logging to do.",
|
|
Packit |
857059 |
NULL
|
|
Packit |
857059 |
};
|
|
Packit |
857059 |
|
|
Packit |
857059 |
c = getopt_long(argc, argv, short_options, long_options, NULL);
|
|
Packit |
857059 |
if (c == -1)
|
|
Packit |
857059 |
break;
|
|
Packit |
857059 |
|
|
Packit |
857059 |
switch (c) {
|
|
Packit |
857059 |
case 'H':
|
|
Packit |
857059 |
strcpy(hfi_name, optarg);
|
|
Packit |
857059 |
break;
|
|
Packit |
857059 |
case 'p':
|
|
Packit |
857059 |
port_no = strtoul(optarg, NULL, 0);
|
|
Packit |
857059 |
break;
|
|
Packit |
857059 |
case 'n':
|
|
Packit |
857059 |
n = strtoul(optarg,NULL,0);
|
|
Packit |
857059 |
break;
|
|
Packit |
857059 |
case 'c':
|
|
Packit |
857059 |
case 'd':
|
|
Packit |
857059 |
case 's':
|
|
Packit |
857059 |
mode = c;
|
|
Packit |
857059 |
break;
|
|
Packit |
857059 |
case 'v':
|
|
Packit |
857059 |
debug = strtol(optarg,NULL,0);
|
|
Packit |
857059 |
break;
|
|
Packit |
857059 |
case 'f':
|
|
Packit |
857059 |
strncpy(filename, optarg, 511);
|
|
Packit |
857059 |
break;
|
|
Packit |
857059 |
default:
|
|
Packit |
857059 |
i=0;
|
|
Packit |
857059 |
printf( "Usage: %s (options)\n", argv[0]);
|
|
Packit |
857059 |
printf( "Options are:\n");
|
|
Packit |
857059 |
while (long_options[i].name != NULL) {
|
|
Packit |
857059 |
printf( " [--%-8s %s | -%c %s] %s\n",
|
|
Packit |
857059 |
long_options[i].name,
|
|
Packit |
857059 |
(long_options[i].has_arg) ? "<arg>" : "",
|
|
Packit |
857059 |
long_options[i].val,
|
|
Packit |
857059 |
(long_options[i].has_arg) ? "<arg>" : "",
|
|
Packit |
857059 |
usage[i]);
|
|
Packit |
857059 |
i++;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
return -1;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
} while(1);
|
|
Packit |
857059 |
|
|
Packit |
857059 |
op_log_set_level(debug);
|
|
Packit |
857059 |
|
|
Packit |
857059 |
if (filename[0]==0) {
|
|
Packit |
857059 |
_DBG_ERROR("You must provide a filename.\n");
|
|
Packit |
857059 |
return -1;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
signal(SIGINT, my_sig);
|
|
Packit |
857059 |
|
|
Packit |
857059 |
switch (mode) {
|
|
Packit |
857059 |
case 'c':
|
|
Packit |
857059 |
client(filename,n);
|
|
Packit |
857059 |
break;
|
|
Packit |
857059 |
case 's':
|
|
Packit |
857059 |
server(filename,n);
|
|
Packit |
857059 |
break;
|
|
Packit |
857059 |
case 'd':
|
|
Packit |
857059 |
dump(filename);
|
|
Packit |
857059 |
break;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
return 0;
|
|
Packit |
857059 |
}
|