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.deserialization;
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.DeserializerExtensionProvider;
15 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
16 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.openflowplugin.impl.protocol.deserialization.key.MessageCodeMatchKey;
19 import org.opendaylight.openflowplugin.impl.protocol.deserialization.match.MatchDeserializer;
20 import org.opendaylight.openflowplugin.api.openflow.protocol.deserialization.MatchEntryDeserializer;
21 import org.opendaylight.openflowplugin.api.openflow.protocol.deserialization.MatchEntryDeserializerRegistry;
22 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
26 * Util class for injecting new match entry deserializers into OpenflowJava
28 public class MatchDeserializerInjector {
31 * Injects deserializers into provided {@link org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerExtensionProvider}
32 * @param provider OpenflowJava deserializer extension provider
34 public static void injectDeserializers(final DeserializerExtensionProvider provider) {
35 for (MatchPath path : MatchPath.values()) {
36 final MatchDeserializer deserializer = new MatchDeserializer(path);
37 provider.registerDeserializer(
38 new MessageCodeMatchKey(
39 EncodeConstants.OF13_VERSION_ID,
40 EncodeConstants.EMPTY_LENGTH,
45 // Inject new match entry serializers here using injector created by createInjector method
46 final Function<Integer, Function<Long, Function<Integer, Consumer<MatchEntryDeserializer>>>> injector =
47 createInjector(deserializer, EncodeConstants.OF13_VERSION_ID);
52 * Create injector that will inject new serializers into {@link org.opendaylight.openflowplugin.api.openflow.protocol.deserialization.MatchEntryDeserializerRegistry}
53 * @param registry Match entry deserializer registry
54 * @param version Openflow version
58 static Function<Integer, Function<Long, Function<Integer, Consumer<MatchEntryDeserializer>>>> createInjector(
59 final MatchEntryDeserializerRegistry registry,
62 return oxmClass -> expId -> oxmField -> deserializer -> {
63 final MatchEntryDeserializerKey key = new MatchEntryDeserializerKey(version, oxmClass, oxmField);
64 key.setExperimenterId(expId);
65 registry.registerEntryDeserializer(key, deserializer);