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 java.math.BigInteger;
13 import java.util.Arrays;
14 import java.util.Collections;
15 import java.util.List;
16 import org.junit.Assert;
17 import org.junit.Test;
18 import org.opendaylight.openflowplugin.api.OFConstants;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowTableRef;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
44 import org.opendaylight.yangtools.yang.binding.Augmentation;
45 import org.opendaylight.yangtools.yang.binding.DataContainer;
48 * test for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor}
50 public class FlowConverterTest {
54 public void testCloneAndAugmentFlowWithSetVlanId() {
55 MockFlow mockFlow = new MockFlow();
56 Action action1 = createAction(
57 new SetVlanIdActionCaseBuilder().setSetVlanIdAction(
58 new SetVlanIdActionBuilder().setVlanId(new VlanId(10)).build())
62 mockFlow.setMatch(new MatchBuilder().setEthernetMatch(createEthernetMatch()).build());
63 mockFlow.setInstructions(toApplyInstruction(Collections.singletonList(action1)));
65 List<FlowModInputBuilder> flowModInputBuilders =
66 FlowConvertor.toFlowModInputs(mockFlow, OFConstants.OFP_VERSION_1_3, BigInteger.ONE);
67 Assert.assertEquals(2, flowModInputBuilders.size());
71 private static Action createAction(final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionCase,
73 Action action = new ActionBuilder().setOrder(order).setAction(actionCase).build();
77 private static EthernetMatch createEthernetMatch() {
78 EthernetMatchBuilder ethernetMatchBuilder = new EthernetMatchBuilder();
79 ethernetMatchBuilder.setEthernetType(new EthernetTypeBuilder().setType(new EtherType(33024L)).build());
80 return ethernetMatchBuilder.build();
83 private static Instructions toApplyInstruction(
84 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actions) {
85 return new InstructionsBuilder()
87 Collections.singletonList(
88 new InstructionBuilder()
91 new ApplyActionsCaseBuilder()
92 .setApplyActions((new ApplyActionsBuilder()).setAction(actions).build())
98 private static Flow createFlowWithActions(final Action...actions) {
99 MockFlow mockFlow = new MockFlow();
100 mockFlow.setInstructions(toApplyInstruction(Arrays.asList(actions)));
104 private static class MockFlow implements AddFlowInput {
105 private Instructions instructions;
108 public void setInstructions(final Instructions instructions) {
109 this.instructions = instructions;
112 public void setMatch(final Match match) {
118 public FlowRef getFlowRef() {
123 public <E extends Augmentation<AddFlowInput>> E getAugmentation(final Class<E> augmentationType) {
128 public FlowTableRef getFlowTable() {
133 public Match getMatch() {
138 public Instructions getInstructions() {
143 public String getContainerName() {
148 public FlowCookie getCookieMask() {
153 public Long getBufferId() {
158 public BigInteger getOutPort() {
163 public Long getOutGroup() {
168 public FlowModFlags getFlags() {
173 public String getFlowName() {
178 public Boolean isInstallHw() {
183 public Boolean isBarrier() {
188 public Boolean isStrict() {
193 public Integer getPriority() {
198 public Integer getIdleTimeout() {
203 public Integer getHardTimeout() {
208 public FlowCookie getCookie() {
213 public Short getTableId() {
218 public NodeRef getNode() {
223 public Uri getTransactionUri() {
228 public Class<? extends DataContainer> getImplementedInterface() {