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.deserialization.action;
11 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
12 import io.netty.buffer.ByteBuf;
13 import java.util.ArrayList;
14 import java.util.List;
15 import java.util.Objects;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector;
18 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
19 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
20 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.ActionChoice;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCaseBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldActionBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
27 import org.opendaylight.yangtools.yang.common.Uint32;
30 * OF13SetFieldActionDeserializer.
32 * @author michal.polkorab
34 public class OF13SetFieldActionDeserializer extends AbstractActionDeserializer
35 implements DeserializerRegistryInjector {
37 private DeserializerRegistry registry;
40 @SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR") // FB doesn't recognize Objects.requireNonNull
41 public Action deserialize(final ByteBuf input) {
42 Objects.requireNonNull(registry);
44 final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping
45 .ActionBuilder builder = new ActionBuilder();
46 final int startIndex = input.readerIndex();
47 input.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
48 final SetFieldCaseBuilder caseBuilder = new SetFieldCaseBuilder();
49 SetFieldActionBuilder actionBuilder = new SetFieldActionBuilder();
50 int oxmClass = input.getUnsignedShort(input.readerIndex());
51 // get oxm_field & hasMask byte and extract the field value
52 int oxmField = input.getUnsignedByte(input.readerIndex()
53 + EncodeConstants.SIZE_OF_SHORT_IN_BYTES) >>> 1;
54 MatchEntryDeserializerKey key = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID,
56 if (oxmClass == EncodeConstants.EXPERIMENTER_VALUE) {
57 long expId = input.getUnsignedInt(input.readerIndex() + EncodeConstants.SIZE_OF_SHORT_IN_BYTES
58 + 2 * EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
59 key.setExperimenterId(Uint32.valueOf(expId));
61 OFDeserializer<MatchEntry> matchDeserializer = registry.getDeserializer(key);
62 List<MatchEntry> entry = new ArrayList<>();
63 entry.add(matchDeserializer.deserialize(input));
64 actionBuilder.setMatchEntry(entry);
65 caseBuilder.setSetFieldAction(actionBuilder.build());
66 builder.setActionChoice(caseBuilder.build());
67 int paddingRemainder = (input.readerIndex() - startIndex) % EncodeConstants.PADDING;
68 if (paddingRemainder != 0) {
69 input.skipBytes(EncodeConstants.PADDING - paddingRemainder);
71 return builder.build();
75 protected ActionChoice getType() {
76 return new SetFieldCaseBuilder().build();
80 public void injectDeserializerRegistry(final DeserializerRegistry deserializerRegistry) {
81 this.registry = deserializerRegistry;