예제 #1
0
    def __validate_netem_parameter(self):
        self.validate_bandwidth_rate()
        self.__validate_network_delay()
        self.__validate_packet_loss_rate()
        self.__validate_packet_duplicate_rate()
        self.__validate_corruption_rate()
        self.__validate_reordering_rate()
        self.__validate_reordering_and_delay()

        netem_param_value_list = [
            self.bandwidth_rate,
            self.packet_loss_rate,
            self.packet_duplicate_rate,
            self.corruption_rate,
            self.reordering_rate,
        ]

        if all([
                not RealNumber(netem_param_value).is_type()
                or netem_param_value <= 0
                for netem_param_value in netem_param_value_list
        ] + [
                self.latency_time <= HumanReadableTime(
                    Tc.ValueRange.LatencyTime.MIN)
        ]):
            raise InvalidParameterError(
                "there are no valid net emulation parameters found. "
                "at least one or more following parameters are required: "
                "--rate, --delay, --loss, --duplicate, --corrupt, --reordering"
            )
예제 #2
0
    def __validate_netem_parameter(self):
        try:
            self.validate_bandwidth_rate()
        except EmptyParameterError:
            pass

        self.__validate_network_delay()
        self.__validate_packet_loss_rate()
        self.__validate_packet_duplicate_rate()
        self.__validate_corruption_rate()
        self.__validate_reordering_rate()
        self.__validate_reordering_and_delay()

        netem_param_value_list = [
            self.bandwidth_rate,
            self.latency_ms,
            self.packet_loss_rate,
            self.packet_duplicate_rate,
            self.corruption_rate,
            self.reordering_rate
        ]

        if all([not RealNumber(
                netem_param_value).is_type() or netem_param_value == 0 for
                netem_param_value in netem_param_value_list]):
            raise ValueError(
                "there is no valid net emulation parameter value."
                "at least one or more following parameters are required: "
                "--rate, --delay, --loss, --corrupt"
            )
예제 #3
0
def is_invalid_param(rate, delay, packet_loss, packet_duplicate, corrupt,
                     reordering):
    param_value_list = [
        delay,
        packet_loss,
        packet_duplicate,
        corrupt,
        reordering,
    ]

    print(param_value_list)

    is_invalid = all([
        not RealNumber(param_value).is_type() or param_value <= 0
        for param_value in param_value_list
    ])

    try:
        Humanreadable(rate, kilo_size=1000).to_bit()
    except (TypeError, ValueError):
        pass
    else:
        is_invalid = False

    return is_invalid
예제 #4
0
    def validate_bandwidth_rate(self):
        if not RealNumber(self.bandwidth_rate).is_type():
            raise EmptyParameterError("bandwidth_rate is empty")

        if self.bandwidth_rate <= 0:
            raise InvalidParameterError(
                "rate must be greater than zero: actual={}".format(
                    self.bandwidth_rate))
예제 #5
0
    def __get_additional_format_len(self):
        if not RealNumber(self.data).is_type():
            return 0

        format_len = 0

        if float(self.data) < 0:
            # for minus character
            format_len += 1

        return format_len
예제 #6
0
    def test_normal_send_parse(self, transmitter, ping_parser, host, count):
        transmitter.destination_host = host
        transmitter.count = count
        result = transmitter.ping()

        ping_parser.parse(result.stdout)

        assert ping_parser.packet_transmit >= count
        assert RealNumber(ping_parser.packet_receive).is_type()
        assert RealNumber(ping_parser.packet_loss_rate).is_type()
        assert RealNumber(ping_parser.packet_loss_count).is_type()
        assert RealNumber(ping_parser.packet_duplicate_rate).is_type()
        assert RealNumber(ping_parser.packet_duplicate_count).is_type()
        assert RealNumber(ping_parser.rtt_min).is_type()
        assert RealNumber(ping_parser.rtt_avg).is_type()
        assert RealNumber(ping_parser.rtt_max).is_type()
        assert RealNumber(ping_parser.rtt_mdev).is_type()
예제 #7
0
파일: common.py 프로젝트: rkd-msw/tcconfig
def is_invalid_param(rate, delay, loss, corrupt):
    params = [
        delay,
        loss,
        corrupt,
    ]

    is_invalid = all([
        not RealNumber(param).is_type() or param == 0 for param in params
    ])

    try:
        Humanreadable(rate, kilo_size=1000).to_no_prefix_value()
    except ValueError:
        pass
    else:
        is_invalid = False

    return is_invalid
예제 #8
0
    def validate_bandwidth_rate(self):
        if typepy.is_null_string(self.__bandwidth_rate):
            return

        # convert bandwidth string [K/M/G bit per second] to a number
        bandwidth_rate = Humanreadable(
            self.__bandwidth_rate, kilo_size=KILO_SIZE).to_kilo_bit()

        if not RealNumber(bandwidth_rate).is_type():
            raise InvalidParameterError(
                "bandwidth_rate must be a number", value=bandwidth_rate)

        if bandwidth_rate <= 0:
            raise InvalidParameterError(
                "bandwidth_rate must be greater than zero",
                value=bandwidth_rate)

        no_limit_kbits = get_no_limit_kbits(self.get_tc_device())
        if bandwidth_rate > no_limit_kbits:
            raise InvalidParameterError(
                "bandwidth_rate must be less than {}".format(no_limit_kbits),
                value=bandwidth_rate)
예제 #9
0
def get_integer_digit(value):
    from typepy import TypeConversionError
    from typepy.type import RealNumber

    float_type = RealNumber(value)

    try:
        abs_value = abs(float_type.convert())
    except TypeConversionError:
        raise ValueError(
            "the value must be a number: value='{}' type='{}'".format(
                value, type(value)))

    if abs_value.is_zero():
        return 1

    try:
        return len(
            str(abs_value.quantize(Decimal("1."),
                                   rounding=decimal.ROUND_DOWN)))
    except decimal.InvalidOperation as e:
        raise ValueError(e)
예제 #10
0
    def __validate_netem_parameter(self):
        try:
            self.validate_bandwidth_rate()
        except EmptyParameterError:
            pass

        self.__validate_network_delay()
        self.__validate_packet_loss_rate()
        self.__validate_corruption_rate()

        netem_param_value_list = [
            self.bandwidth_rate,
            self.latency_ms,
            self.packet_loss_rate,
            self.corruption_rate,
        ]

        if all([
                not RealNumber(netem_param_value).is_type()
                or netem_param_value == 0
                for netem_param_value in netem_param_value_list
        ]):
            raise ValueError("there is no valid net emulation parameter value")
예제 #11
0
    def update(self, value):
        store_value = RealNumber(value).try_convert()
        if store_value is None:
            return

        self.__value_list.append(store_value)