Merge "OPNFLWPLUG-1062 Include additional LLDP fields in liblldp"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / serialization / match / Ipv6LabelEntrySerializerTest.java
1 /*
2  * Copyright (c) 2016 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.openflowplugin.impl.protocol.serialization.match;
10
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
13
14 import org.junit.Test;
15 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
16 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
17 import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6FlowLabel;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
23
24 public class Ipv6LabelEntrySerializerTest extends AbstractMatchEntrySerializerTest {
25
26     @Test
27     public void testSerialize() {
28         final long ipv6flowLabel = 358;
29         final long ipv6flowLabelMask = 100;
30
31         final Match ipv6flowLabelMatch = new MatchBuilder()
32                 .setLayer3Match(new Ipv6MatchBuilder()
33                         .setIpv6Label(new Ipv6LabelBuilder()
34                                 .setIpv6Flabel(new Ipv6FlowLabel(ipv6flowLabel))
35                                 .setFlabelMask(new Ipv6FlowLabel(ipv6flowLabelMask))
36                                 .build())
37                         .build())
38                 .build();
39
40         assertMatch(ipv6flowLabelMatch, true, (out) -> {
41             assertEquals(out.readUnsignedInt(), ipv6flowLabel);
42
43             byte[] mask = new byte[4];
44             out.readBytes(mask);
45             assertArrayEquals(mask, ByteUtil.unsignedIntToBytes(ipv6flowLabelMask));
46         });
47
48         final Match ipv6exyHdrMatchNoMask = new MatchBuilder()
49                 .setLayer3Match(new Ipv6MatchBuilder()
50                         .setIpv6Label(new Ipv6LabelBuilder()
51                                 .setIpv6Flabel(new Ipv6FlowLabel(ipv6flowLabel))
52                                 .build())
53                         .build())
54                 .build();
55
56         assertMatch(ipv6exyHdrMatchNoMask, false, (out) -> assertEquals(out.readUnsignedInt(), ipv6flowLabel));
57     }
58
59     @Override
60     protected short getLength() {
61         return EncodeConstants.SIZE_OF_INT_IN_BYTES;
62     }
63
64     @Override
65     protected int getOxmFieldCode() {
66         return OxmMatchConstants.IPV6_FLABEL;
67     }
68
69     @Override
70     protected int getOxmClassCode() {
71         return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
72     }
73
74 }