~ubuntu-branches/ubuntu/raring/ibutils/raring-proposed

« back to all changes in this revision

Viewing changes to ibdm/ibdm/ibdm.i

  • Committer: Bazaar Package Importer
  • Author(s): Benoit Mortier
  • Date: 2010-01-11 22:22:00 UTC
  • Revision ID: james.westby@ubuntu.com-20100111222200-53kum2et5nh13rv3
Tags: upstream-1.2-OFED-1.4.2
ImportĀ upstreamĀ versionĀ 1.2-OFED-1.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2004 Mellanox Technologies LTD. All rights reserved.
 
3
 *
 
4
 * This software is available to you under a choice of one of two
 
5
 * licenses.  You may choose to be licensed under the terms of the GNU
 
6
 * General Public License (GPL) Version 2, available from the file
 
7
 * COPYING in the main directory of this source tree, or the
 
8
 * OpenIB.org BSD license below:
 
9
 *
 
10
 *     Redistribution and use in source and binary forms, with or
 
11
 *     without modification, are permitted provided that the following
 
12
 *     conditions are met:
 
13
 *
 
14
 *      - Redistributions of source code must retain the above
 
15
 *        copyright notice, this list of conditions and the following
 
16
 *        disclaimer.
 
17
 *
 
18
 *      - Redistributions in binary form must reproduce the above
 
19
 *        copyright notice, this list of conditions and the following
 
20
 *        disclaimer in the documentation and/or other materials
 
21
 *        provided with the distribution.
 
22
 *
 
23
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
24
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
25
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
26
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 
27
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 
28
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
29
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 
30
 * SOFTWARE.
 
31
 *
 
32
 * $Id$
 
33
 */
 
34
 
 
35
 
 
36
/*
 
37
 * IB Fabric Data Model (and Utilities)
 
38
 *
 
39
 * Data Model Interface File for TCL SWIG
 
40
 *
 
41
 */
 
42
 
 
43
%title "IB Fabric Data Model - TCL Extention"
 
44
 
 
45
%module ibdm
 
46
%{
 
47
#include <stdio.h>
 
48
#include <stdlib.h>
 
49
#include <getopt.h>
 
50
#include <inttypes.h>
 
51
#include <sstream>
 
52
#include "Fabric.h"
 
53
#include "SubnMgt.h"
 
54
#include "CredLoops.h"
 
55
#include "TraceRoute.h"
 
56
#include "TopoMatch.h"
 
57
#include "Congestion.h"
 
58
 
 
59
# if __WORDSIZE == 64
 
60
#  define __PRI64_PREFIX   "l"
 
61
#  define __PRIPTR_PREFIX  "l"
 
62
# else
 
63
#  define __PRI64_PREFIX   "ll"
 
64
#  define __PRIPTR_PREFIX
 
65
# endif
 
66
#ifndef PRIx64
 
67
# define PRIx64         __PRI64_PREFIX "x"
 
68
#endif
 
69
%}
 
70
 
 
71
%{
 
72
  /* GLOBALS */
 
73
  static char ibdm_tcl_error_msg[1024];
 
74
  static int  ibdm_tcl_error;
 
75
  static vector< IBFabric *> ibdm_fabrics;
 
76
  static IBLinkWidth UnknownLinkWidth = IB_UNKNOWN_LINK_WIDTH;
 
77
  static IBLinkSpeed UnknownLinkSpeed = IB_UNKNOWN_LINK_SPEED;
 
78
  static IBLinkWidth DefaultLinkWidth = IB_LINK_WIDTH_4X;
 
79
  static IBLinkSpeed DefaultLinkSpeed = IB_LINK_SPEED_2_5;
 
80
 
 
81
  /*
 
82
          MAPPING IBDM OBJECTS TO TCL and BACK:
 
83
          The idea is that we have specifc rules for naming
 
84
          Node, Port, System and SystemPort for a specific Fabric.
 
85
 
 
86
          All Fabrics are stored by id in a global vector.
 
87
 
 
88
          So the object names will follow:
 
89
          <type>:<fabricIdx>/<name>
 
90
 
 
91
  */
 
92
 
 
93
  /* Given a fabric pointer return its idx (starting w 1) or 0 */
 
94
  int ibdmGetFabricIdxByPtr(IBFabric *p_fabric) {
 
95
         /* go over all fabrics and find it's index: */
 
96
         for (unsigned int i = 0; i < ibdm_fabrics.size(); i++) {
 
97
                if (ibdm_fabrics[i] == p_fabric) {
 
98
                  return(i+1);
 
99
                }
 
100
         }
 
101
         return(0);
 
102
  }
 
103
 
 
104
  /* Given a fabric idx return it's pointer */
 
105
  /* Note the index is 1-N and thus we need to -1 it before access */
 
106
  IBFabric *ibdmGetFabricPtrByIdx(unsigned int idx) {
 
107
         if ((idx > ibdm_fabrics.size()) || (idx < 1)) {
 
108
                return NULL;
 
109
         }
 
110
         return ibdm_fabrics[idx - 1];
 
111
  }
 
112
 
 
113
  /*
 
114
         we provide our own constructor such that all IBFabrics are
 
115
         registered in the global vector;
 
116
  */
 
117
  IBFabric *new_IBFabric(void) {
 
118
         IBFabric *p_fabric = new IBFabric();
 
119
    unsigned int i;
 
120
         if (p_fabric) {
 
121
      /* look for an open index in the vector of fabrics */
 
122
      for (i = 0; i < ibdm_fabrics.size(); i++)
 
123
      {
 
124
        if (ibdm_fabrics[i] == NULL)
 
125
        {
 
126
          ibdm_fabrics[i] = p_fabric;
 
127
          return p_fabric;
 
128
        }
 
129
      }
 
130
      ibdm_fabrics.push_back(p_fabric);
 
131
         }
 
132
         return p_fabric;
 
133
  }
 
134
 
 
135
  /*
 
136
         we provide our own destructor such that the deleted fabric is
 
137
    de-registered from the global fabrics vector
 
138
  */
 
139
  void delete_IBFabric(IBFabric *p_fabric) {
 
140
    int idx = ibdmGetFabricIdxByPtr(p_fabric);
 
141
    if (! idx) {
 
142
      printf("ERROR: Fabric idx:%p does not exist in the global vector!\n",
 
143
             p_fabric);
 
144
    } else {
 
145
      ibdm_fabrics[idx-1] = NULL;
 
146
    }
 
147
    delete p_fabric;
 
148
  }
 
149
 
 
150
  /* Given the Object Pointer and Type provide it's TCL name */
 
151
  int ibdmGetObjTclNameByPtr(Tcl_Obj *objPtr, void *ptr, char *type) {
 
152
         char tclName[128];
 
153
         char name[128];
 
154
         IBFabric *p_fabric;
 
155
         string uiType;
 
156
 
 
157
         if (!strcmp(type, "IBNode *")) {
 
158
                IBNode *p_node = (IBNode *)ptr;
 
159
                p_fabric = p_node->p_fabric;
 
160
                sprintf(name, ":%s", p_node->name.c_str());
 
161
                uiType = "node";
 
162
         } else if (!strcmp(type, "IBPort *")) {
 
163
                IBPort *p_port = (IBPort *)ptr;
 
164
                sprintf(name,":%s/%u", p_port->p_node->name.c_str(), p_port->num);
 
165
                p_fabric = p_port->p_node->p_fabric;
 
166
                uiType = "port";
 
167
         } else if (!strcmp(type, "IBSystem *")) {
 
168
                IBSystem *p_system = (IBSystem *)ptr;
 
169
                sprintf(name, ":%s", p_system->name.c_str());
 
170
                uiType = "system";
 
171
                p_fabric = p_system->p_fabric;
 
172
         } else if (!strcmp(type, "IBSysPort *")) {
 
173
                IBSysPort *p_sysPort = (IBSysPort *)ptr;
 
174
                sprintf(name, ":%s:%s",  p_sysPort->p_system->name.c_str(),
 
175
                                  p_sysPort->name.c_str());
 
176
                uiType = "sysport";
 
177
                p_fabric = p_sysPort->p_system->p_fabric;
 
178
         } else if (!strcmp(type, "IBFabric *")) {
 
179
                p_fabric = (IBFabric *)ptr;
 
180
                uiType = "fabric";
 
181
                name[0] = '\0';
 
182
         } else {
 
183
                sprintf(tclName, "-E- Unrecognized Object Type:%s", type);
 
184
                Tcl_SetStringObj(objPtr, tclName, -1);
 
185
                return TCL_ERROR;
 
186
         }
 
187
 
 
188
         /* get the fabric index */
 
189
         int idx = ibdmGetFabricIdxByPtr(p_fabric);
 
190
         if (idx == 0) {
 
191
                Tcl_SetStringObj(objPtr, "-E- Fail to find fabric by ptr", -1);
 
192
                return TCL_ERROR;
 
193
         }
 
194
 
 
195
         sprintf(tclName, "%s:%u%s", uiType.c_str(), idx, name);
 
196
         Tcl_SetStringObj(objPtr, tclName, -1);
 
197
         return TCL_OK;
 
198
  }
 
199
 
 
200
  /* Given the Object TCL Name Get it's pointer */
 
201
  int ibdmGetObjPtrByTclName(Tcl_Obj *objPtr, void **ptr) {
 
202
         /* we need to parse the name and get the type etc. */
 
203
         char buf[256];
 
204
         char *type, *name=0, *fabIdxStr;
 
205
         char *colonIdx, *slashIdx;
 
206
         int fabricIdx;
 
207
         *ptr = NULL;
 
208
 
 
209
         strcpy(buf, Tcl_GetStringFromObj(objPtr,0));
 
210
 
 
211
         /* the format is always: <type>:<idx>[:<name>] */
 
212
 
 
213
         /* first separate the type */
 
214
         colonIdx = index(buf,':');
 
215
         if (!colonIdx) {
 
216
                printf("-E- Bad formatted (no :) ibdm object:%s\n", buf);
 
217
                return TCL_ERROR;
 
218
         }
 
219
         *colonIdx = '\0';
 
220
 
 
221
         type = buf;
 
222
         fabIdxStr = ++colonIdx;
 
223
 
 
224
         /* now separate the fabric section if tyep is not fabric */
 
225
         if (strcmp(type, "fabric")) {
 
226
                slashIdx = index(fabIdxStr,':');
 
227
                if (!slashIdx) {
 
228
                  printf( "-E- Bad formatted ibdm fabric object:%s\n",
 
229
                                         Tcl_GetStringFromObj(objPtr,0));
 
230
                  return TCL_ERROR;
 
231
                }
 
232
                *slashIdx = '\0';
 
233
                name = ++slashIdx;
 
234
         }
 
235
 
 
236
         /* Ok so now get the fabic pointer */
 
237
         fabricIdx = atoi(fabIdxStr);
 
238
 
 
239
         IBFabric *p_fabric = ibdmGetFabricPtrByIdx(fabricIdx);
 
240
         if (! p_fabric) {
 
241
                *ptr = NULL;
 
242
                return TCL_ERROR;
 
243
         }
 
244
 
 
245
         if (!strcmp(type, "fabric")) {
 
246
                *ptr = p_fabric;
 
247
         } else if (!strcmp(type, "node")) {
 
248
                IBNode *p_node = p_fabric->getNode(string(name));
 
249
                if (! p_node) {
 
250
                  printf("-E- Fail to get node:%s\n", name);
 
251
                  return TCL_ERROR;
 
252
                }
 
253
                *ptr = p_node;
 
254
         } else if (!strcmp(type, "port")) {
 
255
                slashIdx = rindex(name,'/');
 
256
                if (!slashIdx) {
 
257
                  printf("-E- Bad formatted ibdm node object:%s\n",
 
258
                                        Tcl_GetStringFromObj(objPtr,0));
 
259
                  return TCL_ERROR;
 
260
                }
 
261
                *slashIdx = '\0';
 
262
                int portNum = atoi(++slashIdx);
 
263
                IBNode *p_node = p_fabric->getNode(string(name));
 
264
                if (! p_node) {
 
265
                  printf("-E- Fail to get node:%s\n", name);
 
266
                  return TCL_ERROR;
 
267
                }
 
268
                IBPort *p_port = p_node->getPort(portNum);
 
269
                if (! p_port) {
 
270
                  printf("-E- Fail to get node:%s port:%u\n",
 
271
                                         name, portNum);
 
272
                  return TCL_ERROR;
 
273
                }
 
274
                *ptr = p_port;
 
275
         } else if (!strcmp(type, "system")) {
 
276
                IBSystem *p_system = p_fabric->getSystem(string(name));
 
277
                if (! p_system) {
 
278
                  printf("-E- Fail to get system:%s\n", name);
 
279
                  return TCL_ERROR;
 
280
                }
 
281
                *ptr = p_system;
 
282
         } else if (!strcmp(type, "sysport")) {
 
283
                /* the format of system port is:  <type>:<idx>:<sys>:<port> */
 
284
                colonIdx = index(name,':');
 
285
                if (!colonIdx) {
 
286
                  printf("-E- Bad formatted ibdm sysport object:%s\n",
 
287
                                        Tcl_GetStringFromObj(objPtr,0) );
 
288
                  return TCL_ERROR;
 
289
                }
 
290
                *colonIdx = '\0';
 
291
                IBSystem *p_system = p_fabric->getSystem(string(name));
 
292
                if (! p_system) {
 
293
                  printf("-E- Fail to get system:%s\n", name);
 
294
                  return TCL_ERROR;
 
295
                }
 
296
                IBSysPort *p_sysPort = p_system->getSysPort(string(++colonIdx));
 
297
                if (! p_sysPort) {
 
298
                  printf("-E- Fail to get system:%s port:%s\n", name, colonIdx);
 
299
                  return TCL_ERROR;
 
300
                }
 
301
                *ptr = p_sysPort;
 
302
         } else {
 
303
                printf("-E- Unrecognized Object Type:%s\n", type);
 
304
                return TCL_ERROR;
 
305
         }
 
306
         return TCL_OK;
 
307
  }
 
308
 
 
309
  int ibdmReportNonUpDownCa2CaPaths(IBFabric *p_fabric, list_pnode rootNodes) {
 
310
    map_pnode_int nodesRank;
 
311
    if (SubnRankFabricNodesByRootNodes(p_fabric, rootNodes, nodesRank))
 
312
    {
 
313
      printf("-E- fail to rank the fabric by the given root nodes.\n");
 
314
      return(1);
 
315
    }
 
316
    return( SubnReportNonUpDownCa2CaPaths(p_fabric, nodesRank));
 
317
  }
 
318
 
 
319
  int ibdmFatTreeRoute(IBFabric *p_fabric, list_pnode rootNodes) {
 
320
    map_pnode_int nodesRank;
 
321
    if (SubnRankFabricNodesByRootNodes(p_fabric, rootNodes, nodesRank))
 
322
    {
 
323
      printf("-E- fail to rank the fabric by the given root nodes.\n");
 
324
      return(1);
 
325
    }
 
326
    return( SubnMgtFatTreeRoute(p_fabric));
 
327
  }
 
328
 
 
329
  int ibdmCheckFabricMCGrpsForCreditLoopPotential(IBFabric *p_fabric, list_pnode rootNodes) {
 
330
    map_pnode_int nodesRank;
 
331
    if (SubnRankFabricNodesByRootNodes(p_fabric, rootNodes, nodesRank))
 
332
    {
 
333
      printf("-E- fail to rank the fabric by the given root nodes.\n");
 
334
      return(1);
 
335
    }
 
336
    return( SubnMgtCheckFabricMCGrpsForCreditLoopPotential(p_fabric, nodesRank));
 
337
  }
 
338
 
 
339
  int ibdmRankFabricByRoots(IBFabric *p_fabric, list_pnode rootNodes) {
 
340
    map_pnode_int nodesRank;
 
341
    if (SubnRankFabricNodesByRootNodes(p_fabric, rootNodes, nodesRank))
 
342
    {
 
343
      printf("-E- fail to rank the fabric by the given root nodes.\n");
 
344
      return(1);
 
345
    }
 
346
    return(0);
 
347
  }
 
348
 
 
349
%}
 
350
 
 
351
 
 
352
//
 
353
// exception handling wrapper based on the MsgMgr interfaces
 
354
//
 
355
 
 
356
// it assumes we do not send the messages to stderr
 
357
%except(tcl8) {
 
358
  ibdm_tcl_error = 0;
 
359
  $function;
 
360
  if (ibdm_tcl_error) {
 
361
         Tcl_SetStringObj(Tcl_GetObjResult(interp), ibdm_tcl_error_msg, -1);
 
362
         return TCL_ERROR;
 
363
  }
 
364
}
 
365
 
 
366
//
 
367
// TYPE MAPS:
 
368
//
 
369
%include typemaps.i
 
370
 
 
371
// Convert a TCL Object to C++ world.
 
372
%typemap(tcl8,in) IBFabric *, IBNode *, IBSystem *, IBPort *, IBSysPort * {
 
373
 
 
374
  void *ptr;
 
375
  if (ibdmGetObjPtrByTclName($source, &ptr) != TCL_OK) {
 
376
         char err[128];
 
377
         sprintf(err, "-E- fail to find ibdm obj by id:%s",Tcl_GetString($source) );
 
378
         // Tcl_SetStringObj(tcl_result, err, strlen(err));
 
379
         return TCL_ERROR;
 
380
  }
 
381
 
 
382
  $target = ($type)ptr;
 
383
}
 
384
 
 
385
// Convert C++ pointer to TCL
 
386
%typemap(tcl8,out) IBFabric *, IBNode *, IBSystem *, IBPort *, IBSysPort * {
 
387
  if ($source)
 
388
         ibdmGetObjTclNameByPtr($target, $source, "$type");
 
389
}
 
390
 
 
391
%typemap(tcl8,check)  IBFabric *, IBNode *, IBSystem *, IBPort *, IBSysPort * {
 
392
  /* the format is always: <type>:<idx>[:<name>] */
 
393
 
 
394
  // get the type from the given source
 
395
  char buf[128];
 
396
  strcpy(buf, Tcl_GetStringFromObj($source,0));
 
397
  char *colonIdx = index(buf,':');
 
398
  if (!colonIdx) {
 
399
         char err[128];
 
400
         sprintf(err, "-E- Bad formatted ibdm object:%s", buf);
 
401
         Tcl_SetStringObj(tcl_result, err, strlen(err));
 
402
         return TCL_ERROR;
 
403
  }
 
404
  *colonIdx = '\0';
 
405
 
 
406
  if (!strcmp("$basetype", "IBFabric ")) {
 
407
        if (strcmp(buf, "fabric")) {
 
408
         char err[256];
 
409
         sprintf(err, "-E- basetype is $basetype but received obj of type %s", buf);
 
410
         Tcl_SetStringObj(tcl_result, err, strlen(err));
 
411
         return TCL_ERROR;
 
412
        }
 
413
  } else if (!strcmp("$basetype", "IBSystem ")) {
 
414
        if (strcmp(buf, "system")) {
 
415
         char err[256];
 
416
         sprintf(err, "-E- basetype is $basetype but received obj of type %s", buf);
 
417
         Tcl_SetStringObj(tcl_result, err, strlen(err));
 
418
         return TCL_ERROR;
 
419
        }
 
420
  } else if (!strcmp("$basetype", "IBSysPort ")) {
 
421
        if (strcmp(buf, "sysport")) {
 
422
         char err[256];
 
423
         sprintf(err, "-E- basetype is $basetype but received obj of type %s", buf);
 
424
         Tcl_SetStringObj(tcl_result, err, strlen(err));
 
425
         return TCL_ERROR;
 
426
        }
 
427
  } else if (!strcmp("$basetype", "IBNode ")) {
 
428
        if (strcmp(buf, "node")) {
 
429
         char err[256];
 
430
         sprintf(err, "-E- basetype is $basetype but received obj of type %s", buf);
 
431
         Tcl_SetStringObj(tcl_result, err, strlen(err));
 
432
         return TCL_ERROR;
 
433
        }
 
434
  } else if (!strcmp("$basetype", "IBPort ")) {
 
435
        if (strcmp(buf, "port")) {
 
436
         char err[256];
 
437
         sprintf(err, "-E- basetype is $basetype but received obj of type %s", buf);
 
438
         Tcl_SetStringObj(tcl_result, err, strlen(err));
 
439
         return TCL_ERROR;
 
440
        }
 
441
  } else {
 
442
         char err[256];
 
443
         sprintf(err, "-E- basetype '$basetype' is unknown");
 
444
         Tcl_SetStringObj(tcl_result, err, strlen(err));
 
445
         return TCL_ERROR;
 
446
  }
 
447
}
 
448
 
 
449
// representing vec_pport in TCL
 
450
%typemap(tcl8, out) vec_pport * {
 
451
  Tcl_Obj *p_tclObj;
 
452
 
 
453
  for (unsigned int i = 0; i < $source->size(); i++) {
 
454
         IBPort *p_port = (*$source)[i];
 
455
         if (p_port) {
 
456
                p_tclObj = Tcl_NewObj();
 
457
                if (ibdmGetObjTclNameByPtr(p_tclObj, p_port, "IBPort *")
 
458
                         != TCL_OK) {
 
459
                  printf("-E- Fail to map Port Object (a Vector element)\n");
 
460
                } else {
 
461
                  Tcl_AppendElement(interp, Tcl_GetString(p_tclObj));
 
462
                }
 
463
                Tcl_DecrRefCount(p_tclObj);
 
464
         }
 
465
  }
 
466
}
 
467
 
 
468
%typemap(tcl8, out) vec_vec_byte * {
 
469
  for (unsigned int i = 0; i < $source->size(); i++) {
 
470
         Tcl_AppendResult(interp,"{", NULL);
 
471
         for (unsigned int j = 0; j < (*$source)[i].size(); j++) {
 
472
                char buf[32];
 
473
                sprintf(buf,"%u ", (*$source)[i][j]);
 
474
                Tcl_AppendResult(interp, buf, NULL);
 
475
         }
 
476
         Tcl_AppendResult(interp,"} ", NULL);
 
477
  }
 
478
}
 
479
 
 
480
%typemap(tcl8, out) vec_byte * {
 
481
  for (unsigned int i = 0; i < $source->size(); i++) {
 
482
         char buf[32];
 
483
         sprintf(buf,"%u ", (*$source)[i]);
 
484
         Tcl_AppendResult(interp, buf, NULL);
 
485
  }
 
486
}
 
487
 
 
488
// representing map_str_psysport in TCL
 
489
%typemap(tcl8, out) map_str_psysport * {
 
490
  // build a TCL list out of the Objec ID's of the ibdm objects in it.
 
491
  map_str_psysport::const_iterator I = $source->begin();
 
492
  Tcl_Obj *p_tclObj;
 
493
 
 
494
  while (I != $source->end()) {
 
495
         p_tclObj = Tcl_NewObj();
 
496
         if (ibdmGetObjTclNameByPtr(p_tclObj, (*I).second, "IBSysPort *") != TCL_OK) {
 
497
                printf("-E- Fail to map SysPort Object (a Vector element)\n");
 
498
         } else {
 
499
                char buf[128];
 
500
                sprintf(buf, "%s %s", (*I).first.c_str(), Tcl_GetString(p_tclObj));
 
501
                Tcl_AppendElement(interp, buf);
 
502
         }
 
503
         Tcl_DecrRefCount(p_tclObj);
 
504
         I++;
 
505
  }
 
506
}
 
507
 
 
508
// representing map_str_psys in TCL
 
509
%typemap(tcl8, out) map_str_psys * {
 
510
  // build a TCL list out of the Objec ID's of the ibdm objects in it.
 
511
  map_str_psys::const_iterator I = $source->begin();
 
512
  Tcl_Obj *p_tclObj;
 
513
 
 
514
  while (I != $source->end()) {
 
515
         p_tclObj = Tcl_NewObj();
 
516
         if (ibdmGetObjTclNameByPtr(p_tclObj, (*I).second, "IBSystem *") != TCL_OK) {
 
517
                printf("-E- Fail to map System Object (a Vector element)\n");
 
518
         } else {
 
519
                char buf[128];
 
520
                sprintf(buf, "%s %s", (*I).first.c_str(), Tcl_GetString(p_tclObj));
 
521
                Tcl_AppendElement(interp, buf);
 
522
         }
 
523
         Tcl_DecrRefCount(p_tclObj);
 
524
         I++;
 
525
  }
 
526
}
 
527
 
 
528
// representing map_str_pnode in TCL
 
529
%typemap(tcl8, out) map_str_pnode * {
 
530
  // build a TCL list out of the Objec ID's of the ibdm objects in it.
 
531
  map_str_pnode::const_iterator I = $source->begin();
 
532
  Tcl_Obj *p_tclObj;
 
533
 
 
534
  while (I != $source->end()) {
 
535
         p_tclObj = Tcl_NewObj();
 
536
         if (ibdmGetObjTclNameByPtr(p_tclObj, (*I).second, "IBNode *") != TCL_OK) {
 
537
                printf("-E- Fail to map Node Object (a Vector element)\n");
 
538
         } else {
 
539
                char buf[128];
 
540
                sprintf(buf, "%s %s", (*I).first.c_str(), Tcl_GetString(p_tclObj));
 
541
                Tcl_AppendElement(interp, buf);
 
542
         }
 
543
         Tcl_DecrRefCount(p_tclObj);
 
544
         I++;
 
545
  }
 
546
}
 
547
 
 
548
// representing map_guid_pport in TCL
 
549
%typemap(tcl8, out) map_guid_pport * {
 
550
  // build a TCL list out of the Objec ID's of the ibdm objects in it.
 
551
  map_guid_pport::const_iterator I = $source->begin();
 
552
  Tcl_Obj *p_tclObj;
 
553
 
 
554
  while (I != $source->end()) {
 
555
         p_tclObj = Tcl_NewObj();
 
556
         if (ibdmGetObjTclNameByPtr(p_tclObj, (*I).second, "IBPort *") != TCL_OK) {
 
557
                printf("-E- Fail to map Port Object (a guid map element)\n");
 
558
         } else {
 
559
                char buf[128];
 
560
                sprintf(buf, "0x%016" PRIx64 " %s",
 
561
              (*I).first, Tcl_GetString(p_tclObj));
 
562
                Tcl_AppendElement(interp, buf);
 
563
         }
 
564
         Tcl_DecrRefCount(p_tclObj);
 
565
         I++;
 
566
  }
 
567
}
 
568
 
 
569
// representing map_guid_pnode in TCL
 
570
%typemap(tcl8, out) map_guid_pnode * {
 
571
  // build a TCL list out of the Objec ID's of the ibdm objects in it.
 
572
  map_guid_pnode::const_iterator I = $source->begin();
 
573
  Tcl_Obj *p_tclObj;
 
574
 
 
575
  while (I != $source->end()) {
 
576
         p_tclObj = Tcl_NewObj();
 
577
         if (ibdmGetObjTclNameByPtr(p_tclObj, (*I).second, "IBNode *") != TCL_OK) {
 
578
                printf("-E- Fail to map Node Object (a guid map element)\n");
 
579
         } else {
 
580
                char buf[128];
 
581
                sprintf(buf, "0x%016" PRIx64 " %s",
 
582
              (*I).first, Tcl_GetString(p_tclObj));
 
583
                Tcl_AppendElement(interp, buf);
 
584
         }
 
585
         Tcl_DecrRefCount(p_tclObj);
 
586
         I++;
 
587
  }
 
588
}
 
589
 
 
590
// representing map_guid_psystem in TCL
 
591
%typemap(tcl8, out) map_guid_psys * {
 
592
  // build a TCL list out of the Objec ID's of the ibdm objects in it.
 
593
  map_guid_psys::const_iterator I = $source->begin();
 
594
  Tcl_Obj *p_tclObj;
 
595
 
 
596
  while (I != $source->end()) {
 
597
         p_tclObj = Tcl_NewObj();
 
598
         if (ibdmGetObjTclNameByPtr(p_tclObj, (*I).second, "IBSystem *") != TCL_OK) {
 
599
                printf("-E- Fail to map System Object (a guid map element)\n");
 
600
         } else {
 
601
                char buf[128];
 
602
                sprintf(buf, "0x%016" PRIx64 " %s",
 
603
              (*I).first, Tcl_GetString(p_tclObj));
 
604
                Tcl_AppendElement(interp, buf);
 
605
         }
 
606
         Tcl_DecrRefCount(p_tclObj);
 
607
         I++;
 
608
  }
 
609
}
 
610
 
 
611
// cast a Tcl String object to string
 
612
%typemap(tcl8,in) string * {
 
613
  int len;
 
614
  static string $target_tmp;
 
615
  $target_tmp = string(Tcl_GetStringFromObj($source,&len));
 
616
  $target = &$target_tmp;
 
617
}
 
618
 
 
619
// NOTE FOR SOME REASON THE RETURN TYPE IS TAKEN NOT AS A POINTER
 
620
// BUT PASSED AS ONE ?????
 
621
 
 
622
// return a char * from a string:
 
623
%typemap(tcl8,out) string, string * {
 
624
        char ezTmp[1024];
 
625
        strcpy(ezTmp, $source->c_str());
 
626
        Tcl_SetStringObj(tcl_result, ezTmp, strlen(ezTmp));
 
627
}
 
628
%{
 
629
#define new_string string
 
630
%}
 
631
// return a char * from a string that was allocated previously
 
632
// so we need to delete it
 
633
%typemap(tcl8,out) new_string, new_string * {
 
634
        char ezTmp[1024];
 
635
        strcpy(ezTmp, $source->c_str());
 
636
        Tcl_SetStringObj(tcl_result, ezTmp, strlen(ezTmp));
 
637
   delete $source;
 
638
}
 
639
 
 
640
%typemap (tcl8, ignore) char **p_out_str (char *p_c) {
 
641
  $target = &p_c;
 
642
}
 
643
 
 
644
%typemap (tcl8, argout) char **p_out_str {
 
645
  if (*$source) {
 
646
     Tcl_SetStringObj($target,*$source,strlen(*$source));
 
647
      free(*$source);
 
648
  } else {
 
649
     Tcl_SetStringObj($target,"",-1);
 
650
  }
 
651
}
 
652
 
 
653
/*
 
654
  TCL Type Maps for Standard Integer Types
 
655
*/
 
656
 
 
657
%typemap(tcl8,in) uint64_t *(uint64_t temp) {
 
658
  temp = strtoull(Tcl_GetStringFromObj($source,NULL), NULL,16);
 
659
  $target = &temp;
 
660
}
 
661
 
 
662
%typemap(tcl8,out) uint64_t {
 
663
  char buff[20];
 
664
  sprintf(buff, "0x%016" PRIx64, *$source);
 
665
  Tcl_SetStringObj($target,buff,strlen(buff));
 
666
}
 
667
 
 
668
%typemap(tcl8,out) uint64_t * {
 
669
  char buff[20];
 
670
  sprintf(buff, "0x%016" PRIx64, *$source);
 
671
  Tcl_SetStringObj($target,buff,strlen(buff));
 
672
}
 
673
 
 
674
%{
 
675
#define new_uint64_t uint64_t
 
676
%}
 
677
%typemap(tcl8,out) new_uint64_t *, new_uint64_t {
 
678
  char buff[20];
 
679
  /* new_uint64_t tcl8 out */
 
680
  sprintf(buff, "0x%016" PRIx64, *$source);
 
681
  Tcl_SetStringObj($target,buff,strlen(buff));
 
682
  delete $source;
 
683
}
 
684
 
 
685
%typemap(tcl8,in) uint32_t * (uint32_t temp){
 
686
  temp = strtoul(Tcl_GetStringFromObj($source,NULL), NULL, 0);
 
687
  $target = &temp;
 
688
}
 
689
 
 
690
%typemap(tcl8,out) uint32_t * {
 
691
  char buff[20];
 
692
  sprintf(buff, "%u", *$source);
 
693
  Tcl_SetStringObj($target,buff,strlen(buff));
 
694
}
 
695
 
 
696
%typemap(tcl8,in) uint16_t * (uint16_t temp) {
 
697
  temp = strtoul(Tcl_GetStringFromObj($source,NULL), NULL, 0);
 
698
  $target = &temp;
 
699
}
 
700
 
 
701
%typemap(tcl8,out) uint16_t * {
 
702
  char buff[20];
 
703
  sprintf(buff, "%u", *$source);
 
704
  Tcl_SetStringObj($target,buff,strlen(buff));
 
705
}
 
706
 
 
707
%typemap(tcl8,in) uint8_t * (uint8_t temp) {
 
708
  temp = strtoul(Tcl_GetStringFromObj($source,NULL), NULL, 0);
 
709
  $target = &temp;
 
710
}
 
711
 
 
712
%typemap(tcl8,out) uint8_t * {
 
713
  char buff[20];
 
714
  sprintf(buff, "%u", *$source);
 
715
  Tcl_SetStringObj($target,buff,strlen(buff));
 
716
}
 
717
 
 
718
%typemap(tcl8,in) ib_net64_t *(uint64_t temp) {
 
719
  temp = cl_hton64(strtoull(Tcl_GetStringFromObj($source,NULL), NULL, 16));
 
720
  $target = &temp;
 
721
}
 
722
 
 
723
%typemap(tcl8,out) ib_net64_t * {
 
724
  char buff[20];
 
725
  sprintf(buff, "0x%016" PRIx64, cl_ntoh64(*$source));
 
726
  Tcl_SetStringObj($target,buff,strlen(buff));
 
727
}
 
728
 
 
729
%typemap(tcl8,in) ib_net32_t *(ib_net32_t temp) {
 
730
  temp = cl_hton32(strtoul(Tcl_GetStringFromObj($source,NULL), NULL, 0));
 
731
  $target = &temp;
 
732
}
 
733
 
 
734
%typemap(tcl8,out) ib_net32_t * {
 
735
  char buff[20];
 
736
  sprintf(buff, "%u", cl_ntoh32(*$source));
 
737
  Tcl_SetStringObj($target,buff,strlen(buff));
 
738
}
 
739
 
 
740
%typemap(tcl8,in) ib_net16_t * (ib_net16_t temp) {
 
741
  temp = cl_hton16(strtoul(Tcl_GetStringFromObj($source,NULL), NULL, 0));
 
742
  $target = &temp;
 
743
}
 
744
 
 
745
%typemap(tcl8,out) ib_net16_t * {
 
746
  char buff[20];
 
747
  sprintf(buff, "%u", cl_hton16(*$source));
 
748
  Tcl_SetStringObj($target,buff,strlen(buff));
 
749
}
 
750
 
 
751
%typemap(tcl8,argout) uint64_t *OUTPUT {
 
752
  char buff[20];
 
753
  sprintf(buff, "0x%016" PRIx64, *$source);
 
754
  Tcl_SetStringObj($target,buff,strlen(buff));
 
755
}
 
756
 
 
757
%typemap(tcl8,ignore) uint64_t *OUTPUT(uint64_t temp) {
 
758
  $target = &temp;
 
759
}
 
760
 
 
761
 
 
762
%typemap(tcl8,argout) ostringstream & {
 
763
  Tcl_SetStringObj($target, (char*)$source->str().c_str(),
 
764
                   $source->str().size() + 1);
 
765
}
 
766
 
 
767
%typemap(tcl8,ignore) ostringstream &(ostringstream tempStream) {
 
768
  $target = &tempStream;
 
769
}
 
770
 
 
771
%typemap(tcl8,out) boolean_t * {
 
772
  if (*$source) {
 
773
         Tcl_SetStringObj($target,"TRUE", 4);
 
774
  } else {
 
775
         Tcl_SetStringObj($target,"FALSE", 5);
 
776
  }
 
777
}
 
778
 
 
779
%typemap(tcl8,in) boolean_t *(boolean_t temp) {
 
780
  if (strcmp(Tcl_GetStringFromObj($source,NULL), "TRUE")) {
 
781
         temp = FALSE;
 
782
  } else {
 
783
         temp = TRUE;
 
784
  }
 
785
  $target = &temp;
 
786
}
 
787
 
 
788
%typemap(tcl8,out) IBLinkWidth * {
 
789
  Tcl_SetStringObj($target,width2char(*$source), -1);
 
790
}
 
791
 
 
792
%typemap(tcl8,in) IBLinkWidth * (IBLinkWidth temp1) {
 
793
  temp1 = char2width(Tcl_GetStringFromObj($source,NULL));
 
794
  $target = &temp1;
 
795
}
 
796
 
 
797
%typemap(tcl8,out) IBLinkSpeed * {
 
798
  Tcl_SetStringObj($target,speed2char(*$source), -1);
 
799
}
 
800
 
 
801
%typemap(tcl8,in) IBLinkSpeed * (IBLinkSpeed temp2) {
 
802
  temp2 = char2speed(Tcl_GetStringFromObj($source,NULL));
 
803
  $target = &temp2;
 
804
}
 
805
%include typemaps.i
 
806
 
 
807
%typemap(tcl8,out) list_pnode *,  list_pnode {
 
808
  // build a TCL list out of the Objec ID's of the ibdm objects in it.
 
809
  list_pnode::const_iterator I = $source->begin();
 
810
  Tcl_Obj *p_tclObj;
 
811
 
 
812
  while (I != $source->end()) {
 
813
         p_tclObj = Tcl_NewObj();
 
814
         if (ibdmGetObjTclNameByPtr(p_tclObj, (*I), "IBNode *") != TCL_OK) {
 
815
                printf("-E- Fail to map Node Object (a guid map element)\n");
 
816
         } else {
 
817
                char buf[128];
 
818
                sprintf(buf, "%s", Tcl_GetString(p_tclObj));
 
819
                Tcl_AppendElement(interp, buf);
 
820
         }
 
821
         Tcl_DecrRefCount(p_tclObj);
 
822
         I++;
 
823
  }
 
824
}
 
825
 
 
826
// given a list of node names - generate the list of nodes
 
827
%typemap(tcl8,in) list_pnode * (list_pnode tmpNodeList) {
 
828
#if TCL_MINOR_VERSION > 3
 
829
  const char **sub_lists;
 
830
#else
 
831
  char **sub_lists;
 
832
#endif
 
833
  int num_sub_lists;
 
834
  int idx;
 
835
 
 
836
  /* we will use the TCL split list to split into elements */
 
837
  if (Tcl_SplitList(interp,
 
838
                    Tcl_GetStringFromObj($source,0),
 
839
                    &num_sub_lists, &sub_lists) != TCL_OK) {
 
840
    printf("-E- Bad formatted list :%s\n",
 
841
           Tcl_GetStringFromObj($source,0));
 
842
    return TCL_ERROR;
 
843
  }
 
844
 
 
845
  for (idx = 0; (idx < num_sub_lists); idx++)
 
846
  {
 
847
    /* we need to double copy since TCL 8.4 requires split res to be const */
 
848
    Tcl_Obj *p_tclObj;
 
849
    void *ptr;
 
850
    char buf[128];
 
851
    strcpy(buf, sub_lists[idx]);
 
852
 
 
853
    if (strncmp("node:", buf, 5)) {
 
854
      printf("-E- Bad formatted node (%u) object:%s\n", idx, buf);
 
855
      return TCL_ERROR;
 
856
    }
 
857
 
 
858
         p_tclObj = Tcl_NewObj();
 
859
    Tcl_SetStringObj(p_tclObj, buf, -1);
 
860
    if (ibdmGetObjPtrByTclName(p_tclObj, &ptr) != TCL_OK) {
 
861
      printf("-E- fail to find ibdm obj by id:%s", buf );
 
862
      Tcl_DecrRefCount(p_tclObj);
 
863
      return TCL_ERROR;
 
864
    }
 
865
    Tcl_DecrRefCount(p_tclObj);
 
866
    tmpNodeList.push_back((IBNode *)ptr);
 
867
  }
 
868
 
 
869
  $target = &tmpNodeList;
 
870
}
 
871
 
 
872
//
 
873
// INTERFACE DEFINITION (~copy of h file)
 
874
//
 
875
 
 
876
%section "IBDM Constants"
 
877
/* These constants are provided by IBDM: */
 
878
 
 
879
typedef enum {IB_UNKNOWN_NODE_TYPE, IB_SW_NODE, IB_CA_NODE} IBNodeType;
 
880
/* Node Types */
 
881
 
 
882
%subsection "Log Verbosity Flags",before,pre
 
883
/* To be or'ed and used as the value of FabricUtilsVerboseLevel */
 
884
%readonly
 
885
#define FABU_LOG_NONE    0x0
 
886
#define FABU_LOG_ERROR   0x1
 
887
#define FABU_LOG_INFO    0x2
 
888
#define FABU_LOG_VERBOSE 0x4
 
889
%readwrite
 
890
 
 
891
%section "IBDM Globals"
 
892
int FabricUtilsVerboseLevel;
 
893
/* Log level: set to FABU_LOG* values  */
 
894
 
 
895
int ibdmUseInternalLog();
 
896
/* instruct ibdm to use intrernal buffer for log */
 
897
int ibdmUseCoutLog();
 
898
/* use stdout for log */
 
899
%new char *ibdmGetAndClearInternalLog();
 
900
/* obtain log messages from internal log and clear it */
 
901
 
 
902
%section "IBDM Objects",pre
 
903
/* This section decribes the various object types exposed by IBDM. */
 
904
%text %{
 
905
 
 
906
  IBDM exposes some of its internal objects. The objects
 
907
  identifiers returned by the various function calls are formatted
 
908
  according to the following rules:
 
909
  Fabric: fabric:<idx>
 
910
  System: system:<fab idx>:<sys name>
 
911
  SysPort: sysport:<fab idx>:<sys name>:<port name>
 
912
  Node: node:<fab idx>:<node name>
 
913
  Port: port:<fab idx>:<node name>/<port num>
 
914
 
 
915
  IBDM Objects are standard Swig-Tcl objects.
 
916
  As such they have two flavors for their usage: Variables, Objects.
 
917
 
 
918
  Variables/Pointers:
 
919
     For each object attribute a "get" and "set" methods are provided.
 
920
          The format of the methods is: <class>_<attribute>_<get|set>.
 
921
     The "set" method is only available for read/write attributes.
 
922
 
 
923
          Example:
 
924
     set nodes [ibdm_get_nodes]
 
925
     set node  [lindex $nodes 0]
 
926
     IBNode_numPorts_get $node
 
927
 
 
928
  Objects:
 
929
     Given an object pointer one can convert it to a Tcl "Object"
 
930
          using the following command:
 
931
     <class> <obj_name> -this <obj pointer>
 
932
 
 
933
     Once declared the <obj-name> can be used in conjunction to
 
934
     with the standard "configure" and "cget" commands.
 
935
 
 
936
          Example (following the previous one):
 
937
     IBFabric VaTech -this $fabric
 
938
          VaTech cget -NodeByName
 
939
 
 
940
     To delete an object symbol (and enable its mapping to another
 
941
     pointer) use:
 
942
     rename <obj name> ""
 
943
     for example:
 
944
     rename VaTech ""
 
945
%}
 
946
 
 
947
//
 
948
// IB Port class.
 
949
// This is not the "End Node" but the physical port of
 
950
// a node.
 
951
//
 
952
class IBPort {
 
953
 public:
 
954
  IBPort    * p_remotePort; // Port connected on the other side of link
 
955
  IBSysPort * p_sysPort;    // The system port (if any) connected to
 
956
  IBNode    * p_node;       // The node the port is part of.
 
957
  int                         num;            // Physical ports are identified by number.
 
958
  unsigned int     base_lid;       // The base lid assigned to the port.
 
959
  IBLinkWidth     width;          // The link width of the port
 
960
  IBLinkSpeed     speed;          // The link speed of the port
 
961
  unsigned int    counter1;       // a generic value to be used by various algorithms
 
962
 
 
963
  IBPort(IBNode *p_nodePtr, int number);
 
964
  // constructor
 
965
 
 
966
  new_uint64_t guid_get();
 
967
  void guid_set(uint64_t guid);
 
968
 
 
969
  new_string getName();
 
970
 
 
971
  void connect (IBPort *p_otherPort,
 
972
                IBLinkWidth w = DefaultLinkWidth,
 
973
                IBLinkSpeed s = DefaultLinkSpeed);
 
974
  // connect the port to another node port
 
975
 
 
976
  int disconnect();
 
977
  // disconnect the port. Return 0 if successful
 
978
 
 
979
};
 
980
 
 
981
//
 
982
// IB Node class
 
983
//
 
984
class IBNode {
 
985
 public:
 
986
  string                           name;      // Name of the node (instance name of the chip)
 
987
  IBNodeType            type;      // Either a CA or SW
 
988
  uint32_t        devId;     // The device ID of the node
 
989
  uint32_t        revId;     // The device revision Id.
 
990
  uint32_t        vendId;    // The device Vendor ID.
 
991
  string          attributes;// Comma-sep string of arbitrary attributes k=v
 
992
  uint8_t         rank;      // The rank of the node in the tree
 
993
%readonly
 
994
  IBSystem           *p_system; // What system we belong to
 
995
  IBFabric           *p_fabric; // What fabric we belong to.
 
996
  unsigned int     numPorts;  // Number of physical ports
 
997
  vec_pport                Ports;     // Vector of all the ports
 
998
  vec_vec_byte          MinHopsTable; // Table describing minimal hop count through
 
999
                                // each port to each target lid
 
1000
  vec_byte        LFT;          // The LFT of this node (for switches only)
 
1001
%readwrite
 
1002
  // void            *p_appData1;  // Application Private Data #1
 
1003
  // void            *p_appData2;  // Application Private Data #2
 
1004
 
 
1005
  new_uint64_t guid_get();
 
1006
  void guid_set(uint64_t guid);
 
1007
 
 
1008
  IBNode(string n,
 
1009
                        IBFabric *p_fab,
 
1010
                        IBSystem *p_sys,
 
1011
                        IBNodeType t, int np);
 
1012
  // Constractor
 
1013
 
 
1014
  ~IBNode();
 
1015
 
 
1016
  inline IBPort *makePort (unsigned int num);
 
1017
  // create a new port by name if required to
 
1018
 
 
1019
  inline IBPort *getPort(unsigned int num);
 
1020
  // get a port by number num = 1..N:
 
1021
 
 
1022
  void setHops (IBPort *p_port, unsigned int lid, int hops);
 
1023
  // Set the min hop for the given port (* is all) lid pair
 
1024
 
 
1025
  int getHops (IBPort *p_port, unsigned int lid);
 
1026
  // Get the min number of hops defined for the given port or all
 
1027
 
 
1028
  IBPort *getFirstMinHopPort(unsigned int lid);
 
1029
  // Scan the node ports and find the first port
 
1030
  // with min hop to the lid
 
1031
 
 
1032
  void setLFTPortForLid (unsigned int lid, unsigned int portNum);
 
1033
  // Set the Linear Forwarding Table:
 
1034
 
 
1035
  int getLFTPortForLid (unsigned int lid);
 
1036
  // Get the LFT for a given lid
 
1037
 
 
1038
  void repHopTable();
 
1039
  // dump out the min hop table of the node
 
1040
 
 
1041
}; // Class IBNode
 
1042
 
 
1043
//
 
1044
// System Port Class
 
1045
// The System Port is a front pannel entity.
 
1046
//
 
1047
class IBSysPort {
 
1048
 public:
 
1049
  string                           name;              // The front pannel name of the port
 
1050
  IBSysPort     *p_remoteSysPort;  // If connected the other side sys port
 
1051
  IBSystem      *p_system;         // System it benongs to
 
1052
  IBPort           *p_nodePort;       // The node port it connects to.
 
1053
 
 
1054
  IBSysPort(string n, IBSystem *p_sys);
 
1055
  // Constructor
 
1056
 
 
1057
  ~IBSysPort();
 
1058
 
 
1059
  void connect (IBSysPort *p_otherSysPort,
 
1060
                IBLinkWidth width = UnknownLinkWidth,
 
1061
                IBLinkSpeed speed = UnknownLinkSpeed);
 
1062
  // connect two SysPorts
 
1063
 
 
1064
  int disconnect();
 
1065
  // disconnect the SysPort (and ports). Return 0 if successful
 
1066
 
 
1067
};
 
1068
 
 
1069
//
 
1070
// IB System Class
 
1071
// This is normally derived into a system specific class
 
1072
//
 
1073
class IBSystem {
 
1074
 public:
 
1075
  string                           name;       // the "host" name of the system
 
1076
  string                           type;       // what is the type i.e. Cougar, Buffalo etc
 
1077
  IBFabric        *p_fabric;  // fabric belongs to
 
1078
%readonly
 
1079
  map_str_pnode NodeByName;   // Provide the node pointer by its name
 
1080
  map_str_psysport PortByName;// A map provising pointer to the SysPort by name
 
1081
%readwrite
 
1082
 
 
1083
  IBSystem(string n, IBFabric *p_fab, string t);
 
1084
  // Constractor
 
1085
 
 
1086
  ~IBSystem();
 
1087
 
 
1088
  new_uint64_t guid_get();
 
1089
  void guid_set(uint64_t guid);
 
1090
 
 
1091
  IBSysPort *makeSysPort (string pName);
 
1092
  // make sure we got the port defined (so define it if not)
 
1093
 
 
1094
  IBPort *getSysPortNodePortByName (string sysPortName);
 
1095
  // get the node port for the given sys port by name
 
1096
 
 
1097
  IBSysPort *getSysPort(string name);
 
1098
  // Get a Sys Port by name
 
1099
};
 
1100
 
 
1101
//
 
1102
// IB Fabric Class
 
1103
// The entire fabric
 
1104
//
 
1105
class IBFabric {
 
1106
 public:
 
1107
%readonly
 
1108
  map_str_pnode NodeByName;   // Provide the node pointer by its name
 
1109
  map_str_psys  SystemByName; // Provide the system pointer by its name
 
1110
  vec_pport     PortByLid;    // Pointer to the Port by its lid
 
1111
  map_guid_pnode NodeByGuid;   // Provides the node by guid
 
1112
  map_guid_psys  SystemByGuid; // Provides the system by guid
 
1113
  map_guid_pport PortByGuid;   // Provides the port by guid
 
1114
%readwrite
 
1115
  unsigned int  minLid;       // Track min lid used.
 
1116
  unsigned int  maxLid;       // Track max lid used.
 
1117
  unsigned int  lmc;          // LMC value used
 
1118
 
 
1119
  // IBFabric() {maxLid = 0;};
 
1120
 
 
1121
  // we need to have our own destructor to take care of the
 
1122
  // fabrics vector cleanup
 
1123
 
 
1124
  // ~IBFabric();
 
1125
 
 
1126
  IBNode *makeNode (string n,
 
1127
                                                  IBSystem *p_sys,
 
1128
                                                  IBNodeType type,
 
1129
                                                  unsigned int numPorts);
 
1130
  // get the node by its name (create one of does not exist)
 
1131
 
 
1132
  IBNode *getNode (string name);
 
1133
  // get the node by its name
 
1134
 
 
1135
  list_pnode *getNodesByType (IBNodeType type);
 
1136
  // return the list of node pointers matching the required type
 
1137
 
 
1138
  IBSystem *makeGenericSystem (string name);
 
1139
  // crate a new generic system - basically an empty contaner for nodes...
 
1140
 
 
1141
  IBSystem *makeSystem (string name, string type);
 
1142
  // crate a new system - the type must have a registed factory.
 
1143
 
 
1144
  IBSystem *getSystem(string name);
 
1145
  // Get system by name
 
1146
 
 
1147
  IBSystem *getSystemByGuid(uint64_t guid);
 
1148
  // get the system by its guid
 
1149
  IBNode *getNodeByGuid(uint64_t guid);
 
1150
  // get the node by its guid
 
1151
  IBPort *getPortByGuid(uint64_t guid);
 
1152
  // get the port by its guid
 
1153
 
 
1154
  void addCable (string t1, string n1, string p1,
 
1155
                                          string t2, string n2, string p2,
 
1156
                 IBLinkWidth width = DefaultLinkWidth,
 
1157
                 IBLinkSpeed speed = DefaultLinkSpeed
 
1158
                 );
 
1159
 
 
1160
  // Add a cable connection
 
1161
 
 
1162
  int parseCables (string fn);
 
1163
  // Parse the cables file and build the fabric
 
1164
 
 
1165
  int parseTopology (string fn);
 
1166
  // Parse Topology File
 
1167
 
 
1168
  int addLink(string type1, int numPorts1, uint64_t sysGuid1,
 
1169
                                  uint64_t nodeGuid1,  uint64_t portGuid1,
 
1170
                                  int vend1, int devId1, int rev1, string desc1,
 
1171
                                  int hcaIdx1, int lid1, int portNum1,
 
1172
                                  string type2, int numPorts2, uint64_t sysGuid2,
 
1173
                                  uint64_t nodeGuid2,  uint64_t portGuid2,
 
1174
                                  int vend2, int devId2, int rev2, string desc2,
 
1175
                                  int hcaIdx2, int lid2, int portNum2,
 
1176
              IBLinkWidth width = DefaultLinkWidth,
 
1177
              IBLinkSpeed speed = DefaultLinkSpeed);
 
1178
  // Add a link into the fabric - this will create system
 
1179
  // and nodes as required.
 
1180
 
 
1181
  int parseSubnetLinks (string fn);
 
1182
  // Parse the OpenSM subnet.lst file and build the fabric from it.
 
1183
 
 
1184
  int parseFdbFile(string fn);
 
1185
  // Parse OpenSM FDB dump file
 
1186
 
 
1187
  int parseMCFdbFile(string fn);
 
1188
  // Parse an OpenSM MCFDBs file and set the MFT table accordingly
 
1189
 
 
1190
  inline void setLidPort (unsigned int lid, IBPort *p_port);
 
1191
  // set a lid port
 
1192
 
 
1193
  inline IBPort *getPortByLid (unsigned int lid);
 
1194
  // get a port by lid
 
1195
 
 
1196
  int dumpTopology(char *fileName, char *ibnlDir);
 
1197
  // write out a topology file and IBNLs into given directory
 
1198
};
 
1199
 
 
1200
/* we use our own version of the constructor */
 
1201
IBFabric*  new_IBFabric();
 
1202
/* we use our own version of the destructor */
 
1203
void delete_IBFabric(IBFabric *p_fabric);
 
1204
 
 
1205
%section "IBDM Functions",pre
 
1206
/* IBDM functions */
 
1207
%text %{
 
1208
This section provide the details about the functions IBDM exposes.
 
1209
The order follows the expected order in a regular IBDM flow.
 
1210
They all return 0 on succes.
 
1211
%}
 
1212
 
 
1213
%subsection "Subnet Utilities",before,pre
 
1214
%text %{
 
1215
 
 
1216
  Subnet Utilities:
 
1217
 
 
1218
  The file holds a set of utilities to be run on the subnet to mimic OpenSM
 
1219
  initialization and analyze the results:
 
1220
 
 
1221
  Assign Lids: SubnMgtAssignLids
 
1222
  Init min hop tables: SubnMgtCalcMinHopTables
 
1223
  Perform Enhanced LMC aware routing: SubnMgtOsmEnhancedRoute
 
1224
  Perform standard routing: SubnMgtOsmRoute
 
1225
  Perform Fat Tree specialized routing: SubnMgtFatTreeRoute
 
1226
  Verify all CA to CA routes: SubnMgtVerifyAllCaToCaRoutes
 
1227
 
 
1228
%}
 
1229
 
 
1230
%name(ibdmAssignLids)
 
1231
 int SubnMgtAssignLids (IBPort *p_smNodePort, unsigned int lmc = 0);
 
1232
// Assign lids
 
1233
 
 
1234
%name(ibdmCalcMinHopTables)
 
1235
 int SubnMgtCalcMinHopTables (IBFabric *p_fabric);
 
1236
// Calculate the minhop table for the switches
 
1237
 
 
1238
%name(ibdmCalcUpDnMinHopTbls)
 
1239
 int SubnMgtCalcUpDnMinHopTblsByRootNodesRex(IBFabric *p_fabric, char *rootNodesNameRex);
 
1240
// Fill in the FDB tables in a Up Down routing.
 
1241
// Start the tree from the given nodes by regular expression
 
1242
 
 
1243
%name (ibdmOsmRoute)
 
1244
 int SubnMgtOsmRoute(IBFabric *p_fabric);
 
1245
// Fill in the FDB tables in an OpesnSM style routing
 
1246
// which is switch based, uses number of routes per port
 
1247
// profiling and treat LMC assigned lids sequentialy
 
1248
// Rely on running the SubnMgtCalcMinHopTables beforehand
 
1249
 
 
1250
%name(ibdmEnhancedRoute)
 
1251
 int SubnMgtOsmEnhancedRoute(IBFabric *p_fabric);
 
1252
// Fill in the FDB tables in an OpesnSM style routing
 
1253
// which is switch based, uses number of routes per port
 
1254
// profiling and treat LMC assigned lids sequentialy.
 
1255
// Also it will favor runing through a new system or node
 
1256
// on top of the port profile.
 
1257
// Rely on running the SubnMgtCalcMinHopTables beforehand
 
1258
 
 
1259
int ibdmFatTreeRoute(IBFabric *p_fabric, list_pnode rootNodes);
 
1260
// Perform Fat Tree specific routing by assigning a single LID to
 
1261
// each root node port a single LID to route through.
 
1262
 
 
1263
%name(ibdmFatTreeAnalysis) int FatTreeAnalysis(IBFabric *p_fabric);
 
1264
// Performs FatTree structural analysis
 
1265
 
 
1266
%name(ibdmFatTreeRouteByPermutation) int FatTreeRouteByPermutation(IBFabric *p_fabric, char* srcs, char* dsts);
 
1267
// Performs optimal permutation routing in FatTree
 
1268
 
 
1269
%name(ibdmVerifyCAtoCARoutes)
 
1270
 int SubnMgtVerifyAllCaToCaRoutes(IBFabric *p_fabric);
 
1271
// Verify point to point connectivity
 
1272
 
 
1273
%name(ibdmVerifyAllPaths)
 
1274
 int SubnMgtVerifyAllRoutes(IBFabric *p_fabric);
 
1275
// Verify all paths
 
1276
 
 
1277
%name(ibdmAnalyzeLoops)
 
1278
 int CrdLoopAnalyze(IBFabric *p_fabric);
 
1279
// Analyze the Fabric for Credit Loops
 
1280
 
 
1281
%name(ibdmFindSymmetricalTreeRoots)
 
1282
list_pnode SubnMgtFindTreeRootNodes(IBFabric *p_fabric);
 
1283
// Analyze the fabric to find its root nodes assuming it is
 
1284
// a pure tree (keeping all levels in place).
 
1285
 
 
1286
%name(ibdmFindRootNodesByMinHop)
 
1287
list_pnode SubnMgtFindRootNodesByMinHop(IBFabric *p_fabric);
 
1288
// Analyze the fabric to find its root nodes using statistical methods
 
1289
// on the profiles of min hops to CAs
 
1290
 
 
1291
int ibdmRankFabricByRoots(IBFabric *p_fabric, list_pnode rootNodes);
 
1292
// Just rank the fabric according to the given nodes list
 
1293
 
 
1294
int ibdmReportNonUpDownCa2CaPaths(IBFabric *p_fabric, list_pnode rootNodes);
 
1295
// Find any routes that exist in the FDB's from CA to CA and do not adhare to
 
1296
// the up/down rules. Report any crossing of the path. Use the given list fo nodes
 
1297
// as roots of the tree.
 
1298
 
 
1299
%name(ibdmCheckMulticastGroups)
 
1300
int SubnMgtCheckFabricMCGrps(IBFabric *p_fabric);
 
1301
// Check all multicast groups :
 
1302
// 1. all switches holding it are connected
 
1303
// 2. No loops (i.e. a single BFS with no returns).
 
1304
 
 
1305
int ibdmCheckFabricMCGrpsForCreditLoopPotential(
 
1306
  IBFabric *p_fabric, list_pnode rootNodes);
 
1307
// Check all multicast groups do not have credit loop potential
 
1308
 
 
1309
%name(ibdmLinkCoverageAnalysis)
 
1310
int LinkCoverageAnalysis(IBFabric *p_fabric, list_pnode rootNodes);
 
1311
// Provide sets of port pairs to run BW check from in a way that is
 
1312
// full bandwidth. Reide in LinkCover.cpp
 
1313
 
 
1314
%subsection "Tracing Utilities",before,pre
 
1315
 
 
1316
%name(ibdmTraceDRPathRoute)
 
1317
int TraceDRPathRoute (IBPort *p_smNodePort, list_int drPathPortNums);
 
1318
// Trace a direct route from the given SM node port
 
1319
 
 
1320
%name(ibdmTraceRouteByMinHops)
 
1321
int TraceRouteByMinHops (IBFabric *p_fabric,
 
1322
  unsigned int slid , unsigned int dlid);
 
1323
// Trace a route from slid to dlid by Min Hop
 
1324
 
 
1325
%typemap(tcl8,in) list_pnode_arg_name*(list_pnode tmp) {
 
1326
        $target = &tmp;
 
1327
}
 
1328
 
 
1329
%typemap(tcl8,argout) list_pnode_arg_name* {
 
1330
  // build a TCL list out of the Objec ID's of the ibdm objects in it.
 
1331
  list_pnode::const_iterator I = $source->begin();
 
1332
  Tcl_Obj *p_tclObj;
 
1333
  Tcl_SetVar(interp, Tcl_GetString($arg),"",0);
 
1334
  while (I != $source->end()) {
 
1335
         p_tclObj = Tcl_NewObj();
 
1336
         if (ibdmGetObjTclNameByPtr(p_tclObj, (*I), "IBNode *") != TCL_OK) {
 
1337
                printf("-E- Fail to map Node Object (a guid map element)\n");
 
1338
         } else {
 
1339
                char buf[128];
 
1340
                sprintf(buf, "%s", Tcl_GetString(p_tclObj));
 
1341
                Tcl_SetVar(interp, Tcl_GetString($arg), buf,
 
1342
                                          TCL_LIST_ELEMENT|TCL_APPEND_VALUE);
 
1343
         }
 
1344
         Tcl_DecrRefCount(p_tclObj);
 
1345
         I++;
 
1346
  }
 
1347
}
 
1348
%{
 
1349
#define list_pnode_arg_name list_pnode
 
1350
%}
 
1351
 
 
1352
%typemap(tcl8,in) unsigned_int_arg_name*(unsigned int tmp) {
 
1353
        $target = &tmp;
 
1354
}
 
1355
 
 
1356
%typemap(tcl8,argout) unsigned_int_arg_name* {
 
1357
   char buf[16];
 
1358
        sprintf(buf, "%u", tmp);
 
1359
   Tcl_SetVar(interp, Tcl_GetString($arg), buf, 0);
 
1360
}
 
1361
%{
 
1362
#define unsigned_int_arg_name unsigned int
 
1363
%}
 
1364
 
 
1365
%name(ibdmTraceRouteByLFT)
 
1366
int TraceRouteByLFT (IBFabric *p_fabric,
 
1367
                                                        unsigned int slid , unsigned int dlid,
 
1368
                                                        unsigned_int_arg_name *hops,
 
1369
                                                        list_pnode_arg_name *p_nodesList);
 
1370
// Trace a route from slid to dlid by LFT
 
1371
 
 
1372
%subsection "Topology Matching Utilities",before,pre
 
1373
 
 
1374
%apply char **p_out_str {char **p_report_str};
 
1375
 
 
1376
%name(ibdmMatchFabrics)
 
1377
int TopoMatchFabrics(
 
1378
  IBFabric *p_spec_fabric,       // The specification fabric
 
1379
  IBFabric *p_discovered_fabric, // The discovered fabric
 
1380
  char     *anchorNodeName,      // The system to be the anchor point
 
1381
  int       anchorPortNum,       // The port number of the anchor port
 
1382
  uint64_t  anchorPortGuid,      // Discovered Guid of the anchor port
 
1383
  char **p_report_str            // Diagnostic output.
 
1384
  );
 
1385
// Error if fabrics deffer. And provide it as result.
 
1386
 
 
1387
%name(ibdmBuildMergedFabric)
 
1388
int
 
1389
TopoMergeDiscAndSpecFabrics(
 
1390
  IBFabric  *p_spec_fabric,       // The specification fabric
 
1391
  IBFabric  *p_discovered_fabric, // The discovered fabric
 
1392
  IBFabric  *p_merged_fabric);    // Output merged fabric (allocated internaly)
 
1393
// Build a merged fabric from a matched discovered and spec fabrics.
 
1394
// NOTE: you have to run ibdmMatchFabrics before calling this routine.
 
1395
 
 
1396
%subsection "Congestion Analysis Utilities",before,pre
 
1397
 
 
1398
%name(ibdmCongInit) int CongInit(IBFabric *p_fabric);
 
1399
// Initialize a fabric for congestion analysis
 
1400
 
 
1401
%name(ibdmCongCleanup) int CongCleanup(IBFabric *p_fabric);
 
1402
// Cleanup congestion analysis data and free memory
 
1403
 
 
1404
%name(ibdmCongClear) int CongZero(IBFabric *p_fabric);
 
1405
// Clear the congestion analysis path trace. Does not affect max paths
 
1406
 
 
1407
%name(ibdmCongTrace)
 
1408
int CongTrackPath(IBFabric *p_fabric, uint16_t srcLid, uint16_t dstLid);
 
1409
// Trace the path from source to destination tracking the visited links
 
1410
 
 
1411
%name(ibdmCongReport) int CongReport(IBFabric *p_fabric, ostringstream &out);
 
1412
// Report the max path count and histogram
 
1413
 
 
1414
%name(ibdmCongDump) int CongDump(IBFabric *p_fabric, ostringstream &out);
 
1415
// provide detailed dump of the link usage
 
1416
 
 
1417
//
 
1418
// FIX OF SWIG TO SUPPORT NAME ALTERNATE MANGLING
 
1419
//
 
1420
%{
 
1421
#include "swig_alternate_mangling.cpp"
 
1422
%}
 
1423
 
 
1424
///////////////////////////////////////////////////////////////////////////////
 
1425
extern char * ibdmSourceVersion;
 
1426
 
 
1427
//
 
1428
// INIT CODE
 
1429
//
 
1430
%init %{
 
1431
 
 
1432
  /* mixing declarations .... */
 
1433
  {
 
1434
         // Register the objects for alternate mangling
 
1435
    SWIG_AlternateObjMangling["_IBFabric_p"] = &ibdmGetObjTclNameByPtr;
 
1436
    SWIG_AlternateNameToObj  ["_IBFabric_p"] = &ibdmGetObjPtrByTclName;
 
1437
 
 
1438
    SWIG_AlternateObjMangling["_IBSystem_p"] = &ibdmGetObjTclNameByPtr;
 
1439
    SWIG_AlternateNameToObj  ["_IBSystem_p"] = &ibdmGetObjPtrByTclName;
 
1440
 
 
1441
    SWIG_AlternateObjMangling["_IBSysPort_p"] = &ibdmGetObjTclNameByPtr;
 
1442
    SWIG_AlternateNameToObj  ["_IBSysPort_p"] = &ibdmGetObjPtrByTclName;
 
1443
 
 
1444
    SWIG_AlternateObjMangling["_IBNode_p"] = &ibdmGetObjTclNameByPtr;
 
1445
    SWIG_AlternateNameToObj  ["_IBNode_p"] = &ibdmGetObjPtrByTclName;
 
1446
 
 
1447
    SWIG_AlternateObjMangling["_IBPort_p"] = &ibdmGetObjTclNameByPtr;
 
1448
    SWIG_AlternateNameToObj  ["_IBPort_p"] = &ibdmGetObjPtrByTclName;
 
1449
  }
 
1450
 
 
1451
%}