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
9 package org.opendaylight.openflowjava.protocol.impl.util;
11 import io.netty.buffer.ByteBuf;
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.OFDeserializer;
17 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
18 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
19 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10;
26 * Unit tests for OF10MatchDeserializer.
28 * @author michal.polkorab
30 public class OF10MatchDeserializerTest {
32 private OFDeserializer<MatchV10> matchDeserializer;
35 * Initializes deserializer registry and lookups correct deserializer.
38 public void startUp() {
39 DeserializerRegistry registry = new DeserializerRegistryImpl();
41 matchDeserializer = registry.getDeserializer(
42 new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class));
46 * Testing correct deserialization of ofp_match.
50 ByteBuf message = BufferHelper.buildBuffer("00 24 08 91 00 20 AA BB CC DD EE FF "
51 + "AA BB CC DD EE FF 00 05 10 00 00 08 07 06 00 00 10 11 12 13 01 02 03 04 "
53 message.skipBytes(4); // skip XID
54 MatchV10 match = matchDeserializer.deserialize(message);
55 Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(false, false, true, false,
56 false, true, false, true, true, false), match.getWildcards());
57 Assert.assertEquals("Wrong srcMask", 24, match.getNwSrcMask().shortValue());
58 Assert.assertEquals("Wrong dstMask", 16, match.getNwDstMask().shortValue());
59 Assert.assertEquals("Wrong in-port", 32, match.getInPort().intValue());
60 Assert.assertEquals("Wrong dl-src", new MacAddress("aa:bb:cc:dd:ee:ff"), match.getDlSrc());
61 Assert.assertEquals("Wrong dl-dst", new MacAddress("aa:bb:cc:dd:ee:ff"), match.getDlDst());
62 Assert.assertEquals("Wrong dl-vlan", 5, match.getDlVlan().intValue());
63 Assert.assertEquals("Wrong dl-vlan-pcp", 16, match.getDlVlanPcp().shortValue());
64 Assert.assertEquals("Wrong dl-type", 8, match.getDlType().intValue());
65 Assert.assertEquals("Wrong nw-tos", 7, match.getNwTos().shortValue());
66 Assert.assertEquals("Wrong nw-proto", 6, match.getNwProto().shortValue());
67 Assert.assertEquals("Wrong nw-src", new Ipv4Address("16.17.18.19"), match.getNwSrc());
68 Assert.assertEquals("Wrong nw-dst", new Ipv4Address("1.2.3.4"), match.getNwDst());
69 Assert.assertEquals("Wrong tp-src", 20560, match.getTpSrc().shortValue());
70 Assert.assertEquals("Wrong tp-dst", 8224, match.getTpDst().shortValue());
74 * Testing correct deserialization of ofp_match.
78 ByteBuf message = BufferHelper.buildBuffer("00 3F FF FF 00 20 AA BB CC DD EE FF "
79 + "AA BB CC DD EE FF 00 05 10 00 00 08 07 06 00 00 10 11 12 13 01 02 03 04 "
81 message.skipBytes(4); // skip XID
82 MatchV10 match = matchDeserializer.deserialize(message);
83 Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(true, true, true, true,
84 true, true, true, true, true, true), match.getWildcards());
85 Assert.assertEquals("Wrong srcMask", 0, match.getNwSrcMask().shortValue());
86 Assert.assertEquals("Wrong dstMask", 0, match.getNwDstMask().shortValue());
87 Assert.assertEquals("Wrong in-port", 32, match.getInPort().intValue());
88 Assert.assertEquals("Wrong dl-src", new MacAddress("aa:bb:cc:dd:ee:ff"), match.getDlSrc());
89 Assert.assertEquals("Wrong dl-dst", new MacAddress("aa:bb:cc:dd:ee:ff"), match.getDlDst());
90 Assert.assertEquals("Wrong dl-vlan", 5, match.getDlVlan().intValue());
91 Assert.assertEquals("Wrong dl-vlan-pcp", 16, match.getDlVlanPcp().shortValue());
92 Assert.assertEquals("Wrong dl-type", 8, match.getDlType().intValue());
93 Assert.assertEquals("Wrong nw-tos", 7, match.getNwTos().shortValue());
94 Assert.assertEquals("Wrong nw-proto", 6, match.getNwProto().shortValue());
95 Assert.assertEquals("Wrong nw-src", new Ipv4Address("16.17.18.19"), match.getNwSrc());
96 Assert.assertEquals("Wrong nw-dst", new Ipv4Address("1.2.3.4"), match.getNwDst());
97 Assert.assertEquals("Wrong tp-src", 20560, match.getTpSrc().shortValue());
98 Assert.assertEquals("Wrong tp-dst", 8224, match.getTpDst().shortValue());