summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2012-01-27 00:41:39 +0100
committerHarald Welte <laforge@gnumonks.org>2012-01-27 00:41:39 +0100
commit6a85705d517dc3b88c23768b451ea9464fd1b7a0 (patch)
tree2b283e63d2d21899e472a15960ee91db7b4772b2
parent50f93a4acde733ab03b85cde9c525bad1a3aec8b (diff)
MGCP: Add VTY commands to reset (RSIP) one or all endpoints
-rw-r--r--openbsc/src/libmgcp/mgcp_protocol.c30
-rw-r--r--openbsc/src/libmgcp/mgcp_vty.c56
2 files changed, 86 insertions, 0 deletions
diff --git a/openbsc/src/libmgcp/mgcp_protocol.c b/openbsc/src/libmgcp/mgcp_protocol.c
index 538c350..607e230 100644
--- a/openbsc/src/libmgcp/mgcp_protocol.c
+++ b/openbsc/src/libmgcp/mgcp_protocol.c
@@ -1087,6 +1087,36 @@ static void send_dlcx(struct mgcp_endpoint *endp, int endpoint)
send_trans(endp->cfg, buf, len);
}
+static int send_agent(struct mgcp_config *cfg, const char *buf, int len)
+{
+ return write(cfg->gw_fd.bfd.fd, buf, len);
+}
+
+int mgcp_send_reset_all(struct mgcp_config *cfg)
+{
+ static const char mgcp_reset[] = {
+ "RSIP 1 *@mgw MGCP 1.0\r\n"
+ };
+
+ return send_agent(cfg, mgcp_reset, sizeof mgcp_reset -1);
+}
+
+int mgcp_send_reset_ep(struct mgcp_endpoint *endp, int endpoint)
+{
+ char buf[128];
+ int len;
+
+ len = snprintf(buf, sizeof(buf),
+ "RSIP 39 %x@mgw MGCP 1.0\r\n"
+ , endpoint);
+ if (len < 0)
+ return len;
+
+ buf[sizeof(buf) - 1] = '\0';
+
+ return send_agent(endp->cfg, buf, len);
+}
+
static void create_transcoder(struct mgcp_endpoint *endp)
{
int port;
diff --git a/openbsc/src/libmgcp/mgcp_vty.c b/openbsc/src/libmgcp/mgcp_vty.c
index 4483f02..7309f50 100644
--- a/openbsc/src/libmgcp/mgcp_vty.c
+++ b/openbsc/src/libmgcp/mgcp_vty.c
@@ -637,12 +637,68 @@ DEFUN(free_endp, free_endp_cmd,
return CMD_SUCCESS;
}
+DEFUN(reset_endp, reset_endp_cmd,
+ "reset-endpoint <0-64> NUMBER",
+ "Reset the given endpoint\n" "Trunk number\n"
+ "Endpoint number in hex.\n")
+{
+ struct mgcp_trunk_config *trunk;
+ struct mgcp_endpoint *endp;
+ int endp_no, rc;
+
+ trunk = find_trunk(g_cfg, atoi(argv[0]));
+ if (!trunk) {
+ vty_out(vty, "%%Trunk %d not found in the config.%s",
+ atoi(argv[0]), VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ if (!trunk->endpoints) {
+ vty_out(vty, "%%Trunk %d has no endpoints allocated.%s",
+ trunk->trunk_nr, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ endp_no = strtoul(argv[1], NULL, 16);
+ if (endp_no < 1 || endp_no >= trunk->number_endpoints) {
+ vty_out(vty, "Endpoint number %s/%d is invalid.%s",
+ argv[1], endp_no, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ endp = &trunk->endpoints[endp_no];
+ rc = mgcp_send_reset_ep(endp, ENDPOINT_NUMBER(endp));
+ if (rc < 0) {
+ vty_out(vty, "Error %d sending reset.%s", rc, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ return CMD_SUCCESS;
+}
+
+DEFUN(reset_all_endp, reset_all_endp_cmd,
+ "reset-all-endpoints",
+ "Reset all endpoints\n")
+{
+ int rc;
+
+ rc = mgcp_send_reset_all(g_cfg);
+ if (rc < 0) {
+ vty_out(vty, "Error %d during endpoint reset.%s",
+ rc, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ return CMD_SUCCESS;
+}
+
+
int mgcp_vty_init(void)
{
install_element_ve(&show_mgcp_cmd);
install_element(ENABLE_NODE, &loop_endp_cmd);
install_element(ENABLE_NODE, &tap_call_cmd);
install_element(ENABLE_NODE, &free_endp_cmd);
+ install_element(ENABLE_NODE, &reset_endp_cmd);
+ install_element(ENABLE_NODE, &reset_all_endp_cmd);
install_element(CONFIG_NODE, &cfg_mgcp_cmd);
install_node(&mgcp_node, config_write_mgcp);