# Handover to cell with worse RXLEV, if RXQUAL is below minimum
# The neighbor cell has worse RXLEV, so no handover is performed.
# If the RXQUAL of the current cell drops below minimum acceptable
# level, the handover is performed. It is also required that 10
# reports are received, before RXQUAL is checked.
#
# (See also test 28, which tests for RXQUAL triggering HO to congested cell.)
#
# TODO: bad RXQUAL may want to prefer assignment within the same cell to avoid interference.
# See Performance Enhancements in a Frequency Hopping GSM Network (Nielsen Wigard 2002), Chapter
# 2.1.1, "Interference" in the list of triggers on p.157.

# first show undesired oscillation when penalty-time low-rxqual-ho is disabled
network
 handover2 penalty-time low-rxqual-ho 0

create-n-bts 2
set-ts-use trx 0 0 states * TCH/F - - - - - -
meas-rep repeat 9 lchan 0 0 1 0 rxlev 40 rxqual 6 ta 0 neighbors 30
expect-no-chan
meas-rep lchan 0 0 1 0 rxlev 40 rxqual 6 ta 0 neighbors 30
expect-ho from lchan 0 0 1 0 to lchan 1 0 1 0
expect-ts-use trx 0 0 states * - - - - - - -
expect-ts-use trx 1 0 states * TCH/F - - - - - -

# Now the channel is on bts 1, which has lower rxlev than bts 0.
# The result is an undesired ho oscillation, because the penalty timer is zero
meas-rep lchan 1 0 1 0 rxlev 30 rxqual 0 ta 0 neighbors 40
expect-ho from lchan 1 0 1 0 to lchan 0 0 1 0

# Set a proper penalty timeout and report bad-rxqual again
network
 handover2 penalty-time low-rxqual-ho 10
meas-rep repeat 10 lchan 0 0 1 0 rxlev 40 rxqual 6 ta 0 neighbors 30
expect-ho from lchan 0 0 1 0 to lchan 1 0 1 0

# This time the penalty timer prevents oscillation
meas-rep repeat 10 lchan 1 0 1 0 rxlev 30 rxqual 0 ta 0 neighbors 40
expect-no-chan

# After the penalty timeout passes, we do go back to the cell with stronger rxlev
wait 10
meas-rep lchan 1 0 1 0 rxlev 30 rxqual 0 ta 0 neighbors 40
expect-ho from lchan 1 0 1 0 to lchan 0 0 1 0
# If the rxqual is still bad here after the penalty timeout, well, then we quickly snap back to the weaker cell, once
meas-rep repeat 10 lchan 0 0 1 0 rxlev 40 rxqual 6 ta 0 neighbors 30
expect-ho from lchan 0 0 1 0 to lchan 1 0 1 0
meas-rep repeat 10 lchan 1 0 1 0 rxlev 30 rxqual 0 ta 0 neighbors 40
expect-no-chan
