#!/bin/sh
# Abre (o cierra, con "off") el peering entre isp1 e isp2 por la LAN del IXP.
# Cada lado anuncia solo lo que origina: un peer no es un proveedor.
set -eu
c1=clab-w07-ixp-isp1
c2=clab-w07-ixp-isp2
no=
[ "${1:-on}" = off ] && no="no "
if [ -z "$no" ]; then
  docker exec "$c1" vtysh -c 'configure terminal' -c 'router bgp 64701' \
    -c 'neighbor 10.208.100.2 remote-as 64702' \
    -c 'neighbor 10.208.100.2 description isp2 (peer por el IXP)' \
    -c 'neighbor 10.208.100.2 advertisement-interval 0' \
    -c 'address-family ipv4 unicast' -c 'neighbor 10.208.100.2 route-map SOLO-PROPIAS out'
  docker exec "$c2" vtysh -c 'configure terminal' -c 'router bgp 64702' \
    -c 'neighbor 10.208.100.1 remote-as 64701' \
    -c 'neighbor 10.208.100.1 description isp1 (peer por el IXP)' \
    -c 'neighbor 10.208.100.1 advertisement-interval 0' \
    -c 'address-family ipv4 unicast' -c 'neighbor 10.208.100.1 route-map SOLO-PROPIAS out'
else
  docker exec "$c1" vtysh -c 'configure terminal' -c 'router bgp 64701' -c 'no neighbor 10.208.100.2'
  docker exec "$c2" vtysh -c 'configure terminal' -c 'router bgp 64702' -c 'no neighbor 10.208.100.1'
fi
