Commit Graph

146 Commits

Author SHA1 Message Date
Harald Welte 3f342ee28c octoi: differentiate UNDERRUN from SUBSTITUTED in counters
A real _underrun_ happens if the RIFO is empty (depth == 0)
and should be counted different from a mere frame substition
due to packet loss.

Change-Id: I5448430b09ec10a16decdfd0a4a40850fe2ed1a6
2022-04-20 15:50:32 +02:00
Sylvain Munaut d413cbcb4b octoi: Fix frame_rifo_depth() function
We use the 'correct' math in frame_rifo_depth now so the
count is accurate down to zero.

We need to fixup the logic that drags the 'write pointer'
(last_in_fn) along when reading from an empty FIFO.

We also need proper init (which was missing alltogether
beforehand).

Change-Id: I088f181e74358eb2c96a7aab7a7c875b9276d980
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2022-04-20 15:48:26 +02:00
Sylvain Munaut ce817ca149 rifo_test: Use a helper function for the rifo init
Because we poke at some of the internals we need to make
sure to maintain the internal state consistent.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I5d9397be391c60f732c89f158d25660e1f32cfac
2022-04-20 15:48:26 +02:00
Harald Welte f226f50d12 rifo_test: print rifo_depth + rifo_frames on every IN/OUT
This shows that rifo_depth is off-by-one for all but the 'empty'
case.  It is intended that 'make check' will fail after this commit,
before the next commit with the fix is introduced.

Change-Id: I1be1889800c83d251d17801f31040c137c06a46d
2022-04-20 15:48:26 +02:00
Harald Welte 30530ff4a7 octoi: Disconnect the link when >= 7500 underruns/s
This situation is the result of the peer clock being continuously
too slow compared to the local clock, leading to RIFO underruns at
[virtually] all of the 8000/s E1 frames.  As the current code doesn't
recover from this, we might as well disconnect and re-start for
recovery.

Change-Id: Ie3fffa1c1c20962b40320c8cc088c140b8d64e77
2022-04-20 14:48:48 +02:00
Sylvain Munaut 8a2e82560c octoi: Simple RX priming / pre-filling
This was not an issue with the original FIFO code, which dynamically
substituted frames and always created the minimal required backlog.

The RIFO can by principle not operate this way, so we really have to
prime / pre-fill it with a number of TDM frames.  That initial fill
level has to be sufficient to cover RTT jitter of the OCTOI link as
well as clock drift between (GPS synced) receiver and transmitter.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I3a4b3846d3dbd1c99989e994ad95e609f2757219
2022-04-19 19:31:18 +02:00
Harald Welte 99161f1423 octoi: Reset FIFO/RIFO when entering ACCEPTED state
For both OCTOI client + server FSM, whenever we enter the ACCEPTED
state (we disconnect), let's reset the RIFO/FIFO state.  This makes
sure no left-over frames from some earlier connection are present,
and also ensures our initial frame number expectations are correct.

Change-Id: I9e721b5dbf22728cb2361ed121d12def7016dcc2
2022-04-19 19:20:48 +02:00
Sylvain Munaut accfded547 OCTOI: Fix the extension of 16b FN from packet to full 32b FN
Only frames withing a certain window are even accepted for processing
the rest is dropped since it could corrupt our state.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I25b2e150d924aa8c714b766cb92e9e23e67cfa4c
2022-04-19 17:59:05 +02:00
Harald Welte f23274d184 e1d: stat_items for the GPS-DO related bits
It is interesting from a monitoring point of view to be able to
correlate the GPSDO state with other performance counters we export.

While each GPS-DO only exists once per icE1usb, we still export the
state per line, to make it easy for external monitoring to have one set
of counters per line.

Change-Id: I1f98610b7c725146a3f016a8737440be5baae858
2022-04-19 17:55:25 +02:00
Harald Welte f7716183a5 octoi: Add new rate-counter for out-of-order packets
Change-Id: Ie97c1efecf8b673620ddc097e0184f8a9c92c3f0
2022-04-19 17:12:42 +02:00
Harald Welte 7fb09b8884 Add rate counters for number of frames muxed/demuxed (E1 side)
Nominally this is of course 8000/s, but this patch should allow us to
verify this in monitoring.  Note that the rate_ctr base of course is
"wrong" as it uses the normal system clock, which is much less precise
than the E1 clock of an icE1usb with GPS-DO.

So it really only helps us to compare Rx against Tx or against other
values/counters derived from the TDM clock.

Change-Id: I40e9fb38561410fbf0902b8a390673690a36ea5e
2022-04-19 15:04:53 +02:00
Harald Welte 0d67df2307 octoi: Update RIFO depth also on dequeue
We updated the RIFO depth on every enqueue, let's also do so on dequeue.
Otherwise the figure might be wrong in case of no further received input
frames.

Change-Id: I175f0503e7435c362f35bd8083b785197d9d7338
2022-04-19 14:57:20 +02:00
Harald Welte b22bcd2059 Fix stats exporter
We called osmo_stats_vty_add_cmds() but we didn't call
osmo_stats_init(), resulting in the user being able to configure stats
reporting, but osmo-e1d would simply never generate the related UDP
packets :(

With this commit, osmo-e1d starts to generate the related packets.

Change-Id: Ic373d3056d044af797664215b08ba0880675ae53
2022-04-18 19:31:36 +02:00
Harald Welte 6d51f79931 Set rate_ctr_group name for each line
"Counters for each line in e1d 256" is not very useful unless you
know that it's "(intf_nr << 8) | line_nr" and 256 == I1/L0.

Let's set the name string explicitly.

Change-Id: I200e068f1bbc495fb806402877551924beea214e
2022-04-17 12:57:29 +02:00
Harald Welte 973ce5c507 Make use of libosmcoore cpu_sched_vty
osmo-e1d automatically uses SCHED_RR already, but for consistency it
actually makes sense to add this, so people can configure the scheduler
priority and/or the cpu affinity this way.

The existing call to SCHED_RR is left in place for backwards
compatibility.  The new VTY commands can just override that, if needed.

Change-Id: I1b8021e6dc864af6e301fced427e24c8bb21ca2f
2022-04-17 12:57:24 +02:00
Harald Welte 1ed219a191 octo: give rate_ctr / stat_items meaningful identifiers
We don't want useless identifiers like 'E1oIP line 5518' but something
that we can understand, like the user account name, or in absence
of that, at least the IP/port.

Change-Id: Ibd98b9606a1d9d5b76d63be83eb3df9e431ab3ad
2022-04-17 12:16:56 +02:00
Harald Welte db59c3f4b9 OCTOI: re-implement LINE_STAT_E1oIP_E1T_FIFO
There use to be a stat_item for the depth of the E1-terminated FIFO, as
in a FIFO this is very easy to determine.  When we switched to RIFO, it
was lost.  Let's re-introduce it with the approximate depth of the RIFO.

Change-Id: I960cbf196ae930b1b72745b8bfe9c2a21fd53325
2022-04-17 11:37:29 +02:00
Sylvain Munaut 2c0af2fa98 RIFO: Add a test for bounds checking
This tests exactly one frame before and one frame after what
should be accepted to make sure those are rejected

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I048e1b8c2b918f7ca4b4327b89bf04430a2838bc
2022-04-14 20:17:14 +00:00
Sylvain Munaut 712d234ca4 RIFO: Fix issue in frame number bounds checking
You can't have a 'min' and 'max' FN because of the wrap
around this needs to be checked "all at once".

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Ie9024f84f79b458248786bca2343a1f8bffb9994
2022-04-14 20:16:32 +00:00
Sylvain Munaut d74c51cda2 RIFO: Fix operator precedence issue in the math for bucket_for_fn
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Iff91cfe93e8c7b53998b1b4dd73684292c105cc8
2022-04-14 20:15:12 +00:00
Sylvain Munaut 1cc564d81a RIFO: Minor typo/comment fixes
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I9b6181f9136b7963681c472b017d005022d27e6e
2022-04-14 20:13:59 +00:00
Harald Welte 97b15ae397 vty: Print only applicable information during 'show line'
If the line is in channelized mode, only print per-TS information.
If the line is in superchannel mode, only print SC information.

This avoids printing information that is not applicable to the line
mode.

Change-Id: I7b55ae8a5e1d352f90e14342d7f7e82e4848118a
2022-04-10 17:35:15 +02:00
Harald Welte 9f3498681a fix segfault on 'show octoi-server' if no server configured
Change-Id: I23697f858337948555456b71539b9afe8c3730b9
2022-04-10 17:35:13 +02:00
Manawyrm c72f38feac RIFO: add more thorough tests and a vetted test.ok file
This commit adds 2 new tests:
 - too old frames (which should get dropped)
 - already correct frames (which shouldn't be touched)

In addition, every test will now be run twice.
Once at frame number 0 and once very close to the wrap-around of
the internal frame counter in order to observe the behaviour.

Change-Id: I930b4361924b2e8bcb566eb7ee64f36e06bc7745
2022-04-09 13:21:52 +02:00
Manawyrm 480d989d62 RIFO: fix frame_rifo_in check on frame number wrap-around
frame_rifo_in would previously return -ERANGE when a frame was written
which was at the edge of the wrap-around of the frame number (because
the maximum value was already across the boundary)

Also: fixed some typos
Change-Id: I88abfc77543d5c64b01f40944b2914e03e57d08f
2022-04-09 13:21:52 +02:00
Harald Welte 38b1c5d3f0 RIFO (random in, first out) for IP->E1 direction
In the past, we used a FIFO structure (first in, first out) - which
obviously cannot deal with packet re-ordering on the IP side.

This patch introduces a new "RIFO" as a replacement for the FIFO.

The RIFO is able to reconstruct E1 frame ordering by using the
reduced frame number from the TDMoIP messages, at least as long
as the related frame number range is within the current RIFO depth.

Change-Id: I22256870114cb85e4e10932554478be7061e086b
2022-04-09 13:21:49 +02:00
Harald Welte 322fbc4901 add example config files for octoi-server and octoi-client
Change-Id: Ia427eb62bbfecea12c31584996a57cb82aa097a0
2022-04-05 22:00:36 +02:00
Harald Welte e324507676 OCTOI: initial support for E1oIP forwarding
This introduces initial support for operation as OCTOI (Osmocom
Community TDMoIP) server and client operation.

Various features are still absent (user authentication, support for
re-ordered packets), but this version is already able to provide
services to clients with dynamic IP addresses as well as servers.

The bulk of the OCTOI / E1oIP code is implemented as a shared library,
to facilitate the development of other servers and clients in the
future, and also to minimize the impact on the existing osmo-e1d code
base.

More information is available at https://osmocom.org/projects/octoi/wiki

Change-Id: I05f5ff697ca8f7dccdcf89660f12089babfcc92e
2022-03-28 12:26:09 +02:00
Harald Welte 8ec461ebe8 vty.c: Fix re-reading of config file after 'write file'
When writing the timeslot mode, we must write it in lower-case,
as the VTY parser reading the config file only supports that.

Change-Id: Ic60449a0ba64117a5cf5e4a8e76484e9c955f09f
2022-03-28 12:13:08 +02:00
Harald Welte 16403fce90 mux_demux.c: Use %zu for size_t
This avoids compiler warnings on 32bit ARM builds

Change-Id: Ice43fb7c4514d364a3ae305847f28197a4f6cb2d
2022-03-28 12:13:08 +02:00
Harald Welte 0e194d4cd7 intf_line: Ensure unique rate counter group indexes
When we have multiple interfaces, we cannot simply use the line->id
as rate counter group index, but should use a combination of interface
id and line id.

Change-Id: I515c1f39285489845f88c3403ebf16835571e154
2022-03-28 12:13:08 +02:00
Harald Welte 620d7d3586 cosmetic: curly braces around multi-line blocks
This reflects our general coding style.

Change-Id: Ibf8ebe4c9fdde2bd66ce6239c8eca833e71fc815
2022-03-28 12:13:08 +02:00
Harald Welte 2819d3fb79 intf_line.c: Make e1d_find_intf_by_usb_serial safe for empty string
Avoid segfault in case the empty string is passed as serial_str.

Change-Id: Ia69912cb714441415d8decd68890d1b97b77132d
2022-03-28 12:13:08 +02:00
Harald Welte 591249a3c2 cosmetic: Remove extra empty newlines from end of intf_line.c
Change-Id: Ie1e193c3d851871c9c96394eb19f5b99c09913f9
2022-03-28 12:13:08 +02:00
Harald Welte 42c443f42d e1d.h: add #pragma once
all other header files already have it in place.

Change-Id: Ia7a7856563c2c9d422b73fdc431e0ea4d456f9aa
2022-03-28 12:13:08 +02:00
Harald Welte f18dcc706f usb: rename 'size' to 'len' in callback functions
What we are passing is not the [underlying] size of the buffer, but
the length of the valid data in them.

Change-Id: I8ce91527351a56c103bd077c9565be2a81d175ac
2022-03-27 17:14:49 +02:00
Harald Welte 8e3924db25 Proper libusb error reporting in all error paths
... using libusb_strerror().

Change-Id: Id205f1cf1bbccd83b789f8ab31fe1d5d4e1fb8a9
2022-02-07 18:38:08 +01:00
Harald Welte 7bc8404f63 GPS-DO support for icE1usb hardware
This adds support for monitoring the GPS-DO that is built-in to the
icE1usb device.  It assumes a very recent firmware with GPS-DO control
moved to a separate USB interface, i.e. after osmo-e1-hardware.git
Change-Id Icd6555a14896c38626fb147b78af44ff719f2254 is merged.

Change-Id: If5e2a6b2dae0290ce3186009e68f618049ebf5ff
2022-02-07 18:38:08 +01:00
Harald Welte f5362e9217 Allow configuration of interfaces/lines via VTY
So far, osmo-e1d automatically opened all compatible icE1usb devices
and all E1 lines on those interfaces.  Let's allow for 'interface' and
'line' configuration in the VTY.  USB devices can be identified by
their serial number string.

If a given device (== E1 interface)  has a VTY configuration, then only
those E1 lines with VTY configuration opened.

For each Line (icE1usb or vpair), the mode (channelized/superchannel)
can also be set via VTY.

Change-Id: I89b57b688b68901f87d9683ab9294772ee747d77
Closes: OS#5400
2022-02-01 17:17:31 +00:00
Harald Welte ef69fd1a63 e1_{intf,line}_new: Allow caller to specify the numeric identifier
This will be used by the upcoming VTY interface changes.

Change-Id: I9ff80831a3e3e3cb6dae178f8b438a9f3f4747df
2022-01-31 19:51:14 +01:00
Harald Welte 9d6dab8992 update copyright statement
Change-Id: I1b4817207369e572a2b070443475289cc527c317
2022-01-31 14:49:31 +00:00
Harald Welte 3fd3df13b5 make rate_counters work
if we don't call rate_ctr_init(), the rate counter internal timer will
not tick,a nd we will never get the per-s/per-m/per-h averages.

Change-Id: Ib5b66c72079330ac161756bcf562d27536d7ce44
2022-01-31 14:49:26 +00:00
Oliver Smith e53eed98ea checkpatch.conf: new file
Related: OS#5399
Change-Id: I4bd109009cbe16f313e19ab78bd5fbcb13b0f656
2022-01-18 09:44:03 +01:00
Harald Welte c6246b654b usb: Use libusb_status_str when logging INT EP error
Change-Id: I3a3cd88ba35796740dbd399eb618617941dae54a
2022-01-10 11:00:06 +01:00
Harald Welte a3ff181a82 usb: Print failed USB isochronous packets
Change-Id: Ib6fcf46be40d47817632ccae4e742d6cf7340cda
2022-01-10 11:00:03 +01:00
Harald Welte 3fff68cbf8 cosmetic: Adhere osmocom coding style in for-loops
We either have to bring osmo-e1d in line with other osmocom projects,
or we'd have to disable the linter in jenkins.

Change-Id: I74ab20b22118d471dcdb60d1b9681ab62eb13d51
2022-01-09 23:39:42 +01:00
Sylvain Munaut 7cc8a7b806 contrib/e1-prbs-test: Delay the TX pipe fill data until first RX
There is non negligible time between the moment init_timeslot is
called and the moment when we get the first RX (which is when
we start sending out data at the same rate we RX it). And those
1024 byte were borderline not enough to not underflow.

By delaying the 1024 byte pre-fill until we get the first RX,
we ensure the time that pre-fill covers is more consistant and
less dependend on whatever the app/scheduling does during the
init phase.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Ic1c93fd138073a75830dc16bb41c4541e68eef90
2022-01-09 15:09:11 +01:00
Sylvain Munaut 3729f8f90e mux_demux: In RAW mode, fill with dummy until first TX
Until the remote side sends the first byte, we send fill
data since it can take it some time after the mode change
and the file descriptor is open for data to show up.

Previously due to a bug, the warning about short read was
not printed, but now that it's fixed, you get a bunch of
fairly "useless" warning at the beginning of the timeslot.

This fixes that since reported data by _e1_tx_raw is "faked"
until the pipe is active. (Fill data is actually added upstream)

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Iaa6268e9b4a7bce5ea3027a29c48c147499373be
2022-01-09 15:09:11 +01:00
Sylvain Munaut e945a897f7 mux_demux: Shuffle functions around for consistency
No functional changes, just making things a bit more organized
for the next patch adding an _e1_tx_raw.

The order after the patch is :

_e1_tx_hdlcfs
_e1_ts_read
_e1_line_mux_out_channelized
_e1_line_mux_out_superchan
e1_line_mux_out

_e1_rx_raw
_e1_rx_hdlcfs
_e1_ts_write
_e1_line_demux_in_channelized
_e1_line_demux_in_superchan
_e1_line_demux_in_ts0
e1_line_demux_in

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I2ced3a5ba3cf3cc1f212d8f3e46cfefa15e4af0c
2022-01-09 15:09:11 +01:00
Sylvain Munaut 0d2a42bc12 usb: Add warning for error during interrupt transfers
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Id4d2c95a2d934700f817e971aa4ce29e4bd85675
2022-01-09 11:43:03 +01:00