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 io.netty.buffer.ByteBuf;
11 import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer;
12 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
19 * Base class for an Oxm match entry deserializer.
21 * @author michal.polkorab
23 public abstract class AbstractOxmMatchEntryDeserializer implements HeaderDeserializer<MatchEntry> {
26 public MatchEntry deserializeHeader(ByteBuf input) {
27 MatchEntryBuilder builder = processHeader(getOxmClass(), getOxmField(), input);
28 return builder.build();
32 * Returns the oxm_field class.
34 protected abstract Class<? extends MatchField> getOxmField();
37 * Returns the oxm_class class.
39 protected abstract Class<? extends OxmClassBase> getOxmClass();
42 * Prepares match entry header - sets oxm_class, oxm_field, hasMask
43 * + sets the buffer.readerIndex() to the end of match entry
44 * - where augmentation starts.
46 * @param oxmClass oxm class type
47 * @param oxmField oxm field type
48 * @param input input bytebuf
49 * @return MatchEntriesBuilder which can be filled with MatchEntry augmentation
51 protected MatchEntryBuilder processHeader(Class<? extends OxmClassBase> oxmClass,
52 Class<? extends MatchField> oxmField, ByteBuf input) {
53 MatchEntryBuilder builder = new MatchEntryBuilder();
54 builder.setOxmClass(oxmClass);
55 // skip oxm_class (provided)
56 input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
57 builder.setOxmMatchField(oxmField);
58 boolean hasMask = (input.readUnsignedByte() & 1) != 0;
59 builder.setHasMask(hasMask);
60 // skip match entry length - not needed
61 input.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);