a63edea95735bf90c54ff2624fd5b25cf1e71df5
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / util / ActionsDeserializerTest.java
1 /*\r
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
3  *\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
7  */\r
8 package org.opendaylight.openflowjava.protocol.impl.util;\r
9 \r
10 import io.netty.buffer.ByteBuf;\r
11 \r
12 import java.util.List;\r
13 \r
14 import org.junit.Assert;\r
15 import org.junit.Test;\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction;\r
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction;\r
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction;\r
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;\r
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlAction;\r
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTtlAction;\r
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsAction;\r
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction;\r
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry;\r
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction;\r
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;\r
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
28 import org.slf4j.Logger;\r
29 import org.slf4j.LoggerFactory;\r
30 \r
31 /**\r
32  * @author michal.polkorab\r
33  *\r
34  */\r
35 public class ActionsDeserializerTest {\r
36 \r
37     private static final Logger LOGGER = LoggerFactory\r
38             .getLogger(ActionsDeserializerTest.class);\r
39     /**\r
40      * Testing actions deserialization\r
41      */\r
42     @Test\r
43     public void test() {\r
44         ByteBuf message = BufferHelper.buildBuffer("00 00 00 10 00 00 00 01 00 02 00 00 00 00 00 00 "\r
45                 + "00 0B 00 08 00 00 00 00 "\r
46                 + "00 0C 00 08 00 00 00 00 "\r
47                 + "00 0F 00 08 03 00 00 00 "\r
48                 + "00 10 00 08 00 00 00 00 "\r
49                 + "00 11 00 08 00 04 00 00 "\r
50                 + "00 12 00 08 00 00 00 00 "\r
51                 + "00 13 00 08 00 05 00 00 "\r
52                 + "00 14 00 08 00 06 00 00 "\r
53                 + "00 15 00 08 00 00 00 07 "\r
54                 + "00 16 00 08 00 00 00 08 "\r
55                 + "00 17 00 08 09 00 00 00 "\r
56                 + "00 18 00 08 00 00 00 00 "\r
57                 + "00 19 00 10 80 00 02 04 00 00 00 0B 00 00 00 00 "\r
58                 + "00 1A 00 08 00 0A 00 00 "\r
59                 + "00 1B 00 08 00 00 00 00 "\r
60                 + "FF FF 00 10 00 00 00 08 00 01 02 03 04 05 06 07");\r
61         \r
62         message.skipBytes(4); // skip XID\r
63         LOGGER.info("bytes: " + message.readableBytes());\r
64         List<Action> actions = ActionsDeserializer.createActions(message, message.readableBytes());\r
65         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
66                 + "openflow.common.action.rev130731.Output", actions.get(0).getType().getName());\r
67         Assert.assertEquals("Wrong action port", 1,\r
68                 actions.get(0).getAugmentation(PortAction.class).getPort().getValue().intValue());\r
69         Assert.assertEquals("Wrong action max-length", 2,\r
70                 actions.get(0).getAugmentation(MaxLengthAction.class).getMaxLength().intValue());\r
71         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
72                 + "openflow.common.action.rev130731.CopyTtlOut", actions.get(1).getType().getName());\r
73         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
74                 + "openflow.common.action.rev130731.CopyTtlIn", actions.get(2).getType().getName());\r
75         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
76                 + "openflow.common.action.rev130731.SetMplsTtl", actions.get(3).getType().getName());\r
77         Assert.assertEquals("Wrong action value", 3,\r
78                 actions.get(3).getAugmentation(MplsTtlAction.class).getMplsTtl().shortValue());\r
79         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
80                 + "openflow.common.action.rev130731.DecMplsTtl", actions.get(4).getType().getName());\r
81         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
82                 + "openflow.common.action.rev130731.PushVlan", actions.get(5).getType().getName());\r
83         Assert.assertEquals("Wrong action value", 4,\r
84                 actions.get(5).getAugmentation(EthertypeAction.class).getEthertype().getValue().intValue());\r
85         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
86                 + "openflow.common.action.rev130731.PopVlan", actions.get(6).getType().getName());\r
87         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
88                 + "openflow.common.action.rev130731.PushMpls", actions.get(7).getType().getName());\r
89         Assert.assertEquals("Wrong action value", 5,\r
90                 actions.get(7).getAugmentation(EthertypeAction.class).getEthertype().getValue().intValue());\r
91         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
92                 + "openflow.common.action.rev130731.PopMpls", actions.get(8).getType().getName());\r
93         Assert.assertEquals("Wrong action value", 6,\r
94                 actions.get(8).getAugmentation(EthertypeAction.class).getEthertype().getValue().intValue());\r
95         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
96                 + "openflow.common.action.rev130731.SetQueue", actions.get(9).getType().getName());\r
97         Assert.assertEquals("Wrong action value", 7,\r
98                 actions.get(9).getAugmentation(QueueIdAction.class).getQueueId().intValue());\r
99         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
100                 + "openflow.common.action.rev130731.Group", actions.get(10).getType().getName());\r
101         Assert.assertEquals("Wrong action value", 8,\r
102                 actions.get(10).getAugmentation(GroupIdAction.class).getGroupId().intValue());\r
103         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
104                 + "openflow.common.action.rev130731.SetNwTtl", actions.get(11).getType().getName());\r
105         Assert.assertEquals("Wrong action value", 9,\r
106                 actions.get(11).getAugmentation(NwTtlAction.class).getNwTtl().intValue());\r
107         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
108                 + "openflow.common.action.rev130731.DecNwTtl", actions.get(12).getType().getName());\r
109         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
110                 + "openflow.common.action.rev130731.SetField", actions.get(13).getType().getName());\r
111         List<MatchEntries> entries = actions.get(13).getAugmentation(OxmFieldsAction.class).getMatchEntries();\r
112         Assert.assertEquals("Wrong number of fields", 1, entries.size());\r
113         Assert.assertEquals("Wrong match entry class", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow."\r
114                 + "oxm.rev130731.OpenflowBasicClass", entries.get(0).getOxmClass().getName());\r
115         Assert.assertEquals("Wrong match entry field", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow."\r
116                 + "oxm.rev130731.InPhyPort", entries.get(0).getOxmMatchField().getName());\r
117         Assert.assertEquals("Wrong match entry mask", false, entries.get(0).isHasMask());\r
118         Assert.assertEquals("Wrong match entry value", 11, \r
119                 entries.get(0).getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue());\r
120         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
121                 + "openflow.common.action.rev130731.PushPbb", actions.get(14).getType().getName());\r
122         Assert.assertEquals("Wrong action value", 10,\r
123                 actions.get(14).getAugmentation(EthertypeAction.class).getEthertype().getValue().intValue());\r
124         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
125                 + "openflow.common.action.rev130731.PopPbb", actions.get(15).getType().getName());\r
126         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight."\r
127                 + "openflow.common.action.rev130731.Experimenter", actions.get(16).getType().getName());\r
128         Assert.assertEquals("Wrong experimenter", 8, actions.get(16).getAugmentation(ExperimenterAction.class)\r
129                 .getExperimenter().intValue());\r
130         Assert.assertArrayEquals("Wrong data", new byte[]{0, 1, 2, 3, 4, 5, 6, 7}, actions.get(16)\r
131                 .getAugmentation(ExperimenterAction.class).getData());\r
132         Assert.assertTrue("Unread data in message", message.readableBytes() == 0);\r
133     }\r
134 \r
135 }\r