aboutsummaryrefslogtreecommitdiffstats
path: root/src/vty/fsm_vty.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vty/fsm_vty.c')
-rw-r--r--src/vty/fsm_vty.c99
1 files changed, 77 insertions, 22 deletions
diff --git a/src/vty/fsm_vty.c b/src/vty/fsm_vty.c
index 9bde241c..19c35daa 100644
--- a/src/vty/fsm_vty.c
+++ b/src/vty/fsm_vty.c
@@ -14,16 +14,12 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
*/
#include <stdlib.h>
#include <string.h>
-#include "../../config.h"
+#include "config.h"
#include <osmocom/vty/command.h>
#include <osmocom/vty/buffer.h>
@@ -51,62 +47,82 @@ extern struct llist_head osmo_g_fsms;
/*! Print information about a FSM [class] to the given VTY
* \param vty The VTY to which to print
+ * \param[in] prefix prefix to print at start of each line (typically indenting)
* \param[in] fsm The FSM class to print
*/
-void vty_out_fsm(struct vty *vty, struct osmo_fsm *fsm)
+void vty_out_fsm2(struct vty *vty, const char *prefix, struct osmo_fsm *fsm)
{
unsigned int i;
const struct value_string *evt_name;
- vty_out(vty, "FSM Name: '%s', Log Subsys: '%s'%s", fsm->name,
+ vty_out(vty, "%sFSM Name: '%s', Log Subsys: '%s'%s", prefix, fsm->name,
log_category_name(fsm->log_subsys), VTY_NEWLINE);
/* list the events */
if (fsm->event_names) {
for (evt_name = fsm->event_names; evt_name->str != NULL; evt_name++) {
- vty_out(vty, " Event %02u (0x%08x): '%s'%s", evt_name->value,
- (1 << evt_name->value), evt_name->str, VTY_NEWLINE);
+ vty_out(vty, "%s Event %02u (0x%08x): '%s'%s", prefix, evt_name->value,
+ (1U << evt_name->value), evt_name->str, VTY_NEWLINE);
}
} else
- vty_out(vty, " No event names are defined for this FSM! Please fix!%s", VTY_NEWLINE);
+ vty_out(vty, "%s No event names are defined for this FSM! Please fix!%s", prefix, VTY_NEWLINE);
/* list the states */
- vty_out(vty, " Number of States: %u%s", fsm->num_states, VTY_NEWLINE);
+ vty_out(vty, "%s Number of States: %u%s", prefix, fsm->num_states, VTY_NEWLINE);
for (i = 0; i < fsm->num_states; i++) {
const struct osmo_fsm_state *state = &fsm->states[i];
- vty_out(vty, " State %-20s InEvtMask: 0x%08x, OutStateMask: 0x%08x%s",
+ vty_out(vty, "%s State %-20s InEvtMask: 0x%08x, OutStateMask: 0x%08x%s", prefix,
state->name, state->in_event_mask, state->out_state_mask,
VTY_NEWLINE);
}
}
+/*! Print information about a FSM [class] to the given VTY
+ * \param vty The VTY to which to print
+ * \param[in] fsm The FSM class to print
+ */
+void vty_out_fsm(struct vty *vty, struct osmo_fsm *fsm)
+{
+ vty_out_fsm2(vty, "", fsm);
+}
+
/*! Print a FSM instance to the given VTY
* \param vty The VTY to which to print
+ * \param[in] prefix prefix to print at start of each line (typically indenting)
* \param[in] fsmi The FSM instance to print
*/
-void vty_out_fsm_inst(struct vty *vty, struct osmo_fsm_inst *fsmi)
+void vty_out_fsm_inst2(struct vty *vty, const char *prefix, struct osmo_fsm_inst *fsmi)
{
struct osmo_fsm_inst *child;
- vty_out(vty, "FSM Instance Name: '%s', ID: '%s'%s",
+ vty_out(vty, "%sFSM Instance Name: '%s', ID: '%s'%s", prefix,
fsmi->name, fsmi->id, VTY_NEWLINE);
- vty_out(vty, " Log-Level: '%s', State: '%s'%s",
+ vty_out(vty, "%s Log-Level: '%s', State: '%s'%s", prefix,
log_level_str(fsmi->log_level),
osmo_fsm_state_name(fsmi->fsm, fsmi->state),
VTY_NEWLINE);
if (fsmi->T)
- vty_out(vty, " Timer: %u%s", fsmi->T, VTY_NEWLINE);
+ vty_out(vty, "%s Timer: %u%s", prefix, fsmi->T, VTY_NEWLINE);
if (fsmi->proc.parent) {
- vty_out(vty, " Parent: '%s', Term-Event: '%s'%s",
+ vty_out(vty, "%s Parent: '%s', Term-Event: '%s'%s", prefix,
fsmi->proc.parent->name,
osmo_fsm_event_name(fsmi->proc.parent->fsm,
fsmi->proc.parent_term_event),
VTY_NEWLINE);
}
llist_for_each_entry(child, &fsmi->proc.children, proc.child) {
- vty_out(vty, " Child: '%s'%s", child->name, VTY_NEWLINE);
+ vty_out(vty, "%s Child: '%s'%s", prefix, child->name, VTY_NEWLINE);
}
}
+/*! Print a FSM instance to the given VTY
+ * \param vty The VTY to which to print
+ * \param[in] fsmi The FSM instance to print
+ */
+void vty_out_fsm_inst(struct vty *vty, struct osmo_fsm_inst *fsmi)
+{
+ vty_out_fsm_inst2(vty, "", fsmi);
+}
+
#define SH_FSM_STR SHOW_STR "Show information about finite state machines\n"
#define SH_FSMI_STR SHOW_STR "Show information about finite state machine instances\n"
@@ -142,6 +158,44 @@ DEFUN(show_fsm, show_fsm_cmd,
return CMD_SUCCESS;
}
+DEFUN(show_fsm_state_graph, show_fsm_state_graph_cmd,
+ "show fsm-state-graph NAME",
+ SHOW_STR "Generate a state transition graph (using DOT language)\n"
+ "FSM name\n")
+{
+ const struct osmo_fsm *fsm;
+
+ fsm = osmo_fsm_find_by_name(argv[0]);
+ if (!fsm) {
+ vty_out(vty, "Error: FSM with name '%s' doesn't exist!%s",
+ argv[0], VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ vty_out(vty, "digraph \"%s\" {%s", fsm->name, VTY_NEWLINE);
+
+ for (unsigned int i = 0; i < fsm->num_states; i++) {
+ const struct osmo_fsm_state *st = &fsm->states[i];
+
+ vty_out(vty, "\t\"%s\"; # out_state_mask=0x%08x%s",
+ st->name, st->out_state_mask, VTY_NEWLINE);
+
+ for (unsigned int j = 0; j < sizeof(st->out_state_mask) * 8; j++) {
+ if (~st->out_state_mask & (1 << j))
+ continue;
+ vty_out(vty, "\t\"%s\" -> \"%s\";%s",
+ st->name, osmo_fsm_state_name(fsm, j),
+ VTY_NEWLINE);
+ }
+
+ vty_out(vty, "%s", VTY_NEWLINE);
+ }
+
+ vty_out(vty, "}%s", VTY_NEWLINE);
+
+ return CMD_SUCCESS;
+}
+
DEFUN(show_fsm_insts, show_fsm_insts_cmd,
"show fsm-instances all",
SH_FSMI_STR
@@ -196,9 +250,10 @@ void osmo_fsm_vty_add_cmds(void)
if (osmo_fsm_vty_cmds_installed)
return;
- install_element_ve(&show_fsm_cmd);
- install_element_ve(&show_fsms_cmd);
- install_element_ve(&show_fsm_inst_cmd);
- install_element_ve(&show_fsm_insts_cmd);
+ install_lib_element_ve(&show_fsm_cmd);
+ install_lib_element_ve(&show_fsms_cmd);
+ install_lib_element_ve(&show_fsm_state_graph_cmd);
+ install_lib_element_ve(&show_fsm_inst_cmd);
+ install_lib_element_ve(&show_fsm_insts_cmd);
osmo_fsm_vty_cmds_installed = true;
}