Search in sources :

Example 56 with Subnetmap

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.

the class NeutronvpnUtils method getNeutronRouterSubnetMaps.

/**
 *This method return the list of Subnetmap associated to the router or a empty list if any.
 * @param routerId the Uuid of router for which subnetmap is find out
 * @return a list of Subnetmap associated to the router. it could be empty if any
 */
protected List<Subnetmap> getNeutronRouterSubnetMaps(Uuid routerId) {
    List<Subnetmap> subnetIdList = new ArrayList<>();
    Optional<Subnetmaps> subnetMaps = read(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(Subnetmaps.class).build());
    if (subnetMaps.isPresent() && subnetMaps.get().getSubnetmap() != null) {
        for (Subnetmap subnetmap : subnetMaps.get().getSubnetmap()) {
            if (routerId.equals(subnetmap.getRouterId())) {
                subnetIdList.add(subnetmap);
            }
        }
    }
    return subnetIdList;
}
Also used : Subnetmaps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps) ArrayList(java.util.ArrayList) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)

Example 57 with Subnetmap

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.

the class NeutronvpnUtils method getInternetvpnUuidBoundToSubnetRouter.

/**
 * This method get Uuid of internet vpn if existing one bound to the same router of the subnetUuid arg.
 * Explanation: If the subnet (of arg subnetUuid) have a router bound and this router have an
 * externalVpn (vpn on externalProvider network) then <b>its Uuid</b> will be returned.
 * @param subnetUuid Uuid of subnet where you are finding a link to an external network
 * @return Uuid of externalVpn or null if it is not found
 */
public Uuid getInternetvpnUuidBoundToSubnetRouter(@Nonnull Uuid subnetUuid) {
    Subnetmap subnetmap = getSubnetmap(subnetUuid);
    Uuid routerUuid = subnetmap.getRouterId();
    LOG.debug("getInternetvpnUuidBoundToSubnetRouter for subnetUuid {}", subnetUuid.getValue());
    if (routerUuid == null) {
        return null;
    }
    Uuid externalNetworkUuid = getExternalNetworkUuidAttachedFromRouterUuid(routerUuid);
    return externalNetworkUuid != null ? getVpnForNetwork(externalNetworkUuid) : null;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)

Example 58 with Subnetmap

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.

the class NeutronvpnUtils method getSubnetsforVpn.

protected List<Uuid> getSubnetsforVpn(Uuid vpnid) {
    List<Uuid> subnets = new ArrayList<>();
    // read subnetmaps
    InstanceIdentifier<Subnetmaps> subnetmapsid = InstanceIdentifier.builder(Subnetmaps.class).build();
    Optional<Subnetmaps> subnetmaps = read(LogicalDatastoreType.CONFIGURATION, subnetmapsid);
    if (subnetmaps.isPresent() && subnetmaps.get().getSubnetmap() != null) {
        List<Subnetmap> subnetMapList = subnetmaps.get().getSubnetmap();
        for (Subnetmap candidateSubnetMap : subnetMapList) {
            if (candidateSubnetMap.getVpnId() != null && candidateSubnetMap.getVpnId().equals(vpnid)) {
                subnets.add(candidateSubnetMap.getId());
            }
        }
    }
    return subnets;
}
Also used : Subnetmaps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ArrayList(java.util.ArrayList) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)

Example 59 with Subnetmap

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.

the class NeutronvpnUtils method shouldVpnHandleIpVersionChangeToRemove.

public boolean shouldVpnHandleIpVersionChangeToRemove(Subnetmap sm, Uuid vpnId) {
    if (sm == null) {
        return false;
    }
    InstanceIdentifier<Subnetmaps> subnetMapsId = InstanceIdentifier.builder(Subnetmaps.class).build();
    Optional<Subnetmaps> allSubnetMaps = read(LogicalDatastoreType.CONFIGURATION, subnetMapsId);
    // calculate and store in list IpVersion for each subnetMap, belonging to current VpnInstance
    List<IpVersionChoice> snIpVersions = new ArrayList<>();
    for (Subnetmap snMap : allSubnetMaps.get().getSubnetmap()) {
        if (snMap.getId().equals(sm.getId())) {
            continue;
        }
        if (snMap.getVpnId() != null && snMap.getVpnId().equals(vpnId)) {
            snIpVersions.add(getIpVersionFromString(snMap.getSubnetIp()));
        }
        if (snMap.getInternetVpnId() != null && snMap.getInternetVpnId().equals(vpnId)) {
            snIpVersions.add(getIpVersionFromString(snMap.getSubnetIp()));
        }
    }
    IpVersionChoice ipVersion = getIpVersionFromString(sm.getSubnetIp());
    if (!snIpVersions.contains(ipVersion)) {
        return true;
    }
    return false;
}
Also used : Subnetmaps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps) ArrayList(java.util.ArrayList) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)

Example 60 with Subnetmap

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.

the class NeutronPortChangeListener method handleNeutronPortDeleted.

private void handleNeutronPortDeleted(final Port port) {
    final String portName = port.getUuid().getValue();
    final Uuid portId = port.getUuid();
    final List<FixedIps> portIpsList = port.getFixedIps();
    jobCoordinator.enqueueJob("PORT- " + portName, () -> {
        WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
        List<ListenableFuture<Void>> futures = new ArrayList<>();
        if (!(NeutronUtils.isPortVnicTypeNormal(port) || isPortTypeSwitchdev(port))) {
            for (FixedIps ip : portIpsList) {
                // remove direct port from subnetMaps config DS
                nvpnManager.removePortsFromSubnetmapNode(ip.getSubnetId(), null, portId);
            }
            LOG.info("Port {} is not a normal and not a direct with switchdev VNIC type ;" + "Skipping OF Port interfaces removal", portName);
            return futures;
        }
        Uuid vpnId = null;
        Set<Uuid> routerIds = new HashSet<>();
        Uuid internetVpnId = null;
        for (FixedIps ip : portIpsList) {
            Subnetmap subnetMap = nvpnManager.removePortsFromSubnetmapNode(ip.getSubnetId(), portId, null);
            if (subnetMap == null) {
                continue;
            }
            if (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
                vpnId = subnetMap.getVpnId();
            }
            if (subnetMap.getRouterId() != null) {
                routerIds.add(subnetMap.getRouterId());
            }
            internetVpnId = subnetMap.getInternetVpnId();
        }
        if (vpnId != null || internetVpnId != null) {
            // remove vpn-interface for this neutron port
            LOG.debug("removing VPN Interface for port {}", portName);
            if (!routerIds.isEmpty()) {
                for (Uuid routerId : routerIds) {
                    nvpnManager.removeFromNeutronRouterInterfacesMap(routerId, portName);
                }
            }
            nvpnManager.deleteVpnInterface(portName, null, /* vpn-id */
            wrtConfigTxn);
        }
        // Remove of-port interface for this neutron port
        // ELAN interface is also implicitly deleted as part of this operation
        LOG.debug("Of-port-interface removal for port {}", portName);
        deleteOfPortInterface(port, wrtConfigTxn);
        // dissociate fixedIP from floatingIP if associated
        nvpnManager.dissociatefixedIPFromFloatingIP(port.getUuid().getValue());
        futures.add(wrtConfigTxn.submit());
        return futures;
    });
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) 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)

Aggregations

Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)50 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)47 ArrayList (java.util.ArrayList)20 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)15 SubnetmapKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey)12 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)11 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)10 IpVersionChoice (org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)9 Network (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)9 SubnetOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry)8 HashSet (java.util.HashSet)7 SubnetOpDataEntryKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey)7 Subnetmaps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps)7 SubnetmapBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapBuilder)7 FixedIps (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps)7 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 SubnetOpDataEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryBuilder)5 Router (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router)5 BigInteger (java.math.BigInteger)4 HashMap (java.util.HashMap)4