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