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 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
10 import java.math.BigInteger;
11 import java.util.Arrays;
12 import java.util.Collections;
13 import java.util.List;
14 import org.junit.Assert;
15 import org.junit.Test;
16 import org.opendaylight.openflowplugin.api.OFConstants;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowTableRef;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
42 import org.opendaylight.yangtools.yang.binding.Augmentation;
43 import org.opendaylight.yangtools.yang.binding.DataContainer;
46 * test for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor}
48 public class FlowConverterTest {
52 public void testCloneAndAugmentFlowWithSetVlanId() {
53 MockFlow mockFlow = new MockFlow();
54 Action action1 = createAction(
55 new SetVlanIdActionCaseBuilder().setSetVlanIdAction(
56 new SetVlanIdActionBuilder().setVlanId(new VlanId(10)).build())
60 mockFlow.setMatch(new MatchBuilder().setEthernetMatch(createEthernetMatch()).build());
61 mockFlow.setInstructions(toApplyInstruction(Collections.singletonList(action1)));
63 List<FlowModInputBuilder> flowModInputBuilders =
64 FlowConvertor.toFlowModInputs(mockFlow, OFConstants.OFP_VERSION_1_3, BigInteger.ONE);
65 Assert.assertEquals(2, flowModInputBuilders.size());
69 private static Action createAction(final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionCase,
71 Action action = new ActionBuilder().setOrder(order).setAction(actionCase).build();
75 private static EthernetMatch createEthernetMatch() {
76 EthernetMatchBuilder ethernetMatchBuilder = new EthernetMatchBuilder();
77 ethernetMatchBuilder.setEthernetType(new EthernetTypeBuilder().setType(new EtherType(33024L)).build());
78 return ethernetMatchBuilder.build();
81 private static Instructions toApplyInstruction(
82 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actions) {
83 return new InstructionsBuilder()
85 Collections.singletonList(
86 new InstructionBuilder()
89 new ApplyActionsCaseBuilder()
90 .setApplyActions((new ApplyActionsBuilder()).setAction(actions).build())
96 private static Flow createFlowWithActions(final Action...actions) {
97 MockFlow mockFlow = new MockFlow();
98 mockFlow.setInstructions(toApplyInstruction(Arrays.asList(actions)));
102 private static class MockFlow implements AddFlowInput {
103 private Instructions instructions;
106 public void setInstructions(final Instructions instructions) {
107 this.instructions = instructions;
110 public void setMatch(final Match match) {
116 public FlowRef getFlowRef() {
121 public <E extends Augmentation<AddFlowInput>> E getAugmentation(final Class<E> augmentationType) {
126 public FlowTableRef getFlowTable() {
131 public Match getMatch() {
136 public Instructions getInstructions() {
141 public String getContainerName() {
146 public FlowCookie getCookieMask() {
151 public Long getBufferId() {
156 public BigInteger getOutPort() {
161 public Long getOutGroup() {
166 public FlowModFlags getFlags() {
171 public String getFlowName() {
176 public Boolean isInstallHw() {
181 public Boolean isBarrier() {
186 public Boolean isStrict() {
191 public Integer getPriority() {
196 public Integer getIdleTimeout() {
201 public Integer getHardTimeout() {
206 public FlowCookie getCookie() {
211 public Short getTableId() {
216 public NodeRef getNode() {
221 public Uri getTransactionUri() {
226 public Class<? extends DataContainer> getImplementedInterface() {