Commit Graph

60 Commits

Author SHA1 Message Date
Holger Hans Peter Freyther cdfc2061bb mgcp: Round the frame time otherwise we have porting issues
With the current multiplication we might end up with 19999 as
time on i386. When we round it ends up as 20000 on i386 and
should work the same on AMD64.
2014-02-03 13:32:34 +01:00
Holger Hans Peter Freyther ba41978b97 mgcp: transit is a signed variable and should be printed like this
On AMD64 we had a difference in the test result most likely due
the bigger size of integers.
2014-02-03 09:20:06 +01:00
Holger Hans Peter Freyther 757971ade8 mgcp: Use the length modifier for the size_t in the printf
Should fix on AMD64:
mgcp_test.c: In function ‘sendto’:
mgcp_test.c:318:10: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘size_t’ [-Wformat]
2014-02-03 09:18:51 +01:00
Jacob Erlbeck b281e4e6f4 mgcp/rtp: Base jitter calculation on input timestamps
So far, the jitter computation has been based on output timestamps.

This patch uses the input timestamps instead and resets jitter
computation on SSRC changes.

Sponsored-by: On-Waves ehf
2014-01-31 11:45:25 +01:00
Jacob Erlbeck eacc9b92a1 mgcp/rtp: Compute delta timestamp based on wallclock
Currently, when the SSRC changes within a stream and SSRC fixing is
enabled, the RTP timestamp between the last packet that has been
received with the old SSRC and the first packet of the new SSRC
is always incremented by one packet duration.
This can lead to audio muting (at least with the nanoBTS) when the
wallclock interval between these packets is too large (> 1s).

This patch changes the implementation to base the RTP timestamp offset
on the wallclock interval that has passed between these two packets.

Ticket: OW#466
Sponsored-by: On-Waves ehf
2014-01-31 11:44:16 +01:00
Jacob Erlbeck 303b54a2a4 mgcp/rtp: Fix transit computation units
Currently micro-secs and RTP rate get mixed when the transit value is
computed in mgcp_patch_and_count().

This patch changes get_current_ts() to accept the desired rate as
argument and to use it for the time conversion instead of always
converting to microseconds. If microseconds are needed,
get_current_ts(1000) can be used.
The arrival_time is now measured in 1/rtp_end->rate seconds so that
it can be directly compared to RTP timestamps as required by RFC3550
(section 6.4.1, see definition of 'interarrival jitter').

Sponsored-by: On-Waves ehf
2014-01-31 11:18:25 +01:00
Jacob Erlbeck e763f3e73e mgcp/test: Fake wallclock for RTP timing/stats tests
Currently the stats (jitter, transit) cannot be checked properly,
since they depend on the wallclock time.

This patch fakes clock_gettime (CLOCK_MONOTONIC) to reflect the
scheduling time of the RTP packets. In addition, the RTP statistical
value are written to stdout.
A RTP test case with a SSRC change along with a reference time delay
has been added.

Sponsored-by: On-Waves ehf
2014-01-31 11:18:25 +01:00
Jacob Erlbeck cf577c3492 mgcp/test: Only include conn_mode into test output
Currently the conn_mode and the output_enabled flags are printed to
stdout.

This patch modifies this to print the output_enabled flags to stderr
instead. The bits in conn_mode are shown as RECV, SEND, and LOOP.
This does not reduce the significance of the test, since there is an
assertion already that verifies the values of the output_enabled
flags with respect to the conn_mode.

Sponsored-by: On-Waves ehf
2014-01-31 11:18:25 +01:00
Jacob Erlbeck ead0529e07 mgcp/test: Don't reset conn_mode between messages
Currently, the conn_mode field is reset after it has been checked.

This patch disables this behaviour and only adds a mark (bit) to
detect modifications.

Sponsored-by: On-Waves ehf
2014-01-20 08:27:03 +01:00
Jacob Erlbeck e35fd13697 mgcp: Synchronize conn mode bits and output enabled flags
This patch changes implementation and the mgcp_connection_mode enum
in a way that net_end.output_enabled (bts_end.output_enabled) flag
always matches the MGCP_CONN_SEND_ONLY (MGCP_CONN_RECV_ONLY) bit of
conn_mode.

Based on this, the conn_mode bits are then used instead of the
output_enabled fields within mgcp_protocol.c.

Sponsored-by: On-Waves ehf
2014-01-20 08:27:03 +01:00
Jacob Erlbeck 8857c90e36 mgcp: Disable output enabled on initialisation
Currently RTP output_enabled is set to 1 on initialisation, which
does not semantically match the initial value of conn_mode
(MGCP_CONN_NONE).

This patch changes this initial value to 0.

Sponsored-by: On-Waves ehf
2014-01-20 08:27:03 +01:00
Jacob Erlbeck 075a9ebdcc mgcp: Send RTP keepalive dummy packets to net
So far, a single dummy packet has been sent immediately after the
reception of a MDCX message. There is no dedicated keep alive
mechanism (it just worked because the audio from the MS has always
been forwarded to the NAT until the 'mgcp: Set output_enabled flags
based on the MGCP mode' patch).

This patch adds explicit, timer based keep alive handling that can be
enable per trunk. A VTY command 'rtp keep-alive' command is added for
configuration which can be used to set the interval in seconds, to
send a single packet after the reception of a CRCX/MDCX when RTP data
from the net is expected ('once'), or to disable the feature
completely ('no rtp keep-alive'). In 'send-recv' connections, only
the initial packet is sent if enabled (even when an interval has been
configured). The default is 'once'.

Note that this removes the mgcp_change_cb() from mgcp_main.c.

Sponsored-by: On-Waves ehf
2014-01-16 13:20:51 +01:00
Jacob Erlbeck 2645c9e7fc mgcp: Set output_enabled flags based on the MGCP mode
This patch enhances parse_conn_mode() to set the output_enabled flags
of each end based on the MGCP mode.

Ticket: OW#1044
Sponsored-by: On-Waves ehf
2014-01-16 13:20:44 +01:00
Jacob Erlbeck 84dfba1579 mgcp/test: Show the number of dummy packets sent
This patch extends the test_messages test to show the number of dummy
packets that has been passed to sendto(). This way, dummy packets are
even being counted when sendto() itself failes (e.g. due to the fd
being -1).

Sponsored-by: On-Waves ehf
2014-01-16 13:20:37 +01:00
Jacob Erlbeck 68c74f59a4 mgcp/test: Reset pkt_period_* after each test
Currently these value may leak into the next test.

This patch will reset them after each message has been processed.

Sponsored-by: On-Waves ehf
2014-01-16 12:17:24 +01:00
Jacob Erlbeck 1b653af283 mgcp/test: Test the connection mode parser
This modifies the test MGCP messages to include M:recvonly (CRCX),
M:sendrecv (MDCX) and M:sendonly (MDCX) outputs the resulting
output_enabled flags and the conn_mode after processing the message.

Sponsored-by: On-Waves ehf
2014-01-16 12:17:24 +01:00
Jacob Erlbeck 4bbddc6de9 mgcp/rtp: Only patch timestamp alignment errors
Currently, all timestamps are force to SeqNo*d + C which is more than
required by the nanoBTS which seems to be sensitive to alignment
errors only (dTS != k*d, d = ptime * rate = 160).

This patch replaces the force_constant_timing feature by a
force_aligned_timing feature. The timestamp offset will only be
changed (and timestamp errors counted) when the alignment does not
match to the raster based on ptime (default 20ms).

The VTY interface does not change.

Sponsored-by: On-Waves ehf
2013-12-19 11:56:11 +01:00
Jacob Erlbeck 65c7a4551a mgcp/test: Use differential output for counters and timestamp
Currently the counter and output timestamp values are written out for
each packet. This makes it difficult to see in the diffs what has
been changed significantly.

This patch changes this by showing differences for those
values. The absolute input values are also shown now. In addition,
the sequence numbers (the difference for the output value) are
written, too.

Sponsored-by: On-Waves ehf
2013-12-19 11:56:11 +01:00
Jacob Erlbeck 93c9da3b37 mgcp/test: Add test cases for constant RTP sequence number
This adds two test cases:
  1. Packet repetition (dSeq=0, dTS=0)
  2. Broken seqNo (dSeq=0, dTS=160)

The second had been already present in the test cases, but it was a
mere copy&paste mistake which turned out to be rather helpful. This
patch therefore turns it into a documented test case.

Sponsored-by: On-Waves ehf
2013-12-19 11:56:11 +01:00
Jacob Erlbeck 0a1bc56e5a mgcp: Optionally send ptime in SDP
Currently the SDP 'ptime' media attribute is never set in generated
MGCP responses.

This patch optionally includes the 'ptime' attribute if
packet_duration_ms is != 0. This behaviour can be enabled/disabled
by using the VTY command "sdp audio-payload send-ptime" (enabled by
default).

Sponsored-by: On-Waves ehf
2013-12-13 13:51:29 +01:00
Jacob Erlbeck 24754f0490 mgcp: Parse SDP to get rate and packet duration
This patch parses the 'ptime' and 'maxptime' SDP attributes, and the
SDP rate information and sets up packet_duration_ms accordingly. If
the packet duration is unknown or allows for different values (e.g.
because 'ptime' uses a range or 'maxptime' allows for more than one
frame) the duration is set to 0.

Sponsored-by: On-Waves ehf
2013-12-13 13:49:32 +01:00
Jacob Erlbeck 2c2ca4df38 mgcp: Put local connection options into a struct
Currently the local connection options have been stored as a string.

This patch replaces this string by a struct (that still contains a
string) along with the parsed fields (only the packetization period
at the moment).

It also re-adds the calls to set_local_cx_options() to the
handle_create_con() and handle_modify_con() functions. Except for
the test program this has no side effects, since the LCO values
aren't used yet.
2013-12-13 13:48:04 +01:00
Jacob Erlbeck ba477d2ba3 mgcp/test: Output the packet duration after MGCP parsing
This also adds additional MDCX tests (based on MDCX4) to test the
analysis of different combinations of 'p' and 'ptime' fields.

Sponsored-by: On-Waves ehf
2013-12-13 13:45:19 +01:00
Holger Hans Peter Freyther a80100644c mgcp: Address compiler error for sprintf misusage...
The hardening flags of debian have highlighted this sprintf mis-usage
in the testcase. Address it.
2013-12-12 13:08:26 +01:00
Jacob Erlbeck 58340e5b5b mgcp/rtp: Fix RTP timestamps if enabled
This forces the output timing to fulfill
   dTS = dSegNo * fixedPacketDuration
where dSegNo = seqNo - lastSeqNo.

If timestamp patching is enabled, the output timestamp will be set
to lastTimestamp + dTS. This kind of relative updating is used to
handle seqNo- and timestamp-wraparounds properly.

The updating of timestamp and SSRC has been separated and the patch
field of mgcp_rtp_state has been renamed to patch_ssrc to reflect
it's semantics more closely. The offset fields are now used always
and will change the corresponding header field if they are != 0.

Ticket: OW#1065
Sponsored-by: On-Waves ehf
2013-12-10 11:17:44 +01:00
Jacob Erlbeck 3da9e4e441 mgcp/rtp: Use SSRC in proper byte ordering
The ssrc has been used without respect to proper byte ordering in
mgcp_patch_and_count(). This only affected log messages.

This patch introduces a new variable 'ssrc' that takes the value of
the SSRC in proper byte order.

Sponsored-by: On-Waves ehf
2013-12-10 11:13:22 +01:00
Jacob Erlbeck db2d431697 mgcp/rtp: Add RTP header patch mode configuration
This adds datastructures and a VTY frontend to configure the
different type of RTP header patching: SSRC and timestamp.

Note that timestamp patching is not yet implemented.

Sponsored-by: On-Waves ehf
2013-12-10 11:11:42 +01:00
Jacob Erlbeck 55ba140da1 mgcp/rtp: Fix output timing error counter
The tsdelta computation and error detection didn't handle the
intialisation phase properly.

This patches fixes this by skipping the output timing validation
when the SSRCs don't match.

Sponsored-by: On-Waves ehf
2013-12-05 16:55:39 +01:00
Jacob Erlbeck 83c0523739 mgcp/rtp: Add more test cases for RTP header patching
This patch extends the existing RTP error check test by adding a
check for timestamp errors after SSRC changes and a check for a
segno delta of 2 (with a timestamp delta of 320).

To test SSRC patching too, a corresponding line will be written on
each SSRC change that has been detected in the output stream.

In addition there is now support for selectively enabling/disabling
SSRC and timestamp patching. The RTP test sequence is repeated for
all combinations thereof.

Sponsored-by: On-Waves ehf
2013-12-05 16:54:25 +01:00
Jacob Erlbeck 78a9501cfd mgcp: Handle SDP in CRCX received by the MGW
So far the SDP part of the CRCX message has been ignored by the MGW.

This patch adds SDP parsing for this case, eventually updating the
net end's payload type and connection parameters.

Sponsored-by: On-Waves ehf
2013-12-05 10:28:51 +01:00
Jacob Erlbeck a52ac66e52 mgcp: Add tests for payload types in MGCP messages
These tests mainly check whether the SDP parsing works properly by
looking at the payload type detected.

Sponsored-by: On-Waves ehf
2013-12-05 10:27:32 +01:00
Jacob Erlbeck 2bee7f96ff mgcp: Add new for_each_line macro that also returns empty lines
This patch add the for_each_line macro based on a strline_r()
function (similar to strtok_r()), that is also part of this patch.
This strline_r() function is tolerant with respect to line endings,
it supports CR-only, CRLF, and LF-only and any combinations thereof
(note that a CRLF is always detected as a single line break).

Similar to for_each_non_empty_line (the former for_each_line) where
the 'save' pointer needed to be initialised by a call to strtok_r(),
the new for_each_line macro expects, that the 'save' pointer has been
initialised by a call to strline_r(). Also note, that
for_each_line/strline_r and for_each_non_empty_line/strtok_r may use
the 'save' pointer differently, so calls to them can not be mixed.

Sponsored-by: On-Waves ehf
2013-12-05 10:27:32 +01:00
Jacob Erlbeck 72c309021a mgcp/rtp: Fix timestamp offset when patching RTP packets
The current implementation increments the seqno but does not increment
the RTP timestamp, leading to two identical timestamps following one
after the other.

This patch fixes this by adding the computed tsdelta when the offset
is calulated. In the unlikely case, that a tsdelta hasn't been
computed yet when the SSRC changes, a tsdelta is computed based on
the RTP rate and a RTP packet duration of 20ms (one speech frame per
channel and packet). If the RTP rate is not known, a rate of 8000 is
assumed.

Note that this approach presumes, that the per RTP packet duration
(in samples) is the same for the last two packets of the stream being
replaced (the first one).

Sponsored-by: On-Waves ehf
2013-11-25 18:30:50 +01:00
Jacob Erlbeck d62419b574 mgcp/rtp: Add test case for RTP timestamp patching and stats
This patch adds a test case to check, whether RTP timestamps are
generated properly after SSRC changes and whether the error counters
work properly.

Sponsored-by: On-Waves ehf
2013-11-25 18:13:35 +01:00
Jacob Erlbeck 50079a1843 mgcp/rtp: Add counter for invalid RTP timestamp deltas
This patch modifies the patch_and_count() function to check for RTP
timestamp inconsistencies. It basically checks, whether dTS/dSeqNo
remains constant. If this fails, the corresponding counter is
incremented. There are four counter for this: Incoming and outgoing,
each for streams from the BTS and the net.

Note that this approach presumes, that the per RTP packet duration
(in samples) remains the same throughout the entire stream. Changing
the number of speech frames per channel and packet will be detected
as error.

In addition, the VTY command 'show mgcp' is extended by an optional
'stats' to show the counter values, too.

Ticket: OW#964
Sponsored-by: On-Waves ehf
2013-11-25 18:07:21 +01:00
Alexander Huemer a1c09a401d Makefile.am: Use AM_CPPFLAGS
Since automake 1.13 INCLUDES is depricates and causes a warning
2013-06-12 09:16:27 +02:00
Holger Hans Peter Freyther 462b7d7158 nat: We want the remote to respond to our DLCX request
We want to send a TRAP with the MGCP statistics from the NAT and
the connected BSC. The BSC endpoint can be either released because
of a DLCX from the MGCP CallAgent or the SCCP Connection release on
the A-link.

This is why we need to queue the statistics when the deleting the
endpoint on the BSC. The processing is continued once the response
arrives. This code assumes that the response of the DLCX will be sent
by the remote side. The current amount of outstanding responses can be
seen on the VTY. This assumption is based on the fact that the BSC has
already responded to the CRCX and maybe to the MDCX.

The MGCP RFC is bended to prefix the transaction identifier with "nat-"
to easily detect the response and hand it to the handler. This will
then parse the response and generate the TRAP. The current version is
v1. We assume that the transaction space is big enough and we will
not re-assign the transaction identifier too early.
2013-04-16 09:17:21 +02:00
Holger Hans Peter Freyther ce55361e93 mgcp: Test and implement re-transmission handling
MGCP is used over UDP and a response might be lost. The MGCP RFC
asks for keeping a list of responses and then using the previous
response to answer a duplicate request. I tried to conserve memory
and just wanted to remember the last transaction identifier and
result-code and re-generate the result from that. This made the
code look bad and this is why the entire response will now be stored.
It sadly increases the memory usage but can not be avoided at this
time.

Remove the msg->l3h pointer for the RQNT callback as strtok has
modified the content of it.
2012-12-10 14:46:00 +01:00
Holger Hans Peter Freyther cf2f158caa mgcp: Add testdata for MDCX handling 2012-12-10 13:35:53 +01:00
Holger Hans Peter Freyther d267f4d685 mgcp: Test the second CRCX as a CRCX and not as a re-transmission
The second CRCX would be mostly ignored and be handled by the
retransmission layer of MGCP.
2012-12-10 12:16:23 +01:00
Holger Hans Peter Freyther 8d0be259cb mgcp: Begin handling of the RQNT message as needed for DTMF
Introduce a callback for the request and forward the signalrequest
to the callback. This is not a full implementation of MGCP RQNT.
2012-11-29 19:56:22 +01:00
Holger Hans Peter Freyther cb306a689e mgcp: Send the jitter statistics at the end of the call 2012-11-12 10:45:09 +01:00
Holger Hans Peter Freyther 38e02c5125 mgcp: Calculate the packet loss as of Appendix A of RFC 3550
Calculate the expected packages and packet loss as of RFC 3550.
The values should be clamped but our packet loss counter is 32
bits and not 24 and we should clamp at other values but I am
waiting for some issues first before dealing with that.
2012-11-12 10:44:58 +01:00
Holger Hans Peter Freyther 0bf15a8187 mgcp: Include statistics at the end of a connection
Follow the MGCP specification and send the collected statistics
at the end of a call. Right now this does not include jitter, packet
loss and delay.
2012-11-12 10:42:05 +01:00
Harald Welte ae1997248c mgcp: implement a more tolerant parser based on strtok_r()
Instead of building complex manual byte-wise parsers, we simply use two
strtok_r loops:  one iterating over all the lines, the next one
iterating over the invididual space-separated elements in the first line.

The benefit is that we now accept \r, \n or \r\n, or any multiple of
them as line ending.  This works around incompliant MGCP implementations
like that of Zynetix MSC.

Addition: mgcp_analyze_header returns 0 when all out parameters have
been set.

Signed-off-by: Holger Hans Peter Freyther <zecke@selfish.org>
2012-03-16 10:24:18 +01:00
Holger Hans Peter Freyther d77023b1c2 mgcp_test: Add wrong messages as input and check what happens
Test parsing some invalid messages and see if we start to crash.
2012-03-16 10:21:29 +01:00
Holger Hans Peter Freyther 5563e6c268 mgcp_test: Rename method as it now operates on an array of messages
This code was cleaned up, catch up and rename the method.
2012-03-16 10:06:39 +01:00
Harald Welte 27fa7901bb MGCP: Add CRCX test cases
The second test case (CRCX_ZYN) fails as the message is not compliant
with the spec.  However, our parer should be more tolerant, just in
case...
2012-01-27 00:37:23 +01:00
Harald Welte f74da14c01 further generalize mgcp testing code
use a data-structure driven approach
2012-01-27 00:36:56 +01:00
Harald Welte 8819d8289d mgcp_test: remove duplicate code 2012-01-27 00:00:44 +01:00