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