Search in sources :

Example 1 with ErrorMessage

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage in project netvirt by opendaylight.

the class NeutronEvpnManager method deleteEVPN.

public Future<RpcResult<DeleteEVPNOutput>> deleteEVPN(DeleteEVPNInput input) {
    DeleteEVPNOutputBuilder opBuilder = new DeleteEVPNOutputBuilder();
    SettableFuture<RpcResult<DeleteEVPNOutput>> 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;
        VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpn.getValue());
        if (vpnInstance != null) {
            neutronvpnManager.removeVpn(vpn);
        } else {
            errorList.add(RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-value", formatAndLog(LOG::warn, "EVPN with vpnid: {} does not exist", vpn.getValue())));
            warningcount++;
        }
    }
    if (failurecount != 0) {
        result.set(RpcResultBuilder.<DeleteEVPNOutput>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("Deletion of EVPN operation successful");
        }
        opBuilder.setResponse(errorResponseList);
        result.set(RpcResultBuilder.<DeleteEVPNOutput>success().withResult(opBuilder.build()).build());
    }
    return result;
}
Also used : 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) DeleteEVPNOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DeleteEVPNOutputBuilder) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)

Example 2 with ErrorMessage

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage in project netvirt by opendaylight.

the class NeutronEvpnManager method createEVPN.

@SuppressWarnings("checkstyle:IllegalCatch")
public Future<RpcResult<CreateEVPNOutput>> createEVPN(CreateEVPNInput input) {
    CreateEVPNOutputBuilder opBuilder = new CreateEVPNOutputBuilder();
    SettableFuture<RpcResult<CreateEVPNOutput>> result = SettableFuture.create();
    List<RpcError> errorList = new ArrayList<>();
    int failurecount = 0;
    int warningcount = 0;
    List<String> existingRDs = neutronvpnUtils.getExistingRDs();
    List<Evpn> vpns = input.getEvpn();
    for (Evpn vpn : vpns) {
        if (vpn.getRouteDistinguisher() == null || vpn.getImportRT() == null || vpn.getExportRT() == null) {
            errorList.add(RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input", formatAndLog(LOG::warn, "Creation of EVPN failed for VPN {} due to absence of RD/iRT/eRT input", vpn.getId().getValue())));
            warningcount++;
            continue;
        }
        VpnInstance.Type vpnInstanceType = VpnInstance.Type.L2;
        if (vpn.getRouteDistinguisher().size() > 1) {
            errorList.add(RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input", formatAndLog(LOG::warn, "Creation of EVPN failed for VPN {} due to multiple RD input {}", vpn.getId().getValue(), vpn.getRouteDistinguisher())));
            warningcount++;
            continue;
        }
        if (existingRDs.contains(vpn.getRouteDistinguisher().get(0))) {
            errorList.add(RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input", formatAndLog(LOG::warn, "Creation of EVPN failed for VPN {} as another VPN with the same RD {} is already " + "configured", vpn.getId().getValue(), vpn.getRouteDistinguisher().get(0))));
            warningcount++;
            continue;
        }
        try {
            neutronvpnManager.createVpn(vpn.getId(), vpn.getName(), vpn.getTenantId(), vpn.getRouteDistinguisher(), vpn.getImportRT(), vpn.getExportRT(), null, /*router-id*/
            null, /*network-id*/
            vpnInstanceType, 0);
        } catch (Exception ex) {
            errorList.add(RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, formatAndLog(LOG::error, "Creation of EVPN failed for VPN {}", vpn.getId().getValue(), ex), ex.getMessage()));
            failurecount++;
        }
    }
    if (failurecount != 0) {
        result.set(RpcResultBuilder.<CreateEVPNOutput>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("EVPN creation successful with no errors");
        }
        opBuilder.setResponse(errorResponseList);
        result.set(RpcResultBuilder.<CreateEVPNOutput>success().withResult(opBuilder.build()).build());
    }
    return result;
}
Also used : 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) Evpn(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.createevpn.input.Evpn) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) CreateEVPNOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.CreateEVPNOutputBuilder)

Example 3 with ErrorMessage

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage 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 4 with ErrorMessage

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage 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 5 with ErrorMessage

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage in project openflowplugin by opendaylight.

the class OnfExperimenterErrorFactoryTest method testDeserializeCodes.

@Test
public void testDeserializeCodes() {
    ByteBuf buffer = ByteBufUtils.buildBuf("ff ff 08 fc 00 00 00 01");
    ErrorMessage builtByFactory = factory.deserialize(buffer);
    Assert.assertEquals("Wrong code", 2300, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong code string", "ONFERR_ET_UNKNOWN", builtByFactory.getCodeString());
    buffer = ByteBufUtils.buildBuf("ff ff 08 fd 00 00 00 01");
    builtByFactory = factory.deserialize(buffer);
    Assert.assertEquals("Wrong code", 2301, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong code string", "ONFERR_ET_EPERM", builtByFactory.getCodeString());
    buffer = ByteBufUtils.buildBuf("ff ff 08 fe 00 00 00 01");
    builtByFactory = factory.deserialize(buffer);
    Assert.assertEquals("Wrong code", 2302, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong code string", "ONFERR_ET_BAD_ID", builtByFactory.getCodeString());
    buffer = ByteBufUtils.buildBuf("ff ff 08 ff 00 00 00 01");
    builtByFactory = factory.deserialize(buffer);
    Assert.assertEquals("Wrong code", 2303, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong code string", "ONFERR_ET_BUNDLE_EXIST", builtByFactory.getCodeString());
    buffer = ByteBufUtils.buildBuf("ff ff 09 00 00 00 00 01");
    builtByFactory = factory.deserialize(buffer);
    Assert.assertEquals("Wrong code", 2304, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong code string", "ONFERR_ET_BUNDLE_CLOSED", builtByFactory.getCodeString());
    buffer = ByteBufUtils.buildBuf("ff ff 09 01 00 00 00 01");
    builtByFactory = factory.deserialize(buffer);
    Assert.assertEquals("Wrong code", 2305, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong code string", "ONFERR_ET_OUT_OF_BUNDLES", builtByFactory.getCodeString());
    buffer = ByteBufUtils.buildBuf("ff ff 09 02 00 00 00 01");
    builtByFactory = factory.deserialize(buffer);
    Assert.assertEquals("Wrong code", 2306, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong code string", "ONFERR_ET_BAD_TYPE", builtByFactory.getCodeString());
    buffer = ByteBufUtils.buildBuf("ff ff 09 03 00 00 00 01");
    builtByFactory = factory.deserialize(buffer);
    Assert.assertEquals("Wrong code", 2307, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong code string", "ONFERR_ET_BAD_FLAGS", builtByFactory.getCodeString());
    buffer = ByteBufUtils.buildBuf("ff ff 09 04 00 00 00 01");
    builtByFactory = factory.deserialize(buffer);
    Assert.assertEquals("Wrong code", 2308, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong code string", "ONFERR_ET_MSG_BAD_LEN", builtByFactory.getCodeString());
    buffer = ByteBufUtils.buildBuf("ff ff 09 05 00 00 00 01");
    builtByFactory = factory.deserialize(buffer);
    Assert.assertEquals("Wrong code", 2309, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong code string", "ONFERR_ET_MSG_BAD_XID", builtByFactory.getCodeString());
    buffer = ByteBufUtils.buildBuf("ff ff 09 06 00 00 00 01");
    builtByFactory = factory.deserialize(buffer);
    Assert.assertEquals("Wrong code", 2310, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong code string", "ONFERR_ET_MSG_UNSUP", builtByFactory.getCodeString());
    buffer = ByteBufUtils.buildBuf("ff ff 09 07 00 00 00 01");
    builtByFactory = factory.deserialize(buffer);
    Assert.assertEquals("Wrong code", 2311, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong code string", "ONFERR_ET_MSG_CONFLICT", builtByFactory.getCodeString());
    buffer = ByteBufUtils.buildBuf("ff ff 09 08 00 00 00 01");
    builtByFactory = factory.deserialize(buffer);
    Assert.assertEquals("Wrong code", 2312, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong code string", "ONFERR_ET_MSG_TOO_MANY", builtByFactory.getCodeString());
    buffer = ByteBufUtils.buildBuf("ff ff 09 09 00 00 00 01");
    builtByFactory = factory.deserialize(buffer);
    Assert.assertEquals("Wrong code", 2313, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong code string", "ONFERR_ET_MSG_FAILED", builtByFactory.getCodeString());
    buffer = ByteBufUtils.buildBuf("ff ff 09 0a 00 00 00 01");
    builtByFactory = factory.deserialize(buffer);
    Assert.assertEquals("Wrong code", 2314, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong code string", "ONFERR_ET_TIMEOUT", builtByFactory.getCodeString());
    buffer = ByteBufUtils.buildBuf("ff ff 09 0b 00 00 00 01");
    builtByFactory = factory.deserialize(buffer);
    Assert.assertEquals("Wrong code", 2315, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong code string", "ONFERR_ET_BUNDLE_IN_PROGRESS", builtByFactory.getCodeString());
    buffer = ByteBufUtils.buildBuf("ff ff 09 0c 00 00 00 01");
    builtByFactory = factory.deserialize(buffer);
    Assert.assertEquals("Wrong code", 2316, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong code string", "UNKNOWN_CODE", builtByFactory.getCodeString());
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) ErrorMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)17 ErrorMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage)17 ByteBuf (io.netty.buffer.ByteBuf)14 ErrorMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder)7 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)6 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)5 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)5 RpcError (org.opendaylight.yangtools.yang.common.RpcError)5 ArrayList (java.util.ArrayList)4 VpnInstance (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance)4 ExecutionException (java.util.concurrent.ExecutionException)3 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)3 ErrorType (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 DeviceRequestFailedException (org.opendaylight.openflowjava.protocol.api.connection.DeviceRequestFailedException)1 VpnInstanceKey (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstanceKey)1 AssociateNetworksOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateNetworksOutput)1 AssociateNetworksOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateNetworksOutputBuilder)1 CreateEVPNOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.CreateEVPNOutputBuilder)1