Bump upstreams for 2022.09 Chlorine
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / util / TypeKeyMakerFactory.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowjava.protocol.impl.util;
10
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;
24
25 /**
26  * Creates KeyMakers.
27  *
28  * @author michal.polkorab
29  */
30 public final class TypeKeyMakerFactory {
31
32     private TypeKeyMakerFactory() {
33         //not called
34     }
35
36     /**
37      * Creates a key maker for MatchEntry instances.
38      *
39      * @param version openflow wire version that shall be used in lookup key
40      * @return lookup key
41      */
42     public static TypeKeyMaker<MatchEntry> createMatchEntriesKeyMaker(final Uint8 version) {
43         return new AbstractTypeKeyMaker<>(version) {
44             @Override
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());
52                     return key;
53                 }
54                 key.setExperimenterId(null);
55                 return key;
56             }
57         };
58     }
59
60     /**
61      * Creates a key maker for Action instances.
62      *
63      * @param version openflow wire version that shall be used in lookup key
64      * @return lookup key
65      */
66     public static TypeKeyMaker<Action> createActionKeyMaker(final Uint8 version) {
67         return new AbstractTypeKeyMaker<>(version) {
68             @Override
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());
74                 }
75                 return new ActionSerializerKey<>(getVersion(),
76                         (Class<ActionChoice>) entry.getActionChoice().implementedInterface(), (Uint32) null);
77             }
78         };
79     }
80
81     /**
82      * Creates a key maker for Instruction instances.
83      *
84      * @param version openflow wire version that shall be used in lookup key
85      * @return lookup key
86      */
87     public static TypeKeyMaker<Instruction> createInstructionKeyMaker(final Uint8 version) {
88         return new AbstractTypeKeyMaker<>(version) {
89             @Override
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());
95                 }
96                 return new InstructionSerializerKey<>(getVersion(),
97                         (Class<InstructionChoice>) entry.getInstructionChoice().implementedInterface(), null);
98             }
99         };
100     }
101 }