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