mirror of
https://gitea.osmocom.org/cellular-infrastructure/osmo-mgw.git
synced 2025-10-23 08:12:01 +00:00
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
This commit is contained in:
@@ -103,7 +103,7 @@ struct mgcp_endpoint {
|
||||
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);
|
||||
|
@@ -33,11 +33,20 @@ const struct mgcp_endpoint_typeset ep_typeset = {
|
||||
.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 @@ struct mgcp_endpoint *mgcp_endp_alloc(struct mgcp_trunk *trunk, char *name)
|
||||
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",
|
||||
|
@@ -66,7 +66,6 @@ struct mgcp_trunk *mgcp_trunk_alloc(struct mgcp_config *cfg, enum mgcp_trunk_typ
|
||||
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 @@ int mgcp_trunk_alloc_endpts(struct mgcp_trunk *trunk)
|
||||
|
||||
/* 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;
|
||||
|
Reference in New Issue
Block a user