From 04967711fc58c3101c2449d09dbc9dcef95df21e Mon Sep 17 00:00:00 2001 From: henry54809 Date: Tue, 3 Aug 2021 19:54:24 -0700 Subject: [PATCH] gateway allocation cleanup (#900) --- config/system/all.conf | 2 +- config/system/alt.yaml | 3 ++- config/system/ata.yaml | 2 ++ config/system/base.yaml | 5 +++++ config/system/default.yaml | 5 ----- config/system/dts.yaml | 1 - config/system/muddy.conf | 2 +- config/system/multi.conf | 2 +- daq/runner.py | 46 +++++++++++++++++++++++++------------- daq/session_server.py | 2 +- daq/topology.py | 2 +- testing/test_dhcp.sh | 1 + testing/test_many.sh | 1 + testing/test_utils.sh | 1 + 14 files changed, 48 insertions(+), 27 deletions(-) diff --git a/config/system/all.conf b/config/system/all.conf index 2c7d74f440..07240a5f47 100644 --- a/config/system/all.conf +++ b/config/system/all.conf @@ -7,7 +7,7 @@ include=default.yaml site_description="Multi-Device All-Tests Configuration" # Upstream dataplane port from the external (secondary) switch. -# Not strictly necessary, but included for illustrative purposes. +switch_setup.of_dpid=2 switch_setup.uplink_port=4 # Switch interfaces diff --git a/config/system/alt.yaml b/config/system/alt.yaml index bbacfdfa34..08b79af351 100644 --- a/config/system/alt.yaml +++ b/config/system/alt.yaml @@ -11,10 +11,11 @@ switch_setup: data_intf: alt-intf alt_of_port: 6669 alt_varz_port: 9305 - uplink_port: 10 ext_br: alt-switch model: EXT_STACK native: True + of_dpid: 2 + uplink_port: 10 # Faux device connection for testing. interfaces: diff --git a/config/system/ata.yaml b/config/system/ata.yaml index 8b3cb5ba9e..8ddccd935e 100644 --- a/config/system/ata.yaml +++ b/config/system/ata.yaml @@ -11,6 +11,8 @@ switch_setup: model: EXT_STACK data_intf: alt-intf data_mac: '22:22:22:22:22:22' + of_dpid: 2 + uplink_port: 7 run_trigger: native_vlan: 122 diff --git a/config/system/base.yaml b/config/system/base.yaml index 9b4094dbef..092292d07f 100644 --- a/config/system/base.yaml +++ b/config/system/base.yaml @@ -10,6 +10,11 @@ include: default.yaml # Description for dashboard. site_description: "Baseline Configuration" +# Default switch configuration. +switch_setup: + of_dpid: 2 + uplink_port: 7 + # Faux interface devices interfaces: faux: diff --git a/config/system/default.yaml b/config/system/default.yaml index 0e7aef13d6..12ab132aa3 100644 --- a/config/system/default.yaml +++ b/config/system/default.yaml @@ -7,11 +7,6 @@ # Description for dashboard. site_description: "Default Configuration" -# Default switch configuration. -switch_setup: - of_dpid: 2 - uplink_port: 7 - # Default time to monitor before starting tests. monitor_scan_sec: 30 diff --git a/config/system/dts.yaml b/config/system/dts.yaml index 784811d5f4..c9c373222f 100644 --- a/config/system/dts.yaml +++ b/config/system/dts.yaml @@ -12,7 +12,6 @@ switch_setup: varz_port: 5678 model: EXT_STACK native: True - of_dpid: '0' run_trigger: vlan_start: 272 diff --git a/config/system/muddy.conf b/config/system/muddy.conf index 1669ec2889..1bf49d91f0 100644 --- a/config/system/muddy.conf +++ b/config/system/muddy.conf @@ -7,7 +7,7 @@ include=default.yaml site_description="Multi-Device Configuration" # Upstream dataplane port from the external (secondary) switch. -# Not strictly necessary, but included for illustrative purposes. +switch_setup.of_dpid=2 switch_setup.uplink_port=4 # Switch interfaces diff --git a/config/system/multi.conf b/config/system/multi.conf index 137c67ad0f..331f6e5d23 100644 --- a/config/system/multi.conf +++ b/config/system/multi.conf @@ -7,7 +7,7 @@ include=default.yaml site_description="Multi-Device Configuration" # Upstream dataplane port from the external (secondary) switch. -# Not strictly necessary, but included for illustrative purposes. +switch_setup.of_dpid=2 switch_setup.uplink_port=4 # Switch interfaces diff --git a/daq/runner.py b/daq/runner.py index bfe7214034..a283b3c939 100644 --- a/daq/runner.py +++ b/daq/runner.py @@ -148,7 +148,7 @@ class DAQRunner: faucet events, connected hosts (to test), and gcp for logging. This class owns the main event loop and shards out work to subclasses.""" - MAX_GATEWAYS = 9 + _DEFAULT_MAX_GATEWAYS = 9 _DEFAULT_RETENTION_DAYS = 30 _SITE_CONFIG = 'site_config.json' _RUNNER_CONFIG_PATH = 'runner/setup' @@ -157,8 +157,14 @@ class owns the main event loop and shards out work to subclasses.""" def __init__(self, config): self.configurator = configurator.Configurator() - self.gateway_sets = set(range(1, self.MAX_GATEWAYS+1)) self.config = config + switch_setup = self.config.get('switch_setup', {}) + max_devices = float(switch_setup.get('uplink_port', 'inf')) - 1 + self.gateway_sets = set(range(1, int(min(self._DEFAULT_MAX_GATEWAYS, max_devices) + 1))) + # TODO: uplink port should not be required for base topology + # Uplink port is used to configure device ports on the pri switch. + switch_setup['uplink_port'] = switch_setup.get('uplink_port', len(self.gateway_sets)) + self.config['switch_setup'] = switch_setup self._result_sets = {} self._devices = Devices() self._ports = {} @@ -588,9 +594,10 @@ def main_loop(self): self._terminate() - def _target_set_has_capacity(self): + def _target_set_has_capacity(self, device): num_triggered = len(self._devices.get_triggered_devices()) - return num_triggered < self._max_hosts + existing = self._get_existing_gateway(device) + return num_triggered < self._max_hosts and (existing or self.gateway_sets) def _target_set_trigger(self, device, remote_trigger=False): assert self._devices.contains(device), 'Target device %s is not expected' % device @@ -617,7 +624,7 @@ def _target_set_trigger(self, device, remote_trigger=False): device.wait_remote = False - if self._target_set_has_capacity(): + if self._target_set_has_capacity(device): LOGGER.info('Target device %s direct activate', device) self._target_set_activate(device) else: @@ -626,11 +633,14 @@ def _target_set_trigger(self, device, remote_trigger=False): device, len(self._target_set_queue)) def _target_set_consider(self): - if self._target_set_queue and self._target_set_has_capacity(): - device = self._target_set_queue.pop(0) - LOGGER.info('Target device %s pop activate (%s)', - device, len(self._target_set_queue)) - self._target_set_activate(device) + if self._target_set_queue: + for num, device in enumerate(self._target_set_queue): + if self._target_set_has_capacity(device): + LOGGER.info('Target device %s pop activate (%s)', + device, len(self._target_set_queue)) + self._target_set_activate(device) + self._target_set_queue.pop(num) + break def _target_set_activate(self, device): external_dhcp = device.dhcp_mode == DhcpMode.EXTERNAL @@ -744,22 +754,28 @@ def _get_test_metadata(self, extension=".daqmodule", root=os.path.join(DAQ_LIB_D } return metadata - def _create_gateway(self, device): + def _get_existing_gateway(self, device): is_native = device is None - assert not is_native or not self._native_gateway, 'native gateway already initialized' if self._native_gateway: return self._native_gateway - group_name = 'native' if is_native else device.group if not is_native: - group_devices = self._devices.get_by_group(group_name) + group_devices = self._devices.get_by_group(device.group) existing_gateways = {device.gateway for device in group_devices if device.gateway} assert len(existing_gateways) <= 1, 'only one existing gateway per group allowed' if existing_gateways: existing = existing_gateways.pop() - LOGGER.debug('Gateway for existing device group %s is %s', group_name, existing) + LOGGER.debug('Gateway for existing device group %s is %s', device.group, existing) return existing + return None + def _create_gateway(self, device): + is_native = device is None + assert not is_native or not self._native_gateway, 'native gateway already initialized' + existing = self._get_existing_gateway(device) + if existing: + return existing + group_name = 'native' if is_native else device.group set_num = 1 if is_native else self._find_gateway_set(device) LOGGER.info('Gateway for device group %s not found, creating set num %d', group_name, set_num) diff --git a/daq/session_server.py b/daq/session_server.py index 699256561a..ae294a75bc 100644 --- a/daq/session_server.py +++ b/daq/session_server.py @@ -146,7 +146,7 @@ def send_device_heartbeats(self): if delta < self._disconnect_timeout_sec: self._send_reply(device_mac, SessionProgress()) else: - LOGGER.warning('Disconnect timeout for %s after %s', device_mac, delta) + LOGGER.warning('Disconnect timeout for %s after %ss', device_mac, round(delta)) self.close_stream(device_mac) diff --git a/daq/topology.py b/daq/topology.py index 5e8b04aa03..00295ade3a 100644 --- a/daq/topology.py +++ b/daq/topology.py @@ -54,7 +54,7 @@ def __init__(self, config): self.sec_name = 'sec' switch_setup = self.config.get('switch_setup', {}) self.sec_port = int(switch_setup['uplink_port']) - self.sec_dpid = int(switch_setup['of_dpid'], 0) + self.sec_dpid = int(switch_setup.get('of_dpid', 0)) self.ext_ofip = switch_setup.get('lo_addr') self.ext_intf = switch_setup.get('data_intf') self._native_faucet = switch_setup.get('native') diff --git a/testing/test_dhcp.sh b/testing/test_dhcp.sh index 605baa9364..b3d786a773 100755 --- a/testing/test_dhcp.sh +++ b/testing/test_dhcp.sh @@ -7,6 +7,7 @@ echo DHCP Tests >> $TEST_RESULTS cat < /tmp/daq.conf include=${DAQ_LIB}/config/system/default.yaml site_description="Multi-Device Configuration" +switch_setup.of_dpid=2 switch_setup.uplink_port=7 interfaces.faux-1.opts= interfaces.faux-2.opts=xdhcp diff --git a/testing/test_many.sh b/testing/test_many.sh index 863bf055c6..2a8ef766bb 100755 --- a/testing/test_many.sh +++ b/testing/test_many.sh @@ -17,6 +17,7 @@ echo Many Tests >> $TEST_RESULTS echo include=../config/system/default.yaml > local/system.conf echo monitor_scan_sec=5 >> local/system.conf +echo switch_setup.of_dpid=2 >> local/system.conf echo switch_setup.uplink_port=$((NUM_DEVICES+1)) >> local/system.conf echo gcp_cred=$gcp_cred >> local/system.conf echo dhcp_lease_time=120s >> local/system.conf diff --git a/testing/test_utils.sh b/testing/test_utils.sh index cf05433565..06d501203c 100644 --- a/testing/test_utils.sh +++ b/testing/test_utils.sh @@ -15,6 +15,7 @@ function generate { rm -rf inst/runtime_conf echo switch_setup.uplink_port=$((faux_num+1)) >> local/system.conf + echo switch_setup.of_dpid=2 >> local/system.conf # Create required number of faux devices for iface in $(seq 1 $faux_num); do