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