コード例 #1
0
    def test_normal(
        self,
        device_option,
        network,
        is_ipv6,
        expected_ip_ver,
        expected_protocol,
        expected_protocol_match,
    ):
        if device_option is None:
            pytest.skip("device option is null")

        tc_obj = TrafficControl(
            device=device_option,
            netem_param=NetemParameter(
                device=device_option,
                latency_time=Tc.ValueRange.LatencyTime.MIN,
                latency_distro_time=Tc.ValueRange.LatencyTime.MIN,
            ),
            dst_network=network,
            is_ipv6=is_ipv6,
            shaping_algorithm=ShapingAlgorithm.HTB,
        )

        assert tc_obj.ip_version == expected_ip_ver
        assert tc_obj.protocol == expected_protocol
        assert tc_obj.protocol_match == expected_protocol_match
コード例 #2
0
    def test_exception(self, device_option, value, expected):
        if device_option is None:
            pytest.skip("device option is null")

        tc_obj = TrafficControl(
            device=device_option,
            netem_param=NetemParameter(
                device=device_option,
                bandwidth_rate=value.get("bandwidth_rate"),
                latency_time=value.get("latency_time",
                                       Tc.ValueRange.LatencyTime.MIN),
                latency_distro_time=value.get("latency_distro_time",
                                              Tc.ValueRange.LatencyTime.MIN),
                packet_loss_rate=value.get("packet_loss_rate"),
                packet_duplicate_rate=value.get("packet_duplicate_rate"),
                corruption_rate=value.get("corruption_rate"),
            ),
            dst_network=value.get(Tc.Param.DST_NETWORK),
            src_port=value.get("src_port"),
            dst_port=value.get("dst_port"),
            shaping_algorithm=ShapingAlgorithm.HTB,
        )

        with pytest.raises(expected):
            tc_obj.validate()
コード例 #3
0
def test_TrafficControl_validate_bandwidth_rate_normal(value):
    tc_obj = TrafficControl(
        "dummy",
        netem_param=NetemParameter("dummy", bandwidth_rate=value),
        direction=TrafficDirection.OUTGOING,
        shaping_algorithm=ShapingAlgorithm.HTB,
    )
    tc_obj.netem_param.validate_bandwidth_rate()
コード例 #4
0
    def test_normal(
        self,
        device_option,
        rate,
        direction,
        delay,
        delay_distro,
        loss,
        duplicate,
        corrupt,
        src_network,
        exclude_src_network,
        dst_network,
        exclude_dst_network,
        src_port,
        exclude_src_port,
        dst_port,
        exclude_dst_port,
        shaping_algorithm,
    ):
        if device_option is None:
            pytest.skip("device option is null")

        tc_obj = TrafficControl(
            device=device_option,
            direction=direction,
            netem_param=NetemParameter(
                device=device_option,
                bandwidth_rate=rate,
                latency_time=delay,
                latency_distro_time=delay_distro,
                packet_loss_rate=loss,
                packet_duplicate_rate=duplicate,
                corruption_rate=corrupt,
            ),
            src_network=src_network,
            exclude_src_network=exclude_src_network,
            dst_network=dst_network,
            exclude_dst_network=exclude_dst_network,
            src_port=src_port,
            exclude_src_port=exclude_src_port,
            dst_port=dst_port,
            exclude_dst_port=exclude_dst_port,
            is_enable_iptables=True,
            shaping_algorithm=shaping_algorithm,
        )

        if is_invalid_param(rate,
                            delay,
                            loss,
                            duplicate,
                            corrupt,
                            reordering=None):
            with pytest.raises(ParameterError):
                tc_obj.validate()
        else:
            tc_obj.validate()
コード例 #5
0
def test_TrafficControl_validate_bandwidth_rate_exception_2(value, expected):
    with pytest.raises(expected):
        tc_obj = TrafficControl(
            "dummy",
            netem_param=NetemParameter(
                "dummy",
                bandwidth_rate=value,
                latency_time=Tc.ValueRange.LatencyTime.MIN,
                latency_distro_time=Tc.ValueRange.LatencyTime.MIN,
            ),
            shaping_algorithm=ShapingAlgorithm.HTB,
        )
        tc_obj.netem_param.validate_bandwidth_rate()
コード例 #6
0
ファイル: test_netem_param.py プロジェクト: yym1995/tcconfig
    def test_normal(self, value, expected):
        param = NetemParameter(device="eth0", bandwidth_rate=value)

        if expected is None:
            param.validate_bandwidth_rate()
        else:
            with pytest.raises(expected):
                param.validate_bandwidth_rate()
コード例 #7
0
    def test_normal_reordering(self, device_option, direction, delay,
                               reordering):
        if device_option is None:
            pytest.skip("device option is null")

        tc_obj = TrafficControl(
            device=device_option,
            netem_param=NetemParameter(
                device=device_option,
                latency_time=delay,
                latency_distro_time=Tc.ValueRange.LatencyTime.MIN,
                reordering_rate=reordering,
            ),
            direction=direction,
            shaping_algorithm=ShapingAlgorithm.HTB,
        )

        tc_obj.validate()
コード例 #8
0
    def test_normal(self, device_value):
        if device_value is None:
            pytest.skip("device option is null")

        delete_all_rules(device_value)

        tc = TrafficControl(
            device=device_value,
            shaping_algorithm="htb",
            direction=TrafficDirection.INCOMING,
            netem_param=NetemParameter(
                device=device_value,
                bandwidth_rate="200kbps",
                packet_loss_rate=0,
                packet_duplicate_rate=0,
                corruption_rate=0,
                reordering_rate=0,
            ),
            src_network="192.168.3.188",
            dst_port=5201,
        )
        assert tc.set_shaping_rule() == 0

        tc = TrafficControl(
            device=device_value,
            shaping_algorithm="htb",
            direction=TrafficDirection.OUTGOING,
            netem_param=NetemParameter(
                device=device_value,
                bandwidth_rate="1000000kbps",
                packet_loss_rate=0,
                packet_duplicate_rate=0,
                corruption_rate=0,
                reordering_rate=0,
            ),
            dst_network="192.168.3.188",
        )
        assert tc.set_shaping_rule() == 0

        result = tcconfig.parser.shaping_rule.TcShapingRuleParser(
            device=device_value,
            ip_version=4,
            logger=NullLogger(),
            tc_command_output=None,
            is_parse_filter_id=False,
        ).get_tc_parameter()
        expected = json.loads(
            """\
            {
                "enp0s3": {
                    "outgoing": {
                        "dst-network=192.168.3.188/32, protocol=ip": {
                            "rate": "1Gbps"
                        }
                    },
                    "incoming": {
                        "src-network=192.168.3.188/32, dst-port=5201, protocol=ip": {
                            "rate": "200Kbps"
                        }
                    }
                }
            }
            """
        )

        print_test_result(expected=expected, actual=result)
        assert result == expected