2 * Copyright (c) 2016 Pantheon Technologies s.r.o. 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.impl.protocol.serialization.instructions;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
13 import org.junit.Test;
14 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
15 import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants;
16 import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
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.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
27 import org.opendaylight.yangtools.yang.binding.util.BindingMap;
29 public class ApplyActionsInstructionSerializerTest extends AbstractInstructionSerializerTest {
31 public void testSerialize() {
33 final Ipv4Prefix prefix = new Ipv4Prefix("192.168.76.0/32");
35 final Instruction instruction = new ApplyActionsCaseBuilder()
36 .setApplyActions(new ApplyActionsBuilder()
37 .setAction(BindingMap.of(new ActionBuilder()
39 .withKey(new ActionKey(order))
40 .setAction(new SetNwSrcActionCaseBuilder()
41 .setSetNwSrcAction(new SetNwSrcActionBuilder()
42 .setAddress(new Ipv4Builder()
43 .setIpv4Address(prefix)
51 assertInstruction(instruction, out -> {
52 out.skipBytes(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
53 assertEquals(out.readUnsignedShort(), ActionConstants.SET_FIELD_CODE);
54 out.skipBytes(Short.BYTES); // Skip length of set field action
55 assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS);
56 assertEquals(out.readUnsignedByte(), OxmMatchConstants.IPV4_SRC << 1);
57 out.skipBytes(Byte.BYTES); // Skip match entry length
59 byte[] addressBytes = new byte[4];
60 out.readBytes(addressBytes);
61 assertArrayEquals(addressBytes, new byte[] { (byte) 192, (byte) 168, 76, 0 });
63 out.skipBytes(4); // Padding at end
68 protected Class<? extends Instruction> getClazz() {
69 return ApplyActionsCase.class;
73 protected int getType() {
74 return InstructionConstants.APPLY_ACTIONS_TYPE;
78 protected int getLength() {