Mass replace CRLF->LF
[openflowjava.git] / 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
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.rev130731.MatchField;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmClassBase;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;
18
19 /**
20  * @author michal.polkorab
21  *
22  */
23 public abstract class AbstractOxmMatchEntryDeserializer implements HeaderDeserializer<MatchEntries> {
24
25     @Override
26     public MatchEntries deserializeHeader(ByteBuf input) {
27         MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input);
28         return builder.build();
29     }
30
31     /**
32      * @return oxm_field class
33      */
34     protected abstract Class<? extends MatchField> getOxmField();
35
36     /**
37      * @return 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      * @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
49      */
50     protected MatchEntriesBuilder processHeader(Class<? extends OxmClassBase> oxmClass,
51             Class<? extends MatchField> oxmField, ByteBuf input) {
52         MatchEntriesBuilder builder = new MatchEntriesBuilder();
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);
61         return builder;
62     }
63     
64 }