This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
dexter gerrit-no-reply at lists.osmocom.orgdexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-mgw/+/18754 ) Change subject: endp: move endpoint name generation into mgcp_endp.c ...................................................................... endp: move endpoint name generation into mgcp_endp.c When the trunk allocates its endpoints by using mgcp_endp_alloc() ist passes the name for each endpoint as a parameter. In order to generate the name endpoint specific knowlege is required. This process can be simplified, since all what mgcp_trunk_alloc_endpts() does is calling mgcp_endp_alloc() in a loop in order to generate a consecuitve series of endpoints. The endpoint names are generated from the index of the for loop. When we just pass the index instead of the endpoint name to mgcp_endp_alloc(), then we can greatly simplify the code since all the knowledge about the name generation can go into mgcp_endp.c. The endpoint will name itsself by the trunk properites and the index number we pass with the allocator function. Change-Id: I8dee07f1c63037d1f73113f69c612d1f2703cee5 Related: OS#2659 --- M include/osmocom/mgcp/mgcp_endp.h M src/libosmo-mgcp/mgcp_endp.c M src/libosmo-mgcp/mgcp_trunk.c 3 files changed, 21 insertions(+), 22 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/54/18754/1 diff --git a/include/osmocom/mgcp/mgcp_endp.h b/include/osmocom/mgcp/mgcp_endp.h index 1fe8266..b3627b0 100644 --- a/include/osmocom/mgcp/mgcp_endp.h +++ b/include/osmocom/mgcp/mgcp_endp.h @@ -103,7 +103,8 @@ uint32_t x_osmo_ign; }; -struct mgcp_endpoint *mgcp_endp_alloc(struct mgcp_trunk *trunk, char *name); +struct mgcp_endpoint *mgcp_endp_alloc(struct mgcp_trunk *trunk, + unsigned int index); void mgcp_endp_release(struct mgcp_endpoint *endp); struct mgcp_endpoint *mgcp_endp_by_name_trunk(int *cause, const char *epname, struct mgcp_trunk *trunk); diff --git a/src/libosmo-mgcp/mgcp_endp.c b/src/libosmo-mgcp/mgcp_endp.c index 62b0854..38d83d5 100644 --- a/src/libosmo-mgcp/mgcp_endp.c +++ b/src/libosmo-mgcp/mgcp_endp.c @@ -33,13 +33,23 @@ .rtp.cleanup_cb = mgcp_cleanup_rtp_bridge_cb }; +/* Generate virtual endpoint name from given parameters */ +static void gen_virtual_epname(char *epname, const char *domain, + unsigned int index) +{ + snprintf(epname, MGCP_ENDPOINT_MAXLEN, "%s%x@%s", + MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK, index, domain); +} + /*! allocate an endpoint and set default values. * \param[in] trunk configuration. - * \param[in] name endpoint name. + * \param[in] name endpoint index. * \returns endpoint on success, NULL on failure. */ -struct mgcp_endpoint *mgcp_endp_alloc(struct mgcp_trunk *trunk, char *name) +struct mgcp_endpoint *mgcp_endp_alloc(struct mgcp_trunk *trunk, + unsigned int index) { struct mgcp_endpoint *endp; + char ep_name_buf[MGCP_ENDPOINT_MAXLEN]; endp = talloc_zero(trunk->endpoints, struct mgcp_endpoint); if (!endp) @@ -48,14 +58,16 @@ INIT_LLIST_HEAD(&endp->conns); endp->cfg = trunk->cfg; endp->trunk = trunk; - endp->name = talloc_strdup(endp, name); switch (trunk->trunk_type) { case MGCP_TRUNK_VIRTUAL: endp->type = &ep_typeset.rtp; + gen_virtual_epname(ep_name_buf, trunk->cfg->domain, index); break; case MGCP_TRUNK_E1: - /* FIXME: Implement E1 allocation */ + /* FIXME: E1 trunk implementation is work in progress, this endpoint + * name is incomplete (subslots) */ + snprintf(ep_name_buf, sizeof(ep_name_buf), "%s-1/%x", MGCP_ENDPOINT_PREFIX_E1_TRUNK, index); LOGP(DLMGCP, LOGL_FATAL, "E1 trunks not implemented!\n"); break; default: @@ -63,6 +75,8 @@ trunk->trunk_type, __FILE__, __LINE__); } + endp->name = talloc_strdup(endp, ep_name_buf); + return endp; } diff --git a/src/libosmo-mgcp/mgcp_trunk.c b/src/libosmo-mgcp/mgcp_trunk.c index 15e4a0a..7774e40 100644 --- a/src/libosmo-mgcp/mgcp_trunk.c +++ b/src/libosmo-mgcp/mgcp_trunk.c @@ -64,7 +64,6 @@ int mgcp_trunk_alloc_endpts(struct mgcp_trunk *trunk) { int i; - char ep_name_buf[MGCP_ENDPOINT_MAXLEN]; struct mgcp_endpoint *endp; /* Make sure the amount of requested endpoints does not execeed @@ -88,22 +87,7 @@ /* create endpoints */ for (i = 0; i < trunk->vty_number_endpoints; ++i) { - switch (trunk->trunk_type) { - case MGCP_TRUNK_VIRTUAL: - snprintf(ep_name_buf, sizeof(ep_name_buf), "%s%x@%s", MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK, i, - trunk->cfg->domain); - break; - case MGCP_TRUNK_E1: - /* FIXME: E1 trunk implementation is work in progress, this endpoint - * name is incomplete (subslots) */ - snprintf(ep_name_buf, sizeof(ep_name_buf), "%s-1/%x", MGCP_ENDPOINT_PREFIX_E1_TRUNK, i); - break; - default: - osmo_panic("Cannot allocate unimplemented trunk type %d! %s:%d\n", - trunk->trunk_type, __FILE__, __LINE__); - } - - endp = mgcp_endp_alloc(trunk, ep_name_buf); + endp = mgcp_endp_alloc(trunk, i); if (!endp) { talloc_free(trunk->endpoints); return -1; -- To view, visit https://gerrit.osmocom.org/c/osmo-mgw/+/18754 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-mgw Gerrit-Branch: master Gerrit-Change-Id: I8dee07f1c63037d1f73113f69c612d1f2703cee5 Gerrit-Change-Number: 18754 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/20200610/c51d76a5/attachment.htm>