예제 #1
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()
예제 #2
0
    def test_normal(
            self, device_option, rate, direction, delay, delay_distro, loss, corrupt,
            network, port):
        if device_option is None:
            pytest.skip("device option is null")

        tc_obj = TrafficControl(
            device=device_option,
            direction=direction,
            bandwidth_rate=rate,
            latency_ms=delay,
            latency_distro_ms=delay_distro,
            packet_loss_rate=loss,
            corruption_rate=corrupt,
            network=network,
            port=port,
            src_network=None,
            is_enable_iptables=True,
        )

        params = [
            rate,
            delay,
            loss,
            corrupt,
        ]
        is_invalid = all([
            not FloatType(param).is_type() or param == 0 for param in params
        ])

        if is_invalid:
            with pytest.raises(ValueError):
                tc_obj.validate()
        else:
            tc_obj.validate()
예제 #3
0
    def test_normal(
            self, device_option, rate, direction, delay, delay_distro,
            loss, duplicate, corrupt, network, src_port, dst_port):
        if device_option is None:
            pytest.skip("device option is null")

        tc_obj = TrafficControl(
            device=device_option,
            direction=direction,
            bandwidth_rate=rate,
            latency_ms=delay,
            latency_distro_ms=delay_distro,
            packet_loss_rate=loss,
            packet_duplicate_rate=duplicate,
            corruption_rate=corrupt,
            dst_network=network,
            src_port=src_port,
            dst_port=dst_port,
            src_network=None,
            is_enable_iptables=True,
        )

        if is_invalid_param(
                rate, delay, loss, duplicate, corrupt, reordering=None):
            with pytest.raises(ValueError):
                tc_obj.validate()
        else:
            tc_obj.validate()
예제 #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_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,
            direction=direction,
            latency_ms=delay,
            reordering_rate=reordering,
        )

        tc_obj.validate()
예제 #6
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,
            direction=direction,
            latency_time=delay,
            latency_distro_time=Tc.ValueRange.LatencyTime.MIN,
            reordering_rate=reordering,
            shaping_algorithm=ShapingAlgorithm.HTB,
        )

        tc_obj.validate()
예제 #7
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,
            bandwidth_rate=value.get("bandwidth_rate"),
            latency_ms=value.get("latency_ms"),
            latency_distro_ms=value.get("latency_distro_ms"),
            packet_loss_rate=value.get("packet_loss_rate"),
            corruption_rate=value.get("curruption_rate"),
            network=value.get("network"),
            port=value.get("port"),
        )

        with pytest.raises(expected):
            tc_obj.validate()
예제 #8
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,
            bandwidth_rate=value.get("bandwidth_rate"),
            latency_ms=value.get("latency_ms"),
            latency_distro_ms=value.get("latency_distro_ms"),
            packet_loss_rate=value.get("packet_loss_rate"),
            corruption_rate=value.get("corruption_rate"),
            network=value.get("network"),
            port=value.get("port"),
        )

        with pytest.raises(expected):
            tc_obj.validate()