Search in sources :

Example 81 with Config

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.afi.safi.graceful.restart.Config in project netvirt by opendaylight.

the class NeutronvpnManager method addSubnetToVpn.

protected void addSubnetToVpn(@Nullable final Uuid vpnId, Uuid subnet, @Nullable final Uuid internetVpnId) {
    LOG.debug("addSubnetToVpn: Adding subnet {} to vpn {}", subnet.getValue(), vpnId != null ? vpnId.getValue() : internetVpnId.getValue());
    Subnetmap sn = updateSubnetNode(subnet, null, vpnId, internetVpnId);
    if (sn == null) {
        LOG.error("addSubnetToVpn: subnetmap is null, cannot add subnet {} to VPN {}", subnet.getValue(), vpnId != null ? vpnId.getValue() : internetVpnId.getValue());
        return;
    }
    if (vpnId != null) {
        VpnMap vpnMap = neutronvpnUtils.getVpnMap(vpnId);
        if (vpnMap == null) {
            LOG.error("addSubnetToVpn: No vpnMap for vpnId {}," + " cannot add subnet {} to VPN", vpnId.getValue(), subnet.getValue());
            return;
        }
        final VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpnId.getValue());
        LOG.debug("addSubnetToVpn: VpnInstance {}", vpnInstance);
        if (isVpnOfTypeL2(vpnInstance)) {
            neutronEvpnUtils.updateElanAndVpn(vpnInstance, sn.getNetworkId().getValue(), NeutronEvpnUtils.Operation.ADD);
        }
    }
    if (internetVpnId != null) {
        VpnMap vpnMap = neutronvpnUtils.getVpnMap(internetVpnId);
        if (vpnMap == null) {
            LOG.error("addSubnetToVpn: No vpnMap for InternetVpnId {}, cannot add " + "subnet {} to VPN", internetVpnId.getValue(), subnet.getValue());
            return;
        }
    }
    final Uuid internetId = internetVpnId;
    // Check if there are ports on this subnet and add corresponding vpn-interfaces
    List<Uuid> portList = sn.getPortList();
    if (portList != null) {
        for (final Uuid portId : portList) {
            String vpnInfName = portId.getValue();
            VpnInterface vpnIface = VpnHelper.getVpnInterface(dataBroker, vpnInfName);
            Port port = neutronvpnUtils.getNeutronPort(portId);
            if (port == null) {
                LOG.error("addSubnetToVpn: Cannot proceed with addSubnetToVpn for port {} in subnet {} " + "since port is absent in Neutron config DS", portId.getValue(), subnet.getValue());
                continue;
            }
            final Boolean isRouterInterface = port.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF) ? true : false;
            jobCoordinator.enqueueJob("PORT-" + portId.getValue(), () -> {
                ListenableFuture<?> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, wrtConfigTxn -> {
                    Adjacencies portAdj = createPortIpAdjacencies(port, isRouterInterface, wrtConfigTxn, vpnIface);
                    if (vpnIface == null) {
                        LOG.trace("addSubnetToVpn: create new VpnInterface for Port {}", vpnInfName);
                        Set<Uuid> listVpn = new HashSet<>();
                        if (vpnId != null) {
                            listVpn.add(vpnId);
                        }
                        if (internetId != null) {
                            listVpn.add(internetId);
                        }
                        writeVpnInterfaceToDs(listVpn, vpnInfName, portAdj, port.getNetworkId(), isRouterInterface, wrtConfigTxn);
                        if (sn.getRouterId() != null) {
                            addToNeutronRouterInterfacesMap(sn.getRouterId(), portId.getValue());
                        }
                    } else {
                        LOG.trace("update VpnInterface for Port {} with adj {}", vpnInfName, portAdj);
                        if (vpnId != null) {
                            updateVpnInterfaceWithAdjacencies(vpnId, vpnInfName, portAdj, wrtConfigTxn);
                        }
                        if (internetId != null) {
                            updateVpnInterfaceWithAdjacencies(internetId, vpnInfName, portAdj, wrtConfigTxn);
                        }
                    }
                });
                LoggingFutures.addErrorLogging(future, LOG, "addSubnetToVpn: Failed while creating VPN interface for vpnId {}, portId {}" + "{}, subnetId {}", vpnId.getValue(), portId, subnet.getValue());
                return Collections.singletonList(future);
            });
        }
    }
}
Also used : VpnInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance) VpnPortipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPort) LearntVpnVipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) Adjacencies(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.Adjacencies) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) HashSet(java.util.HashSet)

Example 82 with Config

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.afi.safi.graceful.restart.Config in project netvirt by opendaylight.

the class NeutronvpnManager method createPortIpAdjacencies.

protected Adjacencies createPortIpAdjacencies(Port port, Boolean isRouterInterface, TypedWriteTransaction<Configuration> wrtConfigTxn, @Nullable VpnInterface vpnIface) {
    List<Adjacency> adjList = new ArrayList<>();
    if (vpnIface != null) {
        adjList = new ArrayList<>(vpnIface.augmentation(Adjacencies.class).getAdjacency().values());
    }
    String infName = port.getUuid().getValue();
    LOG.trace("neutronVpnManager: create config adjacencies for Port: {}", infName);
    for (FixedIps ip : port.nonnullFixedIps().values()) {
        String ipValue = ip.getIpAddress().stringValue();
        String ipPrefix = ip.getIpAddress().getIpv4Address() != null ? ipValue + "/32" : ipValue + "/128";
        Subnetmap snTemp = neutronvpnUtils.getSubnetmap(ip.getSubnetId());
        if (snTemp != null && !FibHelper.doesPrefixBelongToSubnet(ipPrefix, snTemp.getSubnetIp(), false)) {
            continue;
        }
        Uuid vpnId = snTemp != null ? snTemp.getVpnId() : null;
        if (vpnId != null) {
            neutronvpnUtils.createVpnPortFixedIpToPort(vpnId.getValue(), ipValue, infName, port.getMacAddress().getValue(), isRouterInterface, wrtConfigTxn);
            // Create Neutron port adjacency if VPN presence is existing for subnet
            Adjacency vmAdj = new AdjacencyBuilder().withKey(new AdjacencyKey(ipPrefix)).setIpAddress(ipPrefix).setMacAddress(port.getMacAddress().getValue()).setAdjacencyType(AdjacencyType.PrimaryAdjacency).setSubnetId(ip.getSubnetId()).build();
            if (!adjList.contains(vmAdj)) {
                adjList.add(vmAdj);
            }
        }
        Uuid routerId = snTemp != null ? snTemp.getRouterId() : null;
        if (snTemp != null && snTemp.getInternetVpnId() != null) {
            neutronvpnUtils.createVpnPortFixedIpToPort(snTemp.getInternetVpnId().getValue(), ipValue, infName, port.getMacAddress().getValue(), isRouterInterface, wrtConfigTxn);
        }
        if (routerId != null) {
            Router rtr = neutronvpnUtils.getNeutronRouter(routerId);
            if (rtr != null && rtr.getRoutes() != null) {
                List<Routes> routeList = new ArrayList<>(rtr.getRoutes().values());
                // create extraroute Adjacence for each ipValue,
                // because router can have IPv4 and IPv6 subnet ports, or can have
                // more that one IPv4 subnet port or more than one IPv6 subnet port
                List<Adjacency> erAdjList = getAdjacencyforExtraRoute(routeList, ipValue);
                if (!erAdjList.isEmpty()) {
                    adjList.addAll(erAdjList);
                }
            }
        }
    }
    return new AdjacenciesBuilder().setAdjacency(getAdjacencyMap(adjList)).build();
}
Also used : AdjacencyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyBuilder) AdjacencyKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyKey) ArrayList(java.util.ArrayList) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) Router(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) AdjacenciesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.AdjacenciesBuilder) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps)

Example 83 with Config

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.afi.safi.graceful.restart.Config in project netvirt by opendaylight.

the class NeutronPortChangeListener method handleNeutronPortCreated.

private void handleNeutronPortCreated(final Port port) {
    final String portName = port.getUuid().getValue();
    final Uuid portId = port.getUuid();
    final String networkId = port.getNetworkId().getValue();
    final Map<FixedIpsKey, FixedIps> keyFixedIpsMap = port.nonnullFixedIps();
    if (NeutronConstants.IS_ODL_DHCP_PORT.test(port)) {
        return;
    }
    if (!NeutronUtils.isPortVnicTypeNormal(port) && (!isPortTypeSwitchdev(port) || !isSupportedVnicTypeByHost(port, NeutronConstants.VNIC_TYPE_DIRECT))) {
        for (FixedIps ip : keyFixedIpsMap.values()) {
            nvpnManager.updateSubnetmapNodeWithPorts(ip.getSubnetId(), null, portId);
        }
        LOG.info("Port {} is not a normal and not a direct with switchdev VNIC type ;" + "OF Port interfaces are not created", portName);
        return;
    }
    jobCoordinator.enqueueJob("PORT- " + portName, () -> {
        // add direct port to subnetMaps config DS
        // TODO: for direct port as well, operations should be carried out per subnet based on port IP
        ListenableFuture<?> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
            LOG.info("Of-port-interface creation for port {}", portName);
            // Create of-port interface for this neutron port
            String portInterfaceName = createOfPortInterface(port, tx);
            LOG.debug("Creating ELAN Interface for port {}", portName);
            createElanInterface(port, portInterfaceName, tx);
            Set<Uuid> vpnIdList = new HashSet<>();
            Set<Uuid> routerIds = new HashSet<>();
            for (FixedIps ip : keyFixedIpsMap.values()) {
                Subnetmap subnetMap = nvpnManager.updateSubnetmapNodeWithPorts(ip.getSubnetId(), portId, null);
                if (subnetMap != null && subnetMap.getInternetVpnId() != null) {
                    if (!vpnIdList.contains(subnetMap.getInternetVpnId())) {
                        vpnIdList.add(subnetMap.getInternetVpnId());
                    }
                }
                if (subnetMap != null && subnetMap.getVpnId() != null) {
                    // can't use NeutronvpnUtils.getVpnForNetwork to optimise here, because it gives BGPVPN id
                    // obtained subnetMaps belongs to one network => vpnId must be the same for each port Ip
                    Uuid vpnId = subnetMap.getVpnId();
                    if (vpnId != null) {
                        vpnIdList.add(vpnId);
                    }
                }
                if (subnetMap != null && subnetMap.getRouterId() != null) {
                    routerIds.add(subnetMap.getRouterId());
                }
            }
            if (!vpnIdList.isEmpty()) {
                // create new vpn-interface for neutron port
                LOG.debug("handleNeutronPortCreated: Adding VPN Interface for port {} from network {}", portName, networkId);
                nvpnManager.createVpnInterface(vpnIdList, port, tx);
                for (Uuid routerId : routerIds) {
                    nvpnManager.addToNeutronRouterInterfacesMap(routerId, port.getUuid().getValue());
                }
            }
        });
        LoggingFutures.addErrorLogging(future, LOG, "handleNeutronPortCreated: Failed for port {} with networkId {}", portName, networkId);
        return Collections.singletonList(future);
    });
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) FixedIpsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIpsKey) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps) HashSet(java.util.HashSet)

Example 84 with Config

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.afi.safi.graceful.restart.Config in project netvirt by opendaylight.

the class NeutronPortChangeListener method addToFloatingIpPortInfo.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void addToFloatingIpPortInfo(Uuid floatingIpId, Uuid floatingIpPortId, Uuid floatingIpPortSubnetId, String floatingIpPortMacAddress) {
    InstanceIdentifier id = NeutronvpnUtils.buildfloatingIpIdToPortMappingIdentifier(floatingIpId);
    try {
        FloatingIpIdToPortMappingBuilder floatingipIdToPortMacMappingBuilder = new FloatingIpIdToPortMappingBuilder().withKey(new FloatingIpIdToPortMappingKey(floatingIpId)).setFloatingIpId(floatingIpId).setFloatingIpPortId(floatingIpPortId).setFloatingIpPortSubnetId(floatingIpPortSubnetId).setFloatingIpPortMacAddress(floatingIpPortMacAddress);
        LOG.debug("Creating floating IP UUID {} to Floating IP neutron port {} mapping in Floating IP" + " Port Info Config DS", floatingIpId.getValue(), floatingIpPortId.getValue());
        MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, floatingipIdToPortMacMappingBuilder.build());
    } catch (Exception e) {
        LOG.error("Creating floating IP UUID {} to Floating IP neutron port {} mapping in Floating IP" + " Port Info Config DS failed", floatingIpId.getValue(), floatingIpPortId.getValue(), e);
    }
}
Also used : FloatingIpIdToPortMappingBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.port.info.FloatingIpIdToPortMappingBuilder) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) FloatingIpIdToPortMappingKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.port.info.FloatingIpIdToPortMappingKey) ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) ExecutionException(java.util.concurrent.ExecutionException)

Example 85 with Config

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.afi.safi.graceful.restart.Config in project netvirt by opendaylight.

the class NeutronHostConfigChangeListener method extractHostConfig.

private Map<String, String> extractHostConfig(Node node) {
    Map<String, String> config = new HashMap<>();
    OvsdbNodeAugmentation ovsdbNode = getOvsdbNodeAugmentation(node);
    if (ovsdbNode != null && ovsdbNode.getOpenvswitchExternalIds() != null) {
        for (OpenvswitchExternalIds openvswitchExternalIds : ovsdbNode.getOpenvswitchExternalIds().values()) {
            if (openvswitchExternalIds.getExternalIdKey() != null && openvswitchExternalIds.getExternalIdKey().startsWith(OS_HOST_CONFIG_CONFIG_KEY_PREFIX)) {
                // Extract the host type. Max 8 characters after
                // suffix OS_HOST_CONFIG_CONFIG_KEY_PREFIX.length()
                String hostType = openvswitchExternalIds.getExternalIdKey().substring(OS_HOST_CONFIG_CONFIG_KEY_PREFIX.length());
                if (hostType.length() > 0) {
                    if (hostType.length() > HOST_TYPE_STR_LEN) {
                        hostType = hostType.substring(0, HOST_TYPE_STR_LEN);
                    }
                    hostType = "ODL " + hostType.toUpperCase(Locale.getDefault());
                    if (null != openvswitchExternalIds.getExternalIdValue()) {
                        config.put(hostType, openvswitchExternalIds.getExternalIdValue());
                    }
                }
            }
        }
    }
    return config;
}
Also used : OpenvswitchExternalIds(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchExternalIds) HashMap(java.util.HashMap) OvsdbNodeAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation)

Aggregations

ArrayList (java.util.ArrayList)61 ExecutionException (java.util.concurrent.ExecutionException)47 Test (org.junit.Test)46 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)34 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)29 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)26 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)26 BigInteger (java.math.BigInteger)25 Logger (org.slf4j.Logger)25 LoggerFactory (org.slf4j.LoggerFactory)25 List (java.util.List)24 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)24 ByteBuf (io.netty.buffer.ByteBuf)21 Interface (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface)21 Collections (java.util.Collections)20 Map (java.util.Map)18 Singleton (javax.inject.Singleton)18 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)18 Inject (javax.inject.Inject)17 DataBroker (org.opendaylight.mdsal.binding.api.DataBroker)17