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