2 * Copyright (c) 2013 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
8 package org.opendaylight.openflowjava.protocol.impl.serialization.match;
10 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
17 * Parent for all match entry serializers
18 * @author michal.polkorab
20 public abstract class AbstractOxmMatchEntrySerializer
21 implements OFSerializer<MatchEntry>, HeaderSerializer<MatchEntry>{
24 public void serialize(MatchEntry entry, ByteBuf outBuffer) {
25 serializeHeader(entry, outBuffer);
29 public void serializeHeader(MatchEntry entry, ByteBuf outBuffer) {
30 outBuffer.writeShort(getOxmClassCode());
31 writeOxmFieldAndLength(outBuffer, getOxmFieldCode(), entry.isHasMask(),
35 protected static void writeMask(byte[] mask, ByteBuf out, int length) {
36 if (mask != null && mask.length != length) {
37 throw new IllegalArgumentException("incorrect length of mask: "+
38 mask.length + ", expected: " + length);
43 protected static void writeOxmFieldAndLength(ByteBuf out, int fieldValue, boolean hasMask, int lengthArg) {
44 int fieldAndMask = fieldValue << 1;
45 int length = lengthArg;
50 out.writeByte(fieldAndMask);
51 out.writeByte(length);
55 * @return numeric representation of oxm_field
57 protected abstract int getOxmFieldCode();
60 * @return numeric representation of oxm_class
62 protected abstract int getOxmClassCode();
65 * @return match entry value length (without mask length)
67 protected abstract int getValueLength();