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.impl.deserialization.DeserializerRegistryImpl;
\r
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction;
\r
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction;
\r
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;
\r
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlAction;
\r
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTtlAction;
\r
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsAction;
\r
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction;
\r
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry;
\r
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction;
\r
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
\r
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
\r
30 import org.slf4j.Logger;
\r
31 import org.slf4j.LoggerFactory;
\r
34 * @author michal.polkorab
\r
37 public class ActionsDeserializerTest {
\r
39 private static final Logger LOGGER = LoggerFactory
\r
40 .getLogger(ActionsDeserializerTest.class);
\r
41 private DeserializerRegistry registry;
\r
44 * Initializes deserializer registry and lookups correct deserializer
\r
47 public void startUp() {
\r
48 registry = new DeserializerRegistryImpl();
\r
53 * Testing actions deserialization
\r
56 public void test() {
\r
57 ByteBuf message = BufferHelper.buildBuffer("00 00 00 10 00 00 00 01 00 02 00 00 00 00 00 00 "
\r
58 + "00 0B 00 08 00 00 00 00 "
\r
59 + "00 0C 00 08 00 00 00 00 "
\r
60 + "00 0F 00 08 03 00 00 00 "
\r
61 + "00 10 00 08 00 00 00 00 "
\r
62 + "00 11 00 08 00 04 00 00 "
\r
63 + "00 12 00 08 00 00 00 00 "
\r
64 + "00 13 00 08 00 05 00 00 "
\r
65 + "00 14 00 08 00 06 00 00 "
\r
66 + "00 15 00 08 00 00 00 07 "
\r
67 + "00 16 00 08 00 00 00 08 "
\r
68 + "00 17 00 08 09 00 00 00 "
\r
69 + "00 18 00 08 00 00 00 00 "
\r
70 + "00 19 00 10 80 00 02 04 00 00 00 0B 00 00 00 00 "
\r
71 + "00 1A 00 08 00 0A 00 00 "
\r
72 + "00 1B 00 08 00 00 00 00");
\r
74 message.skipBytes(4); // skip XID
\r
75 LOGGER.info("bytes: " + message.readableBytes());
\r
77 CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
\r
78 List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID,
\r
79 message.readableBytes(), message, keyMaker, registry);
\r
80 Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."
\r
81 + "openflow.common.action.rev130731.Output", actions.get(0).getType().getName());
\r
82 Assert.assertEquals("Wrong action port", 1,
\r
83 actions.get(0).getAugmentation(PortAction.class).getPort().getValue().intValue());
\r
84 Assert.assertEquals("Wrong action max-length", 2,
\r
85 actions.get(0).getAugmentation(MaxLengthAction.class).getMaxLength().intValue());
\r
86 Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."
\r
87 + "openflow.common.action.rev130731.CopyTtlOut", actions.get(1).getType().getName());
\r
88 Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."
\r
89 + "openflow.common.action.rev130731.CopyTtlIn", actions.get(2).getType().getName());
\r
90 Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."
\r
91 + "openflow.common.action.rev130731.SetMplsTtl", actions.get(3).getType().getName());
\r
92 Assert.assertEquals("Wrong action value", 3,
\r
93 actions.get(3).getAugmentation(MplsTtlAction.class).getMplsTtl().shortValue());
\r
94 Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."
\r
95 + "openflow.common.action.rev130731.DecMplsTtl", actions.get(4).getType().getName());
\r
96 Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."
\r
97 + "openflow.common.action.rev130731.PushVlan", actions.get(5).getType().getName());
\r
98 Assert.assertEquals("Wrong action value", 4,
\r
99 actions.get(5).getAugmentation(EthertypeAction.class).getEthertype().getValue().intValue());
\r
100 Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."
\r
101 + "openflow.common.action.rev130731.PopVlan", actions.get(6).getType().getName());
\r
102 Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."
\r
103 + "openflow.common.action.rev130731.PushMpls", actions.get(7).getType().getName());
\r
104 Assert.assertEquals("Wrong action value", 5,
\r
105 actions.get(7).getAugmentation(EthertypeAction.class).getEthertype().getValue().intValue());
\r
106 Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."
\r
107 + "openflow.common.action.rev130731.PopMpls", actions.get(8).getType().getName());
\r
108 Assert.assertEquals("Wrong action value", 6,
\r
109 actions.get(8).getAugmentation(EthertypeAction.class).getEthertype().getValue().intValue());
\r
110 Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."
\r
111 + "openflow.common.action.rev130731.SetQueue", actions.get(9).getType().getName());
\r
112 Assert.assertEquals("Wrong action value", 7,
\r
113 actions.get(9).getAugmentation(QueueIdAction.class).getQueueId().intValue());
\r
114 Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."
\r
115 + "openflow.common.action.rev130731.Group", actions.get(10).getType().getName());
\r
116 Assert.assertEquals("Wrong action value", 8,
\r
117 actions.get(10).getAugmentation(GroupIdAction.class).getGroupId().intValue());
\r
118 Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."
\r
119 + "openflow.common.action.rev130731.SetNwTtl", actions.get(11).getType().getName());
\r
120 Assert.assertEquals("Wrong action value", 9,
\r
121 actions.get(11).getAugmentation(NwTtlAction.class).getNwTtl().intValue());
\r
122 Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."
\r
123 + "openflow.common.action.rev130731.DecNwTtl", actions.get(12).getType().getName());
\r
124 Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."
\r
125 + "openflow.common.action.rev130731.SetField", actions.get(13).getType().getName());
\r
126 List<MatchEntries> entries = actions.get(13).getAugmentation(OxmFieldsAction.class).getMatchEntries();
\r
127 Assert.assertEquals("Wrong number of fields", 1, entries.size());
\r
128 Assert.assertEquals("Wrong match entry class", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow."
\r
129 + "oxm.rev130731.OpenflowBasicClass", entries.get(0).getOxmClass().getName());
\r
130 Assert.assertEquals("Wrong match entry field", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow."
\r
131 + "oxm.rev130731.InPhyPort", entries.get(0).getOxmMatchField().getName());
\r
132 Assert.assertEquals("Wrong match entry mask", false, entries.get(0).isHasMask());
\r
133 Assert.assertEquals("Wrong match entry value", 11,
\r
134 entries.get(0).getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue());
\r
135 Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."
\r
136 + "openflow.common.action.rev130731.PushPbb", actions.get(14).getType().getName());
\r
137 Assert.assertEquals("Wrong action value", 10,
\r
138 actions.get(14).getAugmentation(EthertypeAction.class).getEthertype().getValue().intValue());
\r
139 Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."
\r
140 + "openflow.common.action.rev130731.PopPbb", actions.get(15).getType().getName());
\r
141 Assert.assertTrue("Unread data in message", message.readableBytes() == 0);
\r