Bug 1588 - OFConstants.java moved to openflowplugin-api module
[openflowplugin.git] / openflowplugin / src / test / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / FlowConverterTest.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: usha.m.s@ericsson.com
9  */
10 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
11
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;
42
43 import java.math.BigInteger;
44 import java.util.Arrays;
45 import java.util.Collections;
46 import java.util.List;
47
48 /**
49  * test for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor}
50  */
51 public class FlowConverterTest {
52
53
54     @Test
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())
60                 .build(),
61             0);
62
63         mockFlow.setMatch(new MatchBuilder().setEthernetMatch(createEthernetMatch()).build());
64         mockFlow.setInstructions(toApplyInstruction(Collections.singletonList(action1)));
65
66         List<FlowModInputBuilder> flowModInputBuilders =
67             FlowConvertor.toFlowModInputs(mockFlow, OFConstants.OFP_VERSION_1_3, BigInteger.ONE);
68         Assert.assertEquals(2, flowModInputBuilders.size());
69
70     }
71
72     private Action createAction(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionCase,
73         int order) {
74         Action action = new ActionBuilder().setOrder(order).setAction(actionCase).build();
75         return action;
76     }
77
78     private EthernetMatch createEthernetMatch() {
79         EthernetMatchBuilder ethernetMatchBuilder = new EthernetMatchBuilder();
80         ethernetMatchBuilder.setEthernetType(new EthernetTypeBuilder().setType(new EtherType(33024L)).build());
81         return ethernetMatchBuilder.build();
82     }
83
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()
87             .setInstruction(
88                 Collections.singletonList(
89                     new InstructionBuilder()
90                         .setOrder(0)
91                         .setInstruction(
92                             new ApplyActionsCaseBuilder()
93                                 .setApplyActions((new ApplyActionsBuilder()).setAction(actions).build())
94                                 .build()
95                         ).build())
96             ).build();
97     }
98
99     private Flow createFlowWithActions(Action...actions) {
100         MockFlow mockFlow = new MockFlow();
101         mockFlow.setInstructions(toApplyInstruction(Arrays.asList(actions)));
102         return mockFlow;
103     }
104
105     private class MockFlow implements AddFlowInput {
106         private Instructions instructions;
107         private Match match;
108
109         public void setInstructions(Instructions instructions) {
110             this.instructions = instructions;
111         }
112
113         public void setMatch(Match match) {
114             this.match = match;
115         }
116
117
118         @Override
119         public FlowRef getFlowRef() {
120             return null;
121         }
122
123         @Override
124         public <E extends Augmentation<AddFlowInput>> E getAugmentation(Class<E> augmentationType) {
125             return null;
126         }
127
128         @Override
129         public FlowTableRef getFlowTable() {
130             return null;
131         }
132
133         @Override
134         public Match getMatch() {
135             return match;
136         }
137
138         @Override
139         public Instructions getInstructions() {
140             return instructions;
141         }
142
143         @Override
144         public String getContainerName() {
145             return null;
146         }
147
148         @Override
149         public FlowCookie getCookieMask() {
150             return null;
151         }
152
153         @Override
154         public Long getBufferId() {
155             return null;
156         }
157
158         @Override
159         public BigInteger getOutPort() {
160             return null;
161         }
162
163         @Override
164         public Long getOutGroup() {
165             return null;
166         }
167
168         @Override
169         public FlowModFlags getFlags() {
170             return null;
171         }
172
173         @Override
174         public String getFlowName() {
175             return null;
176         }
177
178         @Override
179         public Boolean isInstallHw() {
180             return null;
181         }
182
183         @Override
184         public Boolean isBarrier() {
185             return null;
186         }
187
188         @Override
189         public Boolean isStrict() {
190             return null;
191         }
192
193         @Override
194         public Integer getPriority() {
195             return null;
196         }
197
198         @Override
199         public Integer getIdleTimeout() {
200             return null;
201         }
202
203         @Override
204         public Integer getHardTimeout() {
205             return null;
206         }
207
208         @Override
209         public FlowCookie getCookie() {
210             return null;
211         }
212
213         @Override
214         public Short getTableId() {
215             return null;
216         }
217
218         @Override
219         public NodeRef getNode() {
220             return null;
221         }
222
223         @Override
224         public Uri getTransactionUri() {
225             return null;
226         }
227
228         @Override
229         public Class<? extends DataContainer> getImplementedInterface() {
230             return null;
231         }
232     }
233
234 }