BUG-956 deadlock by rpc invocation - phase2
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / TableFeaturesConvertor.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.util.ArrayList;
12 import java.util.Collections;
13 import java.util.List;
14
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCase;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCase;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCase;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCase;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCase;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCase;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCase;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCase;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCase;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCase;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCase;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetQueueActionCase;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ClearActionsCase;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCase;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCase;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionRelatedTableFeatureProperty;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionRelatedTableFeaturePropertyBuilder;
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.InstructionRelatedTableFeaturePropertyBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NextTableRelatedTableFeatureProperty;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NextTableRelatedTableFeaturePropertyBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmRelatedTableFeatureProperty;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmRelatedTableFeaturePropertyBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.table.features.properties.container.table.feature.properties.NextTableIds;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.table.features.properties.container.table.feature.properties.NextTableIdsBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSpa;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTha;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTpa;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpDscp;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Dst;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Flabel;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdSll;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTll;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpDst;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpSrc;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.multipart.request.table.features.TableFeatures;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table.features._case.multipart.request.table.features.TableFeaturesBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeaturePropertiesBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplyActions;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplyActionsMiss;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplySetfield;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplySetfieldMiss;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.Instructions;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.InstructionsMiss;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.Match;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.NextTable;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.NextTableMiss;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.Wildcards;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteActions;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteActionsMiss;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteSetfield;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteSetfieldMiss;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.match.MatchSetfield;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.next.table.miss.TablesMiss;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.wildcards.WildcardSetfield;
117 import org.slf4j.Logger;
118 import org.slf4j.LoggerFactory;
119
120 /**
121  * Utility class for converting a MD-SAL Table features into the OF library table
122  * features.
123  */
124 public class TableFeaturesConvertor {
125     private static final Logger logger = LoggerFactory.getLogger(TableFeaturesConvertor.class);
126
127     public static List<TableFeatures> toTableFeaturesRequest(
128             org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableFeatures salTableFeaturesList) {
129         List<TableFeatures> ofTableFeaturesList = new ArrayList<>();
130         TableFeaturesBuilder ofTableFeatures = new TableFeaturesBuilder();
131         for (org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures salTableFeatures : salTableFeaturesList
132                 .getTableFeatures()) {
133             ofTableFeatures.setTableId(salTableFeatures.getTableId());
134             ofTableFeatures.setName(salTableFeatures.getName());
135             ofTableFeatures.setMetadataMatch(salTableFeatures.getMetadataMatch());
136             ofTableFeatures.setMetadataWrite(salTableFeatures.getMetadataWrite());
137             ofTableFeatures.setMaxEntries(salTableFeatures.getMaxEntries()); 
138             if (salTableFeatures.getConfig() != null) {
139                 ofTableFeatures.setConfig(new TableConfig(salTableFeatures.getConfig().isDEPRECATEDMASK()));
140             }
141             ofTableFeatures.setTableFeatureProperties(toTableProperties(salTableFeatures.getTableProperties()));
142             ofTableFeaturesList.add(ofTableFeatures.build());
143         }
144         return ofTableFeaturesList;
145     }
146
147     private static List<TableFeatureProperties> toTableProperties(
148             org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.TableProperties tableProperties) {
149         if (tableProperties == null) {
150             return Collections.<TableFeatureProperties> emptyList();
151         }
152         List<TableFeatureProperties> ofTablePropertiesList = new ArrayList<>();
153         
154
155         for (org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeatureProperties property : tableProperties
156                 .getTableFeatureProperties()) {
157                 TableFeaturePropertiesBuilder propBuilder = new TableFeaturePropertiesBuilder();
158                 
159             org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.TableFeaturePropType propType = property
160                     .getTableFeaturePropType();
161             
162             if (propType instanceof Instructions) {
163                 org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.instructions.Instructions instructions = ((Instructions) propType)
164                         .getInstructions();
165                 setInstructionTableFeatureProperty(propBuilder, TableFeaturesPropType.OFPTFPTINSTRUCTIONS,
166                         (instructions == null) ? new ArrayList<Instruction>() : instructions.getInstruction());
167             } else if (propType instanceof InstructionsMiss) {
168                 org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.instructions.miss.InstructionsMiss instructions = ((InstructionsMiss) propType)
169                         .getInstructionsMiss();
170                 setInstructionTableFeatureProperty(propBuilder, TableFeaturesPropType.OFPTFPTINSTRUCTIONSMISS,
171                         (instructions == null) ? new ArrayList<Instruction>() : instructions.getInstruction());
172             } else if (propType instanceof NextTable) {
173                 org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.next.table.Tables tables = ((NextTable) propType)
174                         .getTables();
175                 setNextTableFeatureProperty(propBuilder, TableFeaturesPropType.OFPTFPTNEXTTABLES,
176                         (tables == null) ? new ArrayList<Short>() : tables.getTableIds());
177             } else if (propType instanceof NextTableMiss) {
178                 TablesMiss tables = ((NextTableMiss) propType)
179                         .getTablesMiss();
180                 setNextTableFeatureProperty(propBuilder, TableFeaturesPropType.OFPTFPTNEXTTABLESMISS,
181                         (tables == null) ? new ArrayList<Short>() : tables.getTableIds());
182             } else if (propType instanceof WriteActions) {
183                 org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.write.actions.WriteActions writeActions = ((WriteActions) propType)
184                         .getWriteActions();
185                 setActionTableFeatureProperty(
186                         propBuilder,
187                         TableFeaturesPropType.OFPTFPTWRITEACTIONS,
188                         ((writeActions == null) ? new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action>()
189                                 : writeActions.getAction()));
190             } else if (propType instanceof WriteActionsMiss) {
191                 org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.write.actions.miss.WriteActionsMiss writeActionsMiss = ((WriteActionsMiss) propType)
192                         .getWriteActionsMiss();
193                 setActionTableFeatureProperty(
194                         propBuilder,
195                         TableFeaturesPropType.OFPTFPTWRITEACTIONSMISS,
196                         ((writeActionsMiss == null) ? new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action>()
197                                 : writeActionsMiss.getAction()));
198             } else if (propType instanceof ApplyActions) {
199                 org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.apply.actions.ApplyActions applyActions = ((ApplyActions) propType)
200                         .getApplyActions();
201                 setActionTableFeatureProperty(
202                         propBuilder,
203                         TableFeaturesPropType.OFPTFPTAPPLYACTIONS,
204                         ((applyActions == null) ? new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action>()
205                                 : applyActions.getAction()));
206             } else if (propType instanceof ApplyActionsMiss) {
207                 org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.apply.actions.miss.ApplyActionsMiss applyActionsMiss = ((ApplyActionsMiss) propType)
208                         .getApplyActionsMiss();
209                 setActionTableFeatureProperty(
210                         propBuilder,
211                         TableFeaturesPropType.OFPTFPTAPPLYACTIONSMISS,
212                         ((applyActionsMiss == null) ? new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action>()
213                                 : applyActionsMiss.getAction()));
214             } else if (propType instanceof Match) {
215                 MatchSetfield matchSetField = ((Match) propType).getMatchSetfield();
216                 List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch> setFieldMatch = null;
217                 
218                 if( null != matchSetField) {
219                     setFieldMatch = matchSetField.getSetFieldMatch();
220                 }
221                 
222                 setSetFieldTableFeatureProperty(
223                         propBuilder,
224                         TableFeaturesPropType.OFPTFPTMATCH,
225                         ((setFieldMatch == null) ? new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch>()
226                                 : setFieldMatch));
227             } else if (propType instanceof Wildcards) {
228                 List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch> setFieldMatch = null;
229                 WildcardSetfield wildcardSetField = ((Wildcards) propType).getWildcardSetfield();
230                 
231                 if (null != wildcardSetField) {
232                     setFieldMatch = wildcardSetField.getSetFieldMatch();
233                 }
234                 
235                 setSetFieldTableFeatureProperty(
236                         propBuilder,
237                         TableFeaturesPropType.OFPTFPTWILDCARDS,
238                         ((setFieldMatch == null) ? new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch>()
239                                 : setFieldMatch));
240             } else if (propType instanceof WriteSetfield) {
241                 List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch> setFieldMatch = null; 
242                 org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.write.setfield.WriteSetfield writeSetField = ((WriteSetfield) propType).getWriteSetfield();
243                 
244                 if (null != writeSetField) {
245                     setFieldMatch = writeSetField.getSetFieldMatch();
246                 }
247                 
248                 setSetFieldTableFeatureProperty(
249                         propBuilder,
250                         TableFeaturesPropType.OFPTFPTWRITESETFIELD,
251                         ((setFieldMatch == null) ? new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch>()
252                                 : setFieldMatch));
253             } else if (propType instanceof WriteSetfieldMiss) {
254                 List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch> setFieldMatch = null;
255                 org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.write.setfield.miss.WriteSetfieldMiss writeSetfieldMiss = ((WriteSetfieldMiss) propType).getWriteSetfieldMiss();
256                 
257                 if (null != writeSetfieldMiss) {
258                     setFieldMatch = writeSetfieldMiss.getSetFieldMatch();
259                 }
260                 setSetFieldTableFeatureProperty(
261                         propBuilder,
262                         TableFeaturesPropType.OFPTFPTWRITESETFIELDMISS,
263                         ((setFieldMatch == null) ? new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch>()
264                                 : setFieldMatch));
265             } else if (propType instanceof ApplySetfield) {
266                 List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch> setFieldMatch = null; 
267                 org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.apply.setfield.ApplySetfield applySetfield = ((ApplySetfield) propType).getApplySetfield();
268                   
269                 if (null != applySetfield) {
270                     setFieldMatch = applySetfield.getSetFieldMatch();
271                 }
272                 setSetFieldTableFeatureProperty(
273                         propBuilder,
274                         TableFeaturesPropType.OFPTFPTAPPLYSETFIELD,
275                         ((setFieldMatch == null) ? new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch>()
276                                 : setFieldMatch));
277             } else if (propType instanceof ApplySetfieldMiss) {
278                 List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch> setFieldMatch = null;
279                 org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.apply.setfield.miss.ApplySetfieldMiss applySetfieldMiss = ((ApplySetfieldMiss) propType).getApplySetfieldMiss();
280                 
281                 if (null != applySetfieldMiss) {
282                     setFieldMatch = applySetfieldMiss.getSetFieldMatch();
283                 }
284                 setSetFieldTableFeatureProperty(
285                         propBuilder,
286                         TableFeaturesPropType.OFPTFPTAPPLYSETFIELDMISS,
287                         ((setFieldMatch == null) ? new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch>()
288                                 : setFieldMatch));
289             } // Experimenter and Experimeneter miss Table features are
290               // unhandled
291             ofTablePropertiesList.add(propBuilder.build());
292         }
293         return ofTablePropertiesList;
294     }
295
296     private static void setInstructionTableFeatureProperty(TableFeaturePropertiesBuilder builder,
297             TableFeaturesPropType type, List<Instruction> instructionList) {
298         List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction> instructionTypeList = new ArrayList<>();
299         
300         for (Instruction currInstruction : instructionList) {
301                 InstructionBuilder instructionType = new InstructionBuilder();
302                 
303             org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction instruction = currInstruction
304                     .getInstruction();
305             if (instruction instanceof GoToTableCase) {
306                 instructionType
307                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable.class);
308             } else if (instruction instanceof WriteMetadataCase) {
309                 instructionType
310                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata.class);
311             } else if (instruction instanceof WriteActionsCase) {
312                 instructionType
313                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions.class);
314             } else if (instruction instanceof ApplyActionsCase) {
315                 instructionType
316                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions.class);
317             } else if (instruction instanceof ClearActionsCase) {
318                 instructionType
319                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ClearActions.class);
320             } else if (instruction instanceof MeterCase) {
321                 instructionType
322                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Meter.class);
323             } // TODO: Experimeneter instructions are unhandled
324             instructionTypeList.add(instructionType.build());
325         }
326         InstructionRelatedTableFeaturePropertyBuilder propBuilder = new InstructionRelatedTableFeaturePropertyBuilder();
327         propBuilder.setInstruction(instructionTypeList);
328         builder.setType(type);
329         builder.addAugmentation(InstructionRelatedTableFeatureProperty.class, propBuilder.build());
330     }
331
332     private static void setNextTableFeatureProperty(TableFeaturePropertiesBuilder builder, TableFeaturesPropType type,
333             List<Short> tableIds) {
334         List<NextTableIds> nextTableIdsList = new ArrayList<>();
335         
336         for (Short tableId : tableIds) {
337                 NextTableIdsBuilder nextTableId = new NextTableIdsBuilder();
338             nextTableId.setTableId(tableId);
339             nextTableIdsList.add(nextTableId.build());
340         }
341         NextTableRelatedTableFeaturePropertyBuilder propBuilder = new NextTableRelatedTableFeaturePropertyBuilder();
342         propBuilder.setNextTableIds(nextTableIdsList);
343         builder.setType(type);
344         builder.addAugmentation(NextTableRelatedTableFeatureProperty.class, propBuilder.build());
345     }
346
347     private static void setActionTableFeatureProperty(TableFeaturePropertiesBuilder builder,
348             TableFeaturesPropType type,
349             List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> salActions) {
350         List<Action> actionList = new ArrayList<>();
351         
352         for (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action currAction : salActions) {
353             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionType = currAction
354                     .getAction();
355             ActionBuilder actionBuilder = new ActionBuilder();
356             if (actionType instanceof OutputActionCase) {
357                 actionBuilder
358                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output.class);
359             } else if (actionType instanceof GroupActionCase) {
360                 actionBuilder
361                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group.class);
362             } else if (actionType instanceof CopyTtlOutCase) {
363                 actionBuilder
364                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut.class);
365             } else if (actionType instanceof CopyTtlInCase) {
366                 actionBuilder
367                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlIn.class);
368             } else if (actionType instanceof SetMplsTtlActionCase) {
369                 actionBuilder
370                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl.class);
371             } else if (actionType instanceof DecMplsTtlCase) {
372                 actionBuilder
373                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl.class);
374             } else if (actionType instanceof PushVlanActionCase) {
375                 actionBuilder
376                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan.class);
377             } else if (actionType instanceof PopVlanActionCase) {
378                 actionBuilder
379                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan.class);
380             } else if (actionType instanceof PushMplsActionCase) {
381                 actionBuilder
382                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushMpls.class);
383             } else if (actionType instanceof PopMplsActionCase) {
384                 actionBuilder
385                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopMpls.class);
386             } else if (actionType instanceof SetQueueActionCase) {
387                 actionBuilder
388                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue.class);
389             } else if (actionType instanceof SetNwTtlActionCase) {
390                 actionBuilder
391                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl.class);
392             } else if (actionType instanceof DecNwTtlCase) {
393                 actionBuilder
394                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl.class);
395             } else if (actionType instanceof SetFieldCase) {
396                 actionBuilder
397                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
398             } else if (actionType instanceof PushPbbActionCase) {
399                 actionBuilder
400                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushPbb.class);
401             } else if (actionType instanceof PopPbbActionCase) {
402                 actionBuilder
403                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopPbb.class);
404             } // Experimenter action is unhandled
405             actionList.add(actionBuilder.build());
406         }
407         ActionRelatedTableFeaturePropertyBuilder propBuilder = new ActionRelatedTableFeaturePropertyBuilder();
408         propBuilder.setAction(actionList);
409         builder.setType(type);
410         builder.addAugmentation(ActionRelatedTableFeatureProperty.class, propBuilder.build());
411     }
412
413     private static void setSetFieldTableFeatureProperty(
414             TableFeaturePropertiesBuilder builder,
415             TableFeaturesPropType type,
416             List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch> setFields) {
417         List<MatchEntries> matchEntriesList = new ArrayList<>();
418         
419         for (org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch currMatch : setFields) {
420             Class<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MatchField> currMatchType = currMatch
421                     .getMatchType();
422             MatchEntriesBuilder matchEntryBuilder = new MatchEntriesBuilder();
423             if (currMatchType.equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpOp.class)) {
424                 setMatchEntry(matchEntryBuilder, ArpOp.class, currMatch.isHasMask());
425             } else if (currMatchType
426                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpSha.class)) {
427                 setMatchEntry(matchEntryBuilder, ArpSha.class, currMatch.isHasMask());
428             } else if (currMatchType
429                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpSpa.class)) {
430                 setMatchEntry(matchEntryBuilder, ArpSpa.class, currMatch.isHasMask());
431             } else if (currMatchType
432                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpTha.class)) {
433                 setMatchEntry(matchEntryBuilder, ArpTha.class, currMatch.isHasMask());
434             } else if (currMatchType
435                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpTpa.class)) {
436                 setMatchEntry(matchEntryBuilder, ArpTpa.class, currMatch.isHasMask());
437             } else if (currMatchType
438                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthDst.class)) {
439                 setMatchEntry(matchEntryBuilder, EthDst.class, currMatch.isHasMask());
440             } else if (currMatchType
441                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthSrc.class)) {
442                 setMatchEntry(matchEntryBuilder, EthSrc.class, currMatch.isHasMask());
443             } else if (currMatchType
444                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthType.class)) {
445                 setMatchEntry(matchEntryBuilder, EthType.class, currMatch.isHasMask());
446             } else if (currMatchType
447                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv4Code.class)) {
448                 setMatchEntry(matchEntryBuilder, Icmpv4Code.class, currMatch.isHasMask());
449             } else if (currMatchType
450                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv4Type.class)) {
451                 setMatchEntry(matchEntryBuilder, Icmpv4Type.class, currMatch.isHasMask());
452             } else if (currMatchType
453                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv6Code.class)) {
454                 setMatchEntry(matchEntryBuilder, Icmpv6Code.class, currMatch.isHasMask());
455             } else if (currMatchType
456                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Icmpv6Type.class)) {
457                 setMatchEntry(matchEntryBuilder, Icmpv6Type.class, currMatch.isHasMask());
458             } else if (currMatchType
459                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.InPhyPort.class)) {
460                 setMatchEntry(matchEntryBuilder, InPhyPort.class, currMatch.isHasMask());
461             } else if (currMatchType
462                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.InPort.class)) {
463                 setMatchEntry(matchEntryBuilder, InPort.class, currMatch.isHasMask());
464             } else if (currMatchType
465                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpDscp.class)) {
466                 setMatchEntry(matchEntryBuilder, IpDscp.class, currMatch.isHasMask());
467             } else if (currMatchType
468                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpEcn.class)) {
469                 setMatchEntry(matchEntryBuilder, IpEcn.class, currMatch.isHasMask());
470             } else if (currMatchType
471                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpProto.class)) {
472                 setMatchEntry(matchEntryBuilder, IpProto.class, currMatch.isHasMask());
473             } else if (currMatchType
474                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv4Dst.class)) {
475                 setMatchEntry(matchEntryBuilder, Ipv4Dst.class, currMatch.isHasMask());
476             } else if (currMatchType
477                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv4Src.class)) {
478                 setMatchEntry(matchEntryBuilder, Ipv4Src.class, currMatch.isHasMask());
479             } else if (currMatchType
480                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Dst.class)) {
481                 setMatchEntry(matchEntryBuilder, Ipv6Dst.class, currMatch.isHasMask());
482             } else if (currMatchType
483                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Exthdr.class)) {
484                 setMatchEntry(matchEntryBuilder, Ipv6Exthdr.class, currMatch.isHasMask());
485             } else if (currMatchType
486                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Flabel.class)) {
487                 setMatchEntry(matchEntryBuilder, Ipv6Flabel.class, currMatch.isHasMask());
488             } else if (currMatchType
489                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdSll.class)) {
490                 setMatchEntry(matchEntryBuilder, Ipv6NdSll.class, currMatch.isHasMask());
491             } else if (currMatchType
492                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdTarget.class)) {
493                 setMatchEntry(matchEntryBuilder, Ipv6NdTarget.class, currMatch.isHasMask());
494             } else if (currMatchType
495                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6NdTll.class)) {
496                 setMatchEntry(matchEntryBuilder, Ipv6NdTll.class, currMatch.isHasMask());
497             } else if (currMatchType
498                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Src.class)) {
499                 setMatchEntry(matchEntryBuilder, Ipv6Src.class, currMatch.isHasMask());
500             } else if (currMatchType
501                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Metadata.class)) {
502                 setMatchEntry(matchEntryBuilder, Metadata.class, currMatch.isHasMask());
503             } else if (currMatchType
504                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsBos.class)) {
505                 setMatchEntry(matchEntryBuilder, MplsBos.class, currMatch.isHasMask());
506             } else if (currMatchType
507                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsLabel.class)) {
508                 setMatchEntry(matchEntryBuilder, MplsLabel.class, currMatch.isHasMask());
509             } else if (currMatchType
510                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsTc.class)) {
511                 setMatchEntry(matchEntryBuilder, MplsTc.class, currMatch.isHasMask());
512             } else if (currMatchType
513                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.PbbIsid.class)) {
514                 setMatchEntry(matchEntryBuilder, PbbIsid.class, currMatch.isHasMask());
515             } else if (currMatchType
516                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.SctpDst.class)) {
517                 setMatchEntry(matchEntryBuilder, SctpDst.class, currMatch.isHasMask());
518             } else if (currMatchType
519                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.SctpSrc.class)) {
520                 setMatchEntry(matchEntryBuilder, SctpSrc.class, currMatch.isHasMask());
521             } else if (currMatchType
522                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpDst.class)) {
523                 setMatchEntry(matchEntryBuilder, TcpDst.class, currMatch.isHasMask());
524             } else if (currMatchType
525                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpSrc.class)) {
526                 setMatchEntry(matchEntryBuilder, TcpSrc.class, currMatch.isHasMask());
527             } else if (currMatchType
528                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelId.class)) {
529                 setMatchEntry(matchEntryBuilder, TunnelId.class, currMatch.isHasMask());
530             } else if (currMatchType
531                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.UdpDst.class)) {
532                 setMatchEntry(matchEntryBuilder, UdpDst.class, currMatch.isHasMask());
533             } else if (currMatchType
534                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.UdpDst.class)) {
535                 setMatchEntry(matchEntryBuilder, UdpSrc.class, currMatch.isHasMask());
536             } else if (currMatchType
537                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.VlanPcp.class)) {
538                 setMatchEntry(matchEntryBuilder, VlanPcp.class, currMatch.isHasMask());
539             } else if (currMatchType
540                     .equals(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.VlanVid.class)) {
541                 setMatchEntry(matchEntryBuilder, VlanVid.class, currMatch.isHasMask());
542             }
543             matchEntriesList.add(matchEntryBuilder.build());
544         }
545         OxmRelatedTableFeaturePropertyBuilder propBuilder = new OxmRelatedTableFeaturePropertyBuilder();
546         propBuilder.setMatchEntries(matchEntriesList);
547         builder.setType(type);
548         builder.addAugmentation(OxmRelatedTableFeatureProperty.class, propBuilder.build());
549     }
550
551     private static void setMatchEntry(MatchEntriesBuilder builder,
552             Class<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField> field,
553             Boolean hasMask) {
554         builder.setOxmClass(OpenflowBasicClass.class);
555         builder.setOxmMatchField(field);
556         builder.setHasMask(hasMask);
557     }
558 }