VTY: Show single port; Use 'singular' for ports and links

This commit is contained in:
Andreas Eversberg 2023-02-22 20:09:53 +01:00
parent c9f0c33587
commit e70c91fc4a
1 changed files with 90 additions and 38 deletions

View File

@ -78,8 +78,8 @@ DEFUN(show_interface, show_interface_cmd,
return CMD_SUCCESS;
}
DEFUN(show_links, show_links_cmd,
"show links",
DEFUN(show_link, show_link_cmd,
"show link",
SHOW_STR "Show links and states")
{
struct v5x_interface *v5if = get_interface(vty);
@ -127,9 +127,86 @@ DEFUN(show_links, show_links_cmd,
return CMD_SUCCESS;
}
DEFUN(show_ports, show_ports_cmd,
"show ports",
SHOW_STR "Show user ports and states")
static void print_port(struct vty *vty, struct v5x_user_port *v5up)
{
if (v5up->type == V5X_USER_TYPE_PSTN) {
vty_out(vty, "PSTN port nr %d:", v5up->nr);
vty_out(vty, " Port state=%s;", v5x_le_port_pstn_state_name(v5up->port_fi));
vty_out(vty, " PSTN state=%s%s", v5x_le_pstn_state_name(v5up->pstn.proto), VTY_NEWLINE);
if (v5up->ts[0]) {
if (v5up->interface->dialect == V5X_DIALECT_V51)
vty_out(vty, " Channel: TS %d%s", v5up->ts[0]->nr, VTY_NEWLINE);
else
vty_out(vty, " Channel: link %d TS %d%s", v5up->ts[0]->link->id,
v5up->ts[0]->nr, VTY_NEWLINE);
}
} else {
vty_out(vty, "ISDN port nr %d:", v5up->nr);
vty_out(vty, " Port state=%s%s", v5x_le_port_isdn_state_name(v5up->port_fi), VTY_NEWLINE);
if (v5up->ts[0]) {
if (v5up->interface->dialect == V5X_DIALECT_V51)
vty_out(vty, " Channel B1: TS %d%s", v5up->ts[0]->nr, VTY_NEWLINE);
else
vty_out(vty, " Channel B1: link %d TS %d%s", v5up->ts[0]->link->id,
v5up->ts[0]->nr, VTY_NEWLINE);
}
if (v5up->ts[1]) {
if (v5up->interface->dialect == V5X_DIALECT_V51)
vty_out(vty, " Channel B2: TS %d%s", v5up->ts[1]->nr, VTY_NEWLINE);
else
vty_out(vty, " Channel B2: link %d TS %d%s", v5up->ts[1]->link->id,
v5up->ts[1]->nr, VTY_NEWLINE);
}
}
}
#define SHOW_PORT "Show given user port and states\n"
DEFUN(show_port_pstn, show_port_pstn_cmd,
"show port pstn <0-32767>",
SHOW_STR SHOW_PORT "Show given PSTN user port and states\n" "L3 address")
{
struct v5x_interface *v5if = get_interface(vty);
struct v5x_user_port *v5up;
if (!v5if)
return CMD_WARNING;
v5up = v5x_user_port_find(v5if, atoi(argv[0]), false);
if (!v5up) {
vty_out(vty, "%%Given PSTN user port does not exist.%s", VTY_NEWLINE);
return CMD_WARNING;
}
print_port(vty, v5up);
return CMD_SUCCESS;
}
DEFUN(show_port_isdn, show_port_isdn_cmd,
"show port isdn <0-8175>",
SHOW_STR SHOW_PORT "Show given ISDN user port and states\n" "L3 address")
{
struct v5x_interface *v5if = get_interface(vty);
struct v5x_user_port *v5up;
if (!v5if)
return CMD_WARNING;
v5up = v5x_user_port_find(v5if, atoi(argv[0]), true);
if (!v5up) {
vty_out(vty, "%%Given ISDN user port does not exist.%s", VTY_NEWLINE);
return CMD_WARNING;
}
print_port(vty, v5up);
return CMD_SUCCESS;
}
DEFUN(show_port, show_port_cmd,
"show port",
SHOW_STR "Show all user ports and states")
{
struct v5x_interface *v5if = get_interface(vty);
struct v5x_user_port *v5up;
@ -141,37 +218,10 @@ DEFUN(show_ports, show_ports_cmd,
vty_out(vty, "%%No user ports created!%s", VTY_NEWLINE);
return CMD_WARNING;
}
llist_for_each_entry(v5up, &v5if->user_ports, list) {
if (v5up->type == V5X_USER_TYPE_PSTN) {
vty_out(vty, "PSTN port nr %d:", v5up->nr);
vty_out(vty, " Port state=%s", v5x_le_port_pstn_state_name(v5up->port_fi));
vty_out(vty, " PSTN state=%s%s", v5x_le_pstn_state_name(v5up->pstn.proto), VTY_NEWLINE);
if (v5up->ts[0]) {
if (v5if->dialect == V5X_DIALECT_V51)
vty_out(vty, " Channel: TS %d%s", v5up->ts[0]->nr, VTY_NEWLINE);
else
vty_out(vty, " Channel: link %d TS %d%s", v5up->ts[0]->link->id,
v5up->ts[0]->nr, VTY_NEWLINE);
}
} else {
vty_out(vty, "ISDN port nr %d:", v5up->nr);
vty_out(vty, " Port state=%s%s", v5x_le_port_isdn_state_name(v5up->port_fi), VTY_NEWLINE);
if (v5up->ts[0]) {
if (v5if->dialect == V5X_DIALECT_V51)
vty_out(vty, " Channel B1: TS %d%s", v5up->ts[0]->nr, VTY_NEWLINE);
else
vty_out(vty, " Channel B1: link %d TS %d%s", v5up->ts[0]->link->id,
v5up->ts[0]->nr, VTY_NEWLINE);
}
if (v5up->ts[1]) {
if (v5if->dialect == V5X_DIALECT_V51)
vty_out(vty, " Channel B2: TS %d%s", v5up->ts[1]->nr, VTY_NEWLINE);
else
vty_out(vty, " Channel B2: link %d TS %d%s", v5up->ts[1]->link->id,
v5up->ts[1]->nr, VTY_NEWLINE);
}
}
}
llist_for_each_entry(v5up, &v5if->user_ports, list)
print_port(vty, v5up);
return CMD_SUCCESS;
}
@ -797,8 +847,10 @@ static int config_write_interface_v52(struct vty *vty)
int v5le_vty_init(void)
{
install_element_ve(&show_interface_cmd);
install_element_ve(&show_links_cmd);
install_element_ve(&show_ports_cmd);
install_element_ve(&show_link_cmd);
install_element_ve(&show_port_cmd);
install_element_ve(&show_port_pstn_cmd);
install_element_ve(&show_port_isdn_cmd);
install_element(ENABLE_NODE, &pstn_restart_cmd);
install_element(ENABLE_NODE, &switchover_cmd);
install_element(ENABLE_NODE, &unblock_link_cmd);