Remove EncodeConstants.SIZE_OF_{BYTE,SHORT,INT,LONG}_IN_BYTES
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / util / MatchDeserializerTest.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 package org.opendaylight.openflowjava.protocol.impl.util;
9
10 import io.netty.buffer.ByteBuf;
11 import java.util.List;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
18 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
19 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
20 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
21 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
22 import org.opendaylight.openflowjava.util.ByteBufUtils;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.StandardMatchType;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ArpOp;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ArpSha;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ArpSpa;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ArpTha;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ArpTpa;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.EthDst;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.EthSrc;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.EthType;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Icmpv4Code;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Icmpv4Type;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Icmpv6Code;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Icmpv6Type;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.InPhyPort;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.InPort;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.IpDscp;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.IpEcn;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.IpProto;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv4Dst;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv4Src;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6Dst;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6Exthdr;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6Flabel;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6NdSll;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6NdTarget;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6NdTll;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6Src;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Metadata;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MplsBos;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MplsLabel;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MplsTc;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmMatchType;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.PacketType;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.PbbIsid;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.SctpDst;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.SctpSrc;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.TcpDst;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.TcpSrc;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.TunnelId;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.UdpDst;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.UdpSrc;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.VlanPcp;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.VlanVid;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ArpOpCase;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ArpShaCase;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ArpSpaCase;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ArpThaCase;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ArpTpaCase;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.EthDstCase;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.EthSrcCase;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.EthTypeCase;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Icmpv4CodeCase;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Icmpv4TypeCase;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Icmpv6CodeCase;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Icmpv6TypeCase;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.InPhyPortCase;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.InPortCase;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.IpDscpCase;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.IpEcnCase;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.IpProtoCase;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv4DstCase;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv4SrcCase;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6DstCase;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6ExthdrCase;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6FlabelCase;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6NdSllCase;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6NdTargetCase;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6NdTllCase;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6SrcCase;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.MetadataCase;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.MplsBosCase;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.MplsLabelCase;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.MplsTcCase;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.PacketTypeCase;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.PbbIsidCase;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.SctpDstCase;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.SctpSrcCase;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.TcpDstCase;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.TcpSrcCase;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.TunnelIdCase;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.UdpDstCase;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.UdpSrcCase;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.VlanPcpCase;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.VlanVidCase;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match;
114
115 /**
116  * Unit tests for MatchDeserializer.
117  *
118  * @author michal.polkorab
119  */
120 public class MatchDeserializerTest {
121
122     private OFDeserializer<Match> matchDeserializer;
123     private DeserializerRegistry registry;
124
125     /**
126      * Initializes deserializer registry and lookups correct deserializer.
127      */
128     @Before
129     public void startUp() {
130         registry = new DeserializerRegistryImpl();
131         registry.init();
132         matchDeserializer = registry.getDeserializer(
133                 new MessageCodeKey(EncodeConstants.OF13_VERSION_ID,
134                         EncodeConstants.EMPTY_VALUE, Match.class));
135     }
136
137     /**
138      * Testing Ipv4 address deserialization.
139      */
140     @Test
141     public void testIpv4Address() {
142         ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("80 00 18 04 00 01 02 03");
143
144         MatchEntryDeserializerKey key = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID,
145                 0x8000, 12);
146         key.setExperimenterId(null);
147         OFDeserializer<MatchEntry> entryDeserializer = registry.getDeserializer(key);
148         MatchEntry entry = entryDeserializer.deserialize(buffer);
149         Assert.assertEquals("Wrong Ipv4 address format", new Ipv4Address("0.1.2.3"),
150                 ((Ipv4DstCase) entry.getMatchEntryValue()).getIpv4Dst().getIpv4Address());
151     }
152
153     /**
154      * Testing Ipv6 address deserialization.
155      */
156     @Test
157     public void testIpv6Address() {
158         ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("80 00 34 10 00 00 00 01 00 02 00 03 00 04 00 05 00 06 0F 07");
159
160         MatchEntryDeserializerKey key = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID,
161                 0x8000, 26);
162         key.setExperimenterId(null);
163         OFDeserializer<MatchEntry> entryDeserializer = registry.getDeserializer(key);
164         MatchEntry entry = entryDeserializer.deserialize(buffer);
165         Assert.assertEquals("Wrong Ipv6 address format", new Ipv6Address("0:1:2:3:4:5:6:f07"),
166                 ((Ipv6SrcCase) entry.getMatchEntryValue()).getIpv6Src().getIpv6Address());
167     }
168
169     /**
170      * Testing match deserialization.
171      */
172     @Test
173     public void testMatch() {
174         ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("00 01 01 B0 "
175                 + "80 00 00 04 00 00 00 01 "
176                 + "80 00 02 04 00 00 00 02 "
177                 + "80 00 05 10 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 04 "
178                 + "80 00 07 0C 00 00 00 00 00 05 00 00 00 00 00 06 "
179                 + "80 00 09 0C 00 00 00 00 00 07 00 00 00 00 00 08 "
180                 + "80 00 0A 02 00 09 "
181                 + "80 00 0D 04 00 0A 00 0B "
182                 + "80 00 0E 01 0C "
183                 + "80 00 10 01 0D "
184                 + "80 00 12 01 0E "
185                 + "80 00 14 01 0F "
186                 + "80 00 17 08 0A 00 00 01 00 00 FF 00 "
187                 + "80 00 19 08 0A 00 00 02 00 00 00 FF "
188                 + "80 00 1A 02 00 03 "
189                 + "80 00 1C 02 00 04 "
190                 + "80 00 1E 02 00 05 "
191                 + "80 00 20 02 00 06 "
192                 + "80 00 22 02 00 07 "
193                 + "80 00 24 02 00 08 "
194                 + "80 00 26 01 05 "
195                 + "80 00 28 01 07 "
196                 + "80 00 2A 02 00 10 "
197                 + "80 00 2D 08 0A 00 00 09 00 00 FF 00 "
198                 + "80 00 2F 08 0A 00 00 0A 00 00 00 FF "
199                 + "80 00 31 0C 00 00 00 00 00 01 00 00 00 00 00 03 "
200                 + "80 00 33 0C 00 00 00 00 00 02 00 00 00 00 00 04 "
201                 + "80 00 35 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 "
202                 +             "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 16 "
203                 + "80 00 37 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 17 "
204                 +             "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 18 "
205                 + "80 00 38 04 00 00 00 02 "
206                 + "80 00 3A 01 15 "
207                 + "80 00 3C 01 17 "
208                 + "80 00 3E 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 " //ipv6ndtarget
209                 + "80 00 40 06 00 05 00 00 00 01 "
210                 + "80 00 42 06 00 05 00 00 00 02 "
211                 + "80 00 44 04 00 00 02 03 "
212                 + "80 00 46 01 03 "
213                 + "80 00 48 01 01 "
214                 + "80 00 4B 06 00 00 02 00 00 01 "
215                 + "80 00 4D 10 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 FF "
216                 + "80 00 4F 04 00 00 03 04 "
217                 + "80 00 58 04 00 01 89 4f");
218
219         Match match = matchDeserializer.deserialize(buffer);
220         Assert.assertEquals("Wrong match type", OxmMatchType.class, match.getType());
221         Assert.assertEquals("Wrong match entries size", 41, match.getMatchEntry().size());
222         List<MatchEntry> entries = match.getMatchEntry();
223         MatchEntry entry0 = entries.get(0);
224         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry0.getOxmClass());
225         Assert.assertEquals("Wrong entry field", InPort.class, entry0.getOxmMatchField());
226         Assert.assertEquals("Wrong entry hasMask", false, entry0.isHasMask());
227         Assert.assertEquals("Wrong entry value", 1,
228                 ((InPortCase) entry0.getMatchEntryValue()).getInPort().getPortNumber().getValue().intValue());
229         MatchEntry entry1 = entries.get(1);
230         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry1.getOxmClass());
231         Assert.assertEquals("Wrong entry field", InPhyPort.class, entry1.getOxmMatchField());
232         Assert.assertEquals("Wrong entry hasMask", false, entry1.isHasMask());
233         Assert.assertEquals("Wrong entry value", 2,
234                 ((InPhyPortCase) entry1.getMatchEntryValue()).getInPhyPort().getPortNumber().getValue().intValue());
235         MatchEntry entry2 = entries.get(2);
236         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry2.getOxmClass());
237         Assert.assertEquals("Wrong entry field", Metadata.class, entry2.getOxmMatchField());
238         Assert.assertEquals("Wrong entry hasMask", true, entry2.isHasMask());
239         Assert.assertArrayEquals("Wrong entry value", ByteBufUtils.hexStringToBytes("00 00 00 00 00 00 00 03"),
240                 ((MetadataCase) entry2.getMatchEntryValue()).getMetadata().getMetadata());
241         Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 00 00 00 00 00 00 04"),
242                 ((MetadataCase) entry2.getMatchEntryValue()).getMetadata().getMask());
243         MatchEntry entry3 = entries.get(3);
244         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry3.getOxmClass());
245         Assert.assertEquals("Wrong entry field", EthDst.class, entry3.getOxmMatchField());
246         Assert.assertEquals("Wrong entry hasMask", true, entry3.isHasMask());
247         Assert.assertEquals("Wrong entry value", new MacAddress("00:00:00:00:00:05"),
248                 ((EthDstCase) entry3.getMatchEntryValue()).getEthDst().getMacAddress());
249         Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 00 00 00 00 06"),
250                 ((EthDstCase) entry3.getMatchEntryValue()).getEthDst().getMask());
251         MatchEntry entry4 = entries.get(4);
252         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry4.getOxmClass());
253         Assert.assertEquals("Wrong entry field", EthSrc.class, entry4.getOxmMatchField());
254         Assert.assertEquals("Wrong entry hasMask", true, entry4.isHasMask());
255         Assert.assertEquals("Wrong entry value", new MacAddress("00:00:00:00:00:07"),
256                 ((EthSrcCase) entry4.getMatchEntryValue()).getEthSrc().getMacAddress());
257         Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 00 00 00 00 08"),
258                 ((EthSrcCase) entry4.getMatchEntryValue()).getEthSrc().getMask());
259         MatchEntry entry5 = entries.get(5);
260         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry5.getOxmClass());
261         Assert.assertEquals("Wrong entry field", EthType.class, entry5.getOxmMatchField());
262         Assert.assertEquals("Wrong entry hasMask", false, entry5.isHasMask());
263         Assert.assertEquals("Wrong entry value", 9,
264                 ((EthTypeCase) entry5.getMatchEntryValue()).getEthType().getEthType().getValue().intValue());
265         MatchEntry entry6 = entries.get(6);
266         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry6.getOxmClass());
267         Assert.assertEquals("Wrong entry field", VlanVid.class, entry6.getOxmMatchField());
268         Assert.assertEquals("Wrong entry hasMask", true, entry6.isHasMask());
269         Assert.assertEquals("Wrong entry value", 10,
270                 ((VlanVidCase) entry6.getMatchEntryValue()).getVlanVid().getVlanVid().intValue());
271         Assert.assertEquals("Wrong entry value", false,
272                 ((VlanVidCase) entry6.getMatchEntryValue()).getVlanVid().isCfiBit());
273         Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 0B"),
274                 ((VlanVidCase) entry6.getMatchEntryValue()).getVlanVid().getMask());
275         MatchEntry entry7 = entries.get(7);
276         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry7.getOxmClass());
277         Assert.assertEquals("Wrong entry field", VlanPcp.class, entry7.getOxmMatchField());
278         Assert.assertEquals("Wrong entry hasMask", false, entry7.isHasMask());
279         Assert.assertEquals("Wrong entry value", 12,
280                 ((VlanPcpCase) entry7.getMatchEntryValue()).getVlanPcp().getVlanPcp().intValue());
281         MatchEntry entry8 = entries.get(8);
282         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry8.getOxmClass());
283         Assert.assertEquals("Wrong entry field", IpDscp.class, entry8.getOxmMatchField());
284         Assert.assertEquals("Wrong entry hasMask", false, entry8.isHasMask());
285         Assert.assertEquals("Wrong entry value", 13,
286                 ((IpDscpCase) entry8.getMatchEntryValue()).getIpDscp().getDscp().getValue().intValue());
287         MatchEntry entry9 = entries.get(9);
288         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry9.getOxmClass());
289         Assert.assertEquals("Wrong entry field", IpEcn.class, entry9.getOxmMatchField());
290         Assert.assertEquals("Wrong entry hasMask", false, entry9.isHasMask());
291         Assert.assertEquals("Wrong entry value", 14,
292                 ((IpEcnCase) entry9.getMatchEntryValue()).getIpEcn().getEcn().intValue());
293         MatchEntry entry10 = entries.get(10);
294         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry10.getOxmClass());
295         Assert.assertEquals("Wrong entry field", IpProto.class, entry10.getOxmMatchField());
296         Assert.assertEquals("Wrong entry hasMask", false, entry10.isHasMask());
297         Assert.assertEquals("Wrong entry value", 15,
298                 ((IpProtoCase) entry10.getMatchEntryValue()).getIpProto().getProtocolNumber().intValue());
299         MatchEntry entry11 = entries.get(11);
300         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry11.getOxmClass());
301         Assert.assertEquals("Wrong entry field", Ipv4Src.class, entry11.getOxmMatchField());
302         Assert.assertEquals("Wrong entry hasMask", true, entry11.isHasMask());
303         Assert.assertEquals("Wrong entry value", new Ipv4Address("10.0.0.1"),
304                 ((Ipv4SrcCase) entry11.getMatchEntryValue()).getIpv4Src().getIpv4Address());
305         Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 00 FF 00"),
306                 ((Ipv4SrcCase) entry11.getMatchEntryValue()).getIpv4Src().getMask());
307         MatchEntry entry12 = entries.get(12);
308         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry12.getOxmClass());
309         Assert.assertEquals("Wrong entry field", Ipv4Dst.class, entry12.getOxmMatchField());
310         Assert.assertEquals("Wrong entry hasMask", true, entry12.isHasMask());
311         Assert.assertEquals("Wrong entry value", new Ipv4Address("10.0.0.2"),
312                 ((Ipv4DstCase) entry12.getMatchEntryValue()).getIpv4Dst().getIpv4Address());
313         Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 00 00 FF"),
314                 ((Ipv4DstCase) entry12.getMatchEntryValue()).getIpv4Dst().getMask());
315         MatchEntry entry13 = entries.get(13);
316         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry13.getOxmClass());
317         Assert.assertEquals("Wrong entry field", TcpSrc.class, entry13.getOxmMatchField());
318         Assert.assertEquals("Wrong entry hasMask", false, entry13.isHasMask());
319         Assert.assertEquals("Wrong entry value", 3,
320                 ((TcpSrcCase) entry13.getMatchEntryValue()).getTcpSrc().getPort().getValue().intValue());
321         MatchEntry entry14 = entries.get(14);
322         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry14.getOxmClass());
323         Assert.assertEquals("Wrong entry field", TcpDst.class, entry14.getOxmMatchField());
324         Assert.assertEquals("Wrong entry hasMask", false, entry14.isHasMask());
325         Assert.assertEquals("Wrong entry value", 4,
326                 ((TcpDstCase) entry14.getMatchEntryValue()).getTcpDst().getPort().getValue().intValue());
327         MatchEntry entry15 = entries.get(15);
328         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry15.getOxmClass());
329         Assert.assertEquals("Wrong entry field", UdpSrc.class, entry15.getOxmMatchField());
330         Assert.assertEquals("Wrong entry hasMask", false, entry15.isHasMask());
331         Assert.assertEquals("Wrong entry value", 5,
332                 ((UdpSrcCase) entry15.getMatchEntryValue()).getUdpSrc().getPort().getValue().intValue());
333         MatchEntry entry16 = entries.get(16);
334         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry16.getOxmClass());
335         Assert.assertEquals("Wrong entry field", UdpDst.class, entry16.getOxmMatchField());
336         Assert.assertEquals("Wrong entry hasMask", false, entry16.isHasMask());
337         Assert.assertEquals("Wrong entry value", 6,
338                 ((UdpDstCase) entry16.getMatchEntryValue()).getUdpDst().getPort().getValue().intValue());
339         MatchEntry entry17 = entries.get(17);
340         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry17.getOxmClass());
341         Assert.assertEquals("Wrong entry field", SctpSrc.class, entry17.getOxmMatchField());
342         Assert.assertEquals("Wrong entry hasMask", false, entry17.isHasMask());
343         Assert.assertEquals("Wrong entry value", 7,
344                 ((SctpSrcCase) entry17.getMatchEntryValue()).getSctpSrc().getPort().getValue().intValue());
345         MatchEntry entry18 = entries.get(18);
346         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry18.getOxmClass());
347         Assert.assertEquals("Wrong entry field", SctpDst.class, entry18.getOxmMatchField());
348         Assert.assertEquals("Wrong entry hasMask", false, entry18.isHasMask());
349         Assert.assertEquals("Wrong entry value", 8,
350                 ((SctpDstCase) entry18.getMatchEntryValue()).getSctpDst().getPort().getValue().intValue());
351         MatchEntry entry19 = entries.get(19);
352         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry19.getOxmClass());
353         Assert.assertEquals("Wrong entry field", Icmpv4Type.class, entry19.getOxmMatchField());
354         Assert.assertEquals("Wrong entry hasMask", false, entry19.isHasMask());
355         Assert.assertEquals("Wrong entry value", 5,
356                 ((Icmpv4TypeCase) entry19.getMatchEntryValue()).getIcmpv4Type().getIcmpv4Type().intValue());
357         MatchEntry entry20 = entries.get(20);
358         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry20.getOxmClass());
359         Assert.assertEquals("Wrong entry field", Icmpv4Code.class, entry20.getOxmMatchField());
360         Assert.assertEquals("Wrong entry hasMask", false, entry20.isHasMask());
361         Assert.assertEquals("Wrong entry value", 7,
362                 ((Icmpv4CodeCase) entry20.getMatchEntryValue()).getIcmpv4Code().getIcmpv4Code().intValue());
363         MatchEntry entry21 = entries.get(21);
364         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry21.getOxmClass());
365         Assert.assertEquals("Wrong entry field", ArpOp.class, entry21.getOxmMatchField());
366         Assert.assertEquals("Wrong entry hasMask", false, entry21.isHasMask());
367         Assert.assertEquals("Wrong entry value", 16,
368                 ((ArpOpCase) entry21.getMatchEntryValue()).getArpOp().getOpCode().intValue());
369         MatchEntry entry22 = entries.get(22);
370         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry22.getOxmClass());
371         Assert.assertEquals("Wrong entry field", ArpSpa.class, entry22.getOxmMatchField());
372         Assert.assertEquals("Wrong entry hasMask", true, entry22.isHasMask());
373         Assert.assertEquals("Wrong entry value", new Ipv4Address("10.0.0.9"),
374                 ((ArpSpaCase) entry22.getMatchEntryValue()).getArpSpa().getIpv4Address());
375         Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 00 FF 00"),
376                 ((ArpSpaCase) entry22.getMatchEntryValue()).getArpSpa().getMask());
377         MatchEntry entry23 = entries.get(23);
378         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry23.getOxmClass());
379         Assert.assertEquals("Wrong entry field", ArpTpa.class, entry23.getOxmMatchField());
380         Assert.assertEquals("Wrong entry hasMask", true, entry23.isHasMask());
381         Assert.assertEquals("Wrong entry value", new Ipv4Address("10.0.0.10"),
382                 ((ArpTpaCase) entry23.getMatchEntryValue()).getArpTpa().getIpv4Address());
383         Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 00 00 FF"),
384                 ((ArpTpaCase) entry23.getMatchEntryValue()).getArpTpa().getMask());
385         MatchEntry entry24 = entries.get(24);
386         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry24.getOxmClass());
387         Assert.assertEquals("Wrong entry field", ArpSha.class, entry24.getOxmMatchField());
388         Assert.assertEquals("Wrong entry hasMask", true, entry24.isHasMask());
389         Assert.assertEquals("Wrong entry value", new MacAddress("00:00:00:00:00:01"),
390                 ((ArpShaCase) entry24.getMatchEntryValue()).getArpSha().getMacAddress());
391         Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 00 00 00 00 03"),
392                 ((ArpShaCase) entry24.getMatchEntryValue()).getArpSha().getMask());
393         MatchEntry entry25 = entries.get(25);
394         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry25.getOxmClass());
395         Assert.assertEquals("Wrong entry field", ArpTha.class, entry25.getOxmMatchField());
396         Assert.assertEquals("Wrong entry hasMask", true, entry25.isHasMask());
397         Assert.assertEquals("Wrong entry value", new MacAddress("00:00:00:00:00:02"),
398                 ((ArpThaCase) entry25.getMatchEntryValue()).getArpTha().getMacAddress());
399         Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 00 00 00 00 04"),
400                 ((ArpThaCase) entry25.getMatchEntryValue()).getArpTha().getMask());
401         MatchEntry entry26 = entries.get(26);
402         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry26.getOxmClass());
403         Assert.assertEquals("Wrong entry field", Ipv6Src.class, entry26.getOxmMatchField());
404         Assert.assertEquals("Wrong entry hasMask", true, entry26.isHasMask());
405         Assert.assertEquals("Wrong entry value", new Ipv6Address("::15"),
406                 ((Ipv6SrcCase) entry26.getMatchEntryValue()).getIpv6Src().getIpv6Address());
407         Assert.assertArrayEquals("Wrong entry mask",
408                 ByteBufUtils.hexStringToBytes("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 16"),
409                 ((Ipv6SrcCase) entry26.getMatchEntryValue()).getIpv6Src().getMask());
410         MatchEntry entry27 = entries.get(27);
411         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry27.getOxmClass());
412         Assert.assertEquals("Wrong entry field", Ipv6Dst.class, entry27.getOxmMatchField());
413         Assert.assertEquals("Wrong entry hasMask", true, entry27.isHasMask());
414         Assert.assertEquals("Wrong entry value", new Ipv6Address("::17"),
415                 ((Ipv6DstCase) entry27.getMatchEntryValue()).getIpv6Dst().getIpv6Address());
416         Assert.assertArrayEquals("Wrong entry mask",
417                 ByteBufUtils.hexStringToBytes("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 18"),
418                 ((Ipv6DstCase) entry27.getMatchEntryValue()).getIpv6Dst().getMask());
419         MatchEntry entry28 = entries.get(28);
420         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry28.getOxmClass());
421         Assert.assertEquals("Wrong entry field", Ipv6Flabel.class, entry28.getOxmMatchField());
422         Assert.assertEquals("Wrong entry hasMask", false, entry28.isHasMask());
423         Assert.assertEquals("Wrong entry value", 2,
424                 ((Ipv6FlabelCase) entry28.getMatchEntryValue()).getIpv6Flabel().getIpv6Flabel()
425                 .getValue().intValue());
426         MatchEntry entry29 = entries.get(29);
427         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry29.getOxmClass());
428         Assert.assertEquals("Wrong entry field", Icmpv6Type.class, entry29.getOxmMatchField());
429         Assert.assertEquals("Wrong entry hasMask", false, entry29.isHasMask());
430         Assert.assertEquals("Wrong entry value", 21,
431                 ((Icmpv6TypeCase) entry29.getMatchEntryValue()).getIcmpv6Type().getIcmpv6Type().intValue());
432         MatchEntry entry30 = entries.get(30);
433         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry30.getOxmClass());
434         Assert.assertEquals("Wrong entry field", Icmpv6Code.class, entry30.getOxmMatchField());
435         Assert.assertEquals("Wrong entry hasMask", false, entry30.isHasMask());
436         Assert.assertEquals("Wrong entry value", 23,
437                 ((Icmpv6CodeCase) entry30.getMatchEntryValue()).getIcmpv6Code().getIcmpv6Code().intValue());
438         MatchEntry entry31 = entries.get(31);
439         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry31.getOxmClass());
440         Assert.assertEquals("Wrong entry field", Ipv6NdTarget.class, entry31.getOxmMatchField());
441         Assert.assertEquals("Wrong entry hasMask", false, entry31.isHasMask());
442         Assert.assertEquals("Wrong entry value", new Ipv6Address("::20"),
443                 ((Ipv6NdTargetCase) entry31.getMatchEntryValue()).getIpv6NdTarget().getIpv6Address());
444         MatchEntry entry32 = entries.get(32);
445         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry32.getOxmClass());
446         Assert.assertEquals("Wrong entry field", Ipv6NdSll.class, entry32.getOxmMatchField());
447         Assert.assertEquals("Wrong entry hasMask", false, entry32.isHasMask());
448         Assert.assertEquals("Wrong entry value", new MacAddress("00:05:00:00:00:01"),
449                 ((Ipv6NdSllCase) entry32.getMatchEntryValue()).getIpv6NdSll().getMacAddress());
450         MatchEntry entry33 = entries.get(33);
451         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry33.getOxmClass());
452         Assert.assertEquals("Wrong entry field", Ipv6NdTll.class, entry33.getOxmMatchField());
453         Assert.assertEquals("Wrong entry hasMask", false, entry33.isHasMask());
454         Assert.assertEquals("Wrong entry value", new MacAddress("00:05:00:00:00:02"),
455                 ((Ipv6NdTllCase) entry33.getMatchEntryValue()).getIpv6NdTll().getMacAddress());
456         MatchEntry entry34 = entries.get(34);
457         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry34.getOxmClass());
458         Assert.assertEquals("Wrong entry field", MplsLabel.class, entry34.getOxmMatchField());
459         Assert.assertEquals("Wrong entry hasMask", false, entry34.isHasMask());
460         Assert.assertEquals("Wrong entry value", 515,
461                 ((MplsLabelCase) entry34.getMatchEntryValue()).getMplsLabel().getMplsLabel().intValue());
462         MatchEntry entry35 = entries.get(35);
463         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry35.getOxmClass());
464         Assert.assertEquals("Wrong entry field", MplsTc.class, entry35.getOxmMatchField());
465         Assert.assertEquals("Wrong entry hasMask", false, entry35.isHasMask());
466         Assert.assertEquals("Wrong entry value", 3,
467                 ((MplsTcCase) entry35.getMatchEntryValue()).getMplsTc().getTc().intValue());
468         MatchEntry entry36 = entries.get(36);
469         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry36.getOxmClass());
470         Assert.assertEquals("Wrong entry field", MplsBos.class, entry36.getOxmMatchField());
471         Assert.assertEquals("Wrong entry hasMask", false, entry36.isHasMask());
472         Assert.assertEquals("Wrong entry value", true,
473                 ((MplsBosCase) entry36.getMatchEntryValue()).getMplsBos().isBos());
474         MatchEntry entry37 = entries.get(37);
475         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry37.getOxmClass());
476         Assert.assertEquals("Wrong entry field", PbbIsid.class, entry37.getOxmMatchField());
477         Assert.assertEquals("Wrong entry hasMask", true, entry37.isHasMask());
478         Assert.assertEquals("Wrong entry value", 2,
479                 ((PbbIsidCase) entry37.getMatchEntryValue()).getPbbIsid().getIsid().intValue());
480         Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 00 01"),
481                 ((PbbIsidCase) entry37.getMatchEntryValue()).getPbbIsid().getMask());
482         MatchEntry entry38 = entries.get(38);
483         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry38.getOxmClass());
484         Assert.assertEquals("Wrong entry field", TunnelId.class, entry38.getOxmMatchField());
485         Assert.assertEquals("Wrong entry hasMask", true, entry38.isHasMask());
486         Assert.assertArrayEquals("Wrong entry value", ByteBufUtils.hexStringToBytes("00 00 00 00 00 00 00 07"),
487                 ((TunnelIdCase) entry38.getMatchEntryValue()).getTunnelId().getTunnelId());
488         Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 00 00 00 00 00 00 FF"),
489                 ((TunnelIdCase) entry38.getMatchEntryValue()).getTunnelId().getMask());
490         MatchEntry entry39 = entries.get(39);
491         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry39.getOxmClass());
492         Assert.assertEquals("Wrong entry field", Ipv6Exthdr.class, entry39.getOxmMatchField());
493         Assert.assertEquals("Wrong entry hasMask", true, entry39.isHasMask());
494         Assert.assertEquals("Wrong entry value",
495                 new Ipv6ExthdrFlags(false, false, false, false, false, false, false, false, false),
496                 ((Ipv6ExthdrCase) entry39.getMatchEntryValue()).getIpv6Exthdr().getPseudoField());
497         Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("03 04"),
498                 ((Ipv6ExthdrCase) entry39.getMatchEntryValue()).getIpv6Exthdr().getMask());
499         Assert.assertTrue("Unread data", buffer.readableBytes() == 0);
500         MatchEntry entry40 = entries.get(40);
501         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry40.getOxmClass());
502         Assert.assertEquals("Wrong entry field", PacketType.class, entry40.getOxmMatchField());
503         Assert.assertEquals("Wrong entry hasMask", false, entry40.isHasMask());
504         Assert.assertEquals("Wrong entry value", 0x1894f,
505                 ((PacketTypeCase) entry40.getMatchEntryValue()).getPacketType().getPacketType().longValue());
506     }
507
508     /**
509      * Testing header deserialization.
510      */
511     @Test
512     public void testHeaders() {
513         ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("80 00 18 04 00 01 02 03");
514
515         MatchEntryDeserializerKey key = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID,
516                 0x8000, 12);
517         key.setExperimenterId(null);
518         HeaderDeserializer<MatchEntry> entryDeserializer = registry.getDeserializer(key);
519         MatchEntry entry = entryDeserializer.deserializeHeader(buffer);
520         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry.getOxmClass());
521         Assert.assertEquals("Wrong entry field", Ipv4Dst.class, entry.getOxmMatchField());
522         Assert.assertEquals("Wrong entry hasMask", false, entry.isHasMask());
523         Assert.assertNull("Wrong Ipv4 address", entry.getMatchEntryValue());
524     }
525
526     /**
527      * Testing standard match type.
528      */
529     @Test
530     public void testStandardMatch() {
531         ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("00 00 00 10 80 00 04 08 00 00 00 00 00 00 00 01");
532
533         Match match = matchDeserializer.deserialize(buffer);
534
535         Assert.assertEquals("Wrong match type", StandardMatchType.class, match.getType());
536         Assert.assertEquals("Wrong match entries size", 1, match.getMatchEntry().size());
537     }
538 }