2 * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
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
9 package org.opendaylight.openflowjava.protocol.impl.util;
11 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.openflowjava.protocol.api.keys.ActionDeserializerKey;
14 import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionDeserializerKey;
15 import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterInstructionDeserializerKey;
16 import org.opendaylight.openflowjava.protocol.api.keys.InstructionDeserializerKey;
17 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
18 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
19 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
22 * @author michal.polkorab
25 public abstract class CodeKeyMakerFactory {
27 private CodeKeyMakerFactory() {
34 public static CodeKeyMaker createMatchEntriesKeyMaker(short version) {
35 return new AbstractCodeKeyMaker(version) {
37 public MessageCodeKey make(ByteBuf input) {
38 int oxmClass = input.getUnsignedShort(input.readerIndex());
39 int oxmField = input.getUnsignedByte(input.readerIndex()
40 + EncodeConstants.SIZE_OF_SHORT_IN_BYTES) >>> 1;
41 MatchEntryDeserializerKey key = new MatchEntryDeserializerKey(getVersion(),
43 if (oxmClass == EncodeConstants.EXPERIMENTER_VALUE) {
44 long expId = input.getUnsignedInt(input.readerIndex() + EncodeConstants.SIZE_OF_SHORT_IN_BYTES
45 + 2 * EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
46 key.setExperimenterId(expId);
49 key.setExperimenterId(null);
59 public static CodeKeyMaker createActionsKeyMaker(short version) {
60 return new AbstractCodeKeyMaker(version) {
62 public MessageCodeKey make(ByteBuf input) {
63 int type = input.getUnsignedShort(input.readerIndex());
64 if (type == EncodeConstants.EXPERIMENTER_VALUE) {
65 Long expId = input.getUnsignedInt(input.readerIndex()
66 + 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
67 return new ExperimenterActionDeserializerKey(getVersion(), expId);
69 ActionDeserializerKey actionDeserializerKey = new ActionDeserializerKey(getVersion(), type, null);
70 return actionDeserializerKey;
79 public static CodeKeyMaker createInstructionsKeyMaker(short version) {
80 return new AbstractCodeKeyMaker(version) {
82 public MessageCodeKey make(ByteBuf input) {
83 int type = input.getUnsignedShort(input.readerIndex());
84 if (type == EncodeConstants.EXPERIMENTER_VALUE) {
85 Long expId = input.getUnsignedInt(input.readerIndex()
86 + 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
87 return new ExperimenterInstructionDeserializerKey(getVersion(), expId);
89 return new InstructionDeserializerKey(getVersion(), type, null);