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()
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()
def test_TrafficControl_validate_bandwidth_rate_normal(value): tc_obj = TrafficControl( "dummy", bandwidth_rate=value, direction=TrafficDirection.OUTGOING, shaping_algorithm=ShapingAlgorithm.HTB, ) tc_obj.validate_bandwidth_rate()
def test_TrafficControl_validate_bandwidth_rate_exception_2(value, expected): with pytest.raises(expected): tc_obj = TrafficControl( "dummy", bandwidth_rate=value, latency_time=Tc.ValueRange.LatencyTime.MIN, latency_distro_time=Tc.ValueRange.LatencyTime.MIN, shaping_algorithm=ShapingAlgorithm.HTB) tc_obj.validate_bandwidth_rate()
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()
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()
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
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()
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()
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, dst_network=network, is_ipv6=is_ipv6) assert tc_obj.ip_version == expected_ip_ver assert tc_obj.protocol == expected_protocol assert tc_obj.protocol_match == expected_protocol_match
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()
def test_TrafficControl_validate_bandwidth_rate_exception_1(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, ), direction=TrafficDirection.OUTGOING, shaping_algorithm=ShapingAlgorithm.HTB, ) tc_obj.netem_param.validate_bandwidth_rate()
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()
def test_TrafficControl_validate_bandwidth_rate_exception_1(value, expected): with pytest.raises(expected): tc_obj = TrafficControl( "dummy", bandwidth_rate=value, direction=TrafficDirection.OUTGOING) tc_obj.validate_bandwidth_rate()
def test_TrafficControl_validate_bandwidth_rate_exception_2(value, expected): #tc_obj.bandwidth_rate = value tc_obj = TrafficControl("dummy", bandwidth_rate=value) with pytest.raises(expected): tc_obj._TrafficControl__validate_bandwidth_rate()
def test_TrafficControl_validate_bandwidth_rate_normal(value): tc_obj = TrafficControl("dummy", bandwidth_rate=value) tc_obj._TrafficControl__validate_bandwidth_rate()
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
def test_TrafficControl_validate_bandwidth_rate_normal(value): tc_obj = TrafficControl( "dummy", bandwidth_rate=value, direction=TrafficDirection.OUTGOING) tc_obj.validate_bandwidth_rate()
def test_TrafficControl_validate_bandwidth_rate_exception_2(value, expected): tc_obj = TrafficControl("dummy", bandwidth_rate=value) with pytest.raises(expected): tc_obj.validate_bandwidth_rate()
def test_TrafficControl_validate_bandwidth_rate_normal(value): tc_obj = TrafficControl("dummy", bandwidth_rate=value) tc_obj.validate_bandwidth_rate()