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
9 package org.opendaylight.openflowplugin.impl.protocol.serialization.instructions;
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
14 import java.util.Collections;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
17 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
18 import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants;
19 import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
31 public class ApplyActionsInstructionSerializerTest extends AbstractInstructionSerializerTest {
34 public void testSerialize() throws Exception {
36 final Ipv4Prefix prefix = new Ipv4Prefix("192.168.76.0/32");
38 final Instruction instruction = new ApplyActionsCaseBuilder()
39 .setApplyActions(new ApplyActionsBuilder()
40 .setAction(Collections.singletonList(new ActionBuilder()
42 .setKey(new ActionKey(order))
43 .setAction(new SetNwSrcActionCaseBuilder()
44 .setSetNwSrcAction(new SetNwSrcActionBuilder()
45 .setAddress(new Ipv4Builder()
46 .setIpv4Address(prefix)
54 assertInstruction(instruction, out -> {
55 out.skipBytes(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
56 assertEquals(out.readUnsignedShort(), ActionConstants.SET_FIELD_CODE);
57 out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); // Skip length of set field action
58 assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS);
59 assertEquals(out.readUnsignedByte(), OxmMatchConstants.IPV4_SRC << 1);
60 out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); // Skip match entry length
62 byte[] addressBytes = new byte[4];
63 out.readBytes(addressBytes);
64 assertArrayEquals(addressBytes, new byte[] { (byte) 192, (byte) 168, 76, 0 });
66 out.skipBytes(4); // Padding at end
71 protected Class<? extends Instruction> getClazz() {
72 return ApplyActionsCase.class;
76 protected int getType() {
77 return InstructionConstants.APPLY_ACTIONS_TYPE;
81 protected int getLength() {