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 com.google.common.primitives.Longs;
14 import java.math.BigInteger;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
17 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
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.match.MetadataBuilder;
22 public class MetadataEntrySerializerTest extends AbstractMatchEntrySerializerTest {
25 public void testSerialize() throws Exception {
26 final byte[] metadata = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 };
27 final byte[] metadataMask = new byte[] { 30, 30, 30, 30, 30, 0, 0, 0 };
30 final Match metadataMatch = new MatchBuilder()
31 .setMetadata(new MetadataBuilder()
32 .setMetadata(BigInteger.valueOf(Longs.fromByteArray(metadata)))
33 .setMetadataMask(BigInteger.valueOf(Longs.fromByteArray(metadataMask)))
37 assertMatch(metadataMatch, true, (out) -> {
38 byte[] addressBytes = new byte[8];
39 out.readBytes(addressBytes);
40 assertArrayEquals(addressBytes, metadata);
42 byte[] maskBytes = new byte[8];
43 out.readBytes(maskBytes);
44 assertArrayEquals(maskBytes, metadataMask);
47 final Match metadataMatchNoMask = new MatchBuilder()
48 .setMetadata(new MetadataBuilder()
49 .setMetadata(BigInteger.valueOf(Longs.fromByteArray(metadata)))
53 assertMatch(metadataMatchNoMask, false, (out) -> {
54 byte[] addressBytes = new byte[8];
55 out.readBytes(addressBytes);
56 assertArrayEquals(addressBytes, metadata);
61 protected short getLength() {
62 return EncodeConstants.SIZE_OF_LONG_IN_BYTES;
66 protected int getOxmFieldCode() {
67 return OxmMatchConstants.METADATA;
71 protected int getOxmClassCode() {
72 return OxmMatchConstants.OPENFLOW_BASIC_CLASS;