between: { ^^ \S+ \: \s flags \= } { ^^ \S+ \: \s flags \= }

# 1. Capture interface name, flags and MTU
regexp: ^^ (\S+) \: \s flags \= (\d+) \< ( <-[\>]>+ ) \> \s+ mtu \s (\d+)

# 2. Capture IPv4 address, netmask, broadcast (if present)
regexp: \s+ inet \s (\S+) \s+ netmask \s (\S+) \s+ broadcast \s (\S+)

# 3. Capture IPv6 address, prefixlen, scopeid (if present)
regexp: \s+ inet6 \s (\S+) \s+ prefixlen \s (\d+) \s+ scopeid \s (\S+)

# 4. Capture MAC address and txqueuelen (if present)
regexp: \s+ ether \s (<[0..9a..fA..F:]>+) \s+ txqueuelen \s (\d+)

generator: <<CODE
!python
from sparrow6lib import *

for stream in streams_array:
    iface = None
    flags_num = None
    flags_str = None
    mtu = None
    ipv4 = None
    ipv6 = None
    mac = None

    # Iterate over layers in this stream
    for layer in stream:
        # Each layer contains captures (array of captured groups)
        for c in layer:
            n = len(c)
            if n == 4:
                # Interface line: iface, flags_num, flags_str, mtu
                iface = c[0]
                flags_num = c[1]
                flags_str = c[2]
                mtu = c[3]
            elif n == 3:
                # Could be IPv4 or IPv6
                # IPv4: first group contains dots
                # IPv6: first group contains colons
                if '.' in c[0] or c[0].count(':') < 2:
                    ipv4 = {'addr': c[0], 'netmask': c[1], 'broadcast': c[2]}
                else:
                    ipv6 = {'addr': c[0], 'prefixlen': c[1], 'scopeid': c[2]}
            elif n == 2:
                # MAC line: address, txqueuelen
                mac = {'address': c[0], 'txqueuelen': c[1]}

    # Print assertions for this interface
    if iface:
        print(f"assert: 1 interface {iface} found")
        print(f"assert: {flags_num.isdigit() if flags_num else 0} flags numeric for {iface}")
        print(f"assert: {'UP' in flags_str if flags_str else 0} UP flag present on {iface}")
        print(f"assert: {mtu.isdigit() and int(mtu) > 0 if mtu else 0} valid MTU on {iface}")

        if ipv4:
            print(f"assert: 1 IPv4 address {ipv4['addr']} configured on {iface}")
            print(f"assert: 1 netmask {ipv4['netmask']} on {iface}")
            print(f"assert: 1 broadcast {ipv4['broadcast']} on {iface}")
        else:
            print(f"assert: 0 no IPv4 address on {iface}")

        if ipv6:
            print(f"assert: 1 IPv6 address {ipv6['addr']} configured on {iface}")
            valid_plen = ipv6['prefixlen'].isdigit() and 0 <= int(ipv6['prefixlen']) <= 128
            print(f"assert: {valid_plen} valid prefix length on {iface}")
            print(f"assert: 1 scopeid {ipv6['scopeid']} on {iface}")
        else:
            print(f"assert: 0 no IPv6 address on {iface}")

        if mac:
            parts = mac['address'].split(':')
            is_valid_mac = len(parts) == 6 and all(len(p) == 2 for p in parts)
            print(f"assert: {is_valid_mac} valid MAC format on {iface}")
            txq_ok = mac['txqueuelen'].isdigit() and int(mac['txqueuelen']) > 0
            print(f"assert: {txq_ok} valid txqueuelen on {iface}")
        else:
            print(f"assert: 0 no MAC address on {iface}")
    else:
        print("assert: 0 no interface line found in this stream")
CODE