Change in osmo-mgw[master]: osmux: Cleanup of CID alloc pool APIs
Pau Espin Pedrol has uploaded this change for review. ( https://gerrit.osmocom.org/13774 Change subject: osmux: Cleanup of CID alloc pool APIs .. osmux: Cleanup of CID alloc pool APIs * Cleanup naming to make it far more clear * Drop 2 variables holding CID values (allocated_cid, cid), in favour of 1 value holdinf the value and one bool stating whether the value is used. * Change conn_osmux_allocate_cid to allow allocating either next available CID or a specific one, in preparation for forthcoming patches. This commit can be merged straight away because anyway osmux cannot be enabled in current status (blocked by vty config) and (conn_)osmux_allocate_cid was/is not called anywhere. However, it helps improving code base for future re-introduction of Osmux as it is envisioned. Change-Id: I737a248ac6c74add8e917fe2e2f36779d0f1d685 --- M include/osmocom/mgcp/mgcp_internal.h M include/osmocom/mgcp/osmux.h M src/libosmo-mgcp/mgcp_conn.c M src/libosmo-mgcp/mgcp_osmux.c M src/libosmo-mgcp/mgcp_vty.c M tests/mgcp/mgcp_test.c 6 files changed, 80 insertions(+), 39 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/74/13774/1 diff --git a/include/osmocom/mgcp/mgcp_internal.h b/include/osmocom/mgcp/mgcp_internal.h index ec94584..c0a1b92 100644 --- a/include/osmocom/mgcp/mgcp_internal.h +++ b/include/osmocom/mgcp/mgcp_internal.h @@ -188,9 +188,9 @@ struct { /* Osmux state: disabled, activating, active */ enum osmux_state state; - /* Allocated Osmux circuit ID for this endpoint */ - int allocated_cid; - /* Used Osmux circuit ID for this endpoint */ + /* Is cid holding valid data? is it allocated from pool? */ + bool cid_allocated; + /* Allocated Osmux circuit ID for this conn */ uint8_t cid; /* handle to batch messages */ struct osmux_in_handle *in; diff --git a/include/osmocom/mgcp/osmux.h b/include/osmocom/mgcp/osmux.h index 685be9c..c080c85 100644 --- a/include/osmocom/mgcp/osmux.h +++ b/include/osmocom/mgcp/osmux.h @@ -15,13 +15,16 @@ int osmux_enable_conn(struct mgcp_endpoint *endp, struct mgcp_conn_rtp *conn, struct in_addr *addr, uint16_t port); void osmux_disable_conn(struct mgcp_conn_rtp *conn); -void osmux_allocate_cid(struct mgcp_conn_rtp *conn); -void osmux_release_cid(struct mgcp_conn_rtp *conn); +int conn_osmux_allocate_cid(struct mgcp_conn_rtp *conn, int osmux_cid); +void conn_osmux_release_cid(struct mgcp_conn_rtp *conn); int osmux_xfrm_to_osmux(char *buf, int buf_len, struct mgcp_conn_rtp *conn); int osmux_send_dummy(struct mgcp_endpoint *endp, struct mgcp_conn_rtp *conn); -int osmux_get_cid(void); -void osmux_put_cid(uint8_t osmux_cid); -int osmux_used_cid(void); + +void osmux_cid_pool_get(uint8_t osmux_cid); +int osmux_cid_pool_get_next(void); +void osmux_cid_pool_put(uint8_t osmux_cid); +bool osmux_cid_pool_allocated(uint8_t osmux_cid); +int osmux_cid_pool_count_used(void); enum osmux_state { OSMUX_STATE_DISABLED = 0, /* Osmux not being currently used by endp */ diff --git a/src/libosmo-mgcp/mgcp_conn.c b/src/libosmo-mgcp/mgcp_conn.c index a8341d6..fc70231 100644 --- a/src/libosmo-mgcp/mgcp_conn.c +++ b/src/libosmo-mgcp/mgcp_conn.c @@ -91,7 +91,8 @@ static unsigned int rate_ctr_index = 0; conn_rtp->type = MGCP_RTP_DEFAULT; - conn_rtp->osmux.allocated_cid = -1; + conn_rtp->osmux.cid_allocated = false; + conn_rtp->osmux.cid = 0; /* backpointer to the generic part of the connection */ conn->u.rtp.conn = conn; @@ -121,7 +122,6 @@ static void mgcp_rtp_conn_cleanup(struct mgcp_conn_rtp *conn_rtp) { osmux_disable_conn(conn_rtp); - osmux_release_cid(conn_rtp); mgcp_free_rtp_port(&conn_rtp->end); rate_ctr_group_free(conn_rtp->rate_ctr_group); } diff --git a/src/libosmo-mgcp/mgcp_osmux.c b/src/libosmo-mgcp/mgcp_osmux.c index a2c138d..3bd765e 100644 --- a/src/libosmo-mgcp/mgcp_osmux.c +++ b/src/libosmo-mgcp/mgcp_osmux.c @@ -614,31 +614,46 @@ osmux_xfrm_input_close_circuit(conn->osmux.in, conn->osmux.cid); conn->osmux.state = OSMUX_STATE_DISABLED; - conn->osmux.cid = -1; + conn_osmux_release_cid(conn); osmux_handle_put(conn->osmux.in); } /*! relase OSXMUX cid, that had been allocated to this connection. * \param[in] conn connection with OSMUX cid to release */ -void osmux_release_cid(struct mgcp_conn_rtp *conn) +void conn_osmux_release_cid(struct mgcp_conn_rtp *conn) { - if (!conn) - return; - - if (conn->osmux.state != OSMUX_STATE_ENABLED) - return; - - if (conn->osmux.allocated_cid >= 0) - osmux_put_cid(conn->osmux.allocated_cid); - conn->osmux.allocated_cid = -1; + if (conn->osmux.cid_allocated) +
Change in osmo-mgw[master]: osmux: Cleanup of CID alloc pool APIs
Harald Welte has posted comments on this change. ( https://gerrit.osmocom.org/13774 ) Change subject: osmux: Cleanup of CID alloc pool APIs .. Patch Set 1: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/13774 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-mgw Gerrit-Branch: master Gerrit-MessageType: comment Gerrit-Change-Id: I737a248ac6c74add8e917fe2e2f36779d0f1d685 Gerrit-Change-Number: 13774 Gerrit-PatchSet: 1 Gerrit-Owner: Pau Espin Pedrol Gerrit-Reviewer: Harald Welte Gerrit-Reviewer: Jenkins Builder (102) Gerrit-Comment-Date: Thu, 25 Apr 2019 19:57:31 + Gerrit-HasComments: No Gerrit-HasLabels: Yes
Change in osmo-mgw[master]: osmux: Cleanup of CID alloc pool APIs
Pau Espin Pedrol has submitted this change and it was merged. ( https://gerrit.osmocom.org/13774 ) Change subject: osmux: Cleanup of CID alloc pool APIs .. osmux: Cleanup of CID alloc pool APIs * Cleanup naming to make it far more clear * Drop 2 variables holding CID values (allocated_cid, cid), in favour of 1 value holdinf the value and one bool stating whether the value is used. * Change conn_osmux_allocate_cid to allow allocating either next available CID or a specific one, in preparation for forthcoming patches. This commit can be merged straight away because anyway osmux cannot be enabled in current status (blocked by vty config) and (conn_)osmux_allocate_cid was/is not called anywhere. However, it helps improving code base for future re-introduction of Osmux as it is envisioned. Change-Id: I737a248ac6c74add8e917fe2e2f36779d0f1d685 --- M include/osmocom/mgcp/mgcp_internal.h M include/osmocom/mgcp/osmux.h M src/libosmo-mgcp/mgcp_conn.c M src/libosmo-mgcp/mgcp_osmux.c M src/libosmo-mgcp/mgcp_vty.c M tests/mgcp/mgcp_test.c 6 files changed, 80 insertions(+), 39 deletions(-) Approvals: Harald Welte: Looks good to me, approved Jenkins Builder: Verified diff --git a/include/osmocom/mgcp/mgcp_internal.h b/include/osmocom/mgcp/mgcp_internal.h index 3defc4c..24e28b4 100644 --- a/include/osmocom/mgcp/mgcp_internal.h +++ b/include/osmocom/mgcp/mgcp_internal.h @@ -188,9 +188,9 @@ struct { /* Osmux state: disabled, activating, active */ enum osmux_state state; - /* Allocated Osmux circuit ID for this endpoint */ - int allocated_cid; - /* Used Osmux circuit ID for this endpoint */ + /* Is cid holding valid data? is it allocated from pool? */ + bool cid_allocated; + /* Allocated Osmux circuit ID for this conn */ uint8_t cid; /* handle to batch messages */ struct osmux_in_handle *in; diff --git a/include/osmocom/mgcp/osmux.h b/include/osmocom/mgcp/osmux.h index 685be9c..c080c85 100644 --- a/include/osmocom/mgcp/osmux.h +++ b/include/osmocom/mgcp/osmux.h @@ -15,13 +15,16 @@ int osmux_enable_conn(struct mgcp_endpoint *endp, struct mgcp_conn_rtp *conn, struct in_addr *addr, uint16_t port); void osmux_disable_conn(struct mgcp_conn_rtp *conn); -void osmux_allocate_cid(struct mgcp_conn_rtp *conn); -void osmux_release_cid(struct mgcp_conn_rtp *conn); +int conn_osmux_allocate_cid(struct mgcp_conn_rtp *conn, int osmux_cid); +void conn_osmux_release_cid(struct mgcp_conn_rtp *conn); int osmux_xfrm_to_osmux(char *buf, int buf_len, struct mgcp_conn_rtp *conn); int osmux_send_dummy(struct mgcp_endpoint *endp, struct mgcp_conn_rtp *conn); -int osmux_get_cid(void); -void osmux_put_cid(uint8_t osmux_cid); -int osmux_used_cid(void); + +void osmux_cid_pool_get(uint8_t osmux_cid); +int osmux_cid_pool_get_next(void); +void osmux_cid_pool_put(uint8_t osmux_cid); +bool osmux_cid_pool_allocated(uint8_t osmux_cid); +int osmux_cid_pool_count_used(void); enum osmux_state { OSMUX_STATE_DISABLED = 0, /* Osmux not being currently used by endp */ diff --git a/src/libosmo-mgcp/mgcp_conn.c b/src/libosmo-mgcp/mgcp_conn.c index bfaa111..af5426f 100644 --- a/src/libosmo-mgcp/mgcp_conn.c +++ b/src/libosmo-mgcp/mgcp_conn.c @@ -90,7 +90,8 @@ static unsigned int rate_ctr_index = 0; conn_rtp->type = MGCP_RTP_DEFAULT; - conn_rtp->osmux.allocated_cid = -1; + conn_rtp->osmux.cid_allocated = false; + conn_rtp->osmux.cid = 0; /* backpointer to the generic part of the connection */ conn->u.rtp.conn = conn; @@ -120,7 +121,6 @@ static void mgcp_rtp_conn_cleanup(struct mgcp_conn_rtp *conn_rtp) { osmux_disable_conn(conn_rtp); - osmux_release_cid(conn_rtp); mgcp_free_rtp_port(&conn_rtp->end); rate_ctr_group_free(conn_rtp->rate_ctr_group); } diff --git a/src/libosmo-mgcp/mgcp_osmux.c b/src/libosmo-mgcp/mgcp_osmux.c index a2c138d..3bd765e 100644 --- a/src/libosmo-mgcp/mgcp_osmux.c +++ b/src/libosmo-mgcp/mgcp_osmux.c @@ -614,31 +614,46 @@ osmux_xfrm_input_close_circuit(conn->osmux.in, conn->osmux.cid); conn->osmux.state = OSMUX_STATE_DISABLED; - conn->osmux.cid = -1; + conn_osmux_release_cid(conn); osmux_handle_put(conn->osmux.in); } /*! relase OSXMUX cid, that had been allocated to this connection. * \param[in] conn connection with OSMUX cid to release */ -void osmux_release_cid(struct mgcp_conn_rtp *conn) +void conn_osmux_release_cid(struct mgcp_conn_rtp *conn) { - if (!conn) - return; - - if (conn->osmux.state != OSMUX_STATE_ENABLED) - return; - - if (conn->osmux.allocated_cid >= 0) - osmux_put_cid(conn->osmux.allocated_cid); - conn->osmux.allocated_cid = -1; + if (conn->osmux.cid_alloc