|
| 1 | +#!/usr/bin/env python3 |
| 2 | +r"""LACP Aggregate w/ Degraded Link |
| 3 | +
|
| 4 | +Verify communication over an LACP link aggregate when individual member |
| 5 | +links stop forwarding traffic, without carrier loss. |
| 6 | +
|
| 7 | +.Logical network setup, link breakers (lb1 & lb2) here managed by host PC |
| 8 | +image::lag-failure.svg[] |
| 9 | +
|
| 10 | +The host verifies connectivity with dut2 via dut1 over the aggregate for |
| 11 | +each failure mode step using the `mon` interface. |
| 12 | +
|
| 13 | +""" |
| 14 | +from time import time |
| 15 | +import infamy |
| 16 | +from infamy.netns import TPMR |
| 17 | +from infamy.util import parallel |
| 18 | + |
| 19 | +IPH = "192.168.2.1" |
| 20 | +IP1 = "192.168.2.41" |
| 21 | +IP2 = "192.168.2.42" |
| 22 | + |
| 23 | + |
| 24 | +class LinkBreaker: |
| 25 | + """Encapsulates TPMR based link-breakers.""" |
| 26 | + |
| 27 | + def __init__(self, sys, netns): |
| 28 | + self.net = netns |
| 29 | + self.lb1 = TPMR(sys.ltop.xlate("host", "lb1a")[1], |
| 30 | + sys.ltop.xlate("host", "lb1b")[1]).start() |
| 31 | + self.lb2 = TPMR(sys.ltop.xlate("host", "lb2a")[1], |
| 32 | + sys.ltop.xlate("host", "lb2b")[1]).start() |
| 33 | + |
| 34 | + def forward(self, lb1, lb2): |
| 35 | + """Set link breakers in forwarding or blocking state.""" |
| 36 | + getattr(self.lb1, lb1)() |
| 37 | + getattr(self.lb2, lb2)() |
| 38 | + |
| 39 | + def fail_check(self, peer): |
| 40 | + """Verify connectivity with a given peer during failure.""" |
| 41 | + sequence = [ |
| 42 | + ("forward", "forward"), |
| 43 | + ("forward", "block"), |
| 44 | + ("block", "forward"), |
| 45 | + ("forward", "forward") |
| 46 | + ] |
| 47 | + |
| 48 | + total_start = time() |
| 49 | + print(f"{'LB1':<8} | {'LB2':<8} | {'Status':<8}") |
| 50 | + print("---------|----------|---------") |
| 51 | + |
| 52 | + for lb1, lb2 in sequence: |
| 53 | + state_start = time() |
| 54 | + try: |
| 55 | + print(f"{lb1:<8} | {lb2:<8} | {'...':<8}", end="\r# ") |
| 56 | + self.forward(lb1, lb2) |
| 57 | + self.net.must_reach(peer, timeout=30) |
| 58 | + print(f"{lb1:<8} | {lb2:<8} | {'OK':<8} in " |
| 59 | + f"{time() - state_start:.2f}s") |
| 60 | + except Exception as e: |
| 61 | + print(f"{lb1:<8} | {lb2:<8} | {'FAIL':<8} after " |
| 62 | + f"{time() - state_start:.2f}s") |
| 63 | + print(f"\nError encountered: {e}") |
| 64 | + print(f"Link breakers were in state: LB1='{lb1}', LB2='{lb2}'") |
| 65 | + raise |
| 66 | + |
| 67 | + print(f"Total time: {time() - total_start:.2f}s") |
| 68 | + |
| 69 | + |
| 70 | +def net_init(host, addr): |
| 71 | + """Set up DUT network, dut1 bridges host port with lag0""" |
| 72 | + if host: |
| 73 | + net = [{ |
| 74 | + "name": "br0", |
| 75 | + "type": "infix-if-type:bridge", |
| 76 | + "ipv4": { |
| 77 | + "address": [{"ip": addr, "prefix-length": 24}] |
| 78 | + } |
| 79 | + }, { |
| 80 | + "name": host, |
| 81 | + "bridge-port": {"bridge": "br0"} |
| 82 | + }, { |
| 83 | + "name": "lag0", |
| 84 | + "bridge-port": {"bridge": "br0"} |
| 85 | + }] |
| 86 | + else: |
| 87 | + net = [{ |
| 88 | + "name": "lag0", |
| 89 | + "ipv4": { |
| 90 | + "address": [{"ip": addr, "prefix-length": 24}] |
| 91 | + } |
| 92 | + }] |
| 93 | + return net |
| 94 | + |
| 95 | + |
| 96 | +def dut_init(dut, addr, peer): |
| 97 | + """Configure each DUT specific according to LAG mode and peer""" |
| 98 | + net = net_init(dut["mon"], addr) |
| 99 | + |
| 100 | + dut.put_config_dict("ietf-interfaces", { |
| 101 | + "interfaces": { |
| 102 | + "interface": [{ |
| 103 | + "name": "lag0", |
| 104 | + "type": "infix-if-type:lag", |
| 105 | + "lag": { |
| 106 | + "mode": "lacp", |
| 107 | + "lacp": {"rate": "fast"}, |
| 108 | + "link-monitor": {"interval": 100} |
| 109 | + } |
| 110 | + }, { |
| 111 | + "name": dut["link1"], |
| 112 | + "lag-port": {"lag": "lag0"} |
| 113 | + }, { |
| 114 | + "name": dut["link2"], |
| 115 | + "lag-port": {"lag": "lag0"} |
| 116 | + }] + net |
| 117 | + } |
| 118 | + }) |
| 119 | + |
| 120 | + |
| 121 | +with infamy.Test() as test: |
| 122 | + with test.step("Set up topology and attach to target DUTs"): |
| 123 | + env = infamy.Env() |
| 124 | + dut1 = env.attach("dut1") |
| 125 | + dut2 = env.attach("dut2") |
| 126 | + |
| 127 | + _, mon = env.ltop.xlate("host", "mon") |
| 128 | + with infamy.IsolatedMacVlan(mon) as ns: |
| 129 | + lb = LinkBreaker(env, ns) |
| 130 | + ns.addip(IPH) |
| 131 | + |
| 132 | + print(f"Setting up lag0 in LACP mode between {dut1} and {dut2}") |
| 133 | + with test.step("Set up link aggregate, lag0, between dut1 and dut2"): |
| 134 | + parallel(lambda: dut_init(dut1, IP1, IP2), |
| 135 | + lambda: dut_init(dut2, IP2, IP1)) |
| 136 | + |
| 137 | + with test.step("Initial connectivity check ..."): |
| 138 | + ns.must_reach(IP2, timeout=30) |
| 139 | + |
| 140 | + with test.step("Verify failure modes"): |
| 141 | + lb.fail_check(IP2) |
| 142 | + |
| 143 | + test.succeed() |
0 commit comments