Commit Graph

91 Commits

Author SHA1 Message Date
Philipp Maier 6fbbeec064 mgcp_trunk: pick trunk by number and type
The function mgcp_trunk_by_num() is used to directly pick a specific
trunk that is known by its id number (sometimes called "index").
Traditionally the virtual trunk will reside under id number 0 and all
consecutively created E1 trunks will be created under number 1 to 64.
This works fine, but puts a limitation on us should we ever introduce an
aditional trunk type (e.g. T1). Since the numbers must be unique
regardless of the trunk type one could not have an E1 trunk number 1 and
e.g. a T1 trunk number 1 at the same time. So we should pick the trunk
not only by its number, but also by its type to allow different trunk
types to carry the same number. The trunks will still be distinguishable
by its type along with the respective endpoint prefix.

Change-Id: I7af1e9ce601babd4a51e88201a98319e03945f83
Related: OS#2659
2020-07-07 12:45:14 +02:00
Philipp Maier d19de2ee80 trunk: get rid of virt_trunk pointer
The virtual trunk is a pre-configured trunk that always exists. It is
kept separate from the trunk list using a separate pointer. This makes
thinks unecessarly complicated. Lets organize the trunk in the trunk
list like any other trunk, except that we automatically create it on
startup and assign it always the trunk id number 0.

Change-Id: I81934fbd211b225ab7920e78510729c8e22607b3
Related: OS#2659
2020-06-18 12:03:19 +02:00
Philipp Maier c66ab2c4c3 osmo-mgw: refactor endpoint and trunk handling
The trunk and endpoint handling in osmo-mgw is still very complex and
implemented in various places (mostly mgcp_protocol.c). Also we use
still integers for endpoint identification, which is not flexible enough
to address timeslots/subslots on an E1 trunk. Some refactoring is needed.

  - get rid of integers as endpoint identifiers, use strings instead and
    find the endpoint based on its string name on the trunk.

  - identify the trunk based on the trunk prefix given in the endpoint
    name.

  - refactor trunk and endpoint allocation. Aggregate functionality in
    in mgcp_endp.c and mgcp_trunk.c. Also remove non-reusable code that
    relates to the still exisiting, but unfinished E1 trunk support.

  - refactor rate counters, put them into a separate module and do no
    longer allocate them per trunk. Allocate them globally instead.

Change-Id: Ia8cf4d6caf05a4e13f1f507dc68cbabb7e6239aa
Related: OS#2659
2020-06-12 17:08:41 +02:00
Harald Welte c39b1bffec mgcp_protocol: Avoid code duplication between virtual + other trunks
There were two code paths that were supposed to do exactly the same,
but then in Change-Id I3994af016fb96427263edbba05f560743f85fdd4 only
one of the two was modified, resulting in OS#4034

Let's
* dynamically allocate the virtual trunk
* rename mgcp_config.trunk to mgcp_config.virt_trunk to clarify
* as a result, abolish copy+pasted code for trunk initialization

Change-Id: I54762af6d417b849a24b6e71b6c5c996a5cb3fa6
Related: OS#4034
2020-05-28 09:23:25 +00:00
Pau Espin a7152e055a Use OSMO_FD_* instead of deprecated BSC_FD_*
New define is available since libosmocore 1.1.0, and we already require
1.1.0, so no need to update dependenices.
Let's change it to avoid people re-using old BSC_FD_* symbols when
copy-pasting somewhere else.

Change-Id: I9b6463af713f76c06a144bdbf202c0d91eef4d21
2020-05-09 19:15:50 +02:00
Pau Espin df7d97e4b4 osmux: Fix hardcoded rtp payload_type 98 in osmux conn
Depends on: libosmo-netif.git I5cbeb494a8932953d9fd2dc24dacf8cd97fd84e4
Change-Id: I24698a9613bc0de9460c6ad2d1067c152ebcf0b2
2019-05-19 19:28:49 +02:00
Pau Espin 85978dadab osmux: Fix CID release for non-enabled connections
Change-Id: If65c70b421476776e20233733722d72aa26d69a8
2019-05-19 07:31:51 +00:00
Pau Espin c1ad553d86 osmux: Use DUMMY ft msg as per Osmux spec
That MGCP_DUMMY_LOAD is an old hack prior to Osmux spec update, and it's
not nice since it cannot be 100% distinguished from a usual AMR ft
frame.

Let's use the correct DUMMY ft type and build it according spec. Allow
handling differently the old format for a while until we are sure no old
implementations (like bsc-nat) exist sending that kind of message.

Change-Id: Ib17d20b87b28aade49ba60519b56a96e694819af
2019-05-15 23:00:55 +02:00
Pau Espin 1442c5a99e osmux: Redo read/write osmux glue code to have data routed correctly
Remove old BTS/NET no longer in use and meaningless. Use new osmo-mgw
APIs to inject payload RTP<->Osmux on the correct socket and conn.

Change-Id: I60b6ba3ffdc74efff945ba13a0b736798bdf5d8c
2019-05-14 11:36:33 +02:00
Pau Espin dac2ca7e21 osmux: Delay osmux enable of conn until remote addr is configured by MDCX
Change-Id: I243e53681ebeb3d9cd8ed38bb132172b41745795
2019-05-14 11:36:33 +02:00
Pau Espin 375252279c osmux: Improve logging around osmux enabling events
Change-Id: Iab687b97010fd484cb353b240b120c9c382066fa
2019-05-14 11:36:33 +02:00
Pau Espin 295570c631 osmux: Use remote port to send osmux frames
Previously the local one was used but nobody cared because probably
everybody was using default 1984 on different IP addresses.

Change-Id: I01e590465fa247185d74103578681e9041249099
2019-05-14 11:36:33 +02:00
Pau Espin fa810e8ccd osmux: Mark conn_rtp->type as osmux during CRCX
We also update code to allow setting up RTP related fields to succeed
during CRCX. We also update code to allow setting up RTP related fields to
succeed during CRCX.

Change-Id: Ia6e723d9a28ba38fc3382a4fb35ea6e5bab30c09
2019-05-13 18:56:56 +02:00
Pau Espin 120568651a cosmetic: osmux: Document network byte order in port variable
Change-Id: Ia367ef08625265bc9cbdfcc693720a9b88852f4a
2019-05-13 18:56:56 +02:00
Pau Espin c9a6280c94 osmux: Use LOGPCONN in several log calls
Change-Id: Ieb2c4b53db2df44e0dfbedb7de76d8cf6c83da91
2019-05-13 13:20:13 +02:00
Pau Espin b5583cde41 osmux: Fix reception of legacy dummy payloads
Size check had a bug. Take the opportunity to print wrong frames on
error.

Change-Id: I9f0d4e28a2019c7ad94344f2c34d17c365bebea9
2019-05-13 12:59:51 +02:00
Pau Espin f027f17dcb osmux: Log osmux socket during osmux_init
Change-Id: I43a658b19765b1c3b3cc42f78602b793ee36c67d
2019-05-06 17:41:37 +00:00
Pau Espin ac772d8b0c mgcp_osmux.c: osmux_enable_endpoint: Fix incorrect return check
osmux_xfrm_input_open_circuit returns 0 on success and -1 on error.
Confusion comes from that function being implemented by calling
osmux_batch_add_circuit which returns NULL on error.

cherry-picked from: openbsc.git ac1b03c8e59408336d07527e2597171cb99ed654.

Change-Id: Iba018aa57901642ea4c486526a973fe6023e10cf
2019-05-06 18:02:02 +02:00
Pau Espin 8de58e79b8 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
2019-04-25 21:38:38 +00:00
Pau Espin ff6606cacb osmux: Avoid processing further frames if conn not found
Other frames can come from known connections, so let's keep processing
each of them.

Change-Id: I09190140ba917dfada4b0952230b68e0f5f6d43d
2018-10-16 16:45:43 +02:00
Pau Espin de2a4d7c22 osmux: Improve checks around activating and using enabled osmux
* Refactor code to have unified checks on all paths activating Osmux.
* Improve checkings at activation time and add logging.
* Code now enforces endp osmux status to be enabled before processing
the frame through endp->osmux.out. Before, a delayed or bad pkt could
arrive and be processed by an endp with osmux not enabled, using
endp->osmux.out that was not initialized and ended up crashing:
libosmo-netif/src/osmux.c:281:3: runtime error: member access within null pointer of type 'struct msgb'

This could also happen if a BSC started sending or we received (non legacy dummy) osmux
frames before we received the BSC CRCX ACK agreeing on osmux negotiation
and switching to ACTIVATING state.

Related: SYS#4350

Port from openbsc 4a2cc9eb0a0f9424c16b26fcb757483a39d67482.
Includes fixup from openbsc I438349bffaa46a10ad8983090a4b17aed7e00d82.
Change-Id: Iac11e447ec0d76e4e74ec982a6e3f63b35548978
2018-10-16 16:44:49 +02:00
Pau Espin 48aff62341 osmux: allow enabling osmux only on correct activating state
State ACTIVATING is set once negotiation between the 2 parts went
successfuly.

Port from openbsc 96bd7b075a59eb051079152241b127ca944b0781.
Change-Id: Ic56eda1251be41369d869e687a1cf955df2c6d61
2018-10-16 16:43:42 +02:00
Pau Espin 852ba86949 osmux: Make func handling dummy frames independent of endp type
Port from openbsc 8f321179747f64819d940d72d0212192f69284ca.
Change-Id: I3e16217737fd5ffb95c166c5f7344492cb6a6263
2018-10-16 16:43:34 +02:00
Pau Espin 662fa421c6 osmux: Move parse_cid of legacy dummy frames to own function
Backport from openbsc b010f869c915016b7fa97a26621582cd89de96b0.
Change-Id: I5766165985fbfcecc63d45b9e229322bc8cedf52
2018-10-16 15:54:40 +02:00
Pau Espin d14163e74f osmux: Don't process regular osmux frames if disabled by cfg
Prior to this commit, the check was only done on legacy dummy frames.

Port from openbsc a42d4584fd01c9cd1021fab609bdaaafe859c13a.
Change-Id: I5b6606d72a9f5ae593a8e3ab5fbbe7e1e5a0ae11
2018-10-16 15:49:02 +02:00
Pau Espin 11b4810142 osmux_send_dummy: Avoid logging incorrectly and sending if osmux not enabled
Port from openbsc 37a0307b6193c9b108cfd1aa2a88517a8b5cb907.
Change-Id: Iabc84cb482a425d4a6c2bb08c20b2e02a5a86b36
2018-10-16 15:45:59 +02:00
Pau Espin 9ecceb651b mgcp: Log endpoint nr consistently as hex
Port from openbsc 078905a0603c91b227854abfa01c9e24143e39a1.
Change-Id: Idcb40e6fd561b24e111afe7463f44c43c530fac5
2018-10-16 15:36:08 +02:00
Pau Espin 426a9d9103 osmux: Avoid initing output without enabling osmux
Otherwise we end up in a weird state where we have timers set up but
osmux is still flagged as not enabled.

Cherry-picked from openbsc cad739d2386640a68c24e3d470ddacdcaf377561.
Change-Id: I0a334842463d311bc80a980e60fb702a0a9ad610
2018-10-16 15:31:49 +02:00
Pau Espin 17bf603222 mgcp_osmux: Use define to calculate rtp_ssrc_winlen
Since that define is already used to allocate size of osmux_cid_bitmap,
let's use it here too instead of hardcoding its value.

Change-Id: Ib2e4febee8bc6bcc035ad0a65c5c1eb94ef5e6fb
2018-09-17 13:38:46 +02:00
Pau Espin bcd52e5724 mgcp: Fix osmux_cid_bitmap static array size calculation
Right now it's not a big issue since OSMUX_CID_MAX is 255, so 255+1 is
256 which fits array boundaries correctly (multiple of 8). However, if
for example OSMUX_CID_MAX was modified to be 12, 12+1/8 = 1, so we'd
have an undesired memory access when accessing last 4 CIDs.

A +1 should be kept on top, because OSMUX_CID_MAX specified the maximum
number used by a CID, that is (0,OSMUX_CID_MAX), and as a result we
require OSMUX_CID_MAX+1 slots.

Change-Id: Iaf9b93712dbd2a862b01e70dd8e11893bfa6b24c
2018-09-17 13:36:36 +02:00
Philipp Maier cede2a4b7c stats: replace packet statistic counters with libosmocore rate counters
In struct mgcp_rtp_end one finds unsigned int counters. Those should
be replaced with libosmocore rate counters

- replace packets_rx, octets_rx, packets_tx, octets_tx and
  dropped_packets with libosmocore rate counters.

Change-Id: I47c5c9006df5044e59ddebb895e62adb849d72d5
Related: OS#2517
2018-07-05 15:55:19 +02:00
Pau Espin f2321b7a72 mgcp: switch to new osmux output APIs
Older ones are being deprecated as they may generate interleaved
packets.

Change-Id: I0705aa4dc4b02eaff4d6030795243e6720f7fddf
2018-05-19 12:06:12 +00:00
Pau Espin 4219904cb2 mgcp: mgcp_osmux: use conn_bts when forwarding pkts from bsc_nat
This commit actually doesn't fix the entire code, since anyway osmux
conns are not supported and mgcp_conn_get_rtp() will return NULL.
However, it makes the code more logical and easier to understand once
somebody refactors the code to make it work again.

Change-Id: Ib57e12e5a36b5842c40673c236907bbcbfc390f3
2018-05-19 12:06:12 +00:00
Philipp Maier 37d11c80da cosmetic: rename mgcp_ep.c/h to mgcp_endp.c/h
The short term of endpoint has always been "endp" througout the whole
project and not "ep".

- rename mcgp_ep.c to mgcp_endp.c

- rename mgcp_ep.h to mgcp_endp.h

Change-Id: Id52047bb2d0407655ac272c858ed3412b8ae9e6d
2018-02-05 10:32:42 +01:00
Philipp Maier fdd603c4c8 ep: move endpoint struct and define to mgcp_ep.h
The endpoint and the define that computes the endpoint number is
defined in mgcp_internal.h. Since we have a dedicated module for
endpoint related code it makes sense to move the endpoint related
parts there.

- move struct mgcp_endpoint to mgcp_ep.h

- move #define ENDPOINT_NUMBER(endp) to mgcp_ep.h

Change-Id: Ibae55e1859bd41e2d1918eda433418b4bf8365fe
2018-02-05 10:32:42 +01:00
Harald Welte 1d1b98f4a4 libosmo-mgcp: Cosmetic spelling fixes in comments
Change-Id: Ic0469c2a4d69b55a6a90653ad7ea1ad89a34e4bc
2017-12-25 10:10:29 +01:00
Harald Welte a0ac30faa5 mgcp_rtp_end: Group statistics members into 'stats' sub-struct
Change-Id: I4e0ecdcd9a75fe08abc55b730780c01617f3d4af
2017-12-25 10:10:29 +01:00
Philipp Maier 01d24a3281 MGCP: Connection Identifiers are hex strings
The MGCP spec in RFC3435 is quite clear: Connection Identifiers are
hexadecimal strings of up to 32 characters. We should not print and
parse them as integers on either client or server.

Change the internal uint32_t representation of connection identifiers
to a string representation in the client and also in the server.

Closes: OS#2649
Change-Id: I0531a1b670d00cec50078423a2868207135b2436
2017-12-01 11:58:23 +00:00
Philipp Maier ddf1f9d7d5 osmux: fix nullpointer dereference
in point_lookup() the connection pointer is determined using
mgcp_conn_get_rtp() this function may return 0. At the moment
there are no nullpointer checks implemented

Add checks to test for nullpointer.

Fixes: Coverity CID#178662
Change-Id: If9a3c1ac002bc8adc90ca1c1c3dd1db4feea07ac
2017-11-10 21:30:19 +00:00
Philipp Maier 87bd9be0b0 Initially implement the new osmo-mgw and libosmo-mgcp
Leave the old osmo-bsc_mgcp and libosmo-legacy-mgcp as it is; on a copy thereof
(added by a previous commit), apply changes to initially implement the new
osmo-mgw.

Adjust build system and debian packaging to accomodate the new libosmo-mgcp and
osmo-mgw.

The main differences:

*) use a list to manage rtp connections.

Aggregate all rtp related information inside a single struct.

Use a linked list to manage the both connections (net and bts).
The idea behind using a list is that we might support conference
calls at some later point.

Store the linked list in struct mgcp_endpoint, have a private linked
list for each endpoint. The list contains connection items which are
implemented in struct mgcp_conn. A connection is allocated and freed
using the functions in mgcp_conn.c. A connection is allocated on the
reception of a CRCX command and freed with the reception of a DLCX
command.

*) remove external transcoder feature

Fortunatelly the external transcoder feature is not needed
anymore. This patch removes the related code.

*) vty: get rid of CONN_BTS and CONN_NET

Since the new connection model does not make a difference
between BTS and NET connections the VTY should not use
the fixed CONN_BTS and CONN_NET constants.

- Handle the conns list inside the endpoint directly
- introduce function to dump basic rtp connection info
- introduce human readable names for connections

Parts of the code adjusted to use generalized connections instead of explicit
BTS/NET ones:

- teach mgcp_send_dummy() to send dummy packets to any RTP connection
- network: generalize mgcp_bind_net/bts_rtp_port()
- network: generalize mgcp_send()
- tap: generalize call tapping feature
- stat: generalize statistics
- Replace rtp_data_net() and rtp_data_bts() with generalized rtp_data_rx()

*) mgcp_protocol.c fixes:

- check ci string before it is converted:
  In case of missing ci, a nullpointer is delivered to strtoul().
  Add a function that takes ci, checks it and converts it to an
  uint32_t. Use the return code to react on missing ci.
- output error message on missing CI.
- when parsing the mode, print log message when mode is missing.
- use mode_orig when mode is missing.
- fix ptime formatstring to use %u rather than %d.
- cosmetic: log when connection is deleted on DLCX.
- change loglevels of CRCX, MDCX, DLCX events from DEBUG to NOTICE.

*) mgcp_test

- apply rename of strline_r() to mgcp_strline().
- MGCP command macros:
  - Add 'I: 1' parameters.
  - Use proper port numbers:
    from m=audio 0 RTP/AVP 126
    to   m=audio 16002 RTP/AVP 128
  - Change ptime to 'a=ptime:40' because this is what the MGW currently
    returns.  CRCX generally feed a ptime:40 and this is expected to be
    returned.
- struct mgcp_test: Use only one ptype, there are no explicit BTS and NET
  endpoints anymore.
  Hence remove one column from tests[].
- test_messages():
  - Enable: remove '#if 0'
  - Remove concept of BTS and NET endpoints: test only one conn, as they are
    now interchangeable anyway.
  - remove endpoint init, now done internally.
  - add false asserts in error cases.
- test_retransmission():
  - remove endpoint init, now done internally.
  - add false asserts in error cases.
- test_packet_error_detection():
  - Remove concept of BTS and NET endpoints: test only one conn, as they are
    now interchangeable anyway. Use arbitrary conn ids (e.g. 4711).
  - remove endpoint init, now done internally.
  - add false assert in error case.
  - Assert that a conn really vanishes on DLCX, previously the conn would
    remain and just be unused, now it is actually discarded.
- test_no_cycle()
  - Remove concept of BTS and NET endpoints: test only one conn, as they are
    now interchangeable anyway. Use arbitrary conn ids (e.g. 4711).
- test_no_name()
  - Enable: remove '#if 0'.
  - remove endpoint init, now done internally.
  - add false assert in error case.
- mgcp_test.ok: adjust expected results to status quo:
  - We now see two dummy packets instead of one, now sent to both sides because
    we don't know of BTS or NET side. (maybe drop dummy packets later...)
  - packet duration, conn mode: now sane defaults show instead of unset.
- various whitespace and formatting changes from lindent.

Change-Id: Ie008599136c7ed8a0dfbb0cf803188975a499fc5
2017-10-05 01:40:43 +00:00
Neels Hofmeyr f83ec56212 create libosmo-mgcp and osmo-mgw by copying legacy code
This a cosmetic commit, copying libosmo-legacy-mgcp to libosmo-mgcp and
osmo-bsc_mgcp to osmo-mgw 1:1 at first, to provide a basis for next patches
that highlight the changes from legacy to new code.

Until osmo-msc and osmo-bsc are adjusted to operate with the new code, we will
keep the legacy code alongside the new code. The legacy code might be dropped
later.

Change-Id: Idf54481754a1765bdb2d0d7033bc0d7dc2018024
2017-10-05 01:40:43 +00:00