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