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;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey;
18 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
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.rev100924.Ipv4Address;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.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.rev130731.match.v10.grouping.MatchV10;
26 * @author michal.polkorab
29 public class OF10MatchDeserializerTest {
31 private OFDeserializer<MatchV10> matchDeserializer;
34 * Initializes deserializer registry and lookups correct deserializer
37 public void startUp() {
38 DeserializerRegistry registry = new DeserializerRegistryImpl();
40 matchDeserializer = registry.getDeserializer(
41 new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class));
45 * Testing correct deserialization of ofp_match
49 ByteBuf message = BufferHelper.buildBuffer("00 24 08 91 00 20 AA BB CC DD EE FF "
50 + "AA BB CC DD EE FF 00 05 10 00 00 08 07 06 00 00 10 11 12 13 01 02 03 04 "
52 message.skipBytes(4); // skip XID
53 MatchV10 match = matchDeserializer.deserialize(message);
54 Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(false, false, true, false,
55 false, true, false, true, true, false), match.getWildcards());
56 Assert.assertEquals("Wrong srcMask", 24, match.getNwSrcMask().shortValue());
57 Assert.assertEquals("Wrong dstMask", 16, match.getNwDstMask().shortValue());
58 Assert.assertEquals("Wrong in-port", 32, match.getInPort().intValue());
59 Assert.assertEquals("Wrong dl-src", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlSrc());
60 Assert.assertEquals("Wrong dl-dst", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlDst());
61 Assert.assertEquals("Wrong dl-vlan", 5, match.getDlVlan().intValue());
62 Assert.assertEquals("Wrong dl-vlan-pcp", 16, match.getDlVlanPcp().shortValue());
63 Assert.assertEquals("Wrong dl-type", 8, match.getDlType().intValue());
64 Assert.assertEquals("Wrong nw-tos", 7, match.getNwTos().shortValue());
65 Assert.assertEquals("Wrong nw-proto", 6, match.getNwProto().shortValue());
66 Assert.assertEquals("Wrong nw-src", new Ipv4Address("16.17.18.19"), match.getNwSrc());
67 Assert.assertEquals("Wrong nw-dst", new Ipv4Address("1.2.3.4"), match.getNwDst());
68 Assert.assertEquals("Wrong tp-src", 20560, match.getTpSrc().shortValue());
69 Assert.assertEquals("Wrong tp-dst", 8224, match.getTpDst().shortValue());
73 * Testing correct deserialization of ofp_match
77 ByteBuf message = BufferHelper.buildBuffer("00 3F FF FF 00 20 AA BB CC DD EE FF "
78 + "AA BB CC DD EE FF 00 05 10 00 00 08 07 06 00 00 10 11 12 13 01 02 03 04 "
80 message.skipBytes(4); // skip XID
81 MatchV10 match = matchDeserializer.deserialize(message);
82 Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(true, true, true, true,
83 true, true, true, true, true, true), match.getWildcards());
84 Assert.assertEquals("Wrong srcMask", 0, match.getNwSrcMask().shortValue());
85 Assert.assertEquals("Wrong dstMask", 0, match.getNwDstMask().shortValue());
86 Assert.assertEquals("Wrong in-port", 32, match.getInPort().intValue());
87 Assert.assertEquals("Wrong dl-src", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlSrc());
88 Assert.assertEquals("Wrong dl-dst", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlDst());
89 Assert.assertEquals("Wrong dl-vlan", 5, match.getDlVlan().intValue());
90 Assert.assertEquals("Wrong dl-vlan-pcp", 16, match.getDlVlanPcp().shortValue());
91 Assert.assertEquals("Wrong dl-type", 8, match.getDlType().intValue());
92 Assert.assertEquals("Wrong nw-tos", 7, match.getNwTos().shortValue());
93 Assert.assertEquals("Wrong nw-proto", 6, match.getNwProto().shortValue());
94 Assert.assertEquals("Wrong nw-src", new Ipv4Address("16.17.18.19"), match.getNwSrc());
95 Assert.assertEquals("Wrong nw-dst", new Ipv4Address("1.2.3.4"), match.getNwDst());
96 Assert.assertEquals("Wrong tp-src", 20560, match.getTpSrc().shortValue());
97 Assert.assertEquals("Wrong tp-dst", 8224, match.getTpDst().shortValue());