62c7a50745a06b44edbcf2034c9ef0ea5e37e213
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / match / AbstractOxmMatchEntryDeserializer.java
1 /*\r
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. and others.  All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 package org.opendaylight.openflowjava.protocol.impl.deserialization.match;\r
9 \r
10 import io.netty.buffer.ByteBuf;\r
11 \r
12 import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer;\r
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;\r
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Clazz;\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField;\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;\r
18 \r
19 /**\r
20  * @author michal.polkorab\r
21  *\r
22  */\r
23 public abstract class AbstractOxmMatchEntryDeserializer implements HeaderDeserializer<MatchEntries> {\r
24 \r
25     @Override\r
26     public MatchEntries deserializeHeader(ByteBuf input) {\r
27         MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input);\r
28         return builder.build();\r
29     }\r
30 \r
31     /**\r
32      * @return oxm_field class\r
33      */\r
34     protected abstract Class<? extends MatchField> getOxmField();\r
35 \r
36     /**\r
37      * @return oxm_class class\r
38      */\r
39     protected abstract Class<? extends Clazz> getOxmClass();\r
40 \r
41     /**\r
42      * Prepares match entry header - sets oxm_class, oxm_field, hasMask\r
43      *  + sets the buffer.readerIndex() to the end of match entry \r
44      *  - where augmentation starts\r
45      * @param oxm_class oxm class type\r
46      * @param oxm_field oxm field type\r
47      * @param input input bytebuf\r
48      * @return MatchEntriesBuilder which can be filled with MatchEntry augmentation\r
49      */\r
50     protected MatchEntriesBuilder processHeader(Class<? extends Clazz> oxm_class,\r
51             Class<? extends MatchField> oxm_field, ByteBuf input) {\r
52         MatchEntriesBuilder builder = new MatchEntriesBuilder();\r
53         builder.setOxmClass(oxm_class);\r
54         // skip oxm_class (provided)\r
55         input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
56         builder.setOxmMatchField(oxm_field);\r
57         boolean hasMask = (input.readUnsignedByte() & 1) != 0;\r
58         builder.setHasMask(hasMask);\r
59         // skip match entry length - not needed\r
60         input.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);\r
61         return builder;\r
62     }\r
63     \r
64 }\r