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

« back to all changes in this revision

Viewing changes to ibis/src/ibis.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
%title "IBIS Tcl Extension"
 
36
 
 
37
%module ibis
 
38
%{
 
39
#undef panic
 
40
 
 
41
#ifdef __cplusplus
 
42
#  define BEGIN_C_DECLS extern "C" {
 
43
#  define END_C_DECLS   }
 
44
#else /* !__cplusplus */
 
45
#  define BEGIN_C_DECLS
 
46
#  define END_C_DECLS
 
47
#endif /* __cplusplus */
 
48
 
 
49
BEGIN_C_DECLS
 
50
 
 
51
#include <unistd.h>
 
52
#include <stdio.h>
 
53
#include <string.h>
 
54
#include <stdlib.h>
 
55
#include <getopt.h>
 
56
#include <opensm/osm_log.h>
 
57
#include <complib/cl_qmap.h>
 
58
#include <complib/cl_map.h>
 
59
#include <complib/cl_debug.h>
 
60
#include "ibis.h"
 
61
#include "ibcr.h"
 
62
#include "ibpm.h"
 
63
#include "ibvs.h"
 
64
#include "ibbbm.h"
 
65
#include "ibsac.h"
 
66
#include "ibsm.h"
 
67
#include "ibcc.h"
 
68
 
 
69
END_C_DECLS
 
70
 
 
71
#ifndef PRIx64
 
72
#if __WORDSIZE == 64
 
73
#define __PRI64_PREFIX  "l"
 
74
#else
 
75
#define __PRI64_PREFIX  "L"
 
76
#endif
 
77
 
 
78
#define PRId64          __PRI64_PREFIX"d"
 
79
#define PRIo64          __PRI64_PREFIX"o"
 
80
#define PRIu64          __PRI64_PREFIX"u"
 
81
#define PRIx64          __PRI64_PREFIX"x"
 
82
#endif
 
83
 
 
84
/**********************************************************************
 
85
 **********************************************************************/
 
86
boolean_t
 
87
ibisp_is_debug(void)
 
88
{
 
89
#if defined( _DEBUG_ )
 
90
  return TRUE;
 
91
#else
 
92
  return FALSE;
 
93
#endif /* defined( _DEBUG_ ) */
 
94
}
 
95
 
 
96
%}
 
97
 
 
98
//
 
99
// TYPE MAPS:
 
100
//
 
101
%include ibis_typemaps.i
 
102
 
 
103
//
 
104
// exception handling wrapper based on the MsgMgr interfaces
 
105
//
 
106
%{
 
107
 
 
108
  static char ibis_tcl_error_msg[1024];
 
109
  static int  ibis_tcl_error;
 
110
 
 
111
  void ibis_set_tcl_error(char *err) {
 
112
    if (strlen(err) < 1024)
 
113
      strcpy(ibis_tcl_error_msg, err);
 
114
    else
 
115
      strncpy(ibis_tcl_error_msg, err, 1024);
 
116
    ibis_tcl_error = 1;
 
117
  }
 
118
 
 
119
%}
 
120
// it assumes we do not send the messages to stderr
 
121
%except(tcl8) {
 
122
  /* we can check if IBIS was initialized here */
 
123
  if (!IbisObj.initialized)
 
124
  {
 
125
    Tcl_SetStringObj(
 
126
      Tcl_GetObjResult(interp),
 
127
      "ibis was not yet initialized. please use ibis_init and then ibis_set_port before.", -1);
 
128
    return TCL_ERROR;
 
129
  }
 
130
 
 
131
  if (! IbisObj.port_guid)
 
132
  {
 
133
    Tcl_SetStringObj(
 
134
      Tcl_GetObjResult(interp),
 
135
      " ibis was not yet initialized. please use ibis_set_port before.", -1);
 
136
    return TCL_ERROR;
 
137
  }
 
138
 
 
139
  ibis_tcl_error = 0;
 
140
  $function;
 
141
  if (ibis_tcl_error) {
 
142
         Tcl_SetStringObj(Tcl_GetObjResult(interp), ibis_tcl_error_msg, -1);
 
143
         return TCL_ERROR;
 
144
  }
 
145
}
 
146
 
 
147
//
 
148
// IBCR Interfaces and C Code
 
149
//
 
150
%include ibcr.i
 
151
 
 
152
//
 
153
// IBPM Interfaces and C Code
 
154
//
 
155
%include ibpm.i
 
156
 
 
157
//
 
158
// IBVS Interfaces and C Code
 
159
//
 
160
%include ibvs.i
 
161
 
 
162
//
 
163
// IBBBM Interfaces and C Code
 
164
//
 
165
%include ibbbm.i
 
166
 
 
167
//
 
168
// IBSAC Interfaces and C Code
 
169
//
 
170
%include ibsac.i
 
171
 
 
172
//
 
173
// IBSM Interfaces and C Code
 
174
//
 
175
%include ibsm.i
 
176
 
 
177
//
 
178
// IBCC Interfaces and C Code
 
179
//
 
180
%include ibcc.i
 
181
 
 
182
%{
 
183
  /* globals */
 
184
  ibis_t    IbisObj;
 
185
  static ibis_opt_t  *ibis_opt_p;
 
186
  ibis_opt_t IbisOpts;
 
187
 
 
188
  /* initialize the ibis object - is not done during init so we
 
189
     can play with the options ... */
 
190
  int ibis_ui_init(void)
 
191
  {
 
192
    ib_api_status_t status;
 
193
#ifdef OSM_BUILD_OPENIB
 
194
    complib_init();
 
195
#endif
 
196
 
 
197
         status = ibis_init( &IbisOpts, IbisOpts.log_flags );
 
198
         if( status != IB_SUCCESS ) {
 
199
                printf("-E- Error from ibis_init: %s.\n",
 
200
                                 ib_get_err_str( status ));
 
201
                ibis_destroy();
 
202
                exit(1);
 
203
         }
 
204
 
 
205
    status = ibcr_init(p_ibcr_global);
 
206
    if( status != IB_SUCCESS )
 
207
    {
 
208
      printf("-E- fail to init ibcr_init.\n");
 
209
      ibcr_destroy( p_ibcr_global );
 
210
      exit(1);
 
211
    }
 
212
 
 
213
    status = ibpm_init(p_ibpm_global);
 
214
    if( status != IB_SUCCESS )
 
215
    {
 
216
      printf("-E- fail to init ibpm_init.\n");
 
217
      ibpm_destroy( p_ibpm_global );
 
218
      exit(1);
 
219
    }
 
220
 
 
221
    status = ibvs_init(p_ibvs_global);
 
222
    if( status != IB_SUCCESS )
 
223
    {
 
224
      printf("-E- Fail to init ibvs_init.\n");
 
225
      ibvs_destroy( p_ibvs_global );
 
226
      exit(1);
 
227
    }
 
228
 
 
229
    status = ibbbm_init(p_ibbbm_global);
 
230
    if( status != IB_SUCCESS )
 
231
    {
 
232
      printf("-E- Fail to init ibbbm_init.\n");
 
233
      ibbbm_destroy( p_ibbbm_global );
 
234
      exit(1);
 
235
    }
 
236
 
 
237
    status = ibsm_init(gp_ibsm);
 
238
    if( status != IB_SUCCESS )
 
239
    {
 
240
      printf("-E- Fail to init ibsm_init.\n");
 
241
      ibsm_destroy( gp_ibsm );
 
242
      exit(1);
 
243
    }
 
244
 
 
245
    status = ibcc_init(gp_ibcc);
 
246
    if( status != IB_SUCCESS )
 
247
    {
 
248
      printf("-E- Fail to init ibcc_init.\n");
 
249
      ibcc_destroy( gp_ibcc );
 
250
      exit(1);
 
251
    }
 
252
 
 
253
    return 0;
 
254
  }
 
255
 
 
256
  /* destroy the osm object and close the complib.
 
257
     This function is called from by the Tcl_CreateExitHandler - meaning
 
258
     it will be called when calling 'exit' in the osm shell. */
 
259
  void
 
260
    ibis_exit( ClientData clientData ) {
 
261
    ibcr_destroy(p_ibcr_global);
 
262
    ibpm_destroy(p_ibpm_global);
 
263
    ibvs_destroy(p_ibvs_global);
 
264
    ibbbm_destroy(p_ibbbm_global);
 
265
    ibsm_destroy(gp_ibsm);
 
266
    ibcc_destroy(gp_ibcc);
 
267
 
 
268
    ibis_destroy();
 
269
    usleep(100);
 
270
    complib_exit();
 
271
  }
 
272
 
 
273
  int ibis_ui_destroy(void)
 
274
  {
 
275
    ibis_exit(NULL);
 
276
    return TCL_OK;
 
277
  }
 
278
 
 
279
 
 
280
  /* simply return the active port guid ibis is binded to */
 
281
  uint64_t ibis_get_port(void)
 
282
  {
 
283
    return (IbisObj.port_guid);
 
284
  }
 
285
 
 
286
  /* set the port we bind to and initialize sub packages */
 
287
  int ibis_set_port(uint64_t port_guid)
 
288
  {
 
289
    ib_api_status_t status;
 
290
 
 
291
    if (! IbisObj.initialized) {
 
292
      ibis_set_tcl_error("ibis was not initialized! Please use ibis_init before any call to ibis_*");
 
293
      ibis_tcl_error = 1;
 
294
      return 1;
 
295
    }
 
296
 
 
297
    IbisObj.port_guid = port_guid;
 
298
 
 
299
    status = ibcr_bind(p_ibcr_global);
 
300
    if( status != IB_SUCCESS )
 
301
    {
 
302
      printf("-E- Fail to ibcr_bind.\n");
 
303
      ibcr_destroy( p_ibcr_global );
 
304
      exit(1);
 
305
    }
 
306
 
 
307
    status = ibpm_bind(p_ibpm_global);
 
308
    if( status != IB_SUCCESS )
 
309
    {
 
310
      printf("-E- Fail to ibpm_bind.\n");
 
311
      ibpm_destroy( p_ibpm_global );
 
312
      exit(1);
 
313
    }
 
314
 
 
315
    status = ibvs_bind(p_ibvs_global);
 
316
    if( status != IB_SUCCESS )
 
317
    {
 
318
      printf("-E- Fail to ibvs_bind.\n");
 
319
      ibvs_destroy( p_ibvs_global );
 
320
      exit(1);
 
321
    }
 
322
 
 
323
    status = ibbbm_bind(p_ibbbm_global);
 
324
    if( status != IB_SUCCESS )
 
325
    {
 
326
      printf("-E- Fail to ibbbm_bind.\n");
 
327
      ibbbm_destroy( p_ibbbm_global );
 
328
      exit(1);
 
329
    }
 
330
 
 
331
    status = ibsm_bind(gp_ibsm);
 
332
    if( status != IB_SUCCESS )
 
333
    {
 
334
      printf("-E- Fail to ibsm_bind.\n");
 
335
      ibsm_destroy( gp_ibsm );
 
336
      exit(1);
 
337
    }
 
338
 
 
339
    status = ibcc_bind(gp_ibcc);
 
340
    if( status != IB_SUCCESS )
 
341
    {
 
342
      printf("-E- Fail to ibcc_bind.\n");
 
343
      ibcc_destroy( gp_ibcc );
 
344
      exit(1);
 
345
    }
 
346
 
 
347
    if (ibsac_bind(&IbisObj))
 
348
    {
 
349
      printf("-E- Fail to ibsac_bind.\n");
 
350
      exit(1);
 
351
    }
 
352
 
 
353
    return 0;
 
354
  }
 
355
 
 
356
  int ibis_set_verbosity(int level) {
 
357
    if (IbisObj.initialized)
 
358
      osm_log_set_level( &(IbisObj.log), level );
 
359
    else
 
360
      IbisOpts.log_flags = level;
 
361
 
 
362
         return TCL_OK;
 
363
  }
 
364
 
 
365
  int ibis_puts( osm_log_level_t verbosity, char *msg) {
 
366
         osm_log(&(IbisObj.log), verbosity, msg );
 
367
         return TCL_OK;
 
368
  }
 
369
 
 
370
  int ibis_set_transaction_timeout( uint32_t timeout_ms ) {
 
371
         osm_log(&(IbisObj.log),
 
372
                                OSM_LOG_VERBOSE,
 
373
                                " Setting timeout to:%u[msec]\n", timeout_ms);
 
374
         IbisOpts.transaction_timeout = timeout_ms;
 
375
         return TCL_OK;
 
376
  }
 
377
 
 
378
  /* return the list of port guids and their status etc */
 
379
  static int ibis_get_local_ports_info (ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
 
380
    Tcl_Obj * tcl_result;
 
381
         ibis_t *p_ibis = &IbisObj;
 
382
         uint32_t i;
 
383
         ib_api_status_t status;
 
384
         uint32_t num_ports = GUID_ARRAY_SIZE;
 
385
         ib_port_attr_t attr_array[GUID_ARRAY_SIZE];
 
386
         static char res[128];
 
387
         Tcl_Obj *p_obj;
 
388
 
 
389
    if (!IbisObj.initialized)
 
390
    {
 
391
      Tcl_SetStringObj(
 
392
        Tcl_GetObjResult(interp),
 
393
        "ibis was not yet initialized. please use ibis_init before.", -1);
 
394
      return TCL_ERROR;
 
395
    }
 
396
 
 
397
         /* command options */
 
398
    tcl_result = Tcl_GetObjResult(interp);
 
399
 
 
400
    if ((objc < 1) || (objc > 1)) {
 
401
        Tcl_SetStringObj(tcl_result,"Wrong # args. ibis_get_local_ports_info ",-1);
 
402
        return TCL_ERROR;
 
403
    }
 
404
 
 
405
         /*
 
406
                Call the transport layer for a list of local port
 
407
                GUID values.
 
408
         */
 
409
    status = osm_vendor_get_all_port_attr(
 
410
      p_ibis->p_vendor,
 
411
      attr_array,
 
412
      &num_ports );
 
413
    if( status != IB_SUCCESS )
 
414
    {
 
415
      sprintf(ibis_tcl_error_msg,"-E- fail status:%x\n", status);
 
416
      ibis_tcl_error = 1;
 
417
      return( TCL_ERROR );
 
418
    }
 
419
 
 
420
         /*
 
421
                 Go over all ports and build the return  value
 
422
         */
 
423
         for( i = 0; i < num_ports; i++ )
 
424
    {
 
425
 
 
426
      // start with 1 on host channel adapters.
 
427
      sprintf(res, "0x%016" PRIx64 " 0x%04X %s %u",
 
428
              cl_ntoh64( attr_array[i].port_guid ),
 
429
              attr_array[i].lid,
 
430
              ib_get_port_state_str( attr_array[i].link_state ),
 
431
              attr_array[i].port_num
 
432
              );
 
433
 
 
434
      p_obj = Tcl_NewStringObj(res, strlen(res));
 
435
      Tcl_ListObjAppendElement(interp, tcl_result, p_obj);
 
436
    }
 
437
 
 
438
    return TCL_OK;
 
439
  }
 
440
 
 
441
%}
 
442
 
 
443
 
 
444
 
 
445
//
 
446
// INTERFACE DEFINITION (~copy of h file)
 
447
//
 
448
 
 
449
%section "IBIS Constants"
 
450
/* These constants are provided by IBIS: */
 
451
 
 
452
%subsection "Log Verbosity Flags",before,pre
 
453
/* To be or'ed and used as the "level" argument of ibis_set_verbosity */
 
454
%readonly
 
455
#define IBIS_LOG_NONE                      0x00
 
456
#define IBIS_LOG_ERROR                  0x01
 
457
#define IBIS_LOG_INFO                      0x02
 
458
#define IBIS_LOG_VERBOSE                        0x04
 
459
#define IBIS_LOG_DEBUG                  0x08
 
460
#define IBIS_LOG_FUNCS                  0x10
 
461
#define IBIS_LOG_FRAMES                 0x20
 
462
 
 
463
%section "IBIS Execution Flags",before,pre
 
464
/* These flags are updated by IBIS at run time to reflect internal state: */
 
465
 
 
466
%readonly
 
467
 
 
468
%readwrite
 
469
 
 
470
%section "IBIS Functions",pre
 
471
/* IBIS UI functions */
 
472
%text %{
 
473
This section provide the details about the functions IBIS exposes.
 
474
They all return 0 on succes.
 
475
%}
 
476
 
 
477
int ibis_puts( uint8_t verbosity, char *msg);
 
478
/* Append a message to the OpenSM log */
 
479
 
 
480
/* prevent any exceptions on the following */
 
481
%except(tcl8);
 
482
 
 
483
typedef struct _ibis_opt {
 
484
/* IBIS Options:
 
485
   The IBIS options are available through the predefined object: ibis_opts.
 
486
   It can be manipulated using the standard Tcl methods: cget and configure.
 
487
   Examples: ibis_opts cget -force_log_flush
 
488
             ibis_opts configure -force_log_flush TRUE */
 
489
  // uint32_t transaction_timeout;
 
490
  // /* The maximal time for a GetResp to be waited on before retry (100ms). */
 
491
  boolean_t single_thread;
 
492
  /* run single threaded */
 
493
  boolean_t force_log_flush;
 
494
  /* If TRUE - forces flash after each log message (TRUE). */
 
495
  uint8_t log_flags;
 
496
  /* The log levels to be used */
 
497
  char log_file[1024];
 
498
  /* The name of the log file used (read only) */
 
499
  uint64_t sm_key;
 
500
  /* The SM_Key to be used when sending SubnetMgt and SubnetAdmin MADs */
 
501
  uint64_t m_key;
 
502
  /* The M_Key to be used when sending SubnetMgt */
 
503
  uint64_t v_key;
 
504
  /* The Vendor Key to be used when sending Vendor Specific MADs. */
 
505
} ibis_opt_t;
 
506
 
 
507
%name(ibis_init) int ibis_ui_init();
 
508
/* Initialize ibis object */
 
509
int ibis_set_verbosity(int level);
 
510
/* Change the log verbosity */
 
511
int ibis_set_port(uint64_t guid);
 
512
/* Set the port IBIS is attached to and initialize all sub packages */
 
513
new_uint64_t ibis_get_port();
 
514
/* Provide the GUID of the port IBIS is attached to */
 
515
int ibis_set_transaction_timeout(uint32_t timeout_ms);
 
516
/* Set the transaction time out in [msec] */
 
517
%name(ibis_exit) int ibis_ui_destroy();
 
518
/* Exit IBIS. */
 
519
 
 
520
%text %{
 
521
ibis_get_local_ports_info
 
522
   [return list]
 
523
   Return the list of available IB ports with GUID, LID and State.
 
524
%}
 
525
 
 
526
extern char * ibisSourceVersion;
 
527
 
 
528
//
 
529
// INIT CODE
 
530
//
 
531
%init %{
 
532
 
 
533
  /* Make sure that the osmv, complib and ibisp use
 
534
     same modes (debug/free) */
 
535
  if ( osm_is_debug() != cl_is_debug()    ||
 
536
       osm_is_debug() != ibisp_is_debug() ||
 
537
       ibisp_is_debug() != cl_is_debug() )
 
538
  {
 
539
    fprintf(stderr, "-E- OSMV, Complib and Ibis were compiled using different modes\n");
 
540
    fprintf(stderr, "-E- OSMV debug:%d Complib debug:%d IBIS debug:%d \n",
 
541
            osm_is_debug(), cl_is_debug(), ibisp_is_debug() );
 
542
    exit(1);
 
543
  }
 
544
 
 
545
  /* sub block required for declarations .... */
 
546
  {
 
547
    static int notFirstTime = 0;
 
548
 
 
549
    /* we initialize the structs etc only once. */
 
550
    if (0 == notFirstTime++) {
 
551
      Tcl_StaticPackage(interp, "ibis", Ibis_Init, NULL);
 
552
      Tcl_PkgProvide(interp, "ibis", IBIS_VERSION);
 
553
      /* Default Options  */
 
554
      memset(&IbisOpts, 0,sizeof(ibis_opt_t));
 
555
      IbisOpts.transaction_timeout = 4*OSM_DEFAULT_TRANS_TIMEOUT_MILLISEC;
 
556
      IbisOpts.single_thread = TRUE;
 
557
      IbisOpts.force_log_flush = TRUE;
 
558
      IbisOpts.sm_key = 0;
 
559
      IbisOpts.m_key = 0;
 
560
      IbisOpts.v_key = 0;
 
561
      IbisOpts.log_flags = OSM_LOG_ERROR;
 
562
      strcpy(IbisOpts.log_file,"/tmp/ibis.log");
 
563
 
 
564
 
 
565
      /* we want all exists to cleanup */
 
566
      Tcl_CreateExitHandler(ibis_exit, NULL);
 
567
 
 
568
      /* ------------------ IBCR ---------------------- */
 
569
      p_ibcr_global = ibcr_construct();
 
570
 
 
571
      if (p_ibcr_global == NULL) {
 
572
        printf("-E- Error from ibcr_construct.\n");
 
573
        exit(1);
 
574
      }
 
575
 
 
576
      /* ------------------ IBPM ---------------------- */
 
577
      p_ibpm_global = ibpm_construct();
 
578
 
 
579
      if (p_ibpm_global == NULL) {
 
580
        printf("-E- Error from ibpm_construct.\n");
 
581
        exit(1);
 
582
      }
 
583
 
 
584
      /* ------------------ IBVS ---------------------- */
 
585
                p_ibvs_global = ibvs_construct();
 
586
 
 
587
                if (p_ibvs_global == NULL) {
 
588
                        printf("-E- Error from ibvs_construct.\n");
 
589
         exit(1);
 
590
                }
 
591
 
 
592
      /* ------------------ IBBBM ---------------------- */
 
593
                p_ibbbm_global = ibbbm_construct();
 
594
 
 
595
                if (p_ibbbm_global == NULL) {
 
596
                        printf("-E- Error from ibbbm_construct.\n");
 
597
         exit(1);
 
598
                }
 
599
 
 
600
      /* ------------------ IBSM ---------------------- */
 
601
                gp_ibsm = ibsm_construct();
 
602
 
 
603
                if (gp_ibsm == NULL) {
 
604
                        printf("-E- Error from ibsm_construct.\n");
 
605
         exit(1);
 
606
                }
 
607
 
 
608
      /* Initialize global records */
 
609
      memset(&ibsm_node_info_obj, 0, sizeof(ib_node_info_t));
 
610
      memset(&ibsm_port_info_obj, 0, sizeof(ib_port_info_t));
 
611
      memset(&ibsm_switch_info_obj, 0, sizeof(ib_switch_info_t));
 
612
      memset(&ibsm_lft_block_obj, 0, sizeof(ibsm_lft_block_t));
 
613
      memset(&ibsm_mft_block_obj, 0, sizeof(ibsm_mft_block_t));
 
614
      memset(&ibsm_guid_info_obj, 0, sizeof(ib_guid_info_t));
 
615
      memset(&ibsm_pkey_table_obj, 0, sizeof(ib_pkey_table_t));
 
616
      memset(&ibsm_sm_info_obj, 0, sizeof(ib_sm_info_t));
 
617
 
 
618
      /* ------------------ IBCC ---------------------- */
 
619
 
 
620
      gp_ibcc = ibcc_construct();
 
621
 
 
622
      if (gp_ibcc == NULL) {
 
623
          printf("-E- Error from ibcc_construct.\n");
 
624
          exit(1);
 
625
      }
 
626
 
 
627
      /* Initialize global records */
 
628
      memset(&ibcc_class_port_info_obj, 0, sizeof(ib_class_port_info_t));
 
629
      memset(&ibcc_notice_obj, 0, sizeof(ibcc_notice_attr_t));
 
630
      memset(&ibcc_cong_info_obj, 0, sizeof(ib_cong_info_t));
 
631
      memset(&ibcc_cong_key_info_obj, 0, sizeof(ib_cong_key_info_t));
 
632
      memset(&ibcc_ca_cong_log_obj, 0, sizeof(ibcc_ca_cong_log_t));
 
633
      memset(&ibcc_sw_cong_log_obj, 0, sizeof(ibcc_sw_cong_log_t));
 
634
      memset(&ibcc_sw_cong_setting_obj, 0, sizeof(ib_sw_cong_setting_t));
 
635
      memset(&ibcc_sw_port_cong_setting_obj, 0, sizeof(ib_sw_port_cong_setting_t));
 
636
      memset(&ibcc_ca_cong_setting_obj, 0, sizeof(ib_ca_cong_setting_t));
 
637
      memset(&ibcc_table_obj, 0, sizeof(ib_cc_tbl_t));
 
638
      memset(&ibcc_time_stamp_obj, 0, sizeof(ib_time_stamp_t));
 
639
 
 
640
      /* ------------------ IBSAC ---------------------- */
 
641
 
 
642
      /* Initialize global records */
 
643
      memset(&ibsac_node_rec, 0,sizeof(ibsac_node_rec));
 
644
      memset(&ibsac_portinfo_rec, 0,sizeof(ibsac_portinfo_rec));
 
645
      memset(&ibsac_sminfo_rec, 0, sizeof(ib_sminfo_record_t));
 
646
      memset(&ibsac_swinfo_rec, 0, sizeof(ib_switch_info_record_t));
 
647
      memset(&ibsac_link_rec, 0, sizeof(ib_link_record_t));
 
648
      memset(&ibsac_path_rec, 0, sizeof(ib_path_rec_t));
 
649
      memset(&ibsac_lft_rec, 0, sizeof(ib_lft_record_t));
 
650
      memset(&ibsac_mcm_rec, 0, sizeof(ib_member_rec_t));
 
651
 
 
652
      /*
 
653
       * A1 Supported features:
 
654
       *
 
655
       * Query:                Rec/Info Types    Done
 
656
       *
 
657
       * NodeRecord            (nr, ni)           Y
 
658
       * PortInfoRecord        (pir, pi)          Y
 
659
       * SwitchInfoRecord      (swir, swi)        Y
 
660
       * SMInfoRecord          (smir, smi)        Y
 
661
       * PathRecord            (path)             Y
 
662
       * LinkRecord            (link)             Y
 
663
       * LinFwdTblRecord       (lft)              Y
 
664
       * MulticastFwdTblRecord (mftr, mft)        N - Not supported by OSM
 
665
       *
 
666
       * B Supported features:
 
667
       * MCMemberRecord        (mcm)              Y
 
668
       * ClassPortInfo         (cpi)              Y
 
669
       * InformInfo            (info)             Y
 
670
       * ServiceRecord         (svc)              Y
 
671
       * SL2VLTableRecord      (slvr, slvt)       Y
 
672
       * VLArbTableRecord      (vlarb)            Y
 
673
       * PKeyTableRecord       (pkr, pkt)         Y
 
674
       */
 
675
 
 
676
      /* We use alternate SWIG Objects mangling */
 
677
      SWIG_AltMnglInit();
 
678
      SWIG_AltMnglRegTypeToPrefix("_sacNodeInfo_p", "ni");
 
679
      SWIG_AltMnglRegTypeToPrefix("_sacNodeRec_p", "nr");
 
680
      SWIG_AltMnglRegTypeToPrefix("_sacPortInfo_p", "pi");
 
681
      SWIG_AltMnglRegTypeToPrefix("_sacPortRec_p", "pir");
 
682
      SWIG_AltMnglRegTypeToPrefix("_sacSmInfo_p", "smi");
 
683
      SWIG_AltMnglRegTypeToPrefix("_sacSmRec_p", "smir");
 
684
      SWIG_AltMnglRegTypeToPrefix("_sacSwInfo_p", "swi");
 
685
      SWIG_AltMnglRegTypeToPrefix("_sacSwRec_p", "swir");
 
686
      SWIG_AltMnglRegTypeToPrefix("_sacLinkRec_p", "link");
 
687
      SWIG_AltMnglRegTypeToPrefix("_sacPathRec_p", "path");
 
688
      SWIG_AltMnglRegTypeToPrefix("_sacLFTRec_p", "lft");
 
689
      SWIG_AltMnglRegTypeToPrefix("_sacMCMRec_p", "mcm");
 
690
      SWIG_AltMnglRegTypeToPrefix("_sacClassPortInfo_p", "cpi");
 
691
      SWIG_AltMnglRegTypeToPrefix("_sacInformInfo_p", "info");
 
692
      SWIG_AltMnglRegTypeToPrefix("_sacServiceRec_p", "svc");
 
693
      SWIG_AltMnglRegTypeToPrefix("_sacSlVlTbl_p", "slvt");
 
694
      SWIG_AltMnglRegTypeToPrefix("_sacSlVlRec_p", "slvr");
 
695
      SWIG_AltMnglRegTypeToPrefix("_sacVlArbRec_p", "vlarb");
 
696
      SWIG_AltMnglRegTypeToPrefix("_sacPKeyTbl_p", "pkt");
 
697
      SWIG_AltMnglRegTypeToPrefix("_sacPKeyRec_p", "pkr");
 
698
 
 
699
      // register the pre-allocated objects
 
700
      SWIG_AltMnglRegObj("ni",&(ibsac_node_rec.node_info));
 
701
      SWIG_AltMnglRegObj("nr",&(ibsac_node_rec));
 
702
 
 
703
      SWIG_AltMnglRegObj("pi", &(ibsac_portinfo_rec.port_info));
 
704
      SWIG_AltMnglRegObj("pir",&(ibsac_portinfo_rec));
 
705
 
 
706
      SWIG_AltMnglRegObj("smi", &(ibsac_sminfo_rec.sm_info));
 
707
      SWIG_AltMnglRegObj("smir",&(ibsac_sminfo_rec));
 
708
 
 
709
      SWIG_AltMnglRegObj("swi", &(ibsac_swinfo_rec.switch_info));
 
710
      SWIG_AltMnglRegObj("swir",&(ibsac_swinfo_rec));
 
711
 
 
712
      SWIG_AltMnglRegObj("path",&(ibsac_path_rec));
 
713
 
 
714
      SWIG_AltMnglRegObj("link",&(ibsac_link_rec));
 
715
 
 
716
      SWIG_AltMnglRegObj("lft",&(ibsac_lft_rec));
 
717
 
 
718
      SWIG_AltMnglRegObj("mcm",&(ibsac_mcm_rec));
 
719
 
 
720
      SWIG_AltMnglRegObj("cpi",&(ibsac_class_port_info));
 
721
      SWIG_AltMnglRegObj("info",&(ibsac_inform_info));
 
722
      SWIG_AltMnglRegObj("svc",&(ibsac_svc_rec));
 
723
 
 
724
      SWIG_AltMnglRegObj("slvt", &(ibsac_slvl_rec.slvl_tbl));
 
725
      SWIG_AltMnglRegObj("slvr", &(ibsac_slvl_rec));
 
726
 
 
727
      SWIG_AltMnglRegObj("vlarb", &(ibsac_vlarb_rec));
 
728
 
 
729
      SWIG_AltMnglRegObj("pkt", &(ibsac_pkey_rec.pkey_tbl));
 
730
      SWIG_AltMnglRegObj("pkr", &(ibsac_pkey_rec));
 
731
 
 
732
      usleep(1000);
 
733
    }
 
734
 
 
735
    /* we defined this as a native command so declare it in here */
 
736
    Tcl_CreateObjCommand(interp, "ibis_get_local_ports_info",
 
737
                         ibis_get_local_ports_info, NULL, NULL);
 
738
 
 
739
         /* this will declare an object osm_opts */
 
740
         ibis_opt_p = &IbisOpts;
 
741
         Tcl_CreateObjCommand(interp,"ibis_opts", Tclibis_opt_tMethodCmd,
 
742
                                                                         (ClientData)ibis_opt_p, 0);
 
743
 
 
744
    /* add commands for accessing the global query records */
 
745
 
 
746
    /* ------------------ IBSM ---------------------- */
 
747
 
 
748
    Tcl_CreateObjCommand(interp,"smNodeInfoMad",
 
749
                         TclsmNodeInfoMethodCmd,
 
750
                         (ClientData)&ibsm_node_info_obj, 0);
 
751
 
 
752
    Tcl_CreateObjCommand(interp,"smPortInfoMad",
 
753
                         TclsmPortInfoMethodCmd,
 
754
                         (ClientData)&ibsm_port_info_obj, 0);
 
755
 
 
756
    Tcl_CreateObjCommand(interp,"smSwitchInfoMad",
 
757
                         TclsmSwInfoMethodCmd,
 
758
                         (ClientData)&ibsm_switch_info_obj, 0);
 
759
 
 
760
    Tcl_CreateObjCommand(interp,"smLftBlockMad",
 
761
                         TclsmLftBlockMethodCmd,
 
762
                         (ClientData)&ibsm_lft_block_obj, 0);
 
763
 
 
764
    Tcl_CreateObjCommand(interp,"smMftBlockMad",
 
765
                         TclsmMftBlockMethodCmd,
 
766
                         (ClientData)&ibsm_mft_block_obj, 0);
 
767
 
 
768
    Tcl_CreateObjCommand(interp,"smGuidInfoMad",
 
769
                         TclsmGuidInfoMethodCmd,
 
770
                         (ClientData)&ibsm_guid_info_obj, 0);
 
771
 
 
772
    Tcl_CreateObjCommand(interp,"smPkeyTableMad",
 
773
                         TclsmPkeyTableMethodCmd,
 
774
                         (ClientData)&ibsm_pkey_table_obj, 0);
 
775
 
 
776
    Tcl_CreateObjCommand(interp,"smSlVlTableMad",
 
777
                         TclsmSlVlTableMethodCmd,
 
778
                         (ClientData)&ibsm_slvl_table_obj, 0);
 
779
 
 
780
    Tcl_CreateObjCommand(interp,"smVlArbTableMad",
 
781
                         TclsmVlArbTableMethodCmd,
 
782
                         (ClientData)&ibsm_vl_arb_table_obj, 0);
 
783
 
 
784
    Tcl_CreateObjCommand(interp,"smSMInfoMad",
 
785
                         TclsmSMInfoMethodCmd,
 
786
                         (ClientData)&ibsm_sm_info_obj, 0);
 
787
 
 
788
    Tcl_CreateObjCommand(interp,"smNodeDescMad",
 
789
                         TclsmNodeDescMethodCmd,
 
790
                         (ClientData)&ibsm_node_desc_obj, 0);
 
791
 
 
792
    Tcl_CreateObjCommand(interp,"smNoticeMad",
 
793
                         TclsmNoticeMethodCmd,
 
794
                         (ClientData)&ibsm_notice_obj, 0);
 
795
 
 
796
    /* ------------------ IBCC ---------------------- */
 
797
 
 
798
    Tcl_CreateObjCommand(interp,"ccClassPortInfoMad",
 
799
                         TclccClassPortInfoMethodCmd,
 
800
                         (ClientData)&ibcc_class_port_info_obj, 0);
 
801
 
 
802
    Tcl_CreateObjCommand(interp,"ccNoticeMad",
 
803
                         TclccNoticeMethodCmd,
 
804
                         (ClientData)&ibcc_notice_obj, 0);
 
805
 
 
806
    Tcl_CreateObjCommand(interp,"ccCongestionInfoMad",
 
807
                         TclccCongestionInfoMethodCmd,
 
808
                         (ClientData)&ibcc_cong_info_obj, 0);
 
809
 
 
810
    Tcl_CreateObjCommand(interp,"ccCongestionKeyInfoMad",
 
811
                         TclccCongestionKeyInfoMethodCmd,
 
812
                         (ClientData)&ibcc_cong_key_info_obj, 0);
 
813
 
 
814
    Tcl_CreateObjCommand(interp,"ccCACongestionLogMad",
 
815
                         TclccCACongestionLogMethodCmd,
 
816
                         (ClientData)&ibcc_ca_cong_log_obj, 0);
 
817
 
 
818
    Tcl_CreateObjCommand(interp,"ccSWCongestionLogMad",
 
819
                         TclccSWCongestionLogMethodCmd,
 
820
                         (ClientData)&ibcc_sw_cong_log_obj, 0);
 
821
 
 
822
    Tcl_CreateObjCommand(interp,"ccSWCongestionSettingMad",
 
823
                         TclccSWCongestionSettingMethodCmd,
 
824
                         (ClientData)&ibcc_sw_cong_setting_obj, 0);
 
825
 
 
826
    Tcl_CreateObjCommand(interp,"ccSWPortCongestionSettingMad",
 
827
                         TclccSWPortCongestionSettingMethodCmd,
 
828
                         (ClientData)&ibcc_sw_port_cong_setting_obj, 0);
 
829
 
 
830
    Tcl_CreateObjCommand(interp,"ccCACongestionSettingMad",
 
831
                         TclccCACongestionSettingMethodCmd,
 
832
                         (ClientData)&ibcc_ca_cong_setting_obj, 0);
 
833
 
 
834
    Tcl_CreateObjCommand(interp,"ccTableMad",
 
835
                         TclccTableMethodCmd,
 
836
                         (ClientData)&ibcc_table_obj, 0);
 
837
 
 
838
    Tcl_CreateObjCommand(interp,"ccTimeStampMad",
 
839
                         TclccTimeStampMethodCmd,
 
840
                         (ClientData)&ibcc_time_stamp_obj, 0);
 
841
 
 
842
    /* ------------------ IBSAC --------------------- */
 
843
 
 
844
         Tcl_CreateObjCommand(interp,"sacNodeQuery",
 
845
                                                                 TclsacNodeRecMethodCmd,
 
846
                                                                 (ClientData)&ibsac_node_rec, 0);
 
847
 
 
848
         Tcl_CreateObjCommand(interp,"sacPortQuery",
 
849
                                                                 TclsacPortRecMethodCmd,
 
850
                                                                 (ClientData)&ibsac_portinfo_rec, 0);
 
851
 
 
852
         Tcl_CreateObjCommand(interp,"sacSmQuery",
 
853
                                                                 TclsacSmRecMethodCmd,
 
854
                                                                 (ClientData)&ibsac_sminfo_rec, 0);
 
855
 
 
856
         Tcl_CreateObjCommand(interp,"sacSwQuery",
 
857
                                                                 TclsacSwRecMethodCmd,
 
858
                                                                 (ClientData)&ibsac_swinfo_rec, 0);
 
859
 
 
860
         Tcl_CreateObjCommand(interp,"sacLinkQuery",
 
861
                                                                 TclsacLinkRecMethodCmd,
 
862
                                                                 (ClientData)&ibsac_link_rec, 0);
 
863
 
 
864
         Tcl_CreateObjCommand(interp,"sacPathQuery",
 
865
                                                                 TclsacPathRecMethodCmd,
 
866
                                                                 (ClientData)&ibsac_path_rec, 0);
 
867
 
 
868
         Tcl_CreateObjCommand(interp,"sacLFTQuery",
 
869
                                                                 TclsacLFTRecMethodCmd,
 
870
                                                                 (ClientData)&ibsac_lft_rec, 0);
 
871
 
 
872
         Tcl_CreateObjCommand(interp,"sacMCMQuery",
 
873
                                                                 TclsacMCMRecMethodCmd,
 
874
                                                                 (ClientData)&ibsac_mcm_rec, 0);
 
875
 
 
876
         Tcl_CreateObjCommand(interp,"sacClassPortInfoQuery",
 
877
                                                                 TclsacClassPortInfoMethodCmd,
 
878
                                                                 (ClientData)&ibsac_class_port_info, 0);
 
879
 
 
880
         Tcl_CreateObjCommand(interp,"sacInformInfoQuery",
 
881
                                                                 TclsacInformInfoMethodCmd,
 
882
                                                                 (ClientData)&ibsac_inform_info, 0);
 
883
 
 
884
         Tcl_CreateObjCommand(interp,"sacServiceQuery",
 
885
                                                                 TclsacServiceRecMethodCmd,
 
886
                                                                 (ClientData)&ibsac_svc_rec, 0);
 
887
 
 
888
         Tcl_CreateObjCommand(interp,"sacSLVlQuery",
 
889
                                                                 TclsacSlVlRecMethodCmd,
 
890
                                                                 (ClientData)&ibsac_slvl_rec, 0);
 
891
 
 
892
         Tcl_CreateObjCommand(interp,"sacVlArbQuery",
 
893
                                                                 TclsacVlArbRecMethodCmd,
 
894
                                                                 (ClientData)&ibsac_vlarb_rec, 0);
 
895
 
 
896
         Tcl_CreateObjCommand(interp,"sacPKeyQuery",
 
897
                                                                 TclsacPKeyRecMethodCmd,
 
898
                                                                 (ClientData)&ibsac_pkey_rec, 0);
 
899
 
 
900
    /*
 
901
      use an embedded Tcl code for doing init if given command line
 
902
      parameters: -port_num <port num>
 
903
    */
 
904
    Tcl_GlobalEval(
 
905
      interp,
 
906
      "if {[file tail $argv0] == \"ibis\"} {\n"
 
907
      " set _ibis_port_num_arg_idx [lsearch $argv -port_num]\n"
 
908
      " if {$_ibis_port_num_arg_idx >= 0} {\n"
 
909
      "  if {[llength $argv] < $_ibis_port_num_arg_idx + 2} {\n"
 
910
      "    puts {ibis given -port_num with no actual port number argument}\n"
 
911
      "  } else { \n"
 
912
      "    set _ibis_port_num [lindex $argv [expr $_ibis_port_num_arg_idx + 1]]\n"
 
913
      "    set argv [lreplace $argv $_ibis_port_num_arg_idx [expr $_ibis_port_num_arg_idx + 1]]\n"
 
914
      "    ibis_init\n"
 
915
      "    set _ibis_all_ports [ibis_get_local_ports_info]\n"
 
916
      "    set first_port_idx [lsearch -all $_ibis_all_ports [lindex $_ibis_all_ports 0]]\n"
 
917
      "    if {[llength $first_port_idx] > 1} {\n"
 
918
      "      set _ibis_port_info [lindex $_ibis_all_ports $_ibis_port_num]\n"
 
919
      "    } else {\n"
 
920
      "      set _ibis_port_info [lindex $_ibis_all_ports [expr $_ibis_port_num - 1]]\n"
 
921
      "    }\n"
 
922
      "    if {[lindex $_ibis_port_info 2] != \"ACTIVE\"} {\n"
 
923
      "       puts \"Port $_ibis_port_num is not ACTIVE: $_ibis_port_info\"\n"
 
924
      "       exit 1\n"
 
925
      "    } else { \n"
 
926
      "       ibis_set_port [lindex $_ibis_port_info 0]\n"
 
927
      "       puts \"Port set to:[lindex $_ibis_port_info 0]\"\n"
 
928
      "    }\n"
 
929
      "  }\n"
 
930
      " }\n"
 
931
      "}\n");
 
932
  }
 
933
%}
 
934