Update MRI projects for Aluminium
[openflowplugin.git] / test-provider / src / main / java / org / opendaylight / openflowplugin / test / OpenflowpluginTableFeaturesTestCommandProvider.java
1 /*
2  * Copyright (c) 2014, 2015 Ericsson India Global Services Pvt Ltd. 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 package org.opendaylight.openflowplugin.test;
9
10 import com.google.common.base.Preconditions;
11 import com.google.common.util.concurrent.FutureCallback;
12 import com.google.common.util.concurrent.MoreExecutors;
13 import java.math.BigInteger;
14 import java.util.ArrayList;
15 import java.util.Arrays;
16 import java.util.List;
17 import org.eclipse.osgi.framework.console.CommandInterpreter;
18 import org.eclipse.osgi.framework.console.CommandProvider;
19 import org.opendaylight.mdsal.binding.api.DataBroker;
20 import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
21 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCaseBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCaseBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.ArpOp;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthDst;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthSrc;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.InPort;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv4Dst;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsBos;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.MplsLabel;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableConfig;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatchBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplySetfieldBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplySetfieldMissBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.MatchBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.NextTableBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.NextTableMissBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WildcardsBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteSetfieldBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteSetfieldMissBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.apply.actions.ApplyActionsBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.apply.actions.miss.ApplyActionsMissBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.match.MatchSetfieldBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.next.table.TablesBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.next.table.miss.TablesMissBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.wildcards.WildcardSetfieldBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesKey;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.TablePropertiesBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeatureProperties;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeaturePropertiesBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeaturePropertiesKey;
67 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
68 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
69 import org.opendaylight.yangtools.yang.common.Uint8;
70 import org.osgi.framework.BundleContext;
71
72 @SuppressWarnings("checkstyle:MethodName")
73 public class OpenflowpluginTableFeaturesTestCommandProvider implements CommandProvider {
74
75     private final DataBroker dataBroker;
76     private final BundleContext ctx;
77     private Node testNode;
78
79     public OpenflowpluginTableFeaturesTestCommandProvider(DataBroker dataBroker, BundleContext ctx) {
80         this.dataBroker = dataBroker;
81         this.ctx = ctx;
82     }
83
84     public void init() {
85         ctx.registerService(CommandProvider.class.getName(), this, null);
86         // createTestNode();
87         // createTestTableFeatures();
88     }
89
90     private void createUserNode(String nodeRef) {
91         NodeBuilder builder = new NodeBuilder();
92         builder.setId(new NodeId(nodeRef));
93         builder.withKey(new NodeKey(builder.getId()));
94         testNode = builder.build();
95     }
96
97     private void createTestNode() {
98         NodeBuilder builder = new NodeBuilder();
99         builder.setId(new NodeId(OpenflowpluginTestActivator.NODE_ID));
100         builder.withKey(new NodeKey(builder.getId()));
101         testNode = builder.build();
102     }
103
104     private InstanceIdentifier<Node> nodeToInstanceId(Node node) {
105         return InstanceIdentifier.create(Nodes.class).child(Node.class, node.key());
106     }
107
108     private TableFeaturesBuilder createTestTableFeatures(String tableFeatureTypeArg) {
109
110         String tableFeatureType = tableFeatureTypeArg;
111         if (tableFeatureType == null) {
112             tableFeatureType = "t1";
113         }
114
115         final TableFeaturesBuilder tableFeature = new TableFeaturesBuilder();
116         // Sample data , committing to DataStore
117         if (!tableFeatureType.equals("t1")) {
118
119
120             tableFeature.setTableId((short) 0);
121             tableFeature.setName("Table 0");
122
123
124             tableFeature.setMetadataMatch(BigInteger.valueOf(10));
125             tableFeature.setMetadataWrite(BigInteger.valueOf(10));
126             tableFeature.setMaxEntries(10000L);
127
128             tableFeature.setConfig(new TableConfig(false));
129
130             List<TableFeatureProperties> properties = new ArrayList<>();
131
132
133             switch (tableFeatureType) {
134                 case "t2":
135                     //To set the ApplyActionsMiss
136                     properties.add(createApplyActionsMissTblFeatureProp().build());
137                     break;
138                 case "t3":
139                     // To set the Next Table
140                     properties.add(createNextTblFeatureProp().build());
141                     break;
142                 case "t4":
143                     // To set the Next Table Miss
144                     properties.add(createNextTableMissTblFeatureProp().build());
145                     break;
146                 case "t5":
147                     //To set the ApplyActions
148                     properties.add(createApplyActionsTblFeatureProp().build());
149                     break;
150                 case "t6":
151                     // To set the instructions
152                     properties.add(createInstructionsTblFeatureProp().build());
153                     break;
154                 case "t7":
155                     // To set the instructions miss
156                     properties.add(createInstructionsMissTblFeatureProp().build());
157                     break;
158                 case "t8":
159                     // To set the write actions
160                     properties.add(createWriteActionsTblFeatureProp().build());
161                     break;
162                 case "t9":
163                     // To set the write actions miss
164                     properties.add(createWriteActionsMissTblFeatureProp().build());
165                     break;
166                 case "t10":
167                     // To set the match field
168                     properties.add(createMatchFieldTblFeatureProp().build());
169                     break;
170                 case "t11":
171                     // To set the write set-field
172                     properties.add(createWriteSetFieldTblFeatureProp().build());
173                     break;
174                 case "t12":
175                     // To set the write set-field miss
176                     properties.add(createWriteSetFieldMissTblFeatureProp().build());
177                     break;
178                 case "t13":
179                     // To set the apply set field
180                     properties.add(createApplySetFieldTblFeatureProp().build());
181                     break;
182                 case "t14":
183                     // To set the apply set field miss
184                     properties.add(createApplySetFieldMissTblFeatureProp().build());
185                     break;
186                 case "t15":
187                     // To set the wildcards set field match
188                     properties.add(createWildCardsTblFeatureProp().build());
189                     break;
190                 default:
191                     break;
192             }
193
194
195             TablePropertiesBuilder propertyBld = new TablePropertiesBuilder();
196             propertyBld.setTableFeatureProperties(properties);
197             tableFeature.setTableProperties(propertyBld.build());
198         }
199         return tableFeature;
200     }
201
202     private TableFeaturePropertiesBuilder createApplyActionsMissTblFeatureProp() {
203         TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
204
205         //To set the ApplyActionsMiss
206         List<Action> actionList = new ArrayList<>();
207         ActionBuilder ab = new ActionBuilder();
208
209         ab.setAction(new PopMplsActionCaseBuilder().build());
210         actionList.add(ab.build());
211
212         tableFeatureProperty.setTableFeaturePropType(
213             new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table
214                 .feature.prop.type.ApplyActionsMissBuilder()
215                         .setApplyActionsMiss(new ApplyActionsMissBuilder().setAction(actionList).build()).build());
216
217         TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
218         tableFeatureProperty.withKey(keyValue);
219         tableFeatureProperty.setOrder(1);
220
221         return tableFeatureProperty;
222
223     }
224
225     private TableFeaturePropertiesBuilder createApplyActionsTblFeatureProp() {
226         TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
227         List<Action> actionListt5 = new ArrayList<>();
228         ActionBuilder abt5 = new ActionBuilder();
229
230         abt5.setAction(new PopMplsActionCaseBuilder().build());
231         actionListt5.add(abt5.build());
232
233         tableFeatureProperty.setTableFeaturePropType(
234             new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table
235                 .feature.prop.type.ApplyActionsBuilder()
236                         .setApplyActions(new ApplyActionsBuilder().setAction(actionListt5).build()).build());
237
238         TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
239         tableFeatureProperty.withKey(keyValue);
240         tableFeatureProperty.setOrder(1);
241
242         return tableFeatureProperty;
243     }
244
245     private TableFeaturePropertiesBuilder createNextTblFeatureProp() {
246         TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
247         List<Uint8> nextTblIds = Arrays.asList(Uint8.valueOf(2), Uint8.valueOf(3));
248         NextTableBuilder nextTblBld = new NextTableBuilder();
249
250         nextTblBld.setTables(new TablesBuilder().setTableIds(nextTblIds).build());
251         tableFeatureProperty.setTableFeaturePropType(nextTblBld.build());
252
253         TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
254         tableFeatureProperty.withKey(keyValue);
255         tableFeatureProperty.setOrder(1);
256
257         return tableFeatureProperty;
258     }
259
260     private TableFeaturePropertiesBuilder createNextTableMissTblFeatureProp() {
261         TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
262         List<Uint8> nextTblMissIds = Arrays.asList(Uint8.valueOf(23), Uint8.valueOf(24), Uint8.valueOf(25),
263             Uint8.valueOf(27), Uint8.valueOf(28), Uint8.valueOf(29), Uint8.valueOf(30));
264         NextTableMissBuilder nextTblMissBld = new NextTableMissBuilder();
265
266         nextTblMissBld.setTablesMiss(new TablesMissBuilder().setTableIds(nextTblMissIds).build());
267         tableFeatureProperty.setTableFeaturePropType(nextTblMissBld.build());
268
269         TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
270         tableFeatureProperty.withKey(keyValue);
271         tableFeatureProperty.setOrder(1);
272
273         return tableFeatureProperty;
274     }
275
276
277     private TableFeaturePropertiesBuilder createInstructionsTblFeatureProp() {
278         List<Instruction> instLst = new ArrayList<>();
279         TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
280         tableFeatureProperty.setTableFeaturePropType(
281             new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table
282                 .feature.prop.type.InstructionsBuilder().setInstructions(
283                     new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type
284                         .table.feature.prop.type.instructions.InstructionsBuilder().setInstruction(instLst).build())
285                             .build());
286
287
288         TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
289         tableFeatureProperty.withKey(keyValue);
290         tableFeatureProperty.setOrder(1);
291
292         return tableFeatureProperty;
293     }
294
295     private TableFeaturePropertiesBuilder createInstructionsMissTblFeatureProp() {
296         // To set the instructions miss -- "t7"
297
298         List<Instruction> instLst = new ArrayList<>();
299         TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
300         tableFeatureProperty.setTableFeaturePropType(
301             new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table
302                 .feature.prop.type.InstructionsMissBuilder().setInstructionsMiss(
303                     new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type
304                         .table.feature.prop.type.instructions.miss.InstructionsMissBuilder().setInstruction(instLst)
305                             .build()).build());
306
307
308         TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
309         tableFeatureProperty.withKey(keyValue);
310         tableFeatureProperty.setOrder(1);
311
312         return tableFeatureProperty;
313     }
314
315     private TableFeaturePropertiesBuilder createWriteActionsTblFeatureProp() {
316         // t8
317
318         List<Action> actionList = new ArrayList<>();
319
320         ActionBuilder abt1 = new ActionBuilder();
321         abt1.setAction(new CopyTtlOutCaseBuilder().build());
322         actionList.add(abt1.build());
323
324         ActionBuilder abt2 = new ActionBuilder();
325         abt2.setAction(new PopVlanActionCaseBuilder().build());
326         actionList.add(abt2.build());
327
328         TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
329         tableFeatureProperty.setTableFeaturePropType(
330             new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table
331                 .feature.prop.type.WriteActionsBuilder().setWriteActions(new org.opendaylight.yang.gen.v1.urn
332                     .opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.write.actions
333                         .WriteActionsBuilder().setAction(actionList).build()).build());
334
335         TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
336         tableFeatureProperty.withKey(keyValue);
337         tableFeatureProperty.setOrder(1);
338
339         return tableFeatureProperty;
340     }
341
342     private TableFeaturePropertiesBuilder createWriteActionsMissTblFeatureProp() {
343         // t9
344         List<Action> actionList = new ArrayList<>();
345
346         ActionBuilder abt1 = new ActionBuilder();
347         abt1.setAction(new CopyTtlInCaseBuilder().build());
348         actionList.add(abt1.build());
349
350         ActionBuilder abt2 = new ActionBuilder();
351         abt2.setAction(new PushPbbActionCaseBuilder().build());
352         actionList.add(abt2.build());
353
354         TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
355         tableFeatureProperty.setTableFeaturePropType(
356             new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table
357                 .feature.prop.type.WriteActionsMissBuilder().setWriteActionsMiss(new org.opendaylight.yang.gen.v1.urn
358                     .opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.write.actions
359                         .miss.WriteActionsMissBuilder().setAction(actionList).build()).build());
360
361         TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
362         tableFeatureProperty.withKey(keyValue);
363         tableFeatureProperty.setOrder(1);
364
365         return tableFeatureProperty;
366     }
367
368     private TableFeaturePropertiesBuilder createMatchFieldTblFeatureProp() {
369         //t10
370
371         List<SetFieldMatch> setFieldMatch = new ArrayList<>();
372         SetFieldMatchBuilder setFieldMatchBld = new SetFieldMatchBuilder();
373         setFieldMatchBld.setHasMask(false);
374         setFieldMatchBld.setMatchType(MplsLabel.class);
375
376
377         setFieldMatch.add(setFieldMatchBld.build());
378         MatchBuilder matchBld = new MatchBuilder();
379         MatchSetfieldBuilder matchSetfieldBld = new MatchSetfieldBuilder();
380         matchSetfieldBld.setSetFieldMatch(setFieldMatch);
381         matchBld.setMatchSetfield(matchSetfieldBld.build());
382
383         TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
384         tableFeatureProperty.setTableFeaturePropType(matchBld.build());
385         TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
386         tableFeatureProperty.withKey(keyValue);
387         tableFeatureProperty.setOrder(1);
388
389         return tableFeatureProperty;
390     }
391
392
393     private TableFeaturePropertiesBuilder createWriteSetFieldTblFeatureProp() {
394         //t11
395
396         SetFieldMatchBuilder setFieldMatchBld1 = new SetFieldMatchBuilder();
397         setFieldMatchBld1.setHasMask(false);
398         setFieldMatchBld1.setMatchType(MplsLabel.class);
399
400         SetFieldMatchBuilder setFieldMatchBld2 = new SetFieldMatchBuilder();
401         setFieldMatchBld2.setHasMask(true);
402         setFieldMatchBld2.setMatchType(MplsBos.class);
403
404         SetFieldMatchBuilder setFieldMatchBld3 = new SetFieldMatchBuilder();
405         setFieldMatchBld3.setHasMask(true);
406         setFieldMatchBld3.setMatchType(EthDst.class);
407
408         List<SetFieldMatch> setFieldMatch = new ArrayList<>();
409         setFieldMatch.add(setFieldMatchBld1.build());
410         setFieldMatch.add(setFieldMatchBld2.build());
411         setFieldMatch.add(setFieldMatchBld3.build());
412
413         WriteSetfieldBuilder writeSetfieldBld = new WriteSetfieldBuilder();
414         org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop
415             .type.write.setfield.WriteSetfieldBuilder writeSetfieldBuilder =
416                 new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table
417                     .feature.prop.type.write.setfield.WriteSetfieldBuilder();
418         writeSetfieldBuilder.setSetFieldMatch(setFieldMatch);
419         writeSetfieldBld.setWriteSetfield(writeSetfieldBuilder.build());
420
421         TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
422         tableFeatureProperty.setTableFeaturePropType(writeSetfieldBld.build());
423         TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
424         tableFeatureProperty.withKey(keyValue);
425         tableFeatureProperty.setOrder(1);
426
427         return tableFeatureProperty;
428     }
429
430     private TableFeaturePropertiesBuilder createWriteSetFieldMissTblFeatureProp() {
431         // t12
432
433         SetFieldMatchBuilder setFieldMatchBld1 = new SetFieldMatchBuilder();
434         setFieldMatchBld1.setHasMask(false);
435         setFieldMatchBld1.setMatchType(EthSrc.class);
436
437         SetFieldMatchBuilder setFieldMatchBld2 = new SetFieldMatchBuilder();
438         setFieldMatchBld2.setHasMask(true);
439         setFieldMatchBld2.setMatchType(InPort.class);
440
441         SetFieldMatchBuilder setFieldMatchBld3 = new SetFieldMatchBuilder();
442         setFieldMatchBld3.setHasMask(true);
443         setFieldMatchBld3.setMatchType(Ipv4Dst.class);
444
445         List<SetFieldMatch> setFieldMatch = new ArrayList<>();
446         setFieldMatch.add(setFieldMatchBld1.build());
447         setFieldMatch.add(setFieldMatchBld2.build());
448         setFieldMatch.add(setFieldMatchBld3.build());
449
450         WriteSetfieldMissBuilder writeSetfieldBld = new WriteSetfieldMissBuilder();
451         org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop
452             .type.write.setfield.miss.WriteSetfieldMissBuilder writeSetfieldMissBuilder =
453                 new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table
454                     .feature.prop.type.write.setfield.miss.WriteSetfieldMissBuilder();
455         writeSetfieldMissBuilder.setSetFieldMatch(setFieldMatch);
456         writeSetfieldBld.setWriteSetfieldMiss(writeSetfieldMissBuilder.build());
457
458         TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
459         tableFeatureProperty.setTableFeaturePropType(writeSetfieldBld.build());
460         TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
461         tableFeatureProperty.withKey(keyValue);
462         tableFeatureProperty.setOrder(1);
463
464         return tableFeatureProperty;
465     }
466
467     private TableFeaturePropertiesBuilder createApplySetFieldTblFeatureProp() {
468         //t13
469
470         SetFieldMatchBuilder setFieldMatchBld1 = new SetFieldMatchBuilder();
471         setFieldMatchBld1.setHasMask(false);
472         setFieldMatchBld1.setMatchType(ArpOp.class);
473
474         SetFieldMatchBuilder setFieldMatchBld2 = new SetFieldMatchBuilder();
475         setFieldMatchBld2.setHasMask(true);
476         setFieldMatchBld2.setMatchType(InPort.class);
477
478         SetFieldMatchBuilder setFieldMatchBld3 = new SetFieldMatchBuilder();
479         setFieldMatchBld3.setHasMask(true);
480         setFieldMatchBld3.setMatchType(Ipv4Dst.class);
481
482         List<SetFieldMatch> setFieldMatch = new ArrayList<>();
483         setFieldMatch.add(setFieldMatchBld1.build());
484         setFieldMatch.add(setFieldMatchBld2.build());
485         setFieldMatch.add(setFieldMatchBld3.build());
486
487         ApplySetfieldBuilder applySetfieldBld = new ApplySetfieldBuilder();
488         org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop
489             .type.apply.setfield.ApplySetfieldBuilder applySetfieldBuilder =
490                 new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table
491                     .feature.prop.type.apply.setfield.ApplySetfieldBuilder();
492         applySetfieldBuilder.setSetFieldMatch(setFieldMatch);
493         applySetfieldBld.setApplySetfield(applySetfieldBuilder.build());
494
495         TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
496         tableFeatureProperty.setTableFeaturePropType(applySetfieldBld.build());
497         TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
498         tableFeatureProperty.withKey(keyValue);
499         tableFeatureProperty.setOrder(1);
500
501         return tableFeatureProperty;
502     }
503
504     private TableFeaturePropertiesBuilder createApplySetFieldMissTblFeatureProp() {
505         //t14
506
507         SetFieldMatchBuilder setFieldMatchBld1 = new SetFieldMatchBuilder();
508         setFieldMatchBld1.setHasMask(false);
509         setFieldMatchBld1.setMatchType(ArpOp.class);
510
511         SetFieldMatchBuilder setFieldMatchBld2 = new SetFieldMatchBuilder();
512         setFieldMatchBld2.setHasMask(true);
513         setFieldMatchBld2.setMatchType(InPort.class);
514
515         SetFieldMatchBuilder setFieldMatchBld3 = new SetFieldMatchBuilder();
516         setFieldMatchBld3.setHasMask(true);
517         setFieldMatchBld3.setMatchType(Ipv4Dst.class);
518
519         List<SetFieldMatch> setFieldMatch = new ArrayList<>();
520         setFieldMatch.add(setFieldMatchBld1.build());
521         setFieldMatch.add(setFieldMatchBld2.build());
522         setFieldMatch.add(setFieldMatchBld3.build());
523
524         ApplySetfieldMissBuilder applySetfieldMissBld = new ApplySetfieldMissBuilder();
525         org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop
526             .type.apply.setfield.miss.ApplySetfieldMissBuilder applySetfieldMissBuilder =
527                 new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table
528                     .feature.prop.type.apply.setfield.miss.ApplySetfieldMissBuilder();
529         applySetfieldMissBuilder.setSetFieldMatch(setFieldMatch);
530         applySetfieldMissBld.setApplySetfieldMiss(applySetfieldMissBuilder.build());
531
532         TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
533         tableFeatureProperty.setTableFeaturePropType(applySetfieldMissBld.build());
534         TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
535         tableFeatureProperty.withKey(keyValue);
536         tableFeatureProperty.setOrder(1);
537
538         return tableFeatureProperty;
539     }
540
541     private TableFeaturePropertiesBuilder createWildCardsTblFeatureProp() {
542         //t15
543
544         SetFieldMatchBuilder setFieldMatchBld1 = new SetFieldMatchBuilder();
545         setFieldMatchBld1.setHasMask(false);
546         setFieldMatchBld1.setMatchType(ArpOp.class);
547
548         SetFieldMatchBuilder setFieldMatchBld2 = new SetFieldMatchBuilder();
549         setFieldMatchBld2.setHasMask(true);
550         setFieldMatchBld2.setMatchType(InPort.class);
551
552         List<SetFieldMatch> setFieldMatch = new ArrayList<>();
553         setFieldMatch.add(setFieldMatchBld1.build());
554         setFieldMatch.add(setFieldMatchBld2.build());
555
556         WildcardsBuilder wildCardsBld = new WildcardsBuilder();
557         WildcardSetfieldBuilder wildcardsBuilder =
558                 new WildcardSetfieldBuilder();
559         wildcardsBuilder.setSetFieldMatch(setFieldMatch);
560         wildCardsBld.setWildcardSetfield(wildcardsBuilder.build());
561
562         TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
563         tableFeatureProperty.setTableFeaturePropType(wildCardsBld.build());
564         TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
565         tableFeatureProperty.withKey(keyValue);
566         tableFeatureProperty.setOrder(1);
567
568         return tableFeatureProperty;
569     }
570
571     private void writeTableFeatures(final CommandInterpreter ci, TableFeatures tableFeatures) {
572         ReadWriteTransaction modification = Preconditions.checkNotNull(dataBroker).newReadWriteTransaction();
573
574         KeyedInstanceIdentifier<TableFeatures, TableFeaturesKey> path1 = InstanceIdentifier.create(Nodes.class)
575                 .child(Node.class, testNode.key()).augmentation(FlowCapableNode.class)
576                         .child(TableFeatures.class, new TableFeaturesKey(tableFeatures.getTableId()));
577
578         modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, nodeToInstanceId(testNode), testNode);
579         modification.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, path1, tableFeatures);
580         modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode),
581                 testNode);
582         modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, path1, tableFeatures);
583         modification.commit().addCallback(new FutureCallback<Object>() {
584             @Override
585             public void onSuccess(Object notUsed) {
586                 ci.println("Status of Group Data Loaded Transaction: success.");
587             }
588
589             @Override
590             public void onFailure(Throwable throwable) {
591                 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
592             }
593         }, MoreExecutors.directExecutor());
594     }
595
596     public void _modifyTable(CommandInterpreter ci) {
597         String nref = ci.nextArgument();
598         ci.println(" Table Command Provider modify");
599
600         if (nref == null) {
601             ci.println("test node added");
602             createTestNode();
603         } else {
604             ci.println("User node added" + nref);
605             createUserNode(nref);
606         }
607         String tableFeatureType = ci.nextArgument();
608         TableFeaturesBuilder tableFeaturesBld = createTestTableFeatures(tableFeatureType);
609
610         writeTableFeatures(ci, tableFeaturesBld.build());
611     }
612
613     @Override
614     public String getHelp() {
615         StringBuilder help = new StringBuilder();
616         help.append("---FRM MD-SAL Table test module---\n");
617         help.append("\t modifyTable <node id>        - node ref\n");
618
619         return help.toString();
620     }
621 }
622