2 * Copyright (c) 2016 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.instructions.ApplyActionsInstructionSerializer;
19 import org.opendaylight.openflowplugin.impl.protocol.serialization.instructions.ClearActionsInstructionSerializer;
20 import org.opendaylight.openflowplugin.impl.protocol.serialization.instructions.GoToTableInstructionSerializer;
21 import org.opendaylight.openflowplugin.impl.protocol.serialization.instructions.MeterInstructionSerializer;
22 import org.opendaylight.openflowplugin.impl.protocol.serialization.instructions.WriteActionsInstructionSerializer;
23 import org.opendaylight.openflowplugin.impl.protocol.serialization.instructions.WriteMetadataInstructionSerializer;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ClearActionsCase;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCase;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCase;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase;
33 * Util class for injecting new instruction serializers into OpenflowJava
35 class InstructionSerializerInjector {
38 * Injects serializers into provided {@link org.opendaylight.openflowjava.protocol.api.extensibility.SerializerExtensionProvider}
39 * @param provider OpenflowJava serializer extension provider
41 static void injectSerializers(final SerializerExtensionProvider provider) {
42 // Inject new instruction serializers here using injector created by createInjector method
43 final Function<Class<? extends Instruction>, Consumer<OFSerializer<? extends Instruction>>> injector =
44 createInjector(provider, EncodeConstants.OF13_VERSION_ID);
45 injector.apply(ApplyActionsCase.class).accept(new ApplyActionsInstructionSerializer());
46 injector.apply(ClearActionsCase.class).accept(new ClearActionsInstructionSerializer());
47 injector.apply(GoToTableCase.class).accept(new GoToTableInstructionSerializer());
48 injector.apply(MeterCase.class).accept(new MeterInstructionSerializer());
49 injector.apply(WriteActionsCase.class).accept(new WriteActionsInstructionSerializer());
50 injector.apply(WriteMetadataCase.class).accept(new WriteMetadataInstructionSerializer());
54 * Create injector that will inject new serializers into #{@link org.opendaylight.openflowjava.protocol.api.extensibility.SerializerExtensionProvider}
55 * @param provider OpenflowJava serializer extension provider
56 * @param version Openflow version
60 static Function<Class<? extends Instruction>, Consumer<OFSerializer<? extends Instruction>>> createInjector(final SerializerExtensionProvider provider,
62 return type -> serializer ->
63 provider.registerSerializer(
64 new MessageTypeKey<>(version, type),