2 * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved.
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
9 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
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;
24 public class Ipv6LabelEntrySerializerTest extends AbstractMatchEntrySerializerTest {
27 public void testSerialize() {
28 final long ipv6flowLabel = 358;
29 final long ipv6flowLabelMask = 100;
31 final Match ipv6flowLabelMatch = new MatchBuilder()
32 .setLayer3Match(new Ipv6MatchBuilder()
33 .setIpv6Label(new Ipv6LabelBuilder()
34 .setIpv6Flabel(new Ipv6FlowLabel(ipv6flowLabel))
35 .setFlabelMask(new Ipv6FlowLabel(ipv6flowLabelMask))
40 assertMatch(ipv6flowLabelMatch, true, (out) -> {
41 assertEquals(out.readUnsignedInt(), ipv6flowLabel);
43 byte[] mask = new byte[4];
45 assertArrayEquals(mask, ByteUtil.unsignedIntToBytes(ipv6flowLabelMask));
48 final Match ipv6exyHdrMatchNoMask = new MatchBuilder()
49 .setLayer3Match(new Ipv6MatchBuilder()
50 .setIpv6Label(new Ipv6LabelBuilder()
51 .setIpv6Flabel(new Ipv6FlowLabel(ipv6flowLabel))
56 assertMatch(ipv6exyHdrMatchNoMask, false, (out) -> assertEquals(out.readUnsignedInt(), ipv6flowLabel));
60 protected short getLength() {
61 return EncodeConstants.SIZE_OF_INT_IN_BYTES;
65 protected int getOxmFieldCode() {
66 return OxmMatchConstants.IPV6_FLABEL;
70 protected int getOxmClassCode() {
71 return OxmMatchConstants.OPENFLOW_BASIC_CLASS;