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