Пример #1
0
    def bgpvpn_port_attach(self, context, port_bgpvpn_info):
        port_id = port_bgpvpn_info.pop('id')
        net_id = port_bgpvpn_info.pop('network_id')

        net_info, port_info = self._get_network_port_infos(net_id, port_id)

        # Set IP and MAC adresses in PortInfo
        ip_address = port_bgpvpn_info.pop('ip_address')
        mac_address = port_bgpvpn_info.pop('mac_address')
        port_info.set_ip_mac_infos(ip_address, mac_address)

        # Set gateway IP and MAC (if defined) addresses in NetworkInfo
        gateway_info = GatewayInfo(port_bgpvpn_info.pop('gateway_mac', None),
                                   port_bgpvpn_info.pop('gateway_ip'))

        if has_attachement(port_bgpvpn_info, BGPVPN_L3):
            self._check_arp_voodoo_plug(net_info, gateway_info)

        net_info.set_gateway_info(gateway_info)

        if self.agent_type == n_const.AGENT_TYPE_OVS:
            vlan = self.vlan_manager.get(net_id).vlan
            port_info.set_local_port('%s:%s' % (LINUXIF_PREFIX, vlan))
        else:
            port_info.set_local_port(
                LinuxBridgeManager.get_tap_device_name(port_id)
            )

        net_info.add_service_info(BGPVPN_SERVICE, port_bgpvpn_info)

        self._do_port_plug(port_id)
    def _build_attachment(self, port_info):
        if not port_info.chain_hops:
            return {}

        linuxbr = LinuxBridgeManager.get_bridge_name(port_info.network.id)
        chain_hop = port_info.chain_hops

        attachment = {
            'ip_address':
            port_info.ip_address,
            'mac_address':
            port_info.mac_address,
            'gateway_ip':
            port_info.network.gateway_info.ip,
            'local_port': {
                'linuxif': linuxbr
            },
            bbgp_const.RT_IMPORT: (chain_hop[sfc_const.INGRESS]['rts'] if
                                   chain_hop.get(sfc_const.INGRESS) else []),
            bbgp_const.RT_EXPORT: (chain_hop[sfc_const.EGRESS]['rts']
                                   if chain_hop.get(sfc_const.EGRESS) else [])
        }

        egress_info = chain_hop.get(sfc_const.EGRESS)
        if egress_info:
            if egress_info.get('readv_to_rt'):
                attachment.update({
                    'readvertise':
                    dict(from_rt=egress_info.get('readv_from_rts', []),
                         to_rt=[egress_info['readv_to_rt']])
                })

            if (egress_info.get('redirect_rts')
                    and egress_info.get('classifiers')):
                classifier = jsonutils.loads(egress_info['classifiers'])[0]

                attract_traffic = dict(
                    redirect_rts=egress_info['redirect_rts'],
                    classifier=classifier)

                if egress_info.get('attract_to_rt'):
                    destination_prefix = classifier.get(
                        'destinationPrefix', '0.0.0.0/0')

                    attract_traffic.update(
                        dict(to_rt=[egress_info['attract_to_rt']],
                             static_destination_prefixes=[destination_prefix]))

                attachment.update(dict(attract_traffic=attract_traffic))

            attachment.update(
                dict(lb_consistent_hash_order=egress_info[
                    'lb_consistent_hash_order']))

        return attachment
Пример #3
0
    def _compile_bagpipe_l2_attach_info(self, service_info, port_info):
        attach_info = {
            EVPN: {
                RT_IMPORT: [service_info[EVPN][RT_IMPORT]],
                RT_EXPORT: [service_info[EVPN][RT_EXPORT]]
            }
        }

        attach_info[EVPN].update(dict(
            linuxbr=LinuxBridgeManager.get_bridge_name(port_info.network.id)))

        return attach_info
    def _get_local_port_for_attach(self, port_id, net_id):
        if self.agent_type == n_const.AGENT_TYPE_LINUXBRIDGE:
            port_name = LinuxBridgeManager.get_tap_device_name(port_id)
            bridge_name = LinuxBridgeManager.get_bridge_name(net_id)

            return {"linuxbr": bridge_name, "local_port": {"linuxif": port_name}}
        elif self.agent_type == n_const.AGENT_TYPE_OVS:
            port = self.int_br.get_vif_port_by_id(port_id)
            try:
                vlan = self.get_local_vlan(port_id)

                return {
                    "local_port": {
                        "linuxif": port.port_name,
                        "ovs": {
                            "plugged": True,
                            "port_number": self.patch_mpls_from_tun_ofport,
                            "to_vm_port_number": self.patch_mpls_to_tun_ofport,
                            "vlan": vlan,
                        },
                    }
                }
            except Exception as e:
                LOG.error("could not find vlan for port %s: %s", port_id, e)
    def _build_sfc_detach_info(self, port_info):
        linuxbr = LinuxBridgeManager.get_bridge_name(port_info.network.id)

        detach_info = {
            'network_id': port_info.network.id,
            bbgp_const.IPVPN: {
                'ip_address': port_info.ip_address,
                'mac_address': port_info.mac_address,
                'local_port': {
                    'linuxif': linuxbr
                }
            }
        }

        return detach_info
Пример #6
0
    def _compile_bgpvpn_attach_info(self, service_info, port_info):
        attach_info = {}

        for bgpvpn_type, rt_type in list(
                itertools.product(BGPVPN_TYPES, RT_TYPES)):
            if rt_type in service_info.get(bgpvpn_type, {}):
                bagpipe_bgp_vpn_type = BGPVPN_TYPES_MAP[bgpvpn_type]
                if bagpipe_bgp_vpn_type not in attach_info:
                    attach_info[bagpipe_bgp_vpn_type] = defaultdict(list)

                attach_info[bagpipe_bgp_vpn_type][rt_type] += (
                    service_info[bgpvpn_type][rt_type]
                )

        if self.agent_type == n_const.AGENT_TYPE_OVS:
            # Add OVS VLAN information
            vlan = self.vlan_manager.get(port_info.network.id).vlan
            for vpn_type in (vt for vt in VPN_TYPES if vt in attach_info):
                attach_info[vpn_type].update({
                    'local_port': {
                        'ovs': {
                            'plugged': True,
                            'port_number': self.patch_mpls_from_tun_ofport,
                            'to_vm_port_number': self.patch_mpls_to_tun_ofport,
                            'vlan': vlan
                        }
                    }
                })

            if has_attachement(attach_info, IPVPN):
                # Add fallback information if needed as well
                if port_info.network.gateway_info.mac:
                    attach_info[IPVPN].update({
                        'fallback': {
                            'dst_mac': port_info.network.gateway_info.mac,
                            'src_mac': FALLBACK_SRC_MAC,
                            'ovs_port_number': self.patch_mpls_to_int_ofport
                        }
                    })
        else:
            for vpn_type in VPN_TYPES:
                if has_attachement(attach_info, vpn_type):
                    attach_info[vpn_type].update(
                        dict(linuxbr=LinuxBridgeManager.get_bridge_name(
                             port_info.network.id))
                    )

        return attach_info
Пример #7
0
    def _mock_send_expected_call(self,
                                 vpn_type,
                                 port,
                                 vif,
                                 evpn2ipvpn=False,
                                 others_rts=None,
                                 fallback=None):
        network_id = port['network_id']

        vif_name = vif.port_name if vif else None
        local_port, linuxbr = self._get_expected_local_port(
            network_id, port['id'], vif_name)
        # Change local port if plugging evpn into ipvpn
        if evpn2ipvpn:
            local_port = dict(evpn=dict(id=network_id + '_evpn'))

        import_rt, export_rt = self._get_expected_route_target(
            vpn_type, port, others_rts)

        if vpn_type in BGPVPN_TYPES:
            vpn_type = BGPVPN_TYPES_MAP[vpn_type]

        expected_call = dict(vpn_instance_id=network_id + '_' + vpn_type,
                             vpn_type=vpn_type,
                             local_port=local_port,
                             mac_address=port['mac_address'],
                             ip_address=port['ip_address'],
                             gateway_ip=port['gateway_ip'],
                             import_rt=import_rt,
                             export_rt=export_rt)

        if linuxbr:
            expected_call.update(
                dict(linuxbr=LinuxBridgeManager.get_bridge_name(network_id)))
        if fallback:
            expected_call.update({'fallback': fallback})

        return mock.call(expected_call)
Пример #8
0
    def bagpipe_port_attach(self, context, port_bagpipe_info):
        port_id = port_bagpipe_info.pop('id')
        net_id = port_bagpipe_info.pop('network_id')

        net_info, port_info = self._get_network_port_infos(net_id, port_id)

        # Set IP and MAC adresses in PortInfo
        ip_address = port_bagpipe_info.pop('ip_address')
        mac_address = port_bagpipe_info.pop('mac_address')
        port_info.set_ip_mac_infos(ip_address, mac_address)

        # Set gateway IP address in NetworkInfo
        gateway_info = GatewayInfo(None,
                                   port_bagpipe_info.pop('gateway_ip'))
        net_info.set_gateway_info(gateway_info)

        port_info.set_local_port(
            LinuxBridgeManager.get_tap_device_name(port_id)
        )

        net_info.add_service_info(BAGPIPE_L2_SERVICE, port_bagpipe_info)

        self._do_port_plug(port_id)
Пример #9
0
    def _get_expected_local_port(self, network_id, port_id, vif_name):
        local_port = dict(
            linuxif=LinuxBridgeManager.get_tap_device_name(port_id))
        linuxbr = LinuxBridgeManager.get_bridge_name(network_id)

        return local_port, linuxbr