2 * Copyright (c) 2013 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.openflowjava.protocol.impl.util;
11 import org.opendaylight.openflowjava.protocol.api.keys.ActionSerializerKey;
12 import org.opendaylight.openflowjava.protocol.api.keys.InstructionSerializerKey;
13 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
14 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.experimenter.id.match.entry.ExperimenterIdCase;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.ActionChoice;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.InstructionChoice;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ExperimenterClass;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
22 import org.opendaylight.yangtools.yang.common.Uint32;
23 import org.opendaylight.yangtools.yang.common.Uint8;
28 * @author michal.polkorab
30 public final class TypeKeyMakerFactory {
32 private TypeKeyMakerFactory() {
37 * Creates a key maker for MatchEntry instances.
39 * @param version openflow wire version that shall be used in lookup key
42 public static TypeKeyMaker<MatchEntry> createMatchEntriesKeyMaker(final Uint8 version) {
43 return new AbstractTypeKeyMaker<>(version) {
45 public MatchEntrySerializerKey<?, ?> make(final MatchEntry entry) {
46 MatchEntrySerializerKey<?, ?> key;
47 key = new MatchEntrySerializerKey<>(getVersion(), entry.getOxmClass(),
48 entry.getOxmMatchField());
49 if (ExperimenterClass.VALUE.equals(entry.getOxmClass())) {
50 ExperimenterIdCase entryValue = (ExperimenterIdCase) entry.getMatchEntryValue();
51 key.setExperimenterId(entryValue.getExperimenter().getExperimenter().getValue());
54 key.setExperimenterId(null);
61 * Creates a key maker for Action instances.
63 * @param version openflow wire version that shall be used in lookup key
66 public static TypeKeyMaker<Action> createActionKeyMaker(final Uint8 version) {
67 return new AbstractTypeKeyMaker<>(version) {
69 public MessageTypeKey<?> make(final Action entry) {
70 if (entry.getExperimenterId() != null) {
71 return new ActionSerializerKey<>(getVersion(),
72 (Class<ActionChoice>) entry.getActionChoice().implementedInterface(),
73 entry.getExperimenterId().getValue());
75 return new ActionSerializerKey<>(getVersion(),
76 (Class<ActionChoice>) entry.getActionChoice().implementedInterface(), (Uint32) null);
82 * Creates a key maker for Instruction instances.
84 * @param version openflow wire version that shall be used in lookup key
87 public static TypeKeyMaker<Instruction> createInstructionKeyMaker(final Uint8 version) {
88 return new AbstractTypeKeyMaker<>(version) {
90 public MessageTypeKey<?> make(final Instruction entry) {
91 if (entry.getExperimenterId() != null) {
92 return new InstructionSerializerKey<>(getVersion(),
93 (Class<InstructionChoice>) entry.getInstructionChoice().implementedInterface(),
94 entry.getExperimenterId().getValue().toJava());
96 return new InstructionSerializerKey<>(getVersion(),
97 (Class<InstructionChoice>) entry.getInstructionChoice().implementedInterface(), null);