tests/topotests: Added basic test for disable-establish-hello ldpd option

Test runs ldpd on 3 routers with and without option.
Iptables is used to count LDP hello messages.

Signed-off-by: Andrii Melnychenko <a.melnychenko@vyos.io>
This commit is contained in:
Andrii Melnychenko 2025-03-25 13:25:55 +01:00
parent 7bc20bd767
commit 90084d21e0
8 changed files with 357 additions and 0 deletions

View file

@ -0,0 +1,21 @@
hostname r1
log file ldpd.log
!
! debug mpls ldp zebra
! debug mpls ldp event
! debug mpls ldp errors
! debug mpls ldp messages recv
! debug mpls ldp messages sent
! debug mpls ldp discovery hello recv
! debug mpls ldp discovery hello sent
!
mpls ldp
router-id 1.1.1.1
!
address-family ipv4
discovery transport-address 1.1.1.1
!
!
!
line vty
!

View file

@ -0,0 +1,17 @@
log file zebra.log
!
hostname r1
!
interface lo
ip address 1.1.1.1/32
!
interface r1-eth0
description to sw0
ip address 10.0.1.1/24
no link-detect
!
ip forwarding
!
!
line vty
!

View file

@ -0,0 +1,21 @@
hostname r2
log file ldpd.log
!
! debug mpls ldp zebra
! debug mpls ldp event
! debug mpls ldp errors
! debug mpls ldp messages recv
! debug mpls ldp messages sent
! debug mpls ldp discovery hello recv
! debug mpls ldp discovery hello sent
!
mpls ldp
router-id 2.2.2.2
!
address-family ipv4
discovery transport-address 2.2.2.2
!
!
!
line vty
!

View file

@ -0,0 +1,17 @@
log file zebra.log
!
hostname r2
!
interface lo
ip address 2.2.2.2/32
!
interface r2-eth0
description to sw0
ip address 10.0.1.2/24
no link-detect
!
ip forwarding
!
!
line vty
!

View file

@ -0,0 +1,21 @@
hostname r3
log file ldpd.log
!
! debug mpls ldp zebra
! debug mpls ldp event
! debug mpls ldp errors
! debug mpls ldp messages recv
! debug mpls ldp messages sent
! debug mpls ldp discovery hello recv
! debug mpls ldp discovery hello sent
!
mpls ldp
router-id 3.3.3.3
!
address-family ipv4
discovery transport-address 3.3.3.3
!
!
!
line vty
!

View file

@ -0,0 +1,17 @@
log file zebra.log
!
hostname r3
!
interface lo
ip address 3.3.3.3/32
!
interface r3-eth0
description to sw0
ip address 10.0.1.3/24
no link-detect
!
ip forwarding
!
!
line vty
!

View file

@ -0,0 +1,51 @@
## Color coding:
#########################
## Main FRR: #f08080 red
## Switches: #d0e0d0 gray
## RIP: #19e3d9 Cyan
## RIPng: #fcb314 dark yellow
## OSPFv2: #32b835 Green
## OSPFv3: #19e3d9 Cyan
## ISIS IPv4 #fcb314 dark yellow
## ISIS IPv6 #9a81ec purple
## BGP IPv4 #eee3d3 beige
## BGP IPv6 #fdff00 yellow
##### Colors (see http://www.color-hex.com/)
graph template {
label="Test Topology - LDP-ESTABLISH-HELLO 1";
# Routers
r1 [
shape=doubleoctagon,
label="1.1.1.1",
fillcolor="#f08080",
style=filled,
];
r2 [
shape=doubleoctagon
label="2.2.2.2",
fillcolor="#f08080",
style=filled,
];
r3 [
shape=doubleoctagon
label="3.3.3.3",
fillcolor="#f08080",
style=filled,
];
# Switches
sw0 [
shape=oval,
label="10.0.1.0/24",
fillcolor="#d0e0d0",
style=filled,
];
# Connections
r1 -- sw0 [label="r1-eth0"];
r2 -- sw0 [label="r2-eth0"];
r3 -- sw0 [label="r3-eth0"];
}

View file

@ -0,0 +1,192 @@
#!/usr/bin/env python
# SPDX-License-Identifier: ISC
#
# test_establish_hello_topo1.py
#
# Copyright (c) 2025 by VyOS Networks
# Andrii Melnychenko (a.melnychenko@vyos.io)
#
r"""
test_establish_hello_topo1.py: Simple FRR LDP Test
+-------------+
| r1 |
| 1.1.1.1 |
+-------------+
|
| .1 r1-eth0
|
+---------+ ~~~~~~~~~~~~~
| r2 | .2 r2-eth0 ~~ sw0 ~~
| 2.2.2.2 | ------------- ~~ 10.0.1.0/24 ~~
+---------+ ~~~~~~~~~~~~~
|
| .3 r3-eth0
|
+-------------+
| r3 |
| 3.3.3.3 |
+-------------+
"""
import os
import re
import sys
import pytest
from time import sleep
from lib.topogen import Topogen, get_topogen
fatal_error = ""
pytestmark = [pytest.mark.ldpd]
def build_topo(tgen):
# Setup Routers
for router in ["r1", "r2", "r3"]:
tgen.add_router(router)
# Switch
switch = tgen.add_switch("sw0")
switch.add_link(tgen.gears["r1"])
switch.add_link(tgen.gears["r2"])
switch.add_link(tgen.gears["r3"])
def setup_module(module):
thisDir = os.path.dirname(os.path.realpath(__file__))
tgen = Topogen(build_topo, module.__name__)
tgen.start_topology()
net = tgen.net
# Starting Routers
for router in ["r1", "r2", "r3"]:
net[router].loadConf("zebra", "%s/%s/zebra.conf" % (thisDir, router))
net[router].loadConf("ldpd", "%s/%s/ldpd.conf" % (thisDir, router))
tgen.gears[router].start()
# For debugging after starting FRR daemons, uncomment the next line
# tgen.mininet_cli()
def teardown_module(module):
tgen = get_topogen()
tgen.stop_topology()
def test_default_behaviour():
global fatal_error
# Skip if previous fatal error condition is raised
if fatal_error != "":
pytest.skip(fatal_error)
tgen = get_topogen()
# Setup counters
tgen.gears["r3"].run("""
iptables -t filter -A INPUT -s 10.0.1.1 -p udp --dport 646 -j ACCEPT
iptables -t filter -A INPUT -s 10.0.1.2 -p udp --dport 646 -j ACCEPT
iptables -t filter -A OUTPUT -s 10.0.1.3 -p udp --dport 646 -j ACCEPT
""")
# Setup the LDP service
for router in ["r3", "r2", "r1"]:
tgen.gears[router].vtysh_multicmd([
"configure terminal",
"mpls ldp",
"address-family ipv4",
f"interface {router}-eth0",
"end"])
sleep(7)
# Get values from counters
output = tgen.gears["r3"].run("iptables -t filter -L -v -n")
# Disable the LDP service
for router in ["r3", "r2", "r1"]:
tgen.gears[router].vtysh_multicmd([
"configure terminal",
"mpls ldp",
"address-family ipv4",
f"no interface {router}-eth0",
"end"])
# Remove counter
tgen.gears["r3"].run("iptables -t filter -F")
pattern = r"\n\s+(\d+)"
matches = re.findall(pattern, output)
# Each router should send at least 2 packets of LDP hello,
# one at the start and one after the "interval"(default 5 sec)
# So, router 10.0.1.1(1.1.1.1) should send only 2 packets
# Router 10.0.1.2(2.2.2.2) sent 2 packets plus 2 packets for each attempt to connect to the 1.1.1.1 - in total 4
# Router 10.0.1.3(3.3.3.3) sent 2 packets plus 2 packets to the 1.1.1.1 and 4 packets to the 2.2.2.2 - in total 8
assert matches == ['2', '4', '8'], "Wrong count of the LDP hello messages"
def test_disable_establish_hello():
global fatal_error
# Skip if previous fatal error condition is raised
if fatal_error != "":
pytest.skip(fatal_error)
tgen = get_topogen()
# Setup counters
tgen.gears["r3"].run("""
iptables -t filter -A INPUT -s 10.0.1.1 -p udp --dport 646 -j ACCEPT
iptables -t filter -A INPUT -s 10.0.1.2 -p udp --dport 646 -j ACCEPT
iptables -t filter -A OUTPUT -s 10.0.1.3 -p udp --dport 646 -j ACCEPT
""")
# Setup the LDP service with disable-establish-hello option
for router in ["r3", "r2", "r1"]:
tgen.gears[router].vtysh_multicmd([
"configure terminal",
"mpls ldp",
"address-family ipv4",
f"interface {router}-eth0",
"disable-establish-hello",
"end"])
sleep(7)
# Get values from counters
output = tgen.gears["r3"].run("iptables -t filter -L -v -n")
# Disable the LDP service
for router in ["r3", "r2", "r1"]:
tgen.gears[router].vtysh_multicmd([
"configure terminal",
"mpls ldp",
"address-family ipv4",
f"no interface {router}-eth0",
"end"])
# Remove counter
tgen.gears["r3"].run("iptables -t filter -F")
pattern = r"\n\s+(\d+)"
matches = re.findall(pattern, output)
# With disabled sending LDP hello message on attempt to establish TCP connection
# Each router should only send 2 packets, at start and after 5 seconds(default interval)
assert matches == ['2', '2', '2'], "Wrong count of the LDP hello messages"
if __name__ == "__main__":
# To suppress tracebacks, either use the following pytest call or add "--tb=no" to cli
# retval = pytest.main(["-s", "--tb=no"])
retval = pytest.main(["-s"])
sys.exit(retval)