# Tests of DL_TEST_REQ/RES, DL_XID_REQ/RES in LLC2 subs-bind mode
#
# DL_TEST_REQ and DL_TEST_RES Tests
#
#	1) Normal transmission between two LLC2 streams in DL_IDLE state
#	2) Send with the remote DLSAP not matching
#	3) Send after connect to same address as one in subs-bind
#	4) Send after connect where addresses are different
#	5) Send TEST from LLC2 stream to an LLC2 stream that has enabled
#	   automatic TEST response -- should get the automatic response,
#	   and the other stream sees nothing
#
# DL_XID_REQ and DL_XID_RES Tests
#
#	Tests 6-10 are the same as 1-5, but with XID packets
#
#	11) Test binding/rebinding, bad binds


###### Test case #1 ######
open 1
attach $1 43
bind $1 48 2 2 0 1

open 2
attach $2 43
bind $2 40 2 0 0 1

# subs-bind for remote address with SAP 40
subs_bind $1 0:0:0:0:0:0,40 2

# subs-bind for remote address with SAP 48
subs_bind $2 0:0:0:0:0:0,48 2

test_req $2 0:0:0:0:0:0,48 0 0 '1 2 3'

# Should see an event on the other stream (3)
poll $1 $2 $1

test_ind $1 0

test_res $1 0:0:0:0:0:0,40 0 '4 5 6'

poll $1 $2 $2

test_con $2 0

poll $1 $2 0

check_state $1 dl_idle
check_state $2 dl_idle

close $1
close $2

###### Test case #2 ######
open 1
attach $1 43
bind $1 48 2 2 0 1

open 2
attach $2 43
bind $2 40 2 0 0 1

test_req $2 0:0:0:0:0:0,48 0 0 ''

# Should see an event on the other stream (3)
poll $1 $2 $1

test_ind $1 0

test_res $1 0:0:0:0:0:0,40 0 ''

poll $1 $2 $2

test_con $2 0

poll $1 $2 0

check_state $1 dl_idle
check_state $2 dl_idle

# subs-bind for remote address with SAP 48
subs_bind $1 0:0:0:0:0:0,48 2

# subs-bind for remote address with SAP 40
subs_bind $2 0:0:0:0:0:0,40 2

# send to wrong address
test_req $2 0:0:0:0:0:0,58 0 0 ''
sleep 1

# Should see no event
poll $1 $2 0

# send to wrong address
test_res $1 0:0:0:0:0:0,50 0 ''
sleep 1

# Should see no event
poll $1 $2 0

close $1
close $2

###### Test case #3 ######
open 1
attach $1 43
bind $1 48 2 2 0 1

open 2
attach $2 43
bind $2 40 2 0 0 1

# subs-bind for remote address with SAP 40
subs_bind $1 0:0:0:0:0:0,40 2

# subs-bind for remote address with SAP 48
subs_bind $2 0:0:0:0:0:0,48 2

connect $2 0:0:0:0:0:0,48 0

# Should see an event on the listen stream (3)
poll $1 $2 $1

# Receive the incoming call
connect_ind $1 1 -

# Should see an event on the connecting stream (4)
poll $1 $2 $2

# Receive the connect confirmation
connect_con $2

poll $1 $2 0

test_req $2 0:0:0:0:0:0,48 0 0 ''

# Should see an event on the other stream (3)
poll $1 $2 $1

test_ind $1 0

test_res $1 0:0:0:0:0:0,40 0 ''

poll $1 $2 $2

test_con $2 0

poll $1 $2 0

check_state $1 dl_dataxfer
check_state $2 dl_dataxfer

close $1
close $2

###### Test case #4 ######
open 1
attach $1 43
bind $1 48 2 2 0 1

open 2
attach $2 43
bind $2 40 2 0 0 1

# subs-bind for remote address with SAP 40
subs_bind $1 0:0:0:0:0:0,40 2

test_req $2 0:0:0:0:0:0,48 0 0 ''
sleep 1

poll $1 $2 $1

test_ind $1 0

test_res $2 0:0:0:0:0:0,48 0 ''

poll $1 $2 $1

test_con $1 0

unbind $2
bind $2 58 2 0 0 1

connect $2 0:0:0:0:0:0,48 0

# Should see an event on the listen stream (3)
poll $1 $2 $1

# Receive the incoming call
connect_ind $1 1 -

# Should see an event on the connecting stream (4)
poll $1 $2 $2

# Receive the connect confirmation
connect_con $2

poll $1 $2 0

test_req $2 0:0:0:0:0:0,48 0 0 ''

# Should see an event on the other stream (3)
poll $1 $2 $1

test_ind $1 0

test_res $2 0:0:0:0:0:0,48 0 ''

poll $1 $2 $1

test_con $1 0

poll $1 $2 0

# should not receive responses from address in subs-bind
test_req $2 0:0:0:0:0:0,40 0 0 ''
sleep 1

poll $1 $2 0

test_res $2 0:0:0:0:0:0,40 0 ''
sleep 1

poll $1 $2 0

check_state $1 dl_dataxfer
check_state $2 dl_dataxfer

close $1
close $2

###### Test case #5 ######
open 1
attach $1 43
bind $1 48 2 2 0 3

open 2
attach $2 43
bind $2 40 2 0 0 1

# subs-bind for remote address with SAP 40
subs_bind $1 0:0:0:0:0:0,40 2

# subs-bind for remote address with SAP 48
subs_bind $2 0:0:0:0:0:0,48 2

test_req $2 0:0:0:0:0:0,48 0 0 '8 9 10 11 12'

# Should see event (the con on 2)
poll $1 $2 $2

test_con $2 0

test_res $2 0:0:0:0:0:0,48 0 '13 14 15 16'

# Should see no event
poll $1 $2 0

check_state $1 dl_idle
check_state $2 dl_idle

close $1
close $2

###### Test case #6 ######
open 1
attach $1 43
bind $1 48 2 2 0 2

open 2
attach $2 43
bind $2 40 2 0 0 2

# subs-bind for remote address with SAP 40
subs_bind $1 0:0:0:0:0:0,40 2

# subs-bind for remote address with SAP 48
subs_bind $2 0:0:0:0:0:0,48 2

xid_req $2 0:0:0:0:0:0,48 0 0 '1 2 3'

# Should see an event on the other stream (3)
poll $1 $2 $1

xid_ind $1 0

xid_res $1 0:0:0:0:0:0,40 0 '4 5 6'

poll $1 $2 $2

xid_con $2 0

poll $1 $2 0

check_state $1 dl_idle
check_state $2 dl_idle

close $1
close $2

###### Test case #7 ######
open 1
attach $1 43
bind $1 48 2 2 0 2

open 2
attach $2 43
bind $2 40 2 0 0 2

xid_req $2 0:0:0:0:0:0,48 0 0 ''

# Should see an event on the other stream (3)
poll $1 $2 $1

xid_ind $1 0

xid_res $1 0:0:0:0:0:0,40 0 ''

poll $1 $2 $2

xid_con $2 0

poll $1 $2 0

check_state $1 dl_idle
check_state $2 dl_idle

# subs-bind for remote address with SAP 48
subs_bind $1 0:0:0:0:0:0,48 2

# subs-bind for remote address with SAP 40
subs_bind $2 0:0:0:0:0:0,40 2

# send to wrong address
xid_req $2 0:0:0:0:0:0,58 0 0 ''
sleep 1

# Should see no event
poll $1 $2 0

# send to wrong address
xid_res $1 0:0:0:0:0:0,50 0 ''
sleep 1

# Should see no event
poll $1 $2 0

close $1
close $2

###### Test case #8 ######
open 1
attach $1 43
bind $1 48 2 2 0 2

open 2
attach $2 43
bind $2 40 2 0 0 2

# subs-bind for remote address with SAP 40
subs_bind $1 0:0:0:0:0:0,40 2

# subs-bind for remote address with SAP 48
subs_bind $2 0:0:0:0:0:0,48 2

connect $2 0:0:0:0:0:0,48 0

# Should see an event on the listen stream (3)
poll $1 $2 $1

# Receive the incoming call
connect_ind $1 1 -

# Should see an event on the connecting stream (4)
poll $1 $2 $2

# Receive the connect confirmation
connect_con $2

# Recieve the XID and repond to it.
#NEW-3
poll $1 $2 $2
xid_ind $2 0
xid_res $2 0:0:0:0:0:0,48 0 '81 03 fe'

poll $1 $2 0

xid_req $2 0:0:0:0:0:0,48 0 0 ''

# Should see an event on the other stream (3)
poll $1 $2 $1

xid_ind $1 0

xid_res $1 0:0:0:0:0:0,40 0 ''

poll $1 $2 $2

xid_con $2 0

poll $1 $2 0

check_state $1 dl_dataxfer
check_state $2 dl_dataxfer

close $1
close $2

###### Test case #9 ######
open 1
attach $1 43
bind $1 48 2 2 0 2

open 2
attach $2 43
bind $2 40 2 0 0 2

# subs-bind for remote address with SAP 40
subs_bind $1 0:0:0:0:0:0,40 2

xid_req $2 0:0:0:0:0:0,48 0 0 ''
sleep 1

poll $1 $2 $1

xid_ind $1 0

xid_res $2 0:0:0:0:0:0,48 0 ''

poll $1 $2 $1

xid_con $1 0

unbind $2
bind $2 58 2 0 0 2

connect $2 0:0:0:0:0:0,48 0

# Should see an event on the listen stream (3)
poll $1 $2 $1

# Receive the incoming call
connect_ind $1 1 -

# Should see an event on the connecting stream (4)
poll $1 $2 $2

# Receive the connect confirmation
connect_con $2

# Recieve the XID and repond to it.
#NEW-3
poll $1 $2 $2
xid_ind $2 0
xid_res $2 0:0:0:0:0:0,48 0 '81 03 fe'

poll $1 $2 0

xid_req $2 0:0:0:0:0:0,48 0 0 ''

# Should see an event on the other stream (3)
poll $1 $2 $1

xid_ind $1 0

xid_res $2 0:0:0:0:0:0,48 0 ''

poll $1 $2 $1

xid_con $1 0

poll $1 $2 0

# should not receive responses from address in subs-bind
xid_req $2 0:0:0:0:0:0,40 0 0 ''
sleep 1

poll $1 $2 0

xid_res $2 0:0:0:0:0:0,40 0 ''
sleep 1

poll $1 $2 0

check_state $1 dl_dataxfer
check_state $2 dl_dataxfer

close $1
close $2

###### Test case #5 ######
open 1
attach $1 43
bind $1 48 2 2 0 3

open 2
attach $2 43
bind $2 40 2 0 0 2

# subs-bind for remote address with SAP 40
subs_bind $1 0:0:0:0:0:0,40 2

# subs-bind for remote address with SAP 48
subs_bind $2 0:0:0:0:0:0,48 2

xid_req $2 0:0:0:0:0:0,48 0 0 '8 9 10 11 12'

# Should see event (the con on 2)
poll $1 $2 $2

xid_con $2 0

xid_res $2 0:0:0:0:0:0,48 0 '13 14 15 16'

# Should see no event
poll $1 $2 0

check_state $1 dl_idle
check_state $2 dl_idle

close $1
close $2

###### Test case #11 ######
open 1
attach $1 43
bind $1 40 2 0 0 0

# attempt a peer subs-bind
subs_bind $1 0:0:0:0:0:0,48 1		dl_error_ack dl_unsupported

# subs-bind for remote address with SAP 48
subs_bind $1 0:0:0:0:0:0,48 2

# attempt to subs-bind for another remote address 
subs_bind $1 0:0:0:0:0:0,58 2		dl_error_ack dl_badaddr

subs_unbind $1 0:0:0:0:0:0,48

subs_unbind $1 0:0:0:0:0:0,48		dl_error_ack dl_badaddr

subs_bind $1 0:0:0:0:0:0 2		dl_error_ack dl_badaddr

subs_bind $1 0:0:0:0:0:0,48,48	2	dl_error_ack dl_badaddr

subs_bind $1 0:0:0:0:0:0,58 2

subs_unbind $1 0:0:0:0:0:0,48		 dl_error_ack dl_badaddr

subs_unbind $1 0:0:0:0:0:1,58		 dl_error_ack dl_badaddr

close $1
