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.augments.rev131002.MaskMatchEntry;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
18 * Parent for all match entry serializers
19 * @author michal.polkorab
21 public abstract class AbstractOxmMatchEntrySerializer
22 implements OFSerializer<MatchEntries>, HeaderSerializer<MatchEntries>{
25 public void serialize(MatchEntries entry, ByteBuf outBuffer) {
26 serializeHeader(entry, outBuffer);
30 public void serializeHeader(MatchEntries entry, ByteBuf outBuffer) {
31 outBuffer.writeShort(getOxmClassCode());
32 writeOxmFieldAndLength(outBuffer, getOxmFieldCode(), entry.isHasMask(),
36 protected static void writeMask(MatchEntries entry, ByteBuf out, int length) {
37 if (entry.isHasMask()) {
38 byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask();
39 if (mask != null && mask.length != length) {
40 throw new IllegalArgumentException("incorrect length of mask: "+
41 mask.length + ", expected: " + length);
47 protected static void writeOxmFieldAndLength(ByteBuf out, int fieldValue, boolean hasMask, int lengthArg) {
48 int fieldAndMask = fieldValue << 1;
49 int length = lengthArg;
54 out.writeByte(fieldAndMask);
55 out.writeByte(length);
59 * @return numeric representation of oxm_field
61 protected abstract int getOxmFieldCode();
64 * @return numeric representation of oxm_class
66 protected abstract int getOxmClassCode();
69 * @return match entry value length (without mask length)
71 protected abstract int getValueLength();