f4002122b667e5dcdfd69fcc978b6cdcb9dfa957
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / util / CodeKeyMakerFactory.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 \r
9 package org.opendaylight.openflowjava.protocol.impl.util;\r
10 \r
11 import io.netty.buffer.ByteBuf;\r
12 \r
13 import org.opendaylight.openflowjava.protocol.api.extensibility.EnhancedMessageCodeKey;\r
14 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey;\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;\r
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
18 \r
19 /**\r
20  * @author michal.polkorab\r
21  *\r
22  */\r
23 public abstract class CodeKeyMakerFactory {\r
24 \r
25     /**\r
26      * @param version\r
27      * @return\r
28      */\r
29     public static CodeKeyMaker createMatchEntriesKeyMaker(short version) {\r
30         return new AbstractCodeKeyMaker(version) {\r
31             @Override\r
32             public MessageCodeKey make(ByteBuf input) {\r
33                 int oxmClass = input.getUnsignedShort(input.readerIndex());\r
34                 int oxmField = input.getUnsignedByte(input.readerIndex()\r
35                         + EncodeConstants.SIZE_OF_SHORT_IN_BYTES) >>> 1;\r
36                 return new EnhancedMessageCodeKey(getVersion(), oxmClass,\r
37                         oxmField, MatchEntries.class);\r
38             }\r
39         };\r
40     }\r
41 \r
42     /**\r
43      * @param version\r
44      * @return\r
45      */\r
46     public static CodeKeyMaker createActionsKeyMaker(short version) {\r
47         return new AbstractCodeKeyMaker(version) {\r
48             @Override\r
49             public MessageCodeKey make(ByteBuf input) {\r
50                 // EncodeConstants.EMPTY_VALUE used as temporary value\r
51                 // until action deserializers are split\r
52 //                int type = input.getUnsignedShort(input.readerIndex());\r
53 //                return new MessageCodeKey(getVersion(), type, Action.class);\r
54                 return new MessageCodeKey(getVersion(), EncodeConstants.EMPTY_VALUE, Action.class);\r
55             }\r
56         };\r
57     }\r
58 \r
59     /**\r
60      * @param version\r
61      * @return\r
62      */\r
63     public static CodeKeyMaker createInstructionsKeyMaker(short version) {\r
64         return new AbstractCodeKeyMaker(version) {\r
65             @Override\r
66             public MessageCodeKey make(ByteBuf input) {\r
67                 int type = input.getUnsignedShort(input.readerIndex());\r
68                 return new MessageCodeKey(getVersion(), type, Instruction.class);\r
69             }\r
70         };\r
71     }\r
72 }\r