Search in sources :

Example 11 with VpnMap

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

the class NeutronvpnManager method associateRouter.

/**
 * It handles the invocations to the neutronvpn:associateRouter RPC method.
 */
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public Future<RpcResult<Void>> associateRouter(AssociateRouterInput input) {
    SettableFuture<RpcResult<Void>> result = SettableFuture.create();
    LOG.debug("associateRouter {}", input);
    StringBuilder returnMsg = new StringBuilder();
    Uuid vpnId = input.getVpnId();
    Uuid routerId = input.getRouterId();
    try {
        VpnMap vpnMap = neutronvpnUtils.getVpnMap(vpnId);
        Router rtr = neutronvpnUtils.getNeutronRouter(routerId);
        if (vpnMap != null) {
            if (rtr != null) {
                Uuid extVpnId = neutronvpnUtils.getVpnForRouter(routerId, true);
                if (vpnMap.getRouterId() != null) {
                    returnMsg.append("vpn ").append(vpnId.getValue()).append(" already associated to router ").append(vpnMap.getRouterId().getValue());
                } else if (extVpnId != null) {
                    returnMsg.append("router ").append(routerId.getValue()).append(" already associated to " + "another VPN ").append(extVpnId.getValue());
                } else {
                    associateRouterToVpn(vpnId, routerId);
                }
            } else {
                returnMsg.append("router not found : ").append(routerId.getValue());
            }
        } else {
            returnMsg.append("VPN not found : ").append(vpnId.getValue());
        }
        if (returnMsg.length() != 0) {
            result.set(RpcResultBuilder.<Void>failed().withWarning(ErrorType.PROTOCOL, "invalid-value", formatAndLog(LOG::error, "associate router to vpn {} failed due to {}", routerId.getValue(), returnMsg)).build());
        } else {
            result.set(RpcResultBuilder.<Void>success().build());
        }
    } catch (Exception ex) {
        result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::error, "associate router {} to vpn {} failed due to {}", routerId.getValue(), vpnId.getValue(), ex.getMessage(), ex)).build());
    }
    LOG.debug("associateRouter returns..");
    return result;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Router(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ExecutionException(java.util.concurrent.ExecutionException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)

Example 12 with VpnMap

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

the class NeutronvpnManager method removeSubnetFromVpn.

protected void removeSubnetFromVpn(final Uuid vpnId, Uuid subnet, Uuid internetVpnId) {
    Preconditions.checkArgument(vpnId != null || internetVpnId != null, "removeSubnetFromVpn: at least one VPN must be not null");
    LOG.debug("Removing subnet {} from vpn {}/{}", subnet.getValue(), vpnId, internetVpnId);
    Subnetmap sn = neutronvpnUtils.getSubnetmap(subnet);
    if (sn == null) {
        LOG.error("removeSubnetFromVpn: Subnetmap for subnet {} not found", subnet.getValue());
        return;
    }
    VpnMap vpnMap = null;
    VpnInstance vpnInstance = null;
    if (vpnId != null) {
        vpnMap = neutronvpnUtils.getVpnMap(vpnId);
        if (vpnMap == null) {
            LOG.error("No vpnMap for vpnId {}, cannot remove subnet {} from VPN", vpnId.getValue(), subnet.getValue());
            return;
        }
        vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpnId.getValue());
    }
    if (internetVpnId == null) {
        internetVpnId = sn.getInternetVpnId();
    }
    if (internetVpnId != null) {
        vpnMap = neutronvpnUtils.getVpnMap(internetVpnId);
        if (vpnMap == null) {
            LOG.error("No vpnMap for vpnId {}, cannot remove subnet {}" + " from Internet VPN", internetVpnId.getValue(), subnet.getValue());
            return;
        }
    }
    if (vpnInstance != null && isVpnOfTypeL2(vpnInstance)) {
        neutronEvpnUtils.updateElanAndVpn(vpnInstance, sn.getNetworkId().getValue(), NeutronEvpnUtils.Operation.DELETE);
    }
    boolean subnetVpnAssociation = false;
    if (vpnId != null && sn.getVpnId() != null && sn.getVpnId().getValue().equals(vpnId.getValue())) {
        subnetVpnAssociation = true;
    } else if (internetVpnId != null && sn.getInternetVpnId() != null && sn.getInternetVpnId().getValue().matches(internetVpnId.getValue())) {
        subnetVpnAssociation = true;
    }
    if (subnetVpnAssociation == false) {
        LOG.error("Removing subnet : Subnetmap is not in VPN {}/{}, owns {} and {}", vpnId, internetVpnId, sn.getVpnId(), sn.getInternetVpnId());
        return;
    }
    // Check if there are ports on this subnet; remove corresponding vpn-interfaces
    List<Uuid> portList = sn.getPortList();
    final Uuid internetId = internetVpnId;
    if (portList != null) {
        for (final Uuid portId : portList) {
            LOG.debug("withdrawing subnet IP {} from vpn-interface {}", sn.getSubnetIp(), portId.getValue());
            final Port port = neutronvpnUtils.getNeutronPort(portId);
            jobCoordinator.enqueueJob("PORT-" + portId.getValue(), () -> {
                WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
                List<ListenableFuture<Void>> futures = new ArrayList<>();
                if (port != null) {
                    withdrawPortIpFromVpnIface(vpnId, internetId, port, sn, wrtConfigTxn);
                } else {
                    LOG.warn("Cannot proceed with withdrawPortIpFromVpnIface for port {} in subnet {} since " + "port is absent in Neutron config DS", portId.getValue(), subnet.getValue());
                }
                futures.add(wrtConfigTxn.submit());
                return futures;
            });
        }
    }
    // update subnet-vpn association
    removeFromSubnetNode(subnet, null, null, vpnId, null);
}
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) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) VpnInstance(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance) 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) ArrayList(java.util.ArrayList) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) ListenableFuture(com.google.common.util.concurrent.ListenableFuture)

Example 13 with VpnMap

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

the class NeutronvpnUtils method getRouterforVpn.

protected Uuid getRouterforVpn(Uuid vpnId) {
    InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(vpnId)).build();
    Optional<VpnMap> optionalVpnMap = read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
    if (optionalVpnMap.isPresent()) {
        VpnMap vpnMap = optionalVpnMap.get();
        return vpnMap.getRouterId();
    }
    LOG.error("getRouterforVpn: Failed as VPNMaps DS is absent for VPN {}", vpnId.getValue());
    return null;
}
Also used : VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) VpnMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMapKey)

Example 14 with VpnMap

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

the class NeutronvpnUtils method getRouterIdfromVpnInstance.

public String getRouterIdfromVpnInstance(String vpnName) {
    // returns only router, attached to IPv4 networks
    InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(new Uuid(vpnName))).build();
    Optional<VpnMap> optionalVpnMap = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
    if (!optionalVpnMap.isPresent()) {
        LOG.error("getRouterIdfromVpnInstance : Router not found for vpn : {}", vpnName);
        return null;
    }
    Uuid routerId = optionalVpnMap.get().getRouterId();
    if (routerId != null) {
        return routerId.getValue();
    }
    LOG.info("getRouterIdfromVpnInstance : Router not found for vpn : {}", vpnName);
    return null;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) VpnMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMapKey)

Example 15 with VpnMap

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

the class NeutronvpnUtils method getVpnForNetwork.

protected Uuid getVpnForNetwork(Uuid network) {
    InstanceIdentifier<VpnMaps> vpnMapsIdentifier = InstanceIdentifier.builder(VpnMaps.class).build();
    Optional<VpnMaps> optionalVpnMaps = read(LogicalDatastoreType.CONFIGURATION, vpnMapsIdentifier);
    if (optionalVpnMaps.isPresent() && optionalVpnMaps.get().getVpnMap() != null) {
        List<VpnMap> allMaps = optionalVpnMaps.get().getVpnMap();
        for (VpnMap vpnMap : allMaps) {
            List<Uuid> netIds = vpnMap.getNetworkIds();
            if (netIds != null && netIds.contains(network)) {
                return vpnMap.getVpnId();
            }
        }
    }
    LOG.debug("getVpnForNetwork: Failed for network {} as no VPN present in VPNMaps DS", network.getValue());
    return null;
}
Also used : VpnMaps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.VpnMaps) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap)

Aggregations

VpnMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap)15 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)11 VpnMapKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMapKey)8 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)5 VpnInstance (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance)4 ArrayList (java.util.ArrayList)3 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)3 VpnMaps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.VpnMaps)3 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)3 VpnTarget (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.vpntargets.VpnTarget)2 LearntVpnVipToPort (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort)2 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)2 VpnMapBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMapBuilder)2 Port (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 HashSet (java.util.HashSet)1 ExecutionException (java.util.concurrent.ExecutionException)1 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)1 VpnInstances (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInstances)1 VpnInstanceKey (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstanceKey)1