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;
12 import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer;
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
20 * @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 * @return oxm_field class
34 protected abstract Class<? extends MatchField> getOxmField();
37 * @return 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
45 * @param oxmClass oxm class type
46 * @param oxmField oxm field type
47 * @param input input bytebuf
48 * @return MatchEntriesBuilder which can be filled with MatchEntry augmentation
50 protected MatchEntryBuilder processHeader(Class<? extends OxmClassBase> oxmClass,
51 Class<? extends MatchField> oxmField, ByteBuf input) {
52 MatchEntryBuilder builder = new MatchEntryBuilder();
53 builder.setOxmClass(oxmClass);
54 // skip oxm_class (provided)
55 input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
56 builder.setOxmMatchField(oxmField);
57 boolean hasMask = (input.readUnsignedByte() & 1) != 0;
58 builder.setHasMask(hasMask);
59 // skip match entry length - not needed
60 input.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);