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