#!/usr/bash
setup_net() {

    ip tuntap add dev tap0 mode tap
    ip tuntap add dev tap1 mode tap

    ip link add name br0 type bridge
    ip link add name br1 type bridge

    ip link set dev tap0 master br0
    ip link set dev tap1 master br1

    ip addr add 172.16.1.1/24 dev br0
    ip addr add 172.16.2.1/24 dev br1

    ip link set dev br0 up
    ip link set dev br1 up
    ip link set dev tap0 up
    ip link set dev tap1 up

}
clean_net() {
    ip link set tap0 down 2>/dev/null
    ip link delete tap0 2>/dev/null

    ip link set tap1 down 2>/dev/null
    ip link delete tap1 2>/dev/null

    # 清理 bridge
    ip link set br0 down 2>/dev/null
    ip link delete br0 type bridge 2>/dev/null

    ip link set br1 down 2>/dev/null
    ip link delete br1 type bridge 2>/dev/null
}
