Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1 | /* Message connection list handling */ |
| 2 | |
| 3 | /* |
| 4 | * (C) 2017 by sysmocom s.f.m.c. GmbH <info@sysmocom.de> |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * Author: Philipp Maier |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU Affero General Public License as published by |
| 11 | * the Free Software Foundation; either version 3 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU Affero General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Affero General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #pragma once |
| 25 | |
| 26 | #include <osmocom/mgcp/mgcp_internal.h> |
| 27 | #include <osmocom/core/linuxlist.h> |
Stefan Sperling | ba25eab | 2018-10-30 14:32:31 +0100 | [diff] [blame] | 28 | #include <osmocom/core/rate_ctr.h> |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 29 | #include <inttypes.h> |
| 30 | |
Philipp Maier | 62612e8 | 2020-05-27 16:29:22 +0200 | [diff] [blame] | 31 | #define LOGPCONN(conn, cat, level, fmt, args...) \ |
| 32 | LOGPENDP((conn)->endp, cat, level, "CI:%s " fmt, \ |
| 33 | (conn)->id, \ |
| 34 | ## args) |
| 35 | |
Philipp Maier | b0c05aa | 2020-07-06 11:52:19 +0200 | [diff] [blame] | 36 | /*! Connection type, specifies which member of the union "u" in mgcp_conn |
| 37 | * contains a useful connection description (currently only RTP) */ |
| 38 | enum mgcp_conn_type { |
| 39 | MGCP_CONN_TYPE_RTP, |
| 40 | }; |
| 41 | |
| 42 | /*! MGCP connection (untyped) */ |
| 43 | struct mgcp_conn { |
| 44 | /*! list head */ |
| 45 | struct llist_head entry; |
| 46 | |
| 47 | /*! Backpointer to the endpoint where the conn belongs to */ |
| 48 | struct mgcp_endpoint *endp; |
| 49 | |
| 50 | /*! type of the connection (union) */ |
| 51 | enum mgcp_conn_type type; |
| 52 | |
| 53 | /*! mode of the connection */ |
| 54 | enum mgcp_connection_mode mode; |
| 55 | |
| 56 | /*! copy of the mode to restore the original setting (VTY) */ |
| 57 | enum mgcp_connection_mode mode_orig; |
| 58 | |
| 59 | /*! connection id to identify the connection */ |
| 60 | char id[MGCP_CONN_ID_MAXLEN]; |
| 61 | |
| 62 | /*! human readable name (vty, logging) */ |
| 63 | char name[256]; |
| 64 | |
| 65 | /*! activity tracker (for cleaning up inactive connections) */ |
| 66 | struct osmo_timer_list watchdog; |
| 67 | |
| 68 | /*! union with connection description */ |
| 69 | union { |
| 70 | struct mgcp_conn_rtp rtp; |
| 71 | } u; |
| 72 | |
| 73 | /*! pointer to optional private data */ |
| 74 | void *priv; |
| 75 | }; |
| 76 | |
Philipp Maier | cede2a4 | 2018-07-03 14:14:21 +0200 | [diff] [blame] | 77 | /* RTP connection related counters */ |
| 78 | enum { |
| 79 | IN_STREAM_ERR_TSTMP_CTR, |
| 80 | OUT_STREAM_ERR_TSTMP_CTR, |
| 81 | RTP_PACKETS_RX_CTR, |
| 82 | RTP_OCTETS_RX_CTR, |
| 83 | RTP_PACKETS_TX_CTR, |
| 84 | RTP_OCTETS_TX_CTR, |
Stefan Sperling | ba25eab | 2018-10-30 14:32:31 +0100 | [diff] [blame] | 85 | RTP_DROPPED_PACKETS_CTR, |
| 86 | RTP_NUM_CONNECTIONS, |
| 87 | }; |
| 88 | |
| 89 | /* RTP per-connection statistics. Instances of the corresponding rate counter group |
| 90 | * exist for the lifetime of an RTP connection. |
| 91 | * Must be kept in sync with all_rtp_conn_rate_ctr_desc below */ |
| 92 | static const struct rate_ctr_desc mgcp_conn_rate_ctr_desc[] = { |
| 93 | [IN_STREAM_ERR_TSTMP_CTR] = {"stream_err_tstmp:in", "Inbound rtp-stream timestamp errors."}, |
| 94 | [OUT_STREAM_ERR_TSTMP_CTR] = {"stream_err_tstmp:out", "Outbound rtp-stream timestamp errors."}, |
| 95 | [RTP_PACKETS_RX_CTR] = {"rtp:packets_rx", "Inbound rtp packets."}, |
| 96 | [RTP_OCTETS_RX_CTR] = {"rtp:octets_rx", "Inbound rtp octets."}, |
| 97 | [RTP_PACKETS_TX_CTR] = {"rtp:packets_tx", "Outbound rtp packets."}, |
| 98 | [RTP_OCTETS_TX_CTR] = {"rtp:octets_tx", "Outbound rtp octets."}, |
| 99 | [RTP_DROPPED_PACKETS_CTR] = {"rtp:dropped", "dropped rtp packets."} |
| 100 | }; |
| 101 | |
| 102 | /* Aggregated RTP connection stats. These are updated when an RTP connection is freed. |
| 103 | * Must be kept in sync with mgcp_conn_rate_ctr_desc above */ |
| 104 | static const struct rate_ctr_desc all_rtp_conn_rate_ctr_desc[] = { |
| 105 | [IN_STREAM_ERR_TSTMP_CTR] = {"all_rtp:err_tstmp_in", "Total inbound rtp-stream timestamp errors."}, |
| 106 | [OUT_STREAM_ERR_TSTMP_CTR] = {"all_rtp:err_tstmp_out", "Total outbound rtp-stream timestamp errors."}, |
| 107 | [RTP_PACKETS_RX_CTR] = {"all_rtp:packets_rx", "Total inbound rtp packets."}, |
| 108 | [RTP_OCTETS_RX_CTR] = {"all_rtp:octets_rx", "Total inbound rtp octets."}, |
| 109 | [RTP_PACKETS_TX_CTR] = {"all_rtp:packets_tx", "Total outbound rtp packets."}, |
| 110 | [RTP_OCTETS_TX_CTR] = {"all_rtp:octets_tx", "Total outbound rtp octets."}, |
| 111 | [RTP_DROPPED_PACKETS_CTR] = {"all_rtp:dropped", "Total dropped rtp packets."}, |
| 112 | |
| 113 | /* This last counter does not exist in per-connection stats, only here. */ |
| 114 | [RTP_NUM_CONNECTIONS] = {"all_rtp:num_closed_conns", "Total number of rtp connections closed."} |
Philipp Maier | cede2a4 | 2018-07-03 14:14:21 +0200 | [diff] [blame] | 115 | }; |
| 116 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 117 | struct mgcp_conn *mgcp_conn_alloc(void *ctx, struct mgcp_endpoint *endp, |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 118 | enum mgcp_conn_type type, char *name); |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 119 | struct mgcp_conn *mgcp_conn_get(struct mgcp_endpoint *endp, const char *id); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 120 | struct mgcp_conn_rtp *mgcp_conn_get_rtp(struct mgcp_endpoint *endp, |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 121 | const char *id); |
| 122 | void mgcp_conn_free(struct mgcp_endpoint *endp, const char *id); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 123 | void mgcp_conn_free_oldest(struct mgcp_endpoint *endp); |
| 124 | void mgcp_conn_free_all(struct mgcp_endpoint *endp); |
| 125 | char *mgcp_conn_dump(struct mgcp_conn *conn); |
| 126 | struct mgcp_conn *mgcp_find_dst_conn(struct mgcp_conn *conn); |