Search in sources :

Example 1 with DeviceState

use of org.opendaylight.openflowplugin.api.openflow.device.DeviceState in project openflowplugin by opendaylight.

the class OF10DeviceInitializer method initializeNodeInformation.

@Override
protected Future<Void> initializeNodeInformation(@Nonnull final DeviceContext deviceContext, final boolean switchFeaturesMandatory, final boolean skipTableFeatures, @Nullable final MultipartWriterProvider multipartWriterProvider, @Nullable final ConvertorExecutor convertorExecutor) {
    final ConnectionContext connectionContext = Preconditions.checkNotNull(deviceContext.getPrimaryConnectionContext());
    final DeviceState deviceState = Preconditions.checkNotNull(deviceContext.getDeviceState());
    final DeviceInfo deviceInfo = Preconditions.checkNotNull(deviceContext.getDeviceInfo());
    final CapabilitiesV10 capabilitiesV10 = connectionContext.getFeatures().getCapabilitiesV10();
    // Set capabilities for this device based on capabilities of connection context
    LOG.debug("Setting capabilities for device {}", deviceInfo);
    DeviceStateUtil.setDeviceStateBasedOnV10Capabilities(deviceState, capabilitiesV10);
    final ListenableFuture<Boolean> future = requestMultipart(MultipartType.OFPMPDESC, deviceContext);
    Futures.addCallback(future, new FutureCallback<Boolean>() {

        @Override
        public void onSuccess(@Nullable final Boolean result) {
            if (Boolean.TRUE.equals(result)) {
                LOG.debug("Creating empty flow capable node: {}", deviceInfo);
                makeEmptyFlowCapableNode(deviceContext, deviceInfo);
                LOG.debug("Creating empty tables for {}", deviceInfo);
                DeviceInitializationUtil.makeEmptyTables(deviceContext, deviceInfo, deviceContext.getPrimaryConnectionContext().getFeatures().getTables());
            }
        }

        @Override
        public void onFailure(@Nonnull final Throwable throwable) {
            LOG.warn("Error occurred in preparation node {} for protocol 1.0", deviceInfo);
            LOG.trace("Error for node {} : ", deviceInfo, throwable);
        }
    }, MoreExecutors.directExecutor());
    return Futures.transform(future, new Function<Boolean, Void>() {

        @Nullable
        @Override
        public Void apply(@Nullable final Boolean input) {
            LOG.debug("Writing physical port information for {}", deviceInfo);
            writePhyPortInformation(deviceContext);
            return null;
        }
    }, MoreExecutors.directExecutor());
}
Also used : DeviceState(org.opendaylight.openflowplugin.api.openflow.device.DeviceState) DeviceInfo(org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo) ConnectionContext(org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext) CapabilitiesV10(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10) Nullable(javax.annotation.Nullable)

Example 2 with DeviceState

use of org.opendaylight.openflowplugin.api.openflow.device.DeviceState in project openflowplugin by opendaylight.

the class OF13DeviceInitializer method initializeNodeInformation.

@Override
protected Future<Void> initializeNodeInformation(@Nonnull final DeviceContext deviceContext, final boolean switchFeaturesMandatory, final boolean skipTableFeatures, @Nullable final MultipartWriterProvider multipartWriterProvider, @Nullable final ConvertorExecutor convertorExecutor) {
    final ConnectionContext connectionContext = Preconditions.checkNotNull(deviceContext.getPrimaryConnectionContext());
    final DeviceState deviceState = Preconditions.checkNotNull(deviceContext.getDeviceState());
    final DeviceInfo deviceInfo = Preconditions.checkNotNull(deviceContext.getDeviceInfo());
    final Capabilities capabilities = connectionContext.getFeatures().getCapabilities();
    LOG.debug("Setting capabilities for device {}", deviceInfo);
    DeviceStateUtil.setDeviceStateBasedOnV13Capabilities(deviceState, capabilities);
    // First process description reply, write data to DS and write consequent data if successful
    return Futures.transformAsync(requestMultipart(MultipartType.OFPMPDESC, deviceContext), (AsyncFunction<RpcResult<List<OfHeader>>, Void>) input -> {
        translateAndWriteResult(MultipartType.OFPMPDESC, input.getResult(), deviceContext, multipartWriterProvider, convertorExecutor);
        final List<ListenableFuture<RpcResult<List<OfHeader>>>> futures = new ArrayList<>();
        futures.add(requestAndProcessMultipart(MultipartType.OFPMPMETERFEATURES, deviceContext, skipTableFeatures, multipartWriterProvider, convertorExecutor));
        futures.add(requestAndProcessMultipart(MultipartType.OFPMPGROUPFEATURES, deviceContext, skipTableFeatures, multipartWriterProvider, convertorExecutor));
        futures.add(requestAndProcessMultipart(MultipartType.OFPMPTABLEFEATURES, deviceContext, skipTableFeatures, multipartWriterProvider, convertorExecutor));
        futures.add(requestAndProcessMultipart(MultipartType.OFPMPPORTDESC, deviceContext, skipTableFeatures, multipartWriterProvider, convertorExecutor));
        return Futures.transform(switchFeaturesMandatory ? Futures.allAsList(futures) : Futures.successfulAsList(futures), new Function<List<RpcResult<List<OfHeader>>>, Void>() {

            @Nullable
            @Override
            public Void apply(@Nullable final List<RpcResult<List<OfHeader>>> input) {
                LOG.info("Static node {} successfully finished collecting", deviceContext.getDeviceInfo());
                return null;
            }
        }, MoreExecutors.directExecutor());
    }, MoreExecutors.directExecutor());
}
Also used : MoreExecutors(com.google.common.util.concurrent.MoreExecutors) MultipartWriterProvider(org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ConvertorExecutor(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) MeterFeatures(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterFeatures) LoggerFactory(org.slf4j.LoggerFactory) MultiLayerMultipartCollectorService(org.opendaylight.openflowplugin.impl.services.multilayer.MultiLayerMultipartCollectorService) DeviceState(org.opendaylight.openflowplugin.api.openflow.device.DeviceState) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) DeviceStateUtil(org.opendaylight.openflowplugin.impl.util.DeviceStateUtil) Capabilities(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities) DeviceContext(org.opendaylight.openflowplugin.api.openflow.device.DeviceContext) OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) SingleLayerMultipartCollectorService(org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerMultipartCollectorService) ConnectionContext(org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext) Function(com.google.common.base.Function) Logger(org.slf4j.Logger) MultipartReplyTranslatorUtil(org.opendaylight.openflowplugin.impl.common.MultipartReplyTranslatorUtil) DeviceInitializationUtil(org.opendaylight.openflowplugin.impl.util.DeviceInitializationUtil) Collectors(java.util.stream.Collectors) FutureCallback(com.google.common.util.concurrent.FutureCallback) Objects(java.util.Objects) DeviceInfo(org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) RpcResultBuilder(org.opendaylight.yangtools.yang.common.RpcResultBuilder) MultipartType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) AsyncFunction(com.google.common.util.concurrent.AsyncFunction) Function(com.google.common.base.Function) AsyncFunction(com.google.common.util.concurrent.AsyncFunction) DeviceState(org.opendaylight.openflowplugin.api.openflow.device.DeviceState) Capabilities(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities) OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader) DeviceInfo(org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ArrayList(java.util.ArrayList) List(java.util.List) ConnectionContext(org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext) Nullable(javax.annotation.Nullable)

Example 3 with DeviceState

use of org.opendaylight.openflowplugin.api.openflow.device.DeviceState in project openflowplugin by opendaylight.

the class AbstractCompatibleStatServiceTest method setUp.

@Override
public void setUp() {
    rqContext = new AbstractRequestContext<Object>(42L) {

        @Override
        public void close() {
        // NOOP
        }
    };
    final Answer closeRequestFutureAnswer = invocation -> {
        rqContext.setResult(rpcResult);
        rqContext.close();
        return null;
    };
    Mockito.when(featuresOutput.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
    Mockito.when(rqContextStack.<Object>createRequestContext()).thenReturn(rqContext);
    Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState);
    Mockito.when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
    Mockito.when(deviceInfo.getNodeId()).thenReturn(NODE_ID);
    Mockito.when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
    Mockito.doAnswer(closeRequestFutureAnswer).when(multiMsgCollector).endCollecting(null);
    Mockito.doAnswer(closeRequestFutureAnswer).when(multiMsgCollector).endCollecting(Matchers.any(EventIdentifier.class));
    Mockito.doAnswer(answerVoidToCallback).when(outboundQueueProvider).commitEntry(Matchers.eq(42L), requestInput.capture(), Matchers.any(FutureCallback.class));
    Mockito.when(translatorLibrary.lookupTranslator(Matchers.any(TranslatorKey.class))).thenReturn(translator);
    service = AggregateFlowsInTableService.createWithOook(rqContextStack, deviceContext, new AtomicLong(20L));
}
Also used : MultipartReplyAggregateCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCaseBuilder) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput) Matchers(org.mockito.Matchers) Mock(org.mockito.Mock) NotificationPublishService(org.opendaylight.controller.md.sal.binding.api.NotificationPublishService) DeviceState(org.opendaylight.openflowplugin.api.openflow.device.DeviceState) Captor(org.mockito.Captor) GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput) Answer(org.mockito.stubbing.Answer) ArgumentCaptor(org.mockito.ArgumentCaptor) GetFeaturesOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput) MultipartReplyAggregateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.aggregate._case.MultipartReplyAggregateBuilder) MessageTranslator(org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator) BigInteger(java.math.BigInteger) AggregateFlowsInTableService(org.opendaylight.openflowplugin.impl.statistics.services.AggregateFlowsInTableService) Counter32(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32) MultipartRequestInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput) AbstractRequestContext(org.opendaylight.openflowplugin.impl.rpc.AbstractRequestContext) GetAggregateFlowStatisticsFromFlowTableForAllFlowsInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInputBuilder) Test(org.junit.Test) MultipartReplyMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder) FutureCallback(com.google.common.util.concurrent.FutureCallback) OFConstants(org.opendaylight.openflowplugin.api.OFConstants) DeviceInfo(org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo) AtomicLong(java.util.concurrent.atomic.AtomicLong) Mockito(org.mockito.Mockito) EventIdentifier(org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier) MultipartReply(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply) RpcResultBuilder(org.opendaylight.yangtools.yang.common.RpcResultBuilder) MultipartType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType) TranslatorKey(org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey) AggregateFlowStatisticsUpdate(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsUpdate) TableId(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId) Assert(org.junit.Assert) Collections(java.util.Collections) AggregatedFlowStatistics(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.get.aggregate.flow.statistics.from.flow.table._for.given.match.output.AggregatedFlowStatistics) AbstractStatsServiceTest(org.opendaylight.openflowplugin.impl.statistics.services.AbstractStatsServiceTest) Counter64(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) AggregatedFlowStatisticsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.get.aggregate.flow.statistics.from.flow.table._for.given.match.output.AggregatedFlowStatisticsBuilder) Answer(org.mockito.stubbing.Answer) AtomicLong(java.util.concurrent.atomic.AtomicLong) EventIdentifier(org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier) TranslatorKey(org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey) FutureCallback(com.google.common.util.concurrent.FutureCallback)

Aggregations

DeviceInfo (org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo)3 DeviceState (org.opendaylight.openflowplugin.api.openflow.device.DeviceState)3 FutureCallback (com.google.common.util.concurrent.FutureCallback)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 Nullable (javax.annotation.Nullable)2 ConnectionContext (org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext)2 MultipartType (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType)2 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)2 RpcResultBuilder (org.opendaylight.yangtools.yang.common.RpcResultBuilder)2 Function (com.google.common.base.Function)1 Preconditions (com.google.common.base.Preconditions)1 AsyncFunction (com.google.common.util.concurrent.AsyncFunction)1 Futures (com.google.common.util.concurrent.Futures)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1