[openib-general] [RFC] OpenSM Interactive Console

Hal Rosenstock halr at voltaire.com
Tue Oct 18 12:10:31 PDT 2005


Currently, OpenSM does not support an interactive console. There has
been a desire to introduce the ability to change certain parameters (as
well as display things) once OpenSM has started. This patch introduces
the first most basic commands: help and loglevel. I am investgating
adding smpriority to this. The console is invoked by specifying -console
as an option on the opensm command line.

If you have a request for a command you would like in the console, I
would like to compile a list of these. 

Comments ?

-- Hal

Index: include/opensm/osm_subnet.h
===================================================================
--- include/opensm/osm_subnet.h	(revision 3801)
+++ include/opensm/osm_subnet.h	(working copy)
@@ -221,6 +221,7 @@ typedef struct _osm_subn_opt
   char *                   dump_files_dir;
   char *                   log_file;
   boolean_t                accum_log_file;
+  boolean_t                console;
   cl_map_t                 port_prof_ignore_guids;
   boolean_t                port_profile_switch_nodes;
   uint32_t                 max_port_profile;
Index: include/opensm/osm_console.h
===================================================================
--- include/opensm/osm_console.h	(revision 0)
+++ include/opensm/osm_console.h	(revision 0)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2005 Voltaire, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * $Id$
+ */
+
+#ifndef _OSM_CONSOLE_H_
+#define _OSM_CONSOLE_H_
+
+#include <opensm/osm_base.h>
+#include <opensm/osm_subnet.h>
+#include <opensm/osm_opensm.h>
+
+#ifdef __cplusplus
+#  define BEGIN_C_DECLS extern "C" {
+#  define END_C_DECLS   }
+#else /* !__cplusplus */
+#  define BEGIN_C_DECLS
+#  define END_C_DECLS
+#endif /* __cplusplus */
+
+BEGIN_C_DECLS
+
+void osm_console(osm_opensm_t *p_osm);
+
+END_C_DECLS
+
+#endif	/* _OSM_CONSOLE_H_ */

Property changes on: include/opensm/osm_console.h
___________________________________________________________________
Name: svn:keywords
   + Id

Index: opensm/osm_subnet.c
===================================================================
--- opensm/osm_subnet.c	(revision 3801)
+++ opensm/osm_subnet.c	(working copy)
@@ -399,6 +399,7 @@ osm_subn_set_default_opt(
   p_opt->m_key_lease_period = 0;
   p_opt->sweep_interval = OSM_DEFAULT_SWEEP_INTERVAL_SECS;
   p_opt->max_wire_smps = OSM_DEFAULT_SMP_MAX_ON_WIRE;
+  p_opt->console = FALSE;
   p_opt->transaction_timeout = OSM_DEFAULT_TRANS_TIMEOUT_MILLISEC;
   /* by default we will consider waiting for 50x transaction timeout normal */
   p_opt->max_msg_fifo_timeout = 50*OSM_DEFAULT_TRANS_TIMEOUT_MILLISEC;
Index: opensm/osm_console.c
===================================================================
--- opensm/osm_console.c	(revision 0)
+++ opensm/osm_console.c	(revision 0)
@@ -0,0 +1,184 @@
+/*
+ * Copyright (c) 2005 Voltaire, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#  include <config.h>
+#endif /* HAVE_CONFIG_H */
+
+#define _GNU_SOURCE		/* for getline */
+#include "stdio.h"
+#include <opensm/osm_console.h>
+
+#define OSM_COMMAND_LINE_LEN	120
+#define OSM_COMMAND_PROMPT	"$ "
+
+struct command {
+	char *name;
+	void (*help_function)(void);
+	void (*parse_function)(char **p_last, osm_opensm_t *p_osm);
+};
+
+static const struct command console_cmds[];
+
+static inline char *next_token(char **p_last)
+{
+	return strtok_r(NULL, " \t\n", p_last);
+}
+
+static void help_command()
+{
+	int i;
+
+	printf("Supported commands and syntax:\n");
+	printf("help [<command>]\n");
+	/* skip help command */
+	for (i = 1; console_cmds[i].name; i++)
+		console_cmds[i].help_function();
+}
+
+static void help_loglevel()
+{
+	printf("loglevel [<log-level>]\n");
+}
+
+/* more help routines go here */
+
+static void help_parse(char **p_last, osm_opensm_t *p_osm)
+{
+	char *p_cmd;
+	int i, found = 0;
+
+	p_cmd = next_token(p_last);
+	if (!p_cmd)
+		help_command();
+	else {
+		for (i = 1; console_cmds[i].name; i++) {
+			if (!strcmp(p_cmd, console_cmds[i].name)) {
+				found = 1;
+				console_cmds[i].help_function();
+				break;
+			}
+		}
+		if (!found) {
+			printf("Command %s not found\n\n", p_cmd);
+			help_command();
+		}
+	}
+}
+
+static void loglevel_parse(char **p_last, osm_opensm_t *p_osm)
+{
+	char *p_cmd;
+	int level;
+
+	p_cmd = next_token(p_last);
+	if (!p_cmd)
+		printf("Current log level is 0x%x\n", osm_log_get_level(&p_osm->log));
+	else {
+		/* Handle x, 0x, and decimal specification of log level */
+		if (!strncmp(p_cmd, "x", 1)) { 
+			p_cmd++;
+			level = strtoul(p_cmd, NULL, 16); 
+		} else {
+			if (!strncmp(p_cmd, "0x", 2)) {
+				p_cmd += 2;
+				level = strtoul(p_cmd, NULL, 16); 
+			} else
+				level = strtol(p_cmd, NULL, 10);
+		}
+		if ((level >= 0) && (level < 256)) {
+			printf("Setting log level to 0x%x\n", level);
+			osm_log_set_level(&p_osm->log, level);
+		} else
+			printf("Invalid log level 0x%x\n", level);
+	}
+}
+
+/* more parse routines go here */
+
+static const struct command console_cmds[] =
+{
+	{ "help",	&help_command,		&help_parse},
+	{ "loglevel",	&help_loglevel,		&loglevel_parse},	
+	{ NULL,		NULL,			NULL}	/* end of array */
+};
+
+static void parse_cmd_line(char *line, osm_opensm_t *p_osm)
+{
+	char *p_cmd, *p_last;
+	int i, found = 0;
+
+	/* find first token which is the command */
+	p_cmd = strtok_r(line, " \t\n", &p_last);
+	if (p_cmd) {
+		for (i = 0; console_cmds[i].name; i++) {
+			if (!strcmp(p_cmd, console_cmds[i].name)) {
+				found = 1;
+				console_cmds[i].parse_function(&p_last, p_osm);
+				break;
+			}
+		}
+		if (!found) {
+			printf("Command %s not found\n\n", p_cmd);
+			help_command();
+		}
+	} else {
+		printf("Error parsing command line: %s\n", line);
+		return;
+	}
+}
+
+void osm_console(osm_opensm_t *p_osm)
+{
+	char *p_line;
+	ssize_t len;
+	ssize_t n;
+
+	printf("\nOpenSM Console\n\n");
+	while (1) {
+		printf("%s", OSM_COMMAND_PROMPT);
+		p_line = NULL;
+		/* Get input line */
+		n = getline(&p_line, &len, stdin);
+		if (n > 0) {
+			/* Parse and act on input */
+			parse_cmd_line(p_line, p_osm);
+			free(p_line);
+		} else {
+			printf("Input error\n");
+			fflush(stdin);
+		}
+	}
+}
+

Property changes on: opensm/osm_console.c
___________________________________________________________________
Name: svn:keywords
   + Id

Index: opensm/main.c
===================================================================
--- opensm/main.c	(revision 3801)
+++ opensm/main.c	(working copy)
@@ -61,6 +61,7 @@
 #include <complib/cl_debug.h>
 #include <vendor/osm_vendor_api.h>
 #include <opensm/osm_ucast_updn.h>
+#include <opensm/osm_console.h>
 
 /********************************************************************
        D E F I N E    G L O B A L    V A R I A B L E S
@@ -157,6 +158,8 @@ show_usage(void)
           "          SMPs.\n"
           "          Without -maxsmps, OpenSM defaults to a maximum of\n"
           "          one outstanding SMP.\n\n" );
+  printf( "-console\n"
+          "          This option brings up the OpenSM console.\n\n" );
   printf( "-i <equalize-ignore-guids-file>\n"
           "-ignore-guids <equalize-ignore-guids-file>\n"
           "          This option provides the means to define a set of ports\n"
@@ -368,6 +371,7 @@ parse_ignore_guids_file(IN char *guids_f
   uint64_t port_guid;
   ib_api_status_t status = IB_SUCCESS;
   unsigned int  port_num;
+
   OSM_LOG_ENTER( &p_osm->log, parse_ignore_guids_file );
 
   fh = fopen( guids_file_name, "r" );
@@ -474,6 +478,7 @@ main(
       {  "log_file",      1, NULL, 'f'},
       {  "erase_log_file",0, NULL, 'e'},
       {  "maxsmps",       1, NULL, 'n'},
+      {  "console",       1, NULL, 'q'},
       {  "V",             0, NULL, 'V'},
       {  "help",          0, NULL, 'h'},
       {  "once",          0, NULL, 'o'},
@@ -577,6 +582,14 @@ main(
       printf(" Max wire smp's = %d\n", opt.max_wire_smps);
       break;
 
+    case 'q':
+      /*
+       * OpenSM interactive console
+       */
+      opt.console = TRUE;
+      printf(" Enabling OpenSM interactive console\n");
+      break;
+
     case 'd':
       dbg_lvl = strtol(optarg, NULL, 0);
       printf(" d level = 0x%x\n", dbg_lvl);
@@ -796,7 +809,10 @@ main(
       be implemented in this loop.
     */
     while( !osm_exit_flag )
-      cl_thread_suspend( 10000 );
+      if (opt.console)
+        osm_console(&osm);
+      else
+        cl_thread_suspend( 10000 );
   }
 
 #if 0
Index: opensm/Makefile.am
===================================================================
--- opensm/Makefile.am	(revision 3801)
+++ opensm/Makefile.am	(working copy)
@@ -25,8 +25,8 @@ libopensm_la_LDFLAGS = -version-info $(o
 libopensm_la_DEPENDENCIES = $(srcdir)/libopensm.map
 
 bin_PROGRAMS = opensm
-opensm_SOURCES = main.c osm_db_files.c osm_db_pack.c \
-		 osm_drop_mgr.c osm_fwd_tbl.c \
+opensm_SOURCES = main.c osm_console.c osm_db_files.c \
+		 osm_db_pack.c osm_drop_mgr.c osm_fwd_tbl.c \
 		 osm_inform.c osm_lid_mgr.c osm_lin_fwd_rcv.c \
 		 osm_lin_fwd_rcv_ctrl.c osm_lin_fwd_tbl.c osm_link_mgr.c \
 		 osm_matrix.c osm_mcast_fwd_rcv.c osm_mcast_fwd_rcv_ctrl.c \







More information about the general mailing list