コード例 #1
0
    def get_vn_li_map(self):
        pr = self.physical_router
        vn_list = []
        # get all logical router connected networks
        for lr_id in pr.logical_routers or []:
            lr = LogicalRouterDM.get(lr_id)
            if not lr:
                continue
            vn_list += lr.get_connected_networks(include_internal=True)
            if lr.data_center_interconnect:
                dci = DataCenterInterconnectDM.get(lr.data_center_interconnect)
                if dci.virtual_network:
                    vn_list += [dci.virtual_network]

        vn_dict = {}
        for vn_id in vn_list:
            vn_dict[vn_id] = []

        for vn_id in pr.virtual_networks:
            vn_dict[vn_id] = []
            vn = VirtualNetworkDM.get(vn_id)
            if vn and vn.router_external:
                vn_list = vn.get_connected_private_networks()
                for pvn in vn_list or []:
                    vn_dict[pvn] = []

        li_set = pr.logical_interfaces
        for pi_uuid in pr.physical_interfaces:
            pi = PhysicalInterfaceDM.get(pi_uuid)
            if pi is None:
                continue
            li_set |= pi.logical_interfaces
        for li_uuid in li_set:
            li = LogicalInterfaceDM.get(li_uuid)
            if li is None:
                continue
            vmi_id = li.virtual_machine_interface
            vmi = VirtualMachineInterfaceDM.get(vmi_id)
            if vmi is None:
                continue
            vn_id = vmi.virtual_network
            if li.physical_interface:
                pi = PhysicalInterfaceDM.get(li.physical_interface)
                ae_id = pi.get_parent_ae_id()
                if ae_id and li.physical_interface:
                    _, unit = li.name.split('.')
                    ae_name = "ae" + str(ae_id) + "." + unit
                    vn_dict.setdefault(vn_id, []).append(
                        JunosInterface(ae_name, li.li_type, li.vlan_tag))
                    continue
            vn_dict.setdefault(vn_id, []).append(
                JunosInterface(li.name,
                               li.li_type,
                               li.vlan_tag,
                               li_uuid=li.uuid))
        return vn_dict
コード例 #2
0
    def get_vn_li_map(self):
        pr = self.physical_router
        vn_list = []
        # get all logical router connected networks
        for lr_id in pr.logical_routers or []:
            lr = LogicalRouterDM.get(lr_id)
            if not lr:
                continue
            vn_list += lr.get_connected_networks(include_internal=True)
            if lr.data_center_interconnect:
                dci = DataCenterInterconnectDM.get(lr.data_center_interconnect)
                if dci.virtual_network:
                    vn_list += [dci.virtual_network]

        vn_dict = {}
        for vn_id in vn_list:
            vn_dict[vn_id] = []

        for vn_id in pr.virtual_networks:
            vn_dict[vn_id] = []
            vn = VirtualNetworkDM.get(vn_id)
            if vn and vn.router_external:
                vn_list = vn.get_connected_private_networks()
                for pvn in vn_list or []:
                    vn_dict[pvn] = []

        for lag_uuid in pr.virtual_port_groups or []:
            lag_obj = VirtualPortGroupDM.get(lag_uuid)
            if not lag_obj:
                continue
            ae_id = lag_obj.ae_id
            lag_interfaces = lag_obj.physical_interfaces
            for vmi_uuid in lag_obj.virtual_machine_interfaces:
                vmi_obj = VirtualMachineInterfaceDM.get(vmi_uuid)
                if not vmi_obj:
                    continue
                vn_id = vmi_obj.virtual_network or None
                vlan_tag = vmi_obj.vlan_tag
                if vn_id:
                    for pi_uuid in lag_interfaces:
                        if pi_uuid in pr.physical_interfaces:
                            if ae_id and vlan_tag is not None:
                                ae_name = "ae" + str(ae_id) + "." + str(
                                    vlan_tag)
                                vn_dict.setdefault(vn_id, []).append(
                                    JunosInterface(ae_name, 'l2', vlan_tag))
                                break
        return vn_dict
コード例 #3
0
    def build_ri_config(self):
        vn_dict = self.get_vn_li_map()
        vn_irb_ip_map = None
        if self.is_gateway():
            self.physical_router.evaluate_vn_irb_ip_map(
                set(vn_dict.keys()), 'l2_l3', 'irb', False)
            self.physical_router.evaluate_vn_irb_ip_map(
                set(vn_dict.keys()), 'l3', 'lo0', True)
            vn_irb_ip_map = self.physical_router.get_vn_irb_ip_map()

        for vn_id, interfaces in self.get_sorted_key_value_pairs(vn_dict):
            vn_obj = VirtualNetworkDM.get(vn_id)
            if (vn_obj is None or vn_obj.get_vxlan_vni() is None
                    or vn_obj.vn_network_id is None):
                continue

            export_set = None
            import_set = None
            for ri_id in vn_obj.routing_instances:
                # Find the primary RI by matching the name
                ri_obj = RoutingInstanceDM.get(ri_id)
                if ri_obj is None:
                    continue
                if ri_obj.fq_name[-1] == vn_obj.fq_name[-1]:
                    vrf_name_l2 = DMUtils.make_vrf_name(
                        vn_obj.fq_name[-1], vn_obj.vn_network_id, 'l2')
                    vrf_name_l3 = DMUtils.make_vrf_name(
                        vn_obj.fq_name[-1], vn_obj.vn_network_id, 'l3')
                    if vn_obj.route_targets:
                        export_set = vn_obj.route_targets & ri_obj.export_targets
                        import_set = vn_obj.route_targets & ri_obj.import_targets
                    else:
                        export_set = copy.copy(ri_obj.export_targets)
                        import_set = copy.copy(ri_obj.import_targets)
                    for ri2_id in ri_obj.routing_instances:
                        ri2 = RoutingInstanceDM.get(ri2_id)
                        if ri2 is None:
                            continue
                        import_set |= ri2.export_targets

                    if vn_obj.get_forwarding_mode() in ['l2', 'l2_l3']:
                        irb_ips = None
                        if vn_obj.get_forwarding_mode(
                        ) == 'l2_l3' and self.is_gateway():
                            irb_ips = vn_irb_ip_map['irb'].get(vn_id, [])

                        ri_conf = {
                            'ri_name':
                            vrf_name_l2,
                            'vn':
                            vn_obj,
                            'is_l2':
                            True,
                            'is_l2_l3':
                            (vn_obj.get_forwarding_mode() == 'l2_l3'),
                            'import_targets':
                            import_set,
                            'export_targets':
                            export_set,
                            'prefixes':
                            vn_obj.get_prefixes(),
                            'gateways':
                            irb_ips,
                            'router_external':
                            vn_obj.router_external,
                            'interfaces':
                            interfaces,
                            'vni':
                            vn_obj.get_vxlan_vni(),
                            'network_id':
                            vn_obj.vn_network_id,
                            'encapsulation_priorities':
                            GlobalVRouterConfigDM.
                            global_encapsulation_priorities
                        }
                        self.add_routing_instance(ri_conf)

                    if vn_obj.get_forwarding_mode() in ['l3', 'l2_l3']:
                        interfaces = []
                        lo0_ips = None
                        if vn_obj.get_forwarding_mode() == 'l2_l3':
                            interfaces = [
                                JunosInterface(
                                    'irb.' + str(vn_obj.vn_network_id), 'l3',
                                    0)
                            ]
                        elif self.is_gateway():
                            lo0_ips = vn_irb_ip_map['lo0'].get(vn_id, [])
                        is_internal_vn = True if '_contrail_lr_internal_vn_' in vn_obj.name else False
                        is_dci_vn = True if '_contrail_dci_internal_vn_' in vn_obj.name else False
                        ri_conf = {
                            'ri_name': vrf_name_l3,
                            'vn': vn_obj,
                            'is_l2': False,
                            'is_l2_l3':
                            vn_obj.get_forwarding_mode() == 'l2_l3',
                            'import_targets': import_set,
                            'export_targets': export_set,
                            'prefixes': vn_obj.get_prefixes(),
                            'router_external': vn_obj.router_external,
                            'interfaces': interfaces,
                            'gateways': lo0_ips,
                            'network_id': vn_obj.vn_network_id
                        }
                        if is_dci_vn:
                            ri_conf["prefixes"] = vn_obj.get_prefixes(
                                self.physical_router.uuid)
                            ri_conf['vni'] = vn_obj.get_vxlan_vni(
                                is_dci_vn=is_dci_vn)
                            ri_conf['is_dci_network'] = True
                        elif is_internal_vn:
                            ri_conf['vni'] = vn_obj.get_vxlan_vni(
                                is_internal_vn=is_internal_vn)
                            lr_uuid = DMUtils.extract_lr_uuid_from_internal_vn_name(
                                vrf_name_l3)
                            lr = LogicalRouterDM.get(lr_uuid)
                            if lr:
                                ri_conf[
                                    'router_external'] = lr.logical_router_gateway_external
                            if lr.data_center_interconnect:
                                ri_conf[
                                    'connected_dci_network'] = lr.data_center_interconnect
                        self.add_routing_instance(ri_conf)
                    break

            if export_set and\
                    self.physical_router.is_junos_service_ports_enabled() and\
                    len(vn_obj.instance_ip_map) > 0:
                service_port_ids = DMUtils.get_service_ports(
                    vn_obj.vn_network_id)
                if not self.physical_router \
                        .is_service_port_id_valid(service_port_ids[0]):
                    self._logger.error("DM can't allocate service interfaces"
                                       " for (vn, vn-id)=(%s,%s)" %
                                       (vn_obj.fq_name, vn_obj.vn_network_id))
                else:
                    vrf_name = DMUtils.make_vrf_name(vn_obj.fq_name[-1],
                                                     vn_obj.vn_network_id,
                                                     'l3', True)
                    interfaces = []
                    service_ports = self.physical_router.junos_service_ports.\
                        get('service_port')
                    interfaces.append(
                        JunosInterface(
                            service_ports[0] + "." + str(service_port_ids[0]),
                            'l3', 0))
                    interfaces.append(
                        JunosInterface(
                            service_ports[0] + "." + str(service_port_ids[1]),
                            'l3', 0))
                    ri_conf = {
                        'ri_name': vrf_name,
                        'vn': vn_obj,
                        'import_targets': import_set,
                        'interfaces': interfaces,
                        'fip_map': vn_obj.instance_ip_map,
                        'network_id': vn_obj.vn_network_id,
                        'restrict_proxy_arp': vn_obj.router_external
                    }
                    self.add_routing_instance(ri_conf)
        return
コード例 #4
0
    def build_ri_config(self):
        if not self.is_spine():
            esi_map = self.get_ae_alloc_esi_map()
            self.physical_router.evaluate_ae_id_map(esi_map)
            self.build_ae_config(esi_map)
        vn_dict = self.get_vn_li_map()
        vn_irb_ip_map = None
        if self.is_spine():
            self.physical_router.evaluate_vn_irb_ip_map(
                set(vn_dict.keys()), 'l2_l3', 'irb', False)
            self.physical_router.evaluate_vn_irb_ip_map(
                set(vn_dict.keys()), 'l3', 'lo0', True)
            vn_irb_ip_map = self.physical_router.get_vn_irb_ip_map()

        for vn_id, interfaces in vn_dict.items():
            vn_obj = VirtualNetworkDM.get(vn_id)
            if (vn_obj is None or vn_obj.get_vxlan_vni() is None
                    or vn_obj.vn_network_id is None):
                continue

            export_set = None
            import_set = None
            for ri_id in vn_obj.routing_instances:
                # Find the primary RI by matching the name
                ri_obj = RoutingInstanceDM.get(ri_id)
                if ri_obj is None:
                    continue
                if ri_obj.fq_name[-1] == vn_obj.fq_name[-1]:
                    vrf_name_l2 = DMUtils.make_vrf_name(
                        vn_obj.fq_name[-1], vn_obj.vn_network_id, 'l2')
                    vrf_name_l3 = DMUtils.make_vrf_name(
                        vn_obj.fq_name[-1], vn_obj.vn_network_id, 'l3')
                    export_set = copy.copy(ri_obj.export_targets)
                    import_set = copy.copy(ri_obj.import_targets)
                    if self.is_spine():
                        for ri2_id in ri_obj.routing_instances:
                            ri2 = RoutingInstanceDM.get(ri2_id)
                            if ri2 is None:
                                continue
                            import_set |= ri2.export_targets

                    if vn_obj.get_forwarding_mode() in ['l2', 'l2_l3']:
                        irb_ips = None
                        if vn_obj.get_forwarding_mode(
                        ) == 'l2_l3' and self.is_spine():
                            irb_ips = vn_irb_ip_map['irb'].get(vn_id, [])

                        ri_conf = {
                            'ri_name':
                            vrf_name_l2,
                            'vn':
                            vn_obj,
                            'is_l2':
                            True,
                            'is_l2_l3':
                            (vn_obj.get_forwarding_mode() == 'l2_l3'),
                            'import_targets':
                            import_set,
                            'prefixes':
                            vn_obj.get_prefixes(),
                            'gateways':
                            irb_ips,
                            'router_external':
                            vn_obj.router_external,
                            'interfaces':
                            interfaces,
                            'vni':
                            vn_obj.get_vxlan_vni(),
                            'network_id':
                            vn_obj.vn_network_id,
                            'highest_encapsulation_priority':
                            GlobalVRouterConfigDM.global_encapsulation_priority
                        }
                        if self.is_spine():
                            ri_conf['export_targets'] = export_set
                        self.add_routing_instance(ri_conf)

                    if vn_obj.get_forwarding_mode() in ['l3', 'l2_l3']:
                        interfaces = []
                        lo0_ips = None
                        if vn_obj.get_forwarding_mode() == 'l2_l3':
                            interfaces = [
                                JunosInterface(
                                    'irb.' + str(vn_obj.vn_network_id), 'l3',
                                    0)
                            ]
                        elif self.is_spine():
                            lo0_ips = vn_irb_ip_map['lo0'].get(vn_id, [])
                        ri_conf = {
                            'ri_name': vrf_name_l3,
                            'vn': vn_obj,
                            'is_l2': False,
                            'is_l2_l3':
                            vn_obj.get_forwarding_mode() == 'l2_l3',
                            'import_targets': import_set,
                            'export_targets': export_set,
                            'prefixes': vn_obj.get_prefixes(),
                            'router_external': vn_obj.router_external,
                            'interfaces': interfaces,
                            'gateways': lo0_ips,
                            'network_id': vn_obj.vn_network_id
                        }
                        self.add_routing_instance(ri_conf)
                    break

            if export_set and\
                    self.physical_router.is_junos_service_ports_enabled() and\
                    len(vn_obj.instance_ip_map) > 0:
                service_port_ids = DMUtils.get_service_ports(
                    vn_obj.vn_network_id)
                if not self.physical_router \
                        .is_service_port_id_valid(service_port_ids[0]):
                    self._logger.error("DM can't allocate service interfaces"
                                       " for (vn, vn-id)=(%s,%s)" %
                                       (vn_obj.fq_name, vn_obj.vn_network_id))
                else:
                    vrf_name = DMUtils.make_vrf_name(vn_obj.fq_name[-1],
                                                     vn_obj.vn_network_id,
                                                     'l3', True)
                    interfaces = []
                    service_ports = self.physical_router.junos_service_ports.\
                        get('service_port')
                    interfaces.append(
                        JunosInterface(
                            service_ports[0] + "." + str(service_port_ids[0]),
                            'l3', 0))
                    interfaces.append(
                        JunosInterface(
                            service_ports[0] + "." + str(service_port_ids[1]),
                            'l3', 0))
                    ri_conf = {
                        'ri_name': vrf_name,
                        'vn': vn_obj,
                        'import_targets': import_set,
                        'interfaces': interfaces,
                        'fip_map': vn_obj.instance_ip_map,
                        'network_id': vn_obj.vn_network_id,
                        'restrict_proxy_arp': vn_obj.router_external
                    }
                    self.add_routing_instance(ri_conf)
        return