コード例 #1
0
ファイル: nat_ifaces.py プロジェクト: PetarMI/thesis-eth
def validate_input(o_ifaces: dict, s_ifaces: dict):
    net_validator.validate_interfaces(o_ifaces, s_ifaces)

    check_same_devices(o_ifaces, s_ifaces)
    check_same_length(o_ifaces, s_ifaces)

    check_repeated_subnets(o_ifaces)
    check_repeated_subnets(s_ifaces)
コード例 #2
0
def test_valid_ifaces_success():
    interfaces = {
        "topo-r01": {
            "eth0": "10.0.1.3/24",
            "eth1": "10.0.2.3/24",
            "eth2": "10.0.3.2/24",
        },
        "topo-r02": {
            "eth5": "10.0.2.2/24",
            "eth4": "10.0.5.1/24",
        },
        "topo-r03": {
            "eth2": "10.0.1.4/24",
            "eth6": "10.0.2.4/24",
            "eth3": "10.0.4.2/24",
            "eth0": "10.0.5.5/24"
        }
    }

    net_validator.validate_interfaces(interfaces)
コード例 #3
0
def test_valid_ifaces_fail_no_netmask():
    with pytest.raises(ValueError, match="No prefix for subnet: 10.0.2.2"):
        interfaces = {
            "topo-r01": {
                "eth0": "10.0.1.3/24",
                "eth1": "10.0.2.3/24",
                "eth2": "10.0.3.2/14",
            },
            "topo-r02": {
                "eth5": "10.0.2.2",
                "eth4": "10.0.5.1/24",
            },
            "topo-r03": {
                "eth2": "10.0.1.4/24",
                "eth6": "10.0.2.422/24",
                "eth3": "10.0.4.2/24",
                "eth0": "10.0.5.5/24"
            }
        }

        net_validator.validate_interfaces(interfaces)
コード例 #4
0
def test_valid_ifaces_fail_empty():
    with pytest.raises(ipaddress.AddressValueError):
        interfaces = {
            "topo-r01": {
                "eth0": "10.0.1.3/24",
                "eth1": "10.0.2.3/24",
                "eth2": "10.0.3.2/24",
            },
            "topo-r02": {
                "eth5": "10.0.2.2/24",
                "eth4": "10.0.5.1/24",
            },
            "topo-r03": {
                "eth2": "",
                "eth6": "10.0.2.4/24",
                "eth3": "10.0.4.2/24",
                "eth0": "10.0.5.5/24"
            }
        }

        net_validator.validate_interfaces(interfaces)
コード例 #5
0
def test_valid_ifaces_fail_mixed():
    with pytest.raises(ipaddress.NetmaskValueError,
                       match="Invalid netmask: 10.0.3.2/"):
        interfaces = {
            "topo-r01": {
                "eth0": "10.0.1.3/24",
                "eth1": "10.0.2.3/24",
                "eth2": "10.0.3.2/",
            },
            "topo-r02": {
                "eth5": "10.0.2.2",
                "eth4": "10.0.5.1/24",
            },
            "topo-r03": {
                "eth2": "10.0.1.4/24",
                "eth6": "10.0.2.422/24",
                "eth3": "10.0.4.2/24",
                "eth0": "10.0.5.5/24"
            }
        }

        net_validator.validate_interfaces(interfaces)