ace1243325713a7b8092db6e4e7ebd6a6ff5e6a1
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / multipart / MultipartReplyTableFeaturesTest.java
1 /*
2  * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories.multipart;
10
11 import io.netty.buffer.ByteBuf;
12 import java.util.List;
13 import org.junit.Assert;
14 import org.junit.Test;
15 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.MultipartReplyMessageFactory;
16 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.NextTableRelatedTableFeatureProperty;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.table.features.properties.container.table.feature.properties.NextTableIds;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableFeaturesCase;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.features._case.MultipartReplyTableFeatures;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.features._case.multipart.reply.table.features.TableFeatures;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties;
25
26 /**
27  * Unit tests for MultipartReplyTableFeatures.
28  *
29  * @author michal.polkorab
30  */
31 public class MultipartReplyTableFeaturesTest {
32
33     private final MultipartReplyMessageFactory factory = new MultipartReplyMessageFactory();
34
35     /**
36      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO.
37      */
38     @Test
39     public void testEmptyMultipartReplyTableFeatures() {
40         ByteBuf bb = BufferHelper.buildBuffer("00 0C 00 00 00 00 00 00");
41         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(factory, bb);
42
43         BufferHelper.checkHeaderV13(builtByFactory);
44         Assert.assertEquals("Wrong type", 12, builtByFactory.getType().getIntValue());
45         Assert.assertEquals("Wrong flag", false, builtByFactory.getFlags().isOFPMPFREQMORE());
46         MultipartReplyTableFeaturesCase messageCase =
47                 (MultipartReplyTableFeaturesCase) builtByFactory.getMultipartReplyBody();
48         MultipartReplyTableFeatures message = messageCase.getMultipartReplyTableFeatures();
49         Assert.assertEquals("Wrong table features size", 0, message.getTableFeatures().size());
50     }
51
52     /**
53      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO.
54      */
55     @Test
56     public void testMultipartReplyTableFeatures() {
57         ByteBuf bb = BufferHelper.buildBuffer("00 0C 00 00 00 00 00 00 " + //
58                                               // first table feature
59                                               "00 40 01 00 00 00 00 00 " + // length, tableId, padding
60                                               "4F 70 65 6E 64 61 79 6C 69 67 68 74 00 00 00 00 00 00 00 " + //
61                                               "00 00 00 00 00 00 00 00 00 00 00 00 00 " + // name
62                                               "00 00 00 00 00 00 00 01 " + // metadata match
63                                               "00 00 00 00 00 00 00 02 " + // metadata write
64                                               "00 00 00 00 " + // config
65                                               "00 00 00 2A " + // max entries
66                                               // second table feature
67                                               "00 40 02 00 00 00 00 00 " + // length, tableId, padding
68                                               "4F 70 65 6E 64 61 79 6C 69 67 68 74 00 00 00 00 00 00 00"
69                                               + " 00 00 00 00 00 00 00 00 00 00 00 00 00 " + // name
70                                               "00 00 00 00 00 00 00 03 " + // metadata match
71                                               "00 00 00 00 00 00 00 04 " + // metadata write
72                                               "00 00 00 03 " + // config
73                                               "00 00 00 2B"  // max entries
74                                               );
75         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(factory, bb);
76
77         BufferHelper.checkHeaderV13(builtByFactory);
78         Assert.assertEquals("Wrong type", 12, builtByFactory.getType().getIntValue());
79         Assert.assertEquals("Wrong flag", false, builtByFactory.getFlags().isOFPMPFREQMORE());
80         MultipartReplyTableFeaturesCase messageCase =
81                 (MultipartReplyTableFeaturesCase) builtByFactory.getMultipartReplyBody();
82         MultipartReplyTableFeatures message = messageCase.getMultipartReplyTableFeatures();
83         Assert.assertEquals("Wrong table features size", 2, message.getTableFeatures().size());
84         TableFeatures feature = message.getTableFeatures().get(0);
85         Assert.assertEquals("Wrong table id", 1, feature.getTableId().intValue());
86         Assert.assertEquals("Wrong name", "Opendaylight", feature.getName());
87         Assert.assertArrayEquals("Wrong metadata match",
88                 new byte[]{0, 0, 0, 0, 0, 0, 0, 1}, feature.getMetadataMatch());
89         Assert.assertArrayEquals("Wrong metadata write",
90                 new byte[]{0, 0, 0, 0, 0, 0, 0, 2}, feature.getMetadataWrite());
91         Assert.assertEquals("Wrong config", false, feature.getConfig().isOFPTCDEPRECATEDMASK());
92         Assert.assertEquals("Wrong max entries", 42, feature.getMaxEntries().intValue());
93         feature = message.getTableFeatures().get(1);
94         Assert.assertEquals("Wrong table id", 2, feature.getTableId().intValue());
95         Assert.assertEquals("Wrong name", "Opendaylight", feature.getName());
96         Assert.assertArrayEquals("Wrong metadata match",
97                 new byte[]{0, 0, 0, 0, 0, 0, 0, 3}, feature.getMetadataMatch());
98         Assert.assertArrayEquals("Wrong metadata write",
99                 new byte[]{0, 0, 0, 0, 0, 0, 0, 4}, feature.getMetadataWrite());
100         Assert.assertEquals("Wrong config", true, feature.getConfig().isOFPTCDEPRECATEDMASK());
101         Assert.assertEquals("Wrong max entries", 43, feature.getMaxEntries().intValue());
102     }
103
104     /**
105      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO.
106      */
107     @Test
108     public void testMultipartReplyTableFeatures2() {
109         ByteBuf bb = BufferHelper.buildBuffer("00 0C 00 00 00 00 00 00 " + //
110                                               "00 B0 01 00 00 00 00 00 " + // length, tableId, padding
111                                               "4F 70 65 6E 64 61 79 6C 69 67 68 74 00 00 00 00 00 00 00 " + //
112                                               "00 00 00 00 00 00 00 00 00 00 00 00 00 " + // name
113                                               "00 00 00 00 00 00 00 01 " + // metadata match
114                                               "00 00 00 00 00 00 00 02 " + // metadata write
115                                               "00 00 00 00 " + // config
116                                               "00 00 00 2A " + // max entries
117                                               "00 00 00 04 00 00 00 00 " + //
118                                               "00 01 00 04 00 00 00 00 " + //
119                                               "00 02 00 08 01 02 03 04 " + //
120                                               "00 03 00 07 05 06 07 00 " + //
121                                               "00 04 00 04 00 00 00 00 " + //
122                                               "00 05 00 04 00 00 00 00 " + //
123                                               "00 06 00 04 00 00 00 00 " + //
124                                               "00 07 00 04 00 00 00 00 " + //
125                                               "00 08 00 04 00 00 00 00 " + //
126                                               "00 0A 00 04 00 00 00 00 " + //
127                                               "00 0C 00 04 00 00 00 00 " + //
128                                               "00 0D 00 04 00 00 00 00 " + //
129                                               "00 0E 00 04 00 00 00 00 " + //
130                                               "00 0F 00 04 00 00 00 00"
131                                               );
132         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(factory, bb);
133
134         BufferHelper.checkHeaderV13(builtByFactory);
135         Assert.assertEquals("Wrong type", 12, builtByFactory.getType().getIntValue());
136         Assert.assertEquals("Wrong flag", false, builtByFactory.getFlags().isOFPMPFREQMORE());
137         MultipartReplyTableFeaturesCase messageCase =
138                 (MultipartReplyTableFeaturesCase) builtByFactory.getMultipartReplyBody();
139         MultipartReplyTableFeatures message = messageCase.getMultipartReplyTableFeatures();
140         Assert.assertEquals("Wrong table features size", 1, message.getTableFeatures().size());
141         TableFeatures feature = message.getTableFeatures().get(0);
142         Assert.assertEquals("Wrong table id", 1, feature.getTableId().intValue());
143         Assert.assertEquals("Wrong name", "Opendaylight", feature.getName());
144         Assert.assertArrayEquals("Wrong metadata match",
145                 new byte[]{0, 0, 0, 0, 0, 0, 0, 1}, feature.getMetadataMatch());
146         Assert.assertArrayEquals("Wrong metadata write",
147                 new byte[]{0, 0, 0, 0, 0, 0, 0, 2}, feature.getMetadataWrite());
148         Assert.assertEquals("Wrong config", false, feature.getConfig().isOFPTCDEPRECATEDMASK());
149         Assert.assertEquals("Wrong max entries", 42, feature.getMaxEntries().intValue());
150         Assert.assertEquals("Wrong properties size", 14, feature.getTableFeatureProperties().size());
151         Assert.assertEquals("Wrong property type", TableFeaturesPropType.OFPTFPTINSTRUCTIONS,
152                 feature.getTableFeatureProperties().get(0).getType());
153         Assert.assertEquals("Wrong property type", TableFeaturesPropType.OFPTFPTINSTRUCTIONSMISS,
154                 feature.getTableFeatureProperties().get(1).getType());
155         TableFeatureProperties property = feature.getTableFeatureProperties().get(2);
156         Assert.assertEquals("Wrong property type", TableFeaturesPropType.OFPTFPTNEXTTABLES,
157                 property.getType());
158         List<NextTableIds> tableIds = property.getAugmentation(NextTableRelatedTableFeatureProperty.class)
159                 .getNextTableIds();
160         Assert.assertEquals("Wrong next table id size", 4, tableIds.size());
161         Assert.assertEquals("Wrong next table id", 1, tableIds.get(0).getTableId().intValue());
162         Assert.assertEquals("Wrong next table id", 2, tableIds.get(1).getTableId().intValue());
163         Assert.assertEquals("Wrong next table id", 3, tableIds.get(2).getTableId().intValue());
164         Assert.assertEquals("Wrong next table id", 4, tableIds.get(3).getTableId().intValue());
165         property = feature.getTableFeatureProperties().get(3);
166         Assert.assertEquals("Wrong property type", TableFeaturesPropType.OFPTFPTNEXTTABLESMISS,
167                 property.getType());
168         tableIds = property.getAugmentation(NextTableRelatedTableFeatureProperty.class)
169                 .getNextTableIds();
170         Assert.assertEquals("Wrong next table id size", 3, tableIds.size());
171         Assert.assertEquals("Wrong next table id", 5, tableIds.get(0).getTableId().intValue());
172         Assert.assertEquals("Wrong next table id", 6, tableIds.get(1).getTableId().intValue());
173         Assert.assertEquals("Wrong next table id", 7, tableIds.get(2).getTableId().intValue());
174         Assert.assertEquals("Wrong property type", TableFeaturesPropType.OFPTFPTWRITEACTIONS,
175                 feature.getTableFeatureProperties().get(4).getType());
176         Assert.assertEquals("Wrong property type", TableFeaturesPropType.OFPTFPTWRITEACTIONSMISS,
177                 feature.getTableFeatureProperties().get(5).getType());
178         Assert.assertEquals("Wrong property type", TableFeaturesPropType.OFPTFPTAPPLYACTIONS,
179                 feature.getTableFeatureProperties().get(6).getType());
180         Assert.assertEquals("Wrong property type", TableFeaturesPropType.OFPTFPTAPPLYACTIONSMISS,
181                 feature.getTableFeatureProperties().get(7).getType());
182         Assert.assertEquals("Wrong property type", TableFeaturesPropType.OFPTFPTMATCH,
183                 feature.getTableFeatureProperties().get(8).getType());
184         Assert.assertEquals("Wrong property type", TableFeaturesPropType.OFPTFPTWILDCARDS,
185                 feature.getTableFeatureProperties().get(9).getType());
186         Assert.assertEquals("Wrong property type", TableFeaturesPropType.OFPTFPTWRITESETFIELD,
187                 feature.getTableFeatureProperties().get(10).getType());
188         Assert.assertEquals("Wrong property type", TableFeaturesPropType.OFPTFPTWRITESETFIELDMISS,
189                 feature.getTableFeatureProperties().get(11).getType());
190         Assert.assertEquals("Wrong property type", TableFeaturesPropType.OFPTFPTAPPLYSETFIELD,
191                 feature.getTableFeatureProperties().get(12).getType());
192         Assert.assertEquals("Wrong property type", TableFeaturesPropType.OFPTFPTAPPLYSETFIELDMISS,
193                 feature.getTableFeatureProperties().get(13).getType());
194     }
195 }