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.HeaderDeserializer;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
23 public abstract class AbstractMatchCodec implements
24 OFSerializer<MatchEntry>,
25 OFDeserializer<MatchEntry>,
26 HeaderSerializer<MatchEntry>,
27 HeaderDeserializer<MatchEntry> {
29 protected NxmHeader headerWithMask;
30 protected NxmHeader headerWithoutMask;
32 protected MatchEntryBuilder deserializeHeaderToBuilder(ByteBuf message) {
33 MatchEntryBuilder builder = new MatchEntryBuilder();
34 builder.setOxmClass(getOxmClass());
35 // skip oxm_class - provided
36 message.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
37 builder.setOxmMatchField(getNxmField());
38 boolean hasMask = (message.readUnsignedByte() & 1) != 0;
39 builder.setHasMask(hasMask);
40 // skip match entry length - not needed
41 message.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
46 public MatchEntry deserializeHeader(ByteBuf message) {
47 return deserializeHeaderToBuilder(message).build();
51 public void serializeHeader(MatchEntry input, ByteBuf outBuffer) {
52 outBuffer.writeInt(serializeHeaderToLong(input.isHasMask()).intValue());
55 private Long serializeHeaderToLong(boolean hasMask) {
57 return getHeaderWithHasMask().toLong();
59 return getHeaderWithoutHasMask().toLong();
62 public NxmHeader getHeaderWithoutHasMask() {
63 if (headerWithoutMask == null) {
64 headerWithoutMask = new NxmHeader(getOxmClassCode(), getNxmFieldCode(), false, getValueLength());
66 return headerWithoutMask;
69 public NxmHeader getHeaderWithHasMask() {
70 if (headerWithMask == null) {
71 headerWithMask = new NxmHeader(getOxmClassCode(), getNxmFieldCode(), true, getValueLength());
73 return headerWithMask;
77 * @return numeric representation of nxm_field
79 public abstract int getNxmFieldCode();
82 * @return numeric representation of oxm_class
84 public abstract int getOxmClassCode();
87 * @return match entry value length
89 public abstract int getValueLength();
92 * @return nxm_field class
94 public abstract Class<? extends MatchField> getNxmField();
97 * @return oxm_class class
99 public abstract Class<? extends OxmClassBase> getOxmClass();