Search in sources :

Example 6 with RoleRequestOutput

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

the class RoleReplyMessageFactoryTest method testSerialize.

@Test
public void testSerialize() throws Exception {
    RoleRequestOutputBuilder builder = new RoleRequestOutputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setRole(ControllerRole.forValue(0));
    builder.setGenerationId(BigInteger.valueOf(1L));
    RoleRequestOutput message = builder.build();
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 24);
    Assert.assertEquals("Wrong role", message.getRole().getIntValue(), ControllerRole.forValue((int) serializedBuffer.readUnsignedInt()).getIntValue());
    serializedBuffer.skipBytes(PADDING);
    byte[] genId = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    serializedBuffer.readBytes(genId);
    Assert.assertEquals("Wrong generation ID", message.getGenerationId(), new BigInteger(1, genId));
}
Also used : RoleRequestOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput) RoleRequestOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutputBuilder) BigInteger(java.math.BigInteger) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 7 with RoleRequestOutput

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

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

RoleRequestOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput)7 Test (org.junit.Test)4 RoleRequestOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutputBuilder)4 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)4 BigInteger (java.math.BigInteger)3 SetRoleOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput)3 ByteBuf (io.netty.buffer.ByteBuf)2 RoleRequestInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInputBuilder)2 SalRoleService (org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SalRoleService)2 SetRoleInput (org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInput)2 SetRoleInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInputBuilder)2 Collection (java.util.Collection)1 ExecutionException (java.util.concurrent.ExecutionException)1 Before (org.junit.Before)1 Xid (org.opendaylight.openflowplugin.api.openflow.device.Xid)1 RoleChangeException (org.opendaylight.openflowplugin.impl.role.RoleChangeException)1 TransactionId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId)1 NodeRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef)1 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)1 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)1