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.deserialization.match;
11 import static org.junit.Assert.assertEquals;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.UnpooledByteBufAllocator;
15 import java.math.BigInteger;
16 import org.junit.Test;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
19 import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata;
22 public class MetadataEntryDeserializerTest extends AbstractMatchEntryDeserializerTest {
25 public void deserializeEntry() throws Exception {
26 final ByteBuf in = UnpooledByteBufAllocator.DEFAULT.buffer();
27 final BigInteger metadata = BigInteger.valueOf(20);
28 final BigInteger metadataMask = BigInteger.valueOf(30);
30 writeHeader(in, false);
31 in.writeBytes(ByteUtil.convertBigIntegerToNBytes(metadata, getValueLength()));
33 assertEquals(metadata, deserialize(in).getMetadata().getMetadata());
34 assertEquals(0, in.readableBytes());
36 writeHeader(in, true);
37 in.writeBytes(ByteUtil.convertBigIntegerToNBytes(metadata, getValueLength()));
38 in.writeBytes(ByteUtil.convertBigIntegerToNBytes(metadataMask, getValueLength()));
40 final Metadata desMetadata = deserialize(in).getMetadata();
41 assertEquals(metadata, desMetadata.getMetadata());
42 assertEquals(metadataMask, desMetadata.getMetadataMask());
43 assertEquals(0, in.readableBytes());
47 protected int getOxmClassCode() {
48 return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
52 protected int getOxmFieldCode() {
53 return OxmMatchConstants.METADATA;
57 protected int getValueLength() {
58 return EncodeConstants.SIZE_OF_LONG_IN_BYTES;