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: usha.m.s@ericsson.com
10 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
12 import org.junit.Assert;
13 import org.junit.Test;
14 import org.opendaylight.openflowplugin.api.OFConstants;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowTableRef;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
40 import org.opendaylight.yangtools.yang.binding.Augmentation;
41 import org.opendaylight.yangtools.yang.binding.DataContainer;
43 import java.math.BigInteger;
44 import java.util.Arrays;
45 import java.util.Collections;
46 import java.util.List;
49 * test for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor}
51 public class FlowConverterTest {
55 public void testCloneAndAugmentFlowWithSetVlanId() {
56 MockFlow mockFlow = new MockFlow();
57 Action action1 = createAction(
58 new SetVlanIdActionCaseBuilder().setSetVlanIdAction(
59 new SetVlanIdActionBuilder().setVlanId(new VlanId(10)).build())
63 mockFlow.setMatch(new MatchBuilder().setEthernetMatch(createEthernetMatch()).build());
64 mockFlow.setInstructions(toApplyInstruction(Collections.singletonList(action1)));
66 List<FlowModInputBuilder> flowModInputBuilders =
67 FlowConvertor.toFlowModInputs(mockFlow, OFConstants.OFP_VERSION_1_3, BigInteger.ONE);
68 Assert.assertEquals(2, flowModInputBuilders.size());
72 private Action createAction(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionCase,
74 Action action = new ActionBuilder().setOrder(order).setAction(actionCase).build();
78 private EthernetMatch createEthernetMatch() {
79 EthernetMatchBuilder ethernetMatchBuilder = new EthernetMatchBuilder();
80 ethernetMatchBuilder.setEthernetType(new EthernetTypeBuilder().setType(new EtherType(33024L)).build());
81 return ethernetMatchBuilder.build();
84 private Instructions toApplyInstruction(
85 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actions) {
86 return new InstructionsBuilder()
88 Collections.singletonList(
89 new InstructionBuilder()
92 new ApplyActionsCaseBuilder()
93 .setApplyActions((new ApplyActionsBuilder()).setAction(actions).build())
99 private Flow createFlowWithActions(Action...actions) {
100 MockFlow mockFlow = new MockFlow();
101 mockFlow.setInstructions(toApplyInstruction(Arrays.asList(actions)));
105 private class MockFlow implements AddFlowInput {
106 private Instructions instructions;
109 public void setInstructions(Instructions instructions) {
110 this.instructions = instructions;
113 public void setMatch(Match match) {
119 public FlowRef getFlowRef() {
124 public <E extends Augmentation<AddFlowInput>> E getAugmentation(Class<E> augmentationType) {
129 public FlowTableRef getFlowTable() {
134 public Match getMatch() {
139 public Instructions getInstructions() {
144 public String getContainerName() {
149 public FlowCookie getCookieMask() {
154 public Long getBufferId() {
159 public BigInteger getOutPort() {
164 public Long getOutGroup() {
169 public FlowModFlags getFlags() {
174 public String getFlowName() {
179 public Boolean isInstallHw() {
184 public Boolean isBarrier() {
189 public Boolean isStrict() {
194 public Integer getPriority() {
199 public Integer getIdleTimeout() {
204 public Integer getHardTimeout() {
209 public FlowCookie getCookie() {
214 public Short getTableId() {
219 public NodeRef getNode() {
224 public Uri getTransactionUri() {
229 public Class<? extends DataContainer> getImplementedInterface() {