2 * Copyright (c) 2014 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
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
8 * Contributor: hema.gopalkrishnan@ericsson.com
10 package org.opendaylight.openflowplugin.test;
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;
79 public class OpenflowpluginTableFeaturesTestCommandProvider implements CommandProvider {
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";
89 public OpenflowpluginTableFeaturesTestCommandProvider(BundleContext ctx) {
93 public void onSessionInitiated(ProviderContext session) {
95 dataBroker = session.getSALService(DataBroker.class);
96 ctx.registerService(CommandProvider.class.getName(), this, null);
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();
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();
115 private InstanceIdentifier<Node> nodeToInstanceId(Node node) {
116 return InstanceIdentifier.create(Nodes.class).child(Node.class, node.getKey());
119 private TableBuilder createTestTable(String tableFeatureTypeArg) {
121 String tableFeatureType = tableFeatureTypeArg;
122 if (tableFeatureType == null) {
123 tableFeatureType = "t1";
125 // Sample data , committing to DataStore
127 TableKey key = new TableKey(id);
129 TableBuilder table = new TableBuilder();
130 table.setId((short) 12);
135 List<TableFeatures> ofTablefeatures = new ArrayList<TableFeatures>();
137 // Skip this to send empty table features
138 if (!tableFeatureType.equals("t1")) {
141 TableFeaturesBuilder tableFeature1 = new TableFeaturesBuilder();
142 tableFeature1.setTableId((short) 0);
143 tableFeature1.setName("Table 0");
146 tableFeature1.setMetadataMatch(BigInteger.valueOf(10));
147 tableFeature1.setMetadataWrite(BigInteger.valueOf(10));
148 tableFeature1.setMaxEntries(10000L);
150 tableFeature1.setConfig(new TableConfig(false));
152 List<TableFeatureProperties> properties = new ArrayList<TableFeatureProperties>();
155 switch (tableFeatureType) {
157 //To set the ApplyActionsMiss
158 properties.add(createApplyActionsMissTblFeatureProp().build());
161 // To set the Next Table
162 properties.add(createNextTblFeatureProp().build());
165 // To set the Next Table Miss
166 properties.add(createNextTableMissTblFeatureProp().build());
169 //To set the ApplyActions
170 properties.add(createApplyActionsTblFeatureProp().build());
173 // To set the instructions
174 properties.add(createInstructionsTblFeatureProp().build());
177 // To set the instructions miss
178 properties.add(createInstructionsMissTblFeatureProp().build());
181 // To set the write actions
182 properties.add(createWriteActionsTblFeatureProp().build());
185 // To set the write actions miss
186 properties.add(createWriteActionsMissTblFeatureProp().build());
189 // To set the match field
190 properties.add(createMatchFieldTblFeatureProp().build());
193 // To set the write set-field
194 properties.add(createWriteSetFieldTblFeatureProp().build());
197 // To set the write set-field miss
198 properties.add(createWriteSetFieldMissTblFeatureProp().build());
201 // To set the apply set field
202 properties.add(createApplySetFieldTblFeatureProp().build());
205 // To set the apply set field miss
206 properties.add(createApplySetFieldMissTblFeatureProp().build());
209 // To set the wildcards set field match
210 properties.add(createWildCardsTblFeatureProp().build());
215 TablePropertiesBuilder propertyBld = new TablePropertiesBuilder();
216 propertyBld.setTableFeatureProperties(properties);
217 tableFeature1.setTableProperties(propertyBld.build());
220 ofTablefeatures.add(tableFeature1.build());
223 table.setTableFeatures(ofTablefeatures);
225 testTable = table.build();
229 private TableFeaturePropertiesBuilder createApplyActionsMissTblFeatureProp() {
230 TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
232 //To set the ApplyActionsMiss
233 List<Action> actionList = new ArrayList<Action>();
234 ActionBuilder ab = new ActionBuilder();
236 ab.setAction(new PopMplsActionCaseBuilder().build());
237 actionList.add(ab.build());
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());
243 TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
244 tableFeatureProperty.setKey(keyValue);
245 tableFeatureProperty.setOrder(1);
247 return tableFeatureProperty;
251 private TableFeaturePropertiesBuilder createApplyActionsTblFeatureProp() {
252 TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
253 List<Action> actionListt5 = new ArrayList<Action>();
254 ActionBuilder abt5 = new ActionBuilder();
256 abt5.setAction(new PopMplsActionCaseBuilder().build());
257 actionListt5.add(abt5.build());
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());
263 TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
264 tableFeatureProperty.setKey(keyValue);
265 tableFeatureProperty.setOrder(1);
267 return tableFeatureProperty;
270 private TableFeaturePropertiesBuilder createNextTblFeatureProp() {
271 TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
272 List<Short> nextTblIds = Arrays.asList(new Short[]{2, 3});
273 NextTableBuilder nextTblBld = new NextTableBuilder();
275 nextTblBld.setTables(new TablesBuilder().setTableIds(nextTblIds).build());
276 tableFeatureProperty.setTableFeaturePropType(nextTblBld.build());
278 TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
279 tableFeatureProperty.setKey(keyValue);
280 tableFeatureProperty.setOrder(1);
282 return tableFeatureProperty;
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();
290 nextTblMissBld.setTablesMiss(new TablesMissBuilder().setTableIds(nextTblMissIds).build());
291 tableFeatureProperty.setTableFeaturePropType(nextTblMissBld.build());
293 TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
294 tableFeatureProperty.setKey(keyValue);
295 tableFeatureProperty.setOrder(1);
297 return tableFeatureProperty;
301 private TableFeaturePropertiesBuilder createInstructionsTblFeatureProp() {
302 TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
304 List<Instruction> instLst = new ArrayList<Instruction>();
305 InstructionBuilder ib = new InstructionBuilder();
307 ib.setInstruction(new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder().build());
308 ib.setKey(new InstructionKey(1));
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());
315 TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
316 tableFeatureProperty.setKey(keyValue);
317 tableFeatureProperty.setOrder(1);
319 return tableFeatureProperty;
322 private TableFeaturePropertiesBuilder createInstructionsMissTblFeatureProp() {
323 // To set the instructions miss -- "t7"
324 TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
326 List<Instruction> instLst = new ArrayList<Instruction>();
327 InstructionBuilder ib1 = new InstructionBuilder();
329 ib1.setInstruction(new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCaseBuilder().build());
330 ib1.setKey(new InstructionKey(1));
332 InstructionBuilder ib2 = new InstructionBuilder();
334 ib2.setInstruction(new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCaseBuilder().build());
335 ib2.setKey(new InstructionKey(2));
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());
342 TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
343 tableFeatureProperty.setKey(keyValue);
344 tableFeatureProperty.setOrder(1);
346 return tableFeatureProperty;
349 private TableFeaturePropertiesBuilder createWriteActionsTblFeatureProp() {
351 TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
353 List<Action> actionList = new ArrayList<Action>();
355 ActionBuilder abt1 = new ActionBuilder();
356 abt1.setAction(new CopyTtlOutCaseBuilder().build());
357 actionList.add(abt1.build());
359 ActionBuilder abt2 = new ActionBuilder();
360 abt2.setAction(new PopVlanActionCaseBuilder().build());
361 actionList.add(abt2.build());
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());
367 TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
368 tableFeatureProperty.setKey(keyValue);
369 tableFeatureProperty.setOrder(1);
371 return tableFeatureProperty;
374 private TableFeaturePropertiesBuilder createWriteActionsMissTblFeatureProp() {
376 TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
378 List<Action> actionList = new ArrayList<Action>();
380 ActionBuilder abt1 = new ActionBuilder();
381 abt1.setAction(new CopyTtlInCaseBuilder().build());
382 actionList.add(abt1.build());
384 ActionBuilder abt2 = new ActionBuilder();
385 abt2.setAction(new PushPbbActionCaseBuilder().build());
386 actionList.add(abt2.build());
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());
392 TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
393 tableFeatureProperty.setKey(keyValue);
394 tableFeatureProperty.setOrder(1);
396 return tableFeatureProperty;
399 private TableFeaturePropertiesBuilder createMatchFieldTblFeatureProp() {
401 TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
404 List<SetFieldMatch> setFieldMatch = new ArrayList<SetFieldMatch>();
405 SetFieldMatchBuilder setFieldMatchBld = new SetFieldMatchBuilder();
406 setFieldMatchBld.setHasMask(false);
407 setFieldMatchBld.setMatchType(MplsLabel.class);
410 setFieldMatch.add(setFieldMatchBld.build());
411 MatchBuilder matchBld = new MatchBuilder();
412 MatchSetfieldBuilder matchSetfieldBld = new MatchSetfieldBuilder();
413 matchSetfieldBld.setSetFieldMatch(setFieldMatch);
414 matchBld.setMatchSetfield(matchSetfieldBld.build());
416 tableFeatureProperty.setTableFeaturePropType(matchBld.build());
417 TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
418 tableFeatureProperty.setKey(keyValue);
419 tableFeatureProperty.setOrder(1);
421 return tableFeatureProperty;
425 private TableFeaturePropertiesBuilder createWriteSetFieldTblFeatureProp() {
427 TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
429 List<SetFieldMatch> setFieldMatch = new ArrayList<SetFieldMatch>();
430 SetFieldMatchBuilder setFieldMatchBld1 = new SetFieldMatchBuilder();
431 setFieldMatchBld1.setHasMask(false);
432 setFieldMatchBld1.setMatchType(MplsLabel.class);
434 SetFieldMatchBuilder setFieldMatchBld2 = new SetFieldMatchBuilder();
435 setFieldMatchBld2.setHasMask(true);
436 setFieldMatchBld2.setMatchType(MplsBos.class);
438 SetFieldMatchBuilder setFieldMatchBld3 = new SetFieldMatchBuilder();
439 setFieldMatchBld3.setHasMask(true);
440 setFieldMatchBld3.setMatchType(EthDst.class);
442 setFieldMatch.add(setFieldMatchBld1.build());
443 setFieldMatch.add(setFieldMatchBld2.build());
444 setFieldMatch.add(setFieldMatchBld3.build());
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());
453 tableFeatureProperty.setTableFeaturePropType(writeSetfieldBld.build());
454 TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
455 tableFeatureProperty.setKey(keyValue);
456 tableFeatureProperty.setOrder(1);
458 return tableFeatureProperty;
461 private TableFeaturePropertiesBuilder createWriteSetFieldMissTblFeatureProp() {
463 TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
465 List<SetFieldMatch> setFieldMatch = new ArrayList<SetFieldMatch>();
466 SetFieldMatchBuilder setFieldMatchBld1 = new SetFieldMatchBuilder();
467 setFieldMatchBld1.setHasMask(false);
468 setFieldMatchBld1.setMatchType(EthSrc.class);
470 SetFieldMatchBuilder setFieldMatchBld2 = new SetFieldMatchBuilder();
471 setFieldMatchBld2.setHasMask(true);
472 setFieldMatchBld2.setMatchType(InPort.class);
474 SetFieldMatchBuilder setFieldMatchBld3 = new SetFieldMatchBuilder();
475 setFieldMatchBld3.setHasMask(true);
476 setFieldMatchBld3.setMatchType(Ipv4Dst.class);
478 setFieldMatch.add(setFieldMatchBld1.build());
479 setFieldMatch.add(setFieldMatchBld2.build());
480 setFieldMatch.add(setFieldMatchBld3.build());
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());
488 tableFeatureProperty.setTableFeaturePropType(writeSetfieldBld.build());
489 TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
490 tableFeatureProperty.setKey(keyValue);
491 tableFeatureProperty.setOrder(1);
493 return tableFeatureProperty;
496 private TableFeaturePropertiesBuilder createApplySetFieldTblFeatureProp() {
498 TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
500 List<SetFieldMatch> setFieldMatch = new ArrayList<SetFieldMatch>();
501 SetFieldMatchBuilder setFieldMatchBld1 = new SetFieldMatchBuilder();
502 setFieldMatchBld1.setHasMask(false);
503 setFieldMatchBld1.setMatchType(ArpOp.class);
505 SetFieldMatchBuilder setFieldMatchBld2 = new SetFieldMatchBuilder();
506 setFieldMatchBld2.setHasMask(true);
507 setFieldMatchBld2.setMatchType(InPort.class);
509 SetFieldMatchBuilder setFieldMatchBld3 = new SetFieldMatchBuilder();
510 setFieldMatchBld3.setHasMask(true);
511 setFieldMatchBld3.setMatchType(Ipv4Dst.class);
513 setFieldMatch.add(setFieldMatchBld1.build());
514 setFieldMatch.add(setFieldMatchBld2.build());
515 setFieldMatch.add(setFieldMatchBld3.build());
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());
523 tableFeatureProperty.setTableFeaturePropType(applySetfieldBld.build());
524 TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
525 tableFeatureProperty.setKey(keyValue);
526 tableFeatureProperty.setOrder(1);
528 return tableFeatureProperty;
531 private TableFeaturePropertiesBuilder createApplySetFieldMissTblFeatureProp() {
533 TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
535 List<SetFieldMatch> setFieldMatch = new ArrayList<SetFieldMatch>();
536 SetFieldMatchBuilder setFieldMatchBld1 = new SetFieldMatchBuilder();
537 setFieldMatchBld1.setHasMask(false);
538 setFieldMatchBld1.setMatchType(ArpOp.class);
540 SetFieldMatchBuilder setFieldMatchBld2 = new SetFieldMatchBuilder();
541 setFieldMatchBld2.setHasMask(true);
542 setFieldMatchBld2.setMatchType(InPort.class);
544 SetFieldMatchBuilder setFieldMatchBld3 = new SetFieldMatchBuilder();
545 setFieldMatchBld3.setHasMask(true);
546 setFieldMatchBld3.setMatchType(Ipv4Dst.class);
548 setFieldMatch.add(setFieldMatchBld1.build());
549 setFieldMatch.add(setFieldMatchBld2.build());
550 setFieldMatch.add(setFieldMatchBld3.build());
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());
558 tableFeatureProperty.setTableFeaturePropType(applySetfieldMissBld.build());
559 TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
560 tableFeatureProperty.setKey(keyValue);
561 tableFeatureProperty.setOrder(1);
563 return tableFeatureProperty;
566 private TableFeaturePropertiesBuilder createWildCardsTblFeatureProp() {
568 TableFeaturePropertiesBuilder tableFeatureProperty = new TableFeaturePropertiesBuilder();
570 List<SetFieldMatch> setFieldMatch = new ArrayList<SetFieldMatch>();
571 SetFieldMatchBuilder setFieldMatchBld1 = new SetFieldMatchBuilder();
572 setFieldMatchBld1.setHasMask(false);
573 setFieldMatchBld1.setMatchType(ArpOp.class);
575 SetFieldMatchBuilder setFieldMatchBld2 = new SetFieldMatchBuilder();
576 setFieldMatchBld2.setHasMask(true);
577 setFieldMatchBld2.setMatchType(InPort.class);
580 setFieldMatch.add(setFieldMatchBld1.build());
581 setFieldMatch.add(setFieldMatchBld2.build());
583 WildcardsBuilder wildCardsBld = new WildcardsBuilder();
584 WildcardSetfieldBuilder wildcardsBuilder =
585 new WildcardSetfieldBuilder();
586 wildcardsBuilder.setSetFieldMatch(setFieldMatch);
587 wildCardsBld.setWildcardSetfield(wildcardsBuilder.build());
589 tableFeatureProperty.setTableFeaturePropType(wildCardsBld.build());
590 TableFeaturePropertiesKey keyValue = new TableFeaturePropertiesKey(0);
591 tableFeatureProperty.setKey(keyValue);
592 tableFeatureProperty.setOrder(1);
594 return tableFeatureProperty;
598 private void writeTable(final CommandInterpreter ci, Table table) {
599 ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
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()));
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>() {
613 public void onSuccess(Void aVoid) {
614 ci.println("Status of Group Data Loaded Transaction: success.");
618 public void onFailure(Throwable throwable) {
619 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
624 public void _modifyTable(CommandInterpreter ci) {
625 String nref = ci.nextArgument();
626 ci.println(" Table Command Provider modify");
629 ci.println("test node added");
632 ci.println("User node added" + nref);
633 createUserNode(nref);
635 String tableFeatureType = ci.nextArgument();
636 TableBuilder table = createTestTable(tableFeatureType);
638 writeTable(ci, table.build());
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");
647 return help.toString();