Bump mdsal to 5.0.2
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / match / TunnelIdEntryDeserializerTest.java
1 /*
2  * Copyright (c) 2016 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowplugin.impl.protocol.deserialization.match;
10
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
13
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.UnpooledByteBufAllocator;
16 import java.math.BigInteger;
17 import org.junit.Test;
18 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
19 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
20 import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Tunnel;
22
23 public class TunnelIdEntryDeserializerTest extends AbstractMatchEntryDeserializerTest {
24
25     @Test
26     public void deserializeEntry() {
27         final ByteBuf in = UnpooledByteBufAllocator.DEFAULT.buffer();
28         final BigInteger tunnelId = BigInteger.valueOf(6);
29         final BigInteger tunnelIdMask = BigInteger.valueOf(5);
30
31         writeHeader(in, false);
32         in.writeBytes(ByteUtil.convertBigIntegerToNBytes(tunnelId, EncodeConstants.SIZE_OF_LONG_IN_BYTES));
33
34         Tunnel match = deserialize(in).getTunnel();
35         assertArrayEquals(
36                 ByteUtil.convertBigIntegerToNBytes(tunnelId, EncodeConstants.SIZE_OF_LONG_IN_BYTES),
37                 ByteUtil.uint64toBytes(match.getTunnelId()));
38
39         assertEquals(0, in.readableBytes());
40
41         writeHeader(in, true);
42         in.writeBytes(ByteUtil.convertBigIntegerToNBytes(tunnelId, EncodeConstants.SIZE_OF_LONG_IN_BYTES));
43         in.writeBytes(ByteUtil.convertBigIntegerToNBytes(tunnelIdMask, EncodeConstants.SIZE_OF_LONG_IN_BYTES));
44
45         match = deserialize(in).getTunnel();
46         assertArrayEquals(
47                 ByteUtil.convertBigIntegerToNBytes(tunnelId, EncodeConstants.SIZE_OF_LONG_IN_BYTES),
48                 ByteUtil.uint64toBytes(match.getTunnelId()));
49         assertArrayEquals(
50                 ByteUtil.convertBigIntegerToNBytes(tunnelIdMask, EncodeConstants.SIZE_OF_LONG_IN_BYTES),
51                 ByteUtil.uint64toBytes(match.getTunnelMask()));
52         assertEquals(0, in.readableBytes());
53     }
54
55     @Override
56     protected int getOxmClassCode() {
57         return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
58     }
59
60     @Override
61     protected int getOxmFieldCode() {
62         return OxmMatchConstants.TUNNEL_ID;
63     }
64
65     @Override
66     protected int getValueLength() {
67         return EncodeConstants.SIZE_OF_LONG_IN_BYTES;
68     }
69
70 }