diff --git a/src/Makefile.am b/src/Makefile.am index 066ea91..3b6301a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -11,13 +11,15 @@ mgcp_mgw_LDADD = $(LAFORGE_LIBS) $(NEXUSWARE_C7_LIBS) $(NEXUSWARE_UNIPORTE_LIBS) cellmgr_ng_SOURCES = main.c mtp_layer3.c thread.c input/ipaccess.c pcap.c \ bss_patch.c bssap_sccp.c bsc_sccp.c bsc_ussd.c links.c \ - msc_conn.c link_udp.c snmp_mtp.c debug.c vty_interface.c isup.c \ - mtp_link.c counter.c sccp_state.c bsc.c ss7_application.c + msc_conn.c link_udp.c snmp_mtp.c debug.c isup.c \ + mtp_link.c counter.c sccp_state.c bsc.c ss7_application.c \ + vty_interface.c vty_interface_cmds.c cellmgr_ng_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOSCCP_LIBS) $(LIBOSMOVTY_LIBS) $(NEXUSWARE_C7_LIBS) \ -lpthread -lnetsnmp -lcrypto osmo_stp_SOURCES = main_stp.c mtp_layer3.c thread.c pcap.c link_udp.c snmp_mtp.c \ - debug.c vty_interface.c links.c isup.c sctp_m2ua.c \ - mtp_link.c counter.c bsc.c ss7_application.c + debug.c links.c isup.c sctp_m2ua.c \ + mtp_link.c counter.c bsc.c ss7_application.c \ + vty_interface.c vty_interface_cmds.c osmo_stp_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOSCCP_LIBS) $(LIBOSMOVTY_LIBS) $(NEXUSWARE_C7_LIBS) \ -lpthread -lnetsnmp -lcrypto -lm2ua -lsctp diff --git a/src/vty_interface.c b/src/vty_interface.c index 244fd0a..6528417 100644 --- a/src/vty_interface.c +++ b/src/vty_interface.c @@ -26,7 +26,6 @@ #include #include -#include #include #include @@ -34,9 +33,6 @@ #include #include -#include -#include -#include #undef PACKAGE_NAME #undef PACKAGE_VERSION @@ -329,216 +325,7 @@ DEFUN(cfg_isup_pass, cfg_isup_pass_cmd, return CMD_SUCCESS; } -static void dump_stats(struct vty *vty, struct mtp_link_set *set) -{ - struct mtp_link *link; - - vty_out(vty, "Linkset name: %s opc: %d%s", set->name, set->opc, VTY_NEWLINE); - vty_out_rate_ctr_group(vty, " ", set->ctrg); - - llist_for_each_entry(link, &set->links, entry) { - vty_out(vty, " Link %d%s", link->nr, VTY_NEWLINE); - vty_out_rate_ctr_group(vty, " ", link->ctrg); - } -} - -DEFUN(show_stats, show_stats_cmd, - "show statistics", - SHOW_STR "Display Linkset statistics\n") -{ - struct mtp_link_set *set; - - llist_for_each_entry(set, &bsc->linksets, entry) - dump_stats(vty, set); - - return CMD_SUCCESS; -} - -static void dump_state(struct vty *vty, struct mtp_link_set *set) -{ - struct mtp_link *link; - - if (!set) { - vty_out(vty, "LinkSet for %s is not configured.%s", set->name, VTY_NEWLINE); - return; - } - - vty_out(vty, "LinkSet for %s is %s, remote sccp is %s.%s", - set->name, - set->available == 0 ? "not available" : "available", - set->sccp_up == 0? "not established" : "established", - VTY_NEWLINE); - - llist_for_each_entry(link, &set->links, entry) { - if (link->blocked) - vty_out(vty, " Link %d is blocked.%s", - link->nr, VTY_NEWLINE); - else - vty_out(vty, " Link %d is %s.%s", - link->nr, - link->available == 0 ? "not available" : "available", - VTY_NEWLINE); - } -} - -DEFUN(show_linksets, show_linksets_cmd, - "show link-sets", - SHOW_STR "Display current state of linksets\n") -{ - struct mtp_link_set *set; - - llist_for_each_entry(set, &bsc->linksets, entry) - dump_state(vty, set); - return CMD_SUCCESS; -} - -DEFUN(show_msc, show_msc_cmd, - "show msc", - SHOW_STR "Display the status of the MSC\n") -{ - struct msc_connection *msc = msc_connection_num(bsc, 0); - - if (!msc) { - vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE); - return CMD_WARNING; - } - - vty_out(vty, "MSC link is %s and had %s.%s", - msc->msc_link_down == 0 ? "up" : "down", - msc->first_contact == 1 ? "no contact" : "contact", - VTY_NEWLINE); - return CMD_SUCCESS; -} - -DEFUN(show_slc, show_slc_cmd, - "show link-set <0-100> slc", - SHOW_STR "LinkSet\n" "Linkset nr\n" "SLS to SLC\n") -{ - struct mtp_link_set *set = NULL; - int i; - - set = mtp_link_set_num(bsc, atoi(argv[0])); - - if (!set) { - vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE); - return CMD_WARNING; - } - - vty_out(vty, "LinkSet for %s.%s", argv[0], VTY_NEWLINE); - for (i = 0; i < ARRAY_SIZE(set->slc); ++i) { - if (set->slc[i]) - vty_out(vty, " SLC[%.2d] is on link %d.%s", - i, set->slc[i]->nr, VTY_NEWLINE); - else - vty_out(vty, " SLC[%d] is down.%s", - i, VTY_NEWLINE); - } - - return CMD_SUCCESS; -} - -DEFUN(pcap_set, pcap_set_cmd, - "trace-pcap <0-100> NAME FILE", - "Trace to a PCAP file\n" "Linkset nr.\n" - "Trace Linkset\n" "Filename to trace\n") -{ - struct mtp_link_set *set = NULL; - - set = mtp_link_set_num(bsc, atoi(argv[0])); - - if (!set) { - vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE); - return CMD_WARNING; - } - - - if (set->pcap_fd >= 0 && bsc->pcap_fd != set->pcap_fd) - close(set->pcap_fd); - set->pcap_fd = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, - S_IRUSR | S_IWUSR | S_IRGRP| S_IROTH); - if (set->pcap_fd < 0) { - vty_out(vty, "Failed to open file for writing.%s", VTY_NEWLINE); - return CMD_WARNING; - } - - mtp_pcap_write_header(set->pcap_fd); - return CMD_SUCCESS; -} - -DEFUN(pcap_set_stop, pcap_set_stop_cmd, - "trace-pcap <0-100> NAME stop", - "Trace to a PCAP file\n" "Linkset nr\n" - "Trace Linkset\n" "Stop the tracing\n") -{ - struct mtp_link_set *set = NULL; - - set = mtp_link_set_num(bsc, atoi(argv[0])); - - if (!set) { - vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE); - return CMD_WARNING; - } - - if (set->pcap_fd >= 0 && bsc->pcap_fd != set->pcap_fd) - close(set->pcap_fd); - set->pcap_fd = -1; - return CMD_SUCCESS; -} - -#define FIND_LINK(vty, set_no, nr) ({ \ - struct mtp_link_set *set = NULL; \ - struct mtp_link *link = NULL; \ - set = mtp_link_set_num(bsc, set_no); \ - if (!set) { \ - vty_out(vty, "Unknown Linkset nr %d.%s", set_no, VTY_NEWLINE); \ - return CMD_WARNING; \ - } \ - link = mtp_link_num(set, nr); \ - if (!link) { \ - vty_out(vty, "Can not find link %d.%s", nr, VTY_NEWLINE); \ - return CMD_WARNING; \ - } \ - link; }) - -#define LINK_STR "Operations on the link\n" \ - "Linkset number\n" \ - "Link number\n" - -DEFUN(lnk_block, lnk_block_cmd, - "link <0-100> <0-15> block", - LINK_STR "Block it\n") -{ - struct mtp_link *link = FIND_LINK(vty, atoi(argv[0]), atoi(argv[1])); - mtp_link_block(link); - return CMD_SUCCESS; -} - -DEFUN(lnk_unblock, lnk_unblock_cmd, - "link <0-100> <0-15> unblock", - LINK_STR "Unblock it\n") -{ - struct mtp_link *link = FIND_LINK(vty, atoi(argv[0]), atoi(argv[1])); - mtp_link_unblock(link); - return CMD_SUCCESS; -} - -DEFUN(lnk_reset, lnk_reset_cmd, - "link <0-100> <0-15> reset", - LINK_STR "Reset it\n") -{ - struct mtp_link *link = FIND_LINK(vty, atoi(argv[0]), atoi(argv[1])); - mtp_link_failure(link); - return CMD_SUCCESS; -} - -DEFUN(allow_inject, allow_inject_cmd, - "allow-inject (0|1)", - "Allow to inject messages\n" "Disable\n" "Enable\n") -{ - bsc->allow_inject = atoi(argv[0]); - return CMD_SUCCESS; -} - +extern void cell_vty_init_cmds(void); void cell_vty_init(void) { cmd_init(1); @@ -568,20 +355,7 @@ void cell_vty_init(void) install_element(CELLMGR_NODE, &cfg_msc_time_cmd); install_element(CELLMGR_NODE, &cfg_isup_pass_cmd); - /* special commands */ - install_element(ENABLE_NODE, &pcap_set_cmd); - install_element(ENABLE_NODE, &pcap_set_stop_cmd); - install_element(ENABLE_NODE, &lnk_block_cmd); - install_element(ENABLE_NODE, &lnk_unblock_cmd); - install_element(ENABLE_NODE, &lnk_reset_cmd); - install_element(ENABLE_NODE, &allow_inject_cmd); - - /* show commands */ - install_element_ve(&show_stats_cmd); - install_element_ve(&show_linksets_cmd); - install_element_ve(&show_slc_cmd); - - install_element_ve(&show_msc_cmd); + cell_vty_init_cmds(); } const char *openbsc_copyright = ""; diff --git a/src/vty_interface_cmds.c b/src/vty_interface_cmds.c new file mode 100644 index 0000000..e3c82cb --- /dev/null +++ b/src/vty_interface_cmds.c @@ -0,0 +1,265 @@ +/* VTY code for the Cellmgr */ +/* + * (C) 2010-2011 by Holger Hans Peter Freyther + * (C) 2010-2011 by On-Waves + * All Rights Reserved + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include + +extern struct bsc_data *bsc; + +static void dump_stats(struct vty *vty, struct mtp_link_set *set) +{ + struct mtp_link *link; + + vty_out(vty, "Linkset name: %s opc: %d%s", set->name, set->opc, VTY_NEWLINE); + vty_out_rate_ctr_group(vty, " ", set->ctrg); + + llist_for_each_entry(link, &set->links, entry) { + vty_out(vty, " Link %d%s", link->nr, VTY_NEWLINE); + vty_out_rate_ctr_group(vty, " ", link->ctrg); + } +} + +DEFUN(show_stats, show_stats_cmd, + "show statistics", + SHOW_STR "Display Linkset statistics\n") +{ + struct mtp_link_set *set; + + llist_for_each_entry(set, &bsc->linksets, entry) + dump_stats(vty, set); + + return CMD_SUCCESS; +} + +static void dump_state(struct vty *vty, struct mtp_link_set *set) +{ + struct mtp_link *link; + + if (!set) { + vty_out(vty, "LinkSet for %s is not configured.%s", set->name, VTY_NEWLINE); + return; + } + + vty_out(vty, "LinkSet for %s is %s, remote sccp is %s.%s", + set->name, + set->available == 0 ? "not available" : "available", + set->sccp_up == 0? "not established" : "established", + VTY_NEWLINE); + + llist_for_each_entry(link, &set->links, entry) { + if (link->blocked) + vty_out(vty, " Link %d is blocked.%s", + link->nr, VTY_NEWLINE); + else + vty_out(vty, " Link %d is %s.%s", + link->nr, + link->available == 0 ? "not available" : "available", + VTY_NEWLINE); + } +} + +DEFUN(show_linksets, show_linksets_cmd, + "show link-sets", + SHOW_STR "Display current state of linksets\n") +{ + struct mtp_link_set *set; + + llist_for_each_entry(set, &bsc->linksets, entry) + dump_state(vty, set); + return CMD_SUCCESS; +} + +DEFUN(show_msc, show_msc_cmd, + "show msc", + SHOW_STR "Display the status of the MSC\n") +{ + struct msc_connection *msc = msc_connection_num(bsc, 0); + + if (!msc) { + vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE); + return CMD_WARNING; + } + + vty_out(vty, "MSC link is %s and had %s.%s", + msc->msc_link_down == 0 ? "up" : "down", + msc->first_contact == 1 ? "no contact" : "contact", + VTY_NEWLINE); + return CMD_SUCCESS; +} + +DEFUN(show_slc, show_slc_cmd, + "show link-set <0-100> slc", + SHOW_STR "LinkSet\n" "Linkset nr\n" "SLS to SLC\n") +{ + struct mtp_link_set *set = NULL; + int i; + + set = mtp_link_set_num(bsc, atoi(argv[0])); + + if (!set) { + vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE); + return CMD_WARNING; + } + + vty_out(vty, "LinkSet for %s.%s", argv[0], VTY_NEWLINE); + for (i = 0; i < ARRAY_SIZE(set->slc); ++i) { + if (set->slc[i]) + vty_out(vty, " SLC[%.2d] is on link %d.%s", + i, set->slc[i]->nr, VTY_NEWLINE); + else + vty_out(vty, " SLC[%d] is down.%s", + i, VTY_NEWLINE); + } + + return CMD_SUCCESS; +} + +DEFUN(pcap_set, pcap_set_cmd, + "trace-pcap <0-100> NAME FILE", + "Trace to a PCAP file\n" "Linkset nr.\n" + "Trace Linkset\n" "Filename to trace\n") +{ + struct mtp_link_set *set = NULL; + + set = mtp_link_set_num(bsc, atoi(argv[0])); + + if (!set) { + vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE); + return CMD_WARNING; + } + + + if (set->pcap_fd >= 0 && bsc->pcap_fd != set->pcap_fd) + close(set->pcap_fd); + set->pcap_fd = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, + S_IRUSR | S_IWUSR | S_IRGRP| S_IROTH); + if (set->pcap_fd < 0) { + vty_out(vty, "Failed to open file for writing.%s", VTY_NEWLINE); + return CMD_WARNING; + } + + mtp_pcap_write_header(set->pcap_fd); + return CMD_SUCCESS; +} + +DEFUN(pcap_set_stop, pcap_set_stop_cmd, + "trace-pcap <0-100> NAME stop", + "Trace to a PCAP file\n" "Linkset nr\n" + "Trace Linkset\n" "Stop the tracing\n") +{ + struct mtp_link_set *set = NULL; + + set = mtp_link_set_num(bsc, atoi(argv[0])); + + if (!set) { + vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE); + return CMD_WARNING; + } + + if (set->pcap_fd >= 0 && bsc->pcap_fd != set->pcap_fd) + close(set->pcap_fd); + set->pcap_fd = -1; + return CMD_SUCCESS; +} + +#define FIND_LINK(vty, set_no, nr) ({ \ + struct mtp_link_set *set = NULL; \ + struct mtp_link *link = NULL; \ + set = mtp_link_set_num(bsc, set_no); \ + if (!set) { \ + vty_out(vty, "Unknown Linkset nr %d.%s", set_no, VTY_NEWLINE); \ + return CMD_WARNING; \ + } \ + link = mtp_link_num(set, nr); \ + if (!link) { \ + vty_out(vty, "Can not find link %d.%s", nr, VTY_NEWLINE); \ + return CMD_WARNING; \ + } \ + link; }) + +#define LINK_STR "Operations on the link\n" \ + "Linkset number\n" \ + "Link number\n" + +DEFUN(lnk_block, lnk_block_cmd, + "link <0-100> <0-15> block", + LINK_STR "Block it\n") +{ + struct mtp_link *link = FIND_LINK(vty, atoi(argv[0]), atoi(argv[1])); + mtp_link_block(link); + return CMD_SUCCESS; +} + +DEFUN(lnk_unblock, lnk_unblock_cmd, + "link <0-100> <0-15> unblock", + LINK_STR "Unblock it\n") +{ + struct mtp_link *link = FIND_LINK(vty, atoi(argv[0]), atoi(argv[1])); + mtp_link_unblock(link); + return CMD_SUCCESS; +} + +DEFUN(lnk_reset, lnk_reset_cmd, + "link <0-100> <0-15> reset", + LINK_STR "Reset it\n") +{ + struct mtp_link *link = FIND_LINK(vty, atoi(argv[0]), atoi(argv[1])); + mtp_link_failure(link); + return CMD_SUCCESS; +} + +DEFUN(allow_inject, allow_inject_cmd, + "allow-inject (0|1)", + "Allow to inject messages\n" "Disable\n" "Enable\n") +{ + bsc->allow_inject = atoi(argv[0]); + return CMD_SUCCESS; +} + +void cell_vty_init_cmds(void) +{ + /* special commands */ + install_element(ENABLE_NODE, &pcap_set_cmd); + install_element(ENABLE_NODE, &pcap_set_stop_cmd); + install_element(ENABLE_NODE, &lnk_block_cmd); + install_element(ENABLE_NODE, &lnk_unblock_cmd); + install_element(ENABLE_NODE, &lnk_reset_cmd); + install_element(ENABLE_NODE, &allow_inject_cmd); + + /* show commands */ + install_element_ve(&show_stats_cmd); + install_element_ve(&show_linksets_cmd); + install_element_ve(&show_slc_cmd); + + install_element_ve(&show_msc_cmd); +}