Example #1
0
    def _get_port_infos(self, port, segment, agent_host):
        if not agent_host:
            return

        session = db_api.get_session()
        agent = l2pop_db.get_agent_by_host(session, agent_host)
        if not agent:
            return

        agent_ip = l2pop_db.get_agent_ip(agent)
        if not agent_ip:
            LOG.warning(_LW("Unable to retrieve the agent ip, check the agent "
                            "configuration."))
            return

        if not segment:
            LOG.warning(_LW("Port %(port)s updated by agent %(agent)s "
                            "isn't bound to any segment"),
                        {'port': port['id'], 'agent': agent})
            return

        network_types = l2pop_db.get_agent_l2pop_network_types(agent)
        if network_types is None:
            network_types = l2pop_db.get_agent_tunnel_types(agent)
        if segment['network_type'] not in network_types:
            return

        fdb_entries = [l2pop_rpc.PortInfo(mac_address=port['mac_address'],
                                          ip_address=ip['ip_address'])
                       for ip in port['fixed_ips']]
        return agent_ip, fdb_entries
Example #2
0
    def _get_agent_fdb(self, context, segment, port, agent_host):
        if not agent_host:
            return

        network_id = port['network_id']

        session = db_api.get_session()
        agent_active_ports = l2pop_db.get_agent_network_active_port_count(
            session, agent_host, network_id)

        agent = l2pop_db.get_agent_by_host(db_api.get_session(), agent_host)
        if not self._validate_segment(segment, port['id'], agent):
            return

        agent_ip = l2pop_db.get_agent_ip(agent)
        other_fdb_entries = self._get_fdb_entries_template(
            segment, agent_ip, port['network_id'])
        if agent_active_ports == 0:
            # Agent is removing its last activated port in this network,
            # other agents needs to be notified to delete their flooding entry.
            other_fdb_entries[network_id]['ports'][agent_ip].append(
                const.FLOODING_ENTRY)
        # Notify other agents to remove fdb rules for current port
        if (port['device_owner'] != const.DEVICE_OWNER_DVR_INTERFACE
                and not l3_hamode_db.is_ha_router_port(
                    context, port['device_owner'], port['device_id'])):
            fdb_entries = self._get_port_fdb_entries(port)
            other_fdb_entries[network_id]['ports'][agent_ip] += fdb_entries

        return other_fdb_entries
Example #3
0
    def _get_port_infos(self, port, segment, agent_host):
        if not agent_host:
            return

        session = db_api.get_session()
        agent = l2pop_db.get_agent_by_host(session, agent_host)
        if not agent:
            return

        agent_ip = l2pop_db.get_agent_ip(agent)
        if not agent_ip:
            LOG.warning(_LW("Unable to retrieve the agent ip, check the agent "
                            "configuration."))
            return

        if not segment:
            LOG.warning(_LW("Port %(port)s updated by agent %(agent)s "
                            "isn't bound to any segment"),
                        {'port': port['id'], 'agent': agent})
            return

        network_types = l2pop_db.get_agent_l2pop_network_types(agent)
        if network_types is None:
            network_types = l2pop_db.get_agent_tunnel_types(agent)
        if segment['network_type'] not in network_types:
            return

        fdb_entries = [l2pop_rpc.PortInfo(mac_address=port['mac_address'],
                                          ip_address=ip['ip_address'])
                       for ip in port['fixed_ips']]
        return agent_ip, fdb_entries
Example #4
0
 def test_get_agent_by_host(self):
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     helpers.register_ovs_agent()
     agent = l2pop_db.get_agent_by_host(
         self.ctx.session, helpers.HOST)
     self.assertEqual(constants.AGENT_TYPE_OVS, agent.agent_type)
Example #5
0
    def _get_agent_fdb(self, segment, port, agent_host):
        if not agent_host:
            return

        network_id = port['network_id']

        session = db_api.get_session()
        agent_active_ports = l2pop_db.get_agent_network_active_port_count(
            session, agent_host, network_id)

        agent = l2pop_db.get_agent_by_host(db_api.get_session(), agent_host)
        if not self._validate_segment(segment, port['id'], agent):
            return

        agent_ip = l2pop_db.get_agent_ip(agent)
        other_fdb_entries = self._get_fdb_entries_template(
            segment, agent_ip, port['network_id'])
        if agent_active_ports == 0:
            # Agent is removing its last activated port in this network,
            # other agents needs to be notified to delete their flooding entry.
            other_fdb_entries[network_id]['ports'][agent_ip].append(
                const.FLOODING_ENTRY)
        # Notify other agents to remove fdb rules for current port
        if port['device_owner'] != const.DEVICE_OWNER_DVR_INTERFACE:
            fdb_entries = self._get_port_fdb_entries(port)
            other_fdb_entries[network_id]['ports'][agent_ip] += fdb_entries

        return other_fdb_entries
Example #6
0
 def agent_restarted(self, context):
     agent_host = context.host
     port_context = context._plugin_context
     agent = l2pop_db.get_agent_by_host(port_context, agent_host)
     if l2pop_db.get_agent_uptime(agent) < cfg.CONF.l2pop.agent_boot_time:
         return True
     return False
Example #7
0
 def agent_restarted(self, context):
     agent_host = context.host
     port_context = context._plugin_context
     agent = l2pop_db.get_agent_by_host(port_context, agent_host)
     if l2pop_db.get_agent_uptime(agent) < cfg.CONF.l2pop.agent_boot_time:
         return True
     return False
Example #8
0
 def test_get_agent_by_host(self):
     # Register a L2 agent + A bunch of other agents on the same host
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     helpers.register_ovs_agent()
     agent = l2pop_db.get_agent_by_host(self.ctx.session, helpers.HOST)
     self.assertEqual(constants.AGENT_TYPE_OVS, agent.agent_type)
Example #9
0
 def test_get_agent_by_host_no_candidate(self):
     # Register a bunch of non-L2 agents on the same host
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     agent = l2pop_db.get_agent_by_host(
         self.ctx.session, helpers.HOST)
     self.assertIsNone(agent)
Example #10
0
 def test_get_agent_by_host_no_candidate(self):
     # Register a bunch of non-L2 agents on the same host
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     agent = l2pop_db.get_agent_by_host(
         self.ctx.session, helpers.HOST)
     self.assertIsNone(agent)
Example #11
0
    def _get_agent_fdb(self, context, segment, port, agent_host):
        if not agent_host:
            return

        network_id = port['network_id']

        agent_active_ports = l2pop_db.get_agent_network_active_port_count(
            context, agent_host, network_id)

        agent = l2pop_db.get_agent_by_host(context,
                                           agent_host)
        if not agent:
            LOG.warning("Unable to retrieve active L2 agent on host %s",
                        agent_host)
            return
        if not self._validate_segment(segment, port['id'], agent):
            return

        agent_ip = l2pop_db.get_agent_ip(agent)
        other_fdb_entries = self._get_fdb_entries_template(
            segment, agent_ip, port['network_id'])
        if agent_active_ports == 0:
            # Agent is removing its last activated port in this network,
            # other agents needs to be notified to delete their flooding entry.
            other_fdb_entries[network_id]['ports'][agent_ip].append(
                const.FLOODING_ENTRY)
        # Notify other agents to remove fdb rules for current port
        if (port['device_owner'] != const.DEVICE_OWNER_DVR_INTERFACE and
            not l3_hamode_db.is_ha_router_port(context,
                                               port['device_owner'],
                                               port['device_id'])):
            fdb_entries = self._get_port_fdb_entries(port)
            other_fdb_entries[network_id]['ports'][agent_ip] += fdb_entries

        return other_fdb_entries
Example #12
0
 def test_get_agent_by_host(self):
     # Register a L2 agent + A bunch of other agents on the same host
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     helpers.register_ovs_agent()
     agent = l2pop_db.get_agent_by_host(
         self.ctx.session, helpers.HOST)
     self.assertEqual(constants.AGENT_TYPE_OVS, agent.agent_type)
Example #13
0
 def agent_restarted(self, context):
     agent_host = context.host
     port_context = context._plugin_context
     agent = l2pop_db.get_agent_by_host(port_context, agent_host)
     if l2pop_db.get_agent_uptime(agent) < cfg.CONF.l2pop.agent_boot_time:
         LOG.warning("Agent on host '%s' did not supply 'agent_restarted' "
                     "information in RPC message, determined it restarted "
                     "based on deprecated 'agent_boot_time' config option.",
                     agent_host)
         return True
     return False
Example #14
0
 def agent_restarted(self, context):
     agent_host = context.host
     session = db_api.get_reader_session()
     agent = l2pop_db.get_agent_by_host(session, agent_host)
     if l2pop_db.get_agent_uptime(agent) < cfg.CONF.l2pop.agent_boot_time:
         LOG.warning(
             _LW("Agent on host '%s' did not supply "
                 "'agent_restarted'information in RPC message, "
                 "determined it restarted based on deprecated "
                 "'agent_boot_time' config option."), agent_host)
         return True
     return False
Example #15
0
    def update_port_up(self, context, agent_restarted=None):
        port = context.current
        agent_host = context.host
        port_context = context._plugin_context
        agent = l2pop_db.get_agent_by_host(port_context, agent_host)
        if not agent:
            LOG.warning("Unable to retrieve active L2 agent on host %s",
                        agent_host)
            return

        network_id = port['network_id']

        agent_active_ports = l2pop_db.get_agent_network_active_port_count(
            port_context, agent_host, network_id)

        agent_ip = l2pop_db.get_agent_ip(agent)
        segment = context.bottom_bound_segment
        if not self._validate_segment(segment, port['id'], agent):
            return
        other_fdb_entries = self._get_fdb_entries_template(
            segment, agent_ip, network_id)
        other_fdb_ports = other_fdb_entries[network_id]['ports']

        # with high concurrency more than 1 port may be activated on an agent
        # at the same time (like VM port + a DVR port) so checking for 1 or 2
        is_first_port = agent_active_ports in (1, 2)
        if agent_restarted is None:
            # Only for backport compatibility, will be removed.
            agent_restarted = self.agent_restarted(context)
        if is_first_port or agent_restarted:
            # First port(s) activated on current agent in this network,
            # we have to provide it with the whole list of fdb entries
            agent_fdb_entries = self._create_agent_fdb(port_context,
                                                       agent,
                                                       segment,
                                                       network_id)

            # And notify other agents to add flooding entry
            other_fdb_ports[agent_ip].append(const.FLOODING_ENTRY)

            if agent_fdb_entries[network_id]['ports'].keys():
                self.L2populationAgentNotify.add_fdb_entries(
                    self.rpc_ctx, agent_fdb_entries, agent_host)

        # Notify other agents to add fdb rule for current port
        if (port['device_owner'] != const.DEVICE_OWNER_DVR_INTERFACE and
            not l3_hamode_db.is_ha_router_port(
                port_context, port['device_owner'], port['device_id'])):
            other_fdb_ports[agent_ip] += self._get_port_fdb_entries(port)

        self.L2populationAgentNotify.add_fdb_entries(self.rpc_ctx,
                                                     other_fdb_entries)
Example #16
0
    def update_port_up(self, context):
        port = context.current
        agent_host = context.host
        session = db_api.get_reader_session()
        port_context = context._plugin_context
        agent = l2pop_db.get_agent_by_host(session, agent_host)
        if not agent:
            LOG.warning(_LW("Unable to retrieve active L2 agent on host %s"),
                        agent_host)
            return

        network_id = port['network_id']

        agent_active_ports = l2pop_db.get_agent_network_active_port_count(
            session, agent_host, network_id)

        agent_ip = l2pop_db.get_agent_ip(agent)
        segment = context.bottom_bound_segment
        if not self._validate_segment(segment, port['id'], agent):
            return
        other_fdb_entries = self._get_fdb_entries_template(
            segment, agent_ip, network_id)
        other_fdb_ports = other_fdb_entries[network_id]['ports']

        if agent_active_ports == 1 or (l2pop_db.get_agent_uptime(agent) <
                                       cfg.CONF.l2pop.agent_boot_time):
            # First port activated on current agent in this network,
            # we have to provide it with the whole list of fdb entries
            agent_fdb_entries = self._create_agent_fdb(session,
                                                       agent,
                                                       segment,
                                                       network_id)

            # And notify other agents to add flooding entry
            other_fdb_ports[agent_ip].append(const.FLOODING_ENTRY)

            if agent_fdb_entries[network_id]['ports'].keys():
                self.L2populationAgentNotify.add_fdb_entries(
                    self.rpc_ctx, agent_fdb_entries, agent_host)

        # Notify other agents to add fdb rule for current port
        if (port['device_owner'] != const.DEVICE_OWNER_DVR_INTERFACE and
            not l3_hamode_db.is_ha_router_port(
                port_context, port['device_owner'], port['device_id'])):
            other_fdb_ports[agent_ip] += self._get_port_fdb_entries(port)

        self.L2populationAgentNotify.add_fdb_entries(self.rpc_ctx,
                                                     other_fdb_entries)
Example #17
0
    def update_port_up(self, context):
        port = context.current
        agent_host = context.host
        port_context = context._plugin_context
        agent = l2pop_db.get_agent_by_host(port_context, agent_host)
        if not agent:
            LOG.warning("Unable to retrieve active L2 agent on host %s",
                        agent_host)
            return

        network_id = port['network_id']

        agent_active_ports = l2pop_db.get_agent_network_active_port_count(
            port_context, agent_host, network_id)

        agent_ip = l2pop_db.get_agent_ip(agent)
        segment = context.bottom_bound_segment
        if not self._validate_segment(segment, port['id'], agent):
            return
        other_fdb_entries = self._get_fdb_entries_template(
            segment, agent_ip, network_id)
        other_fdb_ports = other_fdb_entries[network_id]['ports']

        if agent_active_ports == 1 or (l2pop_db.get_agent_uptime(agent) <
                                       cfg.CONF.l2pop.agent_boot_time):
            # First port activated on current agent in this network,
            # we have to provide it with the whole list of fdb entries
            agent_fdb_entries = self._create_agent_fdb(port_context,
                                                       agent,
                                                       segment,
                                                       network_id)

            # And notify other agents to add flooding entry
            other_fdb_ports[agent_ip].append(const.FLOODING_ENTRY)

            if agent_fdb_entries[network_id]['ports'].keys():
                self.L2populationAgentNotify.add_fdb_entries(
                    self.rpc_ctx, agent_fdb_entries, agent_host)

        # Notify other agents to add fdb rule for current port
        if (port['device_owner'] != const.DEVICE_OWNER_DVR_INTERFACE and
            not l3_hamode_db.is_ha_router_port(
                port_context, port['device_owner'], port['device_id'])):
            other_fdb_ports[agent_ip] += self._get_port_fdb_entries(port)

        self.L2populationAgentNotify.add_fdb_entries(self.rpc_ctx,
                                                     other_fdb_entries)
Example #18
0
    def _fixed_ips_changed(self, context, orig, port, diff_ips):
        orig_ips, port_ips = diff_ips

        if (port['device_owner'] == const.DEVICE_OWNER_DVR_INTERFACE):
            agent_host = context.host
        else:
            agent_host = context.original_host

        if not agent_host:
            return

        # We should not add arp responder for non tunnel network type
        port_context = context._plugin_context
        agent = l2pop_db.get_agent_by_host(port_context, agent_host)
        segment = context.bottom_bound_segment
        if not self._validate_segment(segment, port['id'], agent):
            return

        agent_ip = l2pop_db.get_agent_ip_by_host(context._plugin_context,
                                                 agent_host)

        orig_mac_ip = [
            l2pop_rpc.PortInfo(mac_address=port['mac_address'], ip_address=ip)
            for ip in orig_ips
        ]
        port_mac_ip = [
            l2pop_rpc.PortInfo(mac_address=port['mac_address'], ip_address=ip)
            for ip in port_ips
        ]

        upd_fdb_entries = {port['network_id']: {agent_ip: {}}}

        ports = upd_fdb_entries[port['network_id']][agent_ip]
        if orig_mac_ip:
            ports['before'] = orig_mac_ip

        if port_mac_ip:
            ports['after'] = port_mac_ip

        self.L2populationAgentNotify.update_fdb_entries(
            self.rpc_ctx, {'chg_ip': upd_fdb_entries})

        return True
Example #19
0
    def _fixed_ips_changed(self, context, orig, port, diff_ips):
        orig_ips, port_ips = diff_ips

        if (port['device_owner'] == const.DEVICE_OWNER_DVR_INTERFACE):
            agent_host = context.host
        else:
            agent_host = context.original_host

        if not agent_host:
            return

        # We should not add arp responder for non tunnel network type
        port_context = context._plugin_context
        agent = l2pop_db.get_agent_by_host(port_context, agent_host)
        segment = context.bottom_bound_segment
        if not self._validate_segment(segment, port['id'], agent):
            return

        agent_ip = l2pop_db.get_agent_ip_by_host(context._plugin_context,
                                                 agent_host)

        orig_mac_ip = [l2pop_rpc.PortInfo(mac_address=port['mac_address'],
                                          ip_address=ip)
                       for ip in orig_ips]
        port_mac_ip = [l2pop_rpc.PortInfo(mac_address=port['mac_address'],
                                          ip_address=ip)
                       for ip in port_ips]

        upd_fdb_entries = {port['network_id']: {agent_ip: {}}}

        ports = upd_fdb_entries[port['network_id']][agent_ip]
        if orig_mac_ip:
            ports['before'] = orig_mac_ip

        if port_mac_ip:
            ports['after'] = port_mac_ip

        self.L2populationAgentNotify.update_fdb_entries(
            self.rpc_ctx, {'chg_ip': upd_fdb_entries})

        return True
Example #20
0
 def test_get_agent_by_host_no_candidate(self):
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     agent = l2pop_db.get_agent_by_host(self.ctx.session, helpers.HOST)
     self.assertIsNone(agent)
Example #21
0
 def test_get_agent_by_host_no_candidate(self):
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     agent = l2pop_db.get_agent_by_host(
         self.ctx.session, helpers.HOST)
     self.assertIsNone(agent)