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