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 io.netty.buffer.ByteBuf;
13 import java.util.ArrayList;
14 import java.util.List;
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.augments.rev131002.OxmFieldsAction;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsActionBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionBase;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
30 * @author michal.polkorab
33 public class OF13SetFieldActionDeserializer extends AbstractActionDeserializer
34 implements DeserializerRegistryInjector {
36 private DeserializerRegistry registry;
39 public Action deserialize(ByteBuf input) {
40 ActionBuilder builder = new ActionBuilder();
41 builder.setType(getType());
42 int startIndex = input.readerIndex();
43 input.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
44 OxmFieldsActionBuilder matchEntries = new OxmFieldsActionBuilder();
45 int oxmClass = input.getUnsignedShort(input.readerIndex());
46 // get oxm_field & hasMask byte and extract the field value
47 int oxmField = input.getUnsignedByte(input.readerIndex()
48 + EncodeConstants.SIZE_OF_SHORT_IN_BYTES) >>> 1;
49 MatchEntryDeserializerKey key = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID,
51 if (oxmClass == EncodeConstants.EXPERIMENTER_VALUE) {
52 long expId = input.getUnsignedInt(input.readerIndex() + EncodeConstants.SIZE_OF_SHORT_IN_BYTES
53 + 2 * EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
54 key.setExperimenterId(expId);
56 OFDeserializer<MatchEntries> matchDeserializer = registry.getDeserializer(key);
57 List<MatchEntries> entry = new ArrayList<>();
58 entry.add(matchDeserializer.deserialize(input));
59 matchEntries.setMatchEntries(entry);
60 builder.addAugmentation(OxmFieldsAction.class, matchEntries.build());
61 int paddingRemainder = (input.readerIndex() - startIndex) % EncodeConstants.PADDING;
62 if (paddingRemainder != 0) {
63 input.skipBytes(EncodeConstants.PADDING - paddingRemainder);
65 return builder.build();
69 protected Class<? extends ActionBase> getType() {
70 return SetField.class;
74 public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) {
75 this.registry = deserializerRegistry;