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 org.junit.Test;
15 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
16 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
23 public class VlanVidEntrySerializerTest extends AbstractMatchEntrySerializerTest {
26 public void testSerialize() throws Exception {
27 final int vlan = (short) 1;
29 final Match vlanMatch = new MatchBuilder()
30 .setVlanMatch(new VlanMatchBuilder()
31 .setVlanId(new VlanIdBuilder()
32 .setVlanId(new VlanId(vlan))
33 .setVlanIdPresent(true)
38 assertMatch(vlanMatch, false, (out) -> assertEquals(out.readShort(), vlan | (1 << 12)));
40 final Match vlanMatchMaskOnly = new MatchBuilder()
41 .setVlanMatch(new VlanMatchBuilder()
42 .setVlanId(new VlanIdBuilder()
43 .setVlanIdPresent(true)
48 assertMatch(vlanMatchMaskOnly, true, out -> {
49 assertEquals(out.readShort(), (1 << 12));
51 byte[] mask = new byte[2];
53 assertArrayEquals(mask, new byte[] { 16, 0 });
58 protected short getLength() {
59 return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
63 protected int getOxmFieldCode() {
64 return OxmMatchConstants.VLAN_VID;
68 protected int getOxmClassCode() {
69 return OxmMatchConstants.OPENFLOW_BASIC_CLASS;