Search in sources :

Example 46 with RpcResult

use of org.opendaylight.yangtools.yang.common.RpcResult in project netvirt by opendaylight.

the class NeutronEvpnManager method getEVPN.

public Future<RpcResult<GetEVPNOutput>> getEVPN(GetEVPNInput input) {
    GetEVPNOutputBuilder opBuilder = new GetEVPNOutputBuilder();
    SettableFuture<RpcResult<GetEVPNOutput>> result = SettableFuture.create();
    Uuid inputVpnId = input.getId();
    List<VpnInstance> vpns = new ArrayList<>();
    if (inputVpnId == null) {
        vpns = VpnHelper.getAllVpnInstances(dataBroker);
        if (!vpns.isEmpty()) {
            for (VpnInstance vpn : vpns) {
                if (vpn.getIpv4Family().getRouteDistinguisher() != null && vpn.getType() == VpnInstance.Type.L2) {
                    vpns.add(vpn);
                }
            }
        } else {
            // No VPN present
            result.set(RpcResultBuilder.<GetEVPNOutput>success().withResult(opBuilder.build()).build());
            return result;
        }
    } else {
        String name = inputVpnId.getValue();
        VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, name);
        if (vpnInstance != null && vpnInstance.getIpv4Family().getRouteDistinguisher() != null && vpnInstance.getType() == VpnInstance.Type.L2) {
            vpns.add(vpnInstance);
        } else {
            result.set(RpcResultBuilder.<GetEVPNOutput>failed().withWarning(RpcError.ErrorType.PROTOCOL, "invalid-value", formatAndLog(LOG::error, "GetEVPN failed because VPN {} is not present", name)).build());
        }
    }
    List<EvpnInstances> evpnList = new ArrayList<>();
    for (VpnInstance vpnInstance : vpns) {
        Uuid vpnId = new Uuid(vpnInstance.getVpnInstanceName());
        InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(vpnId)).build();
        EvpnInstancesBuilder evpn = new EvpnInstancesBuilder();
        List<String> rd = vpnInstance.getIpv4Family().getRouteDistinguisher();
        List<VpnTarget> vpnTargetList = vpnInstance.getIpv4Family().getVpnTargets().getVpnTarget();
        List<String> ertList = new ArrayList<>();
        List<String> irtList = new ArrayList<>();
        for (VpnTarget vpnTarget : vpnTargetList) {
            if (vpnTarget.getVrfRTType() == VpnTarget.VrfRTType.ExportExtcommunity) {
                ertList.add(vpnTarget.getVrfRTValue());
            }
            if (vpnTarget.getVrfRTType() == VpnTarget.VrfRTType.ImportExtcommunity) {
                irtList.add(vpnTarget.getVrfRTValue());
            }
            if (vpnTarget.getVrfRTType() == VpnTarget.VrfRTType.Both) {
                ertList.add(vpnTarget.getVrfRTValue());
                irtList.add(vpnTarget.getVrfRTValue());
            }
        }
        evpn.setId(vpnId).setRouteDistinguisher(rd).setImportRT(irtList).setExportRT(ertList);
        try {
            Optional<VpnMap> optionalVpnMap = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
            if (optionalVpnMap.isPresent()) {
                VpnMap vpnMap = optionalVpnMap.get();
                evpn.setTenantId(vpnMap.getTenantId()).setName(vpnMap.getName());
            }
        } catch (ReadFailedException e) {
            LOG.error("Error reading the VPN map for {}", vpnMapIdentifier, e);
            result.set(RpcResultBuilder.<GetEVPNOutput>failed().withError(RpcError.ErrorType.APPLICATION, "Error reading the VPN map for " + vpnMapIdentifier, e).build());
            return result;
        }
        evpnList.add(evpn.build());
    }
    opBuilder.setEvpnInstances(evpnList);
    result.set(RpcResultBuilder.<GetEVPNOutput>success().withResult(opBuilder.build()).build());
    return result;
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) GetEVPNOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetEVPNOutputBuilder) VpnInstance(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ArrayList(java.util.ArrayList) VpnMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMapKey) EvpnInstances(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.getevpn.output.EvpnInstances) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnTarget(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.vpntargets.VpnTarget) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) GetEVPNOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetEVPNOutput) EvpnInstancesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.getevpn.output.EvpnInstancesBuilder)

Example 47 with RpcResult

use of org.opendaylight.yangtools.yang.common.RpcResult in project netvirt by opendaylight.

the class NeutronvpnManager method addInterVpnRoutes.

/**
 * Creates the corresponding static routes in the specified VPN. These static routes must be point to an
 * InterVpnLink endpoint and the specified VPN must be the other end of the InterVpnLink. Otherwise the
 * route will be ignored.
 *
 * @param vpnName the VPN identifier
 * @param interVpnLinkRoutes The list of static routes
 * @param nexthopsXinterVpnLinks A Map with the correspondence nextHop-InterVpnLink
 */
public void addInterVpnRoutes(Uuid vpnName, List<Routes> interVpnLinkRoutes, HashMap<String, InterVpnLink> nexthopsXinterVpnLinks) {
    for (Routes route : interVpnLinkRoutes) {
        String nexthop = String.valueOf(route.getNexthop().getValue());
        String destination = String.valueOf(route.getDestination().getValue());
        InterVpnLink interVpnLink = nexthopsXinterVpnLinks.get(nexthop);
        if (isNexthopTheOtherVpnLinkEndpoint(nexthop, vpnName.getValue(), interVpnLink)) {
            AddStaticRouteInput rpcInput = new AddStaticRouteInputBuilder().setDestination(destination).setNexthop(nexthop).setVpnInstanceName(vpnName.getValue()).build();
            Future<RpcResult<AddStaticRouteOutput>> labelOuputFtr = vpnRpcService.addStaticRoute(rpcInput);
            RpcResult<AddStaticRouteOutput> rpcResult;
            try {
                rpcResult = labelOuputFtr.get();
                if (rpcResult.isSuccessful()) {
                    LOG.debug("Label generated for destination {} is: {}", destination, rpcResult.getResult().getLabel());
                } else {
                    LOG.error("RPC call to add a static Route to {} with nexthop {} returned with errors {}", destination, nexthop, rpcResult.getErrors());
                }
            } catch (InterruptedException | ExecutionException e) {
                LOG.error("Error happened while invoking addStaticRoute RPC for nexthop {} with destination {} " + "for VPN {}", nexthop, destination, vpnName.getValue(), e);
            }
        } else {
            // Any other case is a fault.
            LOG.warn("route with destination {} and nexthop {} does not apply to any InterVpnLink", String.valueOf(route.getDestination().getValue()), nexthop);
            continue;
        }
    }
}
Also used : InterVpnLink(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLink) AddStaticRouteInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.AddStaticRouteInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes) ExecutionException(java.util.concurrent.ExecutionException) AddStaticRouteInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.AddStaticRouteInputBuilder) AddStaticRouteOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.AddStaticRouteOutput)

Example 48 with RpcResult

use of org.opendaylight.yangtools.yang.common.RpcResult in project netvirt by opendaylight.

the class NeutronvpnManager method deleteL3VPN.

/**
 * It handles the invocations to the neutronvpn:deleteL3VPN RPC method.
 */
@Override
public Future<RpcResult<DeleteL3VPNOutput>> deleteL3VPN(DeleteL3VPNInput input) {
    DeleteL3VPNOutputBuilder opBuilder = new DeleteL3VPNOutputBuilder();
    SettableFuture<RpcResult<DeleteL3VPNOutput>> result = SettableFuture.create();
    List<RpcError> errorList = new ArrayList<>();
    int failurecount = 0;
    int warningcount = 0;
    List<Uuid> vpns = input.getId();
    for (Uuid vpn : vpns) {
        RpcError error;
        String msg;
        try {
            InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class).child(VpnInstance.class, new VpnInstanceKey(vpn.getValue())).build();
            Optional<VpnInstance> optionalVpn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
            if (optionalVpn.isPresent()) {
                removeVpn(vpn);
            } else {
                errorList.add(RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-value", formatAndLog(LOG::warn, "VPN with vpnid: {} does not exist", vpn.getValue())));
                warningcount++;
            }
        } catch (ReadFailedException ex) {
            errorList.add(RpcResultBuilder.newError(ErrorType.APPLICATION, formatAndLog(LOG::error, "Deletion of L3VPN failed when deleting for uuid {}", vpn.getValue()), ex.getMessage()));
            failurecount++;
        }
    }
    // if none succeeds; result is failure
    if (failurecount + warningcount == vpns.size()) {
        result.set(RpcResultBuilder.<DeleteL3VPNOutput>failed().withRpcErrors(errorList).build());
    } else {
        List<String> errorResponseList = new ArrayList<>();
        if (!errorList.isEmpty()) {
            for (RpcError rpcError : errorList) {
                errorResponseList.add("ErrorType: " + rpcError.getErrorType() + ", ErrorTag: " + rpcError.getTag() + ", ErrorMessage: " + rpcError.getMessage());
            }
        } else {
            errorResponseList.add("Operation successful with no errors");
        }
        opBuilder.setResponse(errorResponseList);
        result.set(RpcResultBuilder.<DeleteL3VPNOutput>success().withResult(opBuilder.build()).build());
    }
    return result;
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) VpnInstance(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RpcError(org.opendaylight.yangtools.yang.common.RpcError) ArrayList(java.util.ArrayList) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) DeleteL3VPNOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DeleteL3VPNOutputBuilder) VpnInstanceKey(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstanceKey)

Example 49 with RpcResult

use of org.opendaylight.yangtools.yang.common.RpcResult in project netvirt by opendaylight.

the class NeutronvpnManager method associateNetworks.

/**
 * It handles the invocations to the neutronvpn:associateNetworks RPC method.
 */
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public Future<RpcResult<AssociateNetworksOutput>> associateNetworks(AssociateNetworksInput input) {
    AssociateNetworksOutputBuilder opBuilder = new AssociateNetworksOutputBuilder();
    SettableFuture<RpcResult<AssociateNetworksOutput>> result = SettableFuture.create();
    LOG.debug("associateNetworks {}", input);
    StringBuilder returnMsg = new StringBuilder();
    Uuid vpnId = input.getVpnId();
    try {
        if (neutronvpnUtils.getVpnMap(vpnId) != null) {
            List<Uuid> netIds = input.getNetworkId();
            if (netIds != null && !netIds.isEmpty()) {
                List<String> failed = associateNetworksToVpn(vpnId, netIds);
                if (!failed.isEmpty()) {
                    returnMsg.append(failed);
                }
            }
        } else {
            returnMsg.append("VPN not found : ").append(vpnId.getValue());
        }
        if (returnMsg.length() != 0) {
            opBuilder.setResponse("ErrorType: PROTOCOL, ErrorTag: invalid-value, ErrorMessage: " + formatAndLog(LOG::error, "associate Networks to vpn {} failed due to {}", vpnId.getValue(), returnMsg));
            result.set(RpcResultBuilder.<AssociateNetworksOutput>success().withResult(opBuilder.build()).build());
        } else {
            result.set(RpcResultBuilder.<AssociateNetworksOutput>success().build());
        }
    } catch (Exception ex) {
        result.set(RpcResultBuilder.<AssociateNetworksOutput>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::error, "associate Networks to vpn {} failed due to {}", input.getVpnId().getValue(), ex.getMessage(), ex)).build());
    }
    LOG.debug("associateNetworks returns..");
    return result;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) AssociateNetworksOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateNetworksOutput) AssociateNetworksOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateNetworksOutputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) 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 50 with RpcResult

use of org.opendaylight.yangtools.yang.common.RpcResult in project netvirt by opendaylight.

the class QosNeutronUtils method getDpnForInterface.

public BigInteger getDpnForInterface(String ifName) {
    BigInteger nodeId = BigInteger.ZERO;
    try {
        GetDpidFromInterfaceInput dpIdInput = new GetDpidFromInterfaceInputBuilder().setIntfName(ifName).build();
        Future<RpcResult<GetDpidFromInterfaceOutput>> dpIdOutput = odlInterfaceRpcService.getDpidFromInterface(dpIdInput);
        RpcResult<GetDpidFromInterfaceOutput> dpIdResult = dpIdOutput.get();
        if (dpIdResult.isSuccessful()) {
            nodeId = dpIdResult.getResult().getDpid();
        } else {
            LOG.error("Could not retrieve DPN Id for interface {}", ifName);
        }
    } catch (NullPointerException | InterruptedException | ExecutionException e) {
        LOG.error("Exception when getting dpn for interface {}", ifName, e);
    }
    return nodeId;
}
Also used : GetDpidFromInterfaceInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetDpidFromInterfaceInput) GetDpidFromInterfaceInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetDpidFromInterfaceInputBuilder) GetDpidFromInterfaceOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetDpidFromInterfaceOutput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) BigInteger(java.math.BigInteger) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)360 Test (org.junit.Test)120 ExecutionException (java.util.concurrent.ExecutionException)118 ArrayList (java.util.ArrayList)61 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)37 InOrder (org.mockito.InOrder)30 List (java.util.List)29 BigInteger (java.math.BigInteger)26 NodeRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef)25 FutureCallback (com.google.common.util.concurrent.FutureCallback)24 AllocateIdInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput)24 AllocateIdOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput)24 RpcError (org.opendaylight.yangtools.yang.common.RpcError)24 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)23 AllocateIdInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder)23 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)22 Future (java.util.concurrent.Future)21 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)21 Logger (org.slf4j.Logger)21 LoggerFactory (org.slf4j.LoggerFactory)21