Updated extension registration keys
[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.MessageCodeKey;\r
14 import org.opendaylight.openflowjava.protocol.api.extensibility.keys.ActionDeserializerKey;\r
15 import org.opendaylight.openflowjava.protocol.api.extensibility.keys.InstructionDeserializerKey;\r
16 import org.opendaylight.openflowjava.protocol.api.extensibility.keys.MatchEntryDeserializerKey;\r
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;\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                 MatchEntryDeserializerKey key = new MatchEntryDeserializerKey(getVersion(),\r
37                         oxmClass, oxmField);\r
38                 if (oxmClass == EncodeConstants.EXPERIMENTER_VALUE) {\r
39                     long expId = input.getUnsignedInt(input.readerIndex() + EncodeConstants.SIZE_OF_SHORT_IN_BYTES\r
40                             + 2 * EncodeConstants.SIZE_OF_BYTE_IN_BYTES);\r
41                     key.setExperimenterId(expId);\r
42                     return key;\r
43                 }\r
44                 key.setExperimenterId(null);\r
45                 return key;\r
46             }\r
47         };\r
48     }\r
49 \r
50     /**\r
51      * @param version\r
52      * @return\r
53      */\r
54     public static CodeKeyMaker createActionsKeyMaker(short version) {\r
55         return new AbstractCodeKeyMaker(version) {\r
56             @Override\r
57             public MessageCodeKey make(ByteBuf input) {\r
58                 int type = input.getUnsignedShort(input.readerIndex());\r
59                 if (type == EncodeConstants.EXPERIMENTER_VALUE) {\r
60                     Long expId = input.getUnsignedInt(input.readerIndex()\r
61                             + 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
62                     return new ActionDeserializerKey(getVersion(), type, expId);\r
63                 }\r
64                 ActionDeserializerKey actionDeserializerKey = new ActionDeserializerKey(getVersion(), type, null);\r
65                 return actionDeserializerKey;\r
66             }\r
67         };\r
68     }\r
69 \r
70     /**\r
71      * @param version\r
72      * @return\r
73      */\r
74     public static CodeKeyMaker createInstructionsKeyMaker(short version) {\r
75         return new AbstractCodeKeyMaker(version) {\r
76             @Override\r
77             public MessageCodeKey make(ByteBuf input) {\r
78                 int type = input.getUnsignedShort(input.readerIndex());\r
79                 if (type == EncodeConstants.EXPERIMENTER_VALUE) {\r
80                     Long expId = input.getUnsignedInt(input.readerIndex()\r
81                             + 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);\r
82                     return new InstructionDeserializerKey(getVersion(), type, expId);\r
83                 }\r
84                 return new InstructionDeserializerKey(getVersion(), type, null);\r
85             }\r
86         };\r
87     }\r
88 }\r