Fix checkstyle violations in openflow-protocol-impl - part 3
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / match / AbstractOxmMatchEntryDeserializer.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.openflowjava.protocol.impl.deserialization.match;
9
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;
17
18 /**
19  * Base class for an Oxm match entry deserializer.
20  *
21  * @author michal.polkorab
22  */
23 public abstract class AbstractOxmMatchEntryDeserializer implements HeaderDeserializer<MatchEntry> {
24
25     @Override
26     public MatchEntry deserializeHeader(ByteBuf input) {
27         MatchEntryBuilder builder = processHeader(getOxmClass(), getOxmField(), input);
28         return builder.build();
29     }
30
31     /**
32      * Returns the oxm_field class.
33      */
34     protected abstract Class<? extends MatchField> getOxmField();
35
36     /**
37      * Returns the oxm_class class.
38      */
39     protected abstract Class<? extends OxmClassBase> getOxmClass();
40
41     /**
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      *
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
50      */
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);
62         return builder;
63     }
64
65 }