Instruction experimenterId fix
[openflowjava.git] / 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.oxm.container.match.entry.value.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
23 /**
24  * Creates KeyMakers
25  * @author michal.polkorab
26  */
27 public abstract class TypeKeyMakerFactory {
28
29     private TypeKeyMakerFactory() {
30         //not called
31     }
32     
33     /**
34      * @param version openflow wire version that shall be used
35      *  in lookup key
36      * @return lookup key
37      */
38     public static TypeKeyMaker<MatchEntry> createMatchEntriesKeyMaker(short version) {
39         return new AbstractTypeKeyMaker<MatchEntry>(version) {
40             @Override
41             public MatchEntrySerializerKey<?, ?> make(MatchEntry entry) {
42                 MatchEntrySerializerKey<?, ?> key;
43                 key = new MatchEntrySerializerKey<>(getVersion(), entry.getOxmClass(),
44                         entry.getOxmMatchField());
45                 if (entry.getOxmClass().equals(ExperimenterClass.class)) {
46                     ExperimenterIdCase entryValue = (ExperimenterIdCase) entry.getMatchEntryValue();
47                     key.setExperimenterId(entryValue.getExperimenter().getExperimenter().getValue());
48                     return key;
49                 }
50                 key.setExperimenterId(null);
51                 return key;
52             }
53         };
54     }
55
56     /**
57      * @param version openflow wire version that shall be used
58      *  in lookup key
59      * @return lookup key
60      */
61     public static TypeKeyMaker<Action> createActionKeyMaker(short version) {
62         return new AbstractTypeKeyMaker<Action>(version) {
63             @Override
64             public MessageTypeKey<?> make(Action entry) {
65                 if (entry.getExperimenterId() != null) {
66                     return new ActionSerializerKey<>(getVersion(),
67                             (Class<ActionChoice>) entry.getActionChoice().getImplementedInterface(),
68                             entry.getExperimenterId().getValue());
69                 }
70                 return new ActionSerializerKey<>(getVersion(),
71                         (Class<ActionChoice>) entry.getActionChoice().getImplementedInterface(), null);
72             }
73         };
74     }
75
76     /**
77      * @param version openflow wire version that shall be used
78      *  in lookup key
79      * @return lookup key
80      */
81     public static TypeKeyMaker<Instruction> createInstructionKeyMaker(short version) {
82         return new AbstractTypeKeyMaker<Instruction>(version) {
83             @Override
84             public MessageTypeKey<?> make(Instruction entry) {
85                 if (entry.getExperimenterId() != null) {
86                     return new InstructionSerializerKey<>(getVersion(),
87                             (Class<InstructionChoice>) entry.getInstructionChoice().getImplementedInterface(),
88                             entry.getExperimenterId().getValue());
89                 }
90                 return new InstructionSerializerKey<>(getVersion(),
91                         (Class<InstructionChoice>) entry.getInstructionChoice().getImplementedInterface(), null);
92             }
93         };
94     }
95 }