Merge "Remove redundant type specifiers"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / serialization / match / TunnelIdEntrySerializerTest.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.serialization.match;
10
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
13
14 import java.math.BigInteger;
15 import java.nio.ByteBuffer;
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.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TunnelBuilder;
22
23 public class TunnelIdEntrySerializerTest extends AbstractMatchEntrySerializerTest {
24
25     @Test
26     public void testSerialize() throws Exception {
27         final long tunnelId = 8;
28         final byte[] tcpMask = new byte[] { 30, 30, 30, 30, 0, 0, 0, 0 };
29
30         final ByteBuffer maskBuff = ByteBuffer.allocate(Long.BYTES);
31         maskBuff.put(tcpMask, 0, tcpMask.length);
32         maskBuff.flip();
33
34         final Match tcpFlagsMatch = new MatchBuilder()
35                 .setTunnel(new TunnelBuilder()
36                         .setTunnelId(BigInteger.valueOf(tunnelId))
37                         .setTunnelMask(BigInteger.valueOf(maskBuff.getLong()))
38                         .build())
39                 .build();
40
41         assertMatch(tcpFlagsMatch, true, (out) -> {
42             assertEquals(out.readLong(), tunnelId);
43
44             byte[] mask = new byte[8];
45             out.readBytes(mask);
46             assertArrayEquals(mask, tcpMask);
47         });
48
49         final Match tcpFlagsMatchNoMask = new MatchBuilder()
50                 .setTunnel(new TunnelBuilder()
51                         .setTunnelId(BigInteger.valueOf(tunnelId))
52                         .build())
53                 .build();
54
55         assertMatch(tcpFlagsMatchNoMask, false, (out) -> assertEquals(out.readLong(), tunnelId));
56     }
57
58     @Override
59     protected short getLength() {
60         return EncodeConstants.SIZE_OF_LONG_IN_BYTES;
61     }
62
63     @Override
64     protected int getOxmFieldCode() {
65         return OxmMatchConstants.TUNNEL_ID;
66     }
67
68     @Override
69     protected int getOxmClassCode() {
70         return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
71     }
72
73 }