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