Fix errors in serializers and deserializers
[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 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;
20
21 import io.netty.buffer.ByteBuf;
22 import io.netty.buffer.UnpooledByteBufAllocator;
23
24 public class TunnelIdEntryDeserializerTest extends AbstractMatchEntryDeserializerTest {
25
26     @Test
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);
31
32         writeHeader(in, false);
33         in.writeBytes(ByteUtil.convertBigIntegerToNBytes(tunnelId, EncodeConstants.SIZE_OF_LONG_IN_BYTES));
34
35         Tunnel match = deserialize(in).getTunnel();
36         assertArrayEquals(
37             ByteUtil.convertBigIntegerToNBytes(tunnelId, EncodeConstants.SIZE_OF_LONG_IN_BYTES),
38             ByteUtil.convertBigIntegerToNBytes(match.getTunnelId(), EncodeConstants.SIZE_OF_LONG_IN_BYTES));
39
40         assertEquals(0, in.readableBytes());
41
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));
45
46         match = deserialize(in).getTunnel();
47         assertArrayEquals(
48             ByteUtil.convertBigIntegerToNBytes(tunnelId, EncodeConstants.SIZE_OF_LONG_IN_BYTES),
49             ByteUtil.convertBigIntegerToNBytes(match.getTunnelId(), EncodeConstants.SIZE_OF_LONG_IN_BYTES));
50         assertArrayEquals(
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());
54     }
55
56     @Override
57     protected int getOxmClassCode() {
58         return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
59     }
60
61     @Override
62     protected int getOxmFieldCode() {
63         return OxmMatchConstants.TUNNEL_ID;
64     }
65
66     @Override
67     protected int getValueLength() {
68         return EncodeConstants.SIZE_OF_LONG_IN_BYTES;
69     }
70
71 }