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