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