|
| 1 | +#!/bin/bash |
| 2 | +# SPDX-License-Identifier: BSD-3-Clause |
| 3 | +# Copyright (c) 2025 Christophe Fontaine |
| 4 | + |
| 5 | +# .--------------------. |
| 6 | +# | netns "ospf-peer" | |
| 7 | +# .--------..------------. | .-------. | |
| 8 | +# | zebra || grout | | | ospfd | | |
| 9 | +# '--------'| | | '-------' | |
| 10 | +# .-------. | .------------. .------------. .-------. | |
| 11 | +# | ospfd | | | p0 | net_tap | x-p0 | | zebra | | |
| 12 | +# '-------' | | +---------------+ | '-------' | |
| 13 | +# .----------. | 172.16.0.1 | | 172.16.0.2 |.----------. | |
| 14 | +# | gr-loop0 | '------------' '------------'| lo | | |
| 15 | +# '----------' | | | | | |
| 16 | +# | ping <------------------------------------> | 16.0.0.1 | | |
| 17 | +# | | | '----------' | |
| 18 | +# '-------------' '--------------------' |
| 19 | + |
| 20 | +. $(dirname $0)/_init_frr.sh |
| 21 | + |
| 22 | +create_interface p0 |
| 23 | +set_ip_address p0 172.16.0.1/24 |
| 24 | + |
| 25 | +start_frr_on_namespace ospf-peer |
| 26 | +ip link set x-p0 netns ospf-peer |
| 27 | + |
| 28 | +ip -n grout l set p0 up |
| 29 | +ip -n ospf-peer l set x-p0 up |
| 30 | + |
| 31 | +# Configure Grout FRR instance |
| 32 | +vtysh <<-EOF |
| 33 | +configure terminal |
| 34 | +ip router-id 172.16.0.1 |
| 35 | +! |
| 36 | +debug ospf event |
| 37 | +debug ospf packet all |
| 38 | +! |
| 39 | +interface lo |
| 40 | + ip address 17.0.0.1/24 |
| 41 | +exit |
| 42 | +! |
| 43 | +interface p0 |
| 44 | + ip ospf hello-interval 1 |
| 45 | +exit |
| 46 | +! |
| 47 | +! |
| 48 | +router ospf |
| 49 | + ospf router-id 172.16.0.1 |
| 50 | + network 172.16.0.0/24 area 10.0.0.1 |
| 51 | + network 17.0.0.0/24 area 10.0.0.1 |
| 52 | +exit |
| 53 | +! |
| 54 | +EOF |
| 55 | + |
| 56 | +vtysh -N ospf-peer <<-EOF |
| 57 | +configure terminal |
| 58 | +ip router-id 172.16.0.2 |
| 59 | +! |
| 60 | +debug ospf event |
| 61 | +debug ospf packet all |
| 62 | +! |
| 63 | +interface lo |
| 64 | + ip address 16.0.0.1/24 |
| 65 | +exit |
| 66 | +! |
| 67 | +interface x-p0 |
| 68 | + ip address 172.16.0.2/24 |
| 69 | + ip ospf hello-interval 1 |
| 70 | +exit |
| 71 | +! |
| 72 | +router ospf |
| 73 | + ospf router-id 172.16.0.2 |
| 74 | + network 172.16.0.0/24 area 10.0.0.1 |
| 75 | + network 16.0.0.0/24 area 10.0.0.1 |
| 76 | +exit |
| 77 | +end |
| 78 | +! |
| 79 | +EOF |
| 80 | + |
| 81 | +attempts=20 |
| 82 | +while ! $(vtysh -c 'show ip ospf neighbor json' | jq '.neighbors."172.16.0.2"[0].converged == "Full"' -e > /dev/null) ; do |
| 83 | + sleep 1 |
| 84 | + if [ "$attempts" -le 0 ]; then |
| 85 | + fail "OSPF failed to connect to neighbor." |
| 86 | + fi |
| 87 | + attempts=$((attempts - 1)) |
| 88 | +done |
| 89 | + |
| 90 | +attempts=10 |
| 91 | +while ! $(vtysh -c 'show ip route ospf json' | jq '."16.0.0.1/32"[0].protocol == "ospf"' -e > /dev/null) ; do |
| 92 | + sleep 1 |
| 93 | + if [ "$attempts" -le 0 ]; then |
| 94 | + fail "OSPF failed to get routes." |
| 95 | + fi |
| 96 | + attempts=$((attempts - 1)) |
| 97 | +done |
| 98 | + |
| 99 | +grcli ping 16.0.0.1 count 1 |
0 commit comments