2 * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.openflowjava.protocol.impl.util;
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;
116 * Unit tests for MatchDeserializer.
118 * @author michal.polkorab
120 public class MatchDeserializerTest {
122 private OFDeserializer<Match> matchDeserializer;
123 private DeserializerRegistry registry;
126 * Initializes deserializer registry and lookups correct deserializer.
129 public void startUp() {
130 registry = new DeserializerRegistryImpl();
132 matchDeserializer = registry.getDeserializer(
133 new MessageCodeKey(EncodeConstants.OF_VERSION_1_3, EncodeConstants.EMPTY_VALUE, Match.class));
137 * Testing Ipv4 address deserialization.
140 public void testIpv4Address() {
141 ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("80 00 18 04 00 01 02 03");
143 MatchEntryDeserializerKey key = new MatchEntryDeserializerKey(EncodeConstants.OF_VERSION_1_3, 0x8000, 12);
144 key.setExperimenterId(null);
145 OFDeserializer<MatchEntry> entryDeserializer = registry.getDeserializer(key);
146 MatchEntry entry = entryDeserializer.deserialize(buffer);
147 Assert.assertEquals("Wrong Ipv4 address format", new Ipv4Address("0.1.2.3"),
148 ((Ipv4DstCase) entry.getMatchEntryValue()).getIpv4Dst().getIpv4Address());
152 * Testing Ipv6 address deserialization.
155 public void testIpv6Address() {
156 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 MatchEntryDeserializerKey key = new MatchEntryDeserializerKey(EncodeConstants.OF_VERSION_1_3, 0x8000, 26);
159 key.setExperimenterId(null);
160 OFDeserializer<MatchEntry> entryDeserializer = registry.getDeserializer(key);
161 MatchEntry entry = entryDeserializer.deserialize(buffer);
162 Assert.assertEquals("Wrong Ipv6 address format", new Ipv6Address("0:1:2:3:4:5:6:f07"),
163 ((Ipv6SrcCase) entry.getMatchEntryValue()).getIpv6Src().getIpv6Address());
167 * Testing match deserialization.
170 public void testMatch() {
171 ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("00 01 01 B0 "
172 + "80 00 00 04 00 00 00 01 "
173 + "80 00 02 04 00 00 00 02 "
174 + "80 00 05 10 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 04 "
175 + "80 00 07 0C 00 00 00 00 00 05 00 00 00 00 00 06 "
176 + "80 00 09 0C 00 00 00 00 00 07 00 00 00 00 00 08 "
177 + "80 00 0A 02 00 09 "
178 + "80 00 0D 04 00 0A 00 0B "
183 + "80 00 17 08 0A 00 00 01 00 00 FF 00 "
184 + "80 00 19 08 0A 00 00 02 00 00 00 FF "
185 + "80 00 1A 02 00 03 "
186 + "80 00 1C 02 00 04 "
187 + "80 00 1E 02 00 05 "
188 + "80 00 20 02 00 06 "
189 + "80 00 22 02 00 07 "
190 + "80 00 24 02 00 08 "
193 + "80 00 2A 02 00 10 "
194 + "80 00 2D 08 0A 00 00 09 00 00 FF 00 "
195 + "80 00 2F 08 0A 00 00 0A 00 00 00 FF "
196 + "80 00 31 0C 00 00 00 00 00 01 00 00 00 00 00 03 "
197 + "80 00 33 0C 00 00 00 00 00 02 00 00 00 00 00 04 "
198 + "80 00 35 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 "
199 + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 16 "
200 + "80 00 37 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 17 "
201 + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 18 "
202 + "80 00 38 04 00 00 00 02 "
205 + "80 00 3E 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 " //ipv6ndtarget
206 + "80 00 40 06 00 05 00 00 00 01 "
207 + "80 00 42 06 00 05 00 00 00 02 "
208 + "80 00 44 04 00 00 02 03 "
211 + "80 00 4B 06 00 00 02 00 00 01 "
212 + "80 00 4D 10 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 FF "
213 + "80 00 4F 04 00 00 03 04 "
214 + "80 00 58 04 00 01 89 4f");
216 Match match = matchDeserializer.deserialize(buffer);
217 Assert.assertEquals("Wrong match type", OxmMatchType.class, match.getType());
218 Assert.assertEquals("Wrong match entries size", 41, match.getMatchEntry().size());
219 List<MatchEntry> entries = match.getMatchEntry();
220 MatchEntry entry0 = entries.get(0);
221 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry0.getOxmClass());
222 Assert.assertEquals("Wrong entry field", InPort.class, entry0.getOxmMatchField());
223 Assert.assertEquals("Wrong entry hasMask", false, entry0.getHasMask());
224 Assert.assertEquals("Wrong entry value", 1,
225 ((InPortCase) entry0.getMatchEntryValue()).getInPort().getPortNumber().getValue().intValue());
226 MatchEntry entry1 = entries.get(1);
227 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry1.getOxmClass());
228 Assert.assertEquals("Wrong entry field", InPhyPort.class, entry1.getOxmMatchField());
229 Assert.assertEquals("Wrong entry hasMask", false, entry1.getHasMask());
230 Assert.assertEquals("Wrong entry value", 2,
231 ((InPhyPortCase) entry1.getMatchEntryValue()).getInPhyPort().getPortNumber().getValue().intValue());
232 MatchEntry entry2 = entries.get(2);
233 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry2.getOxmClass());
234 Assert.assertEquals("Wrong entry field", Metadata.class, entry2.getOxmMatchField());
235 Assert.assertEquals("Wrong entry hasMask", true, entry2.getHasMask());
236 Assert.assertArrayEquals("Wrong entry value", ByteBufUtils.hexStringToBytes("00 00 00 00 00 00 00 03"),
237 ((MetadataCase) entry2.getMatchEntryValue()).getMetadata().getMetadata());
238 Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 00 00 00 00 00 00 04"),
239 ((MetadataCase) entry2.getMatchEntryValue()).getMetadata().getMask());
240 MatchEntry entry3 = entries.get(3);
241 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry3.getOxmClass());
242 Assert.assertEquals("Wrong entry field", EthDst.class, entry3.getOxmMatchField());
243 Assert.assertEquals("Wrong entry hasMask", true, entry3.getHasMask());
244 Assert.assertEquals("Wrong entry value", new MacAddress("00:00:00:00:00:05"),
245 ((EthDstCase) entry3.getMatchEntryValue()).getEthDst().getMacAddress());
246 Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 00 00 00 00 06"),
247 ((EthDstCase) entry3.getMatchEntryValue()).getEthDst().getMask());
248 MatchEntry entry4 = entries.get(4);
249 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry4.getOxmClass());
250 Assert.assertEquals("Wrong entry field", EthSrc.class, entry4.getOxmMatchField());
251 Assert.assertEquals("Wrong entry hasMask", true, entry4.getHasMask());
252 Assert.assertEquals("Wrong entry value", new MacAddress("00:00:00:00:00:07"),
253 ((EthSrcCase) entry4.getMatchEntryValue()).getEthSrc().getMacAddress());
254 Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 00 00 00 00 08"),
255 ((EthSrcCase) entry4.getMatchEntryValue()).getEthSrc().getMask());
256 MatchEntry entry5 = entries.get(5);
257 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry5.getOxmClass());
258 Assert.assertEquals("Wrong entry field", EthType.class, entry5.getOxmMatchField());
259 Assert.assertEquals("Wrong entry hasMask", false, entry5.getHasMask());
260 Assert.assertEquals("Wrong entry value", 9,
261 ((EthTypeCase) entry5.getMatchEntryValue()).getEthType().getEthType().getValue().intValue());
262 MatchEntry entry6 = entries.get(6);
263 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry6.getOxmClass());
264 Assert.assertEquals("Wrong entry field", VlanVid.class, entry6.getOxmMatchField());
265 Assert.assertEquals("Wrong entry hasMask", true, entry6.getHasMask());
266 Assert.assertEquals("Wrong entry value", 10,
267 ((VlanVidCase) entry6.getMatchEntryValue()).getVlanVid().getVlanVid().intValue());
268 Assert.assertEquals("Wrong entry value", false,
269 ((VlanVidCase) entry6.getMatchEntryValue()).getVlanVid().getCfiBit());
270 Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 0B"),
271 ((VlanVidCase) entry6.getMatchEntryValue()).getVlanVid().getMask());
272 MatchEntry entry7 = entries.get(7);
273 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry7.getOxmClass());
274 Assert.assertEquals("Wrong entry field", VlanPcp.class, entry7.getOxmMatchField());
275 Assert.assertEquals("Wrong entry hasMask", false, entry7.getHasMask());
276 Assert.assertEquals("Wrong entry value", 12,
277 ((VlanPcpCase) entry7.getMatchEntryValue()).getVlanPcp().getVlanPcp().intValue());
278 MatchEntry entry8 = entries.get(8);
279 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry8.getOxmClass());
280 Assert.assertEquals("Wrong entry field", IpDscp.class, entry8.getOxmMatchField());
281 Assert.assertEquals("Wrong entry hasMask", false, entry8.getHasMask());
282 Assert.assertEquals("Wrong entry value", 13,
283 ((IpDscpCase) entry8.getMatchEntryValue()).getIpDscp().getDscp().getValue().intValue());
284 MatchEntry entry9 = entries.get(9);
285 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry9.getOxmClass());
286 Assert.assertEquals("Wrong entry field", IpEcn.class, entry9.getOxmMatchField());
287 Assert.assertEquals("Wrong entry hasMask", false, entry9.getHasMask());
288 Assert.assertEquals("Wrong entry value", 14,
289 ((IpEcnCase) entry9.getMatchEntryValue()).getIpEcn().getEcn().intValue());
290 MatchEntry entry10 = entries.get(10);
291 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry10.getOxmClass());
292 Assert.assertEquals("Wrong entry field", IpProto.class, entry10.getOxmMatchField());
293 Assert.assertEquals("Wrong entry hasMask", false, entry10.getHasMask());
294 Assert.assertEquals("Wrong entry value", 15,
295 ((IpProtoCase) entry10.getMatchEntryValue()).getIpProto().getProtocolNumber().intValue());
296 MatchEntry entry11 = entries.get(11);
297 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry11.getOxmClass());
298 Assert.assertEquals("Wrong entry field", Ipv4Src.class, entry11.getOxmMatchField());
299 Assert.assertEquals("Wrong entry hasMask", true, entry11.getHasMask());
300 Assert.assertEquals("Wrong entry value", new Ipv4Address("10.0.0.1"),
301 ((Ipv4SrcCase) entry11.getMatchEntryValue()).getIpv4Src().getIpv4Address());
302 Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 00 FF 00"),
303 ((Ipv4SrcCase) entry11.getMatchEntryValue()).getIpv4Src().getMask());
304 MatchEntry entry12 = entries.get(12);
305 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry12.getOxmClass());
306 Assert.assertEquals("Wrong entry field", Ipv4Dst.class, entry12.getOxmMatchField());
307 Assert.assertEquals("Wrong entry hasMask", true, entry12.getHasMask());
308 Assert.assertEquals("Wrong entry value", new Ipv4Address("10.0.0.2"),
309 ((Ipv4DstCase) entry12.getMatchEntryValue()).getIpv4Dst().getIpv4Address());
310 Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 00 00 FF"),
311 ((Ipv4DstCase) entry12.getMatchEntryValue()).getIpv4Dst().getMask());
312 MatchEntry entry13 = entries.get(13);
313 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry13.getOxmClass());
314 Assert.assertEquals("Wrong entry field", TcpSrc.class, entry13.getOxmMatchField());
315 Assert.assertEquals("Wrong entry hasMask", false, entry13.getHasMask());
316 Assert.assertEquals("Wrong entry value", 3,
317 ((TcpSrcCase) entry13.getMatchEntryValue()).getTcpSrc().getPort().getValue().intValue());
318 MatchEntry entry14 = entries.get(14);
319 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry14.getOxmClass());
320 Assert.assertEquals("Wrong entry field", TcpDst.class, entry14.getOxmMatchField());
321 Assert.assertEquals("Wrong entry hasMask", false, entry14.getHasMask());
322 Assert.assertEquals("Wrong entry value", 4,
323 ((TcpDstCase) entry14.getMatchEntryValue()).getTcpDst().getPort().getValue().intValue());
324 MatchEntry entry15 = entries.get(15);
325 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry15.getOxmClass());
326 Assert.assertEquals("Wrong entry field", UdpSrc.class, entry15.getOxmMatchField());
327 Assert.assertEquals("Wrong entry hasMask", false, entry15.getHasMask());
328 Assert.assertEquals("Wrong entry value", 5,
329 ((UdpSrcCase) entry15.getMatchEntryValue()).getUdpSrc().getPort().getValue().intValue());
330 MatchEntry entry16 = entries.get(16);
331 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry16.getOxmClass());
332 Assert.assertEquals("Wrong entry field", UdpDst.class, entry16.getOxmMatchField());
333 Assert.assertEquals("Wrong entry hasMask", false, entry16.getHasMask());
334 Assert.assertEquals("Wrong entry value", 6,
335 ((UdpDstCase) entry16.getMatchEntryValue()).getUdpDst().getPort().getValue().intValue());
336 MatchEntry entry17 = entries.get(17);
337 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry17.getOxmClass());
338 Assert.assertEquals("Wrong entry field", SctpSrc.class, entry17.getOxmMatchField());
339 Assert.assertEquals("Wrong entry hasMask", false, entry17.getHasMask());
340 Assert.assertEquals("Wrong entry value", 7,
341 ((SctpSrcCase) entry17.getMatchEntryValue()).getSctpSrc().getPort().getValue().intValue());
342 MatchEntry entry18 = entries.get(18);
343 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry18.getOxmClass());
344 Assert.assertEquals("Wrong entry field", SctpDst.class, entry18.getOxmMatchField());
345 Assert.assertEquals("Wrong entry hasMask", false, entry18.getHasMask());
346 Assert.assertEquals("Wrong entry value", 8,
347 ((SctpDstCase) entry18.getMatchEntryValue()).getSctpDst().getPort().getValue().intValue());
348 MatchEntry entry19 = entries.get(19);
349 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry19.getOxmClass());
350 Assert.assertEquals("Wrong entry field", Icmpv4Type.class, entry19.getOxmMatchField());
351 Assert.assertEquals("Wrong entry hasMask", false, entry19.getHasMask());
352 Assert.assertEquals("Wrong entry value", 5,
353 ((Icmpv4TypeCase) entry19.getMatchEntryValue()).getIcmpv4Type().getIcmpv4Type().intValue());
354 MatchEntry entry20 = entries.get(20);
355 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry20.getOxmClass());
356 Assert.assertEquals("Wrong entry field", Icmpv4Code.class, entry20.getOxmMatchField());
357 Assert.assertEquals("Wrong entry hasMask", false, entry20.getHasMask());
358 Assert.assertEquals("Wrong entry value", 7,
359 ((Icmpv4CodeCase) entry20.getMatchEntryValue()).getIcmpv4Code().getIcmpv4Code().intValue());
360 MatchEntry entry21 = entries.get(21);
361 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry21.getOxmClass());
362 Assert.assertEquals("Wrong entry field", ArpOp.class, entry21.getOxmMatchField());
363 Assert.assertEquals("Wrong entry hasMask", false, entry21.getHasMask());
364 Assert.assertEquals("Wrong entry value", 16,
365 ((ArpOpCase) entry21.getMatchEntryValue()).getArpOp().getOpCode().intValue());
366 MatchEntry entry22 = entries.get(22);
367 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry22.getOxmClass());
368 Assert.assertEquals("Wrong entry field", ArpSpa.class, entry22.getOxmMatchField());
369 Assert.assertEquals("Wrong entry hasMask", true, entry22.getHasMask());
370 Assert.assertEquals("Wrong entry value", new Ipv4Address("10.0.0.9"),
371 ((ArpSpaCase) entry22.getMatchEntryValue()).getArpSpa().getIpv4Address());
372 Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 00 FF 00"),
373 ((ArpSpaCase) entry22.getMatchEntryValue()).getArpSpa().getMask());
374 MatchEntry entry23 = entries.get(23);
375 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry23.getOxmClass());
376 Assert.assertEquals("Wrong entry field", ArpTpa.class, entry23.getOxmMatchField());
377 Assert.assertEquals("Wrong entry hasMask", true, entry23.getHasMask());
378 Assert.assertEquals("Wrong entry value", new Ipv4Address("10.0.0.10"),
379 ((ArpTpaCase) entry23.getMatchEntryValue()).getArpTpa().getIpv4Address());
380 Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 00 00 FF"),
381 ((ArpTpaCase) entry23.getMatchEntryValue()).getArpTpa().getMask());
382 MatchEntry entry24 = entries.get(24);
383 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry24.getOxmClass());
384 Assert.assertEquals("Wrong entry field", ArpSha.class, entry24.getOxmMatchField());
385 Assert.assertEquals("Wrong entry hasMask", true, entry24.getHasMask());
386 Assert.assertEquals("Wrong entry value", new MacAddress("00:00:00:00:00:01"),
387 ((ArpShaCase) entry24.getMatchEntryValue()).getArpSha().getMacAddress());
388 Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 00 00 00 00 03"),
389 ((ArpShaCase) entry24.getMatchEntryValue()).getArpSha().getMask());
390 MatchEntry entry25 = entries.get(25);
391 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry25.getOxmClass());
392 Assert.assertEquals("Wrong entry field", ArpTha.class, entry25.getOxmMatchField());
393 Assert.assertEquals("Wrong entry hasMask", true, entry25.getHasMask());
394 Assert.assertEquals("Wrong entry value", new MacAddress("00:00:00:00:00:02"),
395 ((ArpThaCase) entry25.getMatchEntryValue()).getArpTha().getMacAddress());
396 Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 00 00 00 00 04"),
397 ((ArpThaCase) entry25.getMatchEntryValue()).getArpTha().getMask());
398 MatchEntry entry26 = entries.get(26);
399 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry26.getOxmClass());
400 Assert.assertEquals("Wrong entry field", Ipv6Src.class, entry26.getOxmMatchField());
401 Assert.assertEquals("Wrong entry hasMask", true, entry26.getHasMask());
402 Assert.assertEquals("Wrong entry value", new Ipv6Address("::15"),
403 ((Ipv6SrcCase) entry26.getMatchEntryValue()).getIpv6Src().getIpv6Address());
404 Assert.assertArrayEquals("Wrong entry mask",
405 ByteBufUtils.hexStringToBytes("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 16"),
406 ((Ipv6SrcCase) entry26.getMatchEntryValue()).getIpv6Src().getMask());
407 MatchEntry entry27 = entries.get(27);
408 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry27.getOxmClass());
409 Assert.assertEquals("Wrong entry field", Ipv6Dst.class, entry27.getOxmMatchField());
410 Assert.assertEquals("Wrong entry hasMask", true, entry27.getHasMask());
411 Assert.assertEquals("Wrong entry value", new Ipv6Address("::17"),
412 ((Ipv6DstCase) entry27.getMatchEntryValue()).getIpv6Dst().getIpv6Address());
413 Assert.assertArrayEquals("Wrong entry mask",
414 ByteBufUtils.hexStringToBytes("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 18"),
415 ((Ipv6DstCase) entry27.getMatchEntryValue()).getIpv6Dst().getMask());
416 MatchEntry entry28 = entries.get(28);
417 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry28.getOxmClass());
418 Assert.assertEquals("Wrong entry field", Ipv6Flabel.class, entry28.getOxmMatchField());
419 Assert.assertEquals("Wrong entry hasMask", false, entry28.getHasMask());
420 Assert.assertEquals("Wrong entry value", 2,
421 ((Ipv6FlabelCase) entry28.getMatchEntryValue()).getIpv6Flabel().getIpv6Flabel()
422 .getValue().intValue());
423 MatchEntry entry29 = entries.get(29);
424 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry29.getOxmClass());
425 Assert.assertEquals("Wrong entry field", Icmpv6Type.class, entry29.getOxmMatchField());
426 Assert.assertEquals("Wrong entry hasMask", false, entry29.getHasMask());
427 Assert.assertEquals("Wrong entry value", 21,
428 ((Icmpv6TypeCase) entry29.getMatchEntryValue()).getIcmpv6Type().getIcmpv6Type().intValue());
429 MatchEntry entry30 = entries.get(30);
430 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry30.getOxmClass());
431 Assert.assertEquals("Wrong entry field", Icmpv6Code.class, entry30.getOxmMatchField());
432 Assert.assertEquals("Wrong entry hasMask", false, entry30.getHasMask());
433 Assert.assertEquals("Wrong entry value", 23,
434 ((Icmpv6CodeCase) entry30.getMatchEntryValue()).getIcmpv6Code().getIcmpv6Code().intValue());
435 MatchEntry entry31 = entries.get(31);
436 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry31.getOxmClass());
437 Assert.assertEquals("Wrong entry field", Ipv6NdTarget.class, entry31.getOxmMatchField());
438 Assert.assertEquals("Wrong entry hasMask", false, entry31.getHasMask());
439 Assert.assertEquals("Wrong entry value", new Ipv6Address("::20"),
440 ((Ipv6NdTargetCase) entry31.getMatchEntryValue()).getIpv6NdTarget().getIpv6Address());
441 MatchEntry entry32 = entries.get(32);
442 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry32.getOxmClass());
443 Assert.assertEquals("Wrong entry field", Ipv6NdSll.class, entry32.getOxmMatchField());
444 Assert.assertEquals("Wrong entry hasMask", false, entry32.getHasMask());
445 Assert.assertEquals("Wrong entry value", new MacAddress("00:05:00:00:00:01"),
446 ((Ipv6NdSllCase) entry32.getMatchEntryValue()).getIpv6NdSll().getMacAddress());
447 MatchEntry entry33 = entries.get(33);
448 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry33.getOxmClass());
449 Assert.assertEquals("Wrong entry field", Ipv6NdTll.class, entry33.getOxmMatchField());
450 Assert.assertEquals("Wrong entry hasMask", false, entry33.getHasMask());
451 Assert.assertEquals("Wrong entry value", new MacAddress("00:05:00:00:00:02"),
452 ((Ipv6NdTllCase) entry33.getMatchEntryValue()).getIpv6NdTll().getMacAddress());
453 MatchEntry entry34 = entries.get(34);
454 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry34.getOxmClass());
455 Assert.assertEquals("Wrong entry field", MplsLabel.class, entry34.getOxmMatchField());
456 Assert.assertEquals("Wrong entry hasMask", false, entry34.getHasMask());
457 Assert.assertEquals("Wrong entry value", 515,
458 ((MplsLabelCase) entry34.getMatchEntryValue()).getMplsLabel().getMplsLabel().intValue());
459 MatchEntry entry35 = entries.get(35);
460 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry35.getOxmClass());
461 Assert.assertEquals("Wrong entry field", MplsTc.class, entry35.getOxmMatchField());
462 Assert.assertEquals("Wrong entry hasMask", false, entry35.getHasMask());
463 Assert.assertEquals("Wrong entry value", 3,
464 ((MplsTcCase) entry35.getMatchEntryValue()).getMplsTc().getTc().intValue());
465 MatchEntry entry36 = entries.get(36);
466 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry36.getOxmClass());
467 Assert.assertEquals("Wrong entry field", MplsBos.class, entry36.getOxmMatchField());
468 Assert.assertEquals("Wrong entry hasMask", false, entry36.getHasMask());
469 Assert.assertEquals("Wrong entry value", true,
470 ((MplsBosCase) entry36.getMatchEntryValue()).getMplsBos().getBos());
471 MatchEntry entry37 = entries.get(37);
472 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry37.getOxmClass());
473 Assert.assertEquals("Wrong entry field", PbbIsid.class, entry37.getOxmMatchField());
474 Assert.assertEquals("Wrong entry hasMask", true, entry37.getHasMask());
475 Assert.assertEquals("Wrong entry value", 2,
476 ((PbbIsidCase) entry37.getMatchEntryValue()).getPbbIsid().getIsid().intValue());
477 Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 00 01"),
478 ((PbbIsidCase) entry37.getMatchEntryValue()).getPbbIsid().getMask());
479 MatchEntry entry38 = entries.get(38);
480 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry38.getOxmClass());
481 Assert.assertEquals("Wrong entry field", TunnelId.class, entry38.getOxmMatchField());
482 Assert.assertEquals("Wrong entry hasMask", true, entry38.getHasMask());
483 Assert.assertArrayEquals("Wrong entry value", ByteBufUtils.hexStringToBytes("00 00 00 00 00 00 00 07"),
484 ((TunnelIdCase) entry38.getMatchEntryValue()).getTunnelId().getTunnelId());
485 Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("00 00 00 00 00 00 00 FF"),
486 ((TunnelIdCase) entry38.getMatchEntryValue()).getTunnelId().getMask());
487 MatchEntry entry39 = entries.get(39);
488 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry39.getOxmClass());
489 Assert.assertEquals("Wrong entry field", Ipv6Exthdr.class, entry39.getOxmMatchField());
490 Assert.assertEquals("Wrong entry hasMask", true, entry39.getHasMask());
491 Assert.assertEquals("Wrong entry value",
492 new Ipv6ExthdrFlags(false, false, false, false, false, false, false, false, false),
493 ((Ipv6ExthdrCase) entry39.getMatchEntryValue()).getIpv6Exthdr().getPseudoField());
494 Assert.assertArrayEquals("Wrong entry mask", ByteBufUtils.hexStringToBytes("03 04"),
495 ((Ipv6ExthdrCase) entry39.getMatchEntryValue()).getIpv6Exthdr().getMask());
496 Assert.assertTrue("Unread data", buffer.readableBytes() == 0);
497 MatchEntry entry40 = entries.get(40);
498 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry40.getOxmClass());
499 Assert.assertEquals("Wrong entry field", PacketType.class, entry40.getOxmMatchField());
500 Assert.assertEquals("Wrong entry hasMask", false, entry40.getHasMask());
501 Assert.assertEquals("Wrong entry value", 0x1894f,
502 ((PacketTypeCase) entry40.getMatchEntryValue()).getPacketType().getPacketType().longValue());
506 * Testing header deserialization.
509 public void testHeaders() {
510 ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("80 00 18 04 00 01 02 03");
512 MatchEntryDeserializerKey key = new MatchEntryDeserializerKey(EncodeConstants.OF_VERSION_1_3, 0x8000, 12);
513 key.setExperimenterId(null);
514 HeaderDeserializer<MatchEntry> entryDeserializer = registry.getDeserializer(key);
515 MatchEntry entry = entryDeserializer.deserializeHeader(buffer);
516 Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry.getOxmClass());
517 Assert.assertEquals("Wrong entry field", Ipv4Dst.class, entry.getOxmMatchField());
518 Assert.assertEquals("Wrong entry hasMask", false, entry.getHasMask());
519 Assert.assertNull("Wrong Ipv4 address", entry.getMatchEntryValue());
523 * Testing standard match type.
526 public void testStandardMatch() {
527 ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("00 00 00 10 80 00 04 08 00 00 00 00 00 00 00 01");
529 Match match = matchDeserializer.deserialize(buffer);
531 Assert.assertEquals("Wrong match type", StandardMatchType.class, match.getType());
532 Assert.assertEquals("Wrong match entries size", 1, match.getMatchEntry().size());