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