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