# under the License.
from datetime import datetime
+import re
import socket
import struct
import time
def poll_stats(self):
if not self.is_running():
return None
+ if self.client.skip_sleep:
+ self.stop()
+ return self.client.get_stats()
time_elapsed = self.time_elapsed()
if time_elapsed > self.duration_sec:
self.stop()
'''Reserve a range of count consecutive IP addresses spaced by step
'''
if self.next_free + count > self.max_available:
- raise IndexError('No more IP addresses next free=%d max_available=%d requested=%d',
- self.next_free,
- self.max_available,
- count)
+ raise IndexError('No more IP addresses next free=%d max_available=%d requested=%d' %
+ (self.next_free,
+ self.max_available,
+ count))
first_ip = self.get_ip(self.next_free)
last_ip = self.get_ip(self.next_free + count - 1)
self.next_free += count
def __init__(self, port, pci, switch_port=None, vtep_vlan=None, ip=None, tg_gateway_ip=None,
gateway_ip=None, ip_addrs_step=None, tg_gateway_ip_addrs_step=None,
gateway_ip_addrs_step=None, udp_src_port=None, udp_dst_port=None,
- chain_count=1, flow_count=1, vlan_tagging=False):
+ dst_mac=None, chain_count=1, flow_count=1, vlan_tagging=False):
self.chain_count = chain_count
self.flow_count = flow_count
self.dst = None
self.vlan_tagging = vlan_tagging
self.pci = pci
self.mac = None
+ self.dst_mac = dst_mac
self.vm_mac_list = None
subnet = IPNetwork(ip)
self.ip = subnet.ip.format()
for chain_idx in xrange(self.chain_count):
src_ip_first, src_ip_last = self.ip_block.reserve_ip_range(cur_chain_flow_count)
dst_ip_first, dst_ip_last = self.dst.ip_block.reserve_ip_range(cur_chain_flow_count)
+
+ dst_mac = self.dst_mac[chain_idx] if self.dst_mac is not None else self.dst.mac
+ if not re.match("[0-9a-f]{2}([-:])[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$", dst_mac.lower()):
+ raise TrafficClientException("Invalid MAC address '{mac}' specified in "
+ "mac_addrs_left/right".format(mac=dst_mac))
+
configs.append({
'count': cur_chain_flow_count,
'mac_src': self.mac,
- 'mac_dst': self.dst.mac if service_chain == ChainType.EXT else self.vm_mac_list[
+ 'mac_dst': dst_mac if service_chain == ChainType.EXT else self.vm_mac_list[
chain_idx],
'ip_src_addr': src_ip_first,
'ip_src_addr_max': src_ip_last,
self.src_device = None
self.dst_device = None
self.vm_mac_list = None
+ self.mac_addrs_left = generator_config.mac_addrs_left
+ self.mac_addrs_right = generator_config.mac_addrs_right
self.__prep_interfaces(generator_config)
def to_json(self):
'tg_gateway_ip_addrs_step': self.tg_gateway_ip_addrs_step,
'udp_src_port': generator_config.udp_src_port,
'udp_dst_port': generator_config.udp_dst_port,
- 'vlan_tagging': self.vlan_tagging
+ 'vlan_tagging': self.vlan_tagging,
+ 'dst_mac': generator_config.mac_addrs_left
}
dst_config = {
'chain_count': self.service_chain_count,
'tg_gateway_ip_addrs_step': self.tg_gateway_ip_addrs_step,
'udp_src_port': generator_config.udp_src_port,
'udp_dst_port': generator_config.udp_dst_port,
- 'vlan_tagging': self.vlan_tagging
+ 'vlan_tagging': self.vlan_tagging,
+ 'dst_mac': generator_config.mac_addrs_right
}
self.src_device = Device(**dict(src_config, **generator_config.interfaces[0]))
class TrafficClient(object):
PORTS = [0, 1]
- def __init__(self, config, notifier=None):
+ def __init__(self, config, notifier=None, skip_sleep=False):
generator_factory = TrafficGeneratorFactory(config)
self.gen = generator_factory.get_generator_client()
self.tool = generator_factory.get_tool()
self.current_total_rate = {'rate_percent': '10'}
if self.config.single_run:
self.current_total_rate = utils.parse_rate_str(self.config.rate)
+ # UT with dummy TG can bypass all sleeps
+ self.skip_sleep = skip_sleep
def set_macs(self):
for mac, device in zip(self.gen.get_macs(), self.config.generator_config.devices):
self.gen.clear_stats()
self.gen.start_traffic()
LOG.info('Waiting for packets to be received back... (%d / %d)', it + 1, retry_count)
- time.sleep(self.config.generic_poll_sec)
+ if not self.skip_sleep:
+ time.sleep(self.config.generic_poll_sec)
self.gen.stop_traffic()
stats = self.gen.get_stats()
LOG.info('End-to-end connectivity ensured')
return
- time.sleep(self.config.generic_poll_sec)
+ if not self.skip_sleep:
+ time.sleep(self.config.generic_poll_sec)
raise TrafficClientException('End-to-end connectivity cannot be ensured')