2 * Copyright (c) 2014 Cisco Systems, Inc. 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 package org.opendaylight.controller.sal.binding.test.bugfix;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
14 import java.util.ArrayList;
15 import java.util.Collections;
16 import java.util.List;
17 import java.util.concurrent.Callable;
18 import java.util.concurrent.ExecutorService;
19 import java.util.concurrent.Executors;
21 import org.junit.Ignore;
22 import org.junit.Test;
23 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
24 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
25 import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCaseBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.mpls.action._case.PopMplsActionBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.Flows;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.Flow;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.FlowBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.FlowKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
49 import org.opendaylight.yangtools.yang.binding.DataObject;
50 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
51 import org.opendaylight.yangtools.yang.common.RpcResult;
52 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
54 import com.google.common.util.concurrent.Futures;
55 import com.google.common.util.concurrent.ListenableFuture;
56 import com.google.common.util.concurrent.ListeningExecutorService;
57 import com.google.common.util.concurrent.MoreExecutors;
59 @SuppressWarnings("deprecation")
60 public class DOMCodecBug01Test extends AbstractDataServiceTest {
62 private static final long FLOW_ID = 1234;
63 private static final String NODE_ID = "node:1";
65 private static final NodeKey NODE_KEY = new NodeKey(new NodeId(NODE_ID));
67 private static final InstanceIdentifier<Node> NODE_INSTANCE_ID_BA = InstanceIdentifier.builder(Nodes.class) //
68 .child(Node.class, NODE_KEY).toInstance();
70 private static final NodeRef NODE_REF = new NodeRef(NODE_INSTANCE_ID_BA);
72 private static final FlowKey FLOW_KEY = new FlowKey(FLOW_ID, NODE_REF);
74 private static final InstanceIdentifier<? extends DataObject> FLOW_INSTANCE_ID_BA = //
75 InstanceIdentifier.builder(Flows.class) //
76 .child(Flow.class, FLOW_KEY) //
83 * Testcase for https://bugs.opendaylight.org/show_bug.cgi?id=
85 * Cannot compile CoDec for
86 * org.opendaylight.yang.gen.v1.urn.opendaylight.flow
87 * .config.rev130819.flows.Flow
89 * When invoking following code in the consumer, user got an
90 * IllegalStateException during creation of mapping between Java DTOs and
93 * Exception was compilation error which was caused by incorect generation
96 * Reported by Depthi V V
98 * @deprecated This test tests indirect generation, which should be tested
99 * different way. the test creates conflicting transactions
100 * and assumes correct commit - to test codec generation
106 public void testIndirectGeneration() throws Exception {
108 ExecutorService basePool = Executors.newFixedThreadPool(2);
109 ListeningExecutorService listenablePool = MoreExecutors.listeningDecorator(basePool);
113 Object lock = new Object();
114 CreateFlowTask task1 = new CreateFlowTask(lock);
115 CreateFlowTask task2 = new CreateFlowTask(lock);
116 CreateFlowTask task3 = new CreateFlowTask(lock);
118 ListenableFuture<Void> task1Future = listenablePool.submit(task1);
119 ListenableFuture<Void> task2Future = listenablePool.submit(task2);
120 ListenableFuture<Void> task3Future = listenablePool.submit(task3);
123 @SuppressWarnings("unchecked")
124 ListenableFuture<List<Void>> compositeFuture = Futures.allAsList(task1Future,task2Future,task3Future);
128 compositeFuture.get();
130 verifyDataAreStoredProperly();
132 DataModificationTransaction modification2 = baDataService.beginTransaction();
133 modification2.removeConfigurationData(FLOW_INSTANCE_ID_BA);
135 DataObject originalData = modification2.getOriginalConfigurationData().get(FLOW_INSTANCE_ID_BA);
136 assertNotNull(originalData);
137 RpcResult<TransactionStatus> ret2 = modification2.commit().get();
140 assertEquals(TransactionStatus.COMMITED, ret2.getResult());
142 // Data are not in the store.
143 assertNull(baDataService.readConfigurationData(FLOW_INSTANCE_ID_BA));
147 private void createFlow() throws Exception {
149 DataModificationTransaction modification = baDataService.beginTransaction();
151 FlowBuilder flow = new FlowBuilder();
152 MatchBuilder match = new MatchBuilder();
153 VlanMatchBuilder vlanBuilder = new VlanMatchBuilder();
154 VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
155 VlanId vlanId = new VlanId(10);
156 vlanBuilder.setVlanId(vlanIdBuilder.setVlanId(vlanId).build());
157 match.setVlanMatch(vlanBuilder.build());
159 flow.setKey(FLOW_KEY);
160 flow.setMatch(match.build());
161 flow.setNode(NODE_REF);
162 InstructionsBuilder instructions = new InstructionsBuilder();
163 InstructionBuilder instruction = new InstructionBuilder();
165 instruction.setOrder(10);
166 ApplyActionsBuilder applyActions = new ApplyActionsBuilder();
167 List<Action> actionList = new ArrayList<>();
168 PopMplsActionBuilder popMplsAction = new PopMplsActionBuilder();
169 popMplsAction.setEthernetType(34);
170 actionList.add(new ActionBuilder().setAction(new PopMplsActionCaseBuilder().setPopMplsAction(popMplsAction.build()).build()).setOrder(10).build());
172 applyActions.setAction(actionList );
174 instruction.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(applyActions.build()).build());
177 List<Instruction> instructionList = Collections.<Instruction>singletonList(instruction.build());
178 instructions.setInstruction(instructionList );
180 flow.setInstructions(instructions.build());
181 modification.putConfigurationData(FLOW_INSTANCE_ID_BA, flow.build());
182 RpcResult<TransactionStatus> ret = modification.commit().get();
184 assertEquals(TransactionStatus.COMMITED, ret.getResult());
187 private void createFlow2() throws Exception {
188 DataModificationTransaction modification = baDataService.beginTransaction();
190 FlowKey key = new FlowKey(id, new NodeRef(NODE_INSTANCE_ID_BA));
191 InstanceIdentifier<?> path1;
192 FlowBuilder flow = new FlowBuilder();
194 MatchBuilder match = new MatchBuilder();
195 match.setLayer4Match(new TcpMatchBuilder().build());
196 flow.setMatch(match.build());
198 path1 = InstanceIdentifier.builder(Flows.class).child(Flow.class, key).toInstance();
199 // DataObject cls = (DataObject) modification.readConfigurationData(path1);
200 modification.putConfigurationData(path1, flow.build());
201 modification.commit();
205 private class CreateFlowTask implements Callable<Void> {
207 public CreateFlowTask(final Object startSync) {
213 //startSyncObj ect.wait();
217 } catch (Exception e) {
218 throw new RuntimeException(e);
224 private void verifyDataAreStoredProperly() {
225 CompositeNode biFlows = biDataService.readConfigurationData(org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.of(Flows.QNAME));
226 assertNotNull(biFlows);
227 CompositeNode biFlow = biFlows.getFirstCompositeByName(Flow.QNAME);
228 assertNotNull(biFlow);