2 * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.openflowjava.protocol.impl.util;
\r
10 import io.netty.buffer.ByteBuf;
\r
12 import java.util.List;
\r
14 import org.junit.Assert;
\r
15 import org.junit.Before;
\r
16 import org.junit.Test;
\r
17 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
\r
18 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey;
\r
19 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
\r
20 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
\r
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstruction;
\r
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction;
\r
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;
\r
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstruction;
\r
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MeterIdInstruction;
\r
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlAction;
\r
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction;
\r
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction;
\r
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstruction;
\r
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
\r
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;
\r
34 * @author michal.polkorab
\r
37 public class InstructionsDeserializerTest {
\r
39 private OFDeserializer<Instruction> insDeserializer;
\r
42 * Initializes deserializer registry and lookups correct deserializer
\r
45 public void startUp() {
\r
46 DeserializerRegistry registry = new DeserializerRegistryImpl();
\r
48 insDeserializer = registry.getDeserializer(
\r
49 new MessageCodeKey(EncodeConstants.OF13_VERSION_ID,
\r
50 EncodeConstants.EMPTY_VALUE, Instruction.class));
\r
54 * Testing instructions translation
\r
57 public void test() {
\r
58 ByteBuf message = BufferHelper.buildBuffer("00 01 00 08 0A 00 00 00 00 02 00 18 00 00 00 00 "
\r
59 + "00 00 00 00 00 00 00 20 00 00 00 00 00 00 00 30 00 05 00 08 00 00 00 00 00 06 00 08 "
\r
60 + "00 01 02 03 00 03 00 20 00 00 00 00 00 00 00 10 00 00 00 25 00 35 00 00 00 00 00 00 "
\r
61 + "00 16 00 08 00 00 00 50 00 04 00 18 00 00 00 00 00 15 00 08 00 00 00 25 00 0F 00 08 05 00 00 00");
\r
63 message.skipBytes(4); // skip XID
\r
65 List<Instruction> instructions = DecodingUtils.deserializeList(
\r
66 message.readableBytes(), message, insDeserializer);
\r
67 Instruction i1 = instructions.get(0);
\r
68 Assert.assertEquals("Wrong type - i1", "org.opendaylight.yang.gen.v1.urn."
\r
69 + "opendaylight.openflow.common.instruction.rev130731.GotoTable", i1.getType().getName());
\r
70 Assert.assertEquals("Wrong table-id - i1", 10, i1.getAugmentation(TableIdInstruction.class).getTableId().intValue());
\r
71 Instruction i2 = instructions.get(1);
\r
72 Assert.assertEquals("Wrong type - i2", "org.opendaylight.yang.gen.v1.urn."
\r
73 + "opendaylight.openflow.common.instruction.rev130731.WriteMetadata", i2.getType().getName());
\r
74 Assert.assertArrayEquals("Wrong metadata - i2", ByteBufUtils.hexStringToBytes("00 00 00 00 00 00 00 20"),
\r
75 i2.getAugmentation(MetadataInstruction.class).getMetadata());
\r
76 Assert.assertArrayEquals("Wrong metadata-mask - i2", ByteBufUtils.hexStringToBytes("00 00 00 00 00 00 00 30"),
\r
77 i2.getAugmentation(MetadataInstruction.class).getMetadataMask());
\r
78 Instruction i3 = instructions.get(2);
\r
79 Assert.assertEquals("Wrong type - i3", "org.opendaylight.yang.gen.v1.urn."
\r
80 + "opendaylight.openflow.common.instruction.rev130731.ClearActions", i3.getType().getName());
\r
81 Assert.assertEquals("Wrong instructions - i3", 0, i3.getAugmentation(ActionsInstruction.class).getAction().size());
\r
82 Instruction i4 = instructions.get(3);
\r
83 Assert.assertEquals("Wrong type - i4", "org.opendaylight.yang.gen.v1.urn."
\r
84 + "opendaylight.openflow.common.instruction.rev130731.Meter", i4.getType().getName());
\r
85 Assert.assertEquals("Wrong meterId - i4", 66051, i4.getAugmentation(MeterIdInstruction.class).getMeterId().intValue());
\r
86 Instruction i5 = instructions.get(4);
\r
87 Assert.assertEquals("Wrong type - i5", "org.opendaylight.yang.gen.v1.urn."
\r
88 + "opendaylight.openflow.common.instruction.rev130731.WriteActions", i5.getType().getName());
\r
89 Assert.assertEquals("Wrong instructions - i5", 2, i5.getAugmentation(ActionsInstruction.class).getAction().size());
\r
90 Action action1 = i5.getAugmentation(ActionsInstruction.class).getAction().get(0);
\r
91 Assert.assertEquals("Wrong action", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output",
\r
92 action1.getType().getName());
\r
93 Assert.assertEquals("Wrong action", 37, action1.getAugmentation(PortAction.class).getPort().getValue().intValue());
\r
94 Assert.assertEquals("Wrong action", 53, action1.getAugmentation(MaxLengthAction.class).getMaxLength().intValue());
\r
95 Action action2 = i5.getAugmentation(ActionsInstruction.class).getAction().get(1);
\r
96 Assert.assertEquals("Wrong action", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group",
\r
97 action2.getType().getName());
\r
98 Assert.assertEquals("Wrong action", 80, action2.getAugmentation(GroupIdAction.class).getGroupId().intValue());
\r
99 Instruction i6 = instructions.get(5);
\r
100 Assert.assertEquals("Wrong type - i6", "org.opendaylight.yang.gen.v1.urn."
\r
101 + "opendaylight.openflow.common.instruction.rev130731.ApplyActions", i6.getType().getName());
\r
102 Assert.assertEquals("Wrong instructions - i6", 2, i6.getAugmentation(ActionsInstruction.class).getAction().size());
\r
103 action1 = i6.getAugmentation(ActionsInstruction.class).getAction().get(0);
\r
104 Assert.assertEquals("Wrong action", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue",
\r
105 action1.getType().getName());
\r
106 Assert.assertEquals("Wrong action", 37, action1.getAugmentation(QueueIdAction.class).getQueueId().intValue());
\r
107 action2 = i6.getAugmentation(ActionsInstruction.class).getAction().get(1);
\r
108 Assert.assertEquals("Wrong action", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl",
\r
109 action2.getType().getName());
\r
110 Assert.assertEquals("Wrong action", 5, action2.getAugmentation(MplsTtlAction.class).getMplsTtl().intValue());
\r