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.openflowplugin.openflow.md.util.ByteUtil;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
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.ProtocolMatchFieldsBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.PbbBuilder;
23 public class PbbEntrySerializerTest extends AbstractMatchEntrySerializerTest {
26 public void testSerialize() throws Exception {
27 final long pbbId = 6789;
28 final byte[] pbbIdMask = new byte[] { 0, 15, 10 };
30 final Match pbbMatch = new MatchBuilder()
31 .setProtocolMatchFields(new ProtocolMatchFieldsBuilder()
32 .setPbb(new PbbBuilder()
34 .setPbbMask(ByteUtil.bytesToUnsignedMedium(pbbIdMask))
39 assertMatch(pbbMatch, true, (out) -> {
40 assertEquals(out.readUnsignedMedium(), pbbId);
42 final byte[] mask = new byte[3];
44 assertArrayEquals(mask, pbbIdMask);
47 final Match pbbMatchNoMask = new MatchBuilder()
48 .setProtocolMatchFields(new ProtocolMatchFieldsBuilder()
49 .setPbb(new PbbBuilder()
55 assertMatch(pbbMatchNoMask, false, (out) -> assertEquals(out.readUnsignedMedium(), pbbId));
59 protected short getLength() {
60 return EncodeConstants.SIZE_OF_3_BYTES;
64 protected int getOxmFieldCode() {
65 return OxmMatchConstants.PBB_ISID;
69 protected int getOxmClassCode() {
70 return OxmMatchConstants.OPENFLOW_BASIC_CLASS;