Commit Graph

41 Commits

Author SHA1 Message Date
Neels Hofmeyr 7132011afa bssgp_fc_test: do not use real time
Employ osmo_gettimeofday_override_* to take bssgp_fc_test off real time. The
jenkins build slave often failed the test based on sporadic time delays due to
server load and randomly rejected good patches. This patch ends that.

Change-Id: Ie5029b85c2a154554d75d7f9af49a3b93425fdd9
Related: OS#1809
2017-02-07 00:39:54 +00:00
Neels Hofmeyr 8e2f7e87f4 add osmo_gettimeofday as a shim around gettimeofday
This allows feeding a custom time for unit tests by overriding
osmo_gettimeofday.

Change-Id: Ic7a81a6eb51f27fe452962b91f2eae2070d87089
2016-09-22 07:18:39 +02:00
Jacob Erlbeck f78ec5ce0d gb: Add bssgp_msgb_copy function
This function originates from openbsc/src/gprs but is just specific
to BSSGP/Gb on the same level like bssgp_msgb_alloc.

This commit puts the former gprs_msgb_copy function beside
bssgp_msgb_alloc.

Renamed function:

  gprs_msgb_copy -> bssgp_msgb_copy

Sponsored-by: On-Waves ehf
2016-02-22 10:20:49 +01:00
Holger Hans Peter Freyther fdb4667609 test: Fix compiler warnings on 64bit systems
Use %td to print ptrdiff_t use %zu to print size_t,
include time.h on FreeBSD. Some more compiler warnings are
left but they require more thinking.
2015-11-09 16:46:03 +00:00
Jacob Erlbeck cc6ac4cdc4 ns: Force a defined state when sending NS RESET
Currently the state is assumed to remain the same while the reset
procedure is active. While this works correctly in general, a single
unexpected BLOCK_ACK or UNBLOCK_ACK can change the state but will not
stop the reset procedure. The leads to repeated RESET messages, where
the corresponding RESET_ACK is ignored. This is a stable state which
can only be left by manual intervention or by reception of a RESET
message from the peer.

This commit changes the RESET timeout handler to set the state to
BLOCKED/RESET when sending the new NS RESET message.

Note that this should ensure a clean restart even if the state has been
screwed up. It does not fix the handling of BLOCK_ACK or UNBLOCK_ACK
in abnormal cases.

Addresses:
 gprs_ns.c:349 NSEI=8895 Tx NS RESET (NSVCI=8895, cause=O&M intervention)
 gprs_ns.c:878 NSVCI=8895 Rx NS RESET ACK (NSEI=8895, NSVCI=8895)
 gprs_ns.c:887 NS RESET ACK Discarding unexpected message for NS-VCI 8895 from SGSN NSEI=8895

Ticket: OW#1551
Sponsored-by: On-Waves ehf
2015-12-17 14:16:50 +01:00
Jacob Erlbeck 2c58197e5d bssgp/test: Add missing START/END printfs
Sponsored-by: On-Waves ehf
2015-06-19 20:53:31 +02:00
Jacob Erlbeck 9385d1e01b bssgp: Fix bssgp_tx_fc_bvc parameter type
Currently large values for Bmax default MS get sliced since a uint16_t is
used as the type of the corresponding parameter of bssgp_tx_fc_bvc.
GSM 48.018, 11.3.2 which in turn refers to 11.3.5 specifies a maximum
of 6MB (0xffff * 100).

This commit changes the type to uint32_t to cover the full value
range.

Sponsored-by: On-Waves ehf
2015-05-06 17:55:55 +02:00
Jacob Erlbeck 455d34f476 bssgp/test: Fix bssgp-fc test
The fix in the commit "bssgp: Fix call to llist_entry in
fc_queue_timer_cfg" prevents the flow control code from generating
certain logging messages ("-BSSGP-FC: fc_timer_cb() but still not
able to send PDU of 10 bytes") during the tests. This breaks the test
suite, since the update of the correseponding stderr output file
misses.

This commit updates the bssgp_fc_tests.err file accordingly.

Sponsored-by: On-Waves ehf
2015-05-04 07:44:43 +02:00
Jacob Erlbeck b535e391b0 bssgp: Ensure non-NULL bctx before calling bssgp_rx_ptp (Coverity)
Currently bssgp_rx_ptp might be called with bctx being NULL, when the
NS BVCI is neither BVCI_SIGNALLING nor BVCI_PTM, but the message is
a BVC_RESET or it contains an BVCI IE != BVCI_SIGNALLING where the
BVCI is not known.

This patch ensures that bssgp_rx_ptp will only be called with a
non-NULL bctx. A log message will be issued, if the bctx is NULL when
this was not expected.

Fixes: Coverity CID 1040674
Sponsored-by: On-Waves ehf
2015-04-07 20:10:09 +02:00
Jacob Erlbeck 36153dc61a bssgp: Handle BSSGP STATUS messages
Currently incoming BSSGP STATUS messages are just logged and no other
action is taken. This makes it impossible for higher layers to react
to failures which are indicated by corresponding STATUS messages
unless a timeout is triggered as a result of that failure later on.

This commit adds a bssgp_rx_status() function and calls it on
incoming STATUS messages. That function logs a message, increments the
new BSSGP_CTR_STATUS counter if the bctx context exists and invokes
an NM_STATUS status indication. The latter will allow the application
to handle failures immediately. Since all STATUS messages should be
handled, the function is already called in bssgp_rcvmsg and the
message is no longer handled in (and will not reach) bssgp_rx_sign
and bssgp_rx_ptp.

Ticket: OW#1414
Sponsored-by: On-Waves ehf
2015-03-18 21:54:37 +01:00
Holger Hans Peter Freyther e0a1a8021f bssgp: Include sys/socket.h for AF_INET on FreeBSD 2014-10-25 12:19:56 +02:00
Jacob Erlbeck b43baf20c5 gprs: Don't discard SUSPEND/RESUME in bssgp_rcvmsg
Currently sending SUSPEND/RESUME messages to this function (like it
is done in the osmo-sgsn) results in STATUS messages complaining
about an unknown BVCI. The reason is, that these messages rely on a
TLLI/RAI pair to identify the context and do not contain an explicit
BVCI.

This patch modifies bssgp_rcvmsg() to only complain about and unknown
BVCI if one is given but a matching context is not found (except for
RESET messages). The ctx argument is removed from the functions
handling SUSPEND and RESUME since it will always be NULL then.

Sponsored-by: On-Waves ehf
2014-10-23 18:53:02 +02:00
Jacob Erlbeck cdebf7484a gprs/test: Add BSSGP tests
This patch adds a test suite for the BSSGP protocol.
The first (and only) test checks the handling of BSSGP
SUSPEND/RESUME.

Sponsored-by: On-Waves ehf
2014-10-23 18:52:56 +02:00
Holger Hans Peter Freyther 10dd73cf6a bssgp: Free msgb in case of error when calling into gprs_ns_sendmsg
In the OsmoSGSN we have a crash with a DEAD/BLOCKED GPRS-NS and
segmented SN-UNITDATA. For the caller it is not easy to know if
the passed msg buffer has been freed or not. The most easy solution
is to always take the ownership and either pass it on or free it
in case of an error.

Adjust indirect and direct callers of gprs_ns_sendmsg. I found
the following call-chains with an external msgb parameter.

gprs_ns_sendmsg
  <- _bssgp_tx_dl_ud
     <- bssgp_fc_in
        <- bssgp_tx_dl_ud

Update the test to allocate a real msgb because for the test with
'1000' we will msgb_free it right away.

Sponsored-by: On-Waves ehf
2014-10-10 17:55:13 +02:00
Jacob Erlbeck dade018f2f gprs-ns/test: Check the nsvc state explicitely
This patch extends test_sgsn_reset_invalid_state by assertions to check
that nscv->state and nsvc->remote_state have been set as expected.

Sponsored-by: On-Waves ehf
2014-10-09 16:08:44 +02:00
Holger Hans Peter Freyther 84bcce6b4f gprs-ns/test: Re-add return value check for gprs_nsvc_reset
The return value check has been removed in the commit 'Use
gprs_nsvc_reset instead of gprs_ns_tx_reset', because gprs_nsvc_reset
had no return value then. Since a compatible return value has been
added by 'Let gprs_nsvc_reset return a value', the former patch is
partly reverted by this commit.

The printf is now an OSMO_ASSERT. The commit message was taken
from Jacob.

Sponsored-by: On-Waves ehf
2014-10-09 16:08:20 +02:00
Jacob Erlbeck 6ac70a41ee gprs-ns: Fix reset state handling
Currently the NS-VC's state is updated from within gprs_ns_tx_reset,
which can lead to an inconsistent state when the RESET_ACK is lost.
In this state, the NSE_S_RESET bit is set but the Tns-reset timer is
not started.

This patch moves the state update into gprs_nsvc_reset. This way, the
state flags are consistent with the timer.

Addresses:
  SGSN -> BSS       NS_ALIVE
  BSS -> SGSN       NS_ALIVE_ACK
  BSS -> SGSN       BVC_RESET
  SGSN -> BSS       NS_STATUS, Cause: NS-VC blocked, NS VCI: 0x65
  and there is no BSS->SGSN NS_ALIVE

Ticket: OW#1213
Sponsored-by: On-Waves ehf
2014-10-09 07:52:43 +02:00
Jacob Erlbeck cdb85f58c5 gprs-ns/test: Add test_sgsn_reset_invalid_state
This tests the behaviour for a certain combination of messages and
packet losses that can put the NS-VC object into an undefined state.

In that state, the peer's ALIVE messages are properly answered, but
the local test procedure has stopped, incoming unitdata PDUs are
answered by STATUS(NS-VC blocked) and the unblocking procedure is not
initiated.

Ticket: OW#1312
Sponsored-by: On-Waves ehf
2014-10-09 07:46:22 +02:00
Jacob Erlbeck f1bcbb0f8a gprs-ns/test: Add expire_nsvc_timer
This function forces the expiration of the timer within struct
gprs_nsvc. It is meant to be used for controlled (and faster) timer
expiration in unit tests. The timer_mode of the expired timer is
returned (or -1 if the timer wasn't active).

Sponsored-by: On-Waves ehf
2014-10-09 07:44:47 +02:00
Jacob Erlbeck 2381fded68 gprs-ns/test: Save the last PDU type sent
This records the PDU type of the last message sent to the remote peer
in the global variable sent_pdu_type, which can then be used in
assertions.

Note that sent_pdu_type will remain unchanged if no message has been
sent via sendto.

Sponsored-by: On-Waves ehf
2014-10-09 07:43:54 +02:00
Jacob Erlbeck f357c87724 gprs-ns/test: Use gprs_nsvc_reset instead of gprs_ns_tx_reset
Currently gprs_ns_tx_reset is used to let the NS stack generate
NS_RESET message. This is not adjusting the nsvc state properly.

This patch uses gprs_nsvc_reset instead which starts the full reset
procedure.

Sponsored-by: On-Waves ehf
2014-10-09 07:41:14 +02:00
Jacob Erlbeck 3d557b18d0 gprs: Ignore NS RESET_ACK and ALIVE_ACK without RESET
Currently those messages are answered by a NS_STATUS message when
received on an uninitialised (no NS_RESET hat been seen yet) NS_VC
which violates GPP TS 08.16 7.3.1 and 7.4.1.

This patch adds checks to gprs_ns_vc_create() and eventually returns
before the error NS_STATUS message is generated.

Sponsored-by: On-Waves ehf
2013-10-30 15:23:18 +01:00
Jacob Erlbeck e7c427165f grps: Add test for NS messages that shall be ignored
Several messages shall not be answered when a RESET hasn't been
received on a NS-VC:
- NS_RESET_ACK (see 3GPP TS 08.16, 7.3.1)
- NS_ALIVE_ACK (see 3GPP TS 08.16, 7.4.1)
- NS_STATUS (see 3GPP TS 08.16, 7.5.1)

Sponsored-by: On-Waves ehf
2013-10-30 15:23:15 +01:00
Jacob Erlbeck 54b8b2dfef gb: Create new NSVC object instead of patching the NSVCI
When a RESET is received on the same link with a different NSVCI from
a BSS on a dynamically created NS connection do not patch the nsvc
object but create a new one instead. Thus the NSVCI is never modified
at a nsvc object after the NS-VC has been established.

Sponsored-by: On-Waves ehf
2013-10-24 10:01:18 +02:00
Jacob Erlbeck ab852ee234 gb: Fix RESET handling with changing NSEI
This modifies the NS stack's behavior to accept RESET and RESET_ACK
NSEI changes for NS-VC dynamically created by RESET messages from
BSSes. This feature is not used for NS-VC configured via VTY or NS-VC
to a SGSN.

Sponsored-by: On-Waves ehf
2013-10-24 10:01:18 +02:00
Jacob Erlbeck 5405a104bb gb: Fix NS RESET/RESET_ACK abnormal cases
This changes the implementations for the reception of RESET and
RESET_ACK to be compatible with 3GPP TS 08.16, 7.3.1:

- Just send a RESET_ACK with correct values back to the SGSN when a
  RESET with an invalid NSVCI or NSEI has been received.
- Check RESET_ACK for matching NSEI and NSVCI.
- Ignore unexpected RESET_ACKs.

In addition, use RESET_ACK from a BSS to update the BSS source
address based on the NSVCI to be tolerant with changing UDP source
addresses/ports.

Sponsored-by: On-Waves ehf
2013-10-24 10:01:18 +02:00
Jacob Erlbeck 81d7c14756 gb: Add test cases for NS RESET procedures
Add a test handling proper and mismatching RESETs. The latter may
occur, when ports change within a NS-VC without the SGSN getting
notice.

This tests for the behavior of the NS protocol stack for RESET and
RESET_ACK messages which changing/invalid NSEI and NSVCI like it is
being described in 3GPP TS 08.16, 7.3.1.

Sponsored-by: On-Waves ehf
2013-10-24 10:01:18 +02:00
Jacob Erlbeck a52ba0175f gb: Fix gprs_nsvc_delete() to free ctr group
This fixes a SEGV error that happens the next time the statistics
are updated.

Addresses:
 Program terminated with signal 11, Segmentation fault.
 #0  0xb7711fa5 in rate_ctr_group_intv (grp=<optimized out>) at
 rate_ctr.c:107
 107             for (i = 0; i < grp->desc->num_ctr; i++) {
 #0  0xb7711fa5 in rate_ctr_group_intv (grp=<optimized out>) at
     rate_ctr.c:107
 #1  rate_ctr_timer_cb (data=0x0) at rate_ctr.c:129
 #2  0xb770ec59 in osmo_timers_update () at timer.c:243
 #3  0xb770ef7a in osmo_select_main (polling=0) at select.c:133
 #4  0x08049987 in main (argc=3, argv=0xbfba8084) at
     gb_proxy_main.c:306

Sponsored-by: On-Waves ehf
2013-10-24 10:01:18 +02:00
Jacob Erlbeck bf0219654b gb: Fix gprs_active_nsvc_by_nsei()
The state matching condition is inverted. This is corrected by this
fix.

Sponsored-by: On-Waves ehf
2013-10-17 14:45:27 +02:00
Jacob Erlbeck 0d4e949e22 gb: Test sending messages to the SGSN
This adds tests for the gprs_ns_sendmsg() function. For this it
merges back functions from the gbproxy test.

Sponsored-by: On-Waves ehf
2013-10-17 14:45:27 +02:00
Jacob Erlbeck 5e6d679df3 gb: Fix gprs_ns_rx_reset to not create NS-VC duplicates
Under special circumstances (see below) receiving a NS-RESET leads to
duplicated NS-VC entries.

This happens when the source port of a NS-VC changes to a new one
that has already been used by another NS-VC.

This patch changes gprs_ns_rx_reset() to check for this case and to
use the existing NS-VC object. The NS-VC object that was associated
with the source address before is detached from this source but kept
in the NS-VC list so that it can be reattached when a correspondent
NS-RESET is received later on. Meanwhile it will have a cleared link
layer address which will not match a real link info.

A new counter NS_CTR_REPLACED is incremented each time when the NS-VC
object is replacing another one. A new signal S_NS_REPLACED is added
which gets dispatched in this case, too.

Another new counter NS_CTR_NSEI_CHG is incremented each time when the
NSEI of a NS-VC object (with fixed NSVCI) changes.

Ticket: OW#874
Sponsored-by: On-Waves ehf
2013-10-15 10:20:34 +02:00
Jacob Erlbeck 96550e0321 gb: Add functions to access the LL part of the NS-VC objects
Adds the functions gprs_ns_ll_copy() and gprs_ns_ll_clear(). Renames
gprs_ns_format_peer() to gprs_ns_ll_str(). All of these functions
uniformly access the link layer part within the NS-VC objects.

Sponsored-by: On-Waves ehf
2013-10-15 09:48:41 +02:00
Jacob Erlbeck 34fc4701c7 tests/gb: Show invoked signals in test output
Register an osmo signal handler to print a short notice about every
SS_L_NS signal that is generated while processing the tests.

Sponsored-by: On-Waves ehf
2013-10-11 14:41:40 +02:00
Jacob Erlbeck b6390f9bd8 gb: Use the NS-VCI to find an existing NS-VC
Currently when a NS-RESET is recevied over a link that has not yet
been associated with a NS-VC, the NSEI is used to find an existing
NS-VC. If one is found, the reset procedure is initiated.

This behaviour is not conformant with 3GPP TS 08.16 (see chapter
4.2.3) which allows to use several NS-VC between two endpoints in
parallel.

The patch changes the implementation to use the NSVCI instead
of the NSEI to search for an existing NS-VC object.

Ticket: OW#874
Sponsored-by: On-Waves ehf
2013-10-08 14:51:17 +02:00
Jacob Erlbeck 05395a63b7 gb: Fix NS-RESET response message order
According to 3GPP TS 08.16, 7.3 "Reset procedure" the entity
receiving a NS-RESET PDU responds with a NS-RESET-ACK and 'then'
starts the test procedure which essentially means, that a NS-ALIVE
gets sent and a timer is started.

Currently the NS-ALIVE is sent before the NS-RESET-ACK.

This patch fixes the implementation by reversing the order in which
these messages are sent.

Sponsored-by: On-Waves ehf
2013-10-08 14:51:13 +02:00
Jacob Erlbeck dcce196be9 tests/gb: Add test for GPRS NS protocol
This tests the connection establishment by directly calling
gprs_ns_rcvmsg() and printing the resulting messages and the
NS-VC list.
2013-10-08 14:00:24 +02:00
Holger Hans Peter Freyther 5b6416a729 bssgp: Address various compiler warnings in the bssgp code
gb/bssgp_fc_test.c: In function ‘fc_out_cb’:
gb/bssgp_fc_test.c:46:1: warning: no return statement in function returning non-void [-Wreturn-type]
gb/bssgp_fc_test.c: In function ‘fc_in’:
gb/bssgp_fc_test.c:56:1: warning: no return statement in function returning non-void [-Wreturn-type]
gb/bssgp_fc_test.c: In function ‘test_fc’:
gb/bssgp_fc_test.c:79:3: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
2013-09-16 14:13:25 +02:00
Holger Hans Peter Freyther c302eca2c6 tests: Make the gb test work with srcdir != builddir
* Disable color and printing the filename of the stderr log target,
  update the results
* Add the .ok, .err and .sh files to the extra_dist
* Execute the shell script from the source directory
2012-09-11 11:49:35 +02:00
Harald Welte d8b476988d BSSGP: make bvc_ctx->fc a dynamic talloc allocation
this ensures that we can talloc the flow-control queue entries
as siblings off the bvc_ctx.
2012-09-07 12:07:54 +02:00
Harald Welte 04f0989d11 GPRS BSSGP test: integrate into autotest
we use a smalle shell script to iterate over multiple tests
2012-09-07 12:07:54 +02:00
Harald Welte 57e5b94e90 BSSGP flow-control: Add unit test for algorithm tests 2012-09-07 12:07:54 +02:00