# Una red leaf-spine: dos spines, tres leaves, dos hosts por leaf y cuatro nodos de
# dos clientes (tenants) que usaremos con VXLAN.
#
#            s1 AS 65140      s2 AS 65140
#            /  |  \          /  |  \
#           /   |   \________/___|___\____
#          /    |  ___\_____/    |    \   \
#        l1 AS 65141   l2 AS 65142   l3 AS 65143
#       / | | \       / | | \         |  \
#     h1 h2 ta1 tb1  h3 h4 ta2 tb2    h5  h6
#
# Todo enlace leaf-spine es un /31: spine = .0, leaf = .1.
#   10.214.1j.0/31  s1 - lj       10.214.2j.0/31  s2 - lj
# Cada leaf tiene una LAN 10.214.j.0/24 y un loopback 10.214.0.j/32. Los spines usan
# 10.214.0.101 y 10.214.0.102. l3 arranca sin BGP: lo configuran ustedes (lab/).
name: w14-fabric
mgmt:
  network: redes-w14-fabric
  ipv4-subnet: 172.90.14.0/26
  ipv6-subnet: 3fff:172:90:14::/80
topology:
  defaults:
    kind: linux
    image: redes-router
  nodes:
    # Se borra la ruta por defecto de gestión (eth0): lo que un nodo no sabe a dónde
    # mandar debe fallar, no irse por Docker. IPv6 se apaga para no ensuciar capturas.
    s1:
      binds: [s1/frr.conf:/etc/frr/frr.conf:ro, daemons:/etc/frr/daemons:ro, ../captures:/captures]
      exec: &router-exec
        - ip route del default
        - sysctl -w net.ipv6.conf.all.disable_ipv6=1
    s2:
      binds: [s2/frr.conf:/etc/frr/frr.conf:ro, daemons:/etc/frr/daemons:ro, ../captures:/captures]
      exec: *router-exec
    l1:
      binds: [l1/frr.conf:/etc/frr/frr.conf:ro, daemons:/etc/frr/daemons:ro]
      exec:
        - ip route del default
        - sysctl -w net.ipv6.conf.all.disable_ipv6=1
        - ip link add br0 type bridge
        - ip link set eth3 master br0
        - ip link set eth4 master br0
        - ip link set br0 up
    l2:
      binds: [l2/frr.conf:/etc/frr/frr.conf:ro, daemons:/etc/frr/daemons:ro]
      exec:
        - ip route del default
        - sysctl -w net.ipv6.conf.all.disable_ipv6=1
        - ip link add br0 type bridge
        - ip link set eth3 master br0
        - ip link set eth4 master br0
        - ip link set br0 up
    l3:
      binds: [l3/frr.conf:/etc/frr/frr.conf:ro, daemons:/etc/frr/daemons:ro]
      exec:
        - ip route del default
        - sysctl -w net.ipv6.conf.all.disable_ipv6=1
        - ip link add br0 type bridge
        - ip link set eth3 master br0
        - ip link set eth4 master br0
        - ip link set br0 up
    h1:
      binds: [../bin:/w14:ro, ../captures:/captures]
      exec:
        - ip route del default
        - sysctl -w net.ipv6.conf.all.disable_ipv6=1
        - ip addr add 10.214.1.10/24 dev eth1
        - ip route add default via 10.214.1.1
    h2:
      binds: [../bin:/w14:ro, ../captures:/captures]
      exec:
        - ip route del default
        - sysctl -w net.ipv6.conf.all.disable_ipv6=1
        - ip addr add 10.214.1.20/24 dev eth1
        - ip route add default via 10.214.1.1
    h3:
      binds: [../bin:/w14:ro, ../captures:/captures]
      exec:
        - ip route del default
        - sysctl -w net.ipv6.conf.all.disable_ipv6=1
        - ip addr add 10.214.2.10/24 dev eth1
        - ip route add default via 10.214.2.1
    h4:
      binds: [../bin:/w14:ro, ../captures:/captures]
      exec:
        - ip route del default
        - sysctl -w net.ipv6.conf.all.disable_ipv6=1
        - ip addr add 10.214.2.20/24 dev eth1
        - ip route add default via 10.214.2.1
    h5:
      binds: [../bin:/w14:ro, ../captures:/captures]
      exec:
        - ip route del default
        - sysctl -w net.ipv6.conf.all.disable_ipv6=1
        - ip addr add 10.214.3.10/24 dev eth1
        - ip route add default via 10.214.3.1
    h6:
      binds: [../bin:/w14:ro, ../captures:/captures]
      exec:
        - ip route del default
        - sysctl -w net.ipv6.conf.all.disable_ipv6=1
        - ip addr add 10.214.3.20/24 dev eth1
        - ip route add default via 10.214.3.1
    # Máquinas de los dos clientes. Usan a propósito las mismas direcciones: cada
    # cliente elige las suyas sin saber nada del otro.
    ta1:
      binds: [../bin:/w14:ro, ../captures:/captures]
      exec: &tenant-exec-1
        - ip route del default
        - sysctl -w net.ipv6.conf.all.disable_ipv6=1
        - ip addr add 10.99.0.1/24 dev eth1
    tb1:
      binds: [../bin:/w14:ro]
      exec: *tenant-exec-1
    ta2:
      binds: [../bin:/w14:ro]
      exec: &tenant-exec-2
        - ip route del default
        - sysctl -w net.ipv6.conf.all.disable_ipv6=1
        - ip addr add 10.99.0.2/24 dev eth1
    tb2:
      binds: [../bin:/w14:ro]
      exec: *tenant-exec-2
  # Containerlab usa MTU 9500 por defecto; aquí queremos el valor de Ethernet.
  links:
    - {endpoints: ["s1:eth1", "l1:eth1"], mtu: 1500}
    - {endpoints: ["s1:eth2", "l2:eth1"], mtu: 1500}
    - {endpoints: ["s1:eth3", "l3:eth1"], mtu: 1500}
    - {endpoints: ["s2:eth1", "l1:eth2"], mtu: 1500}
    - {endpoints: ["s2:eth2", "l2:eth2"], mtu: 1500}
    - {endpoints: ["s2:eth3", "l3:eth2"], mtu: 1500}
    - {endpoints: ["h1:eth1", "l1:eth3"], mtu: 1500}
    - {endpoints: ["h2:eth1", "l1:eth4"], mtu: 1500}
    - {endpoints: ["h3:eth1", "l2:eth3"], mtu: 1500}
    - {endpoints: ["h4:eth1", "l2:eth4"], mtu: 1500}
    - {endpoints: ["h5:eth1", "l3:eth3"], mtu: 1500}
    - {endpoints: ["h6:eth1", "l3:eth4"], mtu: 1500}
    - {endpoints: ["ta1:eth1", "l1:eth5"], mtu: 1500}
    - {endpoints: ["tb1:eth1", "l1:eth6"], mtu: 1500}
    - {endpoints: ["ta2:eth1", "l2:eth5"], mtu: 1500}
    - {endpoints: ["tb2:eth1", "l2:eth6"], mtu: 1500}
