Search in sources :

Example 1 with RoleRequestInputBuilder

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

the class RoleRequestInputMessageFactory method deserialize.

@Override
public RoleRequestInput deserialize(ByteBuf rawMessage) {
    RoleRequestInputBuilder builder = new RoleRequestInputBuilder();
    builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
    builder.setXid(rawMessage.readUnsignedInt());
    builder.setRole(ControllerRole.forValue(rawMessage.readInt()));
    rawMessage.skipBytes(PADDING);
    byte[] generationId = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    rawMessage.readBytes(generationId);
    builder.setGenerationId(new BigInteger(1, generationId));
    return builder.build();
}
Also used : RoleRequestInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInputBuilder) BigInteger(java.math.BigInteger)

Example 2 with RoleRequestInputBuilder

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

the class RoleRequestInputMessageFactoryTest method testRoleRequestInputMessage.

/**
 * Testing of {@link RoleRequestInputMessageFactory} for correct translation from POJO.
 */
@Test
public void testRoleRequestInputMessage() throws Exception {
    RoleRequestInputBuilder builder = new RoleRequestInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setRole(ControllerRole.forValue(2));
    byte[] generationId = new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 };
    builder.setGenerationId(new BigInteger(1, generationId));
    RoleRequestInput message = builder.build();
    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    roleFactory.serialize(message, out);
    BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH);
    Assert.assertEquals("Wrong role", message.getRole().getIntValue(), ControllerRole.forValue((int) out.readUnsignedInt()).getIntValue());
    out.skipBytes(PADDING_IN_ROLE_REQUEST_MESSAGE);
    byte[] genId = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    out.readBytes(genId);
    Assert.assertEquals("Wrong generation ID", message.getGenerationId(), new BigInteger(1, genId));
}
Also used : RoleRequestInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInputBuilder) BigInteger(java.math.BigInteger) ByteBuf(io.netty.buffer.ByteBuf) RoleRequestInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInput) Test(org.junit.Test)

Example 3 with RoleRequestInputBuilder

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

the class RoleService method getGenerationIdFromDevice.

public Future<BigInteger> getGenerationIdFromDevice(final Short version) {
    LOG.info("getGenerationIdFromDevice called for device: {}", getDeviceInfo().getNodeId().getValue());
    // send a dummy no-change role request to get the generation-id of the switch
    final RoleRequestInputBuilder roleRequestInputBuilder = new RoleRequestInputBuilder();
    roleRequestInputBuilder.setRole(toOFJavaRole(OfpRole.NOCHANGE));
    roleRequestInputBuilder.setVersion(version);
    roleRequestInputBuilder.setGenerationId(BigInteger.ZERO);
    final SettableFuture<BigInteger> finalFuture = SettableFuture.create();
    final ListenableFuture<RpcResult<RoleRequestOutput>> genIdListenableFuture = handleServiceCall(roleRequestInputBuilder);
    Futures.addCallback(genIdListenableFuture, new FutureCallback<RpcResult<RoleRequestOutput>>() {

        @Override
        public void onSuccess(@Nonnull final RpcResult<RoleRequestOutput> roleRequestOutputRpcResult) {
            if (roleRequestOutputRpcResult.isSuccessful()) {
                final RoleRequestOutput roleRequestOutput = roleRequestOutputRpcResult.getResult();
                if (roleRequestOutput != null) {
                    LOG.debug("roleRequestOutput.getGenerationId()={}", roleRequestOutput.getGenerationId());
                    finalFuture.set(roleRequestOutput.getGenerationId());
                } else {
                    LOG.info("roleRequestOutput is null in getGenerationIdFromDevice");
                    finalFuture.setException(new RoleChangeException("Exception in getting generationId for device:" + getDeviceInfo().getNodeId().getValue()));
                }
            } else {
                LOG.error("getGenerationIdFromDevice RPC error " + roleRequestOutputRpcResult.getErrors().iterator().next().getInfo());
                finalFuture.setException(new RoleChangeException(ErrorUtil.errorsToString(roleRequestOutputRpcResult.getErrors())));
            }
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.info("onFailure - getGenerationIdFromDevice RPC error {}", throwable);
            finalFuture.setException(new ExecutionException(throwable));
        }
    }, MoreExecutors.directExecutor());
    return finalFuture;
}
Also used : RoleRequestOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput) RoleChangeException(org.opendaylight.openflowplugin.impl.role.RoleChangeException) RoleRequestInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) BigInteger(java.math.BigInteger) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with RoleRequestInputBuilder

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

the class RoleService method submitRoleChange.

public Future<RpcResult<SetRoleOutput>> submitRoleChange(final OfpRole ofpRole, final Short version, final BigInteger generationId) {
    LOG.info("submitRoleChange called for device:{}, role:{}", getDeviceInfo().getNodeId(), ofpRole);
    final RoleRequestInputBuilder roleRequestInputBuilder = new RoleRequestInputBuilder();
    roleRequestInputBuilder.setRole(toOFJavaRole(ofpRole));
    roleRequestInputBuilder.setVersion(version);
    roleRequestInputBuilder.setGenerationId(generationId);
    final ListenableFuture<RpcResult<RoleRequestOutput>> roleListenableFuture = handleServiceCall(roleRequestInputBuilder);
    final SettableFuture<RpcResult<SetRoleOutput>> finalFuture = SettableFuture.create();
    Futures.addCallback(roleListenableFuture, new FutureCallback<RpcResult<RoleRequestOutput>>() {

        @Override
        public void onSuccess(@Nonnull final RpcResult<RoleRequestOutput> roleRequestOutputRpcResult) {
            LOG.info("submitRoleChange onSuccess for device:{}, role:{}", getDeviceInfo().getNodeId(), ofpRole);
            final RoleRequestOutput roleRequestOutput = roleRequestOutputRpcResult.getResult();
            final Collection<RpcError> rpcErrors = roleRequestOutputRpcResult.getErrors();
            if (roleRequestOutput != null) {
                final SetRoleOutputBuilder setRoleOutputBuilder = new SetRoleOutputBuilder();
                setRoleOutputBuilder.setTransactionId(new TransactionId(BigInteger.valueOf(roleRequestOutput.getXid())));
                finalFuture.set(RpcResultBuilder.<SetRoleOutput>success().withResult(setRoleOutputBuilder.build()).build());
            } else if (rpcErrors != null) {
                LOG.trace("roleRequestOutput is null , rpcErrors={}", rpcErrors);
                for (RpcError rpcError : rpcErrors) {
                    LOG.warn("RpcError on submitRoleChange for {}: {}", deviceContext.getPrimaryConnectionContext().getNodeId(), rpcError.toString());
                }
                finalFuture.set(RpcResultBuilder.<SetRoleOutput>failed().withRpcErrors(rpcErrors).build());
            }
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("submitRoleChange onFailure for device:{}, role:{}", getDeviceInfo().getNodeId(), ofpRole, throwable);
            finalFuture.setException(throwable);
        }
    }, MoreExecutors.directExecutor());
    return finalFuture;
}
Also used : RoleRequestOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RpcError(org.opendaylight.yangtools.yang.common.RpcError) TransactionId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId) SetRoleOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutputBuilder) SetRoleOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput) RoleRequestInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInputBuilder) Collection(java.util.Collection)

Aggregations

RoleRequestInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInputBuilder)4 BigInteger (java.math.BigInteger)3 RoleRequestOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput)2 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)2 ByteBuf (io.netty.buffer.ByteBuf)1 Collection (java.util.Collection)1 ExecutionException (java.util.concurrent.ExecutionException)1 Test (org.junit.Test)1 RoleChangeException (org.opendaylight.openflowplugin.impl.role.RoleChangeException)1 TransactionId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId)1 RoleRequestInput (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInput)1 SetRoleOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput)1 SetRoleOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutputBuilder)1 RpcError (org.opendaylight.yangtools.yang.common.RpcError)1