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