Change in osmo-mgw[master]: mgcp_ctrl: add functions to inspect trunk usage

dexter gerrit-no-reply at lists.osmocom.org
Fri Jul 2 13:31:57 UTC 2021


dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-mgw/+/24822 )


Change subject: mgcp_ctrl: add functions to inspect trunk usage
......................................................................

mgcp_ctrl: add functions to inspect trunk usage

It is useful to have control commands to check on the number of
endpoints and of the number of endpoints in use. This would allow
operators to monitor the MGW usage and also simplifies TTCN3 tests

Change-Id: Ib8b5a6e733f521828647742085cad8eccb3e715b
---
M include/osmocom/mgcp/mgcp_ctrl.h
M src/libosmo-mgcp/mgcp_ctrl.c
2 files changed, 80 insertions(+), 10 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/22/24822/1

diff --git a/include/osmocom/mgcp/mgcp_ctrl.h b/include/osmocom/mgcp/mgcp_ctrl.h
index d7ab7cb..a2d929d 100644
--- a/include/osmocom/mgcp/mgcp_ctrl.h
+++ b/include/osmocom/mgcp/mgcp_ctrl.h
@@ -19,6 +19,12 @@
 
 #pragma once
 
-struct ctrl_handle *mgw_ctrl_interface_setup(struct mgcp_config *cfg,
-                                             const char *bind_addr, uint16_t port);
+#include <osmocom/ctrl/control_cmd.h>
 
+enum bsc_ctrl_node {
+	CTRL_NODE_TRUNK = _LAST_CTRL_NODE,
+	_LAST_CTRL_NODE_MGW
+};
+
+struct ctrl_handle *mgw_ctrl_interface_setup(struct mgcp_config *cfg,
+					     const char *bind_addr, uint16_t port);
diff --git a/src/libosmo-mgcp/mgcp_ctrl.c b/src/libosmo-mgcp/mgcp_ctrl.c
index 0ba231b..b3dce30 100644
--- a/src/libosmo-mgcp/mgcp_ctrl.c
+++ b/src/libosmo-mgcp/mgcp_ctrl.c
@@ -19,18 +19,82 @@
 
 #include <osmocom/ctrl/control_if.h>
 #include <osmocom/mgcp/mgcp.h>
+#include <osmocom/mgcp/mgcp_ctrl.h>
+#include <osmocom/mgcp/mgcp_trunk.h>
+#include <osmocom/mgcp/mgcp_protocol.h>
+#include <osmocom/mgcp/mgcp_endp.h>
 
+static struct mgcp_config *g_cfg = NULL;
 
-static int mgw_ctrl_node_lookup(void *data, vector vline, int *node_type,
-				void **node_data, int *i)
+CTRL_CMD_DEFINE_RO(endpoint_usage, "endpoint_usage");
+static int get_endpoint_usage(struct ctrl_cmd *cmd, void *data)
 {
-	return 0;
+	struct mgcp_trunk *trunk = cmd->node;
+	unsigned int i;
+	unsigned int endpoints_in_use = 0;
+
+	if (!trunk)
+		return CTRL_CMD_ERROR;
+
+	for (i = 0; i < trunk->number_endpoints; i++) {
+		if (trunk->endpoints[i]->callid)
+			endpoints_in_use++;
+	}
+
+	cmd->reply = talloc_asprintf(cmd, "%i", endpoints_in_use);
+	return CTRL_CMD_REPLY;
 }
 
-
-struct ctrl_handle *mgw_ctrl_interface_setup(struct mgcp_config *cfg,
-					     const char *bind_addr, uint16_t port)
+CTRL_CMD_DEFINE_RO(endpoint_count, "endpoint_count");
+static int get_endpoint_count(struct ctrl_cmd *cmd, void *data)
 {
-	return ctrl_interface_setup_dynip2(cfg, bind_addr, port, mgw_ctrl_node_lookup,
-					   _LAST_CTRL_NODE);
+	struct mgcp_trunk *trunk = cmd->node;
+
+	if (!trunk)
+		return CTRL_CMD_ERROR;
+
+	cmd->reply = talloc_asprintf(cmd, "%i", trunk->number_endpoints);
+	return CTRL_CMD_REPLY;
+}
+
+static int mgw_ctrl_node_lookup(void *data, vector vline, int *node_type, void **node_data, int *i)
+{
+	const char *token = vector_slot(vline, *i);
+	unsigned int k;
+	char trunk_prefix_buf[MGCP_ENDPOINT_MAXLEN];
+
+	switch (*node_type) {
+	case CTRL_NODE_ROOT:
+		if (strcmp(token, "trunk") != 0)
+			return 0;
+		(*i)++;
+
+		/* Since it is illegal to use a '/' in ctrl commands, the control interface uses ':' as separator
+		 * instead. */
+		strncpy(trunk_prefix_buf, vector_slot(vline, *i), sizeof(trunk_prefix_buf));
+		for (k = 0; k < strlen(trunk_prefix_buf); k++)
+			if (trunk_prefix_buf[k] == ':')
+				trunk_prefix_buf[k] = '/';
+
+		*node_data = mgcp_trunk_by_name(g_cfg, trunk_prefix_buf);
+		*node_type = CTRL_NODE_TRUNK;
+		break;
+	default:
+		return 0;
+	}
+
+	return 1;
+}
+
+struct ctrl_handle *mgw_ctrl_interface_setup(struct mgcp_config *cfg, const char *bind_addr, uint16_t port)
+{
+	struct ctrl_handle *handle;
+
+	g_cfg = cfg;
+
+	handle = ctrl_interface_setup_dynip2(cfg, bind_addr, port, mgw_ctrl_node_lookup, _LAST_CTRL_NODE_MGW);
+	OSMO_ASSERT(ctrl_cmd_install(CTRL_NODE_TRUNK, &cmd_endpoint_usage) == 0);
+	OSMO_ASSERT(ctrl_cmd_install(CTRL_NODE_TRUNK, &cmd_endpoint_count) == 0);
+
+	return handle;
 }

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-mgw/+/24822
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Change-Id: Ib8b5a6e733f521828647742085cad8eccb3e715b
Gerrit-Change-Number: 24822
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210702/e745aca1/attachment.htm>


More information about the gerrit-log mailing list