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.ArrayList;
12 import java.util.List;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
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.CopyTtlInCaseBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCaseBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCaseBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCaseBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCaseBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCaseBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCaseBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCaseBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCaseBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetQueueActionCaseBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.in._case.CopyTtlInBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.out._case.CopyTtlOutBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.mpls.ttl._case.DecMplsTtlBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.mpls.action._case.PopMplsActionBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.pbb.action._case.PopPbbActionBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.vlan.action._case.PopVlanActionBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbActionBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanActionBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlActionBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstAction;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcAction;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.ttl.action._case.SetNwTtlActionBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.queue.action._case.SetQueueActionBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6Builder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlInCase;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlOutCase;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.DecMplsTtlCase;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.DecNwTtlCase;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.GroupCase;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCase;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopMplsCase;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopMplsCaseBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopVlanCase;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushMplsCase;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushMplsCaseBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushPbbCase;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushVlanCase;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetMplsTtlCase;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwDstCase;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwSrcCase;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwTtlCase;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetQueueCase;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv4Dst;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv4Src;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6Dst;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6Src;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv4DstCase;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv4SrcCase;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6DstCase;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6SrcCase;
99 * test for {@link ActionConvertor}
101 public class ActionConvertorTest {
103 List<Action> actions = new ArrayList<>();
104 static Integer actionItem = 0;
107 * prepare OpenflowPortsUtil util class
110 public void setUp() {
111 OpenflowPortsUtil.init();
115 public void testActionConvertorwithallParameters() {
121 setQueueActionData();
126 setExperimenterData();
127 List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action> OFActionsList = ActionConvertor.getActions(actions, (short) 0X4, BigInteger.ONE, null);
129 outputActions(OFActionsList);
133 private void setExperimenterData() {
135 // TODO:SAL API Missing
139 private void setFieldData() {
141 SetFieldBuilder setFA = new SetFieldBuilder();
143 SetFieldBuilder matchBuilder = setFA;
145 matchBuilder.setInPort(new NodeConnectorId("openflow:1:2125"));
147 SetFieldBuilder setFB = new SetFieldBuilder();
149 ActionBuilder AB = new ActionBuilder();
150 AB.setOrder(actionItem).setAction(new SetFieldCaseBuilder().setSetField(setFB.build()).build());
152 actions.add(actionItem++, AB.build());
156 private void pbbActionData() {
157 PushPbbActionBuilder pushpbb = new PushPbbActionBuilder();
158 pushpbb.setEthernetType(10);
160 ActionBuilder AB = new ActionBuilder();
161 AB.setOrder(actionItem).setAction(new PushPbbActionCaseBuilder().setPushPbbAction(pushpbb.build()).build());
163 actions.add(actionItem++, AB.build());
165 PopPbbActionBuilder popPBB = new PopPbbActionBuilder();
167 ActionBuilder AB1 = new ActionBuilder();
168 AB1.setOrder(actionItem).setAction(new PopPbbActionCaseBuilder().setPopPbbAction(popPBB.build()).build());
170 actions.add(actionItem++, AB1.build());
174 private void NwTtlAction() {
175 SetNwTtlActionBuilder setNwTtlActionBuilder = new SetNwTtlActionBuilder();
177 setNwTtlActionBuilder.setNwTtl((short) 1);
178 ActionBuilder AB = new ActionBuilder();
179 AB.setOrder(actionItem).setAction(new SetNwTtlActionCaseBuilder().setSetNwTtlAction(setNwTtlActionBuilder.build()).build());
181 actions.add(actionItem++, AB.build());
183 DecNwTtlBuilder necNwTtlBuilder = new DecNwTtlBuilder();
186 ActionBuilder AB1 = new ActionBuilder();
187 AB1.setOrder(actionItem).setAction(new DecNwTtlCaseBuilder().setDecNwTtl(necNwTtlBuilder.build()).build());
189 actions.add(actionItem++, AB1.build());
193 private void setGroupAction() {
195 GroupActionBuilder grpIdAB = new GroupActionBuilder();
196 grpIdAB.setGroup("98");
198 ActionBuilder AB = new ActionBuilder();
199 AB.setOrder(actionItem).setAction(new GroupActionCaseBuilder().setGroupAction(grpIdAB.build()).build());
201 actions.add(actionItem++, AB.build());
205 // TODO - check if this method is needed (private and never used locally) - see line 94
207 private static void outputActions(final List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action> oFActionsList) {
209 for (int item = 0; item < oFActionsList.size(); item++) {
211 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action action = oFActionsList
214 if (action.getActionChoice() instanceof OutputActionCase) {
215 OutputActionCase outputActionCase = (OutputActionCase) action.getActionChoice();
216 Assert.assertEquals((Integer) 10, (outputActionCase.getOutputAction().getMaxLength()));
217 long port = 4294967293L;
218 Assert.assertEquals(port, (long) (outputActionCase.getOutputAction().getPort().getValue()));
222 if (action.getActionChoice() instanceof CopyTtlInCase) {
223 CopyTtlInCase copyTtlInCase = (CopyTtlInCase) action.getActionChoice();
224 Assert.assertEquals(action.getActionChoice().getImplementedInterface().getName(), CopyTtlInCase.class.getName());
227 if (action.getActionChoice() instanceof CopyTtlOutCase) {
228 Assert.assertEquals(action.getActionChoice().getImplementedInterface().getName(), CopyTtlOutCase.class.getName());
231 if (action.getActionChoice() instanceof
232 // TODO:getMplsTtl is missing.
234 Assert.assertEquals(action.getActionChoice().getImplementedInterface().getName(), SetMplsTtlCase.class.getName());
237 if (action.getActionChoice() instanceof DecMplsTtlCase) {
238 Assert.assertEquals(action.getActionChoice().getImplementedInterface().getName(),
239 DecMplsTtlCase.class.getName());
242 if (action.getActionChoice() instanceof PushMplsCase) {
243 PushMplsCase pushMplsCase = (PushMplsCase) action.getActionChoice();
244 EtherType etherType = pushMplsCase.getPushMplsAction().getEthertype();
246 if (etherType != null) {
247 Assert.assertEquals((Integer) 10, etherType.getValue());
251 if (action.getActionChoice() instanceof PopMplsCase) {
252 PopMplsCase popMplsCase = (PopMplsCase) action.getActionChoice();
253 Assert.assertEquals((Integer) 10, (popMplsCase.getPopMplsAction().getEthertype().getValue()));
256 if (action.getActionChoice() instanceof
258 // TODO:SetQueue,I dont have getQueueId
260 Assert.assertEquals(action.getActionChoice().getImplementedInterface().getName(), SetQueueCase.class.getName());
263 if (action.getActionChoice() instanceof GroupCase) {
264 GroupCase groupCase = (GroupCase) action.getActionChoice();
265 Assert.assertEquals(98, (long) (groupCase.getGroupAction().getGroupId()));
268 if (action.getActionChoice() instanceof PushVlanCase) {
269 Assert.assertEquals(action.getActionChoice().getImplementedInterface().getName(), PushVlanCase.class.getName());
272 if (action.getActionChoice() instanceof PopVlanCase) {
273 Assert.assertEquals(action.getActionChoice().getImplementedInterface().getName(), PopVlanCase.class.getName());
276 if (action.getActionChoice() instanceof SetNwTtlCase) {
277 Assert.assertEquals(action.getActionChoice().getImplementedInterface().getName(), SetNwTtlCase.class.getName());
279 if (action.getActionChoice() instanceof DecNwTtlCase) {
280 Assert.assertEquals(action.getActionChoice().getImplementedInterface().getName(), DecNwTtlCase.class.getName());
282 if (action.getActionChoice() instanceof PushPbbCase) {
283 PushPbbCase pushPbbCase = (PushPbbCase) action.getActionChoice();
284 if (pushPbbCase.getPushPbbAction().getEthertype() != null) {
285 Assert.assertEquals((Integer) 10, pushPbbCase.getPushPbbAction().getEthertype().getValue());
289 if (action.getActionChoice() instanceof PopMplsCase) {
290 Assert.assertEquals(action.getActionChoice().getImplementedInterface().getName(), PopMplsCase.class.getName());
292 if (action.getActionChoice() instanceof SetFieldCase) {
293 SetFieldCase setFieldCase = (SetFieldCase) action.getActionChoice();
294 Assert.assertNotNull(setFieldCase.getSetFieldAction());
297 Assert.assertEquals(OpenflowBasicClass.class, sf.getMatchEntry().get(0).getOxmClass());
299 if (sf.getMatchEntry().get(0).getOxmMatchField().equals(InPort.class)) {
300 InPortCase inPortCase = ((InPortCase) sf.getMatchEntry().get(0).getMatchEntryValue());
301 Assert.assertEquals(2125, inPortCase.getInPort().getPortNumber().getValue().intValue());
313 private void OutputActionData() {
314 OutputActionBuilder outputB = new OutputActionBuilder();
315 outputB.setMaxLength(10);
316 Uri uri = new Uri(OutputPortValues.CONTROLLER.toString());
317 outputB.setOutputNodeConnector(uri);
319 ActionBuilder AB = new ActionBuilder();
320 AB.setOrder(actionItem).setAction(new OutputActionCaseBuilder().setOutputAction(outputB.build()).build());
322 actions.add(actionItem++, AB.build());
326 private void CopyTtlData() {
327 CopyTtlOutBuilder copyB = new CopyTtlOutBuilder();
329 ActionBuilder AB = new ActionBuilder();
330 AB.setOrder(actionItem).setAction(new CopyTtlOutCaseBuilder().setCopyTtlOut(copyB.build()).build());
332 actions.add(actionItem++, AB.build());
334 CopyTtlInBuilder copyTtlInBuilder = new CopyTtlInBuilder();
336 ActionBuilder AB1 = new ActionBuilder();
337 AB1.setOrder(actionItem).setAction(new CopyTtlInCaseBuilder().setCopyTtlIn(copyTtlInBuilder.build()).build());
339 actions.add(actionItem++, AB1.build());
343 private void MplsTtlActionData() {
345 SetMplsTtlActionBuilder setMplsTtlActionB = new SetMplsTtlActionBuilder();
347 setMplsTtlActionB.setMplsTtl((short) 10);
348 ActionBuilder AB1 = new ActionBuilder();
349 AB1.setOrder(actionItem).setAction(new SetMplsTtlActionCaseBuilder().setSetMplsTtlAction(setMplsTtlActionB.build()).build());
352 actions.add(actionItem++, AB1.build());
354 DecMplsTtlBuilder decMplsTtlB = new DecMplsTtlBuilder();
356 ActionBuilder AB = new ActionBuilder();
357 AB.setOrder(actionItem).setAction(new DecMplsTtlCaseBuilder().setDecMplsTtl(decMplsTtlB.build()).build());
359 actions.add(actionItem++, AB1.build());
362 private void vlanActionData() {
363 PushVlanActionBuilder pvB = new PushVlanActionBuilder();
365 pvB.setVlanId(new VlanId(10));
367 ActionBuilder AB1 = new ActionBuilder();
368 AB1.setOrder(actionItem).setAction(new PushVlanActionCaseBuilder().setPushVlanAction(pvB.build()).build());
370 actions.add(actionItem++, AB1.build());
372 PopVlanActionBuilder popVAB = new PopVlanActionBuilder();
374 ActionBuilder AB = new ActionBuilder();
375 AB.setOrder(actionItem).setAction(new PopVlanActionCaseBuilder().setPopVlanAction(popVAB.build()).build());
377 actions.add(actionItem++, AB.build());
381 private void mplsActionData() {
383 PushMplsActionBuilder pushMB = new PushMplsActionBuilder();
384 pushMB.setEthernetType(10);
386 ActionBuilder AB = new ActionBuilder();
387 AB.setOrder(actionItem).setAction(new PushMplsActionCaseBuilder().setPushMplsAction(pushMB.build()).build());
389 actions.add(actionItem++, AB.build());
391 PopMplsActionBuilder popMB = new PopMplsActionBuilder();
392 popMB.setEthernetType(10);
394 ActionBuilder AB1 = new ActionBuilder();
395 AB1.setOrder(actionItem).setAction(new PopMplsActionCaseBuilder().setPopMplsAction(popMB.build()).build());
397 actions.add(actionItem++, AB1.build());
401 * testing {@link ActionConvertor#ofToSALPushMplsAction(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action)}
405 public void testOFtoSALPushMplsAction() {
406 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder
407 = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder();
408 PushMplsCaseBuilder pushMplsCaseBuilder = new PushMplsCaseBuilder();
409 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.mpls._case.PushMplsActionBuilder pushMplsBuilder =
410 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.mpls._case.PushMplsActionBuilder();
411 pushMplsBuilder.setEthertype(new EtherType(new Integer(34888)));
412 pushMplsCaseBuilder.setPushMplsAction(pushMplsBuilder.build());
413 actionBuilder.setActionChoice(pushMplsCaseBuilder.build());
414 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action action = actionBuilder.build();
415 Assert.assertEquals(34888, ActionConvertor.ofToSALPushMplsAction(action).getPushMplsAction().getEthernetType().intValue());
418 private void setQueueActionData() {
420 SetQueueActionBuilder setQB = new SetQueueActionBuilder();
421 setQB.setQueue("99");
423 ActionBuilder AB1 = new ActionBuilder();
424 AB1.setOrder(actionItem).setAction(new SetQueueActionCaseBuilder().setSetQueueAction(setQB.build()).build());
426 actions.add(actionItem++, AB1.build());
431 * 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)}
435 public void testSalToOFSetNwDst10v4() {
437 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder =
438 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder();
440 address = new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.0.1/32")).build();
441 SetNwDstActionCase action = provisionNwDstActionBuilder(address);
442 ActionConvertor.salToOFSetNwDst(action, actionBuilder, version);
443 Assert.assertEquals(SetNwDstCase.class.getName(), actionBuilder.getActionChoice().getImplementedInterface().getName());
444 SetNwDstCase setNwDstCase = (SetNwDstCase) actionBuilder.getActionChoice();
445 Assert.assertEquals("10.0.0.1", setNwDstCase.getSetNwDstAction().getIpAddress().getValue());
449 * 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)}
453 public void testSalToOFSetNwDst10v6() {
455 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder =
456 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder();
458 /* Use canonical form - no leading zeroes!!! */
459 address = new Ipv6Builder().setIpv6Address(new Ipv6Prefix("2001:db8:85a3:42:1000:8a2e:370:7334/128")).build();
460 SetNwDstActionCase action = provisionNwDstActionBuilder(address);
461 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action ofAction = ActionConvertor.salToOFSetNwDst(action, actionBuilder, version);
462 Assert.assertNull(ofAction);
467 * 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)}
471 public void testSalToOFSetNwDst13v4() {
473 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder =
474 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder();
476 address = new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.0.1/32")).build();
477 SetNwDstActionCase action = provisionNwDstActionBuilder(address);
478 ActionConvertor.salToOFSetNwDst(action, actionBuilder, version);
479 Assert.assertEquals(SetFieldCase.class.getName(), actionBuilder.getActionChoice().getImplementedInterface().getName());
480 SetFieldCase setFieldCase = (SetFieldCase) actionBuilder.getActionChoice();
481 MatchEntry matchEntry = setFieldCase.getSetFieldAction().getMatchEntry().get(0);
482 Assert.assertEquals(Ipv4Dst.class.getName(), matchEntry.getOxmMatchField().getName());
483 Ipv4DstCase ipv4DstCase = ((Ipv4DstCase) matchEntry.getMatchEntryValue());
484 Assert.assertEquals("10.0.0.1", ipv4DstCase.getIpv4Dst().getIpv4Address().getValue());
489 * 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)}
493 public void testSalToOFSetNwDst13v6() {
495 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder =
496 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder();
498 /* Use canonical form - no leading zeroes and a prefix, even if the prefix is /128 !!! */
499 address = new Ipv6Builder().setIpv6Address(new Ipv6Prefix("2001:db8:85a3:42:1000:8a2e:370:7334/128")).build();
500 SetNwDstActionCase action = provisionNwDstActionBuilder(address);
501 ActionConvertor.salToOFSetNwDst(action, actionBuilder, version);
502 Assert.assertEquals(SetFieldCase.class.getName(), actionBuilder.getActionChoice().getImplementedInterface().getName());
503 SetFieldCase setFieldCase = (SetFieldCase) actionBuilder.getActionChoice();
504 MatchEntry matchEntry = setFieldCase.getSetFieldAction().getMatchEntry().get(0);
505 Assert.assertEquals(Ipv6Dst.class.getName(), matchEntry.getOxmMatchField().getName());
506 Ipv6DstCase ipv6DstCase = ((Ipv6DstCase) matchEntry.getMatchEntryValue());
507 /* We check the IP only, the netmask should have gone into the wildcard field */
508 Assert.assertEquals("2001:db8:85a3:42:1000:8a2e:370:7334", ipv6DstCase.getIpv6Dst().getIpv6Address().getValue());
513 * 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)}
517 public void testSalToOFSetNwSrc10v4() {
519 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder =
520 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder();
522 address = new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.0.1/32")).build();
523 SetNwSrcActionCase action = provisionNwSrcActionBuilder(address);
524 ActionConvertor.salToOFSetNwSrc(action, actionBuilder, version);
525 Assert.assertEquals(SetNwSrcCase.class.getName(), actionBuilder.getActionChoice().getImplementedInterface().getName());
526 SetNwSrcCase setNwSrcCase = (SetNwSrcCase) actionBuilder.getActionChoice();
527 Assert.assertEquals("10.0.0.1", setNwSrcCase.getSetNwSrcAction().getIpAddress().getValue());
531 * 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)}
535 public void testSalToOFSetNwSrc10v6() {
537 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder =
538 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder();
540 /* Use canonical form - no leading zeroes and a prefix, even if the prefix is /128 !!! */
541 address = new Ipv6Builder().setIpv6Address(new Ipv6Prefix("2001:db8:85a3:42:1000:8a2e:370:7334/128")).build();
542 SetNwSrcActionCase action = provisionNwSrcActionBuilder(address);
543 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action ofAction = ActionConvertor.salToOFSetNwSrc(action, actionBuilder, version);
544 Assert.assertNull(ofAction);
548 * 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)}
552 public void testSalToOFSetNwSrc13v4() {
554 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder =
555 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder();
557 address = new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.0.1/32")).build();
558 SetNwSrcActionCase action = provisionNwSrcActionBuilder(address);
559 ActionConvertor.salToOFSetNwSrc(action, actionBuilder, version);
560 Assert.assertEquals(SetFieldCase.class.getName(), actionBuilder.getActionChoice().getImplementedInterface().getName());
561 SetFieldCase setFieldCase = (SetFieldCase) actionBuilder.getActionChoice();
562 MatchEntry matchEntry = setFieldCase.getSetFieldAction().getMatchEntry().get(0);
563 Assert.assertEquals(Ipv4Src.class, matchEntry.getOxmMatchField());
564 Ipv4SrcCase ipv4SrcCase = ((Ipv4SrcCase) matchEntry.getMatchEntryValue());
565 Assert.assertEquals("10.0.0.1", ipv4SrcCase.getIpv4Src().getIpv4Address().getValue());
569 * 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)}
573 public void testSalToOFSetNwSrc13v6() {
575 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder =
576 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder();
578 /* Use canonical form - no leading zeroes and a prefix, even if the prefix is /128 !!! */
579 address = new Ipv6Builder().setIpv6Address(new Ipv6Prefix("2001:db8:85a3:42:1000:8a2e:370:7334/128")).build();
580 SetNwSrcActionCase action = provisionNwSrcActionBuilder(address);
581 ActionConvertor.salToOFSetNwSrc(action, actionBuilder, version);
582 Assert.assertEquals(SetFieldCase.class.getName(), actionBuilder.getActionChoice().getImplementedInterface().getName());
583 SetFieldCase setFieldCase = (SetFieldCase) actionBuilder.getActionChoice();
584 MatchEntry matchEntry = setFieldCase.getSetFieldAction().getMatchEntry().get(0);
585 Ipv6SrcCase ipv6SrcCase = ((Ipv6SrcCase) matchEntry.getMatchEntryValue());
586 Assert.assertEquals(Ipv6Src.class.getName(), matchEntry.getOxmMatchField().getName());
587 /* We check the IP only, the netmask should have gone into the wildcard field */
588 Assert.assertEquals("2001:db8:85a3:42:1000:8a2e:370:7334", ipv6SrcCase.getIpv6Src().getIpv6Address().getValue());
592 * testing {@link ActionConvertor#ofToSALPopMplsAction(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action)}
596 public void testOFtoSALPopMplsAction() {
597 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder =
598 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder();
599 PopMplsCaseBuilder popMplsCaseBuilder = new PopMplsCaseBuilder();
600 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.pop.mpls._case.PopMplsActionBuilder popMplsBuilder =
601 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.pop.mpls._case.PopMplsActionBuilder();
602 popMplsBuilder.setEthertype(new EtherType(new EtherType(34888)));
603 popMplsCaseBuilder.setPopMplsAction(popMplsBuilder.build());
604 actionBuilder.setActionChoice(popMplsCaseBuilder.build());
605 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action action = actionBuilder.build();
606 Assert.assertEquals(34888, ActionConvertor.ofToSALPopMplsAction(action).getPopMplsAction().getEthernetType().intValue());
609 private static SetNwDstActionCase provisionNwDstActionBuilder(final Address address) {
610 SetNwDstAction nwDstAction = new SetNwDstActionBuilder().setAddress(address).build();
611 SetNwDstActionCase action = new SetNwDstActionCaseBuilder()
612 .setSetNwDstAction(nwDstAction)
617 private static SetNwSrcActionCase provisionNwSrcActionBuilder(final Address address) {
618 SetNwSrcAction nwSrcAction = new SetNwSrcActionBuilder().setAddress(address).build();
619 SetNwSrcActionCase action = new SetNwSrcActionCaseBuilder()
620 .setSetNwSrcAction(nwSrcAction)