2 * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.openflowjava.protocol.impl.serialization.match;
\r
10 import io.netty.buffer.ByteBuf;
\r
12 import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer;
\r
13 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
\r
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry;
\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
\r
18 * Parent for all match entry serializers
\r
19 * @author michal.polkorab
\r
21 public abstract class AbstractOxmMatchEntrySerializer
\r
22 implements OFSerializer<MatchEntries>, HeaderSerializer<MatchEntries>{
\r
25 public void serialize(MatchEntries entry, ByteBuf outBuffer) {
\r
26 serializeHeader(entry, outBuffer);
\r
30 public void serializeHeader(MatchEntries entry, ByteBuf outBuffer) {
\r
31 outBuffer.writeShort(getOxmClassCode());
\r
32 writeOxmFieldAndLength(outBuffer, getOxmFieldCode(), entry.isHasMask(),
\r
36 protected static void writeMask(MatchEntries entry, ByteBuf out, int length) {
\r
37 if (entry.isHasMask()) {
\r
38 byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask();
\r
39 if (mask != null && mask.length != length) {
\r
40 throw new IllegalArgumentException("incorrect length of mask: "+
\r
41 mask.length + ", expected: " + length);
\r
43 out.writeBytes(mask);
\r
47 protected static void writeOxmFieldAndLength(ByteBuf out, int fieldValue, boolean hasMask, int lengthArg) {
\r
48 int fieldAndMask = fieldValue << 1;
\r
49 int length = lengthArg;
\r
54 out.writeByte(fieldAndMask);
\r
55 out.writeByte(length);
\r
59 * @return numeric representation of oxm_field
\r
61 protected abstract int getOxmFieldCode();
\r
64 * @return numeric representation of oxm_class
\r
66 protected abstract int getOxmClassCode();
\r
69 * @return match entry value length (without mask length)
\r
71 protected abstract int getValueLength();
\r