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