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