#!/bin/bash

. test.common

test_start "ptp4l with telecom BMCA"

# 1 --> 3 --> 5 ->-
#       ^     ^    \
#       |     |     7
#       v     v    /
# 2 --> 4 --> 6 ->-

subnets="1 3 | 2 4 | 3 5 | 4 6 | 5 7 | 6 7 | 3 4 | 5 6"
nodes=7
max_sync_time=100
time_max_limit=5e-6
freq_max_limit=5e-6
master_nodes="1 2"
master_conf="clockClass 6"
slave_conf="dataset_comparison G.8275.x"

extra_node_confs[1]="masterOnly 1"
extra_node_confs[2]="masterOnly 1"
extra_node_confs[3]="
[eth0]
G.8275.portDS.localPriority 127
[eth2]
masterOnly 1"
extra_node_confs[4]="
[eth1]
G.8275.portDS.localPriority 127
[eth3]
masterOnly 1"
extra_node_confs[5]="
[eth2]
G.8275.portDS.localPriority 127
[eth4]
masterOnly 1"
extra_node_confs[6]="
[eth3]
G.8275.portDS.localPriority 127
[eth5]
masterOnly 1"
extra_node_confs[7]="slaveOnly 1"

run_ptp4l || test_fail
check_sync || test_fail

for i in 3 5 7; do
	check_last_log_message $i "selected best master clock" "123456\.fffe\.78..01" || test_fail
done
for i in 4 6; do
	check_last_log_message $i "selected best master clock" "123456\.fffe\.78..02" || test_fail
done

test_pass
