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