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.opendaylight.flow.types.rev131026.flow.MatchBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeaderBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
23 public class Ipv6ExtHeaderEntrySerializerTest extends AbstractMatchEntrySerializerTest {
26 public void testSerialize() throws Exception {
27 final int ipv6extHdr = 358;
28 final int ipv6extHdrMask = 100;
30 final Match ipv6extHdrMatch = new MatchBuilder()
31 .setLayer3Match(new Ipv6MatchBuilder()
32 .setIpv6ExtHeader(new Ipv6ExtHeaderBuilder()
33 .setIpv6Exthdr(ipv6extHdr)
34 .setIpv6ExthdrMask(ipv6extHdrMask)
39 assertMatch(ipv6extHdrMatch, true, (out) -> {
40 assertEquals(out.readUnsignedShort(), ipv6extHdr);
42 byte[] mask = new byte[2];
44 assertArrayEquals(mask, ByteUtil.unsignedShortToBytes(ipv6extHdrMask));
47 final Match ipv6exyHdrMatchNoMask = new MatchBuilder()
48 .setLayer3Match(new Ipv6MatchBuilder()
49 .setIpv6ExtHeader(new Ipv6ExtHeaderBuilder()
50 .setIpv6Exthdr(ipv6extHdr)
55 assertMatch(ipv6exyHdrMatchNoMask, false, (out) -> assertEquals(out.readUnsignedShort(), ipv6extHdr));
59 protected short getLength() {
60 return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
64 protected int getOxmFieldCode() {
65 return OxmMatchConstants.IPV6_EXTHDR;
69 protected int getOxmClassCode() {
70 return OxmMatchConstants.OPENFLOW_BASIC_CLASS;