Bug 868: Replaced use of toInstance() for build().
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / TableFeaturesReplyConvertor.java
1 /**
2  * Copyright (c) 2013 Ericsson. 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.openflowplugin.openflow.md.core.sal.convertor;
10
11 import java.math.BigInteger;
12 import java.util.ArrayList;
13 import java.util.Collections;
14 import java.util.List;
15
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCaseBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCaseBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCaseBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCaseBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCaseBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCaseBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetQueueActionCaseBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ClearActionsCaseBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCaseBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCaseBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionRelatedTableFeatureProperty;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.InstructionRelatedTableFeatureProperty;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NextTableRelatedTableFeatureProperty;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmRelatedTableFeatureProperty;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.table.features.properties.container.table.feature.properties.NextTableIds;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSpa;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTha;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTpa;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpDscp;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Dst;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Flabel;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdSll;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTll;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpDst;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpSrc;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpFlag;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelIpv4Dst;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelIpv4Src;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.features._case.MultipartReplyTableFeatures;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableConfig;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatchBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.MatchBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WildcardsBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.apply.setfield.ApplySetfieldBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.apply.setfield.miss.ApplySetfieldMissBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.match.MatchSetfieldBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.next.table.miss.TablesMissBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.wildcards.WildcardSetfieldBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.write.setfield.WriteSetfieldBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.write.setfield.miss.WriteSetfieldMissBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.TableProperties;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.TablePropertiesBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeaturePropertiesBuilder;
110 import org.slf4j.Logger;
111 import org.slf4j.LoggerFactory;
112
113 /**
114  * Utility class for converting a OF library table features to MD-SAL table
115  * features.
116  */
117 public class TableFeaturesReplyConvertor {
118     private static final Logger logger = LoggerFactory.getLogger(TableFeaturesReplyConvertor.class);
119
120     public static List<TableFeatures> toTableFeaturesReply(
121             final MultipartReplyTableFeatures ofTableFeaturesList) {
122         if (ofTableFeaturesList == null || ofTableFeaturesList.getTableFeatures() == null) {
123             return Collections.<TableFeatures> emptyList();
124         }
125         List<TableFeatures> salTableFeaturesList = new ArrayList<>();
126         TableFeaturesBuilder salTableFeatures = new TableFeaturesBuilder();
127         for (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.
128                 multipart.reply.table.features._case.multipart.reply.table.features.TableFeatures ofTableFeatures : ofTableFeaturesList
129                 .getTableFeatures()) {
130             salTableFeatures.setTableId(ofTableFeatures.getTableId());
131             salTableFeatures.setName(ofTableFeatures.getName());
132             if (ofTableFeatures.getMetadataMatch() != null) {
133                 salTableFeatures.setMetadataMatch(new BigInteger(ofTableFeatures.getMetadataMatch()));
134             }
135             if (ofTableFeatures.getMetadataWrite() != null) {
136                 salTableFeatures.setMetadataWrite(new BigInteger(ofTableFeatures.getMetadataWrite()));
137             }
138             if (ofTableFeatures.getConfig() != null) {
139                 salTableFeatures.setConfig(new TableConfig(ofTableFeatures.getConfig().isOFPTCDEPRECATEDMASK()));
140             }
141             salTableFeatures.setMaxEntries(ofTableFeatures.getMaxEntries());
142             salTableFeatures.setTableProperties(toTableProperties(ofTableFeatures.getTableFeatureProperties()));
143             salTableFeaturesList.add(salTableFeatures.build());
144         }
145         return salTableFeaturesList;
146     }
147
148     private static TableProperties toTableProperties(final List<TableFeatureProperties> ofTablePropertiesList) {
149         if (ofTablePropertiesList == null) {
150             return new TablePropertiesBuilder()
151                     .setTableFeatureProperties(
152                             Collections
153                                     .<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeatureProperties> emptyList())
154                     .build();
155         }
156         List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeatureProperties> salTablePropertiesList = new ArrayList<>();
157         TableFeaturePropertiesBuilder propBuilder = new TableFeaturePropertiesBuilder();
158         for (TableFeatureProperties property : ofTablePropertiesList) {
159             TableFeaturesPropType propType = property.getType();
160             if (propType != null) {
161                 switch (propType) {
162                 case OFPTFPTINSTRUCTIONS:
163                     org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.InstructionsBuilder instructionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.InstructionsBuilder();
164                     instructionBuilder
165                             .setInstructions(new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.instructions.InstructionsBuilder()
166                                     .setInstruction(setInstructionTableFeatureProperty(property)).build());
167                     propBuilder.setTableFeaturePropType(instructionBuilder.build());
168                     break;
169                 case OFPTFPTINSTRUCTIONSMISS:
170                     org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.InstructionsMissBuilder instructionMissBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.InstructionsMissBuilder();
171                     instructionMissBuilder
172                             .setInstructionsMiss(new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.instructions.miss.InstructionsMissBuilder()
173                                     .setInstruction(setInstructionTableFeatureProperty(property)).build());
174                     propBuilder.setTableFeaturePropType(instructionMissBuilder.build());
175                     break;
176                 case OFPTFPTNEXTTABLES:
177                     org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.NextTableBuilder nextTableBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.NextTableBuilder();
178                     nextTableBuilder
179                             .setTables(new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.next.table.TablesBuilder()
180                                     .setTableIds(setNextTableFeatureProperty(property)).build());
181                     propBuilder.setTableFeaturePropType(nextTableBuilder.build());
182                     break;
183                 case OFPTFPTNEXTTABLESMISS:
184                     org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.NextTableMissBuilder nextTableMissBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.NextTableMissBuilder();
185                     nextTableMissBuilder
186                             .setTablesMiss(new TablesMissBuilder()
187                                     .setTableIds(setNextTableFeatureProperty(property)).build());
188                     propBuilder.setTableFeaturePropType(nextTableMissBuilder.build());
189                     break;
190                 case OFPTFPTWRITEACTIONS:
191                     org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteActionsBuilder writeActionsBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteActionsBuilder();
192                     writeActionsBuilder
193                             .setWriteActions(new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.write.actions.WriteActionsBuilder()
194                                     .setAction(setActionTableFeatureProperty(property)).build());
195                     propBuilder.setTableFeaturePropType(writeActionsBuilder.build());
196                     break;
197                 case OFPTFPTWRITEACTIONSMISS:
198                     org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteActionsMissBuilder writeActionsMissBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteActionsMissBuilder();
199                     writeActionsMissBuilder
200                             .setWriteActionsMiss(new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.write.actions.miss.WriteActionsMissBuilder()
201                                     .setAction(setActionTableFeatureProperty(property)).build());
202                     propBuilder.setTableFeaturePropType(writeActionsMissBuilder.build());
203                     break;
204                 case OFPTFPTAPPLYACTIONS:
205                     org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplyActionsBuilder applyActionsBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplyActionsBuilder();
206                     applyActionsBuilder
207                             .setApplyActions(new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.apply.actions.ApplyActionsBuilder()
208                                     .setAction(setActionTableFeatureProperty(property)).build());
209                     propBuilder.setTableFeaturePropType(applyActionsBuilder.build());
210                     break;
211                 case OFPTFPTAPPLYACTIONSMISS:
212                     org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplyActionsMissBuilder applyActionsMissBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplyActionsMissBuilder();
213                     applyActionsMissBuilder
214                             .setApplyActionsMiss(new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.apply.actions.miss.ApplyActionsMissBuilder()
215                                     .setAction(setActionTableFeatureProperty(property)).build());
216                     propBuilder.setTableFeaturePropType(applyActionsMissBuilder.build());
217                     break;
218                 case OFPTFPTMATCH:
219                     MatchSetfieldBuilder matchBuilder = new MatchSetfieldBuilder();
220                     matchBuilder.setSetFieldMatch(setSetFieldTableFeatureProperty(property, true));
221                     propBuilder.setTableFeaturePropType(new MatchBuilder().setMatchSetfield(matchBuilder.build()).build());
222                     break;
223                 case OFPTFPTWILDCARDS:
224                     WildcardSetfieldBuilder wildcardsBuilder = new WildcardSetfieldBuilder();
225                     wildcardsBuilder.setSetFieldMatch(setSetFieldTableFeatureProperty(property, false));
226                     propBuilder.setTableFeaturePropType(new WildcardsBuilder().setWildcardSetfield(wildcardsBuilder.build()).build());
227                     break;
228                 case OFPTFPTWRITESETFIELD:
229                     WriteSetfieldBuilder writeSetfieldBuilder = new WriteSetfieldBuilder();
230                     writeSetfieldBuilder.setSetFieldMatch(setSetFieldTableFeatureProperty(property, false));
231                     propBuilder.setTableFeaturePropType(new
232                             org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteSetfieldBuilder().setWriteSetfield(writeSetfieldBuilder.build()).build());
233                     break;
234                 case OFPTFPTWRITESETFIELDMISS:
235                     WriteSetfieldMissBuilder writeSetfieldMissBuilder = new WriteSetfieldMissBuilder();
236                     writeSetfieldMissBuilder.setSetFieldMatch(setSetFieldTableFeatureProperty(property, false));
237                     propBuilder.setTableFeaturePropType(new
238                             org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteSetfieldMissBuilder().setWriteSetfieldMiss(writeSetfieldMissBuilder.build()).build());
239                     break;
240                 case OFPTFPTAPPLYSETFIELD:
241                     ApplySetfieldBuilder applySetfieldBuilder = new ApplySetfieldBuilder();
242                     applySetfieldBuilder.setSetFieldMatch(setSetFieldTableFeatureProperty(property, false));
243                     propBuilder.setTableFeaturePropType(new
244                             org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplySetfieldBuilder().setApplySetfield(applySetfieldBuilder.build()).build());
245                     break;
246                 case OFPTFPTAPPLYSETFIELDMISS:
247                     ApplySetfieldMissBuilder applySetfieldMissBuilder = new ApplySetfieldMissBuilder();
248                     applySetfieldMissBuilder.setSetFieldMatch(setSetFieldTableFeatureProperty(property, false));
249                     propBuilder.setTableFeaturePropType(new
250                             org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplySetfieldMissBuilder().setApplySetfieldMiss(applySetfieldMissBuilder.build()).build());
251                     break;
252                 case OFPTFPTEXPERIMENTER:
253                     // Experimenter Table features are unhandled
254                     break;
255                 case OFPTFPTEXPERIMENTERMISS:
256                     // Experimenter miss Table features are unhandled
257                     break;
258                 default:
259                     logger.error("Unsupported table feature property : " + propType);
260                     break;
261                 }
262                 salTablePropertiesList.add(propBuilder.build());
263             }
264         }
265         return new TablePropertiesBuilder().setTableFeatureProperties(salTablePropertiesList).build();
266     }
267
268     private static List<Instruction> setInstructionTableFeatureProperty(final TableFeatureProperties properties) {
269         List<Instruction> instructionList = new ArrayList<>();
270         org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder builder = new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder();
271         for (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731
272                 .instructions.grouping.Instruction currInstruction : properties
273                 .getAugmentation(InstructionRelatedTableFeatureProperty.class).getInstruction()) {
274             Class<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.InstructionBase> currInstructionType = currInstruction
275                     .getType();
276             if (currInstructionType
277                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable.class)) {
278                 builder.setInstruction((new GoToTableCaseBuilder()
279                         .build()));
280             } else if (currInstructionType
281                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata.class)) {
282                 builder.setInstruction((new WriteMetadataCaseBuilder()
283                         .build()));
284             } else if (currInstructionType
285                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions.class)) {
286                 builder.setInstruction((new WriteActionsCaseBuilder()
287                         .build()));
288             } else if (currInstructionType
289                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions.class)) {
290                 builder.setInstruction((new ApplyActionsCaseBuilder()
291                         .build()));
292             } else if (currInstructionType
293                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ClearActions.class)) {
294                 builder.setInstruction((new ClearActionsCaseBuilder()
295                         .build()));
296             } else if (currInstructionType
297                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Meter.class)) {
298                 builder.setInstruction((new MeterCaseBuilder()
299                         .build()));
300             } else if (currInstructionType
301                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Experimenter.class)) {
302                 // TODO: Experimenter instructions are unhandled
303             }
304             instructionList.add(builder.build());
305         }
306         return instructionList;
307     }
308
309     private static List<Short> setNextTableFeatureProperty(final TableFeatureProperties properties) {
310         List<Short> nextTableIdsList = new ArrayList<>();
311         for (NextTableIds tableId : properties.getAugmentation(NextTableRelatedTableFeatureProperty.class)
312                 .getNextTableIds()) {
313             nextTableIdsList.add(tableId.getTableId());
314         }
315         return nextTableIdsList;
316     }
317
318     private static List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> setActionTableFeatureProperty(
319             final TableFeatureProperties properties) {
320         List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actionList = new ArrayList<>();
321         int order=0;
322         for (Action action : properties
323                 .getAugmentation(ActionRelatedTableFeatureProperty.class).getAction()) {
324             if (action != null) {
325                 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder actionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder();
326
327                 actionBuilder.setOrder(order++);
328                 Class<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase> actionType = action
329                         .getType();
330                 if (actionType
331                         .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output.class)) {
332                     actionBuilder.setAction(new OutputActionCaseBuilder().build());
333                 } else if (actionType
334                         .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group.class)) {
335                     actionBuilder.setAction(new GroupActionCaseBuilder().build());
336                 } else if (actionType
337                         .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut.class)) {
338                     actionBuilder.setAction(new CopyTtlOutCaseBuilder().build());
339                 } else if (actionType
340                         .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlIn.class)) {
341                     actionBuilder.setAction(new CopyTtlInCaseBuilder().build());
342                 } else if (actionType
343                         .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl.class)) {
344                     actionBuilder.setAction(new SetMplsTtlActionCaseBuilder().build());
345                 } else if (actionType
346                         .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl.class)) {
347                     actionBuilder.setAction(new DecMplsTtlCaseBuilder().build());
348                 } else if (actionType
349                         .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan.class)) {
350                     actionBuilder.setAction(new PushVlanActionCaseBuilder().build());
351                 } else if (actionType
352                         .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan.class)) {
353                     actionBuilder.setAction(new PopVlanActionCaseBuilder().build());
354                 } else if (actionType
355                         .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushMpls.class)) {
356                     actionBuilder.setAction(new PushMplsActionCaseBuilder().build());
357                 } else if (actionType
358                         .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopMpls.class)) {
359                     actionBuilder.setAction(new PopMplsActionCaseBuilder().build());
360                 } else if (actionType
361                         .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue.class)) {
362                     actionBuilder.setAction(new SetQueueActionCaseBuilder().build());
363                 } else if (actionType
364                         .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl.class)) {
365                     actionBuilder.setAction(new SetNwTtlActionCaseBuilder().build());
366                 } else if (actionType
367                         .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl.class)) {
368                     actionBuilder.setAction(new DecNwTtlCaseBuilder().build());
369                 } else if (actionType
370                         .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class)) {
371                     actionBuilder.setAction(new SetFieldCaseBuilder().build());
372                 } else if (actionType
373                         .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushPbb.class)) {
374                     actionBuilder.setAction(new PushPbbActionCaseBuilder().build());
375                 } else if (actionType
376                         .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopPbb.class)) {
377                     actionBuilder.setAction(new PopPbbActionCaseBuilder().build());
378                 } else if (actionType
379                         .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter.class)) {
380                     // TODO: Experimenter Action unhandled.
381                 }
382                 actionList.add(actionBuilder.build());
383             }
384         }
385         return actionList;
386     }
387
388     private static List<SetFieldMatch> setSetFieldTableFeatureProperty(final TableFeatureProperties properties,
389             final boolean setHasMask) {
390         List<SetFieldMatch> setFieldMatchList = new ArrayList<>();
391         SetFieldMatchBuilder setFieldMatchBuilder = new SetFieldMatchBuilder();
392         Class<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MatchField> salMatchField = null;
393         Class<? extends MatchField> ofMatchField = null;
394
395         // This handles only OpenflowBasicClass oxm class.
396         for (MatchEntries currMatch : properties.getAugmentation(OxmRelatedTableFeatureProperty.class)
397                 .getMatchEntries()) {
398             ofMatchField = currMatch.getOxmMatchField();
399             if (ofMatchField.equals(ArpOp.class)) {
400                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpOp.class;
401             } else if (ofMatchField.equals(ArpSha.class)) {
402                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpSha.class;
403             } else if (ofMatchField.equals(ArpSpa.class)) {
404                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpSpa.class;
405             } else if (ofMatchField.equals(ArpTha.class)) {
406                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpTha.class;
407             } else if (ofMatchField.equals(ArpTpa.class)) {
408                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpTpa.class;
409             } else if (ofMatchField.equals(EthDst.class)) {
410                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthDst.class;
411             } else if (ofMatchField.equals(EthSrc.class)) {
412                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthSrc.class;
413             } else if (ofMatchField.equals(EthType.class)) {
414                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthType.class;
415             } else if (ofMatchField.equals(Icmpv4Code.class)) {
416                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv4Code.class;
417             } else if (ofMatchField.equals(Icmpv4Type.class)) {
418                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv4Type.class;
419             } else if (ofMatchField.equals(Icmpv6Code.class)) {
420                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv6Code.class;
421             } else if (ofMatchField.equals(Icmpv6Type.class)) {
422                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv6Type.class;
423             } else if (ofMatchField.equals(InPhyPort.class)) {
424                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.InPhyPort.class;
425             } else if (ofMatchField.equals(InPort.class)) {
426                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.InPort.class;
427             } else if (ofMatchField.equals(IpDscp.class)) {
428                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpDscp.class;
429             } else if (ofMatchField.equals(IpEcn.class)) {
430                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpEcn.class;
431             } else if (ofMatchField.equals(IpProto.class)) {
432                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpProto.class;
433             } else if (ofMatchField.equals(Ipv4Dst.class)) {
434                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv4Dst.class;
435             } else if (ofMatchField.equals(Ipv4Src.class)) {
436                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv4Src.class;
437             } else if (ofMatchField.equals(Ipv6Dst.class)) {
438                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Dst.class;
439             } else if (ofMatchField.equals(Ipv6Exthdr.class)) {
440                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Exthdr.class;
441             } else if (ofMatchField.equals(Ipv6Flabel.class)) {
442                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Flabel.class;
443             } else if (ofMatchField.equals(Ipv6NdSll.class)) {
444                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdSll.class;
445             } else if (ofMatchField.equals(Ipv6NdTarget.class)) {
446                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdTarget.class;
447             } else if (ofMatchField.equals(Ipv6NdTll.class)) {
448                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdTll.class;
449             } else if (ofMatchField.equals(Ipv6Src.class)) {
450                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Src.class;
451             } else if (ofMatchField.equals(Metadata.class)) {
452                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Metadata.class;
453             } else if (ofMatchField.equals(MplsBos.class)) {
454                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsBos.class;
455             } else if (ofMatchField.equals(MplsLabel.class)) {
456                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsLabel.class;
457             } else if (ofMatchField.equals(MplsTc.class)) {
458                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsTc.class;
459             } else if (ofMatchField.equals(PbbIsid.class)) {
460                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.PbbIsid.class;
461             } else if (ofMatchField.equals(SctpDst.class)) {
462                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.SctpDst.class;
463             } else if (ofMatchField.equals(SctpSrc.class)) {
464                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.SctpSrc.class;
465             } else if (ofMatchField.equals(TcpDst.class)) {
466                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpDst.class;
467             } else if (ofMatchField.equals(TcpSrc.class)) {
468                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpSrc.class;
469             } else if (ofMatchField.equals(TunnelId.class)) {
470                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelId.class;
471             } else if (ofMatchField.equals(UdpDst.class)) {
472                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.UdpDst.class;
473             } else if (ofMatchField.equals(UdpSrc.class)) {
474                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.UdpSrc.class;
475             } else if (ofMatchField.equals(VlanPcp.class)) {
476                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.VlanPcp.class;
477             } else if (ofMatchField.equals(VlanVid.class)) {
478                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.VlanVid.class;
479             }
480             // TODO: Move to seperate bundle as soon as extension are supported in openflowplugin/java
481             else if (ofMatchField.equals(TcpFlag.class)) {
482                 //FIXME: move to extensible support
483                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpFlag.class;
484             } else if (ofMatchField.equals(TunnelIpv4Dst.class)) {
485                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelIpv4Dst.class;
486             } else if (ofMatchField.equals(TunnelIpv4Src.class)) {
487                 salMatchField = org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelIpv4Src.class;
488             }
489
490             setFieldMatchBuilder.setMatchType(salMatchField);
491             if (setHasMask) {
492                 setFieldMatchBuilder.setHasMask(currMatch.isHasMask());
493             }
494             setFieldMatchList.add(setFieldMatchBuilder.build());
495         }
496         return setFieldMatchList;
497     }
498
499 }