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;
13 import org.junit.Test;
14 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
15 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
16 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
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.match.layer._3.match.Ipv6MatchBuilder;
23 public class Ipv6DestinationEntrySerializerTest extends AbstractMatchEntrySerializerTest {
26 public void testSerialize() {
27 final Ipv6Prefix ipv6Address = new Ipv6Prefix("2001:db8::/32");
29 final Match ipv6abmMatch = new MatchBuilder()
30 .setLayer3Match(new Ipv6MatchBuilder()
31 .setIpv6Destination(ipv6Address)
35 assertMatch(ipv6abmMatch, true, (out) -> {
36 byte[] address = new byte[16];
37 out.readBytes(address);
38 assertArrayEquals(address,
39 IetfInetUtil.ipv6AddressBytes(IpConversionUtil.extractIpv6Address(ipv6Address)));
41 byte[] mask = new byte[16];
43 assertArrayEquals(mask,
44 IpConversionUtil.convertIpv6PrefixToByteArray(IpConversionUtil.extractIpv6Prefix(ipv6Address)));
49 public void testSerializeWithoutMask() {
50 final Ipv6Prefix ipv6Address = new Ipv6Prefix("2001:db8::123/128");
52 final Match ipv6abmMatch = new MatchBuilder()
53 .setLayer3Match(new Ipv6MatchBuilder()
54 .setIpv6Destination(ipv6Address)
58 assertMatch(ipv6abmMatch, false, (out) -> {
59 byte[] address = new byte[16];
60 out.readBytes(address);
61 assertArrayEquals(address,
62 IetfInetUtil.ipv6AddressBytes(IpConversionUtil.extractIpv6Address(ipv6Address)));
67 protected short getLength() {
68 return EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES;
72 protected int getOxmFieldCode() {
73 return OxmMatchConstants.IPV6_DST;
77 protected int getOxmClassCode() {
78 return OxmMatchConstants.OPENFLOW_BASIC_CLASS;