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.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
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.openflowplugin.openflow.md.util.ByteUtil;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Tunnel;
21 import io.netty.buffer.ByteBuf;
22 import io.netty.buffer.UnpooledByteBufAllocator;
24 public class TunnelIdEntryDeserializerTest extends AbstractMatchEntryDeserializerTest {
27 public void deserializeEntry() throws Exception {
28 final ByteBuf in = UnpooledByteBufAllocator.DEFAULT.buffer();
29 final BigInteger tunnelId = BigInteger.valueOf(6);
30 final BigInteger tunnelIdMask = BigInteger.valueOf(5);
32 writeHeader(in, false);
33 in.writeBytes(ByteUtil.convertBigIntegerToNBytes(tunnelId, EncodeConstants.SIZE_OF_LONG_IN_BYTES));
35 Tunnel match = deserialize(in).getTunnel();
37 ByteUtil.convertBigIntegerToNBytes(tunnelId, EncodeConstants.SIZE_OF_LONG_IN_BYTES),
38 ByteUtil.convertBigIntegerToNBytes(match.getTunnelId(), EncodeConstants.SIZE_OF_LONG_IN_BYTES));
40 assertEquals(0, in.readableBytes());
42 writeHeader(in, true);
43 in.writeBytes(ByteUtil.convertBigIntegerToNBytes(tunnelId, EncodeConstants.SIZE_OF_LONG_IN_BYTES));
44 in.writeBytes(ByteUtil.convertBigIntegerToNBytes(tunnelIdMask, EncodeConstants.SIZE_OF_LONG_IN_BYTES));
46 match = deserialize(in).getTunnel();
48 ByteUtil.convertBigIntegerToNBytes(tunnelId, EncodeConstants.SIZE_OF_LONG_IN_BYTES),
49 ByteUtil.convertBigIntegerToNBytes(match.getTunnelId(), EncodeConstants.SIZE_OF_LONG_IN_BYTES));
51 ByteUtil.convertBigIntegerToNBytes(tunnelIdMask, EncodeConstants.SIZE_OF_LONG_IN_BYTES),
52 ByteUtil.convertBigIntegerToNBytes(match.getTunnelMask(), EncodeConstants.SIZE_OF_LONG_IN_BYTES));
53 assertEquals(0, in.readableBytes());
57 protected int getOxmClassCode() {
58 return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
62 protected int getOxmFieldCode() {
63 return OxmMatchConstants.TUNNEL_ID;
67 protected int getValueLength() {
68 return EncodeConstants.SIZE_OF_LONG_IN_BYTES;