X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fnetwork_services%2Ftraffic_profile%2Ftraffic_profile.py;h=2f97945c0dba3389608d2186f8474916afb58c23;hb=6c5052211e1e3f82d55946d2df090ad787382494;hp=4c6595d94a2b19daa21ae772113ef1e58ab5b1cd;hpb=109423bc807b794dd9fe8b17d9c1fa37f471afcc;p=yardstick.git diff --git a/yardstick/network_services/traffic_profile/traffic_profile.py b/yardstick/network_services/traffic_profile/traffic_profile.py index 4c6595d94..2f97945c0 100644 --- a/yardstick/network_services/traffic_profile/traffic_profile.py +++ b/yardstick/network_services/traffic_profile/traffic_profile.py @@ -19,6 +19,7 @@ import socket import logging from random import SystemRandom import six +import ipaddress from yardstick.network_services.traffic_profile.base import TrafficProfile from trex_stl_lib.trex_stl_client import STLStream @@ -44,6 +45,8 @@ SRC_PORT = 'sport' DST_PORT = 'dport' TYPE_OF_SERVICE = 'tos' +LOG = logging.getLogger(__name__) + class TrexProfile(TrafficProfile): """ This class handles Trex Traffic profile generation and execution """ @@ -66,7 +69,7 @@ class TrexProfile(TrafficProfile): return f def _ethernet_range_action_partial(self, direction, _): - def partial(min_value, max_value): + def partial(min_value, max_value, count): stl_vm_flow_var = STLVmFlowVar(name="mac_{}".format(direction), min_value=1, max_value=30, @@ -80,7 +83,15 @@ class TrexProfile(TrafficProfile): return partial def _ip_range_action_partial(self, direction, count=1): - def partial(min_value, max_value): + def partial(min_value, max_value, count): + ip1 = int(ipaddress.IPv4Address(min_value)) + ip2 = int(ipaddress.IPv4Address(max_value)) + actual_count = (ip2 - ip1) + if not actual_count: + count = 1 + elif actual_count < int(count): + count = actual_count + stl_vm_flow_var = STLVmFlowVarRepeatableRandom(name="ip4_{}".format(direction), min_value=min_value, max_value=max_value, @@ -96,7 +107,7 @@ class TrexProfile(TrafficProfile): return partial def _ip6_range_action_partial(self, direction, _): - def partial(min_value, max_value): + def partial(min_value, max_value, count): min_value, max_value = self._get_start_end_ipv6(min_value, max_value) stl_vm_flow_var = STLVmFlowVar(name="ip6_{}".format(direction), min_value=min_value, @@ -112,7 +123,7 @@ class TrexProfile(TrafficProfile): return partial def _dscp_range_action_partial(self, *_): - def partial(min_value, max_value): + def partial(min_value, max_value, count): stl_vm_flow_var = STLVmFlowVar(name="dscp", min_value=min_value, max_value=max_value, @@ -125,7 +136,13 @@ class TrexProfile(TrafficProfile): self.vm_flow_vars.append(stl_vm_wr_flow_var) def _udp_range_action_partial(self, field, count=1): - def partial(min_value, max_value): + def partial(min_value, max_value, count): + actual_count = int(max_value) - int(min_value) + if not actual_count: + count = 1 + elif int(count) > actual_count: + count = actual_count + stl_vm_flow_var = STLVmFlowVarRepeatableRandom(name="port_{}".format(field), min_value=min_value, max_value=max_value, @@ -134,7 +151,7 @@ class TrexProfile(TrafficProfile): seed=0x1235) self.vm_flow_vars.append(stl_vm_flow_var) stl_vm_wr_flow_var = STLVmWrFlowVar(fv_name='port_{}'.format(field), - pkt_offset=self.udp_sport) + pkt_offset=self.udp[field]) self.vm_flow_vars.append(stl_vm_wr_flow_var) return partial @@ -156,8 +173,10 @@ class TrexProfile(TrafficProfile): self.ip_packet = None self.ip6_packet = None self.udp_packet = None - self.udp_dport = '' - self.udp_sport = '' + self.udp = { + SRC_PORT: '', + DST_PORT: '', + } self.qinq_packet = None self.qinq = False self.vm_flow_vars = [] @@ -188,9 +207,9 @@ class TrexProfile(TrafficProfile): ), } - def execute(self, traffic_generator): + def execute_traffic(self, traffic_generator): """ Generate the stream and run traffic on the given ports """ - pass + raise NotImplementedError() def _call_on_range(self, range, single_action, range_action, count=1, to_int=False): def convert_to_int(val): @@ -203,13 +222,14 @@ class TrexProfile(TrafficProfile): except StopIteration: single_action(min_value) else: - range_action(min_value=min_value, max_value=max_value) + range_action(min_value=min_value, max_value=max_value, count=count) def _set_proto_addr(self, protocol, field, address, count=1): single_action, range_action, to_int = self._map_proto_actions[protocol] self._call_on_range(address, single_action(field), range_action(field, count), + count=count, to_int=to_int, ) @@ -266,8 +286,8 @@ class TrexProfile(TrafficProfile): ip_params['proto'] = socket.getprotobyname(outer_l3v4['proto']) if outer_l3v4['proto'] == 'tcp': self.udp_packet = Pkt.TCP() - self.udp_dport = 'TCP.dport' - self.udp_sport = 'TCP.sport' + self.udp[DST_PORT] = 'TCP.dport' + self.udp[SRC_PORT] = 'TCP.sport' tcp_params = {'flags': '', 'window': 0} self._set_proto_fields(UDP, **tcp_params) if 'ttl' in outer_l3v4: @@ -289,8 +309,8 @@ class TrexProfile(TrafficProfile): ip6_params['proto'] = outer_l3v6['proto'] if outer_l3v6['proto'] == 'tcp': self.udp_packet = Pkt.TCP() - self.udp_dport = 'TCP.dport' - self.udp_sport = 'TCP.sport' + self.udp[DST_PORT] = 'TCP.dport' + self.udp[SRC_PORT] = 'TCP.sport' tcp_params = {'flags': '', 'window': 0} self._set_proto_fields(UDP, **tcp_params) if 'ttl' in outer_l3v6: @@ -364,8 +384,8 @@ class TrexProfile(TrafficProfile): self.ip_packet = Pkt.IP() self.ip6_packet = None self.udp_packet = Pkt.UDP() - self.udp_dport = 'UDP.dport' - self.udp_sport = 'UDP.sport' + self.udp[DST_PORT] = 'UDP.dport' + self.udp[SRC_PORT] = 'UDP.sport' self.qinq = False self.vm_flow_vars = [] outer_l2 = packet_definition.get('outer_l2', None)