Bug 2756 - Match model update
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / util / OF13MatchSerializerTest.java
1 /*
2  * Copyright (c) 2013 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.util;
10
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.UnpooledByteBufAllocator;
13
14 import java.util.ArrayList;
15 import java.util.List;
16
17 import org.junit.Assert;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
21 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
22 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
23 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
24 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
25 import org.opendaylight.openflowjava.util.ByteBufUtils;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6FlowLabel;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.oxm.container.match.entry.value.ExperimenterIdCaseBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.oxm.container.match.entry.value.experimenter.id._case.ExperimenterBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.StandardMatchType;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ExperimenterClass;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv4Src;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6Dst;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6Flabel;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6NdTarget;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6Src;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmMatchType;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv4SrcCaseBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6DstCaseBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6FlabelCaseBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6NdTargetCaseBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6SrcCaseBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv4.src._case.Ipv4SrcBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.dst._case.Ipv6DstBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.flabel._case.Ipv6FlabelBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.nd.target._case.Ipv6NdTargetBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.src._case.Ipv6SrcBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder;
56 import org.slf4j.Logger;
57 import org.slf4j.LoggerFactory;
58
59 /**
60  * @author michal.polkorab
61  *
62  */
63 public class OF13MatchSerializerTest {
64
65     private static final Logger LOG = LoggerFactory
66             .getLogger(OF13MatchSerializerTest.class);
67     private SerializerRegistry registry;
68     private OFSerializer<Match> matchSerializer;
69
70     /**
71      * Initializes serializer table and stores correct factory in field
72      */
73     @Before
74     public void startUp() {
75         registry = new SerializerRegistryImpl();
76         registry.init();
77         matchSerializer = registry.getSerializer(
78                 new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Match.class));
79     }
80
81     /**
82      * Test for correct serialization of Ipv4Address match entry
83      */
84     @Test
85     public void testIpv4Src() {
86         MatchBuilder builder = new MatchBuilder();
87         builder.setType(OxmMatchType.class);
88         List<MatchEntry> entries = new ArrayList<>();
89         MatchEntryBuilder entriesBuilder = new MatchEntryBuilder();
90         entriesBuilder.setOxmClass(OpenflowBasicClass.class);
91         entriesBuilder.setOxmMatchField(Ipv4Src.class);
92         entriesBuilder.setHasMask(false);
93         Ipv4SrcCaseBuilder ipv4SrcCaseBuilder = new Ipv4SrcCaseBuilder();
94         Ipv4SrcBuilder ipv4SrcBuilder = new Ipv4SrcBuilder();
95         ipv4SrcBuilder.setIpv4Address(new Ipv4Address("1.2.3.4"));
96         ipv4SrcCaseBuilder.setIpv4Src(ipv4SrcBuilder.build());
97         entriesBuilder.setMatchEntryValue(ipv4SrcCaseBuilder.build());
98         entries.add(entriesBuilder.build());
99         builder.setMatchEntry(entries);
100         Match match = builder.build();
101
102         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
103         matchSerializer.serialize(match, out);
104
105         Assert.assertEquals("Wrong type", 1, out.readUnsignedShort());
106         out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
107         Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort());
108         Assert.assertEquals("Wrong field and mask", 22, out.readUnsignedByte());
109         out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
110         Assert.assertEquals("Wrong ip address (first number)", 1, out.readUnsignedByte());
111         Assert.assertEquals("Wrong ip address (second number)", 2, out.readUnsignedByte());
112         Assert.assertEquals("Wrong ip address (third number)", 3, out.readUnsignedByte());
113         Assert.assertEquals("Wrong ip address (fourth number)", 4, out.readUnsignedByte());
114     }
115
116     /**
117      * Test for correct serialization of Ipv6Address match entry
118      */
119     @Test
120     public void testIpv6Various() {
121         MatchBuilder builder = new MatchBuilder();
122         builder.setType(OxmMatchType.class);
123         List<MatchEntry> entries = new ArrayList<>();
124         // ipv6 match entry with correct Ipv6 address
125         MatchEntryBuilder entriesBuilder = new MatchEntryBuilder();
126         entriesBuilder.setOxmClass(OpenflowBasicClass.class);
127         entriesBuilder.setOxmMatchField(Ipv6Src.class);
128         entriesBuilder.setHasMask(false);
129         Ipv6SrcCaseBuilder ipv6SrcCaseBuilder = new Ipv6SrcCaseBuilder();
130         Ipv6SrcBuilder ipv6SrcBuilder = new Ipv6SrcBuilder();
131         ipv6SrcBuilder.setIpv6Address(new Ipv6Address("1:2:3:4:5:6:7:8"));
132         ipv6SrcCaseBuilder.setIpv6Src(ipv6SrcBuilder.build());
133         entriesBuilder.setMatchEntryValue(ipv6SrcCaseBuilder.build());
134         entries.add(entriesBuilder.build());
135         // ipv6 match entry with abbreviated Ipv6 address
136         entriesBuilder = new MatchEntryBuilder();
137         entriesBuilder.setOxmClass(OpenflowBasicClass.class);
138         entriesBuilder.setOxmMatchField(Ipv6NdTarget.class);
139         entriesBuilder.setHasMask(false);
140         Ipv6NdTargetCaseBuilder ipv6NdTargetCaseBuilder = new Ipv6NdTargetCaseBuilder();
141         Ipv6NdTargetBuilder ipv6NdTargetBuilder = new Ipv6NdTargetBuilder();
142         ipv6NdTargetBuilder.setIpv6Address(new Ipv6Address("1:2::6:7:8"));
143         ipv6NdTargetCaseBuilder.setIpv6NdTarget(ipv6NdTargetBuilder.build());
144         entriesBuilder.setMatchEntryValue(ipv6NdTargetCaseBuilder.build());
145         entries.add(entriesBuilder.build());
146         // ipv6 match entry with abbreviated Ipv6 address
147         entriesBuilder = new MatchEntryBuilder();
148         entriesBuilder.setOxmClass(OpenflowBasicClass.class);
149         entriesBuilder.setOxmMatchField(Ipv6Dst.class);
150         entriesBuilder.setHasMask(false);
151         Ipv6DstCaseBuilder ipv6DstCaseBuilder = new Ipv6DstCaseBuilder();
152         Ipv6DstBuilder ipv6DstBuilder = new Ipv6DstBuilder();
153         ipv6DstBuilder.setIpv6Address(new Ipv6Address("1::8"));
154         ipv6DstCaseBuilder.setIpv6Dst(ipv6DstBuilder.build());
155         entriesBuilder.setMatchEntryValue(ipv6DstCaseBuilder.build());
156         entries.add(entriesBuilder.build());
157         // ipv6 match entry with abbreviated Ipv6 address
158         entriesBuilder = new MatchEntryBuilder();
159         entriesBuilder.setOxmClass(OpenflowBasicClass.class);
160         entriesBuilder.setOxmMatchField(Ipv6Dst.class);
161         entriesBuilder.setHasMask(false);
162         ipv6DstCaseBuilder = new Ipv6DstCaseBuilder();
163         ipv6DstBuilder = new Ipv6DstBuilder();
164         ipv6DstBuilder.setIpv6Address(new Ipv6Address("::1"));
165         ipv6DstCaseBuilder.setIpv6Dst(ipv6DstBuilder.build());
166         entriesBuilder.setMatchEntryValue(ipv6DstCaseBuilder.build());
167         entries.add(entriesBuilder.build());
168         // ipv6 match entry with abbreviated Ipv6 address
169         entriesBuilder = new MatchEntryBuilder();
170         entriesBuilder.setOxmClass(OpenflowBasicClass.class);
171         entriesBuilder.setOxmMatchField(Ipv6Dst.class);
172         entriesBuilder.setHasMask(false);
173         ipv6DstCaseBuilder = new Ipv6DstCaseBuilder();
174         ipv6DstBuilder = new Ipv6DstBuilder();
175         ipv6DstBuilder.setIpv6Address(new Ipv6Address("::"));
176         ipv6DstCaseBuilder.setIpv6Dst(ipv6DstBuilder.build());
177         entriesBuilder.setMatchEntryValue(ipv6DstCaseBuilder.build());
178         entries.add(entriesBuilder.build());
179         builder.setMatchEntry(entries);
180         Match match = builder.build();
181         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
182         matchSerializer.serialize(match, out);
183
184         Assert.assertEquals("Wrong type", 1, out.readUnsignedShort());
185         out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
186         Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort());
187         Assert.assertEquals("Wrong field and mask", 52, out.readUnsignedByte());
188         Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte());
189         Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort());
190         Assert.assertEquals("Wrong ipv6 address", 2, out.readUnsignedShort());
191         Assert.assertEquals("Wrong ipv6 address", 3, out.readUnsignedShort());
192         Assert.assertEquals("Wrong ipv6 address", 4, out.readUnsignedShort());
193         Assert.assertEquals("Wrong ipv6 address", 5, out.readUnsignedShort());
194         Assert.assertEquals("Wrong ipv6 address", 6, out.readUnsignedShort());
195         Assert.assertEquals("Wrong ipv6 address", 7, out.readUnsignedShort());
196         Assert.assertEquals("Wrong ipv6 address", 8, out.readUnsignedShort());
197         Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort());
198         Assert.assertEquals("Wrong field and mask", 62, out.readUnsignedByte());
199         Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte());
200         Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort());
201         Assert.assertEquals("Wrong ipv6 address", 2, out.readUnsignedShort());
202         Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
203         Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
204         Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
205         Assert.assertEquals("Wrong ipv6 address", 6, out.readUnsignedShort());
206         Assert.assertEquals("Wrong ipv6 address", 7, out.readUnsignedShort());
207         Assert.assertEquals("Wrong ipv6 address", 8, out.readUnsignedShort());
208         Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort());
209         Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte());
210         Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte());
211         Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort());
212         Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
213         Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
214         Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
215         Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
216         Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
217         Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
218         Assert.assertEquals("Wrong ipv6 address", 8, out.readUnsignedShort());
219         Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort());
220         Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte());
221         Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte());
222         Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
223         Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
224         Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
225         Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
226         Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
227         Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
228         Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
229         Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort());
230         Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort());
231         Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte());
232         Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte());
233         Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
234         Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
235         Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
236         Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
237         Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
238         Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
239         Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
240         Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
241     }
242
243     /**
244      * Test for correct serialization of incorrect Ipv6Address match entry
245      */
246     @Test(expected=IllegalStateException.class)
247     public void testIpv6Incorrect() {
248         MatchBuilder builder = new MatchBuilder();
249         builder.setType(OxmMatchType.class);
250         List<MatchEntry> entries = new ArrayList<>();
251         // ipv6 match entry with incorrect Ipv6 address
252         MatchEntryBuilder entriesBuilder = new MatchEntryBuilder();
253         entriesBuilder.setOxmClass(OpenflowBasicClass.class);
254         entriesBuilder.setOxmMatchField(Ipv6Src.class);
255         entriesBuilder.setHasMask(false);
256         Ipv6SrcCaseBuilder ipv6SrcCaseBuilder = new Ipv6SrcCaseBuilder();
257         Ipv6SrcBuilder ipv6SrcBuilder = new Ipv6SrcBuilder();
258         ipv6SrcBuilder.setIpv6Address(new Ipv6Address("1:2::::8"));
259         ipv6SrcCaseBuilder.setIpv6Src(ipv6SrcBuilder.build());
260         entriesBuilder.setMatchEntryValue(ipv6SrcCaseBuilder.build());
261         entries.add(entriesBuilder.build());
262         builder.setMatchEntry(entries);
263         Match match = builder.build();
264         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
265         matchSerializer.serialize(match, out);
266     }
267
268     /**
269      * Test for correct serialization of Ipv4Address match entry
270      */
271     @Test
272     public void testIpv6Flabel() {
273         Match match = buildIpv6FLabelMatch(0x0f9e8dL, false, null);
274
275         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
276         matchSerializer.serialize(match, out);
277
278         Assert.assertEquals("Wrong type", 1, out.readUnsignedShort());
279         out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
280         Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort());
281         Assert.assertEquals("Wrong field and mask", 56, out.readUnsignedByte());
282         out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
283         byte[] label = new byte[4];
284         out.readBytes(label);
285
286         LOG.debug("label: "+ ByteBufUtils.bytesToHexString(label));
287         Assert.assertArrayEquals("Wrong ipv6FLabel", new byte[]{0, 0x0f, (byte) 0x9e, (byte) 0x8d}, label);
288     }
289
290     /**
291      * Test for correct serialization of Ipv4Address match entry
292      */
293     @Test
294     public void testIpv6FlabelWithMask() {
295         Match match = buildIpv6FLabelMatch(0x0f9e8dL, true, new byte[]{0, 1, 2, 3});
296
297         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
298         matchSerializer.serialize(match, out);
299
300         Assert.assertEquals("Wrong type", 1, out.readUnsignedShort());
301         out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
302         Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort());
303         Assert.assertEquals("Wrong field and mask", 57, out.readUnsignedByte());
304         out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
305         byte[] label = new byte[4];
306         out.readBytes(label);
307         Assert.assertArrayEquals("Wrong ipv6FLabel", new byte[]{0, 0x0f, (byte) 0x9e, (byte) 0x8d}, label);
308         byte[] mask = new byte[4];
309         out.readBytes(mask);
310         Assert.assertArrayEquals("Wrong ipv6FLabel mask", new byte[]{0, 1, 2, 3}, mask);
311     }
312
313     /**
314      * Test for correct serialization of Ipv4Address match entry with wrong mask
315      */
316     @Test
317     public void testIpv6FlabelWithMaskBad() {
318         Match match = buildIpv6FLabelMatch(0x0f9e8dL, true, new byte[]{0x0c, 0x7b, 0x6a});
319         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
320
321         try {
322             matchSerializer.serialize(match, out);
323             Assert.fail("incorrect length of mask ignored");
324         } catch (IllegalArgumentException e) {
325             //expected
326         }
327     }
328
329     /**
330      * @param labelValue ipv6 flow label
331      * @param hasMask
332      * @param mask ipv6 flow label mask
333      * @return
334      */
335     private static Match buildIpv6FLabelMatch(long labelValue, boolean hasMask, byte[] mask) {
336         MatchBuilder builder = new MatchBuilder();
337         builder.setType(OxmMatchType.class);
338         List<MatchEntry> entries = new ArrayList<>();
339         MatchEntryBuilder entriesBuilder = new MatchEntryBuilder();
340         entriesBuilder.setOxmClass(OpenflowBasicClass.class);
341         entriesBuilder.setOxmMatchField(Ipv6Flabel.class);
342         entriesBuilder.setHasMask(hasMask);
343         Ipv6FlabelCaseBuilder ipv6FlabelCaseBuilder = new Ipv6FlabelCaseBuilder();
344         Ipv6FlabelBuilder ipv6FlabelBuilder = new Ipv6FlabelBuilder();
345         ipv6FlabelBuilder.setIpv6Flabel(new Ipv6FlowLabel(labelValue));
346         ipv6FlabelBuilder.setMask(mask);
347         ipv6FlabelCaseBuilder.setIpv6Flabel(ipv6FlabelBuilder.build());
348         entriesBuilder.setMatchEntryValue(ipv6FlabelCaseBuilder.build());
349         entries.add(entriesBuilder.build());
350         builder.setMatchEntry(entries);
351         Match match = builder.build();
352         return match;
353     }
354
355     /**
356      * Test Standard match type
357      */
358     @Test
359     public void testStandardMatchType() {
360         MatchBuilder builder = new MatchBuilder();
361         builder.setType(StandardMatchType.class);
362         Match match = builder.build();
363         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
364
365         matchSerializer.serialize(match, out);
366
367         Assert.assertEquals("Wrong match type", 0, out.readUnsignedShort());
368         Assert.assertEquals("Wrong match length", 4, out.readUnsignedShort());
369         Assert.assertEquals("Wrong padding", 0, out.readUnsignedInt());
370         Assert.assertEquals("Unexpected data", 0, out.readableBytes());
371     }
372
373     /**
374      * Test serialize experimenter match entry - with no experimenter
375      * match entry serializer registered
376      */
377     @Test(expected=IllegalStateException.class)
378     public void testSerializeExperimenterMatchEntry() {
379         List<MatchEntry> entries = new ArrayList<>();
380         MatchEntryBuilder builder = new MatchEntryBuilder();
381         builder.setOxmClass(ExperimenterClass.class);
382         builder.setOxmMatchField(OxmMatchFieldClass.class);
383         builder.setHasMask(true);
384         ExperimenterIdCaseBuilder caseBuilder = new ExperimenterIdCaseBuilder();
385         ExperimenterBuilder expBuilder = new ExperimenterBuilder();
386         expBuilder.setExperimenter(new ExperimenterId(42L));
387         caseBuilder.setExperimenter(expBuilder.build());
388         builder.setMatchEntryValue(caseBuilder.build());
389         entries.add(builder.build());
390         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
391
392         ((OF13MatchSerializer) matchSerializer).serializeMatchEntries(entries, out);
393     }
394
395     private class OxmMatchFieldClass extends MatchField {
396         // only for testing purposes
397     }
398 }