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