Search in sources :

Example 46 with Device

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device in project openflowplugin by opendaylight.

the class StatisticsGatheringUtils method markDeviceStateSnapshotEnd.

/**
 * Writes snapshot gathering end timestamp + outcome.
 *
 * @param deviceInfo device info
 * @param txFacade tx manager
 * @param succeeded     outcome of currently finished gathering
 */
static void markDeviceStateSnapshotEnd(final DeviceInfo deviceInfo, final TxFacade txFacade, final boolean succeeded) {
    final InstanceIdentifier<SnapshotGatheringStatusEnd> statusEndPath = deviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableStatisticsGatheringStatus.class).child(SnapshotGatheringStatusEnd.class);
    final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_AND_TIME_FORMAT);
    final SnapshotGatheringStatusEnd gatheringStatus = new SnapshotGatheringStatusEndBuilder().setEnd(new DateAndTime(simpleDateFormat.format(new Date()))).setSucceeded(succeeded).build();
    try {
        txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, statusEndPath, gatheringStatus);
    } catch (TransactionChainClosedException e) {
        LOG.warn("Can't write to transaction, transaction chain probably closed.");
        LOG.trace("Write to transaction exception: ", e);
    }
    txFacade.submitTransaction();
}
Also used : FlowCapableStatisticsGatheringStatus(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableStatisticsGatheringStatus) DateAndTime(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime) TransactionChainClosedException(org.opendaylight.mdsal.binding.api.TransactionChainClosedException) SnapshotGatheringStatusEnd(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.snapshot.gathering.status.grouping.SnapshotGatheringStatusEnd) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) SnapshotGatheringStatusEndBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.snapshot.gathering.status.grouping.SnapshotGatheringStatusEndBuilder)

Example 47 with Device

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device in project openflowplugin by opendaylight.

the class RoleService method submitRoleChange.

public ListenableFuture<RpcResult<SetRoleOutput>> submitRoleChange(final OfpRole ofpRole, final Uint8 version, final Uint64 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(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(Uint64.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)

Example 48 with Device

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device in project openflowplugin by opendaylight.

the class RoleService method getGenerationIdFromDevice.

public ListenableFuture<Uint64> getGenerationIdFromDevice(final Uint8 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(Uint64.ZERO);
    final SettableFuture<Uint64> finalFuture = SettableFuture.create();
    final ListenableFuture<RpcResult<RoleRequestOutput>> genIdListenableFuture = handleServiceCall(roleRequestInputBuilder);
    Futures.addCallback(genIdListenableFuture, new FutureCallback<RpcResult<RoleRequestOutput>>() {

        @Override
        public void onSuccess(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) ExecutionException(java.util.concurrent.ExecutionException) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 49 with Device

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device in project openflowplugin by opendaylight.

the class AbstractRequestCallback method onFailure.

@Override
public final void onFailure(final Throwable throwable) {
    final RpcResultBuilder<T> builder;
    if (null != eventIdentifier) {
        EventsTimeCounter.markEnd(eventIdentifier);
    }
    if (throwable instanceof DeviceRequestFailedException) {
        final Error err = ((DeviceRequestFailedException) throwable).getError();
        final String errorString = String.format("Device reported error type %s code %s", err.getTypeString(), err.getCodeString());
        builder = RpcResultBuilder.<T>failed().withError(RpcError.ErrorType.APPLICATION, errorString, throwable);
        spyMessage(StatisticsGroup.TO_SWITCH_SUBMIT_FAILURE);
    } else {
        if (throwable != null) {
            builder = RpcResultBuilder.<T>failed().withError(RpcError.ErrorType.APPLICATION, throwable.getMessage(), throwable);
        } else {
            Throwable deviceReadFailedThrowable = new Throwable("Failed to read from device.");
            builder = RpcResultBuilder.<T>failed().withError(RpcError.ErrorType.APPLICATION, deviceReadFailedThrowable.getMessage(), deviceReadFailedThrowable);
        }
        spyMessage(StatisticsGroup.TO_SWITCH_SUBMIT_ERROR);
    }
    context.setResult(builder.build());
    RequestContextUtil.closeRequestContext(context);
}
Also used : DeviceRequestFailedException(org.opendaylight.openflowjava.protocol.api.connection.DeviceRequestFailedException) Error(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Error) RpcError(org.opendaylight.yangtools.yang.common.RpcError)

Example 50 with Device

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device in project openflowplugin by opendaylight.

the class ConnectionManagerImplTest method testOnSwitchConnected1.

/**
 * Test method for
 * {@link org.opendaylight.openflowplugin.impl.connection.ConnectionManagerImpl#onSwitchConnected(
 * org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter)}.
 * invoking onConnectionReady first, scenario:
 * <ol>
 * <li>send hello to device (rpc with void output)</li>
 * <li>receive hello from device (notification)</li>
 * <li>send getFeature to device (rpc with getFeatureOutput)</li>
 * <li>wait for rpc to finish with getFeatureOutput</li>
 * </ol>
 *
 * @throws InterruptedException - interrupted exception
 */
@Test
public void testOnSwitchConnected1() throws Exception {
    connectionManagerImpl.onSwitchConnected(connection);
    Mockito.verify(connection).setConnectionReadyListener(connectionReadyListenerAC.capture());
    Mockito.verify(connection).setMessageListener(ofpListenerAC.capture());
    // prepare void reply (hello rpc output)
    final SettableFuture<RpcResult<HelloOutput>> voidResponseFx = SettableFuture.create();
    Mockito.when(connection.hello(any(HelloInput.class))).thenReturn(voidResponseFx);
    // prepare getFeature reply (getFeture rpc output)
    final SettableFuture<RpcResult<GetFeaturesOutput>> featureResponseFx = SettableFuture.create();
    Mockito.when(connection.getFeatures(any(GetFeaturesInput.class))).thenReturn(featureResponseFx);
    // fire handshake
    connectionReadyListenerAC.getValue().onConnectionReady();
    // deliver hello send output (void)
    Thread.sleep(100L);
    final RpcResult<HelloOutput> helloResponse = RpcResultBuilder.success((HelloOutput) null).build();
    voidResponseFx.set(helloResponse);
    // set dpn last connected time to be before dpn hold time seconds from now
    connectionManagerImpl.getDeviceConnectionStatusProvider().addDeviceLastConnectionTime(BigInteger.TEN, LocalDateTime.now().minusSeconds(DEVICE_CONNECTION_HOLD_TIME_IN_SECONDS.toJava()));
    // send hello reply
    final HelloMessage hello = new HelloMessageBuilder().setVersion(EncodeConstants.OF_VERSION_1_3).setXid(Uint32.ONE).build();
    ofpListenerAC.getValue().onHelloMessage(hello);
    // deliver getFeature output
    Thread.sleep(100L);
    final GetFeaturesOutput getFeatureOutput = new GetFeaturesOutputBuilder().setDatapathId(Uint64.TEN).setVersion(EncodeConstants.OF_VERSION_1_3).setXid(Uint32.TWO).setTables(Uint8.valueOf(15)).build();
    final RpcResult<GetFeaturesOutput> rpcFeaturesOutput = RpcResultBuilder.success(getFeatureOutput).build();
    featureResponseFx.set(rpcFeaturesOutput);
    Mockito.verify(deviceConnectedHandler, Mockito.timeout(500)).deviceConnected(any(ConnectionContext.class));
}
Also used : HelloOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloOutput) GetFeaturesOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder) GetFeaturesInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInput) HelloMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) HelloInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput) GetFeaturesOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput) HelloMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessageBuilder) ConnectionContext(org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)50 NodeId (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId)34 L2GatewayDevice (org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice)30 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)29 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)25 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)24 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)24 List (java.util.List)21 ExecutionException (java.util.concurrent.ExecutionException)18 Collection (java.util.Collection)16 Map (java.util.Map)16 Collections (java.util.Collections)15 HashMap (java.util.HashMap)15 Test (org.junit.Test)14 BigInteger (java.math.BigInteger)13 Set (java.util.Set)13 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)13 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)12 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12