Bug 2756 - Match model update
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / match / OxmIpv6FlabelDeserializerTest.java
1 /*
2  * Copyright (c) 2014 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.deserialization.match;
10
11 import io.netty.buffer.ByteBuf;
12
13 import org.junit.Assert;
14 import org.junit.Test;
15 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6Flabel;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6FlabelCase;
20
21 /**
22  * @author michal.polkorab
23  *
24  */
25 public class OxmIpv6FlabelDeserializerTest {
26
27     /**
28      * Tests {@link OxmIpv6FlabelDeserializer#deserialize(ByteBuf)}
29      */
30     @Test
31     public void test() {
32         ByteBuf buffer = BufferHelper.buildBuffer("80 00 38 04 00 00 00 02");
33
34         buffer.skipBytes(4); // skip XID
35         OxmIpv6FlabelDeserializer deserializer = new OxmIpv6FlabelDeserializer();
36         MatchEntry entry = deserializer.deserialize(buffer);
37
38         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry.getOxmClass());
39         Assert.assertEquals("Wrong entry field", Ipv6Flabel.class, entry.getOxmMatchField());
40         Assert.assertEquals("Wrong entry hasMask", false, entry.isHasMask());
41         Assert.assertEquals("Wrong entry value", 2,
42                 ((Ipv6FlabelCase) entry.getMatchEntryValue()).getIpv6Flabel()
43                 .getIpv6Flabel().getValue().intValue());
44     }
45
46     /**
47      * Tests {@link OxmIpv6FlabelDeserializer#deserialize(ByteBuf)}
48      */
49     @Test
50     public void testWithMask() {
51         ByteBuf buffer = BufferHelper.buildBuffer("80 00 39 08 00 00 00 02 00 00 00 05");
52
53         buffer.skipBytes(4); // skip XID
54         OxmIpv6FlabelDeserializer deserializer = new OxmIpv6FlabelDeserializer();
55         MatchEntry entry = deserializer.deserialize(buffer);
56
57         Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry.getOxmClass());
58         Assert.assertEquals("Wrong entry field", Ipv6Flabel.class, entry.getOxmMatchField());
59         Assert.assertEquals("Wrong entry hasMask", true, entry.isHasMask());
60         Assert.assertEquals("Wrong entry value", 2,
61                 ((Ipv6FlabelCase) entry.getMatchEntryValue()).getIpv6Flabel()
62                 .getIpv6Flabel().getValue().intValue());
63         Assert.assertArrayEquals("Wrong entry mask", new byte[]{0, 0, 0, 5},
64                 ((Ipv6FlabelCase) entry.getMatchEntryValue()).getIpv6Flabel().getMask());
65     }
66 }