def _build_vn_config(self, feature_config): if self._physical_router.intent_maps: for intent_uuid in self._physical_router.intent_maps or (): imp = IntentMapDM.get(intent_uuid) if imp.intent_type == 'assisted-replicator': for vn_uuid in imp.virtual_networks or []: vn_obj = VirtualNetworkDM.get(vn_uuid) ri_obj = self._get_primary_ri(vn_obj) if ri_obj is None: continue # build route targets ri_name = DMUtils.make_vrf_name( vn_obj.fq_name[-1], vn_obj.vn_network_id, 'l2') export_targets, import_targets = \ self._get_export_import_targets(vn_obj, ri_obj) network_id = vn_obj.vn_network_id vxlan_id = vn_obj.get_vxlan_vni() ri = RoutingInstance( name=ri_name, virtual_network_mode='l2', export_targets=export_targets, import_targets=import_targets, virtual_network_id=str(network_id), vxlan_id=str(vxlan_id)) feature_config.add_routing_instances(ri) # build vlan config vlan = Vlan(name=DMUtils.make_bridge_name( vn_obj.get_vxlan_vni()), vxlan_id=vn_obj.get_vxlan_vni()) vlan.set_comment(DMUtils.vn_bd_comment( vn_obj, 'VXLAN')) desc = "Virtual Network - %s" % vn_obj.name vlan.set_description(desc) feature_config.add_vlans(vlan)
def _build_ri_config(self, vn, ri_name, ri_obj, interfaces, export_targets, import_targets, feature_config): gevent.idle() encapsulation_priorities = self._get_encapsulation_priorities() highest_encapsulation = encapsulation_priorities[0] network_id = vn.vn_network_id vxlan_id = vn.get_vxlan_vni() is_master_vn = False if vn.logical_router is None: # try updating logical router incase of DM restart vn.set_logical_router(vn.fq_name[-1]) lr_uuid = vn.logical_router if lr_uuid: lr = LogicalRouterDM.get(lr_uuid) if lr: if lr.is_master is True: is_master_vn = True ri = RoutingInstance(name=ri_name, virtual_network_mode='l2', export_targets=export_targets, import_targets=import_targets, virtual_network_id=str(network_id), vxlan_id=str(vxlan_id), is_public_network=vn.router_external, is_master=is_master_vn) ri.set_virtual_network_id(str(network_id)) ri.set_vxlan_id(str(vxlan_id)) ri.set_is_public_network(vn.router_external) vlan = None if highest_encapsulation == 'VXLAN': ri.set_routing_instance_type('virtual-switch') vlan = Vlan(name=DMUtils.make_bridge_name(vxlan_id), vxlan_id=vxlan_id) vlan.set_comment(DMUtils.vn_bd_comment(vn, 'VXLAN')) desc = "Virtual Network - %s" % vn.name vlan.set_description(desc) feature_config.add_vlans(vlan) for interface in interfaces: self._add_ref_to_list(vlan.get_interfaces(), interface.li_name) elif highest_encapsulation in ['MPLSoGRE', 'MPLSoUDP']: ri.set_routing_instance_type('evpn') self._build_l2_evpn_interface_config(interfaces, vn, vlan) return ri
def _build_server_config(self, fconfig): pr = self._physical_router if not pr: return pi_tag = [] for pi in pr.physical_interfaces: pi_obj = PhysicalInterfaceDM.get(pi) if not pi_obj: continue if pi_obj.port: port = PortDM.get(pi_obj.port) pi_info = {'pi': pi, 'tag': port.tags, 'pi_obj': pi_obj} pi_tag.append(pi_info) if not pi_tag: return for pi_info in pi_tag: for tag in pi_info.get('tag') or []: tag_obj = TagDM.get(tag) for vn in tag_obj.virtual_networks or []: vn_obj = VirtualNetworkDM.get(vn) for net_ipam in vn_obj.network_ipams or []: net_ipam_obj = NetworkIpamDM.get(net_ipam) for server_info in \ net_ipam_obj.server_discovery_params: dhcp_relay_server = None if server_info.get('dhcp_relay_server'): dhcp_relay_server = server_info.get( 'dhcp_relay_server')[0] vlan_tag = server_info.get('vlan_tag') or 4094 default_gateway = server_info.get( 'default_gateway') + '/' + str( server_info.get('ip_prefix_len')) # create irb interface irb_intf, li_map = self._add_or_lookup_pi( self._pi_map, 'irb', 'irb') irb_intf.set_comment(self.COMMENT_STR) li_name = 'irb.' + str(vlan_tag) irb_intf_unit = self._add_or_lookup_li(li_map, li_name, vlan_tag) self._add_ip_address(irb_intf_unit, default_gateway) # create LI pi_obj = pi_info.get('pi_obj') access_intf, li_map = self._add_or_lookup_pi( self._pi_map, pi_obj.name, 'regular') access_intf.set_comment(self.COMMENT_STR) li_name = pi_obj.fq_name[-1] + '.' + str(0) access_intf_unit = self._add_or_lookup_li(li_map, li_name, 0) access_intf_unit.add_vlans(Vlan( name=tag_obj.name + "_vlan")) access_intf_unit.set_family("ethernet-switching") if vlan_tag == 4094: access_intf_unit.set_is_tagged(False) else: access_intf_unit.set_is_tagged(True) # create Vlan vlan = Vlan(name=tag_obj.name + "_vlan") vlan.set_vlan_id(vlan_tag) vlan.set_comment(self.COMMENT_STR) vlan.set_l3_interface('irb.' + str(vlan_tag)) # Add the vlan to feature config. fconfig.add_vlans(vlan) # set dhcp relay info if dhcp_relay_server: self._forwarding_options_config = \ self._forwarding_options_config or \ ForwardingOptions() dhcp_relay = DhcpRelay() dhcp_relay.set_comment(self.COMMENT_STR) dhcp_relay.set_dhcp_relay_group( "SVR_RELAY_GRP_" + tag_obj.name) ip_address = IpAddress( address=dhcp_relay_server) dhcp_relay.add_dhcp_server_ips(ip_address) self._add_ref_to_list( dhcp_relay.get_interfaces(), 'irb.' + str(vlan_tag)) self._forwarding_options_config.add_dhcp_relay( dhcp_relay)
def build_svc_chaining_irb_bd_config(self, svc_app_obj, left_right_params): left_fq_name = left_right_params["left_qfx_fq_name"] right_fq_name = left_right_params["right_qfx_fq_name"] left_svc_vlan = left_right_params["left_svc_vlan"] right_svc_vlan = left_right_params["right_svc_vlan"] left_svc_unit = left_right_params["left_svc_unit"] right_svc_unit = left_right_params["right_svc_unit"] for pnf_pi, intf_type in list(svc_app_obj.physical_interfaces.items()): pnf_pi_obj = PhysicalInterfaceDM.get(pnf_pi) for spine_pi in pnf_pi_obj.physical_interfaces: if spine_pi not in self._physical_router.physical_interfaces: continue spine_pi_obj = PhysicalInterfaceDM.get(spine_pi) if spine_pi_obj.fq_name == left_fq_name: li_name = spine_pi_obj.name + "." + left_svc_vlan li_fq_name = spine_pi_obj.fq_name + [ li_name.replace(":", "_") ] li_obj = LogicalInterfaceDM.find_by_fq_name(li_fq_name) if li_obj: # irb creation iip_obj = InstanceIpDM.get(li_obj.instance_ip) if iip_obj: irb_addr = iip_obj.instance_ip_address irb_unit = left_svc_unit left_irb_intf, li_map = self._add_or_lookup_pi( self.pi_map_leafspine, "irb", "irb") intf_unit = self._add_or_lookup_li( li_map, "irb." + str(irb_unit), irb_unit) intf_unit.set_comment("PNF-Service-Chaining") self._add_ip_address(intf_unit, irb_addr + "/29") # build BD config left_bd_vlan = Vlan( name=DMUtils.make_bridge_name(left_svc_unit), vxlan_id=left_svc_unit, ) left_bd_vlan.set_vlan_id(left_svc_vlan) left_bd_vlan.set_description( "PNF-Service-Chaining") left_bd_vlan.set_comment("PNF-Service-Chaining") self._add_ref_to_list( left_bd_vlan.get_interfaces(), "irb." + str(irb_unit), ) self.vlan_map[ left_bd_vlan.get_name()] = left_bd_vlan # create logical interfaces for the aggregated # interfaces left_svc_intf, li_map = self._add_or_lookup_pi( self.pi_map_leafspine, spine_pi_obj.name, "service", ) left_svc_intf_unit = self._add_or_lookup_li( li_map, left_fq_name[-1] + ".0", "0") left_svc_intf_unit.set_comment( "PNF-Service-Chaining") left_svc_intf_unit.set_family("ethernet-switching") vlan_left = Vlan(name="bd-" + left_svc_unit) if (vlan_left.get_name() not in self.svc_intf_vlans["vlan_names"]): left_svc_intf_unit.add_vlans(vlan_left) self.svc_intf_vlans["vlan_names"].append( vlan_left.get_name()) if spine_pi_obj.fq_name == right_fq_name: li_name = spine_pi_obj.name + "." + right_svc_vlan li_fq_name = spine_pi_obj.fq_name + [ li_name.replace(":", "_") ] li_obj = LogicalInterfaceDM.find_by_fq_name(li_fq_name) if li_obj: # irb creation iip_obj = InstanceIpDM.get(li_obj.instance_ip) if iip_obj: irb_addr = iip_obj.instance_ip_address irb_unit = right_svc_unit right_irb_intf, li_map = self._add_or_lookup_pi( self.pi_map_leafspine, "irb", "irb") intf_unit = self._add_or_lookup_li( li_map, "irb." + str(irb_unit), irb_unit) intf_unit.set_comment("PNF-Service-Chaining") self._add_ip_address(intf_unit, irb_addr + "/29") # build BD config right_bd_vlan = Vlan( name=DMUtils.make_bridge_name(right_svc_unit), vxlan_id=right_svc_unit, ) right_bd_vlan.set_vlan_id(right_svc_vlan) right_bd_vlan.set_description( "PNF-Service-Chaining") right_bd_vlan.set_comment("PNF-Service-Chaining") self._add_ref_to_list( right_bd_vlan.get_interfaces(), "irb." + str(irb_unit), ) self.vlan_map[ right_bd_vlan.get_name()] = right_bd_vlan # create logical interfaces for the aggregated # interfaces right_svc_intf, li_map = self._add_or_lookup_pi( self.pi_map_leafspine, spine_pi_obj.name, "service", ) right_svc_intf_unit = self._add_or_lookup_li( li_map, right_fq_name[-1] + ".0", "0") right_svc_intf_unit.set_comment( "PNF-Service-Chaining") right_svc_intf_unit.set_family( "ethernet-switching") vlan_right = Vlan(name="bd-" + right_svc_unit) if (vlan_right.get_name() not in self.svc_intf_vlans["vlan_names"]): right_svc_intf_unit.add_vlans(vlan_right) self.svc_intf_vlans["vlan_names"].append( vlan_right.get_name())