Search in sources :

Example 1 with OfHeader

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

the class MessageDeserializerInjector method injectDeserializers.

/**
 * Injects message deserializers into provided.
 * {@link org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerExtensionProvider}
 *
 * @param provider OpenflowJava deserializer extension provider
 */
static void injectDeserializers(final DeserializerExtensionProvider provider) {
    // Inject new message deserializers here using injector created by createInjector method
    final Function<Integer, Function<Class<? extends OfHeader>, Consumer<OFDeserializer<? extends OfHeader>>>> injector = createInjector(provider, EncodeConstants.OF13_VERSION_ID);
    injector.apply(10).apply(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketInMessage.class).accept(new PacketInMessageDeserializer());
    injector.apply(19).apply(MultipartReply.class).accept(new MultipartReplyMessageDeserializer());
    injector.apply(27).apply(AsyncConfigMessage.class).accept(new AsyncConfigMessageDeserializer());
}
Also used : OFDeserializer(org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer) PacketInMessageDeserializer(org.opendaylight.openflowplugin.impl.protocol.deserialization.messages.PacketInMessageDeserializer) MultipartReply(org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReply) PacketInMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage) Function(java.util.function.Function) MultipartReplyMessageDeserializer(org.opendaylight.openflowplugin.impl.protocol.deserialization.multipart.MultipartReplyMessageDeserializer) OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader) AsyncConfigMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.AsyncConfigMessage) AsyncConfigMessageDeserializer(org.opendaylight.openflowplugin.impl.protocol.deserialization.messages.AsyncConfigMessageDeserializer)

Example 2 with OfHeader

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

the class MessageDeserializerInjector method injectLegacyDeserializers.

@VisibleForTesting
static void injectLegacyDeserializers(final DeserializerExtensionProvider provider) {
    final Function<Integer, Function<Class<? extends OfHeader>, Consumer<OFDeserializer<? extends OfHeader>>>> injector = createInjector(provider, EncodeConstants.OF13_VERSION_ID);
    injector.apply(14).apply(FlowMessage.class).accept(new FlowMessageDeserializer());
    injector.apply(15).apply(GroupMessage.class).accept(new GroupMessageDeserializer());
    injector.apply(29).apply(MeterMessage.class).accept(new MeterMessageDeserializer());
    injector.apply(16).apply(PortMessage.class).accept(new PortMessageDeserializer());
}
Also used : OFDeserializer(org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer) MeterMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterMessage) GroupMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupMessage) GroupMessageDeserializer(org.opendaylight.openflowplugin.impl.protocol.deserialization.messages.GroupMessageDeserializer) FlowMessageDeserializer(org.opendaylight.openflowplugin.impl.protocol.deserialization.messages.FlowMessageDeserializer) Function(java.util.function.Function) PortMessageDeserializer(org.opendaylight.openflowplugin.impl.protocol.deserialization.messages.PortMessageDeserializer) PortMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortMessage) OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader) MeterMessageDeserializer(org.opendaylight.openflowplugin.impl.protocol.deserialization.messages.MeterMessageDeserializer) FlowMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowMessage) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with OfHeader

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

the class MultipartReplyTranslatorUtil method translate.

public static Optional<? extends MultipartReplyBody> translate(final OfHeader message, final DeviceInfo deviceInfo, @Nullable final ConvertorExecutor convertorExecutor, @Nullable final TranslatorLibrary translatorLibrary) {
    if (message instanceof MultipartReply) {
        final Optional<ConvertorExecutor> convertor = Optional.ofNullable(convertorExecutor);
        final Optional<TranslatorLibrary> translator = Optional.ofNullable(translatorLibrary);
        final MultipartReply msg = MultipartReply.class.cast(message);
        final OpenflowVersion ofVersion = OpenflowVersion.get(deviceInfo.getVersion());
        final VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(deviceInfo.getVersion());
        data.setDatapathId(deviceInfo.getDatapathId());
        switch(msg.getType()) {
            case OFPMPFLOW:
                return convertor.flatMap(c -> Optional.of(translateFlow(msg, data, c)));
            case OFPMPAGGREGATE:
                return Optional.of(translateAggregate(msg));
            case OFPMPPORTSTATS:
                return Optional.of(translatePortStats(msg, ofVersion, deviceInfo.getDatapathId()));
            case OFPMPGROUP:
                return convertor.flatMap(c -> Optional.of(translateGroup(msg, data, c)));
            case OFPMPGROUPDESC:
                return convertor.flatMap(c -> Optional.of(translateGroupDesc(msg, data, c)));
            case OFPMPGROUPFEATURES:
                return Optional.of(translateGroupFeatures(msg));
            case OFPMPMETER:
                return convertor.flatMap(c -> Optional.of(translateMeter(msg, data, c)));
            case OFPMPMETERCONFIG:
                return convertor.flatMap(c -> Optional.of(translateMeterConfig(msg, data, c)));
            case OFPMPMETERFEATURES:
                return Optional.of(translateMeterFeatures(msg));
            case OFPMPTABLE:
                return Optional.of(translateTable(msg));
            case OFPMPQUEUE:
                return Optional.of(translateQueue(msg, ofVersion, deviceInfo.getDatapathId()));
            case OFPMPDESC:
                return Optional.of(translateDesc(msg));
            case OFPMPTABLEFEATURES:
                return convertor.flatMap(c -> Optional.of(translateTableFeatures(msg, deviceInfo.getVersion(), c)));
            case OFPMPPORTDESC:
                return translator.flatMap(t -> Optional.of(translatePortDesc(msg, deviceInfo, t)));
            default:
        }
    } else if (message instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReply) {
        return Optional.of(org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReply.class.cast(message).getMultipartReplyBody());
    }
    LOG.debug("Failed to translate {} for node {}.", message.getImplementedInterface(), deviceInfo);
    return Optional.empty();
}
Also used : VersionDatapathIdConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData) OpenflowVersion(org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion) MultipartReply(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply) TranslatorLibrary(org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary) ConvertorExecutor(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor)

Example 4 with OfHeader

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

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

the class SalAsyncConfigServiceImplTest method testGetAsyncTest.

@Test
public void testGetAsyncTest() throws Exception {
    final GetAsyncOutput getAsyncOutput = new GetAsyncOutputBuilder().build();
    final RpcResult<GetAsyncOutput> replyRpcResult = RpcResultBuilder.success(getAsyncOutput).build();
    final ListenableFuture<RpcResult<GetAsyncOutput>> replyFuture = Futures.immediateFuture(replyRpcResult);
    Mockito.when(mockedRequestContext.getFuture()).thenReturn(replyFuture);
    final Future<RpcResult<GetAsyncOutput>> getAsyncResult = salAsyncConfigService.getAsync(new GetAsyncInputBuilder().build());
    Assert.assertNotNull(getAsyncResult);
    Assert.assertTrue(getAsyncResult.isDone());
    Assert.assertTrue(getAsyncResult.get().isSuccessful());
    verify(mockedRequestContextStack).createRequestContext();
    verify(mockedOutboundQueue).commitEntry(Matchers.eq(ServiceMocking.DUMMY_XID_VALUE), Matchers.<OfHeader>any(), Matchers.<FutureCallback<OfHeader>>any());
}
Also used : GetAsyncInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncInputBuilder) OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) GetAsyncOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncOutputBuilder) GetAsyncOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncOutput) Test(org.junit.Test)

Aggregations

OfHeader (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader)30 Test (org.junit.Test)23 MultipartRequestInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder)17 Xid (org.opendaylight.openflowplugin.api.openflow.device.Xid)10 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)5 ExecutionException (java.util.concurrent.ExecutionException)3 ServiceException (org.opendaylight.openflowplugin.impl.services.util.ServiceException)3 GroupMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupMessage)3 MultipartType (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType)3 FutureCallback (com.google.common.util.concurrent.FutureCallback)2 List (java.util.List)2 Future (java.util.concurrent.Future)2 Function (java.util.function.Function)2 OFDeserializer (org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer)2 TypeVersionKey (org.opendaylight.openflowplugin.extension.api.TypeVersionKey)2 ConversionException (org.opendaylight.openflowplugin.extension.api.exception.ConversionException)2 ConverterNotFoundException (org.opendaylight.openflowplugin.extension.api.exception.ConverterNotFoundException)2 ConvertorExecutor (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor)2 PortMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortMessage)2 FlowMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowMessage)2