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;
12 import org.opendaylight.openflowjava.protocol.api.keys.ActionDeserializerKey;
13 import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionDeserializerKey;
14 import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterInstructionDeserializerKey;
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.MessageCodeKey;
18 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
19 import org.opendaylight.yangtools.yang.common.Uint32;
22 * Factory for creating CodeKeyMaker instances.
24 * @author michal.polkorab
26 public final class CodeKeyMakerFactory {
28 private CodeKeyMakerFactory() {
32 public static CodeKeyMaker createMatchEntriesKeyMaker(final short version) {
33 return new AbstractCodeKeyMaker(version) {
35 public MessageCodeKey make(final ByteBuf input) {
36 int oxmClass = input.getUnsignedShort(input.readerIndex());
37 int oxmField = input.getUnsignedByte(input.readerIndex()
38 + EncodeConstants.SIZE_OF_SHORT_IN_BYTES) >>> 1;
39 MatchEntryDeserializerKey key = new MatchEntryDeserializerKey(getVersion(),
41 if (oxmClass == EncodeConstants.EXPERIMENTER_VALUE) {
42 long expId = input.getUnsignedInt(input.readerIndex() + EncodeConstants.SIZE_OF_SHORT_IN_BYTES
43 + 2 * EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
44 key.setExperimenterId(Uint32.valueOf(expId));
47 key.setExperimenterId(null);
53 public static CodeKeyMaker createActionsKeyMaker(final short version) {
54 return new AbstractCodeKeyMaker(version) {
56 public MessageCodeKey make(final ByteBuf input) {
57 int type = input.getUnsignedShort(input.readerIndex());
58 if (type == EncodeConstants.EXPERIMENTER_VALUE) {
59 Long expId = input.getUnsignedInt(input.readerIndex()
60 + 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
61 return new ExperimenterActionDeserializerKey(getVersion(), expId);
63 ActionDeserializerKey actionDeserializerKey = new ActionDeserializerKey(getVersion(), type, null);
64 return actionDeserializerKey;
69 public static CodeKeyMaker createInstructionsKeyMaker(final short version) {
70 return new AbstractCodeKeyMaker(version) {
72 public MessageCodeKey make(final ByteBuf input) {
73 int type = input.getUnsignedShort(input.readerIndex());
74 if (type == EncodeConstants.EXPERIMENTER_VALUE) {
75 Long expId = input.getUnsignedInt(input.readerIndex()
76 + 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
77 return new ExperimenterInstructionDeserializerKey(getVersion(), expId);
79 return new InstructionDeserializerKey(getVersion(), type, null);