# Tests of Ethernet data transmission on subs-bound endpoints

# Open and bind two Ethernet streams
open 1
attach $1 43
bind $1 2040 1 0 0 0

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

subs_bind $2 0:0:0:0:0:0,20,50 2

# Send data from 1 to 2 on one sap
send_udata $1 0:0:0:0:0:0,20,48 '1 2 3 4 5'

poll $1 $2 $2

recv_udata $2 '1 2 3 4 5'

# Send data from 1 to 2 on other sap
send_udata $1 0:0:0:0:0:0,20,50 '1 2 3 4 5'

poll $1 $2 $2

recv_udata $2 '1 2 3 4 5'

# Send data from 1 to 2 on invalid sap
send_udata $1 0:0:0:0:0:0,20,49 '1 2 3 4 5'

sleep 1

poll $1 $2 0

# subs-bind to match some data
subs_bind $2 0:0:0:0:0:0,20,50,20,30 2

# Send data from 1 to 2 on inactive sap
send_udata $1 0:0:0:0:0:0,20,50 '1 2 3 4 5'

sleep 1

poll $1 $2 0

# Send data from 1 to 2 with incorrect match
send_udata $1 0:0:0:0:0:0,20,50 '20 29 3 4 5'

sleep 1

poll $1 $2 0

# Send data from 1 to 2 with too-short match
send_udata $1 0:0:0:0:0:0,20,50 '20'

sleep 1

poll $1 $2 0

# Send data from 1 to 2 on sap with matching data
send_udata $1 0:0:0:0:0:0,20,50 '20 30 3 4 5'

poll $1 $2 $2

recv_udata $2 '20 30 3 4 5'

# Send data from 2 to 2 on sap with matching data
send_udata $2 0:0:0:0:0:0,20,50 '20 30 3 4 5 6 7 8 9 10'

poll $1 $2 $2

recv_udata $2 '20 30 3 4 5 6 7 8 9 10'

# subs-bind to match some data on 1
subs_bind $1 0:0:0:0:0:0,20,50,20,30,3 2

# Send data from 2 to 1 on sap with matching data
send_udata $2 0:0:0:0:0:0,20,50 '20 30 3 4 5 6 7 8 9 10'

poll $1 $2 $1

recv_udata $1 '20 30 3 4 5 6 7 8 9 10'

# subs-unbind 
subs_unbind $1 0:0:0:0:0:0,20,50,20,30,3

# Send data from 1 to 2 on sap with matching data
send_udata $1 0:0:0:0:0:0,20,50 '20 30 3 4 5 6 7 8 9 10'

poll $1 $2 $2

recv_udata $2 '20 30 3 4 5 6 7 8 9 10'

# subs-bind to take over some of 1's area
subs_bind $2 0:0:0:0:0:0,20,40,01 2

# Send data from 1 to 2 on sap with matching data
send_udata $1 0:0:0:0:0:0,20,40 '1 2 3 4 5 6 7 8 9 10'

poll $1 $2 $2

recv_udata $2 '1 2 3 4 5 6 7 8 9 10'

# Send data from 1 to 1 on sap with matching data
send_udata $1 0:0:0:0:0:0,20,40 '2 2 3 4 5 6 7 8 9 10'

poll $1 $2 $1

recv_udata $1 '2 2 3 4 5 6 7 8 9 10'

# unbind 2, causing its subs-bind to be deregistered
unbind $2

# Send data from 1 to 1 on sap which was previously subs-bind for by 2
send_udata $1 0:0:0:0:0:0,20,40 '1 2 3 4 5 6 7 8 9 10'

poll $1 $2 $1

recv_udata $1 '1 2 3 4 5 6 7 8 9 10'
