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.ArrayList;
14 import java.util.List;
15 import org.junit.Assert;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCaseBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCaseBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCaseBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCaseBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCaseBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCaseBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCaseBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetQueueActionCaseBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.in._case.CopyTtlInBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.out._case.CopyTtlOutBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.mpls.ttl._case.DecMplsTtlBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.mpls.action._case.PopMplsActionBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.pbb.action._case.PopPbbActionBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.vlan.action._case.PopVlanActionBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbActionBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanActionBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlActionBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstAction;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcAction;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.ttl.action._case.SetNwTtlActionBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.queue.action._case.SetQueueActionBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6Builder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlInCase;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlOutCase;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.DecMplsTtlCase;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.DecNwTtlCase;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.GroupCase;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCase;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopMplsCase;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopMplsCaseBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopVlanCase;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushMplsCase;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushMplsCaseBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushPbbCase;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushVlanCase;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetMplsTtlCase;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwDstCase;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwSrcCase;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwTtlCase;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetQueueCase;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv4Dst;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv4Src;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6Dst;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6Src;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv4DstCase;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv4SrcCase;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6DstCase;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6SrcCase;
101 * test for {@link ActionConvertor}
103 public class ActionConvertorTest {
105 List<Action> actions = new ArrayList<>();
106 static Integer actionItem = 0;
109 * prepare OpenflowPortsUtil util class
112 public void setUp() {
113 OpenflowPortsUtil.init();
117 public void testActionConvertorwithallParameters() {
123 setQueueActionData();
128 setExperimenterData();
129 List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action> OFActionsList = ActionConvertor.getActions(actions, (short) 0X4, BigInteger.ONE, null);
131 outputActions(OFActionsList);
135 private void setExperimenterData() {
137 // TODO:SAL API Missing
141 private void setFieldData() {
143 SetFieldBuilder setFA = new SetFieldBuilder();
145 SetFieldBuilder matchBuilder = setFA;
147 matchBuilder.setInPort(new NodeConnectorId("openflow:1:2125"));
149 SetFieldBuilder setFB = new SetFieldBuilder();
151 ActionBuilder AB = new ActionBuilder();
152 AB.setOrder(actionItem).setAction(new SetFieldCaseBuilder().setSetField(setFB.build()).build());
154 actions.add(actionItem++, AB.build());
158 private void pbbActionData() {
159 PushPbbActionBuilder pushpbb = new PushPbbActionBuilder();
160 pushpbb.setEthernetType(10);
162 ActionBuilder AB = new ActionBuilder();
163 AB.setOrder(actionItem).setAction(new PushPbbActionCaseBuilder().setPushPbbAction(pushpbb.build()).build());
165 actions.add(actionItem++, AB.build());
167 PopPbbActionBuilder popPBB = new PopPbbActionBuilder();
169 ActionBuilder AB1 = new ActionBuilder();
170 AB1.setOrder(actionItem).setAction(new PopPbbActionCaseBuilder().setPopPbbAction(popPBB.build()).build());
172 actions.add(actionItem++, AB1.build());
176 private void NwTtlAction() {
177 SetNwTtlActionBuilder setNwTtlActionBuilder = new SetNwTtlActionBuilder();
179 setNwTtlActionBuilder.setNwTtl((short) 1);
180 ActionBuilder AB = new ActionBuilder();
181 AB.setOrder(actionItem).setAction(new SetNwTtlActionCaseBuilder().setSetNwTtlAction(setNwTtlActionBuilder.build()).build());
183 actions.add(actionItem++, AB.build());
185 DecNwTtlBuilder necNwTtlBuilder = new DecNwTtlBuilder();
188 ActionBuilder AB1 = new ActionBuilder();
189 AB1.setOrder(actionItem).setAction(new DecNwTtlCaseBuilder().setDecNwTtl(necNwTtlBuilder.build()).build());
191 actions.add(actionItem++, AB1.build());
195 private void setGroupAction() {
197 GroupActionBuilder grpIdAB = new GroupActionBuilder();
198 grpIdAB.setGroup("98");
200 ActionBuilder AB = new ActionBuilder();
201 AB.setOrder(actionItem).setAction(new GroupActionCaseBuilder().setGroupAction(grpIdAB.build()).build());
203 actions.add(actionItem++, AB.build());
207 // TODO - check if this method is needed (private and never used locally) - see line 94
209 private static void outputActions(final List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action> oFActionsList) {
211 for (int item = 0; item < oFActionsList.size(); item++) {
213 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action action = oFActionsList
216 if (action.getActionChoice() instanceof OutputActionCase) {
217 OutputActionCase outputActionCase = (OutputActionCase) action.getActionChoice();
218 Assert.assertEquals((Integer) 10, (outputActionCase.getOutputAction().getMaxLength()));
219 long port = 4294967293L;
220 Assert.assertEquals(port, (long) (outputActionCase.getOutputAction().getPort().getValue()));
224 if (action.getActionChoice() instanceof CopyTtlInCase) {
225 CopyTtlInCase copyTtlInCase = (CopyTtlInCase) action.getActionChoice();
226 Assert.assertEquals(action.getActionChoice().getImplementedInterface().getName(), CopyTtlInCase.class.getName());
229 if (action.getActionChoice() instanceof CopyTtlOutCase) {
230 Assert.assertEquals(action.getActionChoice().getImplementedInterface().getName(), CopyTtlOutCase.class.getName());
233 if (action.getActionChoice() instanceof
234 // TODO:getMplsTtl is missing.
236 Assert.assertEquals(action.getActionChoice().getImplementedInterface().getName(), SetMplsTtlCase.class.getName());
239 if (action.getActionChoice() instanceof DecMplsTtlCase) {
240 Assert.assertEquals(action.getActionChoice().getImplementedInterface().getName(),
241 DecMplsTtlCase.class.getName());
244 if (action.getActionChoice() instanceof PushMplsCase) {
245 PushMplsCase pushMplsCase = (PushMplsCase) action.getActionChoice();
246 EtherType etherType = pushMplsCase.getPushMplsAction().getEthertype();
248 if (etherType != null) {
249 Assert.assertEquals((Integer) 10, etherType.getValue());
253 if (action.getActionChoice() instanceof PopMplsCase) {
254 PopMplsCase popMplsCase = (PopMplsCase) action.getActionChoice();
255 Assert.assertEquals((Integer) 10, (popMplsCase.getPopMplsAction().getEthertype().getValue()));
258 if (action.getActionChoice() instanceof
260 // TODO:SetQueue,I dont have getQueueId
262 Assert.assertEquals(action.getActionChoice().getImplementedInterface().getName(), SetQueueCase.class.getName());
265 if (action.getActionChoice() instanceof GroupCase) {
266 GroupCase groupCase = (GroupCase) action.getActionChoice();
267 Assert.assertEquals(98, (long) (groupCase.getGroupAction().getGroupId()));
270 if (action.getActionChoice() instanceof PushVlanCase) {
271 Assert.assertEquals(action.getActionChoice().getImplementedInterface().getName(), PushVlanCase.class.getName());
274 if (action.getActionChoice() instanceof PopVlanCase) {
275 Assert.assertEquals(action.getActionChoice().getImplementedInterface().getName(), PopVlanCase.class.getName());
278 if (action.getActionChoice() instanceof SetNwTtlCase) {
279 Assert.assertEquals(action.getActionChoice().getImplementedInterface().getName(), SetNwTtlCase.class.getName());
281 if (action.getActionChoice() instanceof DecNwTtlCase) {
282 Assert.assertEquals(action.getActionChoice().getImplementedInterface().getName(), DecNwTtlCase.class.getName());
284 if (action.getActionChoice() instanceof PushPbbCase) {
285 PushPbbCase pushPbbCase = (PushPbbCase) action.getActionChoice();
286 if (pushPbbCase.getPushPbbAction().getEthertype() != null) {
287 Assert.assertEquals((Integer) 10, pushPbbCase.getPushPbbAction().getEthertype().getValue());
291 if (action.getActionChoice() instanceof PopMplsCase) {
292 Assert.assertEquals(action.getActionChoice().getImplementedInterface().getName(), PopMplsCase.class.getName());
294 if (action.getActionChoice() instanceof SetFieldCase) {
295 SetFieldCase setFieldCase = (SetFieldCase) action.getActionChoice();
296 Assert.assertNotNull(setFieldCase.getSetFieldAction());
299 Assert.assertEquals(OpenflowBasicClass.class, sf.getMatchEntry().get(0).getOxmClass());
301 if (sf.getMatchEntry().get(0).getOxmMatchField().equals(InPort.class)) {
302 InPortCase inPortCase = ((InPortCase) sf.getMatchEntry().get(0).getMatchEntryValue());
303 Assert.assertEquals(2125, inPortCase.getInPort().getPortNumber().getValue().intValue());
315 private void OutputActionData() {
316 OutputActionBuilder outputB = new OutputActionBuilder();
317 outputB.setMaxLength(10);
318 Uri uri = new Uri(OutputPortValues.CONTROLLER.toString());
319 outputB.setOutputNodeConnector(uri);
321 ActionBuilder AB = new ActionBuilder();
322 AB.setOrder(actionItem).setAction(new OutputActionCaseBuilder().setOutputAction(outputB.build()).build());
324 actions.add(actionItem++, AB.build());
328 private void CopyTtlData() {
329 CopyTtlOutBuilder copyB = new CopyTtlOutBuilder();
331 ActionBuilder AB = new ActionBuilder();
332 AB.setOrder(actionItem).setAction(new CopyTtlOutCaseBuilder().setCopyTtlOut(copyB.build()).build());
334 actions.add(actionItem++, AB.build());
336 CopyTtlInBuilder copyTtlInBuilder = new CopyTtlInBuilder();
338 ActionBuilder AB1 = new ActionBuilder();
339 AB1.setOrder(actionItem).setAction(new CopyTtlInCaseBuilder().setCopyTtlIn(copyTtlInBuilder.build()).build());
341 actions.add(actionItem++, AB1.build());
345 private void MplsTtlActionData() {
347 SetMplsTtlActionBuilder setMplsTtlActionB = new SetMplsTtlActionBuilder();
349 setMplsTtlActionB.setMplsTtl((short) 10);
350 ActionBuilder AB1 = new ActionBuilder();
351 AB1.setOrder(actionItem).setAction(new SetMplsTtlActionCaseBuilder().setSetMplsTtlAction(setMplsTtlActionB.build()).build());
354 actions.add(actionItem++, AB1.build());
356 DecMplsTtlBuilder decMplsTtlB = new DecMplsTtlBuilder();
358 ActionBuilder AB = new ActionBuilder();
359 AB.setOrder(actionItem).setAction(new DecMplsTtlCaseBuilder().setDecMplsTtl(decMplsTtlB.build()).build());
361 actions.add(actionItem++, AB1.build());
364 private void vlanActionData() {
365 PushVlanActionBuilder pvB = new PushVlanActionBuilder();
367 pvB.setVlanId(new VlanId(10));
369 ActionBuilder AB1 = new ActionBuilder();
370 AB1.setOrder(actionItem).setAction(new PushVlanActionCaseBuilder().setPushVlanAction(pvB.build()).build());
372 actions.add(actionItem++, AB1.build());
374 PopVlanActionBuilder popVAB = new PopVlanActionBuilder();
376 ActionBuilder AB = new ActionBuilder();
377 AB.setOrder(actionItem).setAction(new PopVlanActionCaseBuilder().setPopVlanAction(popVAB.build()).build());
379 actions.add(actionItem++, AB.build());
383 private void mplsActionData() {
385 PushMplsActionBuilder pushMB = new PushMplsActionBuilder();
386 pushMB.setEthernetType(10);
388 ActionBuilder AB = new ActionBuilder();
389 AB.setOrder(actionItem).setAction(new PushMplsActionCaseBuilder().setPushMplsAction(pushMB.build()).build());
391 actions.add(actionItem++, AB.build());
393 PopMplsActionBuilder popMB = new PopMplsActionBuilder();
394 popMB.setEthernetType(10);
396 ActionBuilder AB1 = new ActionBuilder();
397 AB1.setOrder(actionItem).setAction(new PopMplsActionCaseBuilder().setPopMplsAction(popMB.build()).build());
399 actions.add(actionItem++, AB1.build());
403 * testing {@link ActionConvertor#ofToSALPushMplsAction(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action)}
407 public void testOFtoSALPushMplsAction() {
408 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder
409 = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder();
410 PushMplsCaseBuilder pushMplsCaseBuilder = new PushMplsCaseBuilder();
411 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.mpls._case.PushMplsActionBuilder pushMplsBuilder =
412 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.mpls._case.PushMplsActionBuilder();
413 pushMplsBuilder.setEthertype(new EtherType(new Integer(34888)));
414 pushMplsCaseBuilder.setPushMplsAction(pushMplsBuilder.build());
415 actionBuilder.setActionChoice(pushMplsCaseBuilder.build());
416 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action action = actionBuilder.build();
417 Assert.assertEquals(34888, ActionConvertor.ofToSALPushMplsAction(action).getPushMplsAction().getEthernetType().intValue());
420 private void setQueueActionData() {
422 SetQueueActionBuilder setQB = new SetQueueActionBuilder();
423 setQB.setQueue("99");
425 ActionBuilder AB1 = new ActionBuilder();
426 AB1.setOrder(actionItem).setAction(new SetQueueActionCaseBuilder().setSetQueueAction(setQB.build()).build());
428 actions.add(actionItem++, AB1.build());
433 * testing {@link ActionConvertor#salToOFSetNwDst(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder, short)}
437 public void testSalToOFSetNwDst10v4() {
439 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder =
440 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder();
442 address = new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.0.1/32")).build();
443 SetNwDstActionCase action = provisionNwDstActionBuilder(address);
444 ActionConvertor.salToOFSetNwDst(action, actionBuilder, version);
445 Assert.assertEquals(SetNwDstCase.class.getName(), actionBuilder.getActionChoice().getImplementedInterface().getName());
446 SetNwDstCase setNwDstCase = (SetNwDstCase) actionBuilder.getActionChoice();
447 Assert.assertEquals("10.0.0.1", setNwDstCase.getSetNwDstAction().getIpAddress().getValue());
451 * testing {@link ActionConvertor#salToOFSetNwDst(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder, short)}
455 public void testSalToOFSetNwDst10v6() {
457 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder =
458 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder();
460 /* Use canonical form - no leading zeroes!!! */
461 address = new Ipv6Builder().setIpv6Address(new Ipv6Prefix("2001:db8:85a3:42:1000:8a2e:370:7334/128")).build();
462 SetNwDstActionCase action = provisionNwDstActionBuilder(address);
463 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action ofAction = ActionConvertor.salToOFSetNwDst(action, actionBuilder, version);
464 Assert.assertNull(ofAction);
469 * testing {@link ActionConvertor#salToOFSetNwDst(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder, short)}
473 public void testSalToOFSetNwDst13v4() {
475 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder =
476 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder();
478 address = new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.0.1/32")).build();
479 SetNwDstActionCase action = provisionNwDstActionBuilder(address);
480 ActionConvertor.salToOFSetNwDst(action, actionBuilder, version);
481 Assert.assertEquals(SetFieldCase.class.getName(), actionBuilder.getActionChoice().getImplementedInterface().getName());
482 SetFieldCase setFieldCase = (SetFieldCase) actionBuilder.getActionChoice();
483 MatchEntry matchEntry = setFieldCase.getSetFieldAction().getMatchEntry().get(0);
484 Assert.assertEquals(Ipv4Dst.class.getName(), matchEntry.getOxmMatchField().getName());
485 Ipv4DstCase ipv4DstCase = ((Ipv4DstCase) matchEntry.getMatchEntryValue());
486 Assert.assertEquals("10.0.0.1", ipv4DstCase.getIpv4Dst().getIpv4Address().getValue());
491 * testing {@link ActionConvertor#salToOFSetNwDst(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder, short)}
495 public void testSalToOFSetNwDst13v6() {
497 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder =
498 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder();
500 /* Use canonical form - no leading zeroes and a prefix, even if the prefix is /128 !!! */
501 address = new Ipv6Builder().setIpv6Address(new Ipv6Prefix("2001:db8:85a3:42:1000:8a2e:370:7334/128")).build();
502 SetNwDstActionCase action = provisionNwDstActionBuilder(address);
503 ActionConvertor.salToOFSetNwDst(action, actionBuilder, version);
504 Assert.assertEquals(SetFieldCase.class.getName(), actionBuilder.getActionChoice().getImplementedInterface().getName());
505 SetFieldCase setFieldCase = (SetFieldCase) actionBuilder.getActionChoice();
506 MatchEntry matchEntry = setFieldCase.getSetFieldAction().getMatchEntry().get(0);
507 Assert.assertEquals(Ipv6Dst.class.getName(), matchEntry.getOxmMatchField().getName());
508 Ipv6DstCase ipv6DstCase = ((Ipv6DstCase) matchEntry.getMatchEntryValue());
509 /* We check the IP only, the netmask should have gone into the wildcard field */
510 Assert.assertEquals("2001:db8:85a3:42:1000:8a2e:370:7334", ipv6DstCase.getIpv6Dst().getIpv6Address().getValue());
515 * testing {@link ActionConvertor#salToOFSetNwSrc(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder, short)}
519 public void testSalToOFSetNwSrc10v4() {
521 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder =
522 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder();
524 address = new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.0.1/32")).build();
525 SetNwSrcActionCase action = provisionNwSrcActionBuilder(address);
526 ActionConvertor.salToOFSetNwSrc(action, actionBuilder, version);
527 Assert.assertEquals(SetNwSrcCase.class.getName(), actionBuilder.getActionChoice().getImplementedInterface().getName());
528 SetNwSrcCase setNwSrcCase = (SetNwSrcCase) actionBuilder.getActionChoice();
529 Assert.assertEquals("10.0.0.1", setNwSrcCase.getSetNwSrcAction().getIpAddress().getValue());
533 * testing {@link ActionConvertor#salToOFSetNwSrc(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder, short)}
537 public void testSalToOFSetNwSrc10v6() {
539 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder =
540 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder();
542 /* Use canonical form - no leading zeroes and a prefix, even if the prefix is /128 !!! */
543 address = new Ipv6Builder().setIpv6Address(new Ipv6Prefix("2001:db8:85a3:42:1000:8a2e:370:7334/128")).build();
544 SetNwSrcActionCase action = provisionNwSrcActionBuilder(address);
545 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action ofAction = ActionConvertor.salToOFSetNwSrc(action, actionBuilder, version);
546 Assert.assertNull(ofAction);
550 * testing {@link ActionConvertor#salToOFSetNwSrc(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder, short)}
554 public void testSalToOFSetNwSrc13v4() {
556 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder =
557 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder();
559 address = new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.0.1/32")).build();
560 SetNwSrcActionCase action = provisionNwSrcActionBuilder(address);
561 ActionConvertor.salToOFSetNwSrc(action, actionBuilder, version);
562 Assert.assertEquals(SetFieldCase.class.getName(), actionBuilder.getActionChoice().getImplementedInterface().getName());
563 SetFieldCase setFieldCase = (SetFieldCase) actionBuilder.getActionChoice();
564 MatchEntry matchEntry = setFieldCase.getSetFieldAction().getMatchEntry().get(0);
565 Assert.assertEquals(Ipv4Src.class, matchEntry.getOxmMatchField());
566 Ipv4SrcCase ipv4SrcCase = ((Ipv4SrcCase) matchEntry.getMatchEntryValue());
567 Assert.assertEquals("10.0.0.1", ipv4SrcCase.getIpv4Src().getIpv4Address().getValue());
571 * testing {@link ActionConvertor#salToOFSetNwSrc(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder, short)}
575 public void testSalToOFSetNwSrc13v6() {
577 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder =
578 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder();
580 /* Use canonical form - no leading zeroes and a prefix, even if the prefix is /128 !!! */
581 address = new Ipv6Builder().setIpv6Address(new Ipv6Prefix("2001:db8:85a3:42:1000:8a2e:370:7334/128")).build();
582 SetNwSrcActionCase action = provisionNwSrcActionBuilder(address);
583 ActionConvertor.salToOFSetNwSrc(action, actionBuilder, version);
584 Assert.assertEquals(SetFieldCase.class.getName(), actionBuilder.getActionChoice().getImplementedInterface().getName());
585 SetFieldCase setFieldCase = (SetFieldCase) actionBuilder.getActionChoice();
586 MatchEntry matchEntry = setFieldCase.getSetFieldAction().getMatchEntry().get(0);
587 Ipv6SrcCase ipv6SrcCase = ((Ipv6SrcCase) matchEntry.getMatchEntryValue());
588 Assert.assertEquals(Ipv6Src.class.getName(), matchEntry.getOxmMatchField().getName());
589 /* We check the IP only, the netmask should have gone into the wildcard field */
590 Assert.assertEquals("2001:db8:85a3:42:1000:8a2e:370:7334", ipv6SrcCase.getIpv6Src().getIpv6Address().getValue());
594 * testing {@link ActionConvertor#ofToSALPopMplsAction(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action)}
598 public void testOFtoSALPopMplsAction() {
599 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder =
600 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder();
601 PopMplsCaseBuilder popMplsCaseBuilder = new PopMplsCaseBuilder();
602 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.pop.mpls._case.PopMplsActionBuilder popMplsBuilder =
603 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.pop.mpls._case.PopMplsActionBuilder();
604 popMplsBuilder.setEthertype(new EtherType(new EtherType(34888)));
605 popMplsCaseBuilder.setPopMplsAction(popMplsBuilder.build());
606 actionBuilder.setActionChoice(popMplsCaseBuilder.build());
607 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action action = actionBuilder.build();
608 Assert.assertEquals(34888, ActionConvertor.ofToSALPopMplsAction(action).getPopMplsAction().getEthernetType().intValue());
611 private static SetNwDstActionCase provisionNwDstActionBuilder(final Address address) {
612 SetNwDstAction nwDstAction = new SetNwDstActionBuilder().setAddress(address).build();
613 SetNwDstActionCase action = new SetNwDstActionCaseBuilder()
614 .setSetNwDstAction(nwDstAction)
619 private static SetNwSrcActionCase provisionNwSrcActionBuilder(final Address address) {
620 SetNwSrcAction nwSrcAction = new SetNwSrcActionBuilder().setAddress(address).build();
621 SetNwSrcActionCase action = new SetNwSrcActionCaseBuilder()
622 .setSetNwSrcAction(nwSrcAction)