# Seis sistemas autónomos en jerarquía, más dos proveedores grandes en la cima. r6 es
# el atacante, r4 es el cliente con dos proveedores y cache es el servidor RTR.
#
#      AS 64630  c ----peer---- d  AS 64640
#                |              |
#      AS 64610  a              b  AS 64620
#              / | \           / \
#            r1  r6  \        /   r3
#            |        \      /     |
#            h1        r4 ---     srv
#                     AS 64604
#
#   r1 AS 64601 (h1), r3 AS 64603 (srv), r6 AS 64666 (atacante)
name: w07-bgp
mgmt:
  network: redes-w07-bgp
  ipv4-subnet: 172.90.7.0/26
  ipv6-subnet: 3fff:172:90:7::/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.
    c:
      binds: [c/frr.conf:/etc/frr/frr.conf:ro]
      exec: &router-exec
        - ip route del default
        - sysctl -w net.ipv6.conf.all.disable_ipv6=1
    d:
      binds: [d/frr.conf:/etc/frr/frr.conf:ro, daemons-rpki:/etc/frr/daemons]
      exec: *router-exec
    a:
      binds: [a/frr.conf:/etc/frr/frr.conf:ro, daemons-rpki:/etc/frr/daemons]
      exec: *router-exec
    b:
      binds: [b/frr.conf:/etc/frr/frr.conf:ro]
      exec: *router-exec
    r1:
      binds: [r1/frr.conf:/etc/frr/frr.conf:ro]
      exec: *router-exec
    r3:
      binds: [r3/frr.conf:/etc/frr/frr.conf:ro]
      exec: *router-exec
    # r4 y r6 anuncian su bloque desde una interfaz dummy: no necesitan una LAN.
    r4:
      binds: [r4/frr.conf:/etc/frr/frr.conf:ro]
      exec:
        - ip route del default
        - sysctl -w net.ipv6.conf.all.disable_ipv6=1
        - ip link add dum0 type dummy
        - ip link set dum0 up
    r6:
      binds: [r6/frr.conf:/etc/frr/frr.conf:ro, www/attacker.html:/www/index.html]
      exec:
        - ip route del default
        - sysctl -w net.ipv6.conf.all.disable_ipv6=1
        - ip link add dum0 type dummy
        - ip link set dum0 up
        - sh -c 'python3 -m http.server 8080 --directory /www >/dev/null 2>&1 &'
    h1:
      exec:
        - ip route del default
        - sysctl -w net.ipv6.conf.all.disable_ipv6=1
        - ip addr add 100.64.1.10/24 dev eth1
        - ip route add default via 100.64.1.1
    srv:
      binds: [www/server.html:/www/index.html]
      exec:
        - ip route del default
        - sysctl -w net.ipv6.conf.all.disable_ipv6=1
        - ip addr add 100.64.3.10/24 dev eth1
        - ip addr add 100.64.3.200/24 dev eth1
        - ip route add default via 100.64.3.1
        - sh -c 'python3 -m http.server 8080 --directory /www >/dev/null 2>&1 &'
    cache:
      binds: [cache:/cache]
      exec:
        - ip route del default
        - sysctl -w net.ipv6.conf.all.disable_ipv6=1
        - ip addr add 10.207.9.2/30 dev eth1
        - ip addr add 10.207.10.2/30 dev eth2
        - sh -c 'python3 /cache/rtr_cache.py /cache/vrps.txt >/tmp/rtr.log 2>&1 &'
        - sh -c 'python3 /cache/rtr_cache.py /cache/vrps-lax.txt --port 8283 >/tmp/rtr-lax.log 2>&1 &'
  # Containerlab usa MTU 9500 por defecto; aquí queremos el valor de Ethernet.
  links:
    - {endpoints: ["c:eth1", "d:eth1"], mtu: 1500}
    - {endpoints: ["a:eth1", "c:eth2"], mtu: 1500}
    - {endpoints: ["b:eth1", "d:eth2"], mtu: 1500}
    - {endpoints: ["r1:eth2", "a:eth2"], mtu: 1500}
    - {endpoints: ["r6:eth1", "a:eth3"], mtu: 1500}
    - {endpoints: ["r4:eth1", "a:eth4"], mtu: 1500}
    - {endpoints: ["r4:eth2", "b:eth2"], mtu: 1500}
    - {endpoints: ["r3:eth2", "b:eth3"], mtu: 1500}
    - {endpoints: ["h1:eth1", "r1:eth1"], mtu: 1500}
    - {endpoints: ["srv:eth1", "r3:eth1"], mtu: 1500}
    - {endpoints: ["cache:eth1", "a:eth5"], mtu: 1500}
    - {endpoints: ["cache:eth2", "d:eth3"], mtu: 1500}
