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/.
laforge gerrit-no-reply at lists.osmocom.orglaforge has submitted this change. ( 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 properties 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, 18 insertions(+), 22 deletions(-) Approvals: Jenkins Builder: Verified pespin: Looks good to me, but someone else must approve laforge: Looks good to me, approved diff --git a/include/osmocom/mgcp/mgcp_endp.h b/include/osmocom/mgcp/mgcp_endp.h index 5737cd2..8fb8d2c 100644 --- a/include/osmocom/mgcp/mgcp_endp.h +++ b/include/osmocom/mgcp/mgcp_endp.h @@ -103,7 +103,7 @@ 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, const struct mgcp_trunk *trunk); diff --git a/src/libosmo-mgcp/mgcp_endp.c b/src/libosmo-mgcp/mgcp_endp.c index 6c78de2..3f1213b 100644 --- a/src/libosmo-mgcp/mgcp_endp.c +++ b/src/libosmo-mgcp/mgcp_endp.c @@ -33,11 +33,20 @@ .rtp.cleanup_cb = mgcp_cleanup_rtp_bridge_cb }; +/* Generate virtual endpoint name from given parameters */ +static char *gen_virtual_epname(void *ctx, const char *domain, + unsigned int index) +{ + return talloc_asprintf(ctx, "%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; @@ -48,15 +57,18 @@ 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; + endp->name = gen_virtual_epname(endp, 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) */ + endp->name = talloc_asprintf(endp, "%s-1/%x", MGCP_ENDPOINT_PREFIX_E1_TRUNK, index); LOGP(DLMGCP, LOGL_FATAL, "E1 trunks not implemented!\n"); + endp->type = &ep_typeset.rtp; break; default: osmo_panic("Cannot allocate unimplemented trunk type %d! %s:%d\n", diff --git a/src/libosmo-mgcp/mgcp_trunk.c b/src/libosmo-mgcp/mgcp_trunk.c index 6736145..3692351 100644 --- a/src/libosmo-mgcp/mgcp_trunk.c +++ b/src/libosmo-mgcp/mgcp_trunk.c @@ -66,7 +66,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 @@ -90,22 +89,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: 3 Gerrit-Owner: dexter <pmaier at sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge at osmocom.org> Gerrit-Reviewer: neels <nhofmeyr at sysmocom.de> Gerrit-Reviewer: pespin <pespin at sysmocom.de> Gerrit-MessageType: merged -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200618/9fc562c3/attachment.htm>