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.extensibility.MessageCodeKey;
14 import org.opendaylight.openflowjava.protocol.api.keys.ActionDeserializerKey;
15 import org.opendaylight.openflowjava.protocol.api.keys.InstructionDeserializerKey;
16 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
17 import org.opendaylight.openflowjava.protocol.api.keys.experimenter.ExperimenterActionDeserializerKey;
18 import org.opendaylight.openflowjava.protocol.api.keys.experimenter.ExperimenterInstructionDeserializerKey;
19 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
22 * @author michal.polkorab
25 public abstract class CodeKeyMakerFactory {
31 public static CodeKeyMaker createMatchEntriesKeyMaker(short version) {
32 return new AbstractCodeKeyMaker(version) {
34 public MessageCodeKey make(ByteBuf input) {
35 int oxmClass = input.getUnsignedShort(input.readerIndex());
36 int oxmField = input.getUnsignedByte(input.readerIndex()
37 + EncodeConstants.SIZE_OF_SHORT_IN_BYTES) >>> 1;
38 MatchEntryDeserializerKey key = new MatchEntryDeserializerKey(getVersion(),
40 if (oxmClass == EncodeConstants.EXPERIMENTER_VALUE) {
41 long expId = input.getUnsignedInt(input.readerIndex() + EncodeConstants.SIZE_OF_SHORT_IN_BYTES
42 + 2 * EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
43 key.setExperimenterId(expId);
46 key.setExperimenterId(null);
56 public static CodeKeyMaker createActionsKeyMaker(short version) {
57 return new AbstractCodeKeyMaker(version) {
59 public MessageCodeKey make(ByteBuf input) {
60 int type = input.getUnsignedShort(input.readerIndex());
61 if (type == EncodeConstants.EXPERIMENTER_VALUE) {
62 Long expId = input.getUnsignedInt(input.readerIndex()
63 + 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
64 return new ExperimenterActionDeserializerKey(getVersion(), expId);
66 ActionDeserializerKey actionDeserializerKey = new ActionDeserializerKey(getVersion(), type, null);
67 return actionDeserializerKey;
76 public static CodeKeyMaker createInstructionsKeyMaker(short version) {
77 return new AbstractCodeKeyMaker(version) {
79 public MessageCodeKey make(ByteBuf input) {
80 int type = input.getUnsignedShort(input.readerIndex());
81 if (type == EncodeConstants.EXPERIMENTER_VALUE) {
82 Long expId = input.getUnsignedInt(input.readerIndex()
83 + 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
84 return new ExperimenterInstructionDeserializerKey(getVersion(), expId);
86 return new InstructionDeserializerKey(getVersion(), type, null);