Skip to content

Commit

Permalink
gateway allocation cleanup (#900)
Browse files Browse the repository at this point in the history
  • Loading branch information
henry54809 authored Aug 4, 2021
1 parent 10b75ca commit 0496771
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 27 deletions.
2 changes: 1 addition & 1 deletion config/system/all.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion config/system/alt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions config/system/ata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions config/system/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 0 additions & 5 deletions config/system/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion config/system/dts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ switch_setup:
varz_port: 5678
model: EXT_STACK
native: True
of_dpid: '0'

run_trigger:
vlan_start: 272
Expand Down
2 changes: 1 addition & 1 deletion config/system/muddy.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/system/multi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 31 additions & 15 deletions daq/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 = {}
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion daq/session_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion daq/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions testing/test_dhcp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ echo DHCP Tests >> $TEST_RESULTS
cat <<EOF > /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
Expand Down
1 change: 1 addition & 0 deletions testing/test_many.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions testing/test_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0496771

Please sign in to comment.