Search in sources :

Example 11 with ErrorMessage

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

the class ErrorMessageFactoryTest method testWithIncorrectTypeEnum.

/**
 * Test of {@link ErrorMessageFactory} for correct translation into POJO.
 */
@Test
public void testWithIncorrectTypeEnum() {
    ByteBuf bb = BufferHelper.buildBuffer("00 20 00 05 00 01 02 03");
    ErrorMessage builtByFactory = BufferHelper.deserialize(errorFactory, bb);
    BufferHelper.checkHeaderV13(builtByFactory);
    Assert.assertEquals("Wrong type", 32, builtByFactory.getType().intValue());
    Assert.assertEquals("Wrong code", 5, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong type string", "UNKNOWN_TYPE", builtByFactory.getTypeString());
    Assert.assertEquals("Wrong code string", "UNKNOWN_CODE", builtByFactory.getCodeString());
    Assert.assertArrayEquals("Wrong data", new byte[] { 0x00, 0x01, 0x02, 0x03 }, builtByFactory.getData());
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) ErrorMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage) Test(org.junit.Test)

Example 12 with ErrorMessage

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

the class OF10ErrorMessageFactory method deserialize.

@Override
public ErrorMessage deserialize(ByteBuf rawMessage) {
    ErrorMessageBuilder builder = new ErrorMessageBuilder();
    builder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
    builder.setXid(rawMessage.readUnsignedInt());
    int type = rawMessage.readUnsignedShort();
    ErrorTypeV10 errorType = ErrorTypeV10.forValue(type);
    decodeType(builder, errorType, type);
    decodeCode(rawMessage, builder, errorType);
    int remainingBytes = rawMessage.readableBytes();
    if (remainingBytes > 0) {
        byte[] data = new byte[remainingBytes];
        rawMessage.readBytes(data);
        builder.setData(data);
    }
    return builder.build();
}
Also used : ErrorMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder) ErrorTypeV10(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorTypeV10)

Example 13 with ErrorMessage

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

the class OF10ErrorMessageFactoryTest method testWithoutData2.

/**
 * Test of {@link ErrorMessageFactory} for correct translation into POJO.
 * - not existing code used
 */
@Test
public void testWithoutData2() {
    ByteBuf bb = BufferHelper.buildBuffer("00 00 FF FF");
    ErrorMessage builtByFactory = BufferHelper.deserialize(errorFactory, bb);
    BufferHelper.checkHeaderV10(builtByFactory);
    Assert.assertEquals("Wrong type", 0, builtByFactory.getType().intValue());
    Assert.assertEquals("Wrong code", 65535, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong type string", "HELLOFAILED", builtByFactory.getTypeString());
    Assert.assertEquals("Wrong code string", "UNKNOWN_CODE", builtByFactory.getCodeString());
    Assert.assertNull("Data is not null", builtByFactory.getData());
    bb = BufferHelper.buildBuffer("00 01 FF FF");
    builtByFactory = BufferHelper.deserialize(errorFactory, bb);
    BufferHelper.checkHeaderV10(builtByFactory);
    Assert.assertEquals("Wrong type", 1, builtByFactory.getType().intValue());
    Assert.assertEquals("Wrong code", 65535, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong type string", "BADREQUEST", builtByFactory.getTypeString());
    Assert.assertEquals("Wrong code string", "UNKNOWN_CODE", builtByFactory.getCodeString());
    Assert.assertNull("Data is not null", builtByFactory.getData());
    bb = BufferHelper.buildBuffer("00 02 FF FF");
    builtByFactory = BufferHelper.deserialize(errorFactory, bb);
    BufferHelper.checkHeaderV10(builtByFactory);
    Assert.assertEquals("Wrong type", 2, builtByFactory.getType().intValue());
    Assert.assertEquals("Wrong code", 65535, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong type string", "BADACTION", builtByFactory.getTypeString());
    Assert.assertEquals("Wrong code string", "UNKNOWN_CODE", builtByFactory.getCodeString());
    Assert.assertNull("Data is not null", builtByFactory.getData());
    bb = BufferHelper.buildBuffer("00 03 FF FF");
    builtByFactory = BufferHelper.deserialize(errorFactory, bb);
    BufferHelper.checkHeaderV10(builtByFactory);
    Assert.assertEquals("Wrong type", 3, builtByFactory.getType().intValue());
    Assert.assertEquals("Wrong code", 65535, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong type string", "FLOWMODFAILED", builtByFactory.getTypeString());
    Assert.assertEquals("Wrong code string", "UNKNOWN_CODE", builtByFactory.getCodeString());
    Assert.assertNull("Data is not null", builtByFactory.getData());
    bb = BufferHelper.buildBuffer("00 04 FF FF");
    builtByFactory = BufferHelper.deserialize(errorFactory, bb);
    BufferHelper.checkHeaderV10(builtByFactory);
    Assert.assertEquals("Wrong type", 4, builtByFactory.getType().intValue());
    Assert.assertEquals("Wrong code", 65535, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong type string", "PORTMODFAILED", builtByFactory.getTypeString());
    Assert.assertEquals("Wrong code string", "UNKNOWN_CODE", builtByFactory.getCodeString());
    Assert.assertNull("Data is not null", builtByFactory.getData());
    bb = BufferHelper.buildBuffer("00 05 FF FF");
    builtByFactory = BufferHelper.deserialize(errorFactory, bb);
    BufferHelper.checkHeaderV10(builtByFactory);
    Assert.assertEquals("Wrong type", 5, builtByFactory.getType().intValue());
    Assert.assertEquals("Wrong code", 65535, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong type string", "QUEUEOPFAILED", builtByFactory.getTypeString());
    Assert.assertEquals("Wrong code string", "UNKNOWN_CODE", builtByFactory.getCodeString());
    Assert.assertNull("Data is not null", builtByFactory.getData());
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) ErrorMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage) Test(org.junit.Test)

Example 14 with ErrorMessage

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

the class OF10ErrorMessageFactoryTest method testWithIncorrectTypeEnum.

/**
 * Test of {@link OF10ErrorMessageFactory} for correct translation into POJO.
 */
@Test
public void testWithIncorrectTypeEnum() {
    ByteBuf bb = BufferHelper.buildBuffer("00 0A 00 05 00 01 02 03");
    ErrorMessage builtByFactory = BufferHelper.deserialize(errorFactory, bb);
    BufferHelper.checkHeaderV10(builtByFactory);
    Assert.assertEquals("Wrong type", 10, builtByFactory.getType().intValue());
    Assert.assertEquals("Wrong code", 5, builtByFactory.getCode().intValue());
    Assert.assertEquals("Wrong type string", "UNKNOWN_TYPE", builtByFactory.getTypeString());
    Assert.assertEquals("Wrong code string", "UNKNOWN_CODE", builtByFactory.getCodeString());
    Assert.assertArrayEquals("Wrong data", new byte[] { 0x00, 0x01, 0x02, 0x03 }, builtByFactory.getData());
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) ErrorMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage) Test(org.junit.Test)

Example 15 with ErrorMessage

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

the class NeutronvpnManager method dissociateNetworks.

/**
 * It handles the invocations to the neutronvpn:dissociateNetworks RPC method.
 */
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public Future<RpcResult<DissociateNetworksOutput>> dissociateNetworks(DissociateNetworksInput input) {
    DissociateNetworksOutputBuilder opBuilder = new DissociateNetworksOutputBuilder();
    SettableFuture<RpcResult<DissociateNetworksOutput>> result = SettableFuture.create();
    LOG.debug("dissociateNetworks {}", 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 = dissociateNetworksFromVpn(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, "dissociate Networks to vpn {} failed due to {}", vpnId.getValue(), returnMsg));
            result.set(RpcResultBuilder.<DissociateNetworksOutput>success().withResult(opBuilder.build()).build());
        } else {
            result.set(RpcResultBuilder.<DissociateNetworksOutput>success().build());
        }
    } catch (Exception ex) {
        result.set(RpcResultBuilder.<DissociateNetworksOutput>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::error, "dissociate Networks to vpn {} failed due to {}", input.getVpnId().getValue(), ex.getMessage(), ex)).build());
    }
    LOG.debug("dissociateNetworks returns..");
    return result;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) DissociateNetworksOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DissociateNetworksOutput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) DissociateNetworksOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DissociateNetworksOutputBuilder) 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)

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