2 * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.impl.protocol.serialization;
11 import com.google.common.annotations.VisibleForTesting;
12 import java.util.function.Consumer;
13 import java.util.function.Function;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerExtensionProvider;
16 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.ApplyActionsMissTablePropertySerializer;
19 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.ApplyActionsTablePropertySerializer;
20 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.ApplySetfieldMissTablePropertySerializer;
21 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.ApplySetfieldTablePropertySerializer;
22 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.InstructionsMissTablePropertySerializer;
23 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.InstructionsTablePropertySerializer;
24 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.MatchTablePropertySerializer;
25 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.NextTableMissTablePropertySerializer;
26 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.NextTableTablePropertySerializer;
27 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.WildcardsTablePropertySerializer;
28 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.WriteActionsMissTablePropertySerializer;
29 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.WriteActionsTablePropertySerializer;
30 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.WriteSetfieldMissTablePropertySerializer;
31 import org.opendaylight.openflowplugin.impl.protocol.serialization.multipart.tablefeatures.WriteSetfieldTablePropertySerializer;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.TableFeaturePropType;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplyActions;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplyActionsMiss;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplySetfield;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplySetfieldMiss;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.Instructions;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.InstructionsMiss;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.Match;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.NextTable;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.NextTableMiss;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.Wildcards;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteActions;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteActionsMiss;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteSetfield;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteSetfieldMiss;
47 import org.opendaylight.yangtools.yang.common.Uint8;
50 * Util class for injecting new multipart table features serializers into OpenflowJava.
52 final class MultipartTableFeaturesSerializerInjector {
54 private MultipartTableFeaturesSerializerInjector() {
58 * Injects multipart table features serializers into provided
59 * {@link org.opendaylight.openflowjava.protocol.api.extensibility.SerializerExtensionProvider}.
61 * @param provider OpenflowJava serializer extension provider
63 static void injectSerializers(final SerializerExtensionProvider provider) {
64 // Inject new message serializers here using injector created by createInjector method
65 final Function<Class<? extends TableFeaturePropType>, Consumer<OFSerializer<TableFeaturePropType>>> injector =
66 createInjector(provider, EncodeConstants.OF_VERSION_1_3);
68 injector.apply(Instructions.class).accept(new InstructionsTablePropertySerializer());
69 injector.apply(InstructionsMiss.class).accept(new InstructionsMissTablePropertySerializer());
70 injector.apply(NextTable.class).accept(new NextTableTablePropertySerializer());
71 injector.apply(NextTableMiss.class).accept(new NextTableMissTablePropertySerializer());
72 injector.apply(ApplyActions.class).accept(new ApplyActionsTablePropertySerializer());
73 injector.apply(ApplyActionsMiss.class).accept(new ApplyActionsMissTablePropertySerializer());
74 injector.apply(WriteActions.class).accept(new WriteActionsTablePropertySerializer());
75 injector.apply(WriteActionsMiss.class).accept(new WriteActionsMissTablePropertySerializer());
76 injector.apply(Match.class).accept(new MatchTablePropertySerializer());
77 injector.apply(Wildcards.class).accept(new WildcardsTablePropertySerializer());
78 injector.apply(WriteSetfield.class).accept(new WriteSetfieldTablePropertySerializer());
79 injector.apply(WriteSetfieldMiss.class).accept(new WriteSetfieldMissTablePropertySerializer());
80 injector.apply(ApplySetfield.class).accept(new ApplySetfieldTablePropertySerializer());
81 injector.apply(ApplySetfieldMiss.class).accept(new ApplySetfieldMissTablePropertySerializer());
82 // TODO: Add support for experimenters
86 * Create injector that will inject new multipart table features serializers into
87 * #{@link org.opendaylight.openflowjava.protocol.api.extensibility.SerializerExtensionProvider}.
89 * @param provider OpenflowJava serializer extension provider
90 * @param version Openflow version
94 static Function<Class<? extends TableFeaturePropType>, Consumer<OFSerializer<TableFeaturePropType>>> createInjector(
95 final SerializerExtensionProvider provider, final Uint8 version) {
96 return type -> serializer ->
97 provider.registerSerializer(new MessageTypeKey<>(version, type), serializer);