- def __init__(self, yaml_data):
- super(TrexProfile, self).__init__(yaml_data)
- self.flows = 100
- self.pps = 100
- self.pg_id = 0
- self.first_run = True
- self.streams = 1
- self.profile_data = []
- self.profile = None
- self.base_pkt = None
- self.fsize = None
- self.trex_vm = None
- self.vms = []
- self.rate = None
- self.ip_packet = None
- self.ip6_packet = None
- self.udp_packet = None
- self.udp_dport = ''
- self.udp_sport = ''
- self.qinq_packet = None
- self.qinq = False
- self.vm_flow_vars = []
- self.packets = []
- self.ether_packet = []
-
- def execute(self, traffic_generator):
- """ Generate the stream and run traffic on the given ports """
- pass
-
- def _set_ether_fields(self, **kwargs):
- """ set ethernet protocol fields """
- if not self.ether_packet:
- self.ether_packet = Pkt.Ether()
- for key, value in six.iteritems(kwargs):
- setattr(self.ether_packet, key, value)
-
- def _set_ip_fields(self, **kwargs):
- """ set l3 ipv4 protocol fields """
-
- if not self.ip_packet:
- self.ip_packet = Pkt.IP()
- for key in kwargs:
- setattr(self.ip_packet, key, kwargs[key])
-
- def _set_ip6_fields(self, **kwargs):
- """ set l3 ipv6 protocol fields """
- if not self.ip6_packet:
- self.ip6_packet = Pkt.IPv6()
- for key in kwargs:
- setattr(self.ip6_packet, key, kwargs[key])
-
- def _set_udp_fields(self, **kwargs):
- """ set l4 udp ports fields """
- if not self.udp_packet:
- self.udp_packet = Pkt.UDP()
- for key in kwargs:
- setattr(self.udp_packet, key, kwargs[key])
-
- def set_src_mac(self, src_mac):
- """ set source mac address fields """
- src_macs = src_mac.split('-')
- min_value = src_macs[0]
- if len(src_macs) == 1:
- src_mac = min_value
- self._set_ether_fields(src=src_mac)
- else:
- stl_vm_flow_var = STLVmFlowVar(name="mac_src",
- min_value=1,
- max_value=30,
- size=4,
- op='inc',
- step=1)
- self.vm_flow_vars.append(stl_vm_flow_var)
- stl_vm_wr_flow_var = STLVmWrFlowVar(fv_name='mac_src',
- pkt_offset='Ether.src')
- self.vm_flow_vars.append(stl_vm_wr_flow_var)
-
- def set_dst_mac(self, dst_mac):
- """ set destination mac address fields """
- dst_macs = dst_mac.split('-')
- min_value = dst_macs[0]
- if len(dst_macs) == 1:
- dst_mac = min_value
- self._set_ether_fields(dst=dst_mac)
- else:
- stl_vm_flow_var = STLVmFlowVar(name="mac_dst",
+ PROTO_MAP = {
+ ETHERNET: ('ether_packet', Pkt.Ether),
+ IP: ('ip_packet', Pkt.IP),
+ IPv6: ('ip6_packet', Pkt.IPv6),
+ UDP: ('udp_packet', Pkt.UDP),
+ }
+
+ def _general_single_action_partial(self, protocol):
+ def f(field):
+ def partial(value):
+ kwargs = {
+ field: value
+ }
+ self._set_proto_fields(protocol, **kwargs)
+ return partial
+ return f
+
+ def _ethernet_range_action_partial(self, direction, _):
+ def partial(min_value, max_value, count):
+ stl_vm_flow_var = STLVmFlowVar(name="mac_{}".format(direction),