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