2 * Copyright (c) 2014, 2015 Cisco Systems, Inc. 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.openflowjava.nx.codec.match;
11 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
15 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
21 public abstract class AbstractMatchCodec implements OFSerializer<MatchEntry>, OFDeserializer<MatchEntry> {
23 protected NxmHeader headerWithMask;
24 protected NxmHeader headerWithoutMask;
26 protected MatchEntryBuilder deserializeHeader(ByteBuf message) {
27 MatchEntryBuilder builder = new MatchEntryBuilder();
28 builder.setOxmClass(getOxmClass());
29 // skip oxm_class - provided
30 message.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
31 builder.setOxmMatchField(getNxmField());
32 boolean hasMask = (message.readUnsignedByte() & 1) != 0;
33 builder.setHasMask(hasMask);
34 // skip match entry length - not needed
35 message.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
39 protected void serializeHeader(MatchEntry input, ByteBuf outBuffer) {
40 outBuffer.writeInt(serializeHeaderToLong(input.isHasMask()).intValue());
43 private Long serializeHeaderToLong(boolean hasMask) {
45 return getHeaderWithHasMask().toLong();
47 return getHeaderWithoutHasMask().toLong();
50 public NxmHeader getHeaderWithoutHasMask() {
51 if (headerWithoutMask == null) {
52 headerWithoutMask = new NxmHeader(getOxmClassCode(), getNxmFieldCode(), false, getValueLength());
54 return headerWithoutMask;
57 public NxmHeader getHeaderWithHasMask() {
58 if (headerWithMask == null) {
59 headerWithMask = new NxmHeader(getOxmClassCode(), getNxmFieldCode(), true, getValueLength());
61 return headerWithMask;
65 * @return numeric representation of nxm_field
67 public abstract int getNxmFieldCode();
70 * @return numeric representation of oxm_class
72 public abstract int getOxmClassCode();
75 * @return match entry value length
77 public abstract int getValueLength();
80 * @return nxm_field class
82 public abstract Class<? extends MatchField> getNxmField();
85 * @return oxm_class class
87 public abstract Class<? extends OxmClassBase> getOxmClass();