import traceback
from itertools import count
+# pylint: disable=import-error
+from scapy.contrib.mpls import MPLS # flake8: noqa
+# pylint: enable=import-error
from nfvbench.log import LOG
from nfvbench.traffic_server import TRexTrafficServer
from nfvbench.utils import cast_integer
op="random")
vm_param = [vxlan_udp_src_fv,
STLVmWrFlowVar(fv_name="vxlan_udp_src", pkt_offset="UDP.sport")]
+ elif stream_cfg['mpls'] is True:
+ encap_level = '0'
+ pkt_base = Ether(src=stream_cfg['vtep_src_mac'], dst=stream_cfg['vtep_dst_mac'])
+ if stream_cfg['vtep_vlan'] is not None:
+ pkt_base /= Dot1Q(vlan=stream_cfg['vtep_vlan'])
+ if stream_cfg['mpls_outer_label'] is not None:
+ pkt_base /= MPLS(label=stream_cfg['mpls_outer_label'], cos=1, s=0, ttl=255)
+ if stream_cfg['mpls_inner_label'] is not None:
+ pkt_base /= MPLS(label=stream_cfg['mpls_inner_label'], cos=1, s=1, ttl=255)
+ # Flow stats and MPLS labels randomization TBD
+ pkt_base /= Ether(src=stream_cfg['mac_src'], dst=stream_cfg['mac_dst'])
else:
encap_level = '0'
pkt_base = Ether(src=stream_cfg['mac_src'], dst=stream_cfg['mac_dst'])
udp_args = {}
if stream_cfg['udp_src_port']:
udp_args['sport'] = int(stream_cfg['udp_src_port'])
+ udp_args['sport_step'] = int(stream_cfg['udp_port_step'])
+ udp_args['sport_max'] = int(stream_cfg['udp_src_port_max'])
if stream_cfg['udp_dst_port']:
udp_args['dport'] = int(stream_cfg['udp_dst_port'])
- pkt_base /= IP() / UDP(**udp_args)
+ udp_args['dport_step'] = int(stream_cfg['udp_port_step'])
+ udp_args['dport_max'] = int(stream_cfg['udp_dst_port_max'])
+ pkt_base /= IP(src=stream_cfg['ip_src_addr'], dst=stream_cfg['ip_dst_addr']) / \
+ UDP(dport=udp_args['dport'], sport=udp_args['sport'])
+ if stream_cfg['ip_src_static'] is True:
+ src_max_ip_value = stream_cfg['ip_src_addr']
+ else:
+ src_max_ip_value = stream_cfg['ip_src_addr_max']
if stream_cfg['ip_addrs_step'] == 'random':
- src_fv = STLVmFlowVarRepeatableRandom(
+ src_fv_ip = STLVmFlowVarRepeatableRandom(
name="ip_src",
min_value=stream_cfg['ip_src_addr'],
- max_value=stream_cfg['ip_src_addr_max'],
+ max_value=src_max_ip_value,
size=4,
seed=random.randint(0, 32767),
limit=stream_cfg['ip_src_count'])
- dst_fv = STLVmFlowVarRepeatableRandom(
+ dst_fv_ip = STLVmFlowVarRepeatableRandom(
name="ip_dst",
min_value=stream_cfg['ip_dst_addr'],
max_value=stream_cfg['ip_dst_addr_max'],
seed=random.randint(0, 32767),
limit=stream_cfg['ip_dst_count'])
else:
- src_fv = STLVmFlowVar(
+ src_fv_ip = STLVmFlowVar(
name="ip_src",
min_value=stream_cfg['ip_src_addr'],
- max_value=stream_cfg['ip_src_addr'],
+ max_value=src_max_ip_value,
size=4,
op="inc",
step=stream_cfg['ip_addrs_step'])
- dst_fv = STLVmFlowVar(
+ dst_fv_ip = STLVmFlowVar(
name="ip_dst",
min_value=stream_cfg['ip_dst_addr'],
max_value=stream_cfg['ip_dst_addr_max'],
op="inc",
step=stream_cfg['ip_addrs_step'])
- vm_param.extend([
- src_fv,
+ if stream_cfg['udp_port_step'] == 'random':
+ src_fv_port = STLVmFlowVarRepeatableRandom(
+ name="p_src",
+ min_value=udp_args['sport'],
+ max_value=udp_args['sport_max'],
+ size=2,
+ seed=random.randint(0, 32767),
+ limit=udp_args['udp_src_count'])
+ dst_fv_port = STLVmFlowVarRepeatableRandom(
+ name="p_dst",
+ min_value=udp_args['dport'],
+ max_value=udp_args['dport_max'],
+ size=2,
+ seed=random.randint(0, 32767),
+ limit=stream_cfg['udp_dst_count'])
+ else:
+ src_fv_port = STLVmFlowVar(
+ name="p_src",
+ min_value=udp_args['sport'],
+ max_value=udp_args['sport_max'],
+ size=2,
+ op="inc",
+ step=udp_args['sport_step'])
+ dst_fv_port = STLVmFlowVar(
+ name="p_dst",
+ min_value=udp_args['dport'],
+ max_value=udp_args['dport_max'],
+ size=2,
+ op="inc",
+ step=udp_args['dport_step'])
+ vm_param = [
+ src_fv_ip,
STLVmWrFlowVar(fv_name="ip_src", pkt_offset="IP:{}.src".format(encap_level)),
- dst_fv,
- STLVmWrFlowVar(fv_name="ip_dst", pkt_offset="IP:{}.dst".format(encap_level))
- ])
-
- for encap in range(int(encap_level), -1, -1):
- # Fixing the checksums for all encap levels
- vm_param.append(STLVmFixChecksumHw(l3_offset="IP:{}".format(encap),
- l4_offset="UDP:{}".format(encap),
- l4_type=CTRexVmInsFixHwCs.L4_TYPE_UDP))
+ src_fv_port,
+ STLVmWrFlowVar(fv_name="p_src", pkt_offset="UDP:{}.sport".format(encap_level)),
+ dst_fv_ip,
+ STLVmWrFlowVar(fv_name="ip_dst", pkt_offset="IP:{}.dst".format(encap_level)),
+ dst_fv_port,
+ STLVmWrFlowVar(fv_name="p_dst", pkt_offset="UDP:{}.dport".format(encap_level)),
+ STLVmFixChecksumHw(l3_offset="IP:{}".format(encap_level),
+ l4_offset="UDP:{}".format(encap_level),
+ l4_type=CTRexVmInsFixHwCs.L4_TYPE_UDP)
+ ]
pad = max(0, frame_size - len(pkt_base)) * 'x'
return STLPktBuilder(pkt=pkt_base / pad,
if l2frame == 'IMIX':
for ratio, l2_frame_size in zip(IMIX_RATIOS, IMIX_L2_SIZES):
pkt = self._create_pkt(stream_cfg, l2_frame_size)
- if e2e:
+ if e2e or stream_cfg['mpls']:
streams.append(STLStream(packet=pkt,
mode=STLTXCont(pps=ratio)))
else:
else:
l2frame_size = int(l2frame)
pkt = self._create_pkt(stream_cfg, l2frame_size)
- if e2e:
+ if e2e or stream_cfg['mpls']:
streams.append(STLStream(packet=pkt,
+ # Flow stats is disabled for MPLS now
+ # flow_stats=STLFlowStats(pg_id=pg_id),
mode=STLTXCont()))
else:
if stream_cfg['vxlan'] is True:
dst_macs = [None] * chain_count
dst_macs_count = 0
# the index in the list is the chain id
- if self.config.vxlan:
+ if self.config.vxlan or self.config.mpls:
arps = [
ServiceARP(ctx,
src_ip=device.vtep_src_ip,
bpf_filter = "ether dst %s or ether dst %s" % (src_mac_list[0], src_mac_list[1])
# ports must be set in service in order to enable capture
self.client.set_service_mode(ports=self.port_handle)
- self.capture_id = self.client.start_capture(rx_ports=self.port_handle,
- bpf_filter=bpf_filter)
+ self.capture_id = self.client.start_capture \
+ (rx_ports=self.port_handle, bpf_filter=bpf_filter)
def fetch_capture_packets(self):
"""Fetch capture packets in capture mode."""