Remove trailing whitespace
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / util / OF10MatchDeserializerTest.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
9 package org.opendaylight.openflowjava.protocol.impl.util;
10
11 import io.netty.buffer.ByteBuf;
12
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.api.util.EncodeConstants;
20 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;
25
26 /**
27  * @author michal.polkorab
28  *
29  */
30 public class OF10MatchDeserializerTest {
31
32     private OFDeserializer<MatchV10> matchDeserializer;
33
34     /**
35      * Initializes deserializer registry and lookups correct deserializer
36      */
37     @Before
38     public void startUp() {
39         DeserializerRegistry registry = new DeserializerRegistryImpl();
40         registry.init();
41         matchDeserializer = registry.getDeserializer(
42                 new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class));
43     }
44
45     /**
46      * Testing correct deserialization of ofp_match
47      */
48     @Test
49     public void test() {
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 "
52                 + "50 50 20 20");
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());
71     }
72
73     /**
74      * Testing correct deserialization of ofp_match
75      */
76     @Test
77     public void test2() {
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 "
80                 + "50 50 20 20");
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());
99     }
100
101 }