# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
+"""Driver module for TRex traffic generator."""
import os
import random
from itertools import count
from nfvbench.log import LOG
-from nfvbench.specs import ChainType
from nfvbench.traffic_server import TRexTrafficServer
from nfvbench.utils import cast_integer
from nfvbench.utils import timeout
LATENCY_PG_ID_MASK = 0x0100
def __init__(self, traffic_client):
+ """Trex driver."""
AbstractTrafficGenerator.__init__(self, traffic_client)
self.client = None
self.id = count()
If there are latency streams, those same counters need to be added in the same way
"""
+ def get_latency(lval):
+ try:
+ return int(round(lval))
+ except ValueError:
+ return 0
+
for ifs in if_stats:
ifs.tx = ifs.rx = 0
for port in range(2):
try:
lat = trex_stats['latency'][lat_pg_id]['latency']
# dropped_pkts += lat['err_cntrs']['dropped']
- latencies[port].max_usec = int(round(lat['total_max']))
- latencies[port].min_usec = int(round(lat['total_min']))
- latencies[port].avg_usec = int(round(lat['average']))
+ latencies[port].max_usec = get_latency(lat['total_max'])
+ latencies[port].min_usec = get_latency(lat['total_min'])
+ latencies[port].avg_usec = get_latency(lat['average'])
except KeyError:
pass
(self.port_info[0]['speed'],
self.port_info[1]['speed']))
- def set_mode(self):
- if self.config.service_chain == ChainType.EXT and not self.config.no_arp:
- self.__set_l3_mode()
- else:
- self.__set_l2_mode()
-
- def __set_l3_mode(self):
- self.client.set_service_mode(ports=self.port_handle, enabled=True)
- for port, device in zip(self.port_handle, self.generator_config.devices):
- try:
- self.client.set_l3_mode(port=port,
- src_ipv4=device.tg_gateway_ip,
- dst_ipv4=device.dst.gateway_ip,
- vlan=device.vlan_tag if device.vlan_tagging else None)
- except STLError:
- # TRex tries to resolve ARP already, doesn't have to be successful yet
- continue
- self.client.set_service_mode(ports=self.port_handle, enabled=False)
-
- def __set_l2_mode(self):
- self.client.set_service_mode(ports=self.port_handle, enabled=True)
- for port, device in zip(self.port_handle, self.generator_config.devices):
- for cfg in device.get_stream_configs():
- self.client.set_l2_mode(port=port, dst_mac=cfg['mac_dst'])
- self.client.set_service_mode(ports=self.port_handle, enabled=False)
-
def __start_server(self):
server = TRexTrafficServer()
server.run_server(self.generator_config)
"""
self.client.set_service_mode(ports=self.port_handle)
LOG.info('Polling ARP until successful...')
- arps = {}
+ arp_dest_macs = {}
for port, device in zip(self.port_handle, self.generator_config.devices):
# there should be 1 stream config per chain
stream_configs = device.get_stream_configs()
STLServiceARP(ctx,
src_ip=cfg['ip_src_tg_gw'],
dst_ip=cfg['mac_discovery_gw'],
- vlan=device.vlan_tag if device.vlan_tagging else None)
- for cfg in stream_configs()
+ # will be None if no vlan tagging
+ vlan=cfg['vlan_tag'])
+ for cfg in stream_configs
]
for attempt in range(self.config.generic_retry_count):
for chain_id, mac in enumerate(dst_macs):
if not mac:
arp_record = arps[chain_id].get_record()
- if arp_record.dest_mac:
+ if arp_record.dst_mac:
dst_macs[chain_id] = arp_record.dst_mac
dst_macs_count += 1
- LOG.info(' ARP: port=%d chain=%d IP=%s -> MAC=%s',
+ LOG.info(' ARP: port=%d chain=%d src IP=%s dst IP=%s -> MAC=%s',
port, chain_id,
+ arp_record.src_ip,
arp_record.dst_ip, arp_record.dst_mac)
else:
unresolved.append(arp_record.dst_ip)
if dst_macs_count == chain_count:
- arps[port] = dst_macs
+ arp_dest_macs[port] = dst_macs
LOG.info('ARP resolved successfully for port %s', port)
break
else:
break
self.client.set_service_mode(ports=self.port_handle, enabled=False)
- if len(arps) == len(self.port_handle):
- return arps
+ if len(arp_dest_macs) == len(self.port_handle):
+ return arp_dest_macs
return None
def __is_rate_enough(self, l2frame_size, rates, bidirectional, latency):