#!/bin/sh

set -e

ME=$(basename $0)
SCRIPT=$(readlink -f ../../../odi-gen-net-config)
FIXTURES=$(readlink -f ../fixtures)

T=$(mktemp -d /tmp/odi-gen-net-config-bgp-dedupe.XXXXXX)
trap 'rm -rf ${T}' EXIT
mkdir -p ${T}/etc/frr ${T}/etc/network
printf 'bgpd=no\nzebra=yes\nospfd=no\n' > ${T}/etc/frr/daemons

# Two type=bgp specs: the first one hands the management IP through both
# addr= and addbgpi= (must render a single /32 on lo), the second one
# only addbgpi= with another IP (must render a second /32, and the
# empty comma-joined entry from the missing addr= must be skipped).
"${SCRIPT}" --root ${T} --release bookworm \
	--static-iface type=bgp,vlannum=10,iface0=enp0s4,iface1=enp0s5,addr=192.168.101.131/24:192.168.101.1,asnum=65499,addbgpi=192.168.101.131 \
	--static-iface type=bgp,vlannum=10,iface0=enp0s6,iface1=enp0s7,asnum=65499,addbgpi=192.168.101.132

diff -r ${FIXTURES}/bgp-dedupe/etc ${T}/etc
grep -q '^bgpd=yes$' ${T}/etc/frr/daemons
