Merge "Removed enumeration ALL from FlowWildCardsV10"
[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.Test;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;
19
20 /**
21  * @author michal.polkorab
22  *
23  */
24 public class OF10MatchDeserializerTest {
25
26     /**
27      * Testing correct deserialization of ofp_match
28      */
29     @Test
30     public void test() {
31         ByteBuf message = BufferHelper.buildBuffer("00 24 08 91 00 20 AA BB CC DD EE FF "
32                 + "AA BB CC DD EE FF 00 05 10 00 00 08 07 06 00 00 10 11 12 13 01 02 03 04 "
33                 + "50 50 20 20");
34         message.skipBytes(4); // skip XID
35         MatchV10 match = OF10MatchDeserializer.createMatchV10(message);
36         Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(false, false, true, false,
37                 false, true, false, true, true, false), match.getWildcards());
38         Assert.assertEquals("Wrong srcMask", 24, match.getNwSrcMask().shortValue());
39         Assert.assertEquals("Wrong dstMask", 16, match.getNwDstMask().shortValue());
40         Assert.assertEquals("Wrong in-port", 32, match.getInPort().intValue());
41         Assert.assertEquals("Wrong dl-src", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlSrc());
42         Assert.assertEquals("Wrong dl-dst", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlDst());
43         Assert.assertEquals("Wrong dl-vlan", 5, match.getDlVlan().intValue());
44         Assert.assertEquals("Wrong dl-vlan-pcp", 16, match.getDlVlanPcp().shortValue());
45         Assert.assertEquals("Wrong dl-type", 8, match.getDlType().intValue());
46         Assert.assertEquals("Wrong nw-tos", 7, match.getNwTos().shortValue());
47         Assert.assertEquals("Wrong nw-proto", 6, match.getNwProto().shortValue());
48         Assert.assertEquals("Wrong nw-src", new Ipv4Address("16.17.18.19"), match.getNwSrc());
49         Assert.assertEquals("Wrong nw-dst", new Ipv4Address("1.2.3.4"), match.getNwDst());
50         Assert.assertEquals("Wrong tp-src", 20560, match.getTpSrc().shortValue());
51         Assert.assertEquals("Wrong tp-dst", 8224, match.getTpDst().shortValue());
52     }
53     
54     /**
55      * Testing correct deserialization of ofp_match
56      */
57     @Test
58     public void test2() {
59         ByteBuf message = BufferHelper.buildBuffer("00 3F FF FF 00 20 AA BB CC DD EE FF "
60                 + "AA BB CC DD EE FF 00 05 10 00 00 08 07 06 00 00 10 11 12 13 01 02 03 04 "
61                 + "50 50 20 20");
62         message.skipBytes(4); // skip XID
63         MatchV10 match = OF10MatchDeserializer.createMatchV10(message);
64         Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(true, true, true, true,
65                 true, true, true, true, true, true), match.getWildcards());
66         Assert.assertEquals("Wrong srcMask", 0, match.getNwSrcMask().shortValue());
67         Assert.assertEquals("Wrong dstMask", 0, match.getNwDstMask().shortValue());
68         Assert.assertEquals("Wrong in-port", 32, match.getInPort().intValue());
69         Assert.assertEquals("Wrong dl-src", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlSrc());
70         Assert.assertEquals("Wrong dl-dst", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlDst());
71         Assert.assertEquals("Wrong dl-vlan", 5, match.getDlVlan().intValue());
72         Assert.assertEquals("Wrong dl-vlan-pcp", 16, match.getDlVlanPcp().shortValue());
73         Assert.assertEquals("Wrong dl-type", 8, match.getDlType().intValue());
74         Assert.assertEquals("Wrong nw-tos", 7, match.getNwTos().shortValue());
75         Assert.assertEquals("Wrong nw-proto", 6, match.getNwProto().shortValue());
76         Assert.assertEquals("Wrong nw-src", new Ipv4Address("16.17.18.19"), match.getNwSrc());
77         Assert.assertEquals("Wrong nw-dst", new Ipv4Address("1.2.3.4"), match.getNwDst());
78         Assert.assertEquals("Wrong tp-src", 20560, match.getTpSrc().shortValue());
79         Assert.assertEquals("Wrong tp-dst", 8224, match.getTpDst().shortValue());
80     }
81
82 }