コード例 #1
0
    def _initialize(self):
        host_name = 'gw%02d' % self.port_set
        host_port = self._switch_port(self.GATEWAY_OFFSET)
        LOGGER.info('Initializing gateway %s as %s/%d', self.name, host_name,
                    host_port)
        self.tmpdir = self._setup_tmpdir(host_name)
        cls = docker_host.make_docker_host('daqf/networking',
                                           prefix='daq',
                                           network='bridge')
        # Work around an instability in the faucet/clib/docker library, b/152520627.
        if getattr(cls, 'pullImage'):
            setattr(cls, 'pullImage', lambda x: True)
        vol_maps = [os.path.abspath('inst/config') + ':/config/inst']
        host = self.runner.add_host(host_name,
                                    port=host_port,
                                    cls=cls,
                                    tmpdir=self.tmpdir,
                                    vol_maps=vol_maps)
        host.activate()
        self.host = host
        self._change_lease_time(
            self.runner.config.get('initial_dhcp_lease_time'))
        LOGGER.info("Added networking host %s on port %d at %s", host_name,
                    host_port, host.IP())

        dummy_name = 'dummy%02d' % self.port_set
        dummy_port = self._switch_port(self.DUMMY_OFFSET)
        dummy = self.runner.add_host(dummy_name, port=dummy_port)
        # Dummy does not use DHCP, so need to set default route manually.
        dummy.cmd('route add -net 0.0.0.0 gw %s' % host.IP())
        self.dummy = dummy
        LOGGER.info("Added dummy target %s on port %d at %s", dummy_name,
                    dummy_port, dummy.IP())

        self.fake_target = self.TEST_IP_FORMAT % self.port_set
        self.host_intf = self.runner.get_host_interface(host)
        LOGGER.debug('Adding fake target at %s to %s', self.fake_target,
                     self.host_intf)
        host.cmd('ip addr add %s dev %s' % (self.fake_target, self.host_intf))

        self._startup_scan(host)
        log_file = os.path.join(self.tmpdir, 'dhcp_monitor.txt')
        self.dhcp_monitor = dhcp_monitor.DhcpMonitor(self.runner, host,
                                                     self._dhcp_callback,
                                                     log_file)
        self.dhcp_monitor.start()

        ping_retry = self._PING_RETRY_COUNT
        while not self._ping_test(host, dummy):
            ping_retry -= 1
            LOGGER.info('Gateway %s warmup failed at %s with %d', host_name,
                        datetime.datetime.now(), ping_retry)
            assert ping_retry, 'warmup ping failure'

        assert self._ping_test(host, dummy), 'dummy ping failed'
        assert self._ping_test(dummy, host), 'host ping failed'
        assert self._ping_test(dummy, self.fake_target), 'fake ping failed'
        assert self._ping_test(
            host, dummy, src_addr=self.fake_target), 'reverse ping failed'
コード例 #2
0
ファイル: container_gateway.py プロジェクト: faucetsdn/daq
 def _initialize(self, **kwargs):
     super()._initialize(**kwargs)
     self._change_lease_time(
         self.runner.config.get('initial_dhcp_lease_time'))
     self._startup_scan(self.host)
     log_file = os.path.join(self.tmpdir, 'dhcp_monitor.txt')
     self.dhcp_monitor = dhcp_monitor.DhcpMonitor(self.runner, self.host,
                                                  self._dhcp_callback, log_file=log_file)
     self.dhcp_monitor.start()
コード例 #3
0
 def _initialize(self):
     super()._initialize()
     log_file = os.path.join(self.tmpdir, 'dhcp_monitor.txt')
     self.dhcp_monitor = dhcp_monitor.DhcpMonitor(self.runner,
                                                  self.runner.network.pri,
                                                  self._dhcp_callback,
                                                  log_file=log_file,
                                                  intf_name=self._tap_intf)
     self.dhcp_monitor.start()
コード例 #4
0
ファイル: gateway.py プロジェクト: silviaquaglia/daq
    def _initialize(self):
        host_name = 'gw%02d' % self.port_set
        host_port = self._switch_port(self.GATEWAY_OFFSET)
        LOGGER.info('Initializing gateway %s as %s/%d', self.name, host_name,
                    host_port)
        self.tmpdir = self._setup_tmpdir(host_name)
        cls = docker_host.make_docker_host('daq/networking',
                                           prefix='daq',
                                           network='bridge')
        host = self.runner.add_host(host_name,
                                    port=host_port,
                                    cls=cls,
                                    tmpdir=self.tmpdir)
        host.activate()
        LOGGER.info("Adding networking host %s on port %d at %s", host_name,
                    host_port, host.IP())

        dummy_name = 'dummy%02d' % self.port_set
        dummy_port = self._switch_port(self.DUMMY_OFFSET)
        self.dummy = self.runner.add_host(dummy_name, port=dummy_port)
        dummy = self.dummy
        LOGGER.info("Added dummy target %s on port %d at %s", dummy_name,
                    dummy_port, dummy.IP())

        self.fake_target = self.TEST_IP_FORMAT % self.port_set
        self.host_intf = self.runner.get_host_interface(host)
        LOGGER.debug('Adding fake target at %s to %s', self.fake_target,
                     self.host_intf)
        host.cmd('ip addr add %s dev %s' % (self.fake_target, self.host_intf))

        self._startup_scan(host)

        # Dummy doesn't use DHCP, so need to set default route manually.
        dummy.cmd('route add -net 0.0.0.0 gw %s' % host.IP())

        log_file = os.path.join(self.tmpdir, 'dhcp_monitor.txt')
        self.dhcp_monitor = dhcp_monitor.DhcpMonitor(self.runner, host,
                                                     self._dhcp_callback,
                                                     log_file)
        self.dhcp_monitor.start()

        ping_retry = self._PING_RETRY_COUNT
        while not self._ping_test(host, dummy) and ping_retry:
            ping_retry -= 1
            LOGGER.info('Gateway %s warmup ping failed at %s', host_name,
                        datetime.datetime.now())

        assert self._ping_test(host, dummy), 'dummy ping failed'
        assert self._ping_test(dummy, host), 'host ping failed'
        assert self._ping_test(dummy, self.fake_target), 'fake ping failed'
        assert self._ping_test(
            host, dummy, src_addr=self.fake_target), 'reverse ping failed'

        self.host = host
コード例 #5
0
ファイル: external_gateway.py プロジェクト: faucetsdn/daq
 def _initialize(self):
     super()._initialize()
     log_file = os.path.join(self.tmpdir, 'dhcp_monitor.txt')
     self.dhcp_monitor = dhcp_monitor.DhcpMonitor(self.runner,
                                                  self.runner.network.pri,
                                                  self._dhcp_callback,
                                                  log_file=log_file,
                                                  intf_name=self._tap_intf)
     LOGGER.info('Starting gateway %s DHCP monitor on %s', self.port_set,
                 self._tap_intf)
     self.dhcp_monitor.start()
コード例 #6
0
ファイル: host.py プロジェクト: cneilson/daq
    def _activate(self):
        self._state_transition(_STATE.STARTUP, _STATE.INIT)
        LOGGER.info('Set %d activating.', self.port_set)

        if not os.path.exists(self.scan_base):
            os.makedirs(self.scan_base)

        try:
            self.record_result('sanity', state='run')
            networking = self.networking
            networking.activate()
            self._startup_scan()

            dummy_name = 'dummy%02d' % self.port_set
            dummy_port = self.pri_base + self.DUMMY_OFFSET
            self.dummy = self.runner.add_host(dummy_name, port=dummy_port)
            dummy = self.dummy

            self.fake_target = self.TEST_IP_FORMAT % random.randint(10, 99)
            LOGGER.debug('Adding fake target at %s', self.fake_target)
            intf = self.runner.get_host_interface(networking)
            networking.cmd('ip addr add %s dev %s' % (self.fake_target, intf))

            # Dummy doesn't use DHCP, so need to set default route manually.
            dummy.cmd('route add -net 0.0.0.0 gw %s' % networking.IP())

            self.dhcp_monitor = dhcp_monitor.DhcpMonitor(
                self.runner, self.port_set, networking, self.dhcp_callback)

            assert self._ping_test(networking, dummy), 'ping failed'
            assert self._ping_test(dummy, networking), 'ping failed'
            assert self._ping_test(dummy, self.fake_target), 'ping failed'
            assert self._ping_test(networking,
                                   dummy,
                                   src_addr=self.fake_target), 'ping failed'
            self.record_result('sanity')
            self._state_transition(_STATE.ACTIVE, _STATE.STARTUP)
        except Exception as e:
            LOGGER.error('Set %d sanity error: %s', self.port_set, e)
            LOGGER.exception(e)
            self.record_result('sanity', exception=e)
            self._state_transition(_STATE.ERROR)