InstructionDeserializer split into separate deserializers
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / util / OF10ActionsDeserializerTest.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.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.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\r
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressAction;\r
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressAction;\r
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;\r
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTosAction;\r
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction;\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.augments.rev131002.VlanPcpAction;\r
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidAction;\r
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;\r
29 \r
30 /**\r
31  * @author michal.polkorab\r
32  *\r
33  */\r
34 public class OF10ActionsDeserializerTest {\r
35 \r
36     private DeserializerRegistry registry;\r
37 \r
38     /**\r
39      * Initializes deserializer registry and lookups correct deserializer\r
40      */\r
41     @Before\r
42     public void startUp() {\r
43         registry = new DeserializerRegistryImpl();\r
44         registry.init();\r
45     }\r
46 \r
47     /**\r
48      * Testing correct deserialization of actions (OF v1.0)\r
49      */\r
50     @Test\r
51     public void test() {\r
52         ByteBuf message = BufferHelper.buildBuffer("00 00 00 08 00 10 20 00 "\r
53                 + "00 01 00 08 10 10 00 00 "\r
54                 + "00 02 00 08 25 00 00 00 "\r
55                 + "00 03 00 08 00 00 00 00 "\r
56                 + "00 04 00 10 01 02 03 04 05 06 00 00 00 00 00 00 "\r
57                 + "00 05 00 10 02 03 04 05 06 07 00 00 00 00 00 00 "\r
58                 + "00 06 00 08 0A 00 00 01 "\r
59                 + "00 07 00 08 0B 00 00 02 "\r
60                 + "00 08 00 08 01 00 00 00 "\r
61                 + "00 09 00 08 00 02 00 00 "\r
62                 + "00 0A 00 08 00 03 00 00 "\r
63                 + "00 0B 00 10 00 04 00 00 00 00 00 00 00 00 00 30");\r
64         \r
65         message.skipBytes(4); // skip XID\r
66         CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF10_VERSION_ID);\r
67         List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF10_VERSION_ID,\r
68                 message.readableBytes(), message, keyMaker, registry);\r
69         Assert.assertEquals("Wrong number of actions", 12, actions.size());\r
70         Action action1 = actions.get(0);\r
71         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight"\r
72                 + ".openflow.common.action.rev130731.Output", action1.getType().getName());\r
73         Assert.assertEquals("Wrong port", 16,\r
74                 action1.getAugmentation(PortAction.class).getPort().getValue().intValue());\r
75         Assert.assertEquals("Wrong max-length", 8192,\r
76                 action1.getAugmentation(MaxLengthAction.class).getMaxLength().intValue());\r
77         Action action2 = actions.get(1);\r
78         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight"\r
79                 + ".openflow.common.action.rev130731.SetVlanVid", action2.getType().getName());\r
80         Assert.assertEquals("Wrong vlan-vid", 4112,\r
81                 action2.getAugmentation(VlanVidAction.class).getVlanVid().intValue());\r
82         Action action3 = actions.get(2);\r
83         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight"\r
84                 + ".openflow.common.action.rev130731.SetVlanPcp", action3.getType().getName());\r
85         Assert.assertEquals("Wrong vlan-pcp", 37,\r
86                 action3.getAugmentation(VlanPcpAction.class).getVlanPcp().intValue());\r
87         Action action4 = actions.get(3);\r
88         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight"\r
89                 + ".openflow.common.action.rev130731.StripVlan", action4.getType().getName());\r
90         Action action5 = actions.get(4);\r
91         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight"\r
92                 + ".openflow.common.action.rev130731.SetDlSrc", action5.getType().getName());\r
93         Assert.assertArrayEquals("Wrong dl-src", ByteBufUtils.macAddressToBytes("01:02:03:04:05:06"), \r
94                 ByteBufUtils.macAddressToBytes(action5.getAugmentation(DlAddressAction.class).getDlAddress().getValue()));\r
95         Action action6 = actions.get(5);\r
96         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight"\r
97                 + ".openflow.common.action.rev130731.SetDlDst", action6.getType().getName());\r
98         Assert.assertArrayEquals("Wrong dl-dst", ByteBufUtils.macAddressToBytes("02:03:04:05:06:07"), \r
99                 ByteBufUtils.macAddressToBytes(action6.getAugmentation(DlAddressAction.class).getDlAddress().getValue()));\r
100         Action action7 = actions.get(6);\r
101         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight"\r
102                 + ".openflow.common.action.rev130731.SetNwSrc", action7.getType().getName());\r
103         Assert.assertEquals("Wrong nw-src", new Ipv4Address("10.0.0.1"),\r
104                 action7.getAugmentation(IpAddressAction.class).getIpAddress());\r
105         Action action8 = actions.get(7);\r
106         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight"\r
107                 + ".openflow.common.action.rev130731.SetNwDst", action8.getType().getName());\r
108         Assert.assertEquals("Wrong nw-dst", new Ipv4Address("11.0.0.2"),\r
109                 action8.getAugmentation(IpAddressAction.class).getIpAddress());\r
110         Action action9 = actions.get(8);\r
111         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight"\r
112                 + ".openflow.common.action.rev130731.SetNwTos", action9.getType().getName());\r
113         Assert.assertEquals("Wrong nw-tos", 1, action9.getAugmentation(NwTosAction.class).getNwTos().intValue());\r
114         Action action10 = actions.get(9);\r
115         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight"\r
116                 + ".openflow.common.action.rev130731.SetTpSrc", action10.getType().getName());\r
117         Assert.assertEquals("Wrong port", 2, action10.getAugmentation(PortAction.class)\r
118                 .getPort().getValue().intValue());\r
119         Action action11 = actions.get(10);\r
120         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight"\r
121                 + ".openflow.common.action.rev130731.SetTpDst", action11.getType().getName());\r
122         Assert.assertEquals("Wrong port", 3, action11.getAugmentation(PortAction.class)\r
123                 .getPort().getValue().intValue());\r
124         Action action12 = actions.get(11);\r
125         Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight"\r
126                 + ".openflow.common.action.rev130731.Enqueue", action12.getType().getName());\r
127         Assert.assertEquals("Wrong port", 4, action12.getAugmentation(PortAction.class)\r
128                 .getPort().getValue().intValue());\r
129         Assert.assertEquals("Wrong queue-id", 48,\r
130                 action12.getAugmentation(QueueIdAction.class).getQueueId().intValue());\r
131     }\r
132 \r
133 }\r