Search in sources :

Example 6 with Subnetmaps

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

the class NeutronvpnUtils method getNeutronRouterSubnetIds.

@Nonnull
protected List<Uuid> getNeutronRouterSubnetIds(Uuid routerId) {
    LOG.debug("getNeutronRouterSubnetIds for {}", routerId.getValue());
    List<Uuid> 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.getId());
            }
        }
    }
    LOG.debug("getNeutronRouterSubnetIds returns {}", subnetIdList);
    return subnetIdList;
}
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) Nonnull(javax.annotation.Nonnull)

Example 7 with Subnetmaps

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps 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 8 with Subnetmaps

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps 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 9 with Subnetmaps

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps 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 10 with Subnetmaps

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps 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)11 ArrayList (java.util.ArrayList)8 Subnetmaps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps)8 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)6 HashMap (java.util.HashMap)3 IpVersionChoice (org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)3 Optional (com.google.common.base.Optional)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)2 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)2 SubnetOpData (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.SubnetOpData)2 SubnetOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry)2 SubnetmapKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey)2 Strings (com.google.common.base.Strings)1 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1