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.deserialization.match;
10 import static java.util.Objects.requireNonNull;
12 import io.netty.buffer.ByteBuf;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
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.OpenflowBasicClass;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
23 * Base class for an Oxm match entry deserializer.
25 * @author michal.polkorab
27 public abstract class AbstractOxmMatchEntryDeserializer
28 implements HeaderDeserializer<MatchEntry>, OFDeserializer<MatchEntry> {
29 private final @NonNull OxmClassBase oxmClass;
30 private final @NonNull MatchField oxmField;
32 protected AbstractOxmMatchEntryDeserializer(final OxmClassBase oxmClass,
33 final MatchField oxmField) {
34 this.oxmClass = requireNonNull(oxmClass);
35 this.oxmField = requireNonNull(oxmField);
38 protected AbstractOxmMatchEntryDeserializer(final MatchField oxmField) {
39 this(OpenflowBasicClass.VALUE, oxmField);
43 public final MatchEntry deserialize(final ByteBuf input) {
44 final MatchEntryBuilder builder = processHeader(input);
45 deserialize(input, builder);
46 return builder.build();
49 protected abstract void deserialize(ByteBuf input, MatchEntryBuilder builder);
52 public final MatchEntry deserializeHeader(final ByteBuf input) {
53 return processHeader(input).build();
57 * Prepares match entry header - sets oxm_class, oxm_field, hasMask
58 * + sets the buffer.readerIndex() to the end of match entry
59 * - where augmentation starts.
61 * @param input input bytebuf
62 * @return MatchEntriesBuilder which can be filled with MatchEntry augmentation
64 protected final MatchEntryBuilder processHeader(final ByteBuf input) {
65 // skip oxm_class (provided)
66 input.skipBytes(Short.BYTES);
67 final MatchEntryBuilder builder = new MatchEntryBuilder().setOxmClass(oxmClass).setOxmMatchField(oxmField)
68 .setHasMask((input.readUnsignedByte() & 1) != 0);
69 // skip match entry length - not needed
70 input.skipBytes(Byte.BYTES);