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.serialization.match;
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
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;
23 public class TunnelIdEntrySerializerTest extends AbstractMatchEntrySerializerTest {
26 public void testSerialize() {
27 final long tunnelId = 8;
28 final byte[] tcpMask = new byte[] { 30, 30, 30, 30, 0, 0, 0, 0 };
30 final ByteBuffer maskBuff = ByteBuffer.allocate(Long.BYTES);
31 maskBuff.put(tcpMask, 0, tcpMask.length);
34 final Match tcpFlagsMatch = new MatchBuilder()
35 .setTunnel(new TunnelBuilder()
36 .setTunnelId(BigInteger.valueOf(tunnelId))
37 .setTunnelMask(BigInteger.valueOf(maskBuff.getLong()))
41 assertMatch(tcpFlagsMatch, true, (out) -> {
42 assertEquals(out.readLong(), tunnelId);
44 byte[] mask = new byte[8];
46 assertArrayEquals(mask, tcpMask);
49 final Match tcpFlagsMatchNoMask = new MatchBuilder()
50 .setTunnel(new TunnelBuilder()
51 .setTunnelId(BigInteger.valueOf(tunnelId))
55 assertMatch(tcpFlagsMatchNoMask, false, (out) -> assertEquals(out.readLong(), tunnelId));
59 protected short getLength() {
60 return EncodeConstants.SIZE_OF_LONG_IN_BYTES;
64 protected int getOxmFieldCode() {
65 return OxmMatchConstants.TUNNEL_ID;
69 protected int getOxmClassCode() {
70 return OxmMatchConstants.OPENFLOW_BASIC_CLASS;